예제 #1
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()
예제 #2
0
파일: union.py 프로젝트: yueyoum/dianjing
def get_members_ordered_by_explore_point(server_id, char_id, names=True, limit=None):
    """

    :rtype: (list[_ExploreMember], _ExploreMember | None)
    """
    docs = MongoUnionMember.db(server_id).find(
        {'explore_point': {'$gt': 0}}
    ).sort('explore_point', -1)

    result = []
    """:type: list[_ExploreMember]"""
    self_info = None
    """:type: _ExploreMember | None"""

    for index, doc in enumerate(docs):
        rank = index + 1
        if limit and rank > limit:
            break

        obj = _ExploreMember()
        obj.rank = rank
        obj.id = doc['_id']
        obj.explore_point = doc['explore_point']

        result.append(obj)

        if doc['_id'] == char_id:
            self_info = obj

    if names:
        # find names
        char_ids = [r.id for r in result]
        names = batch_get_club_property(server_id, char_ids, 'name')
        for r in result:
            r.name = names[r.id]

    if char_id == 0:
        return result, None

    if self_info:
        return result, self_info

    doc = MongoUnionMember.db(server_id).find_one({'_id': char_id}, {'explore_point': 1})
    if not doc:
        return result, None

    self_info = _ExploreMember()
    self_info.id = char_id
    self_info.name = get_club_property(server_id, char_id, 'name')
    self_info.explore_point = doc.get('explore_point', 0)
    if not self_info.explore_point:
        self_info.rank = 0
        return result, self_info

    rank = MongoUnionMember.db(server_id).find(
        {'explore_point': {'$gt': self_info.explore_point}}
    ).count()

    self_info.rank = rank
    return result, self_info
예제 #3
0
파일: union.py 프로젝트: yueyoum/dianjing
    def add_explore_point(self, point):
        # point 如果大于零,就是给自己和公会都加
        # 如果小于零,只减公会的
        if point > 0:
            self.member_doc['explore_point'] = self.member_doc.get('explore_point', 0) + point
            MongoUnionMember.db(self.server_id).update_one(
                {'_id': self.char_id},
                {'$inc': {
                    'explore_point': point
                }}
            )

            self.union_doc['explore_point'] = self.union_doc.get('explore_point', 0) + point
            MongoUnion.db(self.server_id).update_one(
                {'_id': self.union_doc['_id']},
                {'$inc': {
                    'explore_point': point
                }}
            )

        elif point < 0:
            old_point = self.union_doc.get('explore_point', 0)
            if abs(point) > old_point:
                point = -old_point

            self.union_doc['explore_point'] = old_point + point
            MongoUnion.db(self.server_id).update_one(
                {'_id': self.union_doc['_id']},
                {'$inc': {
                    'explore_point': point
                }}
            )
예제 #4
0
    def create(self, name):
        cost = [(money_text_to_item_id('diamond'),
                 GlobalConfig.value("UNION_CREATE_COST"))]
        rc = ResourceClassification.classify(cost)
        rc.check_exist(self.server_id, self.char_id)

        doc = MongoUnion.document()
        doc['_id'] = make_string_id()
        doc['create_at'] = arrow.utcnow().timestamp
        doc['name'] = name
        doc['owner'] = self.char_id

        try:
            MongoUnion.db(self.server_id).insert_one(doc)
        except DuplicateKeyError:
            raise GameException(
                ConfigErrorMessage.get_error_id("UNION_NAME_HAS_TAKEN"))

        MongoUnionMember.db(self.server_id).update_one({'_id': self.char_id}, {
            '$set': {
                'joined': doc['_id'],
                'joined_at': arrow.utcnow().timestamp
            }
        })

        rc.remove(self.server_id, self.char_id, message="Union.create")
        Union(self.server_id, self.char_id).send_all_notify()
