def decode(obj, unit_name): unit_name = unit_name state = obj['state'] if 'state' in obj else None cfg_id = obj['cfgID'] if 'cfgID' in obj else None pos = PosStateInfo.decode(obj['pos']) if 'pos' in obj else None fwd = FwdStateInfo.decode(obj['fwd']) if 'fwd' in obj else None hp = obj['hp'] if 'hp' in obj else None maxhp = obj['maxhp'] if 'maxhp' in obj else None speed = obj['speed'] if 'speed' in obj else None moving = obj['moving'] if 'moving' in obj else None chrtype = obj['chrtype'] if 'chrtype' in obj else None att = obj['att'] if 'att' in obj else None attspeed = obj['attspeed'] if 'attspeed' in obj else None mag = obj['mag'] if 'mag' in obj else None attpen = obj['attpen'] if 'attpen' in obj else None magpen = obj['magpen'] if 'magpen' in obj else None attpenrate = obj['attpenrate'] if 'attpenrate' in obj else None magpenrate = obj['magpenrate'] if 'magpenrate' in obj else None movelock = obj['movelock'] if 'movelock' in obj else None vis1 = obj['vis1'] if 'vis1' in obj else None vis2 = obj['vis2'] if 'vis2' in obj else None vis3 = obj['vis3'] if 'vis3' in obj else None team = obj['team'] if 'team' in obj else (None if pos is None else (0 if pos.x < 0 else 1)) return UnitStateInfo(unit_name, state, cfg_id, pos, fwd, hp, maxhp, speed, moving, chrtype, att, attspeed, mag, attpen, magpen, attpenrate, magpenrate, movelock, vis1, vis2, vis3, team)
def decode(obj): hero_name = obj['hero_name'] action = obj['action'] skillid = obj['skillid'] if 'skillid' in obj else None tgtid = obj['tgtid'] if 'tgtid' in obj else None tgtpos = PosStateInfo.decode(obj['tgtpos']) if 'tgtpos' in obj else None fwd = FwdStateInfo.decode(obj['fwd']) if 'fwd' in obj else None itemid = obj['itemid'] if 'itemid' in obj else None output_index = obj['output_index'] if 'output_index' in obj else None reward = obj['reward'] if 'reward' in obj else None vpred = obj['vpred'] if 'vpred' in obj else None return CmdAction(hero_name, action, skillid, tgtid, tgtpos, fwd, itemid, output_index, reward, vpred)
def decode(obj, hero_name): hero_name = hero_name state = obj['state'] if 'state' in obj else None cfg_id = obj['cfgID'] if 'cfgID' in obj else None pos = PosStateInfo.decode(obj['pos']) if 'pos' in obj else None fwd = FwdStateInfo.decode(obj['fwd']) if 'fwd' in obj else None hp = obj['hp'] if 'hp' in obj else None maxhp = obj['maxhp'] if 'maxhp' in obj else None maxmp = obj['maxmp'] if 'maxmp' in obj else None #TODO 如果没有信息,mp默认等于0? mp = obj['mp'] if 'mp' in obj else None speed = obj['speed'] if 'speed' in obj else None att = obj['att'] if 'att' in obj else None gold = obj['gold'] if 'gold' in obj else None hprec = obj['Hprec'] if 'Hprec' in obj else None # 是否可见信息(下路阵营,上路阵营,中立生物是否可见) vis1 = obj['vis1'] if 'vis1' in obj else None vis2 = obj['vis2'] if 'vis2' in obj else None vis3 = obj['vis3'] if 'vis3' in obj else None # 更新字段 attspeed = obj['attspeed'] if 'attspeed' in obj else None mag = obj['mag'] if 'mag' in obj else None attpen = obj['attpen'] if 'attpen' in obj else None magpen = obj['magpen'] if 'magpen' in obj else None attpenrate = obj['attpenrate'] if 'attpenrate' in obj else None magpenrate = obj['magpenrate'] if 'magpenrate' in obj else None movelock = obj['movelock'] if 'movelock' in obj else None equips = [] if 'equip0' in obj: equips.append(EquipStateInfo.decode(obj['equip0'], 'equip0')) if 'equip1' in obj: equips.append(EquipStateInfo.decode(obj['equip1'], 'equip1')) if 'equip2' in obj: equips.append(EquipStateInfo.decode(obj['equip2'], 'equip2')) if 'equip3' in obj: equips.append(EquipStateInfo.decode(obj['equip3'], 'equip3')) if 'equip4' in obj: equips.append(EquipStateInfo.decode(obj['equip4'], 'equip4')) if 'equip5' in obj: equips.append(EquipStateInfo.decode(obj['equip5'], 'equip5')) if 'equip6' in obj: equips.append(EquipStateInfo.decode(obj['equip6'], 'equip6')) if 'equip7' in obj: equips.append(EquipStateInfo.decode(obj['equip7'], 'equip7')) buffs = obj['buff'] if 'buff' in obj else [] skills = [] skill_info = HeroStateInfo.decode_add_skill(obj, 'Skill0') if skill_info is not None: skills.append(skill_info) skill_info = HeroStateInfo.decode_add_skill(obj, 'Skill1') if skill_info is not None: skills.append(skill_info) skill_info = HeroStateInfo.decode_add_skill(obj, 'Skill2') if skill_info is not None: skills.append(skill_info) skill_info = HeroStateInfo.decode_add_skill(obj, 'Skill3') if skill_info is not None: skills.append(skill_info) skill_info = HeroStateInfo.decode_add_skill(obj, 'Skill4') if skill_info is not None: skills.append(skill_info) skill_info = HeroStateInfo.decode_add_skill(obj, 'Skill5') if skill_info is not None: skills.append(skill_info) skill_info = HeroStateInfo.decode_add_skill(obj, 'Skill6') if skill_info is not None: skills.append(skill_info) skill_info = HeroStateInfo.decode_add_skill(obj, 'Skill7') if skill_info is not None: skills.append(skill_info) skill_info = HeroStateInfo.decode_add_skill(obj, 'Skill8') if skill_info is not None: skills.append(skill_info) # 根据其实位置来决定英雄阵营,注意,这里的判断只有在第一帧时候是合理的,后续的其实应该根据merge来判断 # 上路是team0,下路team1 team = obj['team'] if 'team' in obj else (None if pos is None else (0 if pos.x < 0 else 1)) return HeroStateInfo(hero_name, state, cfg_id, pos, fwd, hp, maxhp, mp, maxmp, speed, att, gold, hprec, equips, buffs, skills, vis1, vis2, vis3, attspeed, mag, attpen, magpen, attpenrate, magpenrate, movelock, team)
def decode(obj): atker = obj['atker'] defer = obj['defer'] if 'defer' in obj else None tgtpos = PosStateInfo.decode(obj['tgtpos']) if 'tgtpos' in obj else None skill = obj['skill'] return AttackStateInfo(atker, defer, tgtpos, skill)