Hello everybody!
Because a lot of people like .NET languages more then native C++ or LUA ive decided to create a wrapper for scripting in .NET languages. It allows you to create DLLs in managed languages with scripts that get called from the core. It is planed to write a wrapper with identical functions for arcemu, mangos/trinity. So basically scripts written in .NET will be available for every emulation without changes.
This is still a WIP but here is a little example which shows you some of the functions ive implemented yet:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WoW;
namespace Wrapper
{
public class ScriptProvider : IScriptProvider
{
public ScriptProvider()
{
}
public void InitLib(ScriptMgr init)
{
init.RegisterChatHook(new Scripting.ChatHook());
init.RegisterCreatureAI(100, new Scripting.GnollScript());
init.RegisterCreatureGossip(50000, new Scripting.TestGossip());
}
}
}
namespace Scripting
{
public class ChatHook : IOnChatHook
{
public void Execute(Player sender, string message)
{
uint newLevel = 0;
if (uint.TryParse(message, out newLevel))
{
uint level = sender.GetUInt32Value(UnitFields.UNIT_FIELD_LEVEL);
sender.SetUInt32Value(UnitFields.UNIT_FIELD_LEVEL, level + newLevel);
sender.BroadcastMessage("Increased your level by " + newLevel);
}
}
}
public class TestGossip : IGossipScript
{
public override bool OnConstructMenu(Unit sender, Player target, GossipMenu menu)
{
if (!target.HasGMPermission())
return false;
ItemClickDlg Item3Click = delegate(Unit send, Player tar)
{
Console.WriteLine("Player '" + tar.GetName() + "' has clicked the third item!");
return true;
};
menu.AddItem(1, "Menu 1", Item1Click);
menu.AddItem(2, "Menu 2", Item2Click);
menu.AddItem(3, "Menu 3", Item3Click);
menu.SetTextID(197);
return true;
}
public bool Item2Click(Unit sender, Player target)
{
if (sender is Creature)
{
Creature cr = (Creature)sender;
cr.SendChatMessage("You have clicked the second item!");
}
return true;
}
public bool Item1Click(Unit sender, Player target)
{
target.BroadcastMessage("Clicked the first item!");
target.AddItem(39267, 1);
target.AddSpell(28132);
target.IncreaseAllSkills(400);
if (!target.HasQuestFinished(10000))
target.SendNotification("You have to finish the quest 10000 first!");
else
target.TeleportTo(609, 100.0f, 200.0f, 300.0f);
return true;
}
}
public class GnollScript : ICreatureAI
{
public override void OnCombatStart(Unit attacker)
{
if (attacker is Player)
{
Vector pos = attacker.GetPosition();
string msg = "Combat started by '" + ((Player)attacker).GetName() + "' ";
msg += "at position (" + pos.x + "/" + pos.y + "/" + pos.z + ")!";
((Player)attacker).BroadcastMessage(msg);
}
else
Console.WriteLine("Combat was not started by a player!");
}
}
}
So what do you tink about that? Sounds this good or not?
Greetings
Cromon