Example #1
0
    def process(self, from_group: int, from_qq: int, command_list: List[str]):
        # %game register lightless233

        # 初始化数据
        self.from_qq = from_qq
        self.from_group = from_group

        # 1 检查该QQ是否已经有角色了
        has_pc = False
        with db:
            try:
                PlayerInfoModel.get(PlayerInfoModel.qq == from_qq)
                has_pc = True
            except DoesNotExist:
                pass
        if has_pc:
            self.send_msg(utils.build_at_msg(from_qq) + "\n已经有角色啦!暂不支持多个角色!")
            return

        # 2 创建角色
        try:
            nickname = command_list[2]
        except IndexError:
            self.send_msg(utils.build_at_msg(from_qq) + f"\n格式:{self.err_msg}")
            return

        with db:
            player = PlayerInfoModel()
            player.qq = from_qq
            player.nickname = nickname
            player.save()

        self.send_msg(utils.build_at_msg(from_qq) + "\n注册成功!")
Example #2
0
    def process(self):
        self.logger.info(f"{self.name} execute!")

        with db:
            # 1. 取出所有hp和sp不满的玩家
            players: dict = PlayerInfoModel.select().where(
                (PlayerInfoModel.sp_max != PlayerInfoModel.sp_current) |
                (PlayerInfoModel.hp_max != PlayerInfoModel.hp_current)
            ).dicts()

            if len(players) == 0:
                return

            self.logger.info(f"[{self.name}] 有{len(players)}个记录需要更新")

            # 2. 检查这些玩家下次的恢复时间,如果当前时间大于下次恢复时间
            # 如果regain表中没有对应的玩家信息,那么就添加进去
            for player in players:
                qq = player.get("qq")
                try:
                    pc_regain = RegainModel.get(RegainModel.qq == qq)
                except DoesNotExist:
                    pc_regain = RegainModel.create(qq=qq)

                # 获取当前的时间戳
                current_ts = int(time.time())

                self.logger.info(
                    f"[{self.name}] next_hp_ts: {pc_regain.hp_next_time}, next_sp_ts: {pc_regain.sp_next_time}")

                if isinstance(pc_regain.hp_next_time, str):
                    next_hp_ts = time.mktime(
                        datetime.datetime.strptime(pc_regain.hp_next_time, "%Y-%m-%d %H:%M:%S").timetuple())
                    next_sp_ts = time.mktime(
                        datetime.datetime.strptime(pc_regain.sp_next_time, "%Y-%m-%d %H:%M:%S").timetuple())
                else:
                    next_hp_ts = time.mktime(pc_regain.hp_next_time.timetuple())
                    next_sp_ts = time.mktime(pc_regain.sp_next_time.timetuple())

                # 更新hp
                hp_max = player.get("hp_max")
                hp_current = player.get("hp_current")
                if current_ts >= next_hp_ts and hp_max > hp_current:
                    if hp_current + 10 <= hp_max:
                        self.player_service.update_player_hp(qq, 10)
                    else:
                        self.player_service.update_player_hp(qq, hp_max - hp_current)
                    # 重置下次更新时间
                    self.regain_service.update_next_hp_time(qq)

                # 更新sp
                sp_max = player.get("sp_max")
                sp_current = player.get("sp_current")
                if current_ts >= next_sp_ts and sp_max > sp_current:
                    if sp_current + 1 <= sp_max:
                        self.player_service.update_player_sp(qq, 1)
                    else:
                        self.player_service.update_player_sp(qq, sp_max - sp_current)
                    # 重置下次更新时间
                    self.regain_service.update_next_sp_time(qq)
Example #3
0
    def update_player_prop(self, prop, qq, pt):
        with db:
            if prop == "STR":
                query = PlayerInfoModel \
                    .update(base_str=PlayerInfoModel.base_str + pt, rest_pt=PlayerInfoModel.rest_pt - pt) \
                    .where(PlayerInfoModel.qq == qq)
            elif prop == "AGI":
                query = PlayerInfoModel \
                    .update(base_agi=PlayerInfoModel.base_agi + pt, rest_pt=PlayerInfoModel.rest_pt - pt) \
                    .where(PlayerInfoModel.qq == qq)
            elif prop == "VIT":
                query = PlayerInfoModel \
                    .update(base_vit=PlayerInfoModel.base_vit + pt, rest_pt=PlayerInfoModel.rest_pt - pt) \
                    .where(PlayerInfoModel.qq == qq)
            else:
                return None
            query.execute()

            # 一级属性更新完成,计算二级属性
            pc: PlayerInfoModel = self.get_player_info_by_qq(qq)
            new_props = PropertiesTools.calc_properties(
                pc.level, pc.base_str, pc.base_vit, pc.base_agi)
            query = PlayerInfoModel.update(
                hp_max=new_props.get("hp"),
                sp_max=new_props.get("sp"),
                atk=new_props.get("atk"),
                defe=new_props.get("def"),
                cri=new_props.get("cri"),
                hit=new_props.get("hit"),
                eva=new_props.get("eva"),
            ).where(PlayerInfoModel.qq == qq)

            return query.execute()