예제 #5
0
    def add_explore_point(self, point):
        # point 如果大于零,就是给自己和公会都加
        # 如果小于零,只减公会的
        if point > 0:
            self.member_doc['explore_point'] = self.member_doc.get(
                'explore_point', 0) + point
            MongoUnionMember.db(self.server_id).update_one(
                {'_id': self.char_id}, {'$inc': {
                    'explore_point': point
                }})

            self.union_doc['explore_point'] = self.union_doc.get(
                'explore_point', 0) + point
            MongoUnion.db(self.server_id).update_one(
                {'_id': self.union_doc['_id']},
                {'$inc': {
                    'explore_point': point
                }})

        elif point < 0:
            old_point = self.union_doc.get('explore_point', 0)
            if abs(point) > old_point:
                point = -old_point

            self.union_doc['explore_point'] = old_point + point
            MongoUnion.db(self.server_id).update_one(
                {'_id': self.union_doc['_id']},
                {'$inc': {
                    'explore_point': point
                }})
예제 #6
0
파일: union.py 프로젝트: yueyoum/dianjing
    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)
예제 #7
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)
예제 #8
0
파일: union.py 프로젝트: yueyoum/dianjing
    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()
예제 #9
0
파일: union.py 프로젝트: yueyoum/dianjing
    def create(self, name):
        cost = [(money_text_to_item_id('diamond'), GlobalConfig.value("UNION_CREATE_COST"))]
        rc = ResourceClassification.classify(cost)
        rc.check_exist(self.server_id, self.char_id)

        doc = MongoUnion.document()
        doc['_id'] = make_string_id()
        doc['create_at'] = arrow.utcnow().timestamp
        doc['name'] = name
        doc['owner'] = self.char_id

        try:
            MongoUnion.db(self.server_id).insert_one(doc)
        except DuplicateKeyError:
            raise GameException(ConfigErrorMessage.get_error_id("UNION_NAME_HAS_TAKEN"))

        MongoUnionMember.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'joined': doc['_id'],
                'joined_at': arrow.utcnow().timestamp
            }}
        )

        rc.remove(self.server_id, self.char_id, message="Union.create")
        Union(self.server_id, self.char_id).send_all_notify()
예제 #10
0
파일: union.py 프로젝트: yueyoum/dianjing
    def quit(self, kick=False, send_notify=True):
        self.member_doc['joined'] = 0
        self.member_doc['joined_at'] = 0
        self.member_doc['contribution'] = 0
        self.member_doc['today_contribution'] = 0

        if kick:
            flag = 'kick_flag'
        else:
            flag = 'quit_flag'

        self.member_doc[flag] = True

        MongoUnionMember.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'joined': 0,
                'joined_at': 0,
                'contribution': 0,
                'today_contribution': 0,
                flag: True,
            }}
        )

        if send_notify:
            self.send_notify_to_all_members()
예제 #11
0
    def quit(self, kick=False, send_notify=True):
        self.member_doc['joined'] = 0
        self.member_doc['joined_at'] = 0
        self.member_doc['contribution'] = 0
        self.member_doc['today_contribution'] = 0

        if kick:
            flag = 'kick_flag'
        else:
            flag = 'quit_flag'

        self.member_doc[flag] = True

        MongoUnionMember.db(self.server_id).update_one({'_id': self.char_id}, {
            '$set': {
                'joined': 0,
                'joined_at': 0,
                'contribution': 0,
                'today_contribution': 0,
                flag: True,
            }
        })

        if send_notify:
            self.send_notify_to_all_members()
예제 #12
0
    def harass(self, union_id, staff_id):
        doc = MongoUnion.db(self.server_id).find_one({'_id': union_id},
                                                     {'owner': 1})
        if not doc:
            raise GameException(
                ConfigErrorMessage.get_error_id("UNION_NOT_EXIST"))

        staff = StaffManger(self.server_id,
                            self.char_id).get_staff_object(staff_id)

        hi = HarassInfo(self.server_id, self.char_id)
        if not hi.remained_times:
            hi.buy_times()

        if staff.oid == self.member_doc['harass_staff']:
            param = 2
        else:
            param = 1

        hi.record()

        union_coin = int(
            (math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) *
            3.5 * param)
        explore_point = int(
            (math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) * 7 *
            param)
        union_skill_point = int(
            (math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) * 5 *
            param)

        my_explore_point = int(
            (math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) * 5 *
            param)
        self.add_explore_point(my_explore_point)

        Union(self.server_id, doc['owner']).add_explore_point(-explore_point)

        reward = ConfigUnionExplore.get_harass_reward()
        reward = [(_id, _amount * param) for _id, _amount in reward]
        reward.append((UNION_COIN_ID, union_coin))
        reward.append((UNION_SKILL_POINT_ID, union_skill_point))

        rc = ResourceClassification.classify(reward)
        rc.add(self.server_id, self.char_id, message="UnionJoined.harass")

        self.member_doc['harass_staff'] = ConfigUnionExplore.get_staff_id()
        MongoUnionMember.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'harass_staff': self.member_doc['harass_staff']
            }})

        self.send_explore_notify()
        return explore_point, rc, my_explore_point
예제 #13
0
파일: union.py 프로젝트: yueyoum/dianjing
def get_unions_ordered_by_explore_point(server_id, char_id, around_rank=None):
    """

    :rtype: (list[_ExploreUnion], _ExploreUnion | None)
    """
    docs = MongoUnion.db(server_id).find(
        {'explore_point': {'$gt': 0}}
    ).sort('explore_point', -1)

    member_doc = MongoUnionMember.db(server_id).find_one(
        {'_id': char_id},
        {'joined': 1}
    )

    if not member_doc:
        self_union_id = ''
    else:
        self_union_id = member_doc['joined']

    result = []
    """:type: list[_ExploreUnion]"""
    self_info = None
    """:type: _ExploreUnion | None"""

    for index, doc in enumerate(docs):
        obj = _ExploreUnion()
        obj.rank = index + 1
        obj.id = doc['_id']
        obj.name = doc['name']
        obj.explore_point = doc['explore_point']

        result.append(obj)

        if doc['_id'] == self_union_id:
            self_info = obj

    if not around_rank:
        return result, self_info

    around_result = []

    if not self_info:
        for i in [-1, -2]:
            try:
                this_obj = result[i]
            except IndexError:
                continue

            around_result.append(this_obj)
    else:
        for i in range(self_info.rank - 1 - around_rank, self_info.rank + around_rank):
            try:
                this_obj = result[i]
            except IndexError:
                continue

            if this_obj not in around_result and this_obj.id != self_union_id:
                around_result.append(this_obj)

    return around_result, self_info
예제 #14
0
    def get_members(self):
        """

        :rtype: list[_MemberClub]
        """
        owner = self.union_doc['owner']
        docs = MongoUnionMember.db(self.server_id).find(
            {'joined': self.union_doc['_id']})

        owner_doc = None
        members = []
        for doc in docs:
            if doc['_id'] == owner:
                owner_doc = doc
                continue

            members.append(
                _MemberClub(self.server_id, doc['_id'], doc['contribution'],
                            doc['today_contribution']))

        members.sort(key=lambda item: item.contribution, reverse=True)

        if owner_doc:
            members.insert(
                0,
                _MemberClub(self.server_id, owner_doc['_id'],
                            owner_doc['contribution'],
                            owner_doc['today_contribution']))
        return members
예제 #15
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()
예제 #16
0
파일: union.py 프로젝트: yueyoum/dianjing
    def get_member_ids(self):
        docs = MongoUnionMember.db(self.server_id).find(
            {'joined': self.union_doc['_id']},
            {'_id': 1}
        )

        return [d['_id'] for d in docs]
예제 #17
0
파일: union.py 프로젝트: yueyoum/dianjing
    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()
예제 #18
0
    def add_contribution(self, value, send_notify=True):
        # 给自己加
        self.member_doc['contribution'] += value
        self.member_doc['today_contribution'] += value

        MongoUnionMember.db(self.server_id).update_one({'_id': self.char_id}, {
            '$set': {
                'contribution': self.member_doc['contribution'],
                'today_contribution': self.member_doc['today_contribution']
            }
        })

        # 给公会加
        union_contribution = self.union_doc['contribution'] + value
        level = self.union_doc['level']

        while True:
            if level >= ConfigUnionLevel.MAX_LEVEL:
                level = ConfigUnionLevel.MAX_LEVEL

                if union_contribution >= ConfigUnionLevel.get(
                        ConfigUnionLevel.MAX_LEVEL).contribution:
                    union_contribution = ConfigUnionLevel.get(
                        ConfigUnionLevel.MAX_LEVEL).contribution

                break

            up_need = ConfigUnionLevel.get(level).contribution
            if union_contribution < up_need:
                break

            union_contribution -= up_need
            level += 1

        self.union_doc['level'] = level
        self.union_doc['contribution'] = union_contribution

        MongoUnion.db(self.server_id).update_one(
            {'_id': self.union_doc['_id']},
            {'$set': {
                'level': level,
                'contribution': union_contribution
            }})

        if send_notify:
            self.send_notify()
