Events are now pushed onto a stack and popped off. Turns out multiple events *CAN* happen. Fixed quantity bugs when saving to DB. Fixed buying stacks.

This commit is contained in:
Filip Maj 2017-12-10 22:32:24 -05:00
parent 08c5980b22
commit a9d4e621e3
7 changed files with 38 additions and 58 deletions

View File

@ -1624,9 +1624,9 @@ namespace FFXIVClassic_Map_Server
string query = @" string query = @"
INSERT INTO server_items INSERT INTO server_items
(itemId, quality) (itemId, quantity, quality)
VALUES VALUES
(@itemId, @quality); (@itemId, @quantity, @quality);
"; ";
string query2 = @" string query2 = @"
@ -1638,6 +1638,7 @@ namespace FFXIVClassic_Map_Server
MySqlCommand cmd = new MySqlCommand(query, conn); MySqlCommand cmd = new MySqlCommand(query, conn);
cmd.Parameters.AddWithValue("@itemId", itemId); cmd.Parameters.AddWithValue("@itemId", itemId);
cmd.Parameters.AddWithValue("@quantity", quantity);
cmd.Parameters.AddWithValue("@quality", quality); cmd.Parameters.AddWithValue("@quality", quality);
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();

View File

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

View File

@ -175,11 +175,6 @@ namespace FFXIVClassic_Map_Server
Actor ownerActor = Server.GetStaticActors(eventStart.scriptOwnerActorID); Actor ownerActor = Server.GetStaticActors(eventStart.scriptOwnerActorID);
session.GetActor().currentEventOwner = eventStart.scriptOwnerActorID;
session.GetActor().currentEventName = eventStart.triggerName;
if (ownerActor == null) if (ownerActor == null)
{ {
//Is it your retainer? //Is it your retainer?
@ -187,7 +182,7 @@ namespace FFXIVClassic_Map_Server
ownerActor = session.GetActor().currentSpawnedRetainer; ownerActor = session.GetActor().currentSpawnedRetainer;
//Is it a instance actor? //Is it a instance actor?
if (ownerActor == null) if (ownerActor == null)
ownerActor = session.GetActor().zone.FindActorInArea(session.GetActor().currentEventOwner); ownerActor = session.GetActor().zone.FindActorInArea(eventStart.scriptOwnerActorID);
if (ownerActor == null) if (ownerActor == null)
{ {
//Is it a Director? //Is it a Director?

View File

@ -1060,19 +1060,16 @@ namespace FFXIVClassic_Map_Server
if (cost < 0) if (cost < 0)
return false; return false;
if (itemToBuy.GetBazaarMode() == InventoryItem.TYPE_STACK) if (itemToBuy.GetBazaarMode() == InventoryItem.TYPE_SINGLE || itemToBuy.GetBazaarMode() == InventoryItem.TYPE_MULTI || itemToBuy.GetBazaarMode() == InventoryItem.TYPE_STACK)
{
itemToBuy.ChangeQuantity(-quantity);
buyer.AddItemStack(itemToBuy.itemId, quantity, itemToBuy.quality);
buyer.GetItemPackage(Inventory.CURRENCY_CRYSTALS).RemoveItem(1000001, cost);
}
else
{ {
itemToBuy.ChangeQuantity(-quantity); itemToBuy.ChangeQuantity(-quantity);
buyer.AddItem(itemToBuy.itemId, quantity, itemToBuy.quality); buyer.AddItem(itemToBuy.itemId, quantity, itemToBuy.quality);
buyer.GetItemPackage(Inventory.CURRENCY_CRYSTALS).RemoveItem(1000001, cost); buyer.GetItemPackage(Inventory.CURRENCY_CRYSTALS).RemoveItem(1000001, cost);
} }
if (itemToBuy.quantity == 0)
Database.ClearBazaarEntry(bazaar, itemToBuy);
bazaar.CheckBazaarFlags(); bazaar.CheckBazaarFlags();
return true; return true;

View File

@ -151,18 +151,7 @@ namespace FFXIVClassic_Map_Server.Actors
ushort itemPackage = GetPackageForItem(catalogID); ushort itemPackage = GetPackageForItem(catalogID);
if (itemPackages.ContainsKey(itemPackage)) if (itemPackages.ContainsKey(itemPackage))
{ {
InventoryItem item = Server.GetWorldManager().CreateItem(catalogID, quantity, quality); itemPackages[itemPackage].AddItem(catalogID, quantity, quality);
itemPackages[itemPackage].AddItem(item);
}
}
public void AddItemStack(uint catalogID, int quantity, byte quality)
{
ItemData itemData = Server.GetItemGamedata(catalogID);
if (itemData != null)
{
int totalQuantity = itemData.maxStack * quantity;
AddItem(catalogID, totalQuantity, quality);
} }
} }

View File

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

View File

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