def approval(self, msg_id): mark = WinningChatApprovalMark(self.server_id, self.char_id, msg_id) if mark.is_marked(): raise GameException(ConfigErrorMessage.get_error_id("APPROVAL_ONLY_ONCE")) index = -1 for _index, message in enumerate(self.doc['value']): if message['msg_id'] == msg_id: index = _index break if index == -1: raise GameException(ConfigErrorMessage.get_error_id("INVALID_OPERATE")) try: with self.LOCK(self.server_id, self.char_id).lock(3, 3): self.doc['value'][index]['approval'] += 1 self.doc['value'][index]['last_update_at'] += arrow.utcnow().timestamp MongoCommon.db(self.server_id).update_one( {'_id': self.get_id()}, {'$set': { 'value': self.doc['value'] }} ) _data = self.make_notify_data(message=self.doc['value'][index]) self.broadcast(_data) except LockTimeOut: raise GameException(ConfigErrorMessage.get_error_id("SERVER_BUSY")) mark.mark()
def start(self, dungeon_id, formation_slots=None): grade_conf = ConfigDungeonGrade.get(dungeon_id) if not grade_conf: raise GameException( ConfigErrorMessage.get_error_id("DUNGEON_NOT_EXIST")) map_name = ConfigDungeon.get(grade_conf.belong).map_name club_level = get_club_property(self.server_id, self.char_id, 'level') if grade_conf.need_level > club_level: raise GameException( ConfigErrorMessage.get_error_id( "DUNGEON_CLUB_LEVEL_NOT_ENOUGH")) f = Formation(self.server_id, self.char_id) if formation_slots: f.sync_slots(formation_slots) Energy(self.server_id, self.char_id).check(ConfigDungeon.get(grade_conf.belong).cost) ri = TimesInfo(self.server_id, self.char_id, grade_conf.belong) if not ri.remained_match_times: # 购买 self.buy_times(grade_conf.belong) club_one = Club(self.server_id, self.char_id) club_two = ConfigNPCFormation.get(grade_conf.npc) msg = ClubMatch(club_one, club_two, 6, f.get_skill_sequence(), {}).start() msg.key = str(dungeon_id) msg.map_name = map_name return msg
def get_honor_reward(self, honor_id): config = ConfigArenaHonorReward.get(honor_id) if not config: raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE")) if honor_id > self.get_honor_points(): raise GameException( ConfigErrorMessage.get_error_id( "ARENA_HONOR_REWARD_POINT_NOT_ENOUGH")) reward_info = self.get_today_honor_reward_info() if honor_id in reward_info: raise GameException( ConfigErrorMessage.get_error_id( "ARENA_HONOR_REWARD_ALREADY_GOT")) resource_classified = ResourceClassification.classify(config.reward) resource_classified.add( self.server_id, self.char_id, message="Arena.get_honor_reward:{0}".format(honor_id)) today_key = str(get_start_time_of_today().timestamp) MongoArena.db(self.server_id).update_one( {'_id': str(self.char_id)}, {'$push': { 'honor_rewards.{0}'.format(today_key): honor_id }}) reward_info.append(honor_id) self.send_honor_notify(reward_info=reward_info) return resource_classified
def plunder_report(self, key, win): try: way = int(key) assert way in [1, 2, 3] except: raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE")) way_index = way - 1 result = 1 if win else 2 target_id = self.doc['matching']['id'] if not target_id: raise GameException( ConfigErrorMessage.get_error_id("INVALID_OPERATE")) updater = {} self.doc['matching']['result'][way_index] = result updater['matching.result.{0}'.format(way_index)] = result if win: daily_key, info = self.get_daily_reward_info() win_ways = info.get('win_ways', 0) info['win_ways'] = win_ways + 1 self.doc['daily_reward'] = {daily_key: info} updater['daily_reward'] = {daily_key: info} MongoPlunder.db(self.server_id).update_one({'_id': self.char_id}, {'$set': updater}) self.send_plunder_daily_reward_notify() self.send_result_notify() WinningPlunder(self.server_id, self.char_id).set(win)
def buy_reward(self, vip_level): self.check(vip_level) config = ConfigVIP.get(vip_level) if not config: raise GameException( ConfigErrorMessage.get_error_id("INVALID_OPERATE")) if vip_level in self.doc['rewards']: raise GameException( ConfigErrorMessage.get_error_id("VIP_ALREADY_BUY_REWARD")) needs = [(money_text_to_item_id('diamond'), config.diamond_now)] rc = ResourceClassification.classify(needs) rc.check_exist(self.server_id, self.char_id) rc.remove(self.server_id, self.char_id, message="VIP.buy_reward:{0}".format(vip_level)) got = [(config.item_id, 1)] rc = ResourceClassification.classify(got) rc.add(self.server_id, self.char_id, message="VIP.buy_reward:{0}".format(vip_level)) self.doc['rewards'].append(vip_level) MongoVIP.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'rewards': self.doc['rewards'] }}) self.send_notify() return rc
def accept(self, char_id, verify=True): char_id = int(char_id) key = 'friends.{0}'.format(char_id) if verify: doc = MongoFriend.db(self.server_id).find_one( {'_id': self.char_id}, {key: 1}) status = doc['friends'].get(str(char_id), FRIEND_STATUS_NOT) if status == FRIEND_STATUS_NOT or status == FRIEND_STATUS_PEER_CONFIRM: raise GameException( ConfigErrorMessage.get_error_id("FRIEND_ACCEPT_ERROR")) if status == FRIEND_STATUS_OK: raise GameException( ConfigErrorMessage.get_error_id( "FRIEND_ALREADY_IS_FRIEND")) MongoFriend.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { key: FRIEND_STATUS_OK }}) self.send_notify(ids=[char_id]) FriendManager(self.server_id, char_id).someone_accept_me(self.char_id) friend_ok_signal.send(sender=None, server_id=self.server_id, char_id=self.char_id, friend_id=char_id)
def get_reward(self, task_id): config = ConfigTaskDaily.get(task_id) if not config: raise GameException( ConfigErrorMessage.get_error_id("INVALID_OPERATE")) _, status = self.get_task_status(task_id) if status == TASK_DONE: raise GameException( ConfigErrorMessage.get_error_id("TASK_GET_REWARD_ALREADY_GOT")) if status != TASK_FINISH: raise GameException( ConfigErrorMessage.get_error_id("TASK_GET_REWARD_NOT_FINISH")) self.doc['tasks'].remove(task_id) self.doc['done'].append(task_id) resource_classified = ResourceClassification.classify(config.rewards) resource_classified.add( self.server_id, self.char_id, message="TaskDaily.get_reward:{0}".format(task_id)) MongoTaskDaily.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'tasks': self.doc['tasks'], 'done': self.doc['done'], }}) self.send_notify(task_ids=[task_id]) return resource_classified
def add(self, name): doc = MongoCharacter.db(self.server_id).find_one({'name': name}, {'_id': 1}) if not doc: raise GameException( ConfigErrorMessage.get_error_id("CHAR_NOT_EXIST")) char_id = doc['_id'] key = 'friends.{0}'.format(char_id) doc = MongoFriend.db(self.server_id).find_one({'_id': self.char_id}, {key: 1}) status = doc['friends'].get(str(char_id), FRIEND_STATUS_NOT) if status == FRIEND_STATUS_OK: raise GameException( ConfigErrorMessage.get_error_id("FRIEND_ALREADY_IS_FRIEND")) if status == FRIEND_STATUS_PEER_CONFIRM: raise GameException( ConfigErrorMessage.get_error_id( "FRIEND_ADD_REQUEST_ALREADY_SENT")) if status == FRIEND_STATUS_SELF_CONFIRM: # 要添加的是,需要自己确认的,也就是对方也想添加我。那么就直接成为好友 self.accept(char_id, verify=False) return MongoFriend.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { key: FRIEND_STATUS_PEER_CONFIRM }}) self.send_notify(ids=[char_id]) FriendManager(self.server_id, char_id).someone_add_me(self.char_id)
def daily_buy(self): config = ConfigActivityDailyBuy.get(self.create_day) if not config: raise GameException( ConfigErrorMessage.get_error_id("INVALID_OPERATE")) if self.create_day in self.doc['daily_buy']: raise GameException( ConfigErrorMessage.get_error_id( "ACTIVITY_DAILY_BUY_HAS_BOUGHT")) cost = [ (money_text_to_item_id('diamond'), config.diamond_now), ] rc = ResourceClassification.classify(cost) rc.check_exist(self.server_id, self.char_id) rc.remove(self.server_id, self.char_id, message="ActivityNewPlayer.daily_buy") rc = ResourceClassification.classify(config.items) rc.add(self.server_id, self.char_id, message="ActivityNewPlayer.daily_buy") self.doc['daily_buy'].append(self.create_day) MongoActivityNewPlayer.db(self.server_id).update_one( {'_id': self.char_id}, {'$push': { 'daily_buy': self.create_day }}) self.send_daily_buy_notify() return rc
def verify_stars_cloud(platform, uid, param): AppId = settings.THIRD_PROVIDER['stars-cloud']['appid'] pmSecret = settings.THIRD_PROVIDER['stars-cloud']['pmsecret'] if platform == 'uc': try: ixToken, ixTime, ixSign = json.loads(param) except ValueError: raise GameException( ConfigErrorMessage.get_error_id("ACCOUNT_LOGIN_FAILURE")) text = "{0}{1}{2}{3}{4}{5}".format(AppId, platform, uid, ixToken, ixTime, pmSecret) result = hashlib.md5(text).hexdigest() if result != ixSign: raise GameException( ConfigErrorMessage.get_error_id("ACCOUNT_LOGIN_FAILURE")) return if platform == 'SNOWFISH': return raise GameException( ConfigErrorMessage.get_error_id("UNSUPPORTED_PLATFORM"))
def turntable_pick(self, star): if star not in [3, 6, 9]: raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE")) if star > self.doc['current_star']: raise GameException(ConfigErrorMessage.get_error_id("TOWER_STAR_NOT_ENOUGH")) turntable = self.doc.get('turntable', {}) if not turntable: raise GameException(ConfigErrorMessage.get_error_id("INVALID_OPERATE")) got = random.choice(turntable[str(star)]) index = turntable['all_list'].index(got) self.doc['current_star'] -= star self.doc['talents'].append(got) MongoTower.db(self.server_id).update_one( {'_id': self.char_id}, { '$set': { 'current_star': self.doc['current_star'], 'talents': self.doc['talents'], 'turntable': {}, } } ) self.send_notify(act=ACT_UPDATE, levels=[]) return index
def help(self, friend_id, building_id): friend_id = int(friend_id) if not FriendManager(self.server_id, self.char_id).check_friend_exist(friend_id): raise GameException( ConfigErrorMessage.get_error_id("FRIEND_NOT_OK")) if not self.get_remained_help_times(): raise GameException( ConfigErrorMessage.get_error_id( "TERRITORY_NO_HELP_FRIEND_TIMES")) if not TerritoryFriend(self.server_id, friend_id).get_remained_got_help_times(): raise GameException( ConfigErrorMessage.get_error_id("TERRITORY_NO_GOT_HELP_TIMES")) t = Territory(self.server_id, friend_id) building = t.get_building_object(building_id, slots_ids=[]) event_id = building.event_id if not event_id: raise GameException( ConfigErrorMessage.get_error_id("TERRITORY_BUILDING_NO_EVENT")) MongoTerritory.db(self.server_id).update_one( {'_id': friend_id}, {'$set': { 'buildings.{0}.event_id'.format(building_id): 0 }}) config = ConfigTerritoryEvent.get(event_id) if not config.npc: resource_classified = ResourceClassification.classify( config.reward_win) resource_classified.add(self.server_id, self.char_id, message="TerritoryFriend.help") # NOTE: 战斗要等到结算的时候再记录次数 ValueLogTerritoryHelpFriendTimes(self.server_id, self.char_id).record() self.send_remained_times_notify() Territory(self.server_id, friend_id).got_help(self.char_id, building_id, config.target_exp) return None, resource_classified npc_club = ConfigNPCFormation.get(config.npc) my_club = Club(self.server_id, self.char_id) f = Formation(self.server_id, self.char_id) match = ClubMatch(my_club, npc_club, 6, f.get_skill_sequence(), {}) msg = match.start() msg.key = "{0}:{1}:{2}".format(friend_id, building_id, event_id) msg.map_name = GlobalConfig.value_string("MATCH_MAP_TERRITORY_FRIEND") return msg, None
def level_reward_get(self, _id): config = ConfigWelfareLevelReward.get(_id) if not config: raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE")) status = self.get_level_reward_item_status(_id) if status == WELFARE_CAN_NOT: raise GameException(ConfigErrorMessage.get_error_id("WELFARE_LEVEL_REWARD_CAN_NOT")) if status == WELFARE_HAS_GOT: raise GameException(ConfigErrorMessage.get_error_id("WELFARE_LEVEL_REWARD_HAS_GOT")) self.doc['level_reward'].append(_id) rc = ResourceClassification.classify(config.reward) rc.add(self.server_id, self.char_id, message="Welfare.level_reward_get:{0}".format(_id)) MongoWelfare.db(self.server_id).update_one( {'_id': self.char_id}, {'$push': { 'level_reward': _id }} ) self.send_level_reward_notify(_id) return rc
def apply_in(self): now = arrow.utcnow().to(settings.TIME_ZONE) if now.weekday() not in APPLY_WEEKDAY: raise GameException( ConfigErrorMessage.get_error_id("CHAMPIONSHIP_APPLY_NOT_OPEN")) range_start = make_time_of_today(APPLY_TIME_RANGE[0][0], APPLY_TIME_RANGE[0][1]) range_end = make_time_of_today(APPLY_TIME_RANGE[1][0], APPLY_TIME_RANGE[1][1]) if now < range_start or now >= range_end: raise GameException( ConfigErrorMessage.get_error_id("CHAMPIONSHIP_APPLY_NOT_OPEN")) if self.is_applied(): raise GameException( ConfigErrorMessage.get_error_id( "CHAMPIONSHIP_ALREADY_APPLIED")) self.doc['applied'] = True MongoChampionship.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'applied': True }}) self.send_basic_notify()
def agree(self, char_id): if char_id not in self.union_doc['apply_list']: self.send_my_check_notify() raise GameException( ConfigErrorMessage.get_error_id( "UNION_TARGET_ALREADY_JOIN_A_UNION")) self.union_doc['apply_list'].remove(char_id) MongoUnion.db(self.server_id).update_many( {'apply_list': char_id}, {'$pull': { 'apply_list': char_id }}) self.send_my_check_notify() if self.get_members_amount() >= ConfigUnionLevel.get( self.union_doc['level']).members_limit: raise GameException( ConfigErrorMessage.get_error_id("UNION_MEMBERS_REACH_LIMIT")) u = Union(self.server_id, char_id) if isinstance(u, UnionJoined): raise GameException( ConfigErrorMessage.get_error_id( "UNION_TARGET_ALREADY_JOIN_A_UNION")) MongoUnionMember.db(self.server_id).update_one({'_id': char_id}, { '$set': { 'joined': self.union_doc['_id'], 'joined_at': arrow.utcnow().timestamp } }) self.send_notify() Union(self.server_id, char_id).send_all_notify()
def new_player_get(self, _id): config = ConfigWelfareNewPlayer.get(_id) if not config: raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE")) status = self.get_new_player_item_status(_id) if status == WELFARE_CAN_NOT: raise GameException(ConfigErrorMessage.get_error_id("WELFARE_NEW_PLAYER_CAN_NOT")) if status == WELFARE_HAS_GOT: raise GameException(ConfigErrorMessage.get_error_id("WELFARE_NEW_PLAYER_HAS_GOT")) self.doc['new_player'].append(_id) rc = ResourceClassification.classify(config.reward) rc.add(self.server_id, self.char_id, message="Welfare.new_player_get:{0}".format(_id)) MongoWelfare.db(self.server_id).update_one( {'_id': self.char_id}, {'$push': { 'new_player': _id }} ) self.send_new_player_notify(_id) return rc
def sign_in(self, _id): """ :rtype: ResourceClassification """ if self.get_signed_id(): raise GameException( ConfigErrorMessage.get_error_id("UNION_ALREADY_SIGNED")) config = ConfigUnionSignin.get(_id) if not config: raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE")) if config.vip: VIP(self.server_id, self.char_id).check(config.vip) rc = ResourceClassification.classify(config.cost) rc.check_exist(self.server_id, self.char_id) rc.remove(self.server_id, self.char_id, message="Union.sign_in") self.add_contribution(config.contribution, send_notify=False) rc = ResourceClassification.classify(config.rewards) rc.add(self.server_id, self.char_id, message="Union.sign_in") ValueLogUnionSignInTimes(self.server_id, self.char_id).record(sub_id=_id) self.send_notify() return rc
def skill_level_up(self, skill_id): config = ConfigUnionSkill.get(skill_id) if not config: raise GameException( ConfigErrorMessage.get_error_id("UNION_SKILL_NOT_EXIST")) current_level = self.member_doc['skills'].get(str(skill_id), 0) if current_level >= config.max_level: raise GameException( ConfigErrorMessage.get_error_id( "UNION_SKILL_REACH_SELF_MAX_LEVEL")) if current_level >= self.union_doc['level'] * 3: raise GameException( ConfigErrorMessage.get_error_id( "UNION_SKILL_LEVEL_LIMITED_BY_UNION_LEVEL")) rc = ResourceClassification.classify(config.levels[current_level].cost) rc.check_exist(self.server_id, self.char_id) rc.remove(self.server_id, self.char_id, message="UnionJoined.skill_level_up") self.member_doc['skills'][str(skill_id)] = current_level + 1 MongoUnionMember.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'skills.{0}'.format(skill_id): current_level + 1 }}) Club(self.server_id, self.char_id, load_staffs=False).force_load_staffs(send_notify=True) self.send_skill_notify(skill_id=skill_id)
def apply_union(self, union_id): kick_flag = self.member_doc.get('kick_flag', False) quit_flag = self.member_doc.get('quit_flag', False) if kick_flag or quit_flag: raise GameException( ConfigErrorMessage.get_error_id( "UNION_CANNOT_APPLY_QUIT_OR_KICK")) doc = MongoUnion.db(self.server_id).find_one({'_id': union_id}) if not doc: raise GameException( ConfigErrorMessage.get_error_id("UNION_NOT_EXIST")) config = ConfigUnionLevel.get(doc['level']) if MongoUnionMember.db(self.server_id).find({ 'joined': union_id }).count() >= config.members_limit: raise GameException( ConfigErrorMessage.get_error_id( "UNION_CANNOT_APPLY_MEMBERS_LIMIT")) MongoUnion.db(self.server_id).update_one( {'_id': union_id}, {'$addToSet': { 'apply_list': self.char_id }}) self.send_my_applied_notify() u = Union(self.server_id, doc['owner']) u.send_my_check_notify()
def step_up(self): if self.step >= self.config.max_step: raise GameException( ConfigErrorMessage.get_error_id("STAFF_ALREADY_MAX_STEP")) if self.level < self.config.steps[self.step].level_limit: raise GameException( ConfigErrorMessage.get_error_id("STAFF_LEVEL_NOT_ENOUGH")) using_items = self.config.steps[self.step].update_item_need resource_classified = ResourceClassification.classify(using_items) resource_classified.check_exist(self.server_id, self.char_id) resource_classified.remove(self.server_id, self.char_id, message="Staff.step_up:{0}".format( self.oid)) self.step += 1 MongoStaff.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'staffs.{0}.step'.format(self.id): self.step }}) # NOTE 升阶可能会导致 天赋技能 改变 # 不仅会影响自己,可能(如果在阵型中)也会影响到其他选手 # 所以这里不自己 calculate, 而是先让 club 重新 load staffs staff_step_up_signal.send(sender=None, server_id=self.server_id, char_id=self.char_id, staff_id=self.id, staff_oid=self.oid, new_step=self.step)
def training_get_reward(self, building_id, slot_id): building = self.get_building_object(building_id, slots_ids=[slot_id]) try: slot = building.slots[slot_id] except KeyError: raise GameException( ConfigErrorMessage.get_error_id("INVALID_OPERATE")) if not slot.open: raise GameException( ConfigErrorMessage.get_error_id("TERRITORY_SLOT_LOCK")) if not slot.finished: raise GameException( ConfigErrorMessage.get_error_id("TERRITORY_SLOT_NOT_FINISH")) reward = slot.reward level_up = building.add_exp(reward['building_exp']) building.add_product(reward['product_amount']) empty_slot_doc = MongoTerritory.document_slot() self.doc['buildings'][str(building_id)]['level'] = building.level self.doc['buildings'][str(building_id)]['exp'] = building.exp self.doc['buildings'][str( building_id)]['product_amount'] = building.product_amount self.doc['buildings'][str(building_id)]['slots'][str( slot_id)] = empty_slot_doc MongoTerritory.db(self.server_id).update_one({'_id': self.char_id}, { '$set': { 'buildings.{0}.level'.format(building_id): building.level, 'buildings.{0}.exp'.format(building_id): building.exp, 'buildings.{0}.product_amount'.format(building_id): building.product_amount, 'buildings.{0}.slots.{1}'.format(building_id, slot_id): empty_slot_doc } }) if level_up: self.try_unlock_slot() self.send_notify(building_id=building_id, slot_id=slot_id) resource_classified = ResourceClassification.classify(reward['items']) resource_classified.add( self.server_id, self.char_id, message="Territory.training_get_reward:{0}".format(building_id)) # 把建筑产出也要发回到客户端 resource_classified.bag.append( (BUILDING_PRODUCT_ID_TABLE[building_id], reward['product_amount'])) return resource_classified
def destroy(self, staff_id, tp): from core.club import Club from core.formation import Formation self._destroy_check(staff_id) staff = self.get_staff_object(staff_id) if not staff: raise GameException( ConfigErrorMessage.get_error_id("STAFF_NOT_EXIST")) if tp == 0: # 普通分解 items = staff.get_cost_items(70) crystal = ConfigStaffNew.get(staff.oid).crystal items.append((money_text_to_item_id('crystal'), crystal)) else: if staff.is_initial_state(): raise GameException( ConfigErrorMessage.get_error_id( "STAFF_CANNOT_DESTROY_INITIAL_STATE")) # TODO diamond count resource_classified = ResourceClassification.classify([ (money_text_to_item_id('diamond'), 50) ]) resource_classified.check_exist(self.server_id, self.char_id) resource_classified.remove( self.server_id, self.char_id, message="StaffManger.destroy:{0},{1}".format(staff.oid, tp)) items = staff.get_cost_items(100) resource_classified = ResourceClassification.classify(items) resource_classified.add(self.server_id, self.char_id, message="StaffManger.destroy:{0},{1}".format( staff.oid, tp)) if tp == 0: self.remove(staff_id) else: staff.reset() in_formation_staff_ids = Formation( self.server_id, self.char_id).in_formation_staffs().keys() if staff.id in in_formation_staff_ids: Club(self.server_id, self.char_id, load_staffs=False).force_load_staffs(send_notify=True) else: staff.calculate() staff.make_cache() self.send_notify(ids=[staff_id]) self.after_staffs_change_for_trig_signal() return resource_classified
def check_money(self, diamond=0, gold=0, crystal=0, gas=0, renown=0): if diamond > self.diamond: raise GameException(ConfigErrorMessage.get_error_id("DIAMOND_NOT_ENOUGH")) if gold > self.gold: raise GameException(ConfigErrorMessage.get_error_id("GOLD_NOT_ENOUGH")) if crystal > self.crystal: raise GameException(ConfigErrorMessage.get_error_id("CRYSTAL_NOT_ENOUGH")) if gas > self.gas: raise GameException(ConfigErrorMessage.get_error_id("GAS_NOT_ENOUGH")) if renown > self.renown: raise GameException(ConfigErrorMessage.get_error_id("RENOWN_NOT_ENOUGH"))
def kick(self, char_id): if char_id == self.char_id: raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE")) u = Union(self.server_id, char_id) if not isinstance(u, UnionMember ) or u.member_doc['joined'] != self.union_doc['_id']: raise GameException( ConfigErrorMessage.get_error_id("UNION_TARGET_NOT_MEMBER")) u.quit()
def register(name, password): if not name or not password: raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE")) try: with transaction.atomic(): account = AccountRegular.objects.create(name=name, passwd=password) except IntegrityError: raise GameException( ConfigErrorMessage.get_error_id("ACCOUNT_NAME_TAKEN")) return account
def _sweep_check(self): if not self.doc['max_star_level']: raise GameException(ConfigErrorMessage.get_error_id("TOWER_NO_MAX_STAR_LEVEL")) if -1 in self.doc['levels'].values(): raise GameException(ConfigErrorMessage.get_error_id("TOWER_CANNOT_TO_MAX_LEVEL_HAS_FAILURE")) levels_amount = self.doc['max_star_level'] - self.get_current_level() if levels_amount <= 0: raise GameException(ConfigErrorMessage.get_error_id("TOWER_CURRENT_LEVEL_GREAT_THAN_MAX_STAR_LEVEL")) return levels_amount
def check_exists(self, server_id, char_id): doc = MongoResource.db(server_id).find_one({'_id': char_id}) if not doc: raise GameException( ConfigErrorMessage.get_error_id("RESOURCE_NOT_ENOUGH")) for k, v in self.resource.iteritems(): if v > doc['resource'].get(str(k), 0): raise GameException( ConfigErrorMessage.get_error_id("RESOURCE_NOT_ENOUGH")) return doc
def third_login(provider, platform, uid, param): if not provider or not platform or not uid: raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE")) if provider == '1sdk': verify_1sdk(platform, uid, param) elif provider == 'stars-cloud': verify_stars_cloud(platform, uid, param) else: raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE")) return get_or_create_third_account(provider, platform, uid)
def equipment_change(self, bag_slot_id, tp): # 会影响的其他staff_id other_staff_id = "" if not bag_slot_id: # 卸下 bag_slot_id = "" else: # 更换 bag = Bag(self.server_id, self.char_id) slot = bag.get_slot(bag_slot_id) item_id = slot['item_id'] if get_item_type(item_id) != TYPE_EQUIPMENT: raise GameException( ConfigErrorMessage.get_error_id("INVALID_OPERATE")) equip_config = ConfigEquipmentNew.get(item_id) if equip_config.tp != tp: raise GameException( ConfigErrorMessage.get_error_id( "EQUIPMENT_TYPE_NOT_MATCH")) other_staff_id = StaffManger( self.server_id, self.char_id).find_staff_id_by_equipment_slot_id(bag_slot_id) if tp == EQUIP_MOUSE: key = 'equip_mouse' elif tp == EQUIP_KEYBOARD: key = 'equip_keyboard' elif tp == EQUIP_MONITOR: key = 'equip_monitor' elif tp == EQUIP_DECORATION: key = 'equip_decoration' elif tp == EQUIP_SPECIAL: key = 'equip_special' else: raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE")) setattr(self, key, bag_slot_id) MongoStaff.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'staffs.{0}.{1}'.format(self.id, key): bag_slot_id }}) self.calculate() self.make_cache() return other_staff_id
def generate(self, bag_slot_id, tp): if self.doc['item_id']: raise GameException( ConfigErrorMessage.get_error_id( "SPECIAL_EQUIPMENT_IS_IN_PROCESS")) if tp not in [ SPECIAL_EQUIPMENT_GENERATE_NORMAL, SPECIAL_EQUIPMENT_GENERATE_ADVANCE ]: raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE")) bag = Bag(self.server_id, self.char_id) slot = bag.get_slot(bag_slot_id) item_id = slot['item_id'] config = ConfigEquipmentSpecialGenerate.get(item_id) if not config: raise GameException( ConfigErrorMessage.get_error_id("INVALID_OPERATE")) if tp == SPECIAL_EQUIPMENT_GENERATE_NORMAL: cost = config.normal_cost else: cost = config.advance_cost rc = ResourceClassification.classify(cost) rc.check_exist(self.server_id, self.char_id) rc.remove(self.server_id, self.char_id, message="SpecialEquipmentGenerator.generate:{0}".format(tp)) bag.remove_by_slot_id(slot_id=bag_slot_id, amount=1) finish_at = arrow.utcnow().timestamp + config.minutes * 60 self.doc['item_id'] = item_id self.doc['finish_at'] = finish_at self.doc['tp'] = tp MongoSpecialEquipment.db(self.server_id).update_one( {'_id': self.char_id}, { '$set': { 'item_id': self.doc['item_id'], 'finish_at': self.doc['finish_at'], 'tp': self.doc['tp'], } }) self.send_notify()