def _hero_add(char_id, hero_ids, hero_original_ids, send_notify, **kwargs): if send_notify: heros = [Hero.cache_obj(i) for i in hero_ids] add_hero_notify(char_id, heros) heros_dict = char_heros_dict(char_id) achievement = Achievement(char_id) achievement.trig(1, len(heros_dict), send_notify=send_notify) quality_one_heros_amount = 0 quality_two_heros_amount = 0 quality_three_heros_amount = 0 gender_female_heros_amount = 0 for h in heros_dict.values(): original_hero = HEROS[h.oid] if original_hero.quality == 1: quality_one_heros_amount += 1 if original_hero.quality == 2: quality_two_heros_amount += 1 if original_hero.quality == 3: quality_three_heros_amount += 1 if original_hero.gender == 2: gender_female_heros_amount += 1 achievement.trig(2, quality_one_heros_amount, send_notify=send_notify) achievement.trig(3, quality_two_heros_amount, send_notify=send_notify) achievement.trig(4, quality_three_heros_amount, send_notify=send_notify) achievement.trig(5, gender_female_heros_amount, send_notify=send_notify) ActivityStatic(char_id).trig(2001) ActivityStatic(char_id).trig(8001) ActivityStatic(char_id).trig(30003)
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 step_up(request): char_id = request._char_id heros_dict = char_heros_dict(char_id) req = request._proto _id = req.id if _id not in heros_dict: raise SanguoException( errormsg.HERO_NOT_EXSIT, char_id, "Hero Step Up", "hero {0} not belong to char {1}".format(_id, char_id) ) h = Hero(_id) h.step_up() response = HeroStepUpResponse() response.ret = 0 response.id = _id response.step = h.step response.max_socket_amount = h.max_socket_amount response.current_socket_amount = h.current_socket_amount return pack_msg(response)
def up_hero(self, socket_id, hero_id): # 上人 from core.hero import char_heros_dict try: this_socket = self.formation.sockets[str(socket_id)] except KeyError: raise SanguoException(errormsg.FORMATION_NONE_EXIST_SOCKET, self.char_id, "Formation Up Hero", "Socket {0} not exist".format(socket_id)) char_heros = char_heros_dict(self.char_id) if hero_id not in char_heros: raise SanguoException( errormsg.HERO_NOT_EXSIT, self.char_id, "Formation Up Hero", "Set Socket, Hero {0} not belong to self".format(hero_id)) for k, v in self.formation.sockets.iteritems(): if int(k) == socket_id: continue if not v.hero: continue if v.hero == hero_id: # 同一个武将上到多个socket raise SanguoException( errormsg.FORMATION_SET_SOCKET_HERO_IN_MULTI_SOCKET, self.char_id, "Formation Up Hero", "Set Socket. hero {0} already in socket {1}".format( hero_id, k)) # 同名武将不能重复上阵 if char_heros[v.hero].oid == char_heros[hero_id].oid: raise SanguoException( errormsg.FORMATION_SET_SOCKET_SAME_HERO, self.char_id, "Formation Up Hero", "Set Socket. same hero can not in formation at same time") if not this_socket.hero: # 第一次上人 self._first_up_hero(socket_id, hero_id) else: self._replace_hero(socket_id, hero_id) socket_hero_changed_signal.send( sender=None, char_id=self.char_id, socket_id=socket_id, hero_id=hero_id, )
def in_formation_hero_original_ids(self): from core.hero import char_heros_dict ids = self.in_formation_hero_ids() char_heros = char_heros_dict(self.char_id) res = [] for i in ids: if i == 0: res.append(0) else: res.append(char_heros[i].oid) return res
def get_current_value(self, char_id): from core.hero import char_heros_dict heros = char_heros_dict(char_id) hero_oids = [h.oid for h in heros.values()] condition_ids = self.activity_data.condition_objs[0].condition_ids need_hero_ids = [int(i) for i in condition_ids.split(',')] value = 0 for hid in need_hero_ids: if hid in hero_oids: value += 1 return value
def _char_level_up(char_id, new_level, **kwargs): heros_dict = char_heros_dict(char_id) achievement = Achievement(char_id) achievement.trig(18, new_level) heros = [] for hid in heros_dict.keys(): h = Hero(hid) h.save_cache() heros.append(h) update_hero_notify(char_id, heros) activity_stage = ActivityStage(char_id) activity_stage.check(new_level)
def step_up(request): char_id = request._char_id heros_dict = char_heros_dict(char_id) req = request._proto _id = req.id if _id not in heros_dict: raise SanguoException( errormsg.HERO_NOT_EXSIT, char_id, "Hero Step Up", "hero {0} not belong to char {1}".format(_id, char_id) ) h = Hero(_id) h.step_up() return None
def step_up(request): char_id = request._char_id heros_dict = char_heros_dict(char_id) req = request._proto _id = req.id if _id not in heros_dict: raise SanguoException( errormsg.HERO_NOT_EXSIT, char_id, "Hero Step Up", "hero {0} not belong to char {1}".format(_id, char_id)) h = Hero(_id) h.step_up() response = HeroStepUpResponse() response.ret = 0 response.id = _id response.step = h.step response.max_socket_amount = h.max_socket_amount response.current_socket_amount = h.current_socket_amount return pack_msg(response)
def up_hero(self, socket_id, hero_id): # 上人 from core.hero import char_heros_dict try: this_socket = self.formation.sockets[str(socket_id)] except KeyError: raise SanguoException( errormsg.FORMATION_NONE_EXIST_SOCKET, self.char_id, "Formation Up Hero", "Socket {0} not exist".format(socket_id) ) char_heros = char_heros_dict(self.char_id) if hero_id not in char_heros: raise SanguoException( errormsg.HERO_NOT_EXSIT, self.char_id, "Formation Up Hero", "Set Socket, Hero {0} not belong to self".format(hero_id) ) for k, v in self.formation.sockets.iteritems(): if int(k) == socket_id: continue if not v.hero: continue if v.hero == hero_id: # 同一个武将上到多个socket raise SanguoException( errormsg.FORMATION_SET_SOCKET_HERO_IN_MULTI_SOCKET, self.char_id, "Formation Up Hero", "Set Socket. hero {0} already in socket {1}".format(hero_id, k) ) # 同名武将不能重复上阵 if char_heros[v.hero].oid == char_heros[hero_id].oid: raise SanguoException( errormsg.FORMATION_SET_SOCKET_SAME_HERO, self.char_id, "Formation Up Hero", "Set Socket. same hero can not in formation at same time" ) if not this_socket.hero: # 第一次上人 self._first_up_hero(socket_id, hero_id) else: self._replace_hero(socket_id, hero_id) socket_hero_changed_signal.send( sender=None, char_id=self.char_id, socket_id=socket_id, hero_id=hero_id, )