-
-
Notifications
You must be signed in to change notification settings - Fork 648
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into canary-upstream
- Loading branch information
Showing
11 changed files
with
457 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
data-otservbr-global/scripts/creaturescripts/others/hireling_logout.lua
This file was deleted.
Oops, something went wrong.
101 changes: 101 additions & 0 deletions
101
...r-global/scripts/globalevents/game_migrations/20231128213358_move_hireling_data_to_kv.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
local old_hirelingSkills = { | ||
BANKER = 1, -- 1<<0 | ||
COOKING = 2, -- 1<<1 | ||
STEWARD = 4, -- 1<<2 | ||
TRADER = 8, -- 1<<3 | ||
} | ||
|
||
local old_hirelingOutfits = { | ||
BANKER = 1, -- 1<<0 | ||
COOKING = 2, -- 1<<1 | ||
STEWARD = 4, -- 1<<2 | ||
TRADER = 8, -- 1<<3 ... | ||
SERVANT = 16, | ||
HYDRA = 32, | ||
FERUMBRAS = 64, | ||
BONELORD = 128, | ||
DRAGON = 256, | ||
} | ||
|
||
local old_hirelingStorage = { | ||
SKILL = 28800, | ||
OUTFIT = 28900, | ||
} | ||
|
||
local function getOutfits(player) | ||
local flags = player:getStorageValue(old_hirelingStorage.OUTFIT) | ||
local outfits = {} | ||
if flags <= 0 then | ||
return outfits | ||
end | ||
for key, value in pairs(old_hirelingOutfits) do | ||
if hasBitSet(value, flags) then | ||
table.insert(outfits, key) | ||
end | ||
end | ||
return outfits | ||
end | ||
|
||
local function getSkills(player) | ||
local flags = player:getStorageValue(old_hirelingStorage.SKILL) | ||
local skills = {} | ||
if flags <= 0 then | ||
return skills | ||
end | ||
for key, value in pairs(old_hirelingSkills) do | ||
if hasBitSet(value, flags) then | ||
table.insert(skills, key) | ||
end | ||
end | ||
return skills | ||
end | ||
|
||
local function migrateHirelingData(player) | ||
if not player then | ||
return false | ||
end | ||
|
||
local outfits = getOutfits(player) | ||
local skills = getSkills(player) | ||
if #outfits == 0 and #skills == 0 then | ||
return true | ||
end | ||
logger.info("Migrating hireling data for player {}", player:getName()) | ||
for _, outfit in pairs(outfits) do | ||
logger.debug("Enabling hireling outfit: {}", outfit) | ||
local outfit = HIRELING_OUTFITS[outfit] | ||
if outfit then | ||
local name = outfit[2] | ||
if name then | ||
player:enableHirelingOutfit(name) | ||
else | ||
logger.error("Invalid hireling outfit name: {}", outfit[1]) | ||
end | ||
else | ||
logger.error("Invalid hireling outfit: {}", outfit) | ||
end | ||
end | ||
|
||
for _, skill in pairs(skills) do | ||
logger.debug("Enabling hireling skill: {}", skill) | ||
local skill = HIRELING_SKILLS[skill] | ||
if skill then | ||
local name = skill[2] | ||
if name then | ||
player:enableHirelingSkill(name) | ||
else | ||
logger.error("Invalid hireling skill name: {}", skill[1]) | ||
end | ||
else | ||
logger.error("Invalid hireling skill: {}", skill) | ||
end | ||
end | ||
end | ||
|
||
local migration = Migration("20231128213158_move_hireling_data_to_kv") | ||
|
||
function migration:onExecute() | ||
self:forEachPlayer(migrateHirelingData) | ||
end | ||
|
||
migration:register() |
Oops, something went wrong.