Skip to content

Commit

Permalink
Update init.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
Luan Luciano authored Mar 29, 2024
1 parent 96174b1 commit f986510
Showing 1 changed file with 42 additions and 40 deletions.
82 changes: 42 additions & 40 deletions data/modules/scripts/gamestore/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1821,6 +1821,48 @@ function GameStore.processHirelingPurchase(player, offer, productType, hirelingN
end
end

-- Hireling Helpers
local function HandleHirelingNameChange(playerId, offer, newHirelingName)
local player = Player(playerId)
if not player then
return
end

local functionCallback = function(playerId, data, hireling)

Check warning on line 1831 in data/modules/scripts/gamestore/init.lua

View workflow job for this annotation

GitHub Actions / luacheck

[luacheck] reported by reviewdog 🐶 shadowing upvalue argument 'playerId' on line 1825 Raw Output: data/modules/scripts/gamestore/init.lua:1831:36: shadowing upvalue argument 'playerId' on line 1825
local player = Player(playerId)

Check warning on line 1832 in data/modules/scripts/gamestore/init.lua

View workflow job for this annotation

GitHub Actions / luacheck

[luacheck] reported by reviewdog 🐶 shadowing upvalue 'player' on line 1826 Raw Output: data/modules/scripts/gamestore/init.lua:1832:9: shadowing upvalue 'player' on line 1826
if not player then
return
end

local offer = data.offer

Check warning on line 1837 in data/modules/scripts/gamestore/init.lua

View workflow job for this annotation

GitHub Actions / luacheck

[luacheck] reported by reviewdog 🐶 unused variable 'offer' Raw Output: data/modules/scripts/gamestore/init.lua:1837:9: unused variable 'offer'

Check warning on line 1837 in data/modules/scripts/gamestore/init.lua

View workflow job for this annotation

GitHub Actions / luacheck

[luacheck] reported by reviewdog 🐶 shadowing upvalue argument 'offer' on line 1825 Raw Output: data/modules/scripts/gamestore/init.lua:1837:9: shadowing upvalue argument 'offer' on line 1825
local newHirelingName = data.newHirelingName

Check warning on line 1838 in data/modules/scripts/gamestore/init.lua

View workflow job for this annotation

GitHub Actions / luacheck

[luacheck] reported by reviewdog 🐶 shadowing upvalue argument 'newHirelingName' on line 1825 Raw Output: data/modules/scripts/gamestore/init.lua:1838:9: shadowing upvalue argument 'newHirelingName' on line 1825

if not hireling then
return player:showInfoModal("Error", "Your must select a hireling.")
end

if hireling.active > 0 then
return player:showInfoModal("Error", "Your hireling must be inside his/her lamp.")
end

local oldName = hireling.name
hireling.name = newHirelingName

if not player:makeCoinTransaction(data.offer, oldName .. " to " .. newHirelingName) then
return player:showInfoModal("Error", "Transaction error")
end

local lamp = player:findHirelingLamp(hireling:getId())
if lamp then
lamp:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "This mysterious lamp summons your very own personal hireling.\nThis item cannot be traded.\nThis magic lamp is the home of " .. hireling:getName() .. ".")
end
logger.debug("{} has been renamed to {}", oldName, newHirelingName)
sendUpdatedStoreBalances(playerId)
end

player:sendHirelingSelectionModal("Choose a Hireling", "Select a hireling below", functionCallback, { offer = offer, newHirelingName = newHirelingName })
end

function GameStore.processHirelingChangeNamePurchase(player, offer, productType, newHirelingName)
if player:getClient().version < 1200 then
return error({
Expand Down Expand Up @@ -2155,46 +2197,6 @@ function Player:openStore(serviceName) --exporting the method so other scripts c
end
end

-- Hireling Helpers
function HandleHirelingNameChange(playerId, offer, newHirelingName)
local player = Player(playerId)
if not player then
return
end

local cb = function(playerId, data, hireling)
local player = Player(playerId)
if not player then
return
end

if not hireling then
return player:showInfoModal("Error", "Your must select a hireling.")
end

if hireling.active > 0 then
return player:showInfoModal("Error", "Your hireling must be inside his/her lamp.")
end

local oldName = hireling.name
local newHirelingName = data.newHirelingName
hireling.name = newHirelingName

if not player:makeCoinTransaction(data.offer, oldName .. " to " .. newHirelingName) then
return player:showInfoModal("Error", "Transaction error")
end

local lamp = player:findHirelingLamp(hireling:getId())
if lamp then
lamp:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "This mysterious lamp summons your very own personal hireling.\nThis item cannot be traded.\nThis magic lamp is the home of " .. hireling:getName() .. ".")
end
logger.debug("{} has been renamed to {}", oldName, newHirelingName)
sendUpdatedStoreBalances(playerId)
end

player:sendHirelingSelectionModal("Choose a Hireling", "Select a hireling below", cb, { offer = offer, newHirelingName = newHirelingName })
end

function HandleHirelingSexChange(playerId, offer)
local player = Player(playerId)
if not player then
Expand Down

0 comments on commit f986510

Please sign in to comment.