@ -0,0 +1,185 @@
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
current_path = os.path.dirname(os.path.abspath(__file__))
|
||||
print(current_path)
|
||||
DB_FOLDER = current_path
|
||||
class DatabaseHandler:
|
||||
def __init__(self, database):
|
||||
self.database = os.path.join(DB_FOLDER, database)
|
||||
self.conn = None
|
||||
self.cur = None
|
||||
|
||||
def connect(self):
|
||||
self.conn = sqlite3.connect(self.database)
|
||||
self.cur = self.conn.cursor()
|
||||
|
||||
def create_table(self, table_name):
|
||||
self.cur.execute(f"CREATE TABLE IF NOT EXISTS {table_name} (pid INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER, path VARCHAR, xOffset INTEGER, yOffset INTEGER, pOffsetX INTEGER, pOffsetY INTEGER, time INTEGER, rgb VARCHAR);")
|
||||
self.conn.commit()
|
||||
print('创建成功')
|
||||
|
||||
def insert_data(self, table_name, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb):
|
||||
try:
|
||||
self.cur.execute(f"SELECT MAX(pid) FROM {table_name}")
|
||||
max_pid = self.cur.fetchone()[0]
|
||||
if max_pid is not None:
|
||||
pid = max_pid + 1
|
||||
else:
|
||||
pid = 1
|
||||
self.cur.execute(
|
||||
f"INSERT INTO {table_name} (pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb))
|
||||
self.conn.commit()
|
||||
print("数据插入成功")
|
||||
except sqlite3.Error as e:
|
||||
print(f"插入数据失败: {str(e)}")
|
||||
|
||||
def insert_pidData(self, table_name, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb, pid=None):
|
||||
try:
|
||||
self.cur.execute(f"SELECT MAX(pid) FROM {table_name}")
|
||||
max_pid = self.cur.fetchone()[0]
|
||||
if max_pid is not None:
|
||||
if pid > max_pid:
|
||||
pid = max_pid + 1
|
||||
self.cur.execute(
|
||||
f"INSERT INTO {table_name} (pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb))
|
||||
self.conn.commit()
|
||||
print("数据插入成功")
|
||||
else:
|
||||
for i in range(max_pid, pid - 1, -1):
|
||||
self.cur.execute(
|
||||
f"UPDATE {table_name} SET pid = ? WHERE pid = ?",
|
||||
(i + 1, i))
|
||||
self.cur.execute(
|
||||
f"INSERT INTO {table_name} (pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb))
|
||||
self.conn.commit()
|
||||
print("数据插入成功")
|
||||
else:
|
||||
pid = 1
|
||||
self.cur.execute(
|
||||
f"INSERT INTO {table_name} (pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb))
|
||||
self.conn.commit()
|
||||
print("数据插入成功")
|
||||
except sqlite3.Error as e:
|
||||
print(f"插入数据失败: {str(e)}")
|
||||
|
||||
def execute_query(self, table_name, pid=None):
|
||||
try:
|
||||
if pid is None:
|
||||
self.cur.execute(f"SELECT pid, * FROM {table_name}")
|
||||
rows = self.cur.fetchall()
|
||||
for row in rows:
|
||||
pid = row[0] # 第0列是pid
|
||||
data = row[1:] # 后续列为数据
|
||||
print(f"pid: {pid}, data: {data}")
|
||||
return rows # 返回所有行的结果集
|
||||
else:
|
||||
self.cur.execute(f"SELECT * FROM {table_name} WHERE pid = ?", (pid,))
|
||||
row = self.cur.fetchone()
|
||||
if row:
|
||||
print(f"Row with pid {pid}: {row[1:]}")
|
||||
else:
|
||||
print(f"Row with pid {pid} not found")
|
||||
return row[1:]
|
||||
except Exception as e:
|
||||
print(f"Error executing query on table {table_name}: {str(e)}")
|
||||
|
||||
def delete_table(self, table_name):
|
||||
try:
|
||||
self.cur.execute(f"DROP TABLE IF EXISTS {table_name}")
|
||||
self.conn.commit()
|
||||
print(f"Table {table_name} deleted")
|
||||
except Exception as e:
|
||||
print(f"Error deleting table {table_name}: {str(e)}")
|
||||
|
||||
def delete_row(self, table_name, pid):
|
||||
try:
|
||||
# 1. 获取删除行的pid和其后面的所有pid
|
||||
self.cur.execute(f"SELECT pid FROM {table_name} WHERE pid >= ?", (pid,))
|
||||
rows_to_update = self.cur.fetchall()
|
||||
|
||||
# 2. 删除指定行
|
||||
self.cur.execute(f"SELECT path FROM {table_name} WHERE pid = ?", (pid,))
|
||||
path = self.cur.fetchall()
|
||||
self.cur.execute(f"DELETE FROM {table_name} WHERE pid = ?", (pid,))
|
||||
|
||||
# 3. 更新后面行的pid
|
||||
for row in rows_to_update:
|
||||
new_pid = row[0] - 1
|
||||
self.cur.execute(f"UPDATE {table_name} SET pid = ? WHERE pid = ?", (new_pid, row[0]))
|
||||
|
||||
self.conn.commit()
|
||||
print(f"Row with pid {pid} deleted from {table_name}")
|
||||
return path
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
return None
|
||||
|
||||
def get_max_pid(self, table_name):
|
||||
try:
|
||||
self.cur.execute(f"SELECT MAX(pid) FROM {table_name}")
|
||||
max_pid = self.cur.fetchone()[0]
|
||||
if max_pid is not None:
|
||||
return max_pid
|
||||
else:
|
||||
return 0
|
||||
except sqlite3.Error as e:
|
||||
print(f"获取最大 pid 失败: {str(e)}")
|
||||
return 0
|
||||
|
||||
|
||||
def close(self):
|
||||
self.conn.close()
|
||||
|
||||
# 示例用法
|
||||
|
||||
class DatabaseDatum:
|
||||
def __init__(self, *args):
|
||||
self.id = args[0]
|
||||
self.path = args[1]
|
||||
self.xOffset = args[2]
|
||||
self.yOffset = args[3]
|
||||
self.pOffsetX = args[4]
|
||||
self.pOffsetY = args[5]
|
||||
self.time = args[6]
|
||||
self.rgb = args[7]
|
||||
|
||||
'''def get_path_by_pid(self, tablename, pid):
|
||||
db = DatabaseHandler(database='test2.sqlite3')
|
||||
db.connect()
|
||||
query = f"SELECT path FROM {tablename} WHERE pid = ?;"
|
||||
db.cur.execute(query, (pid,))
|
||||
result = db.cur.fetchone()
|
||||
db.close()
|
||||
|
||||
if result:
|
||||
self.path = result[0]
|
||||
else:
|
||||
self.path = None
|
||||
|
||||
return self.path
|
||||
'''
|
||||
# 创建一个DatabaseDatum对象
|
||||
|
||||
|
||||
|
||||
# 调用get_path_by_pid
|
||||
#(datum.get_path_by_pid('rule10',1))
|
||||
|
||||
|
||||
# db = DatabaseHandler(database='test2.sqlite3')
|
||||
# db.connect()
|
||||
# path = db.delete_row('rule13', 3)
|
||||
#
|
||||
# if path and len(path) > 0:
|
||||
# result = path[0][0]
|
||||
# print(result)
|
||||
# else:
|
||||
# print("No path found")
|
||||
#
|
||||
# db.close()
|
||||
#
|
@ -1,94 +0,0 @@
|
||||
|
||||
import psycopg2
|
||||
from psycopg2 import errors
|
||||
|
||||
|
||||
class DatabaseHandler:
|
||||
def __init__(self, database, user, password, host, port):
|
||||
self.database = database
|
||||
self.user = user
|
||||
self.password = password
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.conn = None
|
||||
self.cur = None
|
||||
|
||||
def connect(self):
|
||||
self.conn = psycopg2.connect(database=self.database,
|
||||
user=self.user,
|
||||
password=self.password,
|
||||
host=self.host,
|
||||
port=self.port)
|
||||
self.cur = self.conn.cursor()
|
||||
|
||||
def create_table(self, table_name):
|
||||
self.cur.execute(
|
||||
"SELECT EXISTS(SELECT 1 FROM information_schema.tables WHERE table_name='" + table_name + "');")
|
||||
table_exists = self.cur.fetchone()[0]
|
||||
if table_exists:
|
||||
print("表已存在")
|
||||
else:
|
||||
try:
|
||||
self.cur.execute(f"CREATE SEQUENCE {table_name}_pid_seq START 1;")
|
||||
self.cur.execute(
|
||||
f"CREATE TABLE {table_name} (pid INTEGER DEFAULT nextval('{table_name}_pid_seq'), id INTEGER, path VARCHAR, xOffset INTEGER, yOffset INTEGER, pOffsetX INTEGER, pOffsetY INTEGER, time INTEGER, rgb VARCHAR);")
|
||||
self.conn.commit()
|
||||
print("操作成功")
|
||||
except errors.DuplicateTable:
|
||||
print("表已存在")
|
||||
|
||||
def insert_data(self, table_name, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb):
|
||||
try:
|
||||
self.cur.execute(
|
||||
f"INSERT INTO {table_name} (id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb) VALUES ({id}, '{path}', {xOffset}, {yOffset}, {pOffsetX}, {pOffsetY}, {time}, '{rgb}')")
|
||||
self.conn.commit()
|
||||
print("数据插入成功")
|
||||
except errors.ForeignKeyViolation:
|
||||
print("插入数据失败")
|
||||
|
||||
def execute_query(self, table_name):
|
||||
self.cur.execute("SELECT * FROM " + table_name)
|
||||
rows = self.cur.fetchall()
|
||||
for row in rows:
|
||||
print(row)
|
||||
|
||||
def close(self):
|
||||
self.conn.close()
|
||||
|
||||
#
|
||||
# # 示例用法
|
||||
# db = DatabaseHandler(database='gamerule', user='postgres', password='123456', host='localhost', port='5432')
|
||||
# db.connect()
|
||||
# db.create_table('rule11')
|
||||
# db.insert_data('rule11', 9, '../pictures/terminal_photo.png', 10, 20, 30, 40, 12345, '255,0,0')
|
||||
# db.execute_query('rule11')
|
||||
# db.close()
|
||||
|
||||
|
||||
class DatabaseDatum:
|
||||
def __init__(self, tablename=None, id=None, path=None, xOffset=None, yOffset=None, pOffsetX=None, pOffsetY=None,
|
||||
time=None, rgb=None):
|
||||
self.tablename = tablename
|
||||
self.id = id
|
||||
self.path = path
|
||||
self.xOffset = xOffset
|
||||
self.yOffset = yOffset
|
||||
self.pOffsetX = pOffsetX
|
||||
self.pOffsetY = pOffsetY
|
||||
self.time = time
|
||||
self.rgb = rgb
|
||||
|
||||
def get_path_by_pid(self, tablename, pid):
|
||||
db = DatabaseHandler(database='gamerule', user='postgres', password='123456', host='localhost', port='5432')
|
||||
db.connect()
|
||||
query = f"SELECT path FROM {tablename} WHERE pid = {pid};"
|
||||
db.cur.execute(query)
|
||||
result = db.cur.fetchone()
|
||||
db.close()
|
||||
|
||||
if result:
|
||||
self.path = result[0]
|
||||
else:
|
||||
self.path = None
|
||||
|
||||
return self.path
|
@ -0,0 +1,227 @@
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
current_path = os.path.dirname(os.path.abspath(__file__))
|
||||
print(current_path)
|
||||
DB_FOLDER = current_path
|
||||
|
||||
|
||||
class DatabaseHandler:
|
||||
def __init__(self, database):
|
||||
self.database = os.path.join(DB_FOLDER, database)
|
||||
self.conn = None
|
||||
self.cur = None
|
||||
|
||||
def connect(self):
|
||||
self.conn = sqlite3.connect(self.database)
|
||||
self.cur = self.conn.cursor()
|
||||
|
||||
def create_table(self, table_name):
|
||||
self.cur.execute(
|
||||
f"CREATE TABLE IF NOT EXISTS {table_name} (pid INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER, path VARCHAR, xOffset INTEGER, yOffset INTEGER, pOffsetX INTEGER, pOffsetY INTEGER, time INTEGER, rgb VARCHAR);")
|
||||
self.conn.commit()
|
||||
print('创建成功')
|
||||
|
||||
def insert_data(self, table_name, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb):
|
||||
try:
|
||||
self.cur.execute(f"SELECT MAX(pid) FROM {table_name}")
|
||||
max_pid = self.cur.fetchone()[0]
|
||||
if max_pid is not None:
|
||||
pid = max_pid + 1
|
||||
else:
|
||||
pid = 1
|
||||
self.cur.execute(
|
||||
f"INSERT INTO {table_name} (pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb))
|
||||
self.conn.commit()
|
||||
print("数据插入成功")
|
||||
except sqlite3.Error as e:
|
||||
print(f"插入数据失败: {str(e)}")
|
||||
|
||||
def insert_pidData(self, table_name, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb, pid=None):
|
||||
try:
|
||||
self.cur.execute(f"SELECT MAX(pid) FROM {table_name}")
|
||||
max_pid = self.cur.fetchone()[0]
|
||||
if max_pid is not None:
|
||||
if pid > max_pid:
|
||||
pid = max_pid + 1
|
||||
self.cur.execute(
|
||||
f"INSERT INTO {table_name} (pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb))
|
||||
self.conn.commit()
|
||||
print("数据插入成功")
|
||||
else:
|
||||
for i in range(max_pid, pid - 1, -1):
|
||||
self.cur.execute(
|
||||
f"UPDATE {table_name} SET pid = ? WHERE pid = ?",
|
||||
(i + 1, i))
|
||||
self.cur.execute(
|
||||
f"INSERT INTO {table_name} (pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb))
|
||||
self.conn.commit()
|
||||
print("数据插入成功")
|
||||
else:
|
||||
pid = 1
|
||||
self.cur.execute(
|
||||
f"INSERT INTO {table_name} (pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(pid, id, path, xOffset, yOffset, pOffsetX, pOffsetY, time, rgb))
|
||||
self.conn.commit()
|
||||
print("数据插入成功")
|
||||
except sqlite3.Error as e:
|
||||
print(f"插入数据失败: {str(e)}")
|
||||
|
||||
def execute_query(self, table_name, pid=None):
|
||||
try:
|
||||
if pid is None:
|
||||
self.cur.execute(f"SELECT pid, * FROM {table_name}")
|
||||
rows = self.cur.fetchall()
|
||||
for row in rows:
|
||||
pid = row[0] # 第0列是pid
|
||||
data = row[1:] # 后续列为数据
|
||||
print(f"pid: {pid}, data: {data}")
|
||||
return rows # 返回所有行的结果集
|
||||
else:
|
||||
self.cur.execute(f"SELECT * FROM {table_name} WHERE pid = ?", (pid,))
|
||||
row = self.cur.fetchone()
|
||||
if row:
|
||||
print(f"Row with pid {pid}: {row[1:]}")
|
||||
else:
|
||||
print(f"Row with pid {pid} not found")
|
||||
return row[1:]
|
||||
except Exception as e:
|
||||
print(f"Error executing query on table {table_name}: {str(e)}")
|
||||
|
||||
def delete_table(self, table_name):
|
||||
try:
|
||||
self.cur.execute(f"DROP TABLE IF EXISTS {table_name}")
|
||||
self.conn.commit()
|
||||
print(f"Table {table_name} deleted")
|
||||
except Exception as e:
|
||||
print(f"Error deleting table {table_name}: {str(e)}")
|
||||
|
||||
def delete_row(self, table_name, pid):
|
||||
try:
|
||||
# 1. 获取删除行的pid和其后面的所有pid
|
||||
self.cur.execute(f"SELECT pid FROM {table_name} WHERE pid >= ?", (pid,))
|
||||
rows_to_update = self.cur.fetchall()
|
||||
|
||||
# 2. 删除指定行
|
||||
self.cur.execute(f"SELECT path FROM {table_name} WHERE pid = ?", (pid,))
|
||||
path = self.cur.fetchall()
|
||||
self.cur.execute(f"DELETE FROM {table_name} WHERE pid = ?", (pid,))
|
||||
|
||||
# 3. 更新后面行的pid
|
||||
for row in rows_to_update:
|
||||
new_pid = row[0] - 1
|
||||
self.cur.execute(f"UPDATE {table_name} SET pid = ? WHERE pid = ?", (new_pid, row[0]))
|
||||
|
||||
self.conn.commit()
|
||||
print(f"Row with pid {pid} deleted from {table_name}")
|
||||
return path
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
return None
|
||||
|
||||
def get_max_pid(self, table_name):
|
||||
try:
|
||||
self.cur.execute(f"SELECT MAX(pid) FROM {table_name}")
|
||||
max_pid = self.cur.fetchone()[0]
|
||||
if max_pid is not None:
|
||||
return max_pid
|
||||
else:
|
||||
return 0
|
||||
except sqlite3.Error as e:
|
||||
print(f"获取最大 pid 失败: {str(e)}")
|
||||
return 0
|
||||
|
||||
@staticmethod
|
||||
def init_db():
|
||||
|
||||
db = DatabaseHandler(database='test2.sqlite3')
|
||||
db.connect()
|
||||
|
||||
db.cur.execute(f"SELECT pid, * FROM userConcreteRule")
|
||||
rows = db.cur.fetchall()
|
||||
# 检查结果
|
||||
if rows:
|
||||
print("表有内容")
|
||||
else:
|
||||
print("表没内容")
|
||||
db.create_table('userGeneralRule')
|
||||
db.create_table('userConcreteRule')
|
||||
db.insert_data('userConcreteRule', 0, '返回终端界面', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '找到目标关卡', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '找到目标章节', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '战斗', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '回到基建界面', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '进入基建界面', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '获得奖励', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '进入基建总览', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '改变总览宿舍干员', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '改变发电站干员', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '改变总览工作室干员', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '进入交易站', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '进入生产站', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '到下一个工作室', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '改变当前工作站干员', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '获取信用点', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '消耗信用点', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '获得日常奖励', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '进入招募界面', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '公开招募所有', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '公开招募一个', 0, 0, 0, 0, 0, 0)
|
||||
db.insert_data('userConcreteRule', 0, '使用加急凭证', 0, 0, 0, 0, 0, 0)
|
||||
|
||||
db.close()
|
||||
|
||||
def close(self):
|
||||
self.conn.close()
|
||||
|
||||
|
||||
# 示例用法
|
||||
|
||||
class DatabaseDatum:
|
||||
def __init__(self, *args):
|
||||
self.id = args[0]
|
||||
self.path = args[1]
|
||||
self.xOffset = args[2]
|
||||
self.yOffset = args[3]
|
||||
self.pOffsetX = args[4]
|
||||
self.pOffsetY = args[5]
|
||||
self.time = args[6]
|
||||
self.rgb = args[7]
|
||||
|
||||
'''def get_path_by_pid(self, tablename, pid):
|
||||
db = DatabaseHandler(database='test2.sqlite3')
|
||||
db.connect()
|
||||
query = f"SELECT path FROM {tablename} WHERE pid = ?;"
|
||||
db.cur.execute(query, (pid,))
|
||||
result = db.cur.fetchone()
|
||||
db.close()
|
||||
|
||||
if result:
|
||||
self.path = result[0]
|
||||
else:
|
||||
self.path = None
|
||||
|
||||
return self.path
|
||||
'''
|
||||
# 创建一个DatabaseDatum对象
|
||||
|
||||
|
||||
# 调用get_path_by_pid
|
||||
# (datum.get_path_by_pid('rule10',1))
|
||||
|
||||
|
||||
# db = DatabaseHandler(database='test2.sqlite3')
|
||||
# db.connect()
|
||||
# path = db.delete_row('rule13', 3)
|
||||
#
|
||||
# if path and len(path) > 0:
|
||||
# result = path[0][0]
|
||||
# print(result)
|
||||
# else:
|
||||
# print("No path found")
|
||||
#
|
||||
# db.close()
|
||||
#
|
@ -0,0 +1,46 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
import pyautogui as p
|
||||
from PIL.Image import Image
|
||||
|
||||
from windows.res.tools.deal_picture import DealPicture
|
||||
from windows.res.tools.recognise_words import Recognise_word
|
||||
|
||||
|
||||
class end_condition:
|
||||
|
||||
@staticmethod
|
||||
def area_changed(last_photo, current_photo):
|
||||
last = last_photo
|
||||
current = current_photo
|
||||
# 将元组转换为字典
|
||||
if isinstance(last, Image):
|
||||
last_np = np.array(last.convert('RGB'))[:, :, ::-1]
|
||||
else:
|
||||
last_np = last_photo
|
||||
if isinstance(current, Image):
|
||||
current_np = [np.array(current.convert('RGB'))[:, :, ::-1]]
|
||||
else:
|
||||
current_np = [current]
|
||||
|
||||
changed = DealPicture.mapping_any_photo(last_np, current_np, 0.98)
|
||||
if changed:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def find_photo(photo_adrees):
|
||||
photo = cv2.imread(photo_adrees)
|
||||
if DealPicture.find_photo_center(photo) is not None:
|
||||
return True
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def find_word(word):
|
||||
shot_photo = p.screenshot()
|
||||
words_inf = Recognise_word.recognise_word(shot_photo)
|
||||
position = Recognise_word.find_word_positon(word, words_inf)
|
||||
if position is not None:
|
||||
return True
|
||||
return False
|
@ -1,51 +0,0 @@
|
||||
from PyQt5.QtWidgets import QMainWindow, QWidget, QGridLayout, QLabel, QPushButton
|
||||
from PyQt5 import uic
|
||||
|
||||
|
||||
class operateselect(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.selectedWidget = None
|
||||
uic.loadUi('res/ui/operationSelect_window.ui', self)
|
||||
|
||||
self.findQGridLayout()
|
||||
self.confirmBtn = self.findChild(QPushButton, 'confirmBtn')#确定按钮
|
||||
self.confirmBtn.clicked.connect(self.confirm_clicked)
|
||||
|
||||
|
||||
def confirm_clicked(self):
|
||||
print("已选择:", self.getOperator())
|
||||
self.close()
|
||||
|
||||
def findQGridLayout(self): # 找到QGridLayout
|
||||
grid_layout = self.findChild(QGridLayout, "gridLayout")
|
||||
if grid_layout:
|
||||
for i in range(grid_layout.rowCount()):
|
||||
for j in range(grid_layout.columnCount()):
|
||||
item = grid_layout.itemAtPosition(i, j)
|
||||
if item and isinstance(item.widget(), QWidget):
|
||||
widget = item.widget()
|
||||
widget.mousePressEvent = lambda event, clickedwidget=widget: self.onWidgetClicked(clickedwidget)
|
||||
self.selectedWidget = None
|
||||
|
||||
def onWidgetClicked(self, clickedwidget):
|
||||
# 将之前被选中的QWidget的背景颜色恢复为默认
|
||||
if self.selectedWidget:
|
||||
self.selectedWidget.setStyleSheet("background-color: none;")
|
||||
# 设置被选中的QWidget的背景颜色为浅蓝色
|
||||
clickedwidget.setStyleSheet("background-color: lightblue;")
|
||||
self.selectedWidget = clickedwidget
|
||||
|
||||
label = self.selectedWidget.findChild(QLabel)
|
||||
if label:
|
||||
print("选中的标签文本:", label.text())
|
||||
self.setOperator(label.text())
|
||||
else:
|
||||
print("未找到标签文本")
|
||||
|
||||
def setOperator(self,opt_text):#获取到操作类型值
|
||||
self.operator_text = opt_text
|
||||
|
||||
def getOperator(self):#返回操作类型值
|
||||
return self.operator_text
|
After Width: | Height: | Size: 4.7 KiB |
After Width: | Height: | Size: 5.5 KiB |
@ -0,0 +1,91 @@
|
||||
import pyautogui
|
||||
import cv2
|
||||
import numpy as np
|
||||
from control.database.sqdatabase import *
|
||||
import os
|
||||
|
||||
|
||||
|
||||
class ScreenCapture:
|
||||
def __init__(self):
|
||||
self.screen_width, self.screen_height = pyautogui.size()
|
||||
self.rect_coordinates = []
|
||||
self.flag = 0
|
||||
|
||||
def on_mouse(self, event, x, y, flags, param):
|
||||
if event == cv2.EVENT_LBUTTONDOWN and self.flag == 0:
|
||||
cv2.imshow("Capture", self.capture)
|
||||
self.rect_coordinates = [(x, y)]
|
||||
self.flag = 1
|
||||
|
||||
elif event == cv2.EVENT_MOUSEMOVE and (flags & cv2.EVENT_FLAG_LBUTTON):
|
||||
capture_copy = self.capture.copy()
|
||||
cv2.rectangle(capture_copy, self.rect_coordinates[0], (x, y), (0, 255, 0), 2)
|
||||
cv2.imshow("Capture", capture_copy)
|
||||
|
||||
elif event == cv2.EVENT_LBUTTONUP:
|
||||
self.rect_coordinates.append((x, y))
|
||||
cv2.rectangle(self.capture, self.rect_coordinates[0], self.rect_coordinates[1], (0, 255, 0), 2)
|
||||
cv2.imshow("Capture", self.capture)
|
||||
|
||||
elif event == cv2.EVENT_LBUTTONDOWN and self.flag == 1:
|
||||
cv2.rectangle(self.capture, self.rect_coordinates[0], (x, y), (0, 255, 0), 2)
|
||||
cv2.imshow("Capture", self.capture)
|
||||
|
||||
def capture_screen(self):
|
||||
self.capture = pyautogui.screenshot()
|
||||
self.capture = np.array(self.capture)
|
||||
self.capture = cv2.cvtColor(self.capture, cv2.COLOR_RGB2BGR)
|
||||
|
||||
cv2.namedWindow("Capture", cv2.WINDOW_NORMAL)
|
||||
cv2.setWindowProperty("Capture", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
|
||||
cv2.setMouseCallback("Capture", self.on_mouse)
|
||||
|
||||
while True:
|
||||
cv2.imshow("Capture", self.capture)
|
||||
key = cv2.waitKey(1) & 0xFF
|
||||
|
||||
if key == 13:
|
||||
if len(self.rect_coordinates) == 2:
|
||||
x1, y1 = self.rect_coordinates[0]
|
||||
x2, y2 = self.rect_coordinates[1]
|
||||
if abs(x2 - x1) < 10 or abs(y2 - y1) < 10:
|
||||
raise ValueError("x1, x2, y1, and y2 should have a difference greater than or equal to 10")
|
||||
else:
|
||||
#规范坐标
|
||||
if x1>x2:
|
||||
x = x1
|
||||
x1 = x2
|
||||
x2 = x
|
||||
if y1>y2:
|
||||
y = y1
|
||||
y1 = y2
|
||||
y2 = y
|
||||
|
||||
cropped_area = self.capture[min(y1 + 4, y2 - 4):max(y1 + 4, y2 - 4),
|
||||
min(x1 + 4, x2 - 4):max(x1 + 4, x2 - 4)]
|
||||
|
||||
cv2.imshow("Cropped Area", cropped_area)
|
||||
cv2.destroyAllWindows()
|
||||
current_path = os.getcwd()
|
||||
|
||||
|
||||
file_path = "cropped_area(%d,%d;%d,%d).png" % (x1, y1, x2, y2)
|
||||
print(current_path+'/res/pictures/'+file_path)
|
||||
cv2.imwrite(current_path+'/res/pictures/'+file_path, cropped_area)
|
||||
#cv2.imwrite(current_path +'/'+ file_path, cropped_area)
|
||||
print("截图已保存为%s" % file_path)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return file_path
|
||||
else:
|
||||
print("请先绘制矩形区域再按下'Enter'键进行截图!")
|
||||
|
||||
elif key == 27:
|
||||
break
|
||||
|
||||
cv2.destroyAllWindows()
|
||||
|
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 7.8 KiB |
After Width: | Height: | Size: 5.8 KiB |
After Width: | Height: | Size: 6.2 KiB |
After Width: | Height: | Size: 37 KiB |
After Width: | Height: | Size: 39 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 6.4 KiB |
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 4.7 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 508 B |
After Width: | Height: | Size: 6.4 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 42 KiB |
After Width: | Height: | Size: 7.8 KiB |
After Width: | Height: | Size: 7.3 KiB |
After Width: | Height: | Size: 7.6 KiB |
After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 7.5 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 8.9 KiB |
After Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 5.2 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 9.6 KiB |
@ -0,0 +1,522 @@
|
||||
import time
|
||||
|
||||
from windows.control.database.sqdatabase import DatabaseHandler, DatabaseDatum
|
||||
from windows.entity.operations.endcondition import end_condition
|
||||
from windows.entity.operations.operation import operation
|
||||
import os
|
||||
import keyboard
|
||||
from windows.res.rules import 明日方舟换基建
|
||||
from windows.res.rules import 明日方舟公开招募
|
||||
from windows.res.rules import 明日方舟自动清体力
|
||||
from windows.res.rules import 明日方舟日常处理
|
||||
|
||||
from windows.res.tools.deal_picture import DealPicture
|
||||
|
||||
global i
|
||||
|
||||
|
||||
class DatabaseControl:
|
||||
def __init__(self, database):
|
||||
self.db = DatabaseHandler(database=database)
|
||||
self.db.connect()
|
||||
|
||||
def execute_query(self, table_name, pid):
|
||||
row = self.db.execute_query(table_name, pid)
|
||||
return DatabaseDatum(*row)
|
||||
|
||||
def get_max_pid(self, table_name):
|
||||
return self.db.get_max_pid(table_name)
|
||||
|
||||
def close(self):
|
||||
self.db.close()
|
||||
|
||||
def rule_priority(self, ruleList):
|
||||
for rule in ruleList:
|
||||
self.perform_operations(rule)
|
||||
|
||||
# 注意:请确认
|
||||
|
||||
# while i<=ruleList:
|
||||
# perform_operations(self, ruleList[i])
|
||||
|
||||
def perform_userGeneralRulename(self, gen_name):
|
||||
|
||||
j = 1
|
||||
while j <= self.get_max_pid(gen_name):
|
||||
# 根据gen寻找pid
|
||||
datum = self.execute_query(gen_name, j)
|
||||
pid = datum.id
|
||||
|
||||
# 根据pid寻找name
|
||||
datu = self.execute_query('userConcreteRule', pid)
|
||||
datum = datu.path
|
||||
if datum == '返回终端界面':
|
||||
明日方舟自动清体力.backToTerminal()
|
||||
|
||||
elif datum == '找到目标关卡':
|
||||
明日方舟自动清体力.find_target_level()
|
||||
|
||||
elif datum == '找到目标章节':
|
||||
明日方舟自动清体力.find_target_chapter()
|
||||
|
||||
elif datum == '战斗':
|
||||
明日方舟自动清体力.fight_time()
|
||||
|
||||
elif datum == '回到基建界面':
|
||||
明日方舟换基建.back_to_base()
|
||||
|
||||
elif datum == '进入基建界面':
|
||||
明日方舟换基建.enter_base()
|
||||
|
||||
elif datum == '获得奖励':
|
||||
明日方舟换基建.deal_award()
|
||||
|
||||
elif datum == '进入基建总览':
|
||||
明日方舟换基建.enter_overview()
|
||||
|
||||
elif datum == '改变总览宿舍干员':
|
||||
明日方舟换基建.change_dormitory_operators()
|
||||
|
||||
elif datum == '改变发电站干员':
|
||||
明日方舟换基建.change_electricity_operators()
|
||||
|
||||
elif datum == '改变总览工作室干员':
|
||||
明日方舟换基建.change_office_operators()
|
||||
|
||||
elif datum == '进入交易站':
|
||||
明日方舟换基建.enter_trade_stations()
|
||||
|
||||
elif datum == '进入生产站':
|
||||
明日方舟换基建.enter_product_stations()
|
||||
|
||||
elif datum == '到下一个工作室':
|
||||
明日方舟换基建.to_next_station()
|
||||
|
||||
elif datum == '改变当前工作站干员':
|
||||
明日方舟换基建.change_current_operators()
|
||||
|
||||
elif datum == '获取信用点':
|
||||
明日方舟日常处理.visit_base()
|
||||
|
||||
elif datum == '消耗信用点':
|
||||
明日方舟日常处理.credit_consume()
|
||||
|
||||
elif datum == '获得日常奖励':
|
||||
明日方舟日常处理.acquire_award()
|
||||
|
||||
elif datum == '进入招募界面':
|
||||
明日方舟公开招募.enter_recruit()
|
||||
|
||||
elif datum == '公开招募所有':
|
||||
明日方舟公开招募.public_recruit_all()
|
||||
|
||||
elif datum == '公开招募一个':
|
||||
明日方舟公开招募.public_recruit_one()
|
||||
|
||||
elif datum == '使用加急凭证':
|
||||
明日方舟公开招募.use_ugent_recruit()
|
||||
else:
|
||||
self.perform_operations(datum)
|
||||
j += 1
|
||||
|
||||
def perform_operations(self, table_name):
|
||||
global runTime
|
||||
global i
|
||||
global startId
|
||||
current_working_directory = os.getcwd() + '/res/pictures/'
|
||||
print(current_working_directory)
|
||||
flag = 0
|
||||
if 'i' not in globals():
|
||||
i = 1
|
||||
if i > 9000:
|
||||
flag = 1
|
||||
i = 1
|
||||
|
||||
while (i <= self.get_max_pid(table_name)) or (flag == 1):
|
||||
datum = self.execute_query(table_name, i)
|
||||
r_value = datum.rgb
|
||||
if r_value == '':
|
||||
r_value = 0
|
||||
else:
|
||||
r_value = int(datum.rgb)
|
||||
|
||||
if datum.time == '':
|
||||
datum.time = 1
|
||||
|
||||
if datum.id == 9:
|
||||
operation.click_once1(current_working_directory + datum.path)
|
||||
elif datum.id == 15:
|
||||
operation.open_program(datum.path)
|
||||
elif datum.id == 13:
|
||||
print('延时开始')
|
||||
for k in range(datum.time * 10):
|
||||
operation.delay()
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
print('延时结束')
|
||||
elif datum.id == 1:
|
||||
operation.click_fixed_point(datum.xOffset, datum.yOffset)
|
||||
elif datum.id == 16:
|
||||
startId = i
|
||||
print(startId)
|
||||
j = 0
|
||||
# elif datum.id ==18:
|
||||
|
||||
elif datum.id == 17: # 次数作为结束条件
|
||||
runTime = datum.time
|
||||
if j < runTime:
|
||||
j += 1
|
||||
i = startId
|
||||
|
||||
elif datum.id == 18: # 图片出现作为结束条件
|
||||
|
||||
if operation.find_once(current_working_directory + datum.path) == 'true':
|
||||
break
|
||||
else:
|
||||
i = startId
|
||||
|
||||
elif datum.id == 26:
|
||||
if operation.find_once(current_working_directory + datum.path) != 'true':
|
||||
break
|
||||
else:
|
||||
i = startId
|
||||
|
||||
|
||||
elif datum.id == 27:
|
||||
pos = operation.find_word_position(datum.path)
|
||||
if pos is not None:
|
||||
break
|
||||
else:
|
||||
i = startId
|
||||
|
||||
|
||||
elif datum.id == 28:
|
||||
pos = operation.find_word_position(datum.path)
|
||||
if pos is None:
|
||||
break
|
||||
else:
|
||||
i = startId
|
||||
|
||||
# elif datum.id == 20:
|
||||
# while True:
|
||||
# if operation.click_once1(current_working_directory + datum.path):
|
||||
# break
|
||||
# if keyboard.is_pressed('esc'):
|
||||
# i = 9999
|
||||
# break
|
||||
elif datum.id == 21:
|
||||
while True:
|
||||
if operation.find_once(current_working_directory + datum.path):
|
||||
break
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
|
||||
elif datum.id == 23:
|
||||
while True:
|
||||
if operation.find_word_position(datum.path):
|
||||
break
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
|
||||
elif datum.id == 24:
|
||||
while 1:
|
||||
if not operation.find_word_position(datum.path):
|
||||
break
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
|
||||
elif datum.id == 25:
|
||||
first_photo = None
|
||||
flag_25 = 0
|
||||
while flag_25 == 0:
|
||||
|
||||
if first_photo is None:
|
||||
first_photo = DealPicture.shot_photo(
|
||||
{'left': datum.xOffset, 'top': datum.yOffset, 'width': datum.pOffsetX,
|
||||
'height': datum.pOffsetY})
|
||||
time.sleep(1)
|
||||
current_photo = DealPicture.shot_photo(
|
||||
{'left': datum.xOffset, 'top': datum.yOffset, 'width': datum.pOffsetX,
|
||||
'height': datum.pOffsetY})
|
||||
if end_condition.area_changed(first_photo, current_photo):
|
||||
flag_25 = 1
|
||||
print('匹配成功')
|
||||
else:
|
||||
print('匹配失败')
|
||||
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
|
||||
|
||||
|
||||
|
||||
elif datum.id == 30:
|
||||
operation.keyin(datum.path)
|
||||
|
||||
elif datum.id == 91:
|
||||
|
||||
while True:
|
||||
if operation.click_once(current_working_directory + datum.path, datum.pOffsetX, datum.pOffsetY):
|
||||
break
|
||||
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
|
||||
elif datum.id == 92:
|
||||
while True:
|
||||
pos = operation.find_word_position(datum.path)
|
||||
if pos is not None:
|
||||
operation.click_position_once(pos)
|
||||
break
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
time.sleep(1)
|
||||
|
||||
elif datum.id == 93:
|
||||
|
||||
path_array = datum.path.split(',') # 使用逗号作为分隔符
|
||||
path_array = [int(x) for x in path_array]
|
||||
operation.click_position_once(
|
||||
{'left': path_array[0], 'top': path_array[1], 'width': path_array[2], 'height': path_array[3]})
|
||||
|
||||
i += 1
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
|
||||
elif datum.id == 31:
|
||||
|
||||
while True:
|
||||
pos = operation.find_photo_position(current_working_directory + datum.path)
|
||||
print(pos)
|
||||
if pos is not None:
|
||||
for q in range(datum.time):
|
||||
operation.left_drag(pos, r_value, datum.pOffsetX, datum.pOffsetY)
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
break
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
time.sleep(1)
|
||||
|
||||
elif datum.id == 32:
|
||||
|
||||
while True:
|
||||
pos = operation.find_word_position(datum.path)
|
||||
if pos is not None:
|
||||
for q in range(datum.time):
|
||||
operation.left_drag(pos, r_value, datum.pOffsetX, datum.pOffsetY)
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
break
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
time.sleep(1)
|
||||
|
||||
elif datum.id == 33:
|
||||
path_array = datum.path.split(',') # 使用逗号作为分隔符
|
||||
path_array = [int(x) for x in path_array]
|
||||
|
||||
for q in range(datum.time):
|
||||
operation.left_drag(
|
||||
{'left': path_array[0], 'top': path_array[1], 'width': path_array[2], 'height': path_array[3]},
|
||||
r_value, datum.pOffsetX, datum.pOffsetY)
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
|
||||
elif datum.id == 41:
|
||||
|
||||
while True:
|
||||
pos = operation.find_photo_position(current_working_directory + datum.path)
|
||||
print(pos)
|
||||
if pos is not None:
|
||||
for q in range(datum.time):
|
||||
operation.right_drag(pos, r_value, datum.pOffsetX, datum.pOffsetY)
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
break
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
time.sleep(1)
|
||||
|
||||
elif datum.id == 42:
|
||||
|
||||
while True:
|
||||
pos = operation.find_word_position(datum.path)
|
||||
if pos is not None:
|
||||
for q in range(datum.time):
|
||||
operation.right_drag(pos, r_value, datum.pOffsetX, datum.pOffsetY)
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
break
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
time.sleep(1)
|
||||
|
||||
elif datum.id == 43:
|
||||
path_array = datum.path.split(',') # 使用逗号作为分隔符
|
||||
path_array = [int(x) for x in path_array]
|
||||
|
||||
for q in range(datum.time):
|
||||
operation.right_drag(
|
||||
{'left': path_array[0], 'top': path_array[1], 'width': path_array[2], 'height': path_array[3]},
|
||||
r_value, datum.pOffsetX, datum.pOffsetY)
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
|
||||
elif datum.id == 51:
|
||||
|
||||
while True:
|
||||
pos = operation.find_photo_position(current_working_directory + datum.path)
|
||||
print(pos)
|
||||
if pos is not None:
|
||||
for q in range(datum.time):
|
||||
operation.up_drag(pos, r_value, datum.pOffsetX, datum.pOffsetY)
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
break
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
time.sleep(1)
|
||||
|
||||
elif datum.id == 52:
|
||||
|
||||
while True:
|
||||
pos = operation.find_word_position(datum.path)
|
||||
if pos is not None:
|
||||
for q in range(datum.time):
|
||||
operation.up_drag(pos, r_value, datum.pOffsetX, datum.pOffsetY)
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
break
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
time.sleep(1)
|
||||
|
||||
elif datum.id == 53:
|
||||
path_array = datum.path.split(',') # 使用逗号作为分隔符
|
||||
path_array = [int(x) for x in path_array]
|
||||
|
||||
for q in range(datum.time):
|
||||
operation.up_drag(
|
||||
{'left': path_array[0], 'top': path_array[1], 'width': path_array[2], 'height': path_array[3]},
|
||||
r_value, datum.pOffsetX, datum.pOffsetY)
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
|
||||
elif datum.id == 61:
|
||||
|
||||
while True:
|
||||
pos = operation.find_photo_position(current_working_directory + datum.path)
|
||||
print(pos)
|
||||
if pos is not None:
|
||||
for q in range(datum.time):
|
||||
operation.down_drag(pos, r_value, datum.pOffsetX, datum.pOffsetY)
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
break
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
time.sleep(1)
|
||||
|
||||
elif datum.id == 62:
|
||||
|
||||
while True:
|
||||
pos = operation.find_word_position(datum.path)
|
||||
if pos is not None:
|
||||
for q in range(datum.time):
|
||||
operation.down_drag(pos, r_value, datum.pOffsetX, datum.pOffsetY)
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
break
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
time.sleep(1)
|
||||
|
||||
elif datum.id == 63:
|
||||
path_array = datum.path.split(',') # 使用逗号作为分隔符
|
||||
path_array = [int(x) for x in path_array]
|
||||
|
||||
for q in range(datum.time):
|
||||
operation.down_drag(
|
||||
{'left': path_array[0], 'top': path_array[1], 'width': path_array[2], 'height': path_array[3]},
|
||||
r_value, datum.pOffsetX, datum.pOffsetY)
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
|
||||
elif datum.id == 71:
|
||||
while True:
|
||||
pos = operation.find_photo_position(current_working_directory + datum.path)
|
||||
print(pos)
|
||||
if pos is not None:
|
||||
for q in range(datum.time):
|
||||
operation.click_long(pos, datum.pOffsetX, datum.pOffsetY)
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
break
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
time.sleep(1)
|
||||
|
||||
elif datum.id == 72:
|
||||
|
||||
while True:
|
||||
pos = operation.find_word_position(datum.path)
|
||||
if pos is not None:
|
||||
for q in range(datum.time):
|
||||
operation.left_drag(pos, datum.pOffsetX, datum.pOffsetY)
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
break
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
time.sleep(1)
|
||||
|
||||
elif datum.id == 73:
|
||||
path_array = datum.path.split(',') # 使用逗号作为分隔符
|
||||
path_array = [int(x) for x in path_array]
|
||||
|
||||
for q in range(datum.time):
|
||||
operation.left_drag(
|
||||
{'left': path_array[0], 'top': path_array[1], 'width': path_array[2], 'height': path_array[3]},
|
||||
datum.pOffsetX, datum.pOffsetY)
|
||||
if keyboard.is_pressed('esc'):
|
||||
i = 9999
|
||||
break
|
||||
|
||||
#
|
||||
# if __name__ == '__main__':
|
||||
# db_control = DatabaseControl(database='test2.sqlite3')
|
||||
#
|
||||
# db_control.perform_userGeneralRulename('延时')
|
||||
# db_control.close()
|
@ -0,0 +1,230 @@
|
||||
import time
|
||||
|
||||
import cv2
|
||||
import pyautogui as p
|
||||
from windows.entity.operations.operation_first import operation_first
|
||||
from windows.res.tools.deal_picture import DealPicture
|
||||
from windows.res.tools.recognise_words import Recognise_word
|
||||
|
||||
p.PAUSE = 0.1
|
||||
p.FAILSAFE = True
|
||||
|
||||
|
||||
def backToTerminal():
|
||||
print("back to terminal")
|
||||
find_photo = cv2.imread('res/pictures/terminal_photo.png')
|
||||
positions = DealPicture.find_photo_center(find_photo, 2)
|
||||
while positions is None:
|
||||
click_photo = cv2.imread('res/pictures/back_btn.png')
|
||||
back_confirm = cv2.imread('res/pictures/back_confirm.png')
|
||||
if DealPicture.find_photo_center(click_photo, 1):
|
||||
operation_first.click_once(click_photo)
|
||||
else:
|
||||
return False
|
||||
if DealPicture.find_photo_center(back_confirm, 1):
|
||||
operation_first.click_once(back_confirm)
|
||||
else:
|
||||
return False
|
||||
positions = DealPicture.find_photo_center('res/pictures/terminal_photo.png')
|
||||
print("find terminal")
|
||||
return True
|
||||
|
||||
|
||||
# 19 进入招募界面
|
||||
def enter_recruit():
|
||||
print("enter_recruit")
|
||||
|
||||
find_photo = cv2.imread('res/pictures/in_recruit.png')
|
||||
if DealPicture.find_photo_center(find_photo, 2):
|
||||
print("in_recruit")
|
||||
else:
|
||||
if backToTerminal() is False:
|
||||
return False
|
||||
|
||||
find_photo = cv2.imread('res/pictures/public_recruit.png')
|
||||
stop_photo = cv2.imread('res/pictures/in_recruit.png')
|
||||
DealPicture.find_photo_center(find_photo, 2)
|
||||
if DealPicture.find_photo_center(find_photo, 2):
|
||||
operation_first.click_util(find_photo, lambda: DealPicture.find_photo_center(stop_photo))
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
# 20 公开招募所有
|
||||
def public_recruit_all():
|
||||
print('现在在公开招募界面')
|
||||
find_word = '开始招募干员'
|
||||
find_photo = cv2.imread('res/pictures/in_recruit.png')
|
||||
if DealPicture.find_photo_center(find_photo) is None:
|
||||
return False
|
||||
click_photo = cv2.imread('res/pictures/hire_operator.png')
|
||||
stop_photo = cv2.imread('res/pictures/skip_word.png')
|
||||
while DealPicture.find_photo_center(click_photo) is not None:
|
||||
operation_first.click_util(click_photo, lambda: DealPicture.find_photo_center(stop_photo))
|
||||
click_photo = cv2.imread('res/pictures/skip_word.png')
|
||||
position = DealPicture.find_photo_position(click_photo)
|
||||
if position is not None:
|
||||
stop_photo = cv2.imread('res/pictures/in_recruit.png')
|
||||
operation_first.click_position_util(position, lambda: DealPicture.find_photo_center(stop_photo))
|
||||
else:
|
||||
return False
|
||||
shotphoto = p.screenshot()
|
||||
words_inf = Recognise_word.recognise_word(shotphoto)
|
||||
find_photo = cv2.imread('res/pictures/01times.png')
|
||||
count_fail = 0
|
||||
position = Recognise_word.find_word_positon(find_word, words_inf)
|
||||
|
||||
while position is not None:
|
||||
operation_first.click_position_util(position, lambda: DealPicture.find_photo_center(find_photo))
|
||||
position = DealPicture.find_photo_position(find_photo)
|
||||
|
||||
if position is not None:
|
||||
stop_photo = cv2.imread('res/pictures/09times.png')
|
||||
position['top'] += 70
|
||||
operation_first.click_position_util(position, lambda: DealPicture.find_photo_center(stop_photo))
|
||||
else:
|
||||
return False
|
||||
|
||||
position_photo1 = cv2.imread('res/pictures/profession_need.png')
|
||||
position_photo2 = cv2.imread('res/pictures/white_frame.png')
|
||||
position1 = DealPicture.find_photo_position(position_photo1)
|
||||
position2 = DealPicture.find_photo_position(position_photo2)
|
||||
position = {}
|
||||
if position1 is not None and position2 is not None:
|
||||
position['left'] = position1['left'] + position1['width']
|
||||
position['top'] = position1['top']
|
||||
position['height'] = position1['height']
|
||||
position['width'] = position2['left'] + position2['width'] - position['left']
|
||||
if len(position) > 0:
|
||||
shotphoto = DealPicture.shot_photo(position)
|
||||
words = Recognise_word.recognise_word(shotphoto)
|
||||
priority_list = DealPicture.class_recuit_priority(words)
|
||||
if priority_list is None:
|
||||
return True
|
||||
word_positions = Recognise_word.find_words_positon(priority_list, words)
|
||||
for word_postion in word_positions:
|
||||
word_postion['left'] += position['left']
|
||||
word_postion['top'] += position['top']
|
||||
if priority_list is not None:
|
||||
click_list(word_positions)
|
||||
|
||||
click_photo = cv2.imread('res/pictures/recruit_confirm.png')
|
||||
if DealPicture.find_photo_center(click_photo):
|
||||
operation_first.click_util(click_photo, lambda: DealPicture.find_no_photos([click_photo]))
|
||||
time.sleep(1)
|
||||
shotphoto = p.screenshot()
|
||||
words_inf = Recognise_word.recognise_word(shotphoto)
|
||||
position = Recognise_word.find_word_positon(find_word, words_inf)
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
# 21 公开招募一个
|
||||
def public_recruit_one():
|
||||
try:
|
||||
print('现在在公开招募界面')
|
||||
find_word = '开始招募干员'
|
||||
find_photo = cv2.imread('res/pictures/in_recruit.png')
|
||||
if DealPicture.find_photo_center(find_photo) is None:
|
||||
return False
|
||||
click_photo = cv2.imread('res/pictures/hire_operator.png')
|
||||
stop_photo = cv2.imread('res/pictures/skip_word.png')
|
||||
while DealPicture.find_photo_center(click_photo) is not None:
|
||||
operation_first.click_util(click_photo, lambda: DealPicture.find_photo_center(stop_photo))
|
||||
click_photo = cv2.imread('res/pictures/skip_word.png')
|
||||
position = DealPicture.find_photo_position(click_photo)
|
||||
if position is not None:
|
||||
stop_photo = cv2.imread('res/pictures/in_recruit.png')
|
||||
operation_first.click_position_util(position, lambda: DealPicture.find_photo_center(stop_photo))
|
||||
else:
|
||||
return False
|
||||
shotphoto = p.screenshot()
|
||||
words_inf = Recognise_word.recognise_word(shotphoto)
|
||||
find_photo = cv2.imread('res/pictures/01times.png')
|
||||
position = Recognise_word.find_word_positon(find_word, words_inf)
|
||||
if position is not None:
|
||||
operation_first.click_position_util(position, lambda: DealPicture.find_photo_center(find_photo))
|
||||
position = DealPicture.find_photo_position(find_photo)
|
||||
if position is not None:
|
||||
stop_photo = cv2.imread('res/pictures/09times.png')
|
||||
position['top'] += 70
|
||||
operation_first.click_position_util(position, lambda: DealPicture.find_photo_center(stop_photo))
|
||||
else:
|
||||
return False
|
||||
|
||||
position_photo1 = cv2.imread('res/pictures/profession_need.png')
|
||||
position_photo2 = cv2.imread('res/pictures/white_frame.png')
|
||||
position1 = DealPicture.find_photo_position(position_photo1)
|
||||
position2 = DealPicture.find_photo_position(position_photo2)
|
||||
position = {}
|
||||
if position1 is not None and position2 is not None:
|
||||
position['left'] = position1['left'] + position1['width']
|
||||
position['top'] = position1['top']
|
||||
position['height'] = position1['height']
|
||||
position['width'] = position2['left'] + position2['width'] - position['left']
|
||||
if len(position) > 0:
|
||||
shotphoto = DealPicture.shot_photo(position)
|
||||
words = Recognise_word.recognise_word(shotphoto)
|
||||
priority_list = DealPicture.class_recuit_priority(words)
|
||||
if priority_list is None:
|
||||
return True
|
||||
word_positions = Recognise_word.find_words_positon(priority_list, words)
|
||||
for word_postion in word_positions:
|
||||
word_postion['left'] += position['left']
|
||||
word_postion['top'] += position['top']
|
||||
if priority_list is not None:
|
||||
click_list(word_positions)
|
||||
|
||||
click_photo = cv2.imread('res/pictures/recruit_confirm.png')
|
||||
if DealPicture.find_photo_center(click_photo):
|
||||
operation_first.click_util(click_photo, lambda: DealPicture.find_no_photos([click_photo]))
|
||||
time.sleep(1)
|
||||
else:
|
||||
return False
|
||||
except Exception as e:
|
||||
# 处理其他类型的异常
|
||||
print(f"Unexpected error: {e}")
|
||||
return True
|
||||
|
||||
|
||||
# 22 使用加急凭证
|
||||
def use_ugent_recruit():
|
||||
"""
|
||||
使用加急凭证
|
||||
"""
|
||||
|
||||
click_photo1 = cv2.imread('res/pictures/recruit_now.png')
|
||||
stop_photo1 = cv2.imread('res/pictures/back_confirm.png')
|
||||
while DealPicture.find_photo_center(click_photo1) is not None:
|
||||
|
||||
operation_first.click_util(click_photo1, lambda: DealPicture.find_photo_center(stop_photo1))
|
||||
click_photo = cv2.imread('res/pictures/back_confirm.png')
|
||||
stop_photo = cv2.imread('res/pictures/hire_operator.png')
|
||||
operation_first.click_util(click_photo, lambda: DealPicture.find_photo_center(stop_photo))
|
||||
click_photo = cv2.imread('res/pictures/hire_operator.png')
|
||||
stop_photo = cv2.imread('res/pictures/skip_word.png')
|
||||
operation_first.click_util(click_photo, lambda: DealPicture.find_photo_center(stop_photo))
|
||||
click_photo = cv2.imread('res/pictures/skip_word.png')
|
||||
position = DealPicture.find_photo_position(click_photo)
|
||||
if position is not None:
|
||||
stop_photo = cv2.imread('res/pictures/in_recruit.png')
|
||||
operation_first.click_position_util(position, lambda: DealPicture.find_photo_center(stop_photo))
|
||||
else:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def click_list(positions):
|
||||
for position in positions:
|
||||
operation_first.click_position_once(position)
|
||||
|
||||
|
||||
def start_rule():
|
||||
print('公开招募')
|
||||
if enter_recruit() is False:
|
||||
backToTerminal()
|
||||
enter_recruit()
|
||||
public_recruit_all()
|
||||
backToTerminal()
|
@ -0,0 +1,149 @@
|
||||
import cv2
|
||||
import pyautogui as p
|
||||
from windows.entity.operations.operation_first import operation_first
|
||||
from windows.res.tools.deal_picture import DealPicture
|
||||
|
||||
p.PAUSE = 0.1
|
||||
p.FAILSAFE = True
|
||||
|
||||
|
||||
def backToTerminal():
|
||||
print("back to terminal")
|
||||
find_photo = cv2.imread('res/pictures/terminal_photo.png')
|
||||
positions = DealPicture.find_photo_center(find_photo, 2)
|
||||
while positions is None:
|
||||
click_photo = cv2.imread('res/pictures/back_btn.png')
|
||||
back_confirm = cv2.imread('res/pictures/back_confirm.png')
|
||||
if DealPicture.find_photo_center(click_photo, 1):
|
||||
operation_first.click_once(click_photo)
|
||||
else:
|
||||
return False
|
||||
if DealPicture.find_photo_center(back_confirm, 1):
|
||||
operation_first.click_once(back_confirm)
|
||||
else:
|
||||
return False
|
||||
positions = DealPicture.find_photo_center('res/pictures/terminal_photo.png')
|
||||
print("find terminal")
|
||||
return True
|
||||
|
||||
|
||||
# 16 获取信用点
|
||||
def visit_base():
|
||||
click_photo = cv2.imread('res/pictures/friends.png')
|
||||
stop_photo = cv2.imread('res/pictures/friends_list.png')
|
||||
|
||||
positions = DealPicture.find_photo_center(click_photo, 1)
|
||||
if positions is None:
|
||||
backToTerminal()
|
||||
positions = DealPicture.find_photo_center(click_photo, 1)
|
||||
if positions is not None:
|
||||
operation_first.click_util(click_photo, lambda: DealPicture.find_photo_center(stop_photo))
|
||||
click_photo = cv2.imread('res/pictures/friends_list.png')
|
||||
stop_photo = cv2.imread('res/pictures/visit_base.png')
|
||||
positions = DealPicture.find_photo_center(click_photo, 1)
|
||||
if positions is not None:
|
||||
operation_first.click_util(click_photo, lambda: DealPicture.find_photo_center(stop_photo))
|
||||
else:
|
||||
return False
|
||||
click_photo = cv2.imread('res/pictures/visit_base.png')
|
||||
stop_photo = cv2.imread('res/pictures/visit_next.png')
|
||||
positions = DealPicture.find_photo_center(click_photo, 1)
|
||||
if positions is not None:
|
||||
operation_first.click_util(click_photo, lambda: DealPicture.find_photo_center(stop_photo))
|
||||
else:
|
||||
return False
|
||||
click_photo = cv2.imread('res/pictures/visit_next.png')
|
||||
stop_photo = cv2.imread('res/pictures/communicate_limit.png')
|
||||
positions = DealPicture.find_photo_center(click_photo, 1)
|
||||
if positions is not None:
|
||||
operation_first.click_util(click_photo, lambda: DealPicture.find_photo_center(stop_photo), 0, 0, 15)
|
||||
else:
|
||||
return False
|
||||
backToTerminal()
|
||||
return True
|
||||
|
||||
|
||||
# 17 消耗信用点
|
||||
def credit_consume():
|
||||
click_photo = cv2.imread('res/pictures/shop.png')
|
||||
stop_photo = cv2.imread('res/pictures/credit_deal.png')
|
||||
|
||||
positions = DealPicture.find_photo_center(click_photo, 1)
|
||||
if positions is None:
|
||||
backToTerminal()
|
||||
positions = DealPicture.find_photo_center(click_photo, 1)
|
||||
if positions is not None:
|
||||
operation_first.click_util(click_photo, lambda: DealPicture.find_photo_center(stop_photo))
|
||||
|
||||
click_photo = cv2.imread('res/pictures/credit_deal.png')
|
||||
stop_photo = [cv2.imread('res/pictures/in_credit_deal.png'), cv2.imread('res/pictures/unable_buy.png')]
|
||||
positions = DealPicture.find_photo_center(click_photo, 1)
|
||||
if positions is not None:
|
||||
operation_first.click_util(click_photo, lambda: DealPicture.find_any_photos(stop_photo))
|
||||
else:
|
||||
return False
|
||||
if DealPicture.find_photo_center(stop_photo[0]) is None:
|
||||
backToTerminal()
|
||||
return True
|
||||
find_photo = cv2.imread('res/pictures/sale.png')
|
||||
stop_photo = cv2.imread('res/pictures/buy.png')
|
||||
stop_photo1 = cv2.imread('res/pictures/in_credit_deal.png')
|
||||
|
||||
positions = DealPicture.match_template_all(find_photo, 0.99)
|
||||
for position in positions:
|
||||
operation_first.click_position_util(position, lambda: DealPicture.find_photo_center(stop_photo))
|
||||
buy_position = DealPicture.find_photo_position(stop_photo)
|
||||
if buy_position is not None:
|
||||
operation_first.click_position_util(buy_position, lambda: DealPicture.find_photo_center(stop_photo1))
|
||||
else:
|
||||
if DealPicture.find_photo_center(stop_photo1) is None:
|
||||
find_photo1 = cv2.imread('res/pictures/back_btn.png')
|
||||
if DealPicture.find_photo_center(find_photo1) is not None:
|
||||
operation_first.click_once(find_photo1)
|
||||
backToTerminal()
|
||||
return True
|
||||
|
||||
|
||||
# 18 获得日常奖励
|
||||
def acquire_award():
|
||||
click_photo = cv2.imread('res/pictures/mission.png')
|
||||
stop_photo = cv2.imread('res/pictures/clicked_daily_mission.png')
|
||||
|
||||
positions = DealPicture.find_photo_center(click_photo, 1)
|
||||
if positions is None:
|
||||
backToTerminal()
|
||||
positions = DealPicture.find_photo_center(click_photo, 1)
|
||||
if positions is not None:
|
||||
operation_first.click_util(click_photo, lambda: DealPicture.find_photo_center(stop_photo))
|
||||
|
||||
click_photo = cv2.imread('res/pictures/collect_all_award.png')
|
||||
stop_photo = cv2.imread('res/pictures/unclicked_weekly_mission.png')
|
||||
positions = DealPicture.find_photo_position(click_photo)
|
||||
if positions is not None:
|
||||
operation_first.click_position_util(positions, lambda: DealPicture.find_no_photos(click_photo))
|
||||
operation_first.click_position_util(positions, lambda: DealPicture.find_photo_center(stop_photo))
|
||||
|
||||
click_photo = cv2.imread('res/pictures/unclicked_weekly_mission.png')
|
||||
stop_photo = cv2.imread('res/pictures/clicked_weekly_mission.png')
|
||||
if click_photo is not None:
|
||||
operation_first.click_util(click_photo, lambda: DealPicture.find_photo_center(stop_photo))
|
||||
|
||||
click_photo = cv2.imread('res/pictures/collect_all_award.png')
|
||||
stop_photo = cv2.imread('res/pictures/clicked_weekly_mission.png')
|
||||
positions = DealPicture.find_photo_position(click_photo)
|
||||
if positions is not None:
|
||||
operation_first.click_position_util(positions, lambda: DealPicture.find_no_photos(click_photo))
|
||||
operation_first.click_position_util(positions, lambda: DealPicture.find_photo_center(stop_photo))
|
||||
|
||||
backToTerminal()
|
||||
return True
|
||||
|
||||
|
||||
def start_rule():
|
||||
print('日常处理')
|
||||
if visit_base() is False:
|
||||
backToTerminal()
|
||||
visit_base()
|
||||
backToTerminal()
|
||||
credit_consume()
|
||||
backToTerminal()
|