예제 #19
0
    def explore(self, staff_id):
        staff = StaffManger(self.server_id,
                            self.char_id).get_staff_object(staff_id)

        ei = ExploreInfo(self.server_id, self.char_id)
        ei.check_cd()
        if not ei.remained_times:
            raise GameException(
                ConfigErrorMessage.get_error_id("UNION_EXPLORE_NO_TIMES"))

        if staff.oid == self.member_doc['explore_staff']:
            param = 2
        else:
            param = 1

        ei.record()

        union_coin = int(
            (math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) * 3 *
            param)
        explore_point = int(
            (math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) * 10 *
            param)
        union_skill_point = int(
            (math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) * 4 *
            param)

        self.add_explore_point(explore_point)

        reward = ConfigUnionExplore.get_explore_reward()
        reward = [(_id, _amount * param) for _id, _amount in reward]
        reward.append((UNION_COIN_ID, union_coin))
        reward.append((UNION_SKILL_POINT_ID, union_skill_point))

        rc = ResourceClassification.classify(reward)
        rc.add(self.server_id, self.char_id, message="UnionJoined.explore")

        self.member_doc['explore_staff'] = ConfigUnionExplore.get_staff_id()
        MongoUnionMember.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'explore_staff': self.member_doc['explore_staff']
            }})

        self.send_explore_notify()
        return explore_point, rc
예제 #20
0
파일: union.py 프로젝트: yueyoum/dianjing
    def add_contribution(self, value, send_notify=True):
        # 给自己加
        self.member_doc['contribution'] += value
        self.member_doc['today_contribution'] += value

        MongoUnionMember.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'contribution': self.member_doc['contribution'],
                'today_contribution': self.member_doc['today_contribution']
            }}
        )

        # 给公会加
        union_contribution = self.union_doc['contribution'] + value
        level = self.union_doc['level']

        while True:
            if level >= ConfigUnionLevel.MAX_LEVEL:
                level = ConfigUnionLevel.MAX_LEVEL

                if union_contribution >= ConfigUnionLevel.get(ConfigUnionLevel.MAX_LEVEL).contribution:
                    union_contribution = ConfigUnionLevel.get(ConfigUnionLevel.MAX_LEVEL).contribution

                break

            up_need = ConfigUnionLevel.get(level).contribution
            if union_contribution < up_need:
                break

            union_contribution -= up_need
            level += 1

        self.union_doc['level'] = level
        self.union_doc['contribution'] = union_contribution

        MongoUnion.db(self.server_id).update_one(
            {'_id': self.union_doc['_id']},
            {'$set': {
                'level': level,
                'contribution': union_contribution
            }}
        )

        if send_notify:
            self.send_notify()
예제 #21
0
파일: union.py 프로젝트: yueyoum/dianjing
    def harass(self, union_id, staff_id):
        doc = MongoUnion.db(self.server_id).find_one({'_id': union_id}, {'owner': 1})
        if not doc:
            raise GameException(ConfigErrorMessage.get_error_id("UNION_NOT_EXIST"))

        staff = StaffManger(self.server_id, self.char_id).get_staff_object(staff_id)

        hi = HarassInfo(self.server_id, self.char_id)
        if not hi.remained_times:
            hi.buy_times()

        if staff.oid == self.member_doc['harass_staff']:
            param = 2
        else:
            param = 1

        hi.record()

        union_coin = int((math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) * 3.5 * param)
        explore_point = int((math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) * 7 * param)
        union_skill_point = int((math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) * 5 * param)

        my_explore_point = int((math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) * 5 * param)
        self.add_explore_point(my_explore_point)

        Union(self.server_id, doc['owner']).add_explore_point(-explore_point)

        reward = ConfigUnionExplore.get_harass_reward()
        reward = [(_id, _amount * param) for _id, _amount in reward]
        reward.append((UNION_COIN_ID, union_coin))
        reward.append((UNION_SKILL_POINT_ID, union_skill_point))

        rc = ResourceClassification.classify(reward)
        rc.add(self.server_id, self.char_id, message="UnionJoined.harass")

        self.member_doc['harass_staff'] = ConfigUnionExplore.get_staff_id()
        MongoUnionMember.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'harass_staff': self.member_doc['harass_staff']
            }}
        )

        self.send_explore_notify()
        return explore_point, rc, my_explore_point
