maple_clb/clb/packet_helper.py
2022-03-17 14:52:04 +00:00

136 lines
3.8 KiB
Python

from .character import Character, Traits
from .packet import iPacket, oPacket
class Helpers:
@staticmethod
def character_entries(ipkt: iPacket, view_all=None):
chars = []
ipkt.decode_byte()
total_chars = ipkt.decode_byte()
for i in range(total_chars):
chars.append(Helpers.character_entry(ipkt, view_all))
return chars
@staticmethod
def character_entry(ipkt: iPacket, view_all=None):
stats = Helpers.character_stats(ipkt)
look = Helpers.character_look(ipkt)
look_useful = {"equips": look["equips"], "weapon": look["weapon"]}
if view_all:
ipkt.decode_byte()
rank = {}
if ranked := ipkt.decode_byte():
rank["rank"] = ipkt.decode_int()
rank["rank_move"] = ipkt.decode_int()
rank["job_rank"] = ipkt.decode_int()
rank["job_rank_move"] = ipkt.decode_int()
return Character.fill(stats | look_useful | rank)
@staticmethod
def character_stats(ipkt: iPacket):
stats = {
"idx": ipkt.decode_int(),
"name": ipkt.decode_fixed_string().rstrip("\x00"),
"gender": ipkt.decode_byte(),
"skin": ipkt.decode_byte(),
"face": ipkt.decode_int(),
"hair": ipkt.decode_int()
}
ipkt.decode_buffer(24)
stats |= {
"level": ipkt.decode_byte(),
"job": ipkt.decode_short(),
"strn": ipkt.decode_short(),
"dex": ipkt.decode_short(),
"intl": ipkt.decode_short(),
"luk": ipkt.decode_short(),
"hp": ipkt.decode_int(),
"max_hp": ipkt.decode_int(),
"mp": ipkt.decode_int(),
"max_mp": ipkt.decode_int(),
"ap": ipkt.decode_short(),
"sp": ipkt.decode_short(),
"exp": ipkt.decode_int(),
"fame": ipkt.decode_int(),
"gach_exp": ipkt.decode_int(),
"map_id": ipkt.decode_int(),
"spawn": ipkt.decode_byte(),
}
ipkt.decode_int()
stats["sub_job"] = ipkt.decode_short()
if stats["job"] in [3001, 3100, 3110, 3111, 3112]:
stats["demon_marking"] = ipkt.decode_int()
stats["fatigue"] = ipkt.decode_byte()
ipkt.decode_int() # date
stats["traits_xp"] = {trait: ipkt.decode_int() for trait in Traits}
stats["traits_daily_xp"] = {
trait: ipkt.decode_short() for trait in Traits
}
stats["pvp_exp"] = ipkt.decode_int()
stats["pvp_rank"] = ipkt.decode_byte()
stats["battle_points"] = ipkt.decode_int()
ipkt.decode_byte()
ipkt.decode_int()
ipkt.decode_int()
ipkt.decode_int()
print(f"Stats: {stats}")
return stats
@staticmethod
def character_look(ipkt: iPacket):
look = {
"gender": ipkt.decode_byte(),
"skin": ipkt.decode_byte(),
"face": ipkt.decode_int(),
"job": ipkt.decode_int(),
"mega": ipkt.decode_byte(),
"hair": ipkt.decode_int(),
"equips": [],
"cash_equips": []
}
idx = -1
while idx != 0xFF:
idx = ipkt.decode_byte()
if idx == 0xFF:
idx = -1
break
look["equips"].append((idx, ipkt.decode_int()))
while idx != 0xFF:
idx = ipkt.decode_byte()
if idx == 0xFF:
break
look["cash_equips"].append((idx, ipkt.decode_int()))
look["weapon"] = ipkt.decode_int()
look["mercedes_ears"] = ipkt.decode_byte()
ipkt.decode_buffer(12)
if look["job"] in [3001, 3100, 3110, 3111, 3112]:
look["demon_marking"] = ipkt.decode_int()
return look