atomizer / muledump

all your mules are belong to you
84 stars 144 forks source link

slice off backpack items if char has no backpack #139

Open tischepe opened 7 years ago

tischepe commented 7 years ago

I've noticed that the backpack empty space count is not always correct, The rotmg server returns this: \<Char id="***"> \<ObjectType>782\</ObjectType> \<Level>20\</Level> \<Exp>154063\</Exp> \<CurrentFame>261\</CurrentFame> \<Equipment>2719,2774,2656,2755,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1\</Equipment> ... snip ... \<HasBackpack>0\</HasBackpack> \</Char> The character has no backpack, yet equipment contains 19 items, these 7 nonexistent empty spaces get counted in totals.

So I slice the array if the char has no backpack before pushing it into items.

Nightfirecat commented 7 years ago

What's the story about there being 19 slots of equipment? Why are 12 of 19 valid? (equips make 4, inventory is 8, backpack is 8 more, unless I'm missing something)

Just trying to figure out where all these numbers are coming from.

P.S. It might help to define magic numbers like these as constants. I know that's not done too well across the code as-is, but it would help for future maintenance.

tischepe commented 7 years ago

Everything between \<Char id="***"> and \</Char> is generated by realmofthemadgodhrd.appspot.com/char/list so where those 7 extra -1 items come from, you would need to ask Deca games. You mean, you want to define 0 as equipment_Begin, 3 as equipment_End, 4 as inventory_Begin etc.?

Nightfirecat commented 7 years ago

No, I mean I'd like to define the 12 that marks the end of the slice. Why 12 exactly? What does that represent? (equip + inventory?)

tischepe commented 7 years ago

Yes 12 is (equip + inventory) I see two ways of doing this: to complete the list I was making: 0 as equipment_Begin 3 as equipment_End 4 as inventory_Begin 11 as inventory_End 12 as backpack_Begin 19 as backpack_End then you could write: this.items.chars.push(eq.slice(equipment_Begin, backpack_Begin));

Or you could also just define: equipmentSize as 4 inventorySize as 8 backpackSize as 8 and write: this.items.chars.push(eq.slice(0, equipmentSize + inventorySize));

Nightfirecat commented 7 years ago

I wouldn't overthink it. That said, I'm still a little worried about why 19 is the number we come up with for number of total inventory slots. Is that result different if you check a character which does have a backpack enabled?

tischepe commented 7 years ago

Just to be clear, the 19 in "19 as backpack_End" comes from the fact that javascript start array indexes at 0. The 19 items in "2719,2774,2656,2755,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1" is some weird thing Deca games its servers generate. And yes, a char with backpack does have 20 itemslots. and example: \<Equipment>3151,3160,2703,2757,2815,2698,2698,2698,2698,2698,2698, 2698,2722,2722,2722,2722,2722,2722,2722,2722\</Equipment>