예제 #22
0
파일: union.py 프로젝트: yueyoum/dianjing
    def __new__(cls, server_id, char_id):
        """

        :rtype: IUnion
        """
        member_doc = MongoUnionMember.db(server_id).find_one({'_id': char_id})
        if not member_doc:
            member_doc = MongoUnionMember.document()
            member_doc['_id'] = char_id
            MongoUnionMember.db(server_id).insert_one(member_doc)

        if not member_doc['joined']:
            return UnionNotJoined(server_id, char_id, member_doc, None)

        union_doc = MongoUnion.db(server_id).find_one({'_id': member_doc['joined']})
        if union_doc['owner'] == char_id:
            return UnionOwner(server_id, char_id, member_doc, union_doc)

        return UnionMember(server_id, char_id, member_doc, union_doc)
예제 #23
0
    def __init__(self, *args, **kwargs):
        super(UnionJoined, self).__init__(*args, **kwargs)

        updater = {}
        if 'skills' not in self.member_doc:
            self.member_doc['skills'] = {}
            updater['skills'] = {}

        if not self.member_doc.get('explore_staff', 0):
            self.member_doc['explore_staff'] = ConfigUnionExplore.get_staff_id(
            )
            self.member_doc['harass_staff'] = ConfigUnionExplore.get_staff_id()

            updater['explore_staff'] = self.member_doc['explore_staff']
            updater['harass_staff'] = self.member_doc['harass_staff']

        if updater:
            MongoUnionMember.db(self.server_id).update_one(
                {'_id': self.char_id}, {'$set': updater})
예제 #24
0
    def __new__(cls, server_id, char_id):
        """

        :rtype: IUnion
        """
        member_doc = MongoUnionMember.db(server_id).find_one({'_id': char_id})
        if not member_doc:
            member_doc = MongoUnionMember.document()
            member_doc['_id'] = char_id
            MongoUnionMember.db(server_id).insert_one(member_doc)

        if not member_doc['joined']:
            return UnionNotJoined(server_id, char_id, member_doc, None)

        union_doc = MongoUnion.db(server_id).find_one(
            {'_id': member_doc['joined']})
        if union_doc['owner'] == char_id:
            return UnionOwner(server_id, char_id, member_doc, union_doc)

        return UnionMember(server_id, char_id, member_doc, union_doc)
예제 #25
0
파일: union.py 프로젝트: yueyoum/dianjing
    def __init__(self, *args, **kwargs):
        super(UnionJoined, self).__init__(*args, **kwargs)

        updater = {}
        if 'skills' not in self.member_doc:
            self.member_doc['skills'] = {}
            updater['skills'] = {}

        if not self.member_doc.get('explore_staff', 0):
            self.member_doc['explore_staff'] = ConfigUnionExplore.get_staff_id()
            self.member_doc['harass_staff'] = ConfigUnionExplore.get_staff_id()

            updater['explore_staff'] = self.member_doc['explore_staff']
            updater['harass_staff'] = self.member_doc['harass_staff']

        if updater:
            MongoUnionMember.db(self.server_id).update_one(
                {'_id': self.char_id},
                {'$set': updater}
            )
예제 #26
0
파일: union.py 프로젝트: yueyoum/dianjing
def cronjob_of_union_explore(server_id):
    members, _ = get_members_ordered_by_explore_point(server_id, 0, names=False)
    unions, _ = get_unions_ordered_by_explore_point(server_id, 0)

    MongoUnionMember.db(server_id).update_many(
        {},
        {'$set': {
            'explore_point': 0,
        }}
    )

    MongoUnion.db(server_id).update_many(
        {},
        {'$set': {
            'explore_point': 0,
        }}
    )

    for m in members:
        reward = ConfigUnionMemberExploreRankReward.get_by_rank(m.rank)
        if not reward:
            continue

        attachment = ResourceClassification.classify(reward.reward).to_json()
        m = MailManager(server_id, m.id)
        m.add(reward.mail_title, reward.mail_content, attachment=attachment)

    for u in unions:
        reward = ConfigUnionExploreRankReward.get_by_rank(u.rank)
        if not reward:
            continue

        attachment = ResourceClassification.classify(reward.reward).to_json()
        docs = MongoUnionMember.db(server_id).find(
            {'joined': u.id},
            {'_id': 1}
        )

        for doc in docs:
            m = MailManager(server_id, doc['_id'])
            m.add(reward.mail_title, reward.mail_content, attachment=attachment)
예제 #27
0
파일: union.py 프로젝트: zhifuliu/dianjing
def union_reset(*args):
    logger = Logger("union_reset")
    logger.write("Start")

    try:
        for sid in Server.duty_server_ids():
            MongoUnionMember.db(sid).update_many({}, {
                '$set': {
                    'today_contribution': 0,
                    'quit_flag': False,
                    'kick_flag': False,
                }
            })

            logger.write("Server {0} Finish".format(sid))
    except:
        logger.error(traceback.format_exc())
    else:
        logger.write("Done")
    finally:
        logger.close()
예제 #28
0
파일: union.py 프로젝트: yueyoum/dianjing
    def explore(self, staff_id):
        staff = StaffManger(self.server_id, self.char_id).get_staff_object(staff_id)

        ei = ExploreInfo(self.server_id, self.char_id)
        ei.check_cd()
        if not ei.remained_times:
            raise GameException(ConfigErrorMessage.get_error_id("UNION_EXPLORE_NO_TIMES"))

        if staff.oid == self.member_doc['explore_staff']:
            param = 2
        else:
            param = 1

        ei.record()

        union_coin = int((math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) * 3 * param)
        explore_point = int((math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) * 10 * param)
        union_skill_point = int((math.pow(staff.level, 0.2) + math.pow(staff.step + 1, 0.5)) * 4 * param)

        self.add_explore_point(explore_point)

        reward = ConfigUnionExplore.get_explore_reward()
        reward = [(_id, _amount * param) for _id, _amount in reward]
        reward.append((UNION_COIN_ID, union_coin))
        reward.append((UNION_SKILL_POINT_ID, union_skill_point))

        rc = ResourceClassification.classify(reward)
        rc.add(self.server_id, self.char_id, message="UnionJoined.explore")

        self.member_doc['explore_staff'] = ConfigUnionExplore.get_staff_id()
        MongoUnionMember.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'explore_staff': self.member_doc['explore_staff']
            }}
        )

        self.send_explore_notify()
        return explore_point, rc
예제 #29
0
파일: union.py 프로젝트: yueyoum/dianjing
def union_reset(*args):
    logger = Logger("union_reset")
    logger.write("Start")

    try:
        for sid in Server.duty_server_ids():
            MongoUnionMember.db(sid).update_many(
                {},
                {'$set': {
                    'today_contribution': 0,
                    'quit_flag': False,
                    'kick_flag': False,
                }}
            )

            logger.write("Server {0} Finish".format(sid))
    except:
        logger.error(traceback.format_exc())
    else:
        logger.write("Done")
    finally:
        logger.close()
예제 #30
0
def cronjob_of_union_explore(server_id):
    members, _ = get_members_ordered_by_explore_point(server_id,
                                                      0,
                                                      names=False)
    unions, _ = get_unions_ordered_by_explore_point(server_id, 0)

    MongoUnionMember.db(server_id).update_many(
        {}, {'$set': {
            'explore_point': 0,
        }})

    MongoUnion.db(server_id).update_many({}, {'$set': {
        'explore_point': 0,
    }})

    for m in members:
        reward = ConfigUnionMemberExploreRankReward.get_by_rank(m.rank)
        if not reward:
            continue

        attachment = ResourceClassification.classify(reward.reward).to_json()
        m = MailManager(server_id, m.id)
        m.add(reward.mail_title, reward.mail_content, attachment=attachment)

    for u in unions:
        reward = ConfigUnionExploreRankReward.get_by_rank(u.rank)
        if not reward:
            continue

        attachment = ResourceClassification.classify(reward.reward).to_json()
        docs = MongoUnionMember.db(server_id).find({'joined': u.id},
                                                   {'_id': 1})

        for doc in docs:
            m = MailManager(server_id, doc['_id'])
            m.add(reward.mail_title,
                  reward.mail_content,
                  attachment=attachment)
