1
Fork 0
mirror of https://bitbucket.org/Ioncannon/project-meteor-server.git synced 2025-04-24 21:57:45 +00:00

Reversed all my lua fuckery.

This commit is contained in:
Filip Maj 2018-04-07 14:04:22 -04:00
parent 13727caf14
commit bbd4fcef3b
4 changed files with 49 additions and 116 deletions

View file

@ -110,7 +110,6 @@
<Compile Include="actors\quest\Quest.cs" />
<Compile Include="actors\StaticActors.cs" />
<Compile Include="actors\world\WorldMaster.cs" />
<Compile Include="dataobjects\GameEvent.cs" />
<Compile Include="dataobjects\GuildleveData.cs" />
<Compile Include="dataobjects\TradeTransaction.cs" />
<Compile Include="dataobjects\ZoneConnection.cs" />

View file

@ -88,7 +88,10 @@ namespace FFXIVClassic_Map_Server.Actors
74000, 78000, 81000, 85000, 89000, 92000, 96000, 100000, 100000, 110000}; //Level <= 50
//Event Related
private Stack<GameEvent> runningEvents = new Stack<GameEvent>();
public uint currentEventOwner = 0;
public string currentEventName = "";
public Coroutine currentEventRunning;
//Player Info
public uint destinationZone;
@ -1675,15 +1678,12 @@ namespace FFXIVClassic_Map_Server.Actors
public void StartEvent(Actor owner, EventStartPacket start)
{
GameEvent startedEvent = new GameEvent(start.triggerName, this, owner);
runningEvents.Push(startedEvent);
LuaEngine.GetInstance().EventStarted(startedEvent, start);
LuaEngine.GetInstance().EventStarted(this, owner, start);
}
public void UpdateEvent(EventUpdatePacket update)
{
GameEvent updateEvent = runningEvents.Peek();
LuaEngine.GetInstance().OnEventUpdate(updateEvent, update.luaParams);
LuaEngine.GetInstance().OnEventUpdate(this, update.luaParams);
}
public void KickEvent(Actor actor, string conditionName, params object[] parameters)
@ -1691,8 +1691,6 @@ namespace FFXIVClassic_Map_Server.Actors
if (actor == null)
return;
runningEvents.Pop();
List<LuaParam> lParams = LuaUtils.CreateLuaParamList(parameters);
SubPacket spacket = KickEventPacket.BuildPacket(actorId, actor.actorId, 0x75dc1705, conditionName, lParams);
spacket.DebugPrintSubPacket();
@ -1704,8 +1702,6 @@ namespace FFXIVClassic_Map_Server.Actors
if (actor == null)
return;
runningEvents.Pop();
List<LuaParam> lParams = LuaUtils.CreateLuaParamList(parameters);
SubPacket spacket = KickEventPacket.BuildPacket(actorId, actor.actorId, unknown, conditionName, lParams);
spacket.DebugPrintSubPacket();
@ -1720,17 +1716,20 @@ namespace FFXIVClassic_Map_Server.Actors
public void RunEventFunction(string functionName, params object[] parameters)
{
List<LuaParam> lParams = LuaUtils.CreateLuaParamList(parameters);
SubPacket spacket = RunEventFunctionPacket.BuildPacket(actorId, runningEvents.Peek().GetOwnerActorId(), runningEvents.Peek().GetEventName(), functionName, lParams);
SubPacket spacket = RunEventFunctionPacket.BuildPacket(actorId, currentEventOwner, currentEventName, functionName, lParams);
spacket.DebugPrintSubPacket();
QueuePacket(spacket);
}
public void EndEvent()
{
GameEvent endingEvent = runningEvents.Pop();
SubPacket p = EndEventPacket.BuildPacket(actorId, endingEvent.GetOwnerActorId(), endingEvent.GetEventName());
SubPacket p = EndEventPacket.BuildPacket(actorId, currentEventOwner, currentEventName);
p.DebugPrintSubPacket();
QueuePacket(p);
currentEventOwner = 0;
currentEventName = "";
currentEventRunning = null;
}
public void SendInstanceUpdate()

View file

@ -1,65 +0,0 @@
using FFXIVClassic_Map_Server.Actors;
using MoonSharp.Interpreter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FFXIVClassic_Map_Server.dataobjects
{
class GameEvent
{
private string eventName;
private uint ownerActorId;
private Player playerActor;
private Actor ownerActor;
private Coroutine coroutine;
private uint hashCode;
public GameEvent(String eventName, Player player, Actor owner)
{
this.eventName = eventName;
this.playerActor = player;
this.ownerActor = owner;
this.ownerActorId = owner.actorId;
hashCode = (uint)new Tuple<uint, uint, string>(player.actorId, owner.actorId, eventName).GetHashCode();
}
public string GetEventName()
{
return eventName;
}
public uint GetOwnerActorId()
{
return ownerActorId;
}
public Player GetPlayerActor()
{
return playerActor;
}
public Actor GetOwnerActor()
{
return ownerActor;
}
public Coroutine GetCoroutine()
{
return coroutine;
}
public void SetCoroutine(Coroutine coroutine)
{
this.coroutine = coroutine;
}
public uint GetUniqueEventId()
{
return hashCode;
}
}
}

View file

@ -36,6 +36,7 @@ namespace FFXIVClassic_Map_Server.lua
private Timer luaTimer;
private LuaEngine()
{
UserData.RegistrationPolicy = InteropRegistrationPolicy.Automatic;
@ -107,25 +108,25 @@ namespace FFXIVClassic_Map_Server.lua
}
}
public void OnEventUpdate(GameEvent gEvent, List<LuaParam> args)
public void OnEventUpdate(Player player, List<LuaParam> args)
{
if (mSleepingOnPlayerEvent.ContainsKey(gEvent.GetUniqueEventId()))
if (mSleepingOnPlayerEvent.ContainsKey(player.actorId))
{
try
{
Coroutine coroutine = mSleepingOnPlayerEvent[gEvent.GetUniqueEventId()];
mSleepingOnPlayerEvent.Remove(gEvent.GetUniqueEventId());
Coroutine coroutine = mSleepingOnPlayerEvent[player.actorId];
mSleepingOnPlayerEvent.Remove(player.actorId);
DynValue value = coroutine.Resume(LuaUtils.CreateLuaParamObjectList(args));
ResolveResume(gEvent.GetPlayerActor(), coroutine, value);
ResolveResume(player, coroutine, value);
}
catch (ScriptRuntimeException e)
{
LuaEngine.SendError(gEvent.GetPlayerActor(), String.Format("OnEventUpdated: {0}", e.DecoratedMessage));
gEvent.GetPlayerActor().EndEvent();
LuaEngine.SendError(player, String.Format("OnEventUpdated: {0}", e.DecoratedMessage));
player.EndEvent();
}
}
else
gEvent.GetPlayerActor().EndEvent();
player.EndEvent();
}
private static string GetScriptPath(Actor target)
@ -214,7 +215,7 @@ namespace FFXIVClassic_Map_Server.lua
private void CallLuaFunctionNpc(Player player, Npc target, string funcName, bool optional, params object[] args)
{
object[] args2 = new object[args.Length + (player == null ? 1:2)];
object[] args2 = new object[args.Length + (player == null ? 1 : 2)];
Array.Copy(args, 0, args2, (player == null ? 1 : 2), args.Length);
if (player != null)
{
@ -364,32 +365,32 @@ namespace FFXIVClassic_Map_Server.lua
}
}
public void EventStarted(GameEvent gEvent, EventStartPacket eventStart)
public void EventStarted(Player player, Actor target, EventStartPacket eventStart)
{
List<LuaParam> lparams = eventStart.luaParams;
lparams.Insert(0, new LuaParam(2, eventStart.triggerName));
if (mSleepingOnPlayerEvent.ContainsKey(gEvent.GetUniqueEventId()))
if (mSleepingOnPlayerEvent.ContainsKey(player.actorId))
{
Coroutine coroutine = mSleepingOnPlayerEvent[gEvent.GetUniqueEventId()];
mSleepingOnPlayerEvent.Remove(gEvent.GetUniqueEventId());
Coroutine coroutine = mSleepingOnPlayerEvent[player.actorId];
mSleepingOnPlayerEvent.Remove(player.actorId);
try{
try
{
DynValue value = coroutine.Resume();
ResolveResume(null, coroutine, value);
}
catch (ScriptRuntimeException e)
{
LuaEngine.SendError(gEvent.GetPlayerActor(), String.Format("OnEventStarted: {0}", e.DecoratedMessage));
gEvent.GetPlayerActor().EndEvent();
LuaEngine.SendError(player, String.Format("OnEventStarted: {0}", e.DecoratedMessage));
player.EndEvent();
}
}
else
{
if (gEvent.GetOwnerActor() is Director)
((Director)gEvent.GetOwnerActor()).OnEventStart(gEvent.GetPlayerActor(), LuaUtils.CreateLuaParamObjectList(lparams));
if (target is Director)
((Director)target).OnEventStart(player, LuaUtils.CreateLuaParamObjectList(lparams));
else
CallLuaFunction(gEvent.GetPlayerActor(), gEvent.GetOwnerActor(), "onEventStarted", false, LuaUtils.CreateLuaParamObjectList(lparams));
CallLuaFunction(player, target, "onEventStarted", false, LuaUtils.CreateLuaParamObjectList(lparams));
}
}
@ -611,9 +612,8 @@ namespace FFXIVClassic_Map_Server.lua
return;
List<SubPacket> SendError = new List<SubPacket>();
player.SendMessage(SendMessagePacket.MESSAGE_TYPE_SYSTEM_ERROR, "", message);
player.EndEvent();
player.QueuePacket(EndEventPacket.BuildPacket(player.actorId, player.currentEventOwner, player.currentEventName));
}
}
}