Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

Commit

Permalink
[add/opt] follow/wfhelper: Refactor and implemented auto join followi…
Browse files Browse the repository at this point in the history
…ng player's room
  • Loading branch information
kmou424 committed Mar 5, 2022
1 parent 23fe1b8 commit 07a6144
Show file tree
Hide file tree
Showing 17 changed files with 497 additions and 224 deletions.
80 changes: 80 additions & 0 deletions lib/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import cv2
import numpy

from lib.times import Time


class Point:
def __init__(self, x: float, y: float):
self.x = x
self.y = y

def loadZoom(self, zoom: float):
if zoom > 1.0:
self.x = self.x * zoom
self.y = self.y * zoom


class Rect:
def __init__(self, left_top: Point, right_bottom: Point):
self.left_top = left_top
self.right_bottom = right_bottom


class Rgb:
def __init__(self, r, g, b):
self.red = r
self.green = g
self.blue = b

@staticmethod
def point2rgb(img: cv2.cv2, point: Point):
return Rgb.pixel2rgb(img[point.y, point.x])

@staticmethod
def pixel2rgb(pixel: numpy.ndarray):
return Rgb(pixel[2], pixel[1], pixel[0])


class Color:
def __init__(self, left: Rgb, right: Rgb):
self.left = left
self.right = right

def isMatch(self, src: Rgb):
return (self.left.red <= src.red <= self.right.red) and \
(self.left.green <= src.green <= self.right.green) and \
(self.left.blue <= src.blue <= self.right.blue)


class Boss:
BossLevels = {
'prim': '初级',
'mid': '中级',
'high': '高级',
'highp': '高级+',
'super': '超级'
}

def __init__(self, item: dict):
self.item = item

def isAvailable(self) -> bool:
end_time = Time.getTimeStampByStandardFormat(self.item['end'])
now_time = Time.getTimeStampForNow()
return end_time > now_time

def getName(self) -> str:
return self.item['name']

def getId(self) -> str:
return self.item['id']

def getType(self) -> str:
return self.item['type']

def getLevels(self) -> str:
return self.item['levels']

def getMinLevel(self):
return self.getLevels().split(' ')[0]
31 changes: 29 additions & 2 deletions lib/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from lib.base import Rect, Point, Color, Rgb
from lib.logger import Logger
from lib.utils import Color, Rgb, Point, Rect