예제 #31
0
    def send_notify_to_all_members(self,
                                   rank=None,
                                   send_my_check_notify=False):
        if rank is None:
            rank = self.get_rank()

        docs = MongoUnionMember.db(self.server_id).find(
            {'joined': self.union_doc['_id']}, {'_id': 1})

        for doc in docs:
            u = Union(self.server_id, doc['_id'])
            u.send_notify(rank=rank)
            if send_my_check_notify:
                u.send_my_check_notify()
예제 #32
0
파일: union.py 프로젝트: yueyoum/dianjing
    def send_notify_to_all_members(self, rank=None, send_my_check_notify=False):
        if rank is None:
            rank = self.get_rank()

        docs = MongoUnionMember.db(self.server_id).find(
            {'joined': self.union_doc['_id']},
            {'_id': 1}
        )

        for doc in docs:
            u = Union(self.server_id, doc['_id'])
            u.send_notify(rank=rank)
            if send_my_check_notify:
                u.send_my_check_notify()
예제 #33
0
파일: union.py 프로젝트: yueyoum/dianjing
    def get_members(self):
        """

        :rtype: list[_MemberClub]
        """
        owner = self.union_doc['owner']
        docs = MongoUnionMember.db(self.server_id).find({'joined': self.union_doc['_id']})

        owner_doc = None
        members = []
        for doc in docs:
            if doc['_id'] == owner:
                owner_doc = doc
                continue

            members.append(_MemberClub(self.server_id, doc['_id'], doc['contribution'], doc['today_contribution']))

        members.sort(key=lambda item: item.contribution, reverse=True)

        if owner_doc:
            members.insert(0, _MemberClub(self.server_id, owner_doc['_id'], owner_doc['contribution'],
                                          owner_doc['today_contribution']))
        return members
예제 #34
0
def union_info(request):
    servers_select = get_servers_select_context()

    context = {
        'current': 'union',
        'servers_select': servers_select,
        'unions': [],
        'members': [],
    }

    sid = request.GET.get('sid', 0)
    if not sid:
        return render_to_response(
            'dianjing_statistics_union.html',
            context=context
        )

    try:
        sid = int(sid)
    except:
        raise Http404()

    context['sid'] = sid

    uid = request.GET.get('uid', '')
    if not uid:
        docs = MongoUnion.db(sid).find({}).sort('create_at', -1)

        for doc in docs:
            union_data = {
                'id': doc['_id'],
                'name': doc['name'],
                'bulletin': doc['bulletin'],
                'create_at': arrow.get(doc['create_at']).to(settings.TIME_ZONE).format("YYYY-MM-DD HH:mm:ss"),
                'owner': doc['owner'],
                'level': doc['level'],
                'contribution': doc['contribution'],
                'members_amount': MongoUnionMember.db(sid).find({'joined': doc['_id']}).count(),
            }

            context['unions'].append(union_data)

        return render_to_response(
            'dianjing_statistics_union.html',
            context=context
        )

    doc = MongoUnion.db(sid).find_one({'_id': uid})
    if not doc:
        raise Http404()

    context['unions'] = [{
        'id': doc['_id'],
        'name': doc['name'],
        'bulletin': doc['bulletin'],
        'create_at': arrow.get(doc['create_at']).to(settings.TIME_ZONE).format("YYYY-MM-DD HH:mm:ss"),
        'owner': doc['owner'],
        'level': doc['level'],
        'contribution': doc['contribution'],
        'members_amount': MongoUnionMember.db(sid).find({'joined': doc['_id']}).count(),
    }]

    docs = MongoUnionMember.db(sid).find({'joined': uid})
    for doc in docs:
        member_data = {
            'id': doc['_id'],
            'joined_at': arrow.get(doc['joined_at']).to(settings.TIME_ZONE).format("YYYY-MM-DD HH:mm:ss"),
            'contribution': doc['contribution'],
        }

        context['members'].append(member_data)

    return render_to_response(
        'dianjing_statistics_union.html',
        context=context
    )
