def test_refresh_gold(self): config = ConfigStaffRecruit.get(RECRUIT_ENUM_TO_CONFIG_ID[RECRUIT_GOLD]) for i in range(1, config.lucky_times+1): self.update(**{'diamond': config.cost_value}) StaffRecruit(self.server_id, self.char_id).refresh(RECRUIT_GOLD) staff_ids = StaffRecruit(self.server_id, self.char_id).get_self_refreshed_staffs() quality_s = 0 quality_a = 0 quality_b = 0 for staff_id in staff_ids: conf = ConfigStaff.get(int(staff_id)) if conf.quality == 'S': quality_s += 1 elif conf.quality == 'A': quality_a += 1 elif conf.quality == 'B': quality_b += 1 if i == 1 or i % config.lucky_times == 0: assert quality_s == 1 assert quality_a == 1 assert quality_b == 6 else: assert quality_a == 2 assert quality_b == 6
def check_exist(self, server_id, char_id): from core.club import Club from core.bag import Bag from core.staff import StaffManger, StaffRecruit from core.territory import Territory from core.arena import Arena from core.energy import Energy money_text = self.money_as_text_dict() if money_text: Club(server_id, char_id).check_money(**money_text) if self.bag: Bag(server_id, char_id).check_items(self.bag) if self.staff: StaffManger(server_id, char_id).check_original_staff_is_initial_state( self.staff) if self.territory_product: Territory(server_id, char_id).check_product(self.territory_product) if self.work_card: Territory(server_id, char_id).check_work_card(self.work_card) if self.arena_point: Arena(server_id, char_id).check_point(self.arena_point) if self.energy: Energy(server_id, char_id).check(self.energy) if self.staff_recruit_score: StaffRecruit(server_id, char_id).check_score(self.staff_recruit_score) if self.resource_data: _r = _Resource() _r.resource = dict(self.resource_data) _r.check_exists(server_id, char_id)
def add(self, server_id, char_id, message=""): from core.club import Club from core.bag import Bag from core.staff import StaffManger, StaffRecruit from core.talent import TalentManager from core.territory import Territory from core.vip import VIP from core.arena import Arena from core.energy import Energy from core.plunder import Plunder club_property = self.money_as_text_dict() if self.club_exp: club_property['exp'] = self.club_exp if club_property: club_property['message'] = message Club(server_id, char_id).update(**club_property) if self.vip_exp: VIP(server_id, char_id).add_exp(self.vip_exp) if self.bag: bag = Bag(server_id, char_id) bag.batch_add(self.bag) sm = StaffManger(server_id, char_id) if self.staff: sm.batch_add(self.staff) if self.staff_exp_pool: sm.add_exp_pool(self.staff_exp_pool) if self.talent_point: TalentManager(server_id, char_id).add_talent_points(self.talent_point) if self.arena_point: Arena(server_id, char_id).add_point(self.arena_point) if self.territory_product: Territory(server_id, char_id).add_product(self.territory_product) if self.work_card: Territory(server_id, char_id).add_work_card(self.work_card) if self.energy: Energy(server_id, char_id).add(self.energy) if self.staff_recruit_score: StaffRecruit(server_id, char_id).add_score(self.staff_recruit_score) if self.station_exp: Plunder(server_id, char_id).add_station_exp(self.station_exp) if self.resource_data: _r = _Resource() _r.resource = dict(self.resource_data) _r.add(server_id, char_id)
def test_refresh_error_tp(self): tp = 9999 try: StaffRecruit(self.server_id, self.char_id).refresh(tp) except GameException as e: assert e.error_id == ConfigErrorMessage.get_error_id("BAD_MESSAGE") else: raise Exception("can not be here!")
def recruit(request): server_id = request._game_session.server_id char_id = request._game_session.char_id tp = request._proto.tp mode = request._proto.mode recruit = StaffRecruit(server_id, char_id) items = recruit.recruit(tp, mode) response = StaffRecruitResponse() response.ret = 0 for _id, _amount in items: _item = response.drop.items.add() _item.id = _id _item.amount = _amount return ProtobufResponse(response)
def test_recruit(self): config = ConfigStaffRecruit.get(RECRUIT_ENUM_TO_CONFIG_ID[RECRUIT_NORMAL]) cost_type = 'gold' if config.cost_type == 1 else 'diamond' self.update(**{cost_type: config.cost_value}) StaffRecruit(self.server_id, self.char_id).refresh(RECRUIT_NORMAL) staff_ids = StaffRecruit(self.server_id, self.char_id).get_self_refreshed_staffs() doc = MongoStaff.db(self.server_id).find_one({'_id': self.char_id}, {'staffs': 1}) test_id = 0 for staff_id in staff_ids: if str(staff_id) not in doc['staffs'].keys(): test_id = staff_id break assert StaffManger(self.server_id, self.char_id).has_staff(test_id) is False staff_cfg = ConfigStaff.get(test_id) tp = 'gold' if staff_cfg.buy_type == 1 else 'diamond' self.update(**{tp: staff_cfg.buy_cost}) StaffRecruit(self.server_id, self.char_id).recruit(test_id) assert StaffManger(self.server_id, self.char_id).has_staff(test_id) is True
def test_recruit_already_have(self): config = ConfigStaffRecruit.get(RECRUIT_ENUM_TO_CONFIG_ID[RECRUIT_NORMAL]) cost_type = 'gold' if config.cost_type == 1 else 'diamond' self.update(**{cost_type: config.cost_value}) StaffRecruit(self.server_id, self.char_id).refresh(RECRUIT_NORMAL) staff_ids = StaffRecruit(self.server_id, self.char_id).get_self_refreshed_staffs() doc = MongoStaff.db(self.server_id).find_one({'_id': 1}, {'staffs': 1}) test_id = 0 for staff_id in staff_ids: if str(staff_id) not in doc['staffs'].keys(): StaffManger(self.server_id, self.char_id).add(staff_id) test_id = staff_id break try: StaffRecruit(self.server_id, self.char_id).recruit(test_id) except GameException as e: assert e.error_id == ConfigErrorMessage.get_error_id("STAFF_ALREADY_HAVE") else: raise Exception("can not be here!")
def test_refresh_resource_not_enough(self): config = ConfigStaffRecruit.get(random.choice(ConfigStaffRecruit.INSTANCES.keys())) error = "GOLD_NOT_ENOUGH" if config.cost_type == 1 else "DIAMOND_NOT_ENOUGH" tp = RECRUIT_DIAMOND if config.cost_type == 2 else RECRUIT_NORMAL try: StaffRecruit(self.server_id, self.char_id).refresh(tp) except GameException as e: assert e.error_id == ConfigErrorMessage.get_error_id(error) else: raise Exception("can not be here!")
def test_recruit_staff_not_exist(self): staff_ids = ConfigStaff.INSTANCES.keys() test_id = 0 for i in range(0, 10000): if i not in staff_ids: test_id = i break try: StaffRecruit(self.server_id, self.char_id).recruit(test_id) except GameException as e: assert e.error_id == ConfigErrorMessage.get_error_id("STAFF_NOT_EXIST") else: raise Exception("error")
def test_refresh_by_use_resource(self): config = ConfigStaffRecruit.get(random.choice(ConfigStaffRecruit.INSTANCES.keys())) cost_type = 'gold' if config.cost_type == 1 else 'diamond' self.update(**{cost_type: config.cost_value}) tp = RECRUIT_NORMAL if config.cost_type == 2: tp = RECRUIT_GOLD if config.cost_type == 3: tp = RECRUIT_DIAMOND staffs = StaffRecruit(self.server_id, self.char_id).refresh(tp) assert len(staffs) > 0
def test_recruit_not_in_list(self): config = ConfigStaffRecruit.get(RECRUIT_ENUM_TO_CONFIG_ID[RECRUIT_NORMAL]) cost_type = 'gold' if config.cost_type == 1 else 'diamond' self.update(**{cost_type: config.cost_value}) StaffRecruit(self.server_id, self.char_id).refresh(RECRUIT_NORMAL) config_ids = ConfigStaff.INSTANCES.keys() staff_ids = StaffRecruit(self.server_id, self.char_id).get_self_refreshed_staffs() doc = MongoStaff.db(self.server_id).find_one({'_id': self.char_id}, {'staffs': 1}) has_staffs = [int(staff_id) for staff_id in doc['staffs'].keys()] staffs_set = set(staff_ids) | set(has_staffs) test_id = 0 for staff_id in config_ids: if staff_id not in staffs_set: test_id = staff_id break try: StaffRecruit(self.server_id, self.char_id).recruit(test_id) except GameException as e: assert e.error_id == ConfigErrorMessage.get_error_id("STAFF_RECRUIT_NOT_IN_LIST") else: raise Exception("can not be here!")
def remove(self, server_id, char_id, message=""): from core.club import Club from core.bag import Bag from core.staff import StaffManger, StaffRecruit from core.territory import Territory from core.arena import Arena from core.energy import Energy money_text = self.money_as_text_dict() if money_text: money_text = {k: -v for k, v in money_text.iteritems()} money_text['message'] = message Club(server_id, char_id).update(**money_text) if self.bag: bag = Bag(server_id, char_id) for _id, _amount in self.bag: bag.remove_by_item_id(_id, _amount) if self.staff: StaffManger(server_id, char_id).internal_remove_by_oid(self.staff) if self.territory_product: Territory(server_id, char_id).remove_product(self.territory_product) if self.work_card: Territory(server_id, char_id).remove_work_card(self.work_card) if self.arena_point: Arena(server_id, char_id).remove_point(self.arena_point) if self.energy: Energy(server_id, char_id).remove(self.energy) if self.staff_recruit_score: StaffRecruit(server_id, char_id).remove_score(self.staff_recruit_score) if self.resource_data: _r = _Resource() _r.resource = dict(self.resource_data) _r.remove(server_id, char_id)
def game_start_handler(server_id, char_id, **kwargs): MessagePipe(char_id).clean() msg = UTCNotify() msg.timestamp = arrow.utcnow().timestamp MessagePipe(char_id).put(msg=msg) msg = SocketServerNotify() ss = random.choice(settings.SOCKET_SERVERS) msg.ip = ss['host'] msg.port = ss['tcp'] MessagePipe(char_id).put(msg=msg) _Resource.send_notify(server_id, char_id) UnitManager(server_id, char_id).send_notify() Bag(server_id, char_id).send_notify() StaffManger(server_id, char_id).send_notify() StaffRecruit(server_id, char_id).send_notify() f = Formation(server_id, char_id) f.send_formation_notify() f.send_slot_notify() club = Club(server_id, char_id) club.set_login() club.send_notify() msg = CreateDaysNotify() msg.days = days_passed(club.create_at) msg.create_at = club.create_at MessagePipe(char_id).put(msg=msg) chall = Challenge(server_id, char_id) chall.send_chapter_notify() chall.send_challenge_notify() FriendManager(server_id, char_id).send_notify() MailManager(server_id, char_id).send_notify() TaskMain(server_id, char_id).send_notify() TaskDaily(server_id, char_id).send_notify() Chat(server_id, char_id).send_notify() Notification(server_id, char_id).send_notify() FinanceStatistics(server_id, char_id).send_notify() TalentManager(server_id, char_id).send_notify() Dungeon(server_id, char_id).send_notify() a = Arena(server_id, char_id) a.send_notify() a.send_honor_notify() t = Tower(server_id, char_id) t.send_notify() t.send_goods_notify() Territory(server_id, char_id).send_notify() TerritoryStore(server_id, char_id).send_notify() TerritoryFriend(server_id, char_id).send_remained_times_notify() Store(server_id, char_id).send_notify() VIP(server_id, char_id).send_notify() Collection(server_id, char_id).send_notify() Energy(server_id, char_id).send_notify() w = Welfare(server_id, char_id) w.send_signin_notify() w.send_new_player_notify() w.send_level_reward_notify() w.send_energy_reward_notify() Union(server_id, char_id).send_all_notify() Purchase(server_id, char_id).send_notify() ac = ActivityNewPlayer(server_id, char_id) ac.send_notify() ac.send_daily_buy_notify() ActivityOnlineTime(server_id, char_id).send_notify() ActivityChallenge(server_id, char_id).send_notify() ActivityPurchaseDaily(server_id, char_id).send_notify() ActivityPurchaseContinues(server_id, char_id).send_notify() ActivityLevelGrowing(server_id, char_id).send_notify() p = Plunder(server_id, char_id) p.send_search_notify() p.send_result_notify() p.send_revenge_notify() p.send_station_notify() p.send_formation_notify() p.send_plunder_times_notify() p.send_plunder_daily_reward_notify() SpecialEquipmentGenerator(server_id, char_id).send_notify() Party(server_id, char_id).send_notify() ins = Inspire(server_id, char_id) ins.try_open_slots(send_notify=False) ins.send_notify() cs = Championship(server_id, char_id) cs.try_initialize(send_notify=False) cs.send_notify() WinningPlunder(server_id, char_id).send_notify() WinningArena(server_id, char_id).send_notify() WinningChampionship(server_id, char_id).send_notify() Worship(server_id, char_id).send_notify() CommonArenaWinningChat(server_id, char_id).send_notify() CommonPlunderWinningChat(server_id, char_id).send_notify() CommonChampionshipChat(server_id, char_id).send_notify() send_system_notify(server_id, char_id) BroadCast(server_id, char_id).try_cast_login_notify()
def test_refresh_hot(self): StaffRecruit(self.server_id, self.char_id).refresh(RECRUIT_HOT)
def test_send_notify(self): StaffRecruit(self.server_id, self.char_id).send_notify()