def use_formation(self, fid): if fid != 0: config = ConfigFormation.get(fid) if not config: raise GameException(ConfigErrorMessage.get_error_id("FORMATION_NOT_EXIST")) level = self.doc['levels'].get(str(fid), 0) if level == 0: raise GameException(ConfigErrorMessage.get_error_id("FORMATION_NOT_ACTIVE")) if not self.is_formation_valid(fid): raise GameException(ConfigErrorMessage.get_error_id("FORMATION_CAN_NOT_USE")) updater = {'using': fid} self.doc['using'] = fid # 把格子策略设置为默认值 for k in self.doc['slots']: self.doc['slots'][k]['policy'] = 1 updater['slots.{0}.policy'.format(k)] = 1 self.MONGO_COLLECTION.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': updater} ) self.send_slot_notify(slot_ids=self.doc['slots'].keys()) self.send_formation_notify(formation_ids=[]) # 阵型改变,从而改变天赋 # 所以这里暴力重新加载staffs club = Club(self.server_id, self.char_id, load_staffs=False) club.force_load_staffs(send_notify=True)
def levelup_formation(self, fid): from core.challenge import Challenge config = ConfigFormation.get(fid) if not config: raise GameException(ConfigErrorMessage.get_error_id("FORMATION_NOT_EXIST")) level = self.doc['levels'].get(str(fid), 0) if level == 0: raise GameException(ConfigErrorMessage.get_error_id("FORMATION_NOT_ACTIVE")) if level >= config.max_level: raise GameException(ConfigErrorMessage.get_error_id("FORMATION_REACH_MAX_LEVEL")) Challenge(self.server_id, self.char_id).check_starts(config.levels[level].level_up_need_star) rc = ResourceClassification.classify(config.levels[level].level_up_need_items) rc.check_exist(self.server_id, self.char_id) rc.remove(self.server_id, self.char_id, message="Formation.levelup_formation:{0}".format(fid)) self.doc['levels'][str(fid)] = level + 1 self.MONGO_COLLECTION.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'levels.{0}'.format(fid): level + 1 }} ) self.send_formation_notify(formation_ids=[fid]) if fid == self.doc['using']: # 阵型改变,从而改变天赋 # 所以这里暴力重新加载staffs club = Club(self.server_id, self.char_id, load_staffs=False) club.force_load_staffs(send_notify=True)
def sync_slots(self, slots_data): super(Formation, self).sync_slots(slots_data) self.send_slot_notify(slot_ids=self.doc['slots'].keys()) # 阵型改变,从而改变天赋 # 所以这里暴力重新加载staffs club = Club(self.server_id, self.char_id, load_staffs=False) club.force_load_staffs(send_notify=True)
def set_unit(self, slot_id, unit_id): super(Formation, self).set_unit(slot_id, unit_id) # 检测阵型是否还可用 if self.doc['using'] and not self.is_formation_valid(self.doc['using']): self.use_formation(0) else: self.send_slot_notify(slot_ids=[slot_id]) # NOTE 兵种改变可能会导致牵绊改变,从而改变天赋 # 所以这里暴力重新加载staffs club = Club(self.server_id, self.char_id, load_staffs=False) club.force_load_staffs(send_notify=True)
def set_staff(self, slot_id, staff_id): old_staff_id = super(Formation, self).set_staff(slot_id, staff_id) # 检测阵型是否还可用 if self.doc['using'] and not self.is_formation_valid(self.doc['using']): self.use_formation(0) else: self.send_slot_notify(slot_ids=[slot_id]) # NOTE 阵型改变,重新load staffs # 这里不直接调用 club.force_load_staffs 的 send_notify # 是因为这里 改变的staff 还可能包括下阵的 changed_staff_ids = self.in_formation_staffs().keys() if old_staff_id: changed_staff_ids.append(old_staff_id) club = Club(self.server_id, self.char_id, load_staffs=False) club.force_load_staffs() club.send_notify() StaffManger(self.server_id, self.char_id).send_notify(ids=changed_staff_ids) return old_staff_id
def after_change(self, uid): from core.formation import Formation from core.plunder import Plunder from core.championship import Championship self.load_units() unit = self.get_unit_object(uid) all_units = self.get_units_data() all_units_object = [ self.get_unit_object(k) for k, _ in all_units.iteritems() ] changed_units = {} for u in all_units_object: if u.config.race == unit.config.race: changed_units[u.id] = u self.send_notify_with_unit_objs(changed_units.values()) fm = Formation(self.server_id, self.char_id) _changed = False for k, v in fm.in_formation_staffs().iteritems(): if v['unit_id'] in changed_units: _changed = True break if _changed: club = Club(self.server_id, self.char_id, load_staffs=False) club.force_load_staffs(send_notify=True) _p = Plunder(self.server_id, self.char_id) if _p.find_way_id_by_unit_id(uid): _p.send_formation_notify() _c = Championship(self.server_id, self.char_id) if _c.find_way_id_by_unit_id(uid): _c.send_formation_notify()
def after_change(self, uid): from core.formation import Formation from core.plunder import Plunder from core.championship import Championship self.load_units() unit = self.get_unit_object(uid) all_units = self.get_units_data() all_units_object = [self.get_unit_object(k) for k, _ in all_units.iteritems()] changed_units = {} for u in all_units_object: if u.config.race == unit.config.race: changed_units[u.id] = u self.send_notify_with_unit_objs(changed_units.values()) fm = Formation(self.server_id, self.char_id) _changed = False for k, v in fm.in_formation_staffs().iteritems(): if v['unit_id'] in changed_units: _changed = True break if _changed: club = Club(self.server_id, self.char_id, load_staffs=False) club.force_load_staffs(send_notify=True) _p = Plunder(self.server_id, self.char_id) if _p.find_way_id_by_unit_id(uid): _p.send_formation_notify() _c = Championship(self.server_id, self.char_id) if _c.find_way_id_by_unit_id(uid): _c.send_formation_notify()
def inspire_staff_changed_handler(server_id, char_id, staff_id, **kwargs): club = Club(server_id, char_id, load_staffs=False) club.force_load_staffs(send_notify=True)