def destroy(self, using_sycee): if self.level == UNIT_INIT_LEVEL and self.step == UNIT_INIT_STEP: raise GameException(ConfigErrorMessage.get_error_id("UNIT_IS_INIT_CANNOT_DESTROY")) if using_sycee: need_diamond = GlobalConfig.value("UNIT_DESTROY_SYCEE") cost = [(money_text_to_item_id('diamond'), need_diamond), ] rc = ResourceClassification.classify(cost) rc.check_exist(self.server_id, self.char_id) rc.remove(self.server_id, self.char_id, message="Unit.destroy:{0}".format(self.id)) percent = 1 else: percent = 0.7 items = self.get_strengthen_cost() items = [(_id, int(_amount * percent)) for _id, _amount in items] rc = ResourceClassification.classify(items) rc.add(self.server_id, self.char_id, message="Unit.destroy:{0}".format(self.id)) self.level = UNIT_INIT_LEVEL self.step = UNIT_INIT_STEP MongoUnit.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'units.{0}.level'.format(self.id): self.level, 'units.{0}.step'.format(self.id): self.step, }} ) return rc
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 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 send_reward(self, goods_id): if goods_id == YUEKA_ID: # 月卡买了就立即发送 # 后面的再定时发送 config = ConfigPurchaseYueka.get(YUEKA_ID) got = 0 actual_got = 0 MongoPurchase.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'yueka_remained_days': 29, 'yueka_new': True }} ) self.doc['yueka_remained_days'] = 29 self.doc['yueka_new'] = True rc = ResourceClassification.classify(config.rewards) attachment = rc.to_json() m = MailManager(self.server_id, self.char_id) m.add(config.mail_title, config.mail_content, attachment=attachment) else: config = ConfigPurchaseGoods.get(goods_id) got = config.diamond actual_got = config.diamond + config.diamond_extra if self.get_purchase_times() == 0: # 首充 actual_got = config.diamond * 2 + config.diamond_extra doc = MongoPurchaseLog.document() doc['_id'] = make_string_id() doc['char_id'] = self.char_id doc['goods_id'] = goods_id doc['got'] = got doc['actual_got'] = actual_got doc['timestamp'] = arrow.utcnow().timestamp MongoPurchaseLog.db(self.server_id).insert_one(doc) reward = [ (VIP_EXP_ITEM_ID, config.vip_exp), (money_text_to_item_id('diamond'), actual_got) ] rc = ResourceClassification.classify(reward) rc.add(self.server_id, self.char_id, message="Purchase.send_reward:{0}".format(goods_id)) purchase_done_signal.send( sender=None, server_id=self.server_id, char_id=self.char_id, goods_id=goods_id, got=got, actual_got=actual_got, ) self.send_notify()
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 buy_item(self, party_level, buy_id, member_ids): ret = api_handle.API.Party.BuyDone() ret.ret = 0 config = ConfigPartyLevel.get(party_level) if buy_id not in [config.buy_one, config.buy_two]: ret.ret = ConfigErrorMessage.get_error_id("PARTY_BUY_ITEM_NOT_EXIST") return ret config_buy = ConfigPartyBuyItem.get(buy_id) try: rc = ResourceClassification.classify(config_buy.cost) rc.check_exist(self.server_id, self.char_id) rc.remove(self.server_id, self.char_id, message="Party.buy_item:{0},{1}".format(party_level, buy_id)) except GameException as e: ret.ret = e.error_id return ret # 把购买的物品加给所有人 item_id, item_amount = config_buy.buy_result() reward = [(item_id, item_amount), ] rc = ResourceClassification.classify(reward) rc.add(self.server_id, self.char_id) for mid in member_ids: rc.add(self.server_id, mid, message="Party.buy_item:{0},{1}".format(party_level, buy_id)) ret.buy_name = config_buy.name ret.item_name = ConfigItemNew.get(item_id).name ret.item_amount = item_amount return ret
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 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 make_inspire(self): """ :rtype: ResourceClassification | None """ if not self.remained_inspire_times(): raise GameException(ConfigErrorMessage.get_error_id("TERRITORY_NO_INSPIRE_TIMES")) cost = [(money_text_to_item_id('diamond'), self.inspire_cost()), ] rc = ResourceClassification.classify(cost) rc.check_exist(self.server_id, self.char_id) rc.remove(self.server_id, self.char_id, message="Building.make_inspire") ValueLogTerritoryBuildingInspireTimes(self.server_id, self.char_id).record(sub_id=self.id) config = ConfigTerritoryBuilding.get(self.id).levels[self.level].inspire level_up = self.add_exp(config.exp) reward = config.get_reward() if reward: rc = ResourceClassification.classify(reward) rc.add(self.server_id, self.char_id, message="Building.make_inspire") return rc, level_up return None, level_up
def buy(self, item_id): config = ConfigTerritoryStore.get(item_id) if not config: raise GameException(ConfigErrorMessage.get_error_id("TERRITORY_STORE_ITEM_NOT_EXIST")) remained_times = self.get_remained_times(item_id) if not remained_times: raise GameException(ConfigErrorMessage.get_error_id("TERRITORY_STORE_ITEM_NO_TIMES")) resource_classified = ResourceClassification.classify(config.needs) resource_classified.check_exist(self.server_id, self.char_id) resource_classified.remove(self.server_id, self.char_id, message="TerritoryStore.buy:{0}".format(item_id)) got = [(config.item_id, config.item_amount), ] resource_classified = ResourceClassification.classify(got) resource_classified.add(self.server_id, self.char_id, message="TerritoryStore.buy:{0}".format(item_id)) if str(item_id) in self.times: self.times[str(item_id)] += 1 else: self.times[str(item_id)] = 1 ValueLogTerritoryStoreBuyTimes(self.server_id, self.char_id).record(sub_id=item_id) self.send_notify(item_id=item_id) return resource_classified
def make_inspire(self): """ :rtype: ResourceClassification | None """ if not self.remained_inspire_times(): raise GameException( ConfigErrorMessage.get_error_id("TERRITORY_NO_INSPIRE_TIMES")) cost = [ (money_text_to_item_id('diamond'), self.inspire_cost()), ] rc = ResourceClassification.classify(cost) rc.check_exist(self.server_id, self.char_id) rc.remove(self.server_id, self.char_id, message="Building.make_inspire") ValueLogTerritoryBuildingInspireTimes( self.server_id, self.char_id).record(sub_id=self.id) config = ConfigTerritoryBuilding.get( self.id).levels[self.level].inspire level_up = self.add_exp(config.exp) reward = config.get_reward() if reward: rc = ResourceClassification.classify(reward) rc.add(self.server_id, self.char_id, message="Building.make_inspire") return rc, level_up return None, level_up
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 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 equipment_destroy(self, slot_id, use_sycee): # 装备销毁 """ :rtype: ResourceClassification """ self._equipment_destroy_check(slot_id) this_slot = self.doc['slots'][slot_id] item_id = this_slot['item_id'] config = ConfigEquipmentNew.get(item_id) level = this_slot['level'] equip = Equipment.load_from_slot_data(this_slot) if use_sycee: if equip.is_special: min_level = 0 else: min_level = min(config.levels.keys()) if level == min_level: raise GameException(ConfigErrorMessage.get_error_id("EQUIPMENT_CANNOT_DESTROY_NO_LEVEL_UP")) diamond = GlobalConfig.value("EQUIPMENT_DESTROY_SYCEE") rf = ResourceClassification.classify([(money_text_to_item_id('diamond'), diamond)]) rf.check_exist(self.server_id, self.char_id) rf.remove(self.server_id, self.char_id) MongoBag.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'slots.{0}.level'.format(slot_id): 0 }} ) self.doc['slots'][slot_id]['level'] = 0 self.send_notify(slot_ids=[slot_id]) results = equip.get_destroy_back_items(is_normal_destroy=False) else: self.remove_by_slot_id(slot_id, 1) results = equip.get_destroy_back_items(is_normal_destroy=True) if config.renown: results.append((money_text_to_item_id('renown'), config.renown)) resource_classified = ResourceClassification.classify(results) resource_classified.add(self.server_id, self.char_id, message="Bag.equipment_destroy:{0}".format(item_id)) return resource_classified
def buy(self, tp, goods_id): if tp not in ALL_TYPES: raise GameException(ConfigErrorMessage.get_error_id("INVALID_OPERATE")) config = ConfigStore.get(goods_id) if not config: raise GameException(ConfigErrorMessage.get_error_id("STORE_GOODS_NOT_EXIST")) try: data = self.doc['tp'][str(tp)]['goods'][str(goods_id)] except KeyError: raise GameException(ConfigErrorMessage.get_error_id("INVALID_OPERATE")) if data['times'] >= config.times_limit: raise GameException(ConfigErrorMessage.get_error_id("STORE_GOODS_NO_TIMES")) if config.condition_id == 1: # VIP 等级 VIP(self.server_id, self.char_id).check(config.condition_value) elif config.condition_id == 2: # 爬塔历史最高星 Tower(self.server_id, self.char_id).check_history_max_star(config.condition_value) elif config.condition_id == 3: # 竞技场当前排名 Arena(self.server_id, self.char_id).check_current_rank(config.condition_value) elif config.condition_id == 4: # 当前公会等级 Union(self.server_id, self.char_id).check_level(config.condition_value) item_id, item_amount, need_id, need_amount = config.content[data['index']] resource_classify = ResourceClassification.classify([(need_id, need_amount)]) resource_classify.check_exist(self.server_id, self.char_id) resource_classify.remove(self.server_id, self.char_id, message="Store.buy:{0}".format(goods_id)) resource_classify = ResourceClassification.classify([(item_id, item_amount)]) resource_classify.add(self.server_id, self.char_id, message="Store.buy:{0}".format(goods_id)) data['times'] += 1 MongoStore.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'tp.{0}.goods.{1}.times'.format(tp, goods_id): data['times'] }} ) self.send_notify(tp=tp) return resource_classify
def signin(self): today_times = ValueLogWelfareSignInTimes(self.server_id, self.char_id).count_of_today() if today_times > 0: raise GameException(ConfigErrorMessage.get_error_id("WELFARE_ALREADY_SIGNED")) day = self.doc['signin'] + 1 if day == ConfigWelfareSignIn.LAST_DAY: self.doc['signin'] = ConfigWelfareSignIn.FIRST_DAY - 1 else: self.doc['signin'] = day config = ConfigWelfareSignIn.get(day) reward = [] reward.extend(config.reward) if VIP(self.server_id, self.char_id).level >= config.vip: reward.extend(config.vip_reward) rc = ResourceClassification.classify(reward) rc.add(self.server_id, self.char_id, message="Welfare.signin") MongoWelfare.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'signin': self.doc['signin'] }} ) ValueLogWelfareSignInTimes(self.server_id, self.char_id).record() self.send_signin_notify() return rc
def create(self, party_level): ret = api_handle.API.Party.CreateDone() ret.ret = 0 config = ConfigPartyLevel.get(party_level) if not config: ret.ret = ConfigErrorMessage.get_error_id("INVALID_OPERATE") return ret union = Union(self.server_id, self.char_id) union_id = union.get_joined_union_id() if not union_id: ret.ret = ConfigErrorMessage.get_error_id("PARTY_CANNOT_CREATE_NO_UNION") try: union.check_level(config.need_union_level) cost = [(money_text_to_item_id('diamond'), config.need_diamond), ] rc = ResourceClassification.classify(cost) rc.check_exist(self.server_id, self.char_id) except GameException as e: ret.ret = e.error_id return ret ret.union_id = union_id return ret
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 end(self, party_level, member_ids): ret = api_handle.API.Party.EndDone() ret.ret = 0 config = ConfigPartyLevel.get(party_level) talent_id = random.choice(config.talent_skills) self.doc['talent_id'] = talent_id MongoParty.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'talent_id': talent_id }}) # apply talent_id to club Club(self.server_id, self.char_id).force_load_staffs(send_notify=True) reward = [ (config.item_id, 1), ] rc = ResourceClassification.classify(reward) attachment = rc.to_json() char_ids = [self.char_id] char_ids.extend(member_ids) for c in char_ids: m = MailManager(self.server_id, c) m.add(config.mail_title, config.mail_content, attachment=attachment) ret.talent_id = talent_id return ret
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 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 end(self, party_level, member_ids): ret = api_handle.API.Party.EndDone() ret.ret = 0 config = ConfigPartyLevel.get(party_level) talent_id = random.choice(config.talent_skills) self.doc['talent_id'] = talent_id MongoParty.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'talent_id': talent_id }} ) # apply talent_id to club Club(self.server_id, self.char_id).force_load_staffs(send_notify=True) reward = [(config.item_id, 1), ] rc = ResourceClassification.classify(reward) attachment = rc.to_json() char_ids = [self.char_id] char_ids.extend(member_ids) for c in char_ids: m = MailManager(self.server_id, c) m.add(config.mail_title, config.mail_content, attachment=attachment) ret.talent_id = talent_id return ret
def create(self, name): cost = [(money_text_to_item_id('diamond'), GlobalConfig.value("UNION_CREATE_COST"))] rc = ResourceClassification.classify(cost) rc.check_exist(self.server_id, self.char_id) doc = MongoUnion.document() doc['_id'] = make_string_id() doc['create_at'] = arrow.utcnow().timestamp doc['name'] = name doc['owner'] = self.char_id try: MongoUnion.db(self.server_id).insert_one(doc) except DuplicateKeyError: raise GameException( ConfigErrorMessage.get_error_id("UNION_NAME_HAS_TAKEN")) MongoUnionMember.db(self.server_id).update_one({'_id': self.char_id}, { '$set': { 'joined': doc['_id'], 'joined_at': arrow.utcnow().timestamp } }) rc.remove(self.server_id, self.char_id, message="Union.create") Union(self.server_id, self.char_id).send_all_notify()
def send_rank_reward_and_reset_star(cls, server_id): char_ids = Club.get_recent_login_char_ids(server_id) char_ids = [i for i in char_ids] condition = {'$and': [ {'_id': {'$in': char_ids}}, {'today_max_star': {'$ne': 0}} ]} docs = MongoTower.db(server_id).find(condition, {'_id': 1}).sort('today_max_star', -1) rank = 1 for doc in docs: cid = doc['_id'] config = ConfigTowerRankReward.get(rank) rc = ResourceClassification.classify(config.reward) m = MailManager(server_id, cid) m.add( config.mail_title, config.mail_content, attachment=rc.to_json(), ) rank += 1 # reset today max star MongoTower.db(server_id).update_many( {}, {'$set': { 'today_max_star': 0, }} )
def get_reward(self, _id): if arrow.utcnow().timestamp >= self.reward_end_at: raise GameException(ConfigErrorMessage.get_error_id("ACTIVITY_NEW_PLAYER_REWARD_EXPIRE")) config = ConfigActivityNewPlayer.get(_id) if not config: raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE")) if config.day > self.create_day: raise GameException(ConfigErrorMessage.get_error_id("ACTIVITY_NEW_PLAYER_DAY_NOT_ARRIVE")) _, status = self.get_activity_status(_id) if status == ACTIVITY_COMPLETE: raise GameException(ConfigErrorMessage.get_error_id("ACTIVITY_NEW_PLAYER_HAS_GOT")) if status == ACTIVITY_DOING: raise GameException(ConfigErrorMessage.get_error_id("ACTIVITY_NEW_PLAYER_CONDITION_NOT_SATISFY")) rc = ResourceClassification.classify(config.rewards) rc.add(self.server_id, self.char_id, message="ActivityNewPlayer.get_reward:{0}".format(_id)) self.doc['done'].append(_id) MongoActivityNewPlayer.db(self.server_id).update_one( {'_id': self.char_id}, {'$push': { 'done': _id }} ) self.send_notify(ids=[_id]) return rc
def do_level_up(_add): _item_needs = equip.get_level_up_needs_items(_add) resource_classified = ResourceClassification.classify(_item_needs) resource_classified.check_exist(self.server_id, self.char_id) resource_classified.remove(self.server_id, self.char_id, message="Bag.equipment_level_up:{0}".format(item_id))
def equipment_batch_destroy(self, slot_ids): total_items = {} for slot_id in slot_ids: self._equipment_destroy_check(slot_id) this_slot = self.doc['slots'][slot_id] item_id = this_slot['item_id'] config = ConfigEquipmentNew.get(item_id) equip = Equipment.load_from_slot_data(this_slot) items = equip.get_destroy_back_items(is_normal_destroy=True) if config.renown: items.append((money_text_to_item_id('renown'), config.renown)) for _id, _amount in items: if _id in total_items: total_items[_id] += _amount else: total_items[_id] = _amount rc = ResourceClassification.classify(total_items.items()) rc.add(self.server_id, self.char_id, message="Bag.equipment_batch_destroy") for slot_id in slot_ids: self.remove_by_slot_id(slot_id, 1) return rc
def buy_plunder_times(self): info = PlunderTimesBuyInfo(self.server_id, self.char_id) if not info.remained_buy_times: raise GameException( ConfigErrorMessage.get_error_id("PLUNDER_NO_BUY_TIMES")) cost = [ (money_text_to_item_id('diamond'), info.buy_cost), ] rc = ResourceClassification.classify(cost) rc.check_exist(self.server_id, self.char_id) rc.remove(self.server_id, self.char_id, message="Plunder.buy_plunder_times") ValueLogPlunderBuyTimes(self.server_id, self.char_id).record() self.doc['plunder_remained_times'] += 1 MongoPlunder.db(self.server_id).update_one({'_id': self.char_id}, { '$set': { 'plunder_remained_times': self.doc['plunder_remained_times'] } }) self.send_plunder_times_notify()
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 reset(self): if not self.doc['cost_point']: raise GameException( ConfigErrorMessage.get_error_id( "TALENT_CANNOT_RESET_NOT_USE_POINT")) using_items = [(money_text_to_item_id('diamond'), RESET_TALENT_TREE_COST)] 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="TalentManager.reset") self.doc['talents'] = ConfigTalent.INIT_TALENT_IDS self.doc['cost_point'] = 0 MongoTalent.db(self.server_id).update_one({'_id': self.char_id}, { '$set': { 'talents': self.doc['talents'], 'cost_point': self.doc['cost_point'], } }) self.send_notify() self.after_change()
def create(self, party_level): ret = api_handle.API.Party.CreateDone() ret.ret = 0 config = ConfigPartyLevel.get(party_level) if not config: ret.ret = ConfigErrorMessage.get_error_id("INVALID_OPERATE") return ret union = Union(self.server_id, self.char_id) union_id = union.get_joined_union_id() if not union_id: ret.ret = ConfigErrorMessage.get_error_id( "PARTY_CANNOT_CREATE_NO_UNION") try: union.check_level(config.need_union_level) cost = [ (money_text_to_item_id('diamond'), config.need_diamond), ] rc = ResourceClassification.classify(cost) rc.check_exist(self.server_id, self.char_id) except GameException as e: ret.ret = e.error_id return ret ret.union_id = union_id return ret
def trig(self, challenge_id): if not self.doing: # 任务都做完了 return config = ConfigTaskMain.get(self.doing) if not Challenge(self.server_id, self.char_id).is_challenge_id_passed(config.challenge_id): return if self.doing >= ConfigTaskMain.MAX_ID: self.doing = 0 else: self.doing += 1 MongoTaskMain.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'doing': self.doing }} ) resource_classified = ResourceClassification.classify(config.items) resource_classified.add(self.server_id, self.char_id, message="TaskMain.trig:{0}".format(challenge_id)) self.send_notify(update=True)
def start(self, party_level, member_ids): # member_ids 只是组员, 不包括创建者自己 ret = api_handle.API.Party.StartDone() ret.ret = 0 config = ConfigPartyLevel.get(party_level) try: cost = [ (money_text_to_item_id('diamond'), config.need_diamond), ] rc = ResourceClassification.classify(cost) rc.check_exist(self.server_id, self.char_id) rc.remove(self.server_id, self.char_id, message="Party.start:{0}".format(party_level)) except GameException as e: ret.ret = e.error_id return ret ValueLogPartyCreateTimes(self.server_id, self.char_id).record() ValueLogPartyEngageTimes(self.server_id, self.char_id).record() for mid in member_ids: ValueLogPartyJoinTimes(self.server_id, mid).record() ValueLogPartyEngageTimes(self.server_id, self.char_id).record() return ret
def _send_one_mail(self, m): if m.items: rc = ResourceClassification.classify(m.get_parsed_items()) attachment = rc.to_json() else: attachment = "" if m.condition_type == 1: # 全部服务器 for s in ModelServer.objects.all(): self._send_to_one_server(s.id, m, attachment) elif m.condition_type == 2: # 指定服务器 for sid in m.get_parsed_condition_value(): self._send_to_one_server(sid, m, attachment) elif m.condition_type == 3: # 指定排除服务器 values = m.get_parsed_condition_value() for s in ModelServer.objects.exclude(id__in=values): self._send_to_one_server(s.id, m, attachment) elif m.condition_type == 11: # 指定角色ID values = m.get_parsed_condition_value() chars = ModelCharacter.objects.filter(id__in=values) for c in chars: self._send_to_one_char(c.server_id, c.id, m, attachment)
def match_report(self, key, win): try: friend_id, building_id, event_id = key.split(':') friend_id = int(friend_id) building_id = int(building_id) event_id = int(event_id) except: raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE")) # NOTE: 战斗要等到结算的时候再记录次数 ValueLogTerritoryHelpFriendTimes(self.server_id, self.char_id).record() self.send_remained_times_notify() config = ConfigTerritoryEvent.get(event_id) Territory(self.server_id, friend_id).got_help(self.char_id, building_id, config.target_exp) if win: drop = config.reward_win else: drop = config.reward_lose resource_classified = ResourceClassification.classify(drop) resource_classified.add( self.server_id, self.char_id, message="TerritoryFriend.match_report:{0}".format(win)) return resource_classified
def batch_destroy(self, staff_ids): total_items = {} for sid in staff_ids: self._destroy_check(sid) staff = self.get_staff_object(sid) if not staff: raise GameException( ConfigErrorMessage.get_error_id("STAFF_NOT_EXIST")) _items = staff.get_cost_items(70) _crystal = ConfigStaffNew.get(staff.oid).crystal _items.append((money_text_to_item_id('crystal'), _crystal)) for _id, _amount in _items: if _id in total_items: total_items[_id] += _amount else: total_items[_id] = _amount rc = ResourceClassification.classify(total_items.items()) rc.add(self.server_id, self.char_id, message="StaffManger.batch_destroy") self.remove(staff_ids) self.after_staffs_change_for_trig_signal() return rc
def daily_reward_get(self, _id): config = ConfigPlunderDailyReward.get(_id) if not config: raise GameException(ConfigErrorMessage.get_error_id("INVALID_OPERATE")) key, info = self.get_daily_reward_info() win_ways = info.get('win_ways', 0) got_list = info.get('got_list', []) if _id in got_list: raise GameException(ConfigErrorMessage.get_error_id("PLUNDER_DAILY_REWARD_ALREADY_GOT")) if win_ways < _id: raise GameException(ConfigErrorMessage.get_error_id("PLUNDER_DAILY_REWARD_NOT_ENOUGH")) rc = ResourceClassification.classify(config.reward) rc.add(self.server_id, self.char_id, message="Plunder.daily_reward_get:{0}".format(_id)) got_list.append(_id) info['got_list'] = got_list self.doc['daily_reward'] = {key: info} MongoPlunder.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'daily_reward': {key: info} }} ) self.send_plunder_daily_reward_notify(info=info) return rc
def level_up(self, add_level): assert add_level > 0 from core.club import get_club_property max_level = min(self.config.max_level, get_club_property(self.server_id, self.char_id, 'level') * 2) if self.level >= max_level: raise GameException(ConfigErrorMessage.get_error_id("UNIT_REACH_MAX_LEVEL")) old_level = self.level if add_level == 1: using_items = self.config.levels[self.level].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="Unit.level_up:{0}".format(self.id)) self.level += 1 else: # 这里要反过来试,如果正向试的话, 可能需要试5次,此时有点慢 # 反过来只对 只是升一两次的情况比较慢,但这种可以接受 can_add_level = max_level - self.level if add_level > can_add_level: add_level = can_add_level def _try_up(_add): _using_items = [] this_level = self.level for _ in range(_add): items = self.config.levels[this_level].update_item_need _using_items.extend(items) this_level += 1 rc = ResourceClassification.classify(_using_items) rc.check_exist(self.server_id, self.char_id) rc.remove(self.server_id, self.char_id, message="Unit.level_up:{0}".format(self.id)) for i in range(add_level, 0, -1): try: _try_up(i) except GameException as e: if i == 1: # 只升一级都报错 raise e else: # 没有raise GameException 资源是够的 self.level += i break if self.level != old_level: MongoUnit.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'units.{0}.level'.format(self.id): self.level }} ) # 升级可能会导致其他的unit属性改变(加成) # 所以在UnitManage 里统一load一次unit return self.level - old_level
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 send_yueka_reward(cls, server_id): config = ConfigPurchaseYueka.get(YUEKA_ID) condition = {'$and': [ {'yueka_remained_days': {'$gt': 0}}, {'yueka_new': False} ]} docs = MongoPurchase.db(server_id).find(condition) MongoPurchase.db(server_id).update_many( condition, {'$inc': { 'yueka_remained_days': -1 }} ) # 把今天新购买的,设置为False,以便后面的定时任务好发送月卡 MongoPurchase.db(server_id).update_many( {'yueka_new': True}, {'$set': {'yueka_new': False}} ) rc = ResourceClassification.classify(config.rewards) attachment = rc.to_json() amount = 0 for doc in docs: m = MailManager(server_id, doc['_id']) m.add(config.mail_title, config.mail_content, attachment=attachment) amount += 1 return amount
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 _make_single_up(): star_config = ConfigStaffStar.get(self.star) using_items = [(star_config.need_item_id, star_config.need_item_amount)] 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.star_up:{0}".format(self.oid)) if random.randint(1, 100) <= 20: _exp = 6 is_crit = True else: _exp = random.randint(1, 3) is_crit = False exp = self.star_exp + _exp while True: if self.star == ConfigStaffStar.MAX_STAR: if exp >= ConfigStaffStar.get(self.star).exp: exp = ConfigStaffStar.get(self.star).exp - 1 break if exp < ConfigStaffStar.get(self.star).exp: break exp -= ConfigStaffStar.get(self.star).exp self.star += 1 self.star_exp = exp return is_crit, _exp, star_config.need_item_id, star_config.need_item_amount
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 batch_destroy(self, staff_ids): total_items = {} for sid in staff_ids: self._destroy_check(sid) staff = self.get_staff_object(sid) if not staff: raise GameException(ConfigErrorMessage.get_error_id("STAFF_NOT_EXIST")) _items = staff.get_cost_items(70) _crystal = ConfigStaffNew.get(staff.oid).crystal _items.append((money_text_to_item_id('crystal'), _crystal)) for _id, _amount in _items: if _id in total_items: total_items[_id] += _amount else: total_items[_id] = _amount rc = ResourceClassification.classify(total_items.items()) rc.add(self.server_id, self.char_id, message="StaffManger.batch_destroy") self.remove(staff_ids) self.after_staffs_change_for_trig_signal() return rc
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 refresh(self): cd = self.get_refresh_cd() if cd: # 就是要花钱了 ti = TimesInfo(self.server_id, self.char_id) if not ti.remained_reset_times: raise GameException( ConfigErrorMessage.get_error_id( "ARENA_NO_SEARCH_RESET_TIMES")) cost = [ (money_text_to_item_id('diamond'), ti.reset_cost), ] rc = ResourceClassification.classify(cost) rc.check_exist(self.server_id, self.char_id) rc.remove(self.server_id, self.char_id, message="Arena.refresh") ValueLogArenaSearchResetTimes(self.server_id, self.char_id).record() else: ArenaRefreshCD(self.server_id, self.char_id).set(ARENA_REFRESH_CD_SECONDS) rival = self.search_rival() MongoArena.db(self.server_id).update_one({'_id': str(self.char_id)}, {'$set': { 'rival': rival }}) self.send_notify()
def trig(self, challenge_id): if not self.doing: # 任务都做完了 return config = ConfigTaskMain.get(self.doing) if not Challenge(self.server_id, self.char_id).is_challenge_id_passed( config.challenge_id): return if self.doing >= ConfigTaskMain.MAX_ID: self.doing = 0 else: self.doing += 1 MongoTaskMain.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'doing': self.doing }}) resource_classified = ResourceClassification.classify(config.items) resource_classified.add( self.server_id, self.char_id, message="TaskMain.trig:{0}".format(challenge_id)) self.send_notify(update=True)
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 refresh(self): cd = self.get_refresh_cd() if cd: # 就是要花钱了 ti = TimesInfo(self.server_id, self.char_id) if not ti.remained_reset_times: raise GameException(ConfigErrorMessage.get_error_id("ARENA_NO_SEARCH_RESET_TIMES")) cost = [(money_text_to_item_id('diamond'), ti.reset_cost), ] rc = ResourceClassification.classify(cost) rc.check_exist(self.server_id, self.char_id) rc.remove(self.server_id, self.char_id, message="Arena.refresh") ValueLogArenaSearchResetTimes(self.server_id, self.char_id).record() else: ArenaRefreshCD(self.server_id, self.char_id).set(ARENA_REFRESH_CD_SECONDS) rival = self.search_rival() MongoArena.db(self.server_id).update_one( {'_id': str(self.char_id)}, {'$set': { 'rival': rival }} ) self.send_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 buy_goods(self, goods_index): goods = self.doc.get('goods', []) try: goods_id, bought = goods[goods_index] except IndexError: raise GameException(ConfigErrorMessage.get_error_id("INVALID_OPERATE")) if bought: raise GameException(ConfigErrorMessage.get_error_id("TOWER_GOODS_HAS_BOUGHT")) config = ConfigTowerSaleGoods.get(goods_id) if config.vip_need: VIP(self.server_id, self.char_id).check(config.vip_need) cost = [(money_text_to_item_id('diamond'), config.price_now)] rc = ResourceClassification.classify(cost) rc.check_exist(self.server_id, self.char_id) rc.remove(self.server_id, self.char_id, message="Tower.buy_goods") got = [(config.item_id, config.amount)] rc = ResourceClassification.classify(got) rc.add(self.server_id, self.char_id, message="Tower.buy_goods") self.doc['goods'][goods_index][1] = 1 # NOTE 这里要把买完的那一组删掉 if goods_index % 2 == 0: # 0, 2, 4 的情况,这组下一个的index是 goods_index+1 other_index = goods_index + 1 else: other_index = goods_index - 1 if self.doc['goods'][other_index][1] == 1: _index = min(other_index, goods_index) self.doc['goods'].pop(_index) self.doc['goods'].pop(_index) MongoTower.db(self.server_id).update_one( {'_id': self.char_id}, {'$set': { 'goods': self.doc['goods'] }} ) self.send_goods_notify() return rc
def send_rank_reward(cls, server_id): char_ids = Club.get_recent_login_char_ids(server_id) # 加上一分钟,确保已经到了第二天 # 定时任务要是 23:59:59 启动,那天数判断就错了 weekday = arrow.utcnow().to( settings.TIME_ZONE).replace(minutes=1).weekday() for cid in char_ids: arena = Arena(server_id, cid) rank = arena.get_current_rank() # 每日奖励 config = ConfigArenaRankReward.get(rank) rc = ResourceClassification.classify(config.reward) m = MailManager(server_id, cid) m.add( config.mail_title, config.mail_content, attachment=rc.to_json(), ) if weekday == 0: # 周一发周奖励 config_weekly = ConfigArenaRankRewardWeekly.get(rank) rc = ResourceClassification.classify(config_weekly.reward) m = MailManager(server_id, cid) m.add(config_weekly.mail_title, config_weekly.mail_content, attachment=rc.to_json()) if weekday == 0: docs = MongoArena.db(server_id).find({'_id': { '$regex': '^\d+$' }}, {'_id': 1}) default_score_doc = MongoArenaScore.db(server_id).find_one( {'_id': ARENA_DEFAULT_SCORE}) for doc in docs: if doc['_id'] in default_score_doc['char_ids']: continue ArenaScore(server_id, int(doc['_id'])).set_score(ARENA_DEFAULT_SCORE)
def _remove_money(): cost = [(money_text_to_item_id('gold'), config.cost_value_1)] resource_classify = ResourceClassification.classify(cost) resource_classify.check_exist(self.server_id, self.char_id) resource_classify.remove(self.server_id, self.char_id, message="StaffRecruit.recruit:1,1")
def create(cls, server_id, char_id, club_name, club_flag): from core.staff import StaffManger from core.formation import Formation from core.mail import MailManager from apps.config.models import Mail as ModelMail doc = MongoCharacter.document() doc['_id'] = char_id doc['create_at'] = arrow.utcnow().timestamp doc['name'] = club_name doc['flag'] = club_flag doc['gold'] = CHAR_INIT_GOLD doc['diamond'] = CHAR_INIT_DIAMOND doc['crystal'] = CHAR_INIT_CRYSTAL doc['gas'] = CHAR_INIT_GAS sm = StaffManger(server_id, char_id) formation_init_data = [] for staff_id, unit_id in CHAR_INIT_STAFFS: uid = sm.add(staff_id, send_notify=False, trig_signal=False) formation_init_data.append((uid, unit_id)) fm = Formation(server_id, char_id) fm.initialize(formation_init_data) MongoCharacter.db(server_id).insert_one(doc) # add welfare mail start_time = get_start_time_of_today() condition = Q(send_at__gte=start_time.format("YYYY-MM-DD HH:mm:ssZ")) &\ Q(send_at__lte=arrow.utcnow().format("YYYY-MM-DD HH:mm:ssZ")) mails = ModelMail.objects.filter(condition) m = MailManager(server_id, char_id) for m_obj in mails: if not m_obj.welfare: continue ok = False if m_obj.condition_type == 1: ok = True elif m_obj.condition_type == 2 and server_id in m_obj.get_parsed_condition_value(): ok = True elif m_obj.condition_type == 3 and server_id not in m_obj.get_parsed_condition_value(): ok = True if not ok: continue if m_obj.items: rc = ResourceClassification.classify(m_obj.get_parsed_items()) attachment = rc.to_json() else: attachment = "" m.add(m_obj.title, m_obj.content, attachment=attachment, send_notify=False)
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