Пример #1
0
    def be_beaten(self, self_score, rival_score, win, rival_id):
        score = calculate_score(self_score, rival_score, win)
        self.set_score(score)

        rival_name = get_char_property(rival_id, 'name')

        record = MongoEmbeddedArenaBeatenRecord()
        record.name = rival_name
        record.old_score = self_score
        record.new_score = score

        self.mongo_arena.beaten_record.append(record)
        self.mongo_arena.save()
Пример #2
0
    def someone_refuse_me(self, from_id):
        from_id = int(from_id)
        if from_id in self.mf.pending:
            self.mf.pending.remove(from_id)
        self.mf.save()

        from_char_name = get_char_property(from_id, 'name')

        mail = Mail(self.char_id)
        mail.add(MAIL_FRIEND_REFUSE_TITLE,
                 MAIL_FRIEND_REFUSE_CONTENT.format(from_char_name))

        self.send_remove_friend_notify([from_id])
        self.send_friends_amount_notify()
Пример #3
0
    def someone_refuse_me(self, from_id):
        from_id = int(from_id)
        if from_id in self.mf.pending:
            self.mf.pending.remove(from_id)
        self.mf.save()

        from_char_name = get_char_property(from_id, 'name')

        mail = Mail(self.char_id)
        mail.add(
            MAIL_FRIEND_REFUSE_TITLE,
            MAIL_FRIEND_REFUSE_CONTENT.format(from_char_name)
        )

        self.send_remove_friend_notify([from_id])
        self.send_friends_amount_notify()
Пример #4
0
    def make_log_message(self, boss_id):
        try:
            this_boss = self.mongo_boss.opened[str(boss_id)]
        except KeyError:
            raise SanguoException(
                errormsg.INVALID_OPERATE,
                self.char_id,
                "UnionBoss Get Log",
                "no log for boss {0}".format(boss_id)
            )

        hp = float(UNION_BOSS[boss_id].hp)

        msg = protomsg.UnionBossGetLogResponse()
        msg.ret = 0
        msg.boss_id = boss_id

        logs = []

        for log in self.get_battle_members_in_ordered(boss_id):
            msg_log = protomsg.UnionBossGetLogResponse.BossLog()
            msg_log.char_id = log.char_id
            msg_log.char_name = get_char_property(log.char_id, 'name')
            msg_log.damage = log.damage
            msg_log.precent = int(log.damage/hp * 100)

            logs.append(msg_log)

        if this_boss.killer:
            for log in logs:
                if log.char_id == this_boss.killer:
                    msg.killer.MergeFrom(log)
                    break

        for log in logs[:UNION_BOSS_REWARD_LOWEST_RANK]:
            msg_log = msg.logs.add()
            msg_log.MergeFrom(log)

        return msg
Пример #5
0
    def make_log_message(self, boss_id):
        try:
            this_boss = self.mongo_boss.opened[str(boss_id)]
        except KeyError:
            raise SanguoException(errormsg.INVALID_OPERATE, self.char_id,
                                  "UnionBoss Get Log",
                                  "no log for boss {0}".format(boss_id))

        hp = float(UNION_BOSS[boss_id].hp)

        msg = protomsg.UnionBossGetLogResponse()
        msg.ret = 0
        msg.boss_id = boss_id

        logs = []

        for log in self.get_battle_members_in_ordered(boss_id):
            msg_log = protomsg.UnionBossGetLogResponse.BossLog()
            msg_log.char_id = log.char_id
            msg_log.char_name = get_char_property(log.char_id, 'name')
            msg_log.damage = log.damage
            msg_log.precent = int(log.damage / hp * 100)

            logs.append(msg_log)

        if this_boss.killer:
            for log in logs:
                if log.char_id == this_boss.killer:
                    msg.killer.MergeFrom(log)
                    break

        for log in logs[:UNION_BOSS_REWARD_LOWEST_RANK]:
            msg_log = msg.logs.add()
            msg_log.MergeFrom(log)

        return msg
Пример #6
0
 def get_current_value(self, char_id):
     from core.character import get_char_property
     return get_char_property(char_id, 'vip')
