def purge_soul(self, _id): self.mongo_hs.souls.pop(str(_id)) self.mongo_hs.save() msg = protomsg.RemoveHeroSoulNotify() msg.ids.append(_id) publish_to_char(self.char_id, pack_msg(msg))
def remove_soul(self, souls): remove_souls = [] update_souls = [] for _id, amount in souls: if not self.has_soul(_id, amount): raise SanguoException( errormsg.SOUL_NOT_ENOUGH, self.char_id, "HeroSoul Remove", "HeroSoul {0} not enough/exist, expected amount {1}". format(_id, amount)) for _id, amount in souls: str_id = str(_id) self.mongo_hs.souls[str_id] -= amount if self.mongo_hs.souls[str_id] <= 0: remove_souls.append(_id) self.mongo_hs.souls.pop(str_id) else: update_souls.append((_id, self.mongo_hs.souls[str_id])) self.mongo_hs.save() if remove_souls: msg = protomsg.RemoveHeroSoulNotify() msg.ids.extend(remove_souls) publish_to_char(self.char_id, pack_msg(msg)) if update_souls: msg = protomsg.UpdateHeroSoulNotify() for _id, amount in update_souls: s = msg.herosouls.add() s.id = _id s.amount = amount publish_to_char(self.char_id, pack_msg(msg))