Example #4
0
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
"""
    test_db.py
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    $END$

    :author:    lightless <*****@*****.**>
    :homepage:  None
    :license:   GPL-3.0, see LICENSE for more details.
    :copyright: Copyright (c) 2017-2020 lightless. All rights reserved
"""

from models.player import PlayerInfoModel

players = PlayerInfoModel.select().where(
    PlayerInfoModel.sp_max != PlayerInfoModel.sp_current,
    PlayerInfoModel.hp_max != PlayerInfoModel.hp_current).dicts()

print(len(players))

for player in players:
    print(player)
Example #5
0
 def update_player_sp(self, qq, value):
     with db:
         query = PlayerInfoModel.update(
             sp_current=PlayerInfoModel.sp_current +
             value).where(PlayerInfoModel.qq == qq)
         return query.execute()
Example #6
0
 def get_player_info_by_qq(self, qq):
     with db:
         try:
             return PlayerInfoModel.get(PlayerInfoModel.qq == qq)
         except DoesNotExist:
             return None
Example #7
0
    def process(self, from_group: int, from_qq: int, command_list: List[str]):

        # 初始化数据
        self.from_qq = from_qq
        self.from_group = from_group
        target_pc = None
        target_type = None
        show_self = False

        try:
            target_pc = command_list[2]
            # 没异常,说明要查看其他人的数据
            result = utils.get_qq_from_at_msg(target_pc)
            if result == None:
                target_type = "NICKNAME"
            else:
                target_type = "QQ"
                target_pc = result

        except IndexError:
            # 没有指定参数,查看自己的数据
            target_pc = from_qq
            target_type = "QQ"
            show_self = True

        # 打一下log
        self.logger.info(
            f"[{self.command_name}] target_pc:{target_pc}, target_type: {target_type}"
        )

        # 开始查询数据
        with db:
            try:
                if target_type == "QQ":
                    pc_result: PlayerInfoModel = PlayerInfoModel.get(
                        PlayerInfoModel.qq == target_pc)
                else:
                    pc_result: PlayerInfoModel = PlayerInfoModel.get(
                        PlayerInfoModel.nickname == target_pc)
            except DoesNotExist:
                # 查无此人
                self.send_msg(
                    utils.build_at_msg(from_qq) + "\n无此人数据!"
                    "\n请确认目标是否正确,或请先执行%game register nickname进行注册!")
                return

        # 格式化数据
        data_msg = "Nickname: " + pc_result.nickname + "\n"
        if show_self:
            data_msg += f"Rest PT: {pc_result.rest_pt}\n"
        data_msg += f"Level: {pc_result.level}\n" \
                    f"Exp: {pc_result.exp}\n" \
                    f"==========\n" \
                    f"STR: {pc_result.base_str}\n" \
                    f"VIT: {pc_result.base_vit}\n" \
                    f"AGI: {pc_result.base_agi}\n" \
                    f"LUK: {pc_result.base_luck}\n" \
                    f"==========\n" \
                    f"HP: {pc_result.hp_current} / {pc_result.hp_max}\n" \
                    f"SP: {pc_result.sp_current} / {pc_result.sp_max}\n" \
                    f"ATK: {pc_result.atk}\n" \
                    f"DEF: {pc_result.defe}\n" \
                    f"CRI: {self.convert(pc_result.cri * 100, 2)}%\n" \
                    f"HIT: {self.convert(pc_result.hit * 100, 2)}%\n" \
                    f"EVA: {self.convert(pc_result.eva * 100, 2)}%\n" \
                    f"=========="
        self.send_msg(utils.build_at_msg(from_qq) + "\n" + data_msg)