hello
im using nestharus' encoder system and theres a strange bug
when i save the hero with just stats, the code is 8 letter long but when experience is added the code jumps to 21 letter
thank you if you help me !
im using nestharus' encoder system and theres a strange bug
when i save the hero with just stats, the code is 8 letter long but when experience is added the code jumps to 21 letter
thank you if you help me !
JASS:
library Encoders uses Catalogs
globals
private constant integer CUR_ENC_VER = 2
private Encoder array encoders
endglobals
function GetEncoder takes nothing returns Encoder
return encoders[CUR_ENC_VER]
endfunction
private struct Encoder1 extends array
private static constant integer ENC_VER = 2
private static constant string ENCODER_BASE = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
private static constant integer ENCODER_HASH = 148194
private static constant integer ENCODER_PLAYER_HASH = 2562
private static method onInit takes nothing returns nothing
local Encoder encoder = Encoder.create(Base[ENCODER_BASE], ENCODER_HASH, ENCODER_PLAYER_HASH,1)
local CodeRange hero = CodeRange.create(1,HeroCatalog.count)
local CodeRange lvl = CodeRange.create(1,90)
local CodeRange xp = CodeRange.create(0,99)
local CodeRange stats = CodeRange.create(0,0)
local CodeRange stat = CodeRange.create(0,256)
local CodeRange inv = CodeRange.create(0,0)
local CodeRange it = CodeRange.create(0,ItemCatalog.count)
local CodeRange ab = CodeRange.create(0,8)
local CodeRange ab2 = CodeRange.create(0,12)
local CodeRange charge = CodeRange.create(1,99)
local CodeRange abilities = CodeRange.create(0,0)
local CodeRange resource = CodeRange.create(0,1000000)
call it.link(ItemCatalog.chargeMin,ItemCatalog.chargeMax,charge, 1)
call abilities.linka(ab)
call abilities.linka(ab)
call abilities.linka(ab)
call abilities.linka(ab)
call abilities.linka(ab2)
call stats.linka(lvl)
call stats.linka(xp)
call stats.linka(stat)
call stats.linka(stat)
call stats.linka(stat)
call inv.linka(it)
call inv.linka(it)
call inv.linka(it)
call inv.linka(it)
call inv.linka(it)
call inv.linka(it)
call hero.linka(stats)
call hero.linka(inv)
call hero.link(HeroCatalog.abilMin, HeroCatalog.abilMax, abilities, 0)
call encoder.add(hero)
call encoder.add(resource)
call encoder.add(resource)
set encoders[ENC_VER] = encoder
endmethod
endstruct
endlibrary
JASS:
struct Saver extends array
private static method saveAbilities takes DataBuffer buffer, unit hero returns nothing
local AbilityCatalog1 i = AbilityCatalog[GetUnitTypeId(hero)]
local integer c = i.count
local integer o = 0
loop
exitwhen o == c
set o = o + 1
call buffer.write(GetUnitAbilityLevel(hero, i.raw(o)))
endloop
endmethod
private static method saveItem takes DataBuffer buffer, item i returns nothing
if (i == null) then
call buffer.write(0)
else
call buffer.write(ItemCatalog[GetItemTypeId(i)].id)
if (buffer.id == 1) then
call buffer.write(GetItemCharges(i))
endif
endif
endmethod
private static method saveInventory takes DataBuffer buffer, unit u returns nothing
call saveItem(buffer,UnitItemInSlot(u,0))
call saveItem(buffer,UnitItemInSlot(u,1))
call saveItem(buffer,UnitItemInSlot(u,2))
call saveItem(buffer,UnitItemInSlot(u,3))
call saveItem(buffer,UnitItemInSlot(u,4))
call saveItem(buffer,UnitItemInSlot(u,5))
endmethod
private static method saveStats takes DataBuffer buffer, unit hero returns nothing
call buffer.write(GetHeroLevel(hero))
call buffer.write(GetPercentHeroXP(hero))
call buffer.write(GetHeroStr(hero, false))
call buffer.write(GetHeroAgi(hero, false))
call buffer.write(GetHeroInt(hero, false))
endmethod
private static method saveHero takes DataBuffer buffer, unit hero, integer pid returns nothing
call buffer.write(HeroCatalog[GetUnitTypeId(hero)].id)
call saveStats(buffer, hero)
call saveInventory(buffer, hero)
call saveAbilities(buffer, hero)
endmethod
private static method run takes nothing returns boolean
local player p = GetTriggerPlayer()
local integer pid = GetPlayerId(p)
local Encoder encoder
local DataBuffer buffer
local integer start = 0
local integer iid
if (pdata[pid]) then
set encoder = GetEncoder()
set buffer = encoder.write(pid)
call saveHero(buffer, hero[pid], pid)
call buffer.write(GetPlayerState(p, PLAYER_STATE_RESOURCE_LUMBER))
call buffer.write(GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD))
call DisplayTextToPlayer(p,0,0,"|c0080ffffCode : |r"+buffer.code)
endif
return false
endmethod
private static method runs takes nothing returns nothing
local integer i = 7
local trigger t = CreateTrigger()
call PauseTimer(GetExpiredTimer())
call DestroyTimer(GetExpiredTimer())
loop
if (GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(i)) == MAP_CONTROL_USER) then
call TriggerRegisterPlayerChatEvent(t, Player(i), "-save", true)
endif
exitwhen i == 0
set i = i - 1
endloop
call TriggerAddCondition(t, function thistype.run)
endmethod
private static method onInit takes nothing returns nothing
call TimerStart(CreateTimer(), 0, false, function thistype.runs)
endmethod
endstruct
Last edited: