Beispiel #1
0
    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()
Beispiel #2
0
    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
Beispiel #3
0
    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
        )
Beispiel #4
0
    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)
Beispiel #5
0
    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
Beispiel #6
0
    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()
Beispiel #7
0
    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()
Beispiel #8
0
    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
Beispiel #9
0
    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
Beispiel #10
0
    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)
Beispiel #11
0
    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)
Beispiel #12
0
    def active_formation(self, fid):
        from core.challenge import Challenge

        config = ConfigFormation.get(fid)
        if not config:
            raise GameException(ConfigErrorMessage.get_error_id("FORMATION_NOT_EXIST"))

        if str(fid) in self.doc['levels']:
            raise GameException(ConfigErrorMessage.get_error_id("FORMATION_ALREADY_ACTIVE"))

        Challenge(self.server_id, self.char_id).check_starts(config.active_need_star)

        rc = ResourceClassification.classify(config.active_need_items)
        rc.check_exist(self.server_id, self.char_id)
        rc.remove(self.server_id, self.char_id, message="Formation.active_formation:{0}".format(fid))

        self.doc['levels'][str(fid)] = 1
        self.MONGO_COLLECTION.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'levels.{0}'.format(fid): 1
            }}
        )

        self.send_formation_notify(formation_ids=[fid])
Beispiel #13
0
    def equipment_change(self, staff_id, slot_id, tp):
        from core.formation import Formation

        if tp not in [EQUIP_MOUSE, EQUIP_KEYBOARD, EQUIP_MONITOR, EQUIP_DECORATION, EQUIP_SPECIAL]:
            raise GameException(ConfigErrorMessage.get_error_id("INVALID_OPERATE"))

        staff = self.get_staff_object(staff_id)
        if not staff:
            raise GameException(ConfigErrorMessage.get_error_id("STAFF_NOT_EXIST"))

        other_staff_id = staff.equipment_change(slot_id, tp)
        if other_staff_id:
            # 把装备从 这个 staff 上撤下
            self.get_staff_object(other_staff_id).equipment_change("", tp)

        changed = [staff_id]
        if other_staff_id:
            changed.append(other_staff_id)

        self.send_notify(ids=changed)

        in_formation_staff_ids = Formation(self.server_id, self.char_id).in_formation_staffs().keys()
        if staff.id in in_formation_staff_ids or other_staff_id in in_formation_staff_ids:
            self.after_staff_change(staff_id)

            task_condition_trig_signal.send(
                sender=None,
                server_id=self.server_id,
                char_id=self.char_id,
                condition_name='core.formation.Formation'
            )
Beispiel #14
0
    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
Beispiel #15
0
    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
Beispiel #16
0
    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
Beispiel #17
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
Beispiel #18
0
    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
Beispiel #19
0
    def skill_sequence_set_staff(self, seq_id, index_id, staff_id):
        if seq_id not in self.SKILL_SEQUENCE_IDS:
            raise GameException(ConfigErrorMessage.get_error_id("INVALID_OPERATE"))

        if index_id not in self.SKILL_SEQUENCE_INDEX_RANGE:
            raise GameException(ConfigErrorMessage.get_error_id("INVALID_OPERATE"))

        skill_sequence = self.doc.get('skill_sequence', {})
        if staff_id == "":
            # 下人
            try:
                skill_sequence[str(seq_id)][index_id] = ""
            except (KeyError, IndexError):
                raise GameException(ConfigErrorMessage.get_error_id("INVALID_OPERATE"))
        else:
            # 上人,检查是否在阵型中
            if not self.is_staff_in_formation(staff_id):
                raise GameException(ConfigErrorMessage.get_error_id("FORMATION_STAFF_NOT_IN"))

            staffs = skill_sequence.get(str(seq_id), ["", "", ""])
            if staff_id in staffs:
                raise GameException(ConfigErrorMessage.get_error_id("SKILL_SEQUENCE_CAN_NOT_SAME"))

            staffs[index_id] = staff_id
            skill_sequence[str(seq_id)] = staffs

        self.doc['skill_sequence'] = skill_sequence
        self.MONGO_COLLECTION.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'skill_sequence': skill_sequence
            }}
        )
Beispiel #20
0
    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
Beispiel #21
0
    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
Beispiel #22
0
    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
        )
Beispiel #23
0
    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
Beispiel #24
0
    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)
Beispiel #25
0
    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)
Beispiel #26
0
    def speedup(self):
        if not self.doc['item_id']:
            raise GameException(ConfigErrorMessage.get_error_id("SPECIAL_EQUIPMENT_NOT_IN_PROCESS"))

        seconds = self.doc['finish_at'] - arrow.utcnow().timestamp
        if seconds <= 0:
            raise GameException(ConfigErrorMessage.get_error_id("SPECIAL_EQUIPMENT_ALREADY_FINISHED"))

        minutes, remained = divmod(seconds, 60)
        if remained:
            minutes += 1

        diamond = minutes * GlobalConfig.value("EQUIPMENT_SPECIAL_SPEEDUP_PARAM") * 0.1
        diamond = int(diamond)
        cost = [(money_text_to_item_id('diamond'), diamond)]

        rc = ResourceClassification.classify(cost)
        rc.check_exist(self.server_id, self.char_id)
        rc.remove(self.server_id, self.char_id, message="SpecialEquipmentGenerator.speedup")

        # make sure is finished
        self.doc['finish_at'] = arrow.utcnow().timestamp - 1
        MongoSpecialEquipment.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'finish_at': self.doc['finish_at']
            }}
        )

        self.send_notify()
Beispiel #27
0
    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
Beispiel #28
0
    def start(self, challenge_id, formation_slots=None):
        config = ConfigChallengeMatch.get(challenge_id)
        if not config:
            raise GameException(ConfigErrorMessage.get_error_id("CHALLENGE_NOT_EXIST"))

        if config.condition_challenge:
            doc = MongoChallenge.db(self.server_id).find_one(
                {'_id': self.char_id},
                {'challenge_star.{0}'.format(config.condition_challenge): 1}
            )

            if str(config.condition_challenge) not in doc['challenge_star']:
                raise GameException(ConfigErrorMessage.get_error_id("CHALLENGE_NOT_OPEN"))

        rt = RemainedTimes(self.server_id, self.char_id, challenge_id)
        if not rt.remained_match_times:
            raise GameException(ConfigErrorMessage.get_error_id("CHALLENGE_WITHOUT_TIMES"))

        f = Formation(self.server_id, self.char_id)
        if formation_slots:
            f.sync_slots(formation_slots)

        Energy(self.server_id, self.char_id).check(config.energy)

        club_one = Club(self.server_id, self.char_id)
        club_two = ChallengeNPCClub(challenge_id)
        match = ClubMatch(club_one, club_two, 6, f.get_skill_sequence(), {})
        msg = match.start()
        msg.key = str(challenge_id)
        msg.map_name = config.map_name
        return msg
Beispiel #29
0
    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()
Beispiel #30
0
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
Beispiel #31
0
    def find_search_target_index_by_target_id(self, target_id):
        target_id = str(target_id)
        for index, s in enumerate(self.doc['search']):
            if str(s['id']) == target_id:
                return index

        raise GameException(
            ConfigErrorMessage.get_error_id("PLUNDER_CANNOT_FIND_TARGET"))
Beispiel #32
0
 def test_speedup_slot_empty(self):
     try:
         TrainingProperty(1, 1).speedup(self.staff_id, 1)
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id(
             'TRAINING_PROPERTY_SPEEDUP_CANNOT_EMPTY')
     else:
         raise Exception('error')
Beispiel #33
0
 def test_delte_not_exist(self):
     try:
         Notification(1, 1).delete("xxxxx")
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id(
             "NOTIFICATION_NOT_EXIST")
     else:
         raise Exception("can not be here!")
Beispiel #34
0
 def test_cancel_not_broadcast(self):
     try:
         TrainingBroadcast(1, 1).cancel(1)
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id(
             "TRAINING_BROADCAST_NOT_TRAINING")
     else:
         raise Exception('Error')
Beispiel #35
0
    def check_work_card(self, amount):
        new_amount = self.doc['work_card'] - amount
        if new_amount < 0:
            raise GameException(
                ConfigErrorMessage.get_error_id(
                    "TERRITORY_WORK_CARD_NOT_ENOUGH"))

        return new_amount
Beispiel #36
0
 def test_start_not_open(self):
     sponsor_id = self.get_one_not_open_sponsor()
     try:
         TrainingSponsor(1, 1).start(sponsor_id)
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id("TRAINING_SPONSOR_NOT_OPEN")
     else:
         raise Exception("error")
Beispiel #37
0
    def set_unit(self, way_id, slot_id, unit_id):
        if slot_id not in [1, 2, 3]:
            raise GameException(
                ConfigErrorMessage.get_error_id("INVALID_OPERATE"))

        w = self.get_way_object(way_id)
        w.set_unit(slot_id, unit_id)
        self.send_formation_notify()
Beispiel #38
0
 def test_get_reward(self):
     try:
         ActivityLoginReward(1, 1).get_reward(10)
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id(
             "LOGIN_REWARD_NOT_TO_TIME")
     else:
         raise Exception("can not be here!")
Beispiel #39
0
 def test_start_in_broadcasting(self):
     TrainingBroadcast(1, 1).start(1, self.staff_id)
     try:
         TrainingShop(1, 1).start(1, self.staff_id)
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id(
             "TRAINING_DOING_BROADCAST")
     else:
         raise Exception('Error')
Beispiel #40
0
 def test_set_staffs_not_own(self):
     staff_ids = random.sample(ConfigStaff.INSTANCES.keys(), 10)
     try:
         Club(1, 1).set_match_staffs(staff_ids)
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id(
             "STAFF_NOT_EXIST")
     else:
         raise RuntimeError("can not be here!")
Beispiel #41
0
    def auto_refresh(self, tp):
        if tp not in ALL_TYPES:
            raise GameException(
                ConfigErrorMessage.get_error_id("INVALID_OPERATE"))

        if self.next_auto_refresh_timestamp(tp) > arrow.utcnow().timestamp:
            return

        self.make_refresh(tp, set_timestamp=True)
Beispiel #42
0
 def test_upgrade_speedup_can_not(self):
     skills = SkillManager(1, 1).get_staff_skills(self.staff_id)
     skill_id = random.choice(skills.keys())
     try:
         SkillManager(1, 1).upgrade_speedup(self.staff_id, int(skill_id))
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id("SKILL_UPGRADE_SPEEDUP_CANNOT")
     else:
         raise Exception('error')
Beispiel #43
0
 def test_buy_not_exist(self):
     l = LadderStore(1, 1)
     try:
         l.buy(9999999999)
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id(
             "LADDER_STORE_ITEM_NOT_EXIST")
     else:
         raise Exception("can not be here!")
Beispiel #44
0
 def test_start_item_not_enough(self):
     try:
         TrainingProperty(1, 1).start(self.staff_id,
                                      get_one_available_training(1))
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id(
             "ITEM_NOT_ENOUGH")
     else:
         raise Exception('error')
Beispiel #45
0
 def check_product(self, items):
     # items: [(_id, amount),]
     for _id, amount in items:
         building_id = TERRITORY_PRODUCT_BUILDING_TABLE[_id]
         if self.doc['buildings'][str(
                 building_id)]['product_amount'] < amount:
             raise GameException(
                 ConfigErrorMessage.get_error_id(
                     "ITEM_{0}_NOT_ENOUGH".format(_id)))
Beispiel #46
0
 def test_start_signing(self):
     sponsor_id = self.open_sponsor()
     try:
         TrainingSponsor(1, 1).start(sponsor_id)
         TrainingSponsor(1, 1).start(sponsor_id)
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id("TRAINING_SPONSOR_ALREADY_START")
     else:
         raise Exception("error")
Beispiel #47
0
 def test_start_doing_shop(self):
     TrainingShop(1, 1).start(1, self.staff_id)
     try:
         TrainingBroadcast(1, 1).start(1, self.staff_id)
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id(
             "TRAINING_DOING_SHOP")
     else:
         raise Exception('error')
Beispiel #48
0
 def test_speedup_not_enough_diamond(self):
     try:
         TrainingBroadcast(1, 1).start(1, self.staff_id)
         TrainingBroadcast(1, 1).speedup(1)
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id(
             "DIAMOND_NOT_ENOUGH")
     else:
         raise Exception('Error')
Beispiel #49
0
 def test_get_reward_not_finish(self):
     TrainingBroadcast(1, 1).start(1, int(self.staff_id))
     try:
         TrainingBroadcast(1, 1).get_reward(1)
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id(
             "TRAINING_BROADCAST_NOT_FINISH")
     else:
         raise Exception('error')
Beispiel #50
0
 def test_check_talent_points_not_enough(self):
     amount = 10000
     try:
         TalentManager(self.server_id,
                       self.char_id).check_talent_points(amount)
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id("BAD_MESSAGE")
     else:
         Exception('Error')
Beispiel #51
0
 def test_start_slot_not_empty(self):
     TrainingBroadcast(1, 1).start(1, self.staff_id)
     try:
         TrainingBroadcast(1, 1).start(1, self.staff_id)
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id(
             "TRAINING_BROADCAST_NOT_EMPTY")
     else:
         raise Exception('Error')
Beispiel #52
0
    def wrap(self, *args, **kwargs):
        now = arrow.utcnow().to(settings.TIME_ZONE)
        for (_h1, _m1), (_h2, _m2) in TIME_LIMIT:
            if _h1 <= now.hour <= _h2 and _m1 <= now.minute < _m2:
                raise GameException(
                    ConfigErrorMessage.get_error_id(
                        "CHAMPIONSHIP_FORMATION_FORBIDDEN"))

        return fun(self, *args, **kwargs)
Beispiel #53
0
    def test_accept_error(self):
        self.make_friend_request()

        try:
            FriendManager(1, 1).accept(2)
        except GameException as e:
            assert e.error_id == ConfigErrorMessage.get_error_id("FRIEND_ACCEPT_ERROR")
        else:
            raise Exception('test_accept_error error')
Beispiel #54
0
    def test_add_request_already_sent(self):
        self.make_friend_request()

        try:
            FriendManager(1, 1).add('two')
        except GameException as e:
            assert e.error_id == ConfigErrorMessage.get_error_id('FRIEND_ADD_REQUEST_ALREADY_SENT')
        else:
            raise Exception('add_request_sended error')
Beispiel #55
0
    def test_get_reward_can_not(self):
        i = random.choice(ConfigActiveReward.INSTANCES.keys())

        try:
            ActiveValue(1, 1).get_reward(i)
        except GameException as e:
            assert e.error_id == ConfigErrorMessage.get_error_id(
                "ACTIVE_REWARD_CAN_NOT_GET")
        else:
            raise Exception("can not be here!")
Beispiel #56
0
    def set_staff(self, way_id, slot_id, staff_id):
        way_list = [1, 2, 3]
        if way_id not in way_list:
            raise GameException(
                ConfigErrorMessage.get_error_id("INVALID_OPERATE"))

        if slot_id not in [1, 2, 3]:
            raise GameException(
                ConfigErrorMessage.get_error_id("INVALID_OPERATE"))

        way_list.remove(way_id)
        for i in way_list:
            w = self.get_way_object(i)
            w.try_unset_staff(staff_id)

        w = self.get_way_object(way_id)
        w.set_staff(slot_id, staff_id)

        self.send_formation_notify()
Beispiel #57
0
 def test_start_doing_exp(self):
     set_enough_gold_and_diamond(self.staff_id)
     TrainingExp(1, 1).start(1, self.staff_id)
     try:
         TrainingBroadcast(1, 1).start(1, self.staff_id)
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id(
             "TRAINING_DOING_EXP")
     else:
         raise Exception('error')
Beispiel #58
0
 def test_start_times_limit(self):
     Dungeon(self.server_id, self.char_id).report(1, 2)
     try:
         Dungeon(self.server_id, self.char_id).start(1)
     except GameException as e:
         print e.error_id
         assert e.error_id == ConfigErrorMessage.get_error_id(
             "DUNGEON_NO_TIMES")
     else:
         raise Exception('error')
Beispiel #59
0
    def get_attachment(self, mail_id):
        this_mail = self.get_mail(mail_id)
        if not this_mail:
            raise GameException(ConfigErrorMessage.get_error_id("MAIL_NOT_EXISTS"))

        attachment = this_mail['attachment']
        if not attachment:
            raise GameException(ConfigErrorMessage.get_error_id("MAIL_HAS_NO_ATTACHMENT"))

        rc = ResourceClassification.load_from_json(attachment)
        rc.add(self.server_id, self.char_id, message="MailManager.get_attachment")

        MongoMail.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {'mails.{0}.attachment'.format(mail_id): ""}}
        )

        self.send_notify(ids=[mail_id])
        return rc
Beispiel #60
0
 def test_start_staff_in_training(self):
     TrainingShop(1, 1).open([2])
     TrainingShop(1, 1).start(2, self.staff_id)
     try:
         TrainingShop(1, 1).start(1, self.staff_id)
     except GameException as e:
         assert e.error_id == ConfigErrorMessage.get_error_id(
             "TRAINING_SHOP_STAFF_IN_TRAINING")
     else:
         raise Exception('error')