class _ConfigValue:
Expand All @@ -19,10 +19,12 @@ class ConfigSections:
class ConfigOptions:
GAMING_MODE_MAIN = _ConfigValue('GamingModeMain')
TRACK_BELL_SWITCH = _ConfigValue('TrackBellSwitch')
TRACK_BOSS_LIST_SWITCH = _ConfigValue('TrackBossListSwitch')
TRACK_FOLLOW_SWITCH = _ConfigValue('TrackFollowSwitch')
ROOM_CREATOR_SWITCH = _ConfigValue('RoomCreatorSwitch')
BELL_SELECTOR_MODE = _ConfigValue('BellSelectorMode')
BELL_BOSS_SELECTOR_ADVANCED = _ConfigValue('BellBossSelectorAdvanced')
FOLLOW_FRIEND_SELECT = _ConfigValue('FollowFriendSelect')
FOLLOW_FRIEND_SELECT_NAME = _ConfigValue('FollowFriendSelectName')
# full non-full
ROOM_CREATOR_START_FIGHT_MODE = _ConfigValue('RoomCreatorStartFightMode')
ROOM_CREATOR_GHOST_MODE = _ConfigValue('RoomCreatorGhostMode')
Expand Down Expand Up @@ -254,6 +256,13 @@ class CheckTemplate:
'tw': Rect(Point(632, 285), Point(682, 332))
}
)
BOSS_LIST_REFRESH_UNAVAILABLE_BUTTON = Template(
'Boss_list_refresh_unavailable_button',
{
'cn': Rect(Point(632, 285), Point(682, 332)),
'tw': Rect(Point(632, 285), Point(682, 332))
}
)
BOSS_INFO_EXCHANGE_BUTTON = Template(
'Boss_info_exchange_button',
{
Expand Down Expand Up @@ -400,6 +409,13 @@ class CheckTemplate:
)


class Locate:
BOSS_LIST_CARD_TITLE_ROOM_SUFFIX = {
'cn': '的房间',
'tw': '的房間'
}


class Const:
# Boss列表头图底部坐标Y
BOSS_LIST_HEADER_BOTTOM_Y = 372
Expand All @@ -411,6 +427,16 @@ class Const:
BOSS_LIST_CARD_RIGHT_X = 695
# "i"图标左侧(防止点到"i"图标)
BOSS_LIST_CARD_RIGHT_X_NO_INFO = 648
# "i"图标到卡片顶部距离
BOSS_LIST_CARD_INFO_MARGIN_TOP = 45
# "i"图标到卡片底部距离
BOSS_LIST_CARD_INFO_MARGIN_BOTTOM = 44
# "i"图标右边的房间状态颜色图案间距
BOSS_LIST_CARD_INFO_MARGIN_LEFT_ROOM_STATUS = 48
# 卡片文字内容 右边坐标 X
BOSS_LIST_CARD_TEXT_RIGHT = 540
# 卡片文字内容 左边坐标 X
BOSS_LIST_CARD_TEXT_LEFT = 200


class ResultCode:
Expand Down Expand Up @@ -461,6 +487,7 @@ class Task:
GO_CREATOR_CHECK_BOSS_LIST = Status(402, "寻找目标Boss")
GO_CREATOR_CHECK_BOSS_LEVEL = Status(403, "选择目标难度")
GO_CREATOR_CREATE_ROOM = Status(404, "创建目标Boss房间")
GO_FOLLOW_CHECK_BOSS_LIST = Status(501, "寻找房间")
GO_LOGIN = Status(901, "前往登录")
GO_CONTINUE_AFTER_LOGIN = Status(902, "已登录,准备开始检测当前界面")
GO_CHECK_INTERFACE = Status(903, "检测当前界面")
46 changes: 24 additions & 22 deletions lib/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

import cv2

from lib.base import Rect, Boss
from lib.config import ConfigManager
from lib.constants import ConfigSections, ConfigOptions, ConfigValues
from lib.utils import Rect, Boss, Args


class ResourceJson:
@staticmethod
def getBossInfo(server: str):
target = "template/{server}/boss/index.json"\
target = "template/{server}/boss/index.json" \
.format(server=server)
with open(target, encoding='utf-8') as file:
res = json.load(file)
ret = []
for i in res:
boss = Boss(i)
if (boss.getType() == 'special' and boss.isAvailable())\
if (boss.getType() == 'special' and boss.isAvailable()) \
or boss.getType() == 'normal':
ret.append(i)
return ret
Expand All @@ -34,42 +34,42 @@ def getGamePackageName(server: str):
return Resource.__package_name.get(server)

@staticmethod
def getGamingModeMain(mArgs: Args):
gaming_mode_main = mArgs.cfgMan\
.selectSection(ConfigSections.SECTION_MAIN.get())\
def getGamingModeMain(cfgMan: ConfigManager):
gaming_mode_main = cfgMan \
.selectSection(ConfigSections.SECTION_MAIN.get()) \
.getString(ConfigOptions.GAMING_MODE_MAIN.get(), default=ConfigValues.GAMING_MODE_MAIN_GUEST.get())
if gaming_mode_main == ConfigValues.GAMING_MODE_MAIN_GUEST.get():
return ConfigValues.GAMING_MODE_MAIN_GUEST
if gaming_mode_main == ConfigValues.GAMING_MODE_MAIN_OWNER.get():
return ConfigValues.GAMING_MODE_MAIN_OWNER

@staticmethod
def getBellBossList(mArgs: Args):
bell_selector_mode = mArgs.cfgMan\
.selectSection(ConfigSections.SECTION_CUSTOM.get())\
def getBellBossList(cfgMan: ConfigManager):
bell_selector_mode = cfgMan \
.selectSection(ConfigSections.SECTION_CUSTOM.get()) \
.getString(ConfigOptions.BELL_SELECTOR_MODE.get(), default='no')
ret = None
if bell_selector_mode == ConfigValues.BELL_SELECTOR_MODE_COMMON.get():
ret = mArgs.cfgMan\
.selectSection(ConfigSections.SECTION_CUSTOM.get())\
ret = cfgMan \
.selectSection(ConfigSections.SECTION_CUSTOM.get()) \
.getString(ConfigOptions.COMMON_BOSS_SELECTOR.get())
if bell_selector_mode == ConfigValues.BELL_SELECTOR_MODE_ADVANCED.get():
ret = mArgs.cfgMan\
.selectSection(ConfigSections.SECTION_CUSTOM.get())\
ret = cfgMan \
.selectSection(ConfigSections.SECTION_CUSTOM.get()) \
.getString(ConfigOptions.BELL_BOSS_SELECTOR_ADVANCED.get())
if ret is not None:
ret = ret.split(',')
return ret

@staticmethod
def getTemplate(server: str, template_img_name: str):
target = "template/{server}/{tin}.png"\
target = "template/{server}/{tin}.png" \
.format(server=server, tin=template_img_name)
return cv2.imread(target)

@staticmethod
def getBossTemplate(server: str, boss_id: str):
target = "template/{server}/boss/Boss_{boss_id}.png"\
target = "template/{server}/boss/Boss_{boss_id}.png" \
.format(server=server, boss_id=boss_id)
return cv2.imread(target)

Expand All @@ -82,12 +82,14 @@ def getMinBossTemplate(cfgMan: ConfigManager, GameServer: str) -> cv2.cv2:
for boss_info in ResourceJson.getBossInfo(GameServer):
boss = Boss(boss_info)
if boss.getId() == boss_id:
return Resource \
.getBossTemplate(
GameServer,
"{id}_{level}".format(id=boss_id, level=boss.getMinLevel())
)
return Resource.getBossTemplate(
GameServer,
"{id}_{level}".format(id=boss_id, level=boss.getMinLevel())
)

@staticmethod
def cropImg(img: cv2.cv2, rect: Rect):
return img[rect.left_top.y:rect.right_bottom.y, rect.left_top.x:rect.right_bottom.x]
def cropImg(img: cv2.cv2, rect: Rect, isGray=False):
img = img[rect.left_top.y:rect.right_bottom.y, rect.left_top.x:rect.right_bottom.x]
if isGray:
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
return img
Loading

0 comments on commit 07a6144

Please sign in to comment.