def equip_add(self, oid, level=1, notify=True): try: this_equip = EQUIPMENTS[oid] except KeyError: raise SanguoException( errormsg.EQUIPMENT_NOT_EXIST, self.char_id, "Equipment Add", "Equipment {0} NOT exist".format(oid) ) new_id = id_generator('equipment')[0] me = MongoEmbeddedEquipment() me.oid = oid me.level = level me.gems = [0] * this_equip.slots self.item.equipments[str(new_id)] = me self.item.save() if notify: msg = protomsg.AddEquipNotify() msg_equip = msg.equips.add() self._msg_equip(msg_equip, new_id, me, Equipment(self.char_id, new_id, self.item)) publish_to_char(self.char_id, pack_msg(msg)) return new_id
def create(self,name): if len(name) > UNION_NAME_MAX_LENGTH: raise SanguoException( errormsg.UNION_NAME_TOO_LONG, self.char_id, "Union Create", "name too long: {0}".format(name.encode('utf-8')) ) if MongoUnion.objects.filter(name=name).count() > 0: raise SanguoException( errormsg.UNION_NAME_ALREADY_EXIST, self.char_id, "Union Create", "name already exist: {0}".format(name.encode('utf-8')) ) resource = Resource(self.char_id, "Union Create") with resource.check(sycee=-UNION_CREATE_NEEDS_SYCEE): new_id = id_generator('union')[0] mu = MongoUnion(id=new_id) mu.owner = self.char_id mu.name = name mu.bulletin = UNION_DEFAULT_DES mu.level = 1 mu.contribute_points = 0 mu.save() UnionMember(self.char_id).join_union(new_id) Union(self.char_id, new_id).send_notify() UnionBattle(self.char_id).send_notify()
def equip_add(self, oid, level=1, notify=True): try: this_equip = EQUIPMENTS[oid] except KeyError: raise SanguoException(errormsg.EQUIPMENT_NOT_EXIST, self.char_id, "Equipment Add", "Equipment {0} NOT exist".format(oid)) new_id = id_generator('equipment')[0] me = MongoEmbeddedEquipment() me.oid = oid me.level = level me.gems = [0] * this_equip.slots self.item.equipments[str(new_id)] = me self.item.save() if notify: msg = protomsg.AddEquipNotify() msg_equip = msg.equips.add() self._msg_equip(msg_equip, new_id, me, Equipment(self.char_id, new_id, self.item)) publish_to_char(self.char_id, pack_msg(msg)) return new_id
def add(self, oid): assert oid in HORSE embedded_horse = MongoEmbeddedHorse() embedded_horse.oid = oid embedded_horse.attack = 0 embedded_horse.defense = 0 embedded_horse.hp = 0 new_id = id_generator('equipment')[0] self.mongo_horse.horses[str(new_id)] = embedded_horse self.mongo_horse.save() hobj = OneHorse( new_id, embedded_horse.oid, embedded_horse.attack, embedded_horse.defense, embedded_horse.hp ) msg = HorsesAddNotify() msg_h = msg.horses.add() msg_h.MergeFrom(hobj.make_msg()) publish_to_char(self.char_id, pack_msg(msg))
def save_hero(char_id, hero_original_ids, add_notify=True): if not isinstance(hero_original_ids, (list, tuple)): hero_original_ids = [hero_original_ids] char_hero_oids = get_char_hero_oids(char_id) to_soul_hero_ids = [] for h in hero_original_ids[:]: if h in char_hero_oids: to_soul_hero_ids.append(h) hero_original_ids.remove(h) souls = {} if to_soul_hero_ids: for sid in to_soul_hero_ids: this_hero = HEROS[sid] souls[this_hero.id] = souls.get(this_hero.id, 0) + 1 for k in souls.keys(): souls[k] *= external_calculate.Hero.step_up_using_soul_amount( HEROS[k].quality) hs = HeroSoul(char_id) hs.add_soul(souls.items()) hero_to_soul_signal.send( sender=None, char_id=char_id, souls=souls.items(), ) id_range = [] if hero_original_ids: length = len(hero_original_ids) id_range = id_generator('charhero', length) for i, _id in enumerate(id_range): MongoHero(id=_id, char=char_id, oid=hero_original_ids[i], step=HERO_START_STEP, progress=0).save() hero_add_signal.send( sender=None, char_id=char_id, hero_ids=id_range, hero_original_ids=hero_original_ids, send_notify=add_notify, ) res = _SaveHeroResult() res.id_range = id_range res.actual_heros = [(oid, 1) for oid in hero_original_ids] res.to_souls = souls.items() return res
def save_hero(char_id, hero_original_ids, add_notify=True): if not isinstance(hero_original_ids, (list, tuple)): hero_original_ids = [hero_original_ids] char_hero_oids = get_char_hero_oids(char_id) to_soul_hero_ids = [] for h in hero_original_ids[:]: if h in char_hero_oids: to_soul_hero_ids.append(h) hero_original_ids.remove(h) souls = {} if to_soul_hero_ids: for sid in to_soul_hero_ids: this_hero = HEROS[sid] souls[this_hero.id] = souls.get(this_hero.id, 0) + 1 for k in souls.keys(): souls[k] *= external_calculate.Hero.step_up_using_soul_amount(HEROS[k].quality) hs = HeroSoul(char_id) hs.add_soul(souls.items()) hero_to_soul_signal.send( sender=None, char_id=char_id, souls=souls.items(), ) id_range = [] if hero_original_ids: length = len(hero_original_ids) id_range = id_generator('charhero', length) for i, _id in enumerate(id_range): MongoHero(id=_id, char=char_id, oid=hero_original_ids[i], step=HERO_START_STEP, progress=0).save() hero_add_signal.send( sender=None, char_id=char_id, hero_ids=id_range, hero_original_ids=hero_original_ids, send_notify=add_notify, ) res = _SaveHeroResult() res.id_range = id_range res.actual_heros = [(oid, 1) for oid in hero_original_ids] res.to_souls = souls.items() return res
def add(self, oid): assert oid in HORSE embedded_horse = MongoEmbeddedHorse() embedded_horse.oid = oid embedded_horse.attack = 0 embedded_horse.defense = 0 embedded_horse.hp = 0 new_id = id_generator('equipment')[0] self.mongo_horse.horses[str(new_id)] = embedded_horse self.mongo_horse.save() hobj = OneHorse(new_id, embedded_horse.oid, embedded_horse.attack, embedded_horse.defense, embedded_horse.hp) msg = HorsesAddNotify() msg_h = msg.horses.add() msg_h.MergeFrom(hobj.make_msg()) publish_to_char(self.char_id, pack_msg(msg))
def save_hero(char_id, hero_original_ids, add_notify=True): if not isinstance(hero_original_ids, (list, tuple)): hero_original_ids = [hero_original_ids] char_hero_oids = get_char_hero_oids(char_id) to_soul_hero_ids = [] for h in hero_original_ids[:]: if h in char_hero_oids: to_soul_hero_ids.append(h) hero_original_ids.remove(h) souls = {} if to_soul_hero_ids: for sid in to_soul_hero_ids: this_hero = HEROS[sid] souls[this_hero.id] = souls.get(this_hero.id, 0) + 1 for k in souls.keys(): souls[k] *= SAVE_HERO_TO_SOUL_TABLE[ HEROS[k].quality ] hs = HeroSoul(char_id) hs.add_soul(souls.items()) hero_to_soul_signal.send( sender=None, char_id=char_id, souls=souls.items(), ) id_range = [] if hero_original_ids: length = len(hero_original_ids) id_range = id_generator('charhero', length) for i, _id in enumerate(id_range): mh = MongoHero(id=_id) mh.char = char_id mh.oid = hero_original_ids[i] mh.step = HERO_START_STEP mh.progress = 0 wuxing = { str( HEROS[mh.oid].wuxings[0] ): MongoEmbeddedHeroWuxing(level=1, exp=0) } mh.wuxings = wuxing mh.save() hero_add_signal.send( sender=None, char_id=char_id, hero_ids=id_range, hero_original_ids=hero_original_ids, send_notify=add_notify, ) res = _SaveHeroResult() res.id_range = id_range res.actual_heros = [(oid, 1) for oid in hero_original_ids] res.to_souls = souls.items() return res
def save_hero(char_id, hero_original_ids, add_notify=True): if not isinstance(hero_original_ids, (list, tuple)): hero_original_ids = [hero_original_ids] char_hero_oids = get_char_hero_oids(char_id) to_soul_hero_ids = [] for h in hero_original_ids[:]: if h in char_hero_oids: to_soul_hero_ids.append(h) hero_original_ids.remove(h) souls = {} if to_soul_hero_ids: for sid in to_soul_hero_ids: this_hero = HEROS[sid] souls[this_hero.id] = souls.get(this_hero.id, 0) + 1 for k in souls.keys(): souls[k] *= SAVE_HERO_TO_SOUL_TABLE[HEROS[k].quality] hs = HeroSoul(char_id) hs.add_soul(souls.items()) hero_to_soul_signal.send( sender=None, char_id=char_id, souls=souls.items(), ) id_range = [] if hero_original_ids: length = len(hero_original_ids) id_range = id_generator('charhero', length) for i, _id in enumerate(id_range): mh = MongoHero(id=_id) mh.char = char_id mh.oid = hero_original_ids[i] mh.step = HERO_START_STEP mh.progress = 0 wuxing = { str(HEROS[mh.oid].wuxings[0]): MongoEmbeddedHeroWuxing(level=1, exp=0) } mh.wuxings = wuxing mh.save() hero_add_signal.send( sender=None, char_id=char_id, hero_ids=id_range, hero_original_ids=hero_original_ids, send_notify=add_notify, ) res = _SaveHeroResult() res.id_range = id_range res.actual_heros = [(oid, 1) for oid in hero_original_ids] res.to_souls = souls.items() return res