예제 #35
0
파일: union.py 프로젝트: yueyoum/dianjing
 def get_members_amount(self):
     return MongoUnionMember.db(self.server_id).find({'joined': self.union_doc['_id']}).count()
예제 #36
0
파일: union.py 프로젝트: yueyoum/dianjing
 def members_amount(self):
     return MongoUnionMember.db(self.server_id).find({'joined': self.id}).count()
예제 #37
0
 def get_members_amount(self):
     return MongoUnionMember.db(self.server_id).find({
         'joined':
         self.union_doc['_id']
     }).count()
예제 #38
0
def get_members_ordered_by_explore_point(server_id,
                                         char_id,
                                         names=True,
                                         limit=None):
    """

    :rtype: (list[_ExploreMember], _ExploreMember | None)
    """
    docs = MongoUnionMember.db(server_id).find({
        'explore_point': {
            '$gt': 0
        }
    }).sort('explore_point', -1)

    result = []
    """:type: list[_ExploreMember]"""
    self_info = None
    """:type: _ExploreMember | None"""

    for index, doc in enumerate(docs):
        rank = index + 1
        if limit and rank > limit:
            break

        obj = _ExploreMember()
        obj.rank = rank
        obj.id = doc['_id']
        obj.explore_point = doc['explore_point']

        result.append(obj)

        if doc['_id'] == char_id:
            self_info = obj

    if names:
        # find names
        char_ids = [r.id for r in result]
        names = batch_get_club_property(server_id, char_ids, 'name')
        for r in result:
            r.name = names[r.id]

    if char_id == 0:
        return result, None

    if self_info:
        return result, self_info

    doc = MongoUnionMember.db(server_id).find_one({'_id': char_id},
                                                  {'explore_point': 1})
    if not doc:
        return result, None

    self_info = _ExploreMember()
    self_info.id = char_id
    self_info.name = get_club_property(server_id, char_id, 'name')
    self_info.explore_point = doc.get('explore_point', 0)
    if not self_info.explore_point:
        self_info.rank = 0
        return result, self_info

    rank = MongoUnionMember.db(server_id).find({
        'explore_point': {
            '$gt': self_info.explore_point
        }
    }).count()

    self_info.rank = rank
    return result, self_info
예제 #39
0
def get_unions_ordered_by_explore_point(server_id, char_id, around_rank=None):
    """

    :rtype: (list[_ExploreUnion], _ExploreUnion | None)
    """
    docs = MongoUnion.db(server_id).find({
        'explore_point': {
            '$gt': 0
        }
    }).sort('explore_point', -1)

    member_doc = MongoUnionMember.db(server_id).find_one({'_id': char_id},
                                                         {'joined': 1})

    if not member_doc:
        self_union_id = ''
    else:
        self_union_id = member_doc['joined']

    result = []
    """:type: list[_ExploreUnion]"""
    self_info = None
    """:type: _ExploreUnion | None"""

    for index, doc in enumerate(docs):
        obj = _ExploreUnion()
        obj.rank = index + 1
        obj.id = doc['_id']
        obj.name = doc['name']
        obj.explore_point = doc['explore_point']

        result.append(obj)

        if doc['_id'] == self_union_id:
            self_info = obj

    if not around_rank:
        return result, self_info

    around_result = []

    if not self_info:
        for i in [-1, -2]:
            try:
                this_obj = result[i]
            except IndexError:
                continue

            around_result.append(this_obj)
    else:
        for i in range(self_info.rank - 1 - around_rank,
                       self_info.rank + around_rank):
            try:
                this_obj = result[i]
            except IndexError:
                continue

            if this_obj not in around_result and this_obj.id != self_union_id:
                around_result.append(this_obj)

    return around_result, self_info
예제 #40
0
    def get_member_ids(self):
        docs = MongoUnionMember.db(self.server_id).find(
            {'joined': self.union_doc['_id']}, {'_id': 1})

        return [d['_id'] for d in docs]
예제 #41
0
 def members_amount(self):
     return MongoUnionMember.db(self.server_id).find({
         'joined': self.id
     }).count()