fix(premium): allow to spawn only one squire per player
This commit is contained in:
@@ -13,6 +13,9 @@ local SQUIRE_CREATURE_TEMPLATE_ID = 9000001
|
||||
|
||||
local NPC_TEXT_ID = 10000000
|
||||
|
||||
local premiums_table = {}
|
||||
local squires_table = {}
|
||||
|
||||
---todo extract to utils
|
||||
---@param inputstr string
|
||||
---@param separator string
|
||||
@@ -30,7 +33,7 @@ end
|
||||
|
||||
---@return boolean
|
||||
local function IsPremium(player)
|
||||
return player:HasFlag(PREMIUM_FLAG_INDEX, 1)
|
||||
return premiums_table[player:GetAccountId()] == true
|
||||
end
|
||||
|
||||
local function OnPremiumPlayer(player)
|
||||
@@ -58,7 +61,7 @@ local function RefreshPremiumStatus(player)
|
||||
local flags = query:GetUInt32(0)
|
||||
|
||||
if HasFlag(flags, ACCOUNT_FLAG_RECURRING_BILLING) then
|
||||
player:SetFlag(PREMIUM_FLAG_INDEX, 1)
|
||||
premiums_table[player:GetAccountId()] = true
|
||||
|
||||
OnPremiumPlayer(player)
|
||||
|
||||
@@ -108,7 +111,16 @@ end
|
||||
local function OnSummonSquireCast(player)
|
||||
local x, y, z, o = player:GetLocation()
|
||||
|
||||
if (squires_table[player:GetGUIDLow()] ~= nil) then
|
||||
local existing_squire = player:GetMap():GetWorldObject(squires_table[player:GetGUIDLow()])
|
||||
if (existing_squire ~= nil) then
|
||||
existing_squire:DespawnOrUnsummon()
|
||||
end
|
||||
end
|
||||
|
||||
local squire = player:SpawnCreature(SQUIRE_CREATURE_TEMPLATE_ID, x + 1, y + 1, z, o, 1, 30000)
|
||||
squires_table[player:GetGUIDLow()] = squire:GetGUID()
|
||||
print(squires_table[player:GetGUIDLow()])
|
||||
|
||||
if squire then
|
||||
squire:SetFaction(player:GetFaction())
|
||||
@@ -141,26 +153,27 @@ local function OnGossipSelect(event, player, creature, sender, intid, code)
|
||||
player:GossipComplete()
|
||||
end
|
||||
|
||||
if intid == 2 then
|
||||
player:SendShowBank(creature)
|
||||
player:GossipComplete()
|
||||
end
|
||||
if intid == 2 then
|
||||
player:SendShowBank(creature)
|
||||
player:GossipComplete()
|
||||
end
|
||||
|
||||
if intid == 3 then
|
||||
player:SendAuctionMenu(creature)
|
||||
player:GossipComplete()
|
||||
end
|
||||
if intid == 3 then
|
||||
player:SendAuctionMenu(creature)
|
||||
player:GossipComplete()
|
||||
end
|
||||
|
||||
if intid == 4 then
|
||||
player:DurabilityRepairAll()
|
||||
player:PlayDirectSound(1116)
|
||||
player:GossipComplete()
|
||||
end
|
||||
if intid == 4 then
|
||||
player:DurabilityRepairAll()
|
||||
player:PlayDirectSound(1116)
|
||||
player:GossipComplete()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function OnLogout(event, player)
|
||||
player:RemoveSpell(SUMMON_SQUIRE_SPELL_ID)
|
||||
squires_table[player:GetGUID()] = nil
|
||||
end
|
||||
|
||||
RegisterCreatureGossipEvent(SQUIRE_CREATURE_TEMPLATE_ID, 1, OnGossipHello)
|
||||
@@ -169,4 +182,3 @@ RegisterPlayerEvent(PLAYER_EVENT_ON_LOGIN, OnLogin)
|
||||
RegisterPlayerEvent(PLAYER_EVENT_ON_LOGOUT, OnLogout)
|
||||
RegisterPlayerEvent(PLAYER_EVENT_ON_COMMAND, OnCommand)
|
||||
RegisterPlayerEvent(PLAYER_EVENT_ON_SPELL_CAST, OnSpellCast)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user