mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-08-03 00:01:57 +02:00
Implemented "wait" functionality to the lua engine. Lost commits due to screw up.
This commit is contained in:
parent
bc30958d37
commit
718bc28c57
12 changed files with 302 additions and 611 deletions
|
@ -88,7 +88,7 @@ namespace FFXIVClassic_Map_Server.Actors
|
|||
List<LuaParam> lParams;
|
||||
|
||||
Player player = Server.GetWorldManager().GetPCInWorld(playerActorId);
|
||||
lParams = DoActorInit(player);
|
||||
lParams = LuaEngine.GetInstance().CallLuaFunctionForReturn(player, this, "init");
|
||||
|
||||
if (uniqueIdentifier.Equals("1"))
|
||||
{
|
||||
|
@ -372,159 +372,14 @@ namespace FFXIVClassic_Map_Server.Actors
|
|||
this.eventConditions = conditions;
|
||||
}
|
||||
|
||||
public List<LuaParam> DoActorInit(Player player)
|
||||
public void DoOnActorSpawn(Player player)
|
||||
{
|
||||
LuaScript parent = null, child = null;
|
||||
|
||||
if (File.Exists("./scripts/base/" + classPath + ".lua"))
|
||||
parent = LuaEngine.LoadScript("./scripts/base/" + classPath + ".lua");
|
||||
|
||||
if (zone is PrivateArea)
|
||||
{
|
||||
if (File.Exists(String.Format("./scripts/unique/{0}/privatearea/{1}/{2}/{3}.lua", zone.zoneName, ((PrivateArea)zone).GetPrivateAreaName(), className, uniqueIdentifier)))
|
||||
child = LuaEngine.LoadScript(String.Format("./scripts/unique/{0}/privatearea/{1}/{2}/{3}.lua", zone.zoneName, ((PrivateArea)zone).GetPrivateAreaName(), className, uniqueIdentifier));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (File.Exists(String.Format("./scripts/unique/{0}/{1}/{2}.lua", zone.zoneName, className, uniqueIdentifier)))
|
||||
child = LuaEngine.LoadScript(String.Format("./scripts/unique/{0}/{1}/{2}.lua", zone.zoneName, className, uniqueIdentifier));
|
||||
}
|
||||
|
||||
if (parent == null && child == null)
|
||||
{
|
||||
LuaEngine.SendError(player, String.Format("ERROR: Could not find script for actor {0}.", GetName()));
|
||||
return null;
|
||||
}
|
||||
|
||||
DynValue result;
|
||||
|
||||
if (child != null && child.Globals["init"] != null)
|
||||
result = child.Call(child.Globals["init"], this);
|
||||
else if (parent != null && parent.Globals["init"] != null)
|
||||
result = parent.Call(parent.Globals["init"], this);
|
||||
else
|
||||
return null;
|
||||
|
||||
List<LuaParam> lparams = LuaUtils.CreateLuaParamList(result);
|
||||
return lparams;
|
||||
}
|
||||
|
||||
public Coroutine GetEventStartCoroutine(Player player)
|
||||
{
|
||||
LuaScript parent = null, child = null;
|
||||
|
||||
if (File.Exists("./scripts/base/" + classPath + ".lua"))
|
||||
parent = LuaEngine.LoadScript("./scripts/base/" + classPath + ".lua");
|
||||
if (zone is PrivateArea)
|
||||
{
|
||||
if (File.Exists(String.Format("./scripts/unique/{0}/privatearea/{1}/{2}/{3}.lua", zone.zoneName, ((PrivateArea)zone).GetPrivateAreaName(), className, uniqueIdentifier)))
|
||||
child = LuaEngine.LoadScript(String.Format("./scripts/unique/{0}/privatearea/{1}/{2}/{3}.lua", zone.zoneName, ((PrivateArea)zone).GetPrivateAreaName(), className, uniqueIdentifier));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (File.Exists(String.Format("./scripts/unique/{0}/{1}/{2}.lua", zone.zoneName, className, uniqueIdentifier)))
|
||||
child = LuaEngine.LoadScript(String.Format("./scripts/unique/{0}/{1}/{2}.lua", zone.zoneName, className, uniqueIdentifier));
|
||||
}
|
||||
|
||||
if (parent == null && child == null)
|
||||
{
|
||||
LuaEngine.SendError(player, String.Format("ERROR: Could not find script for actor {0}.", GetName()));
|
||||
return null;
|
||||
}
|
||||
|
||||
//Run Script
|
||||
Coroutine coroutine;
|
||||
|
||||
if (child != null && !child.Globals.Get("onEventStarted").IsNil())
|
||||
coroutine = child.CreateCoroutine(child.Globals["onEventStarted"]).Coroutine;
|
||||
else if (parent.Globals.Get("onEventStarted") != null && !parent.Globals.Get("onEventStarted").IsNil())
|
||||
coroutine = parent.CreateCoroutine(parent.Globals["onEventStarted"]).Coroutine;
|
||||
else
|
||||
return null;
|
||||
|
||||
return coroutine;
|
||||
}
|
||||
|
||||
public void DoEventUpdate(Player player, EventUpdatePacket eventUpdate)
|
||||
{
|
||||
LuaScript parent = null, child = null;
|
||||
|
||||
if (File.Exists("./scripts/base/" + classPath + ".lua"))
|
||||
parent = LuaEngine.LoadScript("./scripts/base/" + classPath + ".lua");
|
||||
if (File.Exists(String.Format("./scripts/unique/{0}/{1}/{2}.lua", zone.zoneName, className, uniqueIdentifier)))
|
||||
child = LuaEngine.LoadScript(String.Format("./scripts/unique/{0}/{1}/{2}.lua", zone.zoneName, className, uniqueIdentifier));
|
||||
|
||||
if (parent == null && child == null)
|
||||
{
|
||||
//LuaEngine.SendError(player, String.Format("ERROR: Could not find script for actor {0}.", GetName()));
|
||||
return;
|
||||
}
|
||||
|
||||
//Have to do this to combine LuaParams
|
||||
List<Object> objects = new List<Object>();
|
||||
objects.Add(player);
|
||||
objects.Add(this);
|
||||
objects.Add(eventUpdate.val2);
|
||||
objects.AddRange(LuaUtils.CreateLuaParamObjectList(eventUpdate.luaParams));
|
||||
|
||||
//Run Script
|
||||
DynValue result;
|
||||
|
||||
if (child != null && !child.Globals.Get("onEventUpdate").IsNil())
|
||||
result = child.Call(child.Globals["onEventUpdate"], objects.ToArray());
|
||||
else if (!parent.Globals.Get("onEventUpdate").IsNil())
|
||||
result = parent.Call(parent.Globals["onEventUpdate"], objects.ToArray());
|
||||
else
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
internal void DoOnActorSpawn(Player player)
|
||||
{
|
||||
LuaScript parent = null, child = null;
|
||||
|
||||
if (File.Exists("./scripts/base/" + classPath + ".lua"))
|
||||
parent = LuaEngine.LoadScript("./scripts/base/" + classPath + ".lua");
|
||||
if (File.Exists(String.Format("./scripts/unique/{0}/{1}/{2}.lua", zone.zoneName, className, uniqueIdentifier)))
|
||||
child = LuaEngine.LoadScript(String.Format("./scripts/unique/{0}/{1}/{2}.lua", zone.zoneName, className, uniqueIdentifier));
|
||||
|
||||
if (parent == null && child == null)
|
||||
{
|
||||
//LuaEngine.SendError(player, String.Format("ERROR: Could not find script for actor {0}.", GetName()));
|
||||
return;
|
||||
}
|
||||
|
||||
//Run Script
|
||||
if (child != null && child.Globals["onSpawn"] != null)
|
||||
child.Call(child.Globals["onSpawn"], player, this);
|
||||
else if (parent != null && parent.Globals["onSpawn"] != null)
|
||||
parent.Call(parent.Globals["onSpawn"], player, this);
|
||||
else
|
||||
return;
|
||||
LuaEngine.GetInstance().CallLuaFunction(player, this, "onSpawn");
|
||||
}
|
||||
|
||||
public void Update(double deltaTime)
|
||||
{
|
||||
LuaScript parent = null, child = null;
|
||||
|
||||
if (File.Exists("./scripts/base/" + classPath + ".lua"))
|
||||
parent = LuaEngine.LoadScript("./scripts/base/" + classPath + ".lua");
|
||||
if (File.Exists(String.Format("./scripts/unique/{0}/{1}/{2}.lua", zone.zoneName, className, uniqueIdentifier)))
|
||||
child = LuaEngine.LoadScript(String.Format("./scripts/unique/{0}/{1}/{2}.lua", zone.zoneName, className, uniqueIdentifier));
|
||||
|
||||
if (parent == null && child == null)
|
||||
{
|
||||
//LuaEngine.SendError(player, String.Format("ERROR: Could not find script for actor {0}.", GetName()));
|
||||
return;
|
||||
}
|
||||
|
||||
//Run Script
|
||||
if (child != null && child.Globals["onThink"] != null)
|
||||
child.Call(child.Globals["onThink"], this, deltaTime);
|
||||
else if (parent != null && parent.Globals["onThink"] != null)
|
||||
parent.Call(parent.Globals["onThink"], this, deltaTime);
|
||||
else
|
||||
return;
|
||||
LuaEngine.GetInstance().CallLuaFunction(null, this, "onUpdate", deltaTime);
|
||||
}
|
||||
|
||||
//A party member list packet came, set the party
|
||||
|
|
|
@ -1226,98 +1226,12 @@ namespace FFXIVClassic_Map_Server.Actors
|
|||
|
||||
public void StartEvent(Actor owner, EventStartPacket start)
|
||||
{
|
||||
//Have to do this to combine LuaParams
|
||||
List<Object> objects = new List<Object>();
|
||||
objects.Add(this);
|
||||
objects.Add(owner);
|
||||
objects.Add(start.triggerName);
|
||||
|
||||
if (start.luaParams != null)
|
||||
objects.AddRange(LuaUtils.CreateLuaParamObjectList(start.luaParams));
|
||||
|
||||
if (owner is Npc)
|
||||
{
|
||||
currentEventRunning = ((Npc)owner).GetEventStartCoroutine(this);
|
||||
|
||||
if (currentEventRunning != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
currentEventRunning.Resume(objects.ToArray());
|
||||
}
|
||||
catch (ScriptRuntimeException e)
|
||||
{
|
||||
Program.Log.Error("[LUA] {0}", e.DecoratedMessage);
|
||||
EndEvent();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EndEvent();
|
||||
}
|
||||
}
|
||||
else if (owner is Director)
|
||||
{
|
||||
currentEventRunning = ((Director)owner).GetEventStartCoroutine(this);
|
||||
|
||||
if (currentEventRunning != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
currentEventRunning.Resume(objects.ToArray());
|
||||
}
|
||||
catch (ScriptRuntimeException e)
|
||||
{
|
||||
Program.Log.Error("[LUA] {0}", e.DecoratedMessage);
|
||||
EndEvent();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EndEvent();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
currentEventRunning = LuaEngine.DoActorOnEventStarted(this, owner, start);
|
||||
|
||||
if (currentEventRunning != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
currentEventRunning.Resume(objects.ToArray());
|
||||
}
|
||||
catch (ScriptRuntimeException e)
|
||||
{
|
||||
Program.Log.Error("[LUA] {0}", e.DecoratedMessage);
|
||||
EndEvent();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EndEvent();
|
||||
}
|
||||
}
|
||||
|
||||
LuaEngine.GetInstance().EventStarted(this, owner, start);
|
||||
}
|
||||
|
||||
public void UpdateEvent(EventUpdatePacket update)
|
||||
{
|
||||
if (currentEventRunning == null)
|
||||
return;
|
||||
|
||||
if (currentEventRunning.State == CoroutineState.Suspended)
|
||||
{
|
||||
try
|
||||
{
|
||||
currentEventRunning.Resume(LuaUtils.CreateLuaParamObjectList(update.luaParams));
|
||||
}
|
||||
catch (ScriptRuntimeException e)
|
||||
{
|
||||
Program.Log.Error("[LUA] {0}", e.DecoratedMessage);
|
||||
EndEvent();
|
||||
}
|
||||
}
|
||||
LuaEngine.GetInstance().OnEventUpdate(this);
|
||||
}
|
||||
|
||||
public void KickEvent(Actor actor, string conditionName, params object[] parameters)
|
||||
|
@ -1455,7 +1369,7 @@ namespace FFXIVClassic_Map_Server.Actors
|
|||
|
||||
public void Update(double delta)
|
||||
{
|
||||
LuaEngine.OnPlayerUpdate(this, delta);
|
||||
LuaEngine.GetInstance().CallLuaFunction(this, this, "OnUpdate", delta);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -70,39 +70,23 @@ namespace FFXIVClassic_Map_Server.actors.director
|
|||
|
||||
public void OnTalkEvent(Player player, Npc npc)
|
||||
{
|
||||
if (File.Exists("./scripts/directors/" + directorScriptPath + ".lua"))
|
||||
{
|
||||
LuaScript script = LuaEngine.LoadScript("./scripts/directors/" + directorScriptPath + ".lua");
|
||||
|
||||
if (script == null)
|
||||
return;
|
||||
|
||||
//Run Script
|
||||
if (!script.Globals.Get("onTalkEvent").IsNil())
|
||||
script.Call(script.Globals["onTalkEvent"], player, npc);
|
||||
}
|
||||
else
|
||||
{
|
||||
LuaEngine.SendError(player, String.Format("ERROR: Could not find script for director {0}.", GetName()));
|
||||
}
|
||||
LuaEngine.GetInstance().CallLuaFunction(player, this, "onTalkEvent", npc);
|
||||
}
|
||||
|
||||
public void OnCommandEvent(Player player, Command command)
|
||||
{
|
||||
if (File.Exists("./scripts/directors/" + directorScriptPath + ".lua"))
|
||||
{
|
||||
LuaScript script = LuaEngine.LoadScript("./scripts/directors/" + directorScriptPath + ".lua");
|
||||
LuaEngine.GetInstance().CallLuaFunction(player, this, "onCommandEvent", command);
|
||||
}
|
||||
|
||||
if (script == null)
|
||||
return;
|
||||
|
||||
//Run Script
|
||||
if (!script.Globals.Get("onCommandEvent").IsNil())
|
||||
script.Call(script.Globals["onCommandEvent"], player, command);
|
||||
}
|
||||
else
|
||||
public void DoActorInit(string directorPath)
|
||||
{
|
||||
List<LuaParam> lparams = LuaEngine.GetInstance().CallLuaFunctionForReturn(null, this, "init");
|
||||
|
||||
if (lparams.Count == 1 && lparams[0].value is string)
|
||||
{
|
||||
LuaEngine.SendError(player, String.Format("ERROR: Could not find script for director {0}.", GetName()));
|
||||
classPath = (string)lparams[0].value;
|
||||
className = classPath.Substring(classPath.LastIndexOf("/") + 1);
|
||||
isCreated = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,52 +110,6 @@ namespace FFXIVClassic_Map_Server.actors.director
|
|||
Server.GetWorldManager().GetZone(zoneId).DeleteDirector(actorId);
|
||||
}
|
||||
|
||||
public void DoActorInit(string directorPath)
|
||||
{
|
||||
LuaScript script = null;
|
||||
|
||||
if (File.Exists("./scripts/directors/" + directorPath + ".lua"))
|
||||
script = LuaEngine.LoadScript("./scripts/directors/" + directorPath + ".lua");
|
||||
else
|
||||
return;
|
||||
|
||||
DynValue result;
|
||||
|
||||
if (script != null && script.Globals["init"] != null)
|
||||
result = script.Call(script.Globals["init"], this);
|
||||
else
|
||||
return;
|
||||
|
||||
List<LuaParam> lparams = LuaUtils.CreateLuaParamList(result);
|
||||
|
||||
if (lparams.Count == 1 && lparams[0].value is string)
|
||||
{
|
||||
classPath = (string)lparams[0].value;
|
||||
className = classPath.Substring(classPath.LastIndexOf("/") + 1);
|
||||
isCreated = true;
|
||||
}
|
||||
}
|
||||
|
||||
public Coroutine GetEventStartCoroutine(Player player)
|
||||
{
|
||||
LuaScript script = null;
|
||||
|
||||
if (File.Exists("./scripts/directors/" + directorScriptPath + ".lua"))
|
||||
script = LuaEngine.LoadScript("./scripts/directors/" + directorScriptPath + ".lua");
|
||||
else
|
||||
return null;
|
||||
|
||||
//Run Script
|
||||
Coroutine coroutine;
|
||||
|
||||
if (script != null && !script.Globals.Get("onEventStarted").IsNil())
|
||||
coroutine = script.CreateCoroutine(script.Globals["onEventStarted"]).Coroutine;
|
||||
else
|
||||
return null;
|
||||
|
||||
return coroutine;
|
||||
}
|
||||
|
||||
public bool IsCreated()
|
||||
{
|
||||
return isCreated;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue