diff --git a/FFXIVClassic Map Server/dataobjects/GameEvent.cs b/FFXIVClassic Map Server/dataobjects/GameEvent.cs new file mode 100644 index 00000000..f0815a83 --- /dev/null +++ b/FFXIVClassic Map Server/dataobjects/GameEvent.cs @@ -0,0 +1,65 @@ +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(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; + } + + } +} diff --git a/data/scripts/commands/BazaarCheckCommand.lua b/data/scripts/commands/BazaarCheckCommand.lua new file mode 100644 index 00000000..87b63e84 --- /dev/null +++ b/data/scripts/commands/BazaarCheckCommand.lua @@ -0,0 +1,29 @@ +--[[ + +BazaarCheckCommand Script + +Handles what happens when you examine a player's bazaar + +--]] + +require ("global") + +function onEventStarted(player, actor, triggerName, name, arg1, arg2, arg3, bazaarActorId) + + local bazaarActor = nil; + + if (name ~= nil) then + bazaarActor = player:GetZone():FindPCInZone(name); + elseif (bazaarActorId ~= nil) then + bazaarActor = player:GetZone():FindActorInArea(bazaarActorId); + end + + if (bazaarActor ~= nil) then + callClientFunction(player, "delegateCommand", GetStaticActor("BazaarCheckCommand"), "processChackBazaar"); + else + --Show error + end + + player:EndEvent(); + +end \ No newline at end of file diff --git a/data/scripts/commands/BazaarDealCommand.lua b/data/scripts/commands/BazaarDealCommand.lua index 81c6abf2..17edb358 100644 --- a/data/scripts/commands/BazaarDealCommand.lua +++ b/data/scripts/commands/BazaarDealCommand.lua @@ -13,25 +13,42 @@ function onEventStarted(player, actor, triggerName, rewardItem, seekItem, bazaar local originalReward = nil; local originalSeek = nil; + --Handle special case for offers + if (seekItem == nil) then + originalSeek = player:GetItemPackage(0):GetItemAtSlot(rewardItem.seekSlot); + originalReward = player:GetItemPackage(0):GetItemAtSlot(rewardItem.offerSlot); + end + --Handle Reward if (type(rewardItem) == "number") then rewardItem = GetWorldManager():CreateItem(rewardItem, rewardAmount); + player:RemoveItem(1000001, rewardAmount); + elseif (seekItem == nil) then + rewardItem = originalReward; + if (bazaarMode ~= 11) then + rewardItem = GetWorldManager():CreateItem(rewardItem.itemId, rewardAmount, rewardItem.quality, rewardItem.modifiers); + end else rewardItem = player:GetItem(rewardItem); originalReward = rewardItem; if (bazaarMode ~= 11) then - rewardItem = GetWorldManager():CreateItem(rewardItem.itemId, rewardAmount, rewardItem.quality); + rewardItem = GetWorldManager():CreateItem(rewardItem.itemId, rewardAmount, rewardItem.quality, rewardItem.modifiers); end end --Handle Seek if (type(seekItem) == "number") then - seekItem = GetWorldManager():CreateItem(seekItem, rewardAmount); + seekItem = GetWorldManager():CreateItem(seekItem, seekAmount); + elseif (seekItem == nil) then + seekItem = originalSeek; + if (bazaarMode ~= 11) then + seekItem = GetWorldManager():CreateItem(seekItem.itemId, seekAmount, seekItem.quality, seekItem.modifiers); + end else seekItem = player:GetItem(seekItem); originalSeek = seekItem; if (bazaarMode ~= 11) then - seekItem = GetWorldManager():CreateItem(seekItem.itemId, seekAmount, seekItem.quality); + seekItem = GetWorldManager():CreateItem(seekItem.itemId, seekAmount, seekItem.quality, seekItem.modifiers); end end diff --git a/data/scripts/commands/BazaarTradeCommand.lua b/data/scripts/commands/BazaarTradeCommand.lua new file mode 100644 index 00000000..fcefbdee --- /dev/null +++ b/data/scripts/commands/BazaarTradeCommand.lua @@ -0,0 +1,51 @@ +--[[ + +BazaarTradeCommand Script + +Handles bazaar trade + +All bazaar args have a Reward (The item the person who fufills the request gets) and a Seek (The item the player wants, either gil or an item). + +--]] + +function onEventStarted(player, actor, triggerName, rewardItem, seekItemOrCost, seekAmount, arg1, bazaarActorId, rewardAmount, rewardItemId, nameIndex, arg2, type9ItemIds) + + local originalReward = nil; + local originalSeek = nil; + local bazaarActor = nil; + + --Get the bazaar actor + if (bazaarActorId ~= nil) then + bazaarActor = player:GetZone():FindActorInArea(bazaarActorId); + end + + --Abort if no actor + if (bazaarActor == nil) then + player:EndEvent(); + return; + end + + --If seekItem is a number, we are buying an item (ExecuteBazaarBuy) + if (type(seekItemOrCost) == "number") then + if (player:GetCurrentGil() >= seekItemOrCost) then + if (GetWorldManager():BazaarBuyOperation(bazaarActor, player, bazaarActor:GetItem(rewardItem), rewardAmount, seekItemOrCost)) then + else + end + else + --Show no gil error + end + else --Else we are fufilling a sought out item (ExecuteBazaarSell) + local rewardItem = player:GetItem(rewardItem); + local seekItem = player:GetItem(seekItemOrCost); + + if (rewardItem ~= nil and seekItem ~= nil) then + if (GetWorldManager():BazaarSellOperation(bazaarActor, player, rewardItem, rewardAmount, seekItem, seekAmount)) then + else + end + else + end + end + + player:EndEvent(); + +end \ No newline at end of file diff --git a/data/scripts/commands/BazaarUndealCommand.lua b/data/scripts/commands/BazaarUndealCommand.lua index b16f42fb..c8fe46d8 100644 --- a/data/scripts/commands/BazaarUndealCommand.lua +++ b/data/scripts/commands/BazaarUndealCommand.lua @@ -8,6 +8,8 @@ Handles canceling bazaar items function onEventStarted(player, actor, triggerName, rewardItem, arg1, bazaarType, arg2, bazaarActor, rewardAmount, seekAmount, arg3, arg4, type9ItemIds) + GetWorldManager():RemoveFromBazaar(player, player:GetItem(rewardItem)); + player:EndEvent(); end \ No newline at end of file diff --git a/data/scripts/commands/EquipCommand.lua b/data/scripts/commands/EquipCommand.lua index c9894c91..73432f6e 100644 --- a/data/scripts/commands/EquipCommand.lua +++ b/data/scripts/commands/EquipCommand.lua @@ -58,7 +58,7 @@ function onEventStarted(player, actor, triggerName, invActionInfo, param1, param --Equip Item if (invActionInfo ~= nil) then - item = player:GetInventory(0):GetItemAtSlot(invActionInfo.slot); + item = player:GetItemPackage(0):GetItemAtSlot(invActionInfo.slot); equipItem(player, equipSlot, item); player:SendAppearance(); --Unequip Item diff --git a/data/scripts/commands/ItemWasteCommand.lua b/data/scripts/commands/ItemWasteCommand.lua index e827391e..a5ff9cd2 100644 --- a/data/scripts/commands/ItemWasteCommand.lua +++ b/data/scripts/commands/ItemWasteCommand.lua @@ -10,6 +10,6 @@ The param "itemDBIds" has the vars: item1 and item2. --]] function onEventStarted(player, actor, triggerName, itemReference, targetPackage, sourcePackage, arg1, arg2, unknown, arg3, arg4, arg5, type9ItemIds) - player:GetInventory(targetPackage):RemoveItemAtSlot(itemReference.slot); + player:GetItemPackage(itemReference.itemPackage):RemoveItemAtSlot(itemReference.slot); player:EndEvent(); end