def create_character_infomation_message(char_id): from core.character import Char from core.formation import Formation from core.hero import char_heros_dict msg = CharacterInfomation() char = Char(char_id) heros = char_heros_dict(char_id) f = Formation(char_id) msg.id = char.mc.id msg.name = char.mc.name msg.level = char.mc.level msg.vip = char.mc.vip msg.power = char.power msg.leader = f.get_leader_oid() for hid in f.in_formation_hero_ids(): msg_hero = msg.formation.add() if hid == 0: msg_hero.id = 0 msg_hero.oid = 0 msg_hero.step = 0 else: h = heros[hid] msg_hero.id = h.id msg_hero.oid = h.oid msg_hero.step = h.step return msg
def break_hero(char_id, _id): # 主动将武将转为卡魂 try: h = char_heros_dict(char_id)[_id] except KeyError: raise SanguoException( errormsg.HERO_NOT_EXSIT, char_id, "Hero Break", "hero {0} not exist".format(_id) ) formation = Formation(char_id) if _id in formation.in_formation_hero_ids(): raise SanguoException( errormsg.HERO_CANNOT_BREAK_IN_FORMATION, char_id, "Hero Break", "hero {0} in formation, cannot break".format(_id) ) oid = h.oid quality = HEROS[oid].quality souls_amount = SAVE_HERO_TO_SOUL_TABLE[quality] MongoHero.objects.get(id=_id).delete() hero_del_signal.send( sender=None, char_id=char_id, hero_id=_id, hero_oid=oid ) HeroSoul(char_id).add_soul([(oid, souls_amount)])
def break_hero(char_id, _id): # 主动将武将转为卡魂 try: h = char_heros_dict(char_id)[_id] except KeyError: raise SanguoException(errormsg.HERO_NOT_EXSIT, char_id, "Hero Break", "hero {0} not exist".format(_id)) formation = Formation(char_id) if _id in formation.in_formation_hero_ids(): raise SanguoException( errormsg.HERO_CANNOT_BREAK_IN_FORMATION, char_id, "Hero Break", "hero {0} in formation, cannot break".format(_id)) oid = h.oid quality = HEROS[oid].quality souls_amount = SAVE_HERO_TO_SOUL_TABLE[quality] MongoHero.objects.get(id=_id).delete() hero_del_signal.send(sender=None, char_id=char_id, hero_id=_id, hero_oid=oid) HeroSoul(char_id).add_soul([(oid, souls_amount)])
def power(self): f = Formation(self.id) hero_ids = f.in_formation_hero_ids() p = 0 for hid in hero_ids: if hid == 0: continue h = Hero.cache_obj(hid) p += h.power return p
def __init__(self, char_id, city_id): from core.affairs import Affairs from core.battle.hero import BattleHero self.city_id = city_id if char_id: char = Char(char_id) self.char_id = char_id self.name = char.mc.name self.level = char.mc.level self.power = char.power self.leader = char.leader_oid f = Formation(char_id) self.formation = f.in_formation_hero_ids() self.hero_original_ids = f.in_formation_hero_original_ids() self.gold = Affairs(self.char_id).get_drop()['gold'] self.msg_char_information = create_character_infomation_message( self.char_id).SerializeToString() battle_heros = [] for hid in self.formation: if hid == 0: battle_heros.append(None) else: battle_heros.append(BattleHero(hid)) self.battle_heros = base64.b64encode(dill.dumps(battle_heros)) else: self.char_id = 0 self.name = "" self.level = 0 self.power = 0 self.leader = 0 self.formation = [] self.hero_original_ids = [] self.gold = 0 self.msg_char_information = "" self.battle_heros = base64.b64encode(dill.dumps([None] * 9))
def __init__(self, char_id, city_id): from core.affairs import Affairs from core.battle.hero import BattleHero self.city_id = city_id if char_id: char = Char(char_id) self.char_id = char_id self.name = char.mc.name self.level = char.mc.level self.power = char.power self.leader = char.leader_oid f = Formation(char_id) self.formation = f.in_formation_hero_ids() self.hero_original_ids = f.in_formation_hero_original_ids() self.gold = Affairs(self.char_id).get_drop()['gold'] self.msg_char_information = create_character_infomation_message(self.char_id).SerializeToString() battle_heros = [] for hid in self.formation: if hid == 0: battle_heros.append(None) else: battle_heros.append(BattleHero(hid)) self.battle_heros = base64.b64encode(dill.dumps(battle_heros)) else: self.char_id = 0 self.name = "" self.level = 0 self.power = 0 self.leader = 0 self.formation = [] self.hero_original_ids = [] self.gold = 0 self.msg_char_information = "" self.battle_heros = base64.b64encode(dill.dumps([None] * 9))
def __init__(self, char_id, city_id): self.city_id = city_id if char_id: char = Char(char_id) self.char_id = char_id self.name = char.mc.name self.level = char.mc.level self.power = char.power self.leader = char.leader_oid f = Formation(char_id) self.formation = f.in_formation_hero_ids() self.hero_original_ids = f.in_formation_hero_original_ids() else: self.char_id = 0 self.name = "" self.level = 0 self.power = 0 self.leader = 0 self.formation = [] self.hero_original_ids = []
def _msg_friend(self, msg, fid, status): char_f = Char(fid) cache_f = char_f.cacheobj msg.id = fid msg.name = cache_f.name msg.level = cache_f.level msg.official = cache_f.official if status == FRIEND_OK or status == FRIEND_NOT: msg.power = char_f.power msg.status = status f = Formation(fid) in_formation_hero_ids = [h for h in f.in_formation_hero_ids() if h] hero_list = [(Hero.cache_obj(hid).power, hid) for hid in in_formation_hero_ids] hero_list.sort(key=lambda item: -item[0]) leader_oid = Hero.cache_obj(hero_list[0][1]).oid if status == FRIEND_OK: f = Formation(fid) msg.formation.extend(f.in_formation_hero_original_ids()) msg.leader = leader_oid
def _msg_friend(self, msg, fid, status): char_f = Char(fid) cache_f = char_f.cacheobj msg.id = fid msg.name = cache_f.name msg.level = cache_f.level msg.official = cache_f.official if status == FRIEND_OK or status == FRIEND_NOT: msg.power = char_f.power msg.status = status f = Formation(fid) in_formation_hero_ids = [h for h in f.in_formation_hero_ids() if h] hero_list = [(Hero.cache_obj(hid).power, hid) for hid in in_formation_hero_ids] hero_list.sort(key=lambda item: -item[0]) leader_oid = Hero.cache_obj(hero_list[0][1]).oid if status == FRIEND_OK: f = Formation(fid) msg.formation.extend(f.in_formation_hero_original_ids()) msg.leader = leader_oid if status == FRIEND_OK and fid not in self.mf.plunder_gives: msg.can_give_plunder_times = True else: msg.can_give_plunder_times = False if fid in self.mf.plunder_senders: msg.got_plunder_times_status = MsgFriend.CAN_GET elif fid in self.mf.plunder_gots: msg.got_plunder_times_status = MsgFriend.ALREADY_GET else: msg.got_plunder_times_status = MsgFriend.CAN_NOT_GET