def evolution(request): req = request._proto char_id = request._char_id h = Horse(char_id) h.evolution(req.horse_id, req.horse_soul_id) return None
def up_horse(self, socket_id, horse_id): # 上马 from core.horse import Horse try: this_socket = self.formation.sockets[str(socket_id)] except KeyError: raise SanguoException(errormsg.FORMATION_NONE_EXIST_SOCKET, self.char_id, "Formation Up Horse", "Socket {0} not exist".format(socket_id)) horse = Horse(self.char_id) if not horse.has_horse(horse_id): raise SanguoException( errormsg.HORSE_NOT_EXIST, self.char_id, "formation Up Horse", "horse, {0} not belong to self".format(horse_id)) changed_socket = [] this_socket.horse = horse_id for k, v in self.formation.sockets.iteritems(): if int(k) == socket_id: continue if v.horse == horse_id: v.horse = 0 changed_socket.append((int(k), v)) break changed_socket.append((socket_id, this_socket)) self.formation.save() for k, v in changed_socket: self.send_socket_changed_notify(k, v)
def strength_confirm(request): req = request._proto char_id = request._char_id h = Horse(char_id) cancel = True if req.tp == 2 else False h.strength_confirm(cancel) return None
def strength(request): req = request._proto char_id = request._char_id h = Horse(char_id) new_horse = h.strength(req.id, req.method) response = HorseStrengthResponse() response.ret = 0 response.new_horse.MergeFrom(new_horse.make_msg()) return pack_msg(response)
def _check_horses(char_id, ids, func_name=""): from core.horse import Horse horse = Horse(char_id) for _id in ids: if not horse.has_horse(_id): raise SanguoException(HORSE_NOT_ENOUGH, char_id, func_name, "horse {0} Not Enough/Exist".format(_id)) yield for _id in ids: horse.remove(_id)
def _add_equip_attrs(self): from core.item import Equipment f = Formation(self.char_id) socket = f.find_socket_by_hero(self.id) if not socket: return # 先把装备数值加到人物上 equipments = [] for x in ['weapon', 'armor', 'jewelry']: equip_id = getattr(socket, x) if equip_id: equip = Equipment(self.char_id, equip_id) self.attack += equip.attack self.defense += equip.defense self.hp += equip.hp equipments.append(equip) # 然后加成人物的专属装备 additions = {} special_equipments = self.model_hero.special_equipments if special_equipments: for equip in equipments: _cls = equip.equip.cls if _cls not in special_equipments: continue _tp = equip.equip.tp additions[_tp] = additions.get(_tp, 0) + special_equipments[_cls] for _tp, _add_percent in additions.items(): if _tp == 1: # attack self.attack *= (1 + _add_percent / 100.0) elif _tp == 2: # defense self.defense *= (1 + _add_percent / 100.0) else: # hp self.hp *= (1 + _add_percent / 100.0) self.hp = int(self.hp) # 最后再把宝石加上 for equip in equipments: for k, v in equip.gem_attributes.iteritems(): value = getattr(self, k) setattr(self, k, value + v) # 马 if socket.horse: horse = Horse(self.char_id).mongo_horse.horses[str(socket.horse)] self.attack += horse.attack self.defense += horse.defense self.hp += horse.hp self.crit += int(HORSE[horse.oid].crit / 10)
def up_horse(self, socket_id, horse_id): # 上马 from core.horse import Horse try: this_socket = self.formation.sockets[str(socket_id)] except KeyError: raise SanguoException( errormsg.FORMATION_NONE_EXIST_SOCKET, self.char_id, "Formation Up Horse", "Socket {0} not exist".format(socket_id) ) horse = Horse(self.char_id) if not horse.has_horse(horse_id): raise SanguoException( errormsg.HORSE_NOT_EXIST, self.char_id, "formation Up Horse", "horse, {0} not belong to self".format(horse_id) ) changed_socket = [] this_socket.horse = horse_id for k, v in self.formation.sockets.iteritems(): if int(k) == socket_id: continue if v.horse == horse_id: v.horse = 0 changed_socket.append((int(k), v)) break changed_socket.append((socket_id, this_socket)) self.formation.save() for k, v in changed_socket: self.send_socket_changed_notify(k, v)
def sell(request): req = request._proto char_id = request._char_id item = Item(char_id) horse = Horse(char_id) # check for ele in req.elements: if ele.tp == 1: print "NOT SUPPORT SELL HERO" continue if ele.tp == 2: print "NOT SUPPORT SELL SOUL" continue if ele.tp == 3: item.equip_check_sell([ele.id]) continue if ele.tp == 4: item.gem_check_sell(ele.id, ele.amount) continue if ele.tp == 5: item.stuff_check_sell(ele.id, ele.amount) continue if ele.tp == 6: horse.check_sell(ele.id) continue # sell for ele in req.elements: if ele.tp == 1: print "NOT SUPPORT SELL HERO" continue if ele.tp == 2: print "NOT SUPPORT SELL SOUL" continue if ele.tp == 3: item.equip_sell([ele.id]) continue if ele.tp == 4: item.gem_sell(ele.id, ele.amount) continue if ele.tp == 5: item.stuff_sell(ele.id, ele.amount) continue if ele.tp == 6: horse.sell(ele.id) continue return None
def add(self, **kwargs): from core.character import Char from core.hero import save_hero, HeroSoul, FakeSaveHeroResult from core.item import Item from core.horse import Horse from core.union.member import Member notify_settings = {} notify_settings['purchase_notify'] = kwargs.get('purchase_notify', True) data = _get_resource_data(**kwargs) purchase_got = kwargs.get('purchase_got', 0) purchase_actual_got = kwargs.get('purchase_actual_got', 0) if data['gold'] or data['sycee'] or data['exp'] or data['official_exp'] or purchase_got: char = Char(self.char_id) char.update(gold=data['gold'], sycee=data['sycee'], exp=data['exp'], official_exp=data['official_exp'], purchase_got=purchase_got, purchase_actual_got=purchase_actual_got, notify_settings=notify_settings ) union_coin = kwargs.get('union_coin', 0) union_contribute_points = kwargs.get('union_contribute_points', 0) if union_coin or union_contribute_points: m = Member(self.char_id) m.add_coin(union_coin, send_notify=False) m.add_contribute_points(union_contribute_points) if data['heros']: heros = [] for _id, _amount in data['heros']: heros.extend([_id] * _amount) sh_res = save_hero(self.char_id, heros) else: sh_res = FakeSaveHeroResult if data['souls']: hs = HeroSoul(self.char_id) hs.add_soul(data['souls']) item = Item(self.char_id) for _id, _level, _amount in data['equipments']: for i in range(_amount): item.equip_add(_id, _level) if data['gems']: item.gem_add(data['gems']) if data['stuffs']: item.stuff_add(data['stuffs']) if data['horses']: horse = Horse(self.char_id) for _id, _amount in data['horses']: for i in range(_amount): horse.add(_id) # normalize the data if data['heros']: data['heros'] = sh_res.actual_heros souls = dict(data['souls']) for _sid, _samount in sh_res.to_souls: souls[_sid] = souls.get(_sid, 0) + _samount data['souls'] = souls.items() data['income'] = 1 data['func_name'] = self.func_name data['des'] = self.des resource_logger(self.char_id, data) data.pop('income') data.pop('func_name') data.pop('des') return data
def login_notify(char_id): message_clean(char_id) function_open = FunctionOpen(char_id) function_open.send_notify() hero_objs = char_heros_obj(char_id) Char(char_id).send_notify() VIP(char_id).send_notify() hero_notify(char_id, hero_objs) Item(char_id).send_notify() f = Formation(char_id) f.send_socket_notify() f.send_formation_notify() Plunder(char_id).send_notify() p = Prison(char_id) p.send_prisoners_notify() a = Arena(char_id) a.send_notify() a.login_process() f = Friend(char_id) f.send_friends_notify() f.send_friends_amount_notify() CheckIn(char_id).send_notify() stage = Stage(char_id) stage.send_already_stage_notify() stage.send_new_stage_notify() stage_elite = EliteStage(char_id) stage_elite.send_notify() stage_elite.send_times_notify() stage_activity = ActivityStage(char_id) stage_activity.check(send_notify=False) stage_activity.send_notify() stage_activity.send_remained_times_notify() HeroPanel(char_id).send_notify() Task(char_id).send_notify() Achievement(char_id).send_notify() HeroSoul(char_id).send_notify() Levy(char_id).send_notify() Attachment(char_id).send_notify() BasePurchaseAction(char_id).send_notify() SystemBroadcast(char_id).send_global_broadcast() ChatMessagePublish(char_id).send_notify() affairs = Affairs(char_id) affairs.send_city_notify() affairs.send_hang_notify() HorseFreeTimesManager(char_id).send_notify() Horse(char_id).send_notify() union.send_notify(char_id) ae = ActivityEntry(char_id, 50006) if ae and ae.is_valid(): ae.enable(ae.get_current_value(char_id)) ActivityStatic(char_id).send_notify() # mail notify 要放在最后,因为 其他功能初始化时可能会产生登录邮件 Mail(char_id).send_notify()
def add(self, **kwargs): from core.character import Char from core.hero import save_hero, HeroSoul, FakeSaveHeroResult from core.item import Item from core.horse import Horse from core.union.member import Member update_settings = {} update_settings['purchase_notify'] = kwargs.get( 'purchase_notify', True) update_settings['as_vip_exp'] = kwargs.get('as_vip_exp', True) data = _get_resource_data(**kwargs) purchase_got = kwargs.get('purchase_got', 0) purchase_actual_got = kwargs.get('purchase_actual_got', 0) if data['gold'] or data['sycee'] or data['exp'] or data[ 'official_exp'] or purchase_got: char = Char(self.char_id) char.update(gold=data['gold'], sycee=data['sycee'], exp=data['exp'], official_exp=data['official_exp'], purchase_got=purchase_got, purchase_actual_got=purchase_actual_got, update_settings=update_settings) union_coin = kwargs.get('union_coin', 0) union_contribute_points = kwargs.get('union_contribute_points', 0) if union_coin or union_contribute_points: m = Member(self.char_id) m.add_coin(union_coin, send_notify=False) m.add_contribute_points(union_contribute_points) if data['heros']: heros = [] for _id, _amount in data['heros']: heros.extend([_id] * _amount) sh_res = save_hero(self.char_id, heros) else: sh_res = FakeSaveHeroResult if data['souls']: hs = HeroSoul(self.char_id) hs.add_soul(data['souls']) item = Item(self.char_id) for _id, _level, _amount in data['equipments']: for i in range(_amount): item.equip_add(_id, _level) if data['gems']: item.gem_add(data['gems']) if data['stuffs']: item.stuff_add(data['stuffs']) if data['horses']: horse = Horse(self.char_id) for _id, _amount in data['horses']: for i in range(_amount): horse.add(_id) # normalize the data if data['heros']: data['heros'] = sh_res.actual_heros souls = dict(data['souls']) for _sid, _samount in sh_res.to_souls: souls[_sid] = souls.get(_sid, 0) + _samount data['souls'] = souls.items() data['income'] = 1 data['func_name'] = self.func_name data['des'] = self.des resource_logger(self.char_id, data) data.pop('income') data.pop('func_name') data.pop('des') return data