def add(self, **kwargs): from core.character import Char from core.hero import save_hero, HeroSoul, FakeSaveHeroResult from core.item import Item 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, ) 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']) # 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 _check_hero_soul(char_id, souls, func_name=""): from core.hero import HeroSoul hs = HeroSoul(char_id) for _id, _amount in souls: if not hs.has_soul(_id, _amount): raise SanguoException(SOUL_NOT_ENOUGH, char_id, func_name, 'Soul {0} Not Enough/Exist.'.format(_id)) yield hs.remove_soul(souls)
def login_notify(char_id): hero_objs = char_heros_obj(char_id) Char(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() hang = Hang(char_id) hang.send_notify() Plunder(char_id).send_notify() p = Prison(char_id) p.send_prisoners_notify() Arena(char_id).send_notify() f = Friend(char_id) f.send_friends_notify() f.send_friends_amount_notify() m = Mail(char_id) m.send_mail_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_remained_times_notify() stage_activity = ActivityStage(char_id) 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() FunctionOpen(char_id).send_notify() Levy(char_id).send_notify() Attachment(char_id).send_notify()
def char_initialize(account_id, server_id, char_id, name): mc = MongoCharacter(id=char_id) mc.account_id = account_id mc.server_id = server_id mc.name = name mc.gold = CHARACTER_INIT['gold'] mc.sycee = CHARACTER_INIT['sycee'] mc.save() from core.item import Item item = Item(char_id) # save equipment for _id, _amount in CHARACTER_INIT['equipment']: for _x in range(_amount): item.equip_add(_id, notify=False) # save gem if CHARACTER_INIT['gem']: item.gem_add(CHARACTER_INIT['gem'], send_notify=False) # save stuff if CHARACTER_INIT['stuff']: item.stuff_add(CHARACTER_INIT['stuff'], send_notify=False) # save hero if CHARACTER_INIT['hero']: save_hero(char_id, CHARACTER_INIT['hero'], add_notify=False) # save souls: if CHARACTER_INIT['souls']: s = HeroSoul(char_id) s.add_soul(CHARACTER_INIT['souls']) # hero in formation! in_formaiton_heros = CHARACTER_INIT['hero_in_formation'] final_in_formation_heros = {} for k, v in in_formaiton_heros.iteritems(): new_ids = [] for _equip_id in v: if not _equip_id: new_ids.append(0) else: new_ids.append(item.equip_add(_equip_id, notify=False)) final_in_formation_heros[k] = new_ids hero_ids = save_hero(char_id, final_in_formation_heros.keys(), add_notify=False).id_range hero_new_id_to_oid_table = dict(zip(hero_ids, final_in_formation_heros.keys())) hero_oid_socket_id_table = {} f = Formation(char_id) for hid in hero_ids: this_oid = hero_new_id_to_oid_table[hid] weapon, armor, jewelry = final_in_formation_heros[this_oid] _sid = f.initialize_socket(hero=hid, weapon=weapon, armor=armor, jewelry=jewelry) hero_oid_socket_id_table[this_oid] = _sid socket_ids = FORMATION_INIT_TABLE[:] for index, oid in enumerate(socket_ids): if oid: socket_ids[index] = hero_oid_socket_id_table[oid] if FORMATION_INIT_OPENED_SOCKETS > len(hero_ids): for i in range(FORMATION_INIT_OPENED_SOCKETS - len(hero_ids)): _sid = f.initialize_socket() for index, sid in enumerate(socket_ids): if sid == 0: socket_ids[index] = _sid break f.save_formation(socket_ids, send_notify=False)
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() 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() if Arena.FUNC_ID not in function_open.mf.freeze: arena = Arena(char_id) arena.send_notify() arena.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_remained_times_notify() stage_activity = ActivityStage(char_id) 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() PurchaseAction(char_id).send_notify() SystemBroadcast(char_id).send_global_broadcast() affairs = Affairs(char_id) affairs.send_city_notify() affairs.send_hang_notify() # mail notify 要放在最后,因为 其他功能初始化时可能会产生登录邮件 Mail(char_id).send_notify()
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 char_initialize(account_id, server_id, char_id, name): mc = MongoCharacter(id=char_id) mc.account_id = account_id mc.server_id = server_id mc.name = name mc.gold = CHARACTER_INIT['gold'] mc.sycee = CHARACTER_INIT['sycee'] mc.save() from core.item import Item item = Item(char_id) # save equipment for _id, _amount in CHARACTER_INIT['equipment']: for _x in range(_amount): item.equip_add(_id, notify=False) # save gem if CHARACTER_INIT['gem']: item.gem_add(CHARACTER_INIT['gem'], send_notify=False) # save stuff if CHARACTER_INIT['stuff']: item.stuff_add(CHARACTER_INIT['stuff'], send_notify=False) # save hero if CHARACTER_INIT['hero']: save_hero(char_id, CHARACTER_INIT['hero'], add_notify=False) # save souls: if CHARACTER_INIT['souls']: s = HeroSoul(char_id) s.add_soul(CHARACTER_INIT['souls']) # hero in formation! in_formaiton_heros = CHARACTER_INIT['hero_in_formation'] final_in_formation_heros = {} for k, v in in_formaiton_heros.iteritems(): new_ids = [] for _equip_id in v: if not _equip_id: new_ids.append(0) else: new_ids.append(item.equip_add(_equip_id, notify=False)) final_in_formation_heros[k] = new_ids hero_ids = save_hero(char_id, final_in_formation_heros.keys(), add_notify=False).id_range hero_new_id_to_oid_table = dict( zip(hero_ids, final_in_formation_heros.keys())) hero_oid_socket_id_table = {} f = Formation(char_id) for hid in hero_ids: this_oid = hero_new_id_to_oid_table[hid] weapon, armor, jewelry = final_in_formation_heros[this_oid] _sid = f.initialize_socket(hero=hid, weapon=weapon, armor=armor, jewelry=jewelry) hero_oid_socket_id_table[this_oid] = _sid socket_ids = FORMATION_INIT_TABLE[:] for index, oid in enumerate(socket_ids): if oid: socket_ids[index] = hero_oid_socket_id_table[oid] if FORMATION_INIT_OPENED_SOCKETS > len(hero_ids): for i in range(FORMATION_INIT_OPENED_SOCKETS - len(hero_ids)): _sid = f.initialize_socket() for index, sid in enumerate(socket_ids): if sid == 0: socket_ids[index] = _sid break f.save_formation(socket_ids, send_notify=False)
def add(self, **kwargs): from core.character import Char from core.hero import save_hero, HeroSoul from core.item import Item 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, ) if data['heros']: heros = [] for _id, _amount in data['heros']: heros.extend([_id] * _amount) sh_res = save_hero(self.char_id, heros) 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']) # 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 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