mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-06-08 21:44:35 +02:00
Removed NLua and replaced it with MoonSharp. Scripting for NPCs has been implemented, but still have to test a lot.
This commit is contained in:
parent
74be19c51d
commit
300748668f
27 changed files with 22603 additions and 136 deletions
|
@ -4,7 +4,8 @@ using FFXIVClassic_Map_Server.dataobjects;
|
|||
using FFXIVClassic_Map_Server.packets.receive.events;
|
||||
using FFXIVClassic_Map_Server.packets.send;
|
||||
using FFXIVClassic_Map_Server.packets.send.events;
|
||||
using NLua;
|
||||
using MoonSharp.Interpreter;
|
||||
using MoonSharp.Interpreter.Interop;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
@ -17,59 +18,129 @@ namespace FFXIVClassic_Map_Server.lua
|
|||
class LuaEngine
|
||||
{
|
||||
const string FILEPATH_COMMANDS = "./scripts/command/{0}.lua";
|
||||
const string FILEPATH_EVENTS = "./scripts/talk/{0}.lua";
|
||||
|
||||
Lua lstate = new Lua();
|
||||
const string FILEPATH_NPCS = "./scripts/zones/{0}/npcs/{1}.lua";
|
||||
|
||||
public LuaEngine()
|
||||
{
|
||||
{
|
||||
UserData.RegistrationPolicy = InteropRegistrationPolicy.Automatic;
|
||||
}
|
||||
|
||||
public List<LuaParam> doActorOnInstantiate(Player player, Actor target)
|
||||
{
|
||||
string luaPath;
|
||||
|
||||
if (target is Npc)
|
||||
{
|
||||
luaPath = String.Format(FILEPATH_NPCS, target.zoneId, target.getName());
|
||||
if (File.Exists(luaPath))
|
||||
{
|
||||
Script script = new Script();
|
||||
script.DoFile(luaPath);
|
||||
DynValue result = script.Call(script.Globals["onInstantiate"], player, target);
|
||||
List<LuaParam> lparams = LuaUtils.createLuaParamList(result);
|
||||
return lparams;
|
||||
}
|
||||
else
|
||||
{
|
||||
List<SubPacket> sendError = new List<SubPacket>();
|
||||
sendError.Add(EndEventPacket.buildPacket(player.actorId, player.playerSession.eventCurrentOwner, player.playerSession.eventCurrentStarter));
|
||||
player.sendMessage(SendMessagePacket.MESSAGE_TYPE_SYSTEM_ERROR, "", String.Format("ERROR: Could not find script for actor {0}.", target.getName()));
|
||||
player.playerSession.queuePacket(BasePacket.createPacket(sendError, true, false));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void doEventStart(ConnectedPlayer player, Actor target, EventStartPacket packet)
|
||||
public void doActorOnEventStarted(Player player, Actor target)
|
||||
{
|
||||
string luaPath;
|
||||
|
||||
if (target is Command)
|
||||
{
|
||||
luaPath = String.Format(FILEPATH_COMMANDS, target.getName());
|
||||
if (File.Exists(luaPath))
|
||||
{
|
||||
Script script = new Script();
|
||||
script.DoFile(luaPath);
|
||||
DynValue result = script.Call(script.Globals["onEventStarted"], player, target);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<SubPacket> sendError = new List<SubPacket>();
|
||||
sendError.Add(EndEventPacket.buildPacket(player.actorId, player.playerSession.eventCurrentOwner, player.playerSession.eventCurrentStarter));
|
||||
player.sendMessage(SendMessagePacket.MESSAGE_TYPE_SYSTEM_ERROR, "", String.Format("ERROR: Could not find script for actor {0}.", target.getName()));
|
||||
player.playerSession.queuePacket(BasePacket.createPacket(sendError, true, false));
|
||||
}
|
||||
}
|
||||
else if (target is Npc)
|
||||
luaPath = String.Format(FILEPATH_EVENTS, target.getName());
|
||||
else
|
||||
luaPath = "";
|
||||
|
||||
if (File.Exists(luaPath))
|
||||
{
|
||||
lstate.DoFile(luaPath);
|
||||
var eventStarted = lstate["eventStarted"] as LuaFunction;
|
||||
eventStarted.Call(new LuaPlayer(player), player.eventCurrentOwner, LuaUtils.createLuaParamObjectList(packet.luaParams));
|
||||
}
|
||||
else
|
||||
{
|
||||
List<SubPacket> sendError = new List<SubPacket>();
|
||||
sendError.Add(EndEventPacket.buildPacket(player.actorID, player.eventCurrentOwner, player.eventCurrentStarter));
|
||||
sendError.Add(SendMessagePacket.buildPacket(player.actorID, player.actorID, SendMessagePacket.MESSAGE_TYPE_GENERAL_INFO, "", "ERROR: Could not find script for event"));
|
||||
player.queuePacket(BasePacket.createPacket(sendError, true, false));
|
||||
luaPath = String.Format(FILEPATH_NPCS, target.zoneId, target.getName());
|
||||
if (File.Exists(luaPath))
|
||||
{
|
||||
Script script = new Script();
|
||||
script.DoFile(luaPath);
|
||||
DynValue result = script.Call(script.Globals["onEventStarted"], player, target);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<SubPacket> sendError = new List<SubPacket>();
|
||||
sendError.Add(EndEventPacket.buildPacket(player.actorId, player.playerSession.eventCurrentOwner, player.playerSession.eventCurrentStarter));
|
||||
player.sendMessage(SendMessagePacket.MESSAGE_TYPE_SYSTEM_ERROR, "", String.Format("ERROR: Could not find script for actor {0}.", target.getName()));
|
||||
player.playerSession.queuePacket(BasePacket.createPacket(sendError, true, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void doEventUpdated(ConnectedPlayer player, Actor target, EventUpdatePacket packet)
|
||||
public void doActorOnEventUpdated(Player player, Actor target, EventUpdatePacket eventUpdate)
|
||||
{
|
||||
string luaPath = String.Format(FILEPATH_EVENTS, ((Command)target).getName());
|
||||
string luaPath;
|
||||
|
||||
if (File.Exists(luaPath))
|
||||
if (target is Command)
|
||||
{
|
||||
lstate.DoFile(luaPath);
|
||||
var eventStarted = lstate["eventUpdated"] as LuaFunction;
|
||||
eventStarted.Call(new LuaPlayer(player), player.eventCurrentOwner, packet.step, LuaUtils.createLuaParamObjectList(packet.luaParams));
|
||||
luaPath = String.Format(FILEPATH_COMMANDS, target.getName());
|
||||
if (File.Exists(luaPath))
|
||||
{
|
||||
Script script = new Script();
|
||||
script.DoFile(luaPath);
|
||||
DynValue result = script.Call(script.Globals["onEventUpdate"], player, target, eventUpdate.step, eventUpdate.luaParams);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<SubPacket> sendError = new List<SubPacket>();
|
||||
sendError.Add(EndEventPacket.buildPacket(player.actorId, player.playerSession.eventCurrentOwner, player.playerSession.eventCurrentStarter));
|
||||
player.sendMessage(SendMessagePacket.MESSAGE_TYPE_SYSTEM_ERROR, "", String.Format("ERROR: Could not find script for actor {0}.", target.getName()));
|
||||
player.playerSession.queuePacket(BasePacket.createPacket(sendError, true, false));
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (target is Npc)
|
||||
{
|
||||
List<SubPacket> sendError = new List<SubPacket>();
|
||||
sendError.Add(EndEventPacket.buildPacket(player.actorID, player.eventCurrentOwner, player.eventCurrentStarter));
|
||||
sendError.Add(SendMessagePacket.buildPacket(player.actorID, player.actorID, SendMessagePacket.MESSAGE_TYPE_GENERAL_INFO, "", "ERROR: Could not find script for event"));
|
||||
player.queuePacket(BasePacket.createPacket(sendError, true, false));
|
||||
luaPath = String.Format(FILEPATH_NPCS, target.zoneId, target.getName());
|
||||
if (File.Exists(luaPath))
|
||||
{
|
||||
Script script = new Script();
|
||||
script.DoFile(luaPath);
|
||||
|
||||
//Have to do this to combine LuaParams
|
||||
List<Object> objects = new List<Object>();
|
||||
objects.Add(player);
|
||||
objects.Add(target);
|
||||
objects.Add(eventUpdate.step);
|
||||
objects.AddRange(LuaUtils.createLuaParamObjectList(eventUpdate.luaParams));
|
||||
|
||||
//Run Script
|
||||
DynValue result = script.Call(script.Globals["onEventUpdate"], objects.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
List<SubPacket> sendError = new List<SubPacket>();
|
||||
sendError.Add(EndEventPacket.buildPacket(player.actorId, player.playerSession.eventCurrentOwner, player.playerSession.eventCurrentStarter));
|
||||
player.sendMessage(SendMessagePacket.MESSAGE_TYPE_SYSTEM_ERROR, "", String.Format("ERROR: Could not find script for actor {0}.", target.getName()));
|
||||
player.playerSession.queuePacket(BasePacket.createPacket(sendError, true, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue