Example #1
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
Example #2
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
        )
Example #3
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)
Example #4
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
Example #5
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()
Example #6
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()
Example #7
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)
Example #8
0
    def apply_in(self):
        now = arrow.utcnow().to(settings.TIME_ZONE)
        if now.weekday() not in APPLY_WEEKDAY:
            raise GameException(
                ConfigErrorMessage.get_error_id("CHAMPIONSHIP_APPLY_NOT_OPEN"))

        range_start = make_time_of_today(APPLY_TIME_RANGE[0][0],
                                         APPLY_TIME_RANGE[0][1])
        range_end = make_time_of_today(APPLY_TIME_RANGE[1][0],
                                       APPLY_TIME_RANGE[1][1])

        if now < range_start or now >= range_end:
            raise GameException(
                ConfigErrorMessage.get_error_id("CHAMPIONSHIP_APPLY_NOT_OPEN"))

        if self.is_applied():
            raise GameException(
                ConfigErrorMessage.get_error_id(
                    "CHAMPIONSHIP_ALREADY_APPLIED"))

        self.doc['applied'] = True
        MongoChampionship.db(self.server_id).update_one(
            {'_id': self.char_id}, {'$set': {
                'applied': True
            }})

        self.send_basic_notify()
Example #9
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
Example #10
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)
Example #11
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
Example #12
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
        )
Example #13
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
            }}
        )
Example #14
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
Example #15
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
Example #16
0
def verify_stars_cloud(platform, uid, param):
    AppId = settings.THIRD_PROVIDER['stars-cloud']['appid']
    pmSecret = settings.THIRD_PROVIDER['stars-cloud']['pmsecret']

    if platform == 'uc':
        try:
            ixToken, ixTime, ixSign = json.loads(param)
        except ValueError:
            raise GameException(
                ConfigErrorMessage.get_error_id("ACCOUNT_LOGIN_FAILURE"))

        text = "{0}{1}{2}{3}{4}{5}".format(AppId, platform, uid, ixToken,
                                           ixTime, pmSecret)

        result = hashlib.md5(text).hexdigest()
        if result != ixSign:
            raise GameException(
                ConfigErrorMessage.get_error_id("ACCOUNT_LOGIN_FAILURE"))
        return

    if platform == 'SNOWFISH':
        return

    raise GameException(
        ConfigErrorMessage.get_error_id("UNSUPPORTED_PLATFORM"))
Example #17
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()
Example #18
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'
            )
Example #19
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
Example #20
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)
Example #21
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)
Example #22
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])
Example #23
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
Example #24
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)
Example #25
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
Example #26
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
Example #27
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)
Example #28
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
Example #29
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()
Example #30
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)
Example #31
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
Example #32
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)
Example #33
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
Example #34
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)
Example #35
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()
Example #36
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
Example #37
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
Example #38
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
Example #39
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
Example #40
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
Example #41
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
Example #42
0
    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
Example #43
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
Example #44
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
Example #45
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()
Example #46
0
    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
Example #47
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()
Example #48
0
    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
Example #49
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
Example #50
0
 def check_money(self, diamond=0, gold=0, crystal=0, gas=0, renown=0):
     if diamond > self.diamond:
         raise GameException(ConfigErrorMessage.get_error_id("DIAMOND_NOT_ENOUGH"))
     if gold > self.gold:
         raise GameException(ConfigErrorMessage.get_error_id("GOLD_NOT_ENOUGH"))
     if crystal > self.crystal:
         raise GameException(ConfigErrorMessage.get_error_id("CRYSTAL_NOT_ENOUGH"))
     if gas > self.gas:
         raise GameException(ConfigErrorMessage.get_error_id("GAS_NOT_ENOUGH"))
     if renown > self.renown:
         raise GameException(ConfigErrorMessage.get_error_id("RENOWN_NOT_ENOUGH"))
Example #51
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
Example #52
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()
Example #53
0
def third_login(provider, platform, uid, param):
    if not provider or not platform or not uid:
        raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))

    if provider == '1sdk':
        verify_1sdk(platform, uid, param)
    elif provider == 'stars-cloud':
        verify_stars_cloud(platform, uid, param)
    else:
        raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))

    return get_or_create_third_account(provider, platform, uid)
Example #54
0
    def _sweep_check(self):
        if not self.doc['max_star_level']:
            raise GameException(ConfigErrorMessage.get_error_id("TOWER_NO_MAX_STAR_LEVEL"))

        if -1 in self.doc['levels'].values():
            raise GameException(ConfigErrorMessage.get_error_id("TOWER_CANNOT_TO_MAX_LEVEL_HAS_FAILURE"))

        levels_amount = self.doc['max_star_level'] - self.get_current_level()
        if levels_amount <= 0:
            raise GameException(ConfigErrorMessage.get_error_id("TOWER_CURRENT_LEVEL_GREAT_THAN_MAX_STAR_LEVEL"))

        return levels_amount
Example #55
0
    def check_exists(self, server_id, char_id):
        doc = MongoResource.db(server_id).find_one({'_id': char_id})
        if not doc:
            raise GameException(
                ConfigErrorMessage.get_error_id("RESOURCE_NOT_ENOUGH"))

        for k, v in self.resource.iteritems():
            if v > doc['resource'].get(str(k), 0):
                raise GameException(
                    ConfigErrorMessage.get_error_id("RESOURCE_NOT_ENOUGH"))

        return doc
Example #56
0
    def equipment_change(self, bag_slot_id, tp):
        # 会影响的其他staff_id
        other_staff_id = ""

        if not bag_slot_id:
            # 卸下
            bag_slot_id = ""
        else:
            # 更换
            bag = Bag(self.server_id, self.char_id)
            slot = bag.get_slot(bag_slot_id)

            item_id = slot['item_id']
            if get_item_type(item_id) != TYPE_EQUIPMENT:
                raise GameException(
                    ConfigErrorMessage.get_error_id("INVALID_OPERATE"))

            equip_config = ConfigEquipmentNew.get(item_id)
            if equip_config.tp != tp:
                raise GameException(
                    ConfigErrorMessage.get_error_id(
                        "EQUIPMENT_TYPE_NOT_MATCH"))

            other_staff_id = StaffManger(
                self.server_id,
                self.char_id).find_staff_id_by_equipment_slot_id(bag_slot_id)

        if tp == EQUIP_MOUSE:
            key = 'equip_mouse'
        elif tp == EQUIP_KEYBOARD:
            key = 'equip_keyboard'
        elif tp == EQUIP_MONITOR:
            key = 'equip_monitor'
        elif tp == EQUIP_DECORATION:
            key = 'equip_decoration'
        elif tp == EQUIP_SPECIAL:
            key = 'equip_special'
        else:
            raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))

        setattr(self, key, bag_slot_id)
        MongoStaff.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'staffs.{0}.{1}'.format(self.id, key): bag_slot_id
            }})

        self.calculate()
        self.make_cache()

        return other_staff_id