Пример #7
0
    def cronjob_auto_transfer_union(cls):
        transfer_dict = {}

        now = arrow.utcnow()
        local_date = now.to(settings.TIME_ZONE).date()
        timestamp = now.timestamp - 3600 * 24 * 3

        unions = MongoUnion._get_collection().find({}, {'owner': 1})
        owner_union_id_dict = {doc['owner']: doc['_id'] for doc in unions}

        conditions = {
            '$and': [{
                '_id': {
                    '$in': owner_union_id_dict.keys()
                }
            }, {
                'last_checkin_timestamp': {
                    '$lte': timestamp
                }
            }]
        }

        member_docs = MongoUnionMember._get_collection().find(
            conditions, {'last_checkin_timestamp': 1})

        for doc in member_docs:
            char_id = doc['_id']
            union_id = owner_union_id_dict[char_id]

            last_checkin_date = arrow.get(doc['last_checkin_timestamp']).to(
                settings.TIME_ZONE).date()
            days = (local_date - last_checkin_date).days
            # 昨天签到了,今天检测的时候, days 就是1
            # 但是从逻辑上看,应该是连续签到的,
            # 前天签到,昨天没有,今天检测的时候,days是2
            # 逻辑看来是已经 一天 没有签到了
            # 所以 days 在这里 -1
            days -= 1

            if days < 3:
                continue

            u = Union(char_id, union_id)
            if days >= 7:
                # transfer
                next_owner = u.find_next_owner()

                transfer_dict[union_id] = (char_id, next_owner)
                if next_owner:
                    u.transfer(next_owner)

                    m = Mail(char_id)
                    m.add(
                        MAIL_UNION_OWNER_TRANSFER_DONE_TITLE,
                        MAIL_UNION_OWNER_TRANSFER_DONE_CONTENT.format(
                            get_char_property(char_id, 'name')))
            else:
                members = u.member_list
                for mid in members:
                    m = Mail(mid)
                    m.add(
                        MAIL_UNION_OWNER_TRANSFER_NOTIFY_TITLE,
                        MAIL_UNION_OWNER_TRANSFER_NOTIFY_CONTENT.format(days))

        return transfer_dict
Пример #8
0
    def cronjob_auto_transfer_union(cls):
        transfer_dict = {}

        now = arrow.utcnow()
        local_date = now.to(settings.TIME_ZONE).date()
        timestamp = now.timestamp - 3600 * 24 * 3

        unions = MongoUnion._get_collection().find({}, {'owner': 1})
        owner_union_id_dict = {doc['owner']: doc['_id'] for doc in unions}

        conditions = {
            '$and': [
                {'_id': {'$in': owner_union_id_dict.keys()}},
                {'last_checkin_timestamp': {'$lte': timestamp}}
            ]
        }

        member_docs = MongoUnionMember._get_collection().find(
                conditions,
                {'last_checkin_timestamp':1}
        )

        for doc in member_docs:
            char_id = doc['_id']
            union_id = owner_union_id_dict[char_id]

            last_checkin_date = arrow.get(doc['last_checkin_timestamp']).to(settings.TIME_ZONE).date()
            days = (local_date - last_checkin_date).days
            # 昨天签到了,今天检测的时候, days 就是1
            # 但是从逻辑上看,应该是连续签到的,
            # 前天签到,昨天没有,今天检测的时候,days是2
            # 逻辑看来是已经 一天 没有签到了
            # 所以 days 在这里 -1
            days -= 1

            if days < 3:
                continue

            u = Union(char_id, union_id)
            if days >= 7:
                # transfer
                next_owner = u.find_next_owner()

                transfer_dict[union_id] = (char_id, next_owner)
                if next_owner:
                    u.transfer(next_owner)

                    m = Mail(char_id)
                    m.add(
                        MAIL_UNION_OWNER_TRANSFER_DONE_TITLE,
                        MAIL_UNION_OWNER_TRANSFER_DONE_CONTENT.format(get_char_property(char_id, 'name'))
                    )
            else:
                members = u.member_list
                for mid in members:
                    m = Mail(mid)
                    m.add(
                        MAIL_UNION_OWNER_TRANSFER_NOTIFY_TITLE,
                        MAIL_UNION_OWNER_TRANSFER_NOTIFY_CONTENT.format(days)
                    )

        return transfer_dict