mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-19 11:09:29 +08:00
add: add python interface for obtaining resource information and GG factor
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import json
|
||||
from typing import Dict
|
||||
|
||||
import requests
|
||||
import adbutils
|
||||
from pydantic import BaseModel
|
||||
@@ -33,19 +36,137 @@ class CrackApi:
|
||||
level: str = ""
|
||||
id: str = ""
|
||||
|
||||
class ShipInfo(BaseModel):
|
||||
config_id: int
|
||||
emotion: int
|
||||
rarity: int
|
||||
level: int
|
||||
exp: int
|
||||
curr_star: int
|
||||
|
||||
def __init__(self, base_url):
|
||||
self.api_url = base_url
|
||||
|
||||
def post(self, path, data=None):
|
||||
url = f'{self.api_url}/{path}'
|
||||
def get(self, path, **kwargs):
|
||||
args = []
|
||||
for k, v in kwargs.items():
|
||||
if v is None:
|
||||
continue
|
||||
args.append(f'{k}={v}')
|
||||
if args:
|
||||
url = f'{self.api_url}/{path}?{"&".join(args)}'
|
||||
else:
|
||||
url = f'{self.api_url}/{path}'
|
||||
try:
|
||||
response = requests.post(url, data=data) # TODO: add timeout
|
||||
response = requests.get(url) # TODO: add timeout
|
||||
except requests.exceptions.Timeout:
|
||||
raise CrackerError('CrackApi request timeout')
|
||||
except Exception as e:
|
||||
raise CrackerError(f'CrackApi request error: {e}')
|
||||
if response.status_code != 200:
|
||||
raise CrackerError(f'CrackApi response error: {response.status_code}')
|
||||
return response
|
||||
|
||||
def post(self, path, data=None):
|
||||
url = f'{self.api_url}/{path}'
|
||||
if data is not None and isinstance(data, dict):
|
||||
data_str = json.dumps(data)
|
||||
else:
|
||||
data_str = data
|
||||
try:
|
||||
response = requests.post(url, data=data_str) # TODO: add timeout
|
||||
except requests.exceptions.Timeout:
|
||||
raise CrackerError('CrackApi request timeout')
|
||||
except Exception as e:
|
||||
raise CrackerError(f'CrackApi request error: {e}')
|
||||
if response.status_code != 200:
|
||||
raise CrackerError(f'CrackApi response error: {response.status_code}')
|
||||
|
||||
def get_coin(self) -> int:
|
||||
response = self.get('get_coin')
|
||||
return int(response.text)
|
||||
|
||||
def get_oil(self) -> int:
|
||||
response = self.get('get_oil')
|
||||
return int(response.text)
|
||||
|
||||
def get_gems(self) -> int:
|
||||
response = self.get('get_gems')
|
||||
return int(response.text)
|
||||
|
||||
def get_level(self) -> int:
|
||||
response = self.get('get_level')
|
||||
return int(response.text)
|
||||
|
||||
def get_exp(self) -> int:
|
||||
response = self.get('get_exp')
|
||||
return int(response.text)
|
||||
|
||||
def get_merit(self) -> int:
|
||||
response = self.get('get_merit')
|
||||
return int(response.text)
|
||||
|
||||
def get_guild_coin(self) -> int:
|
||||
response = self.get('get_guild_coin')
|
||||
return int(response.text)
|
||||
|
||||
def get_design_prt(self) -> int:
|
||||
response = self.get('get_design_prt')
|
||||
return int(response.text)
|
||||
|
||||
def get_core_data(self) -> str:
|
||||
response = self.get('get_core_data')
|
||||
return response.text
|
||||
|
||||
def get_medal(self) -> int:
|
||||
response = self.get('get_medal')
|
||||
return int(response.text)
|
||||
|
||||
def get_pt(self) -> int:
|
||||
response = self.get('get_pt')
|
||||
return int(response.text)
|
||||
|
||||
def get_specialized_core(self) -> int:
|
||||
response = self.get('get_specialized_core')
|
||||
return int(response.text)
|
||||
|
||||
def get_curr_action_points(self) -> int:
|
||||
response = self.get('get_curr_action_points')
|
||||
return int(response.text)
|
||||
|
||||
def scan_dock(self) -> Dict[int, ShipInfo]:
|
||||
response = self.get('scan_dock')
|
||||
json_data = json.loads(response.text)
|
||||
res = {}
|
||||
for k, v in json_data.items():
|
||||
res[int(k)] = CrackApi.ShipInfo(**v)
|
||||
return res
|
||||
|
||||
def scan_storage(self) -> Dict[int, int]:
|
||||
response = self.get('scan_storage')
|
||||
json_data = json.loads(response.text)
|
||||
res = {}
|
||||
for k, v in json_data.items():
|
||||
res[int(k)] = int(v)
|
||||
return res
|
||||
|
||||
def get_ship_info(self, ship_id: int) -> ShipInfo:
|
||||
response = self.get('get_ship_info', id=ship_id)
|
||||
json_data = json.loads(response.text)
|
||||
return CrackApi.ShipInfo(**json_data)
|
||||
|
||||
def get_storage_item_count(self, item_id: int) -> int:
|
||||
response = self.get('get_storage_item_count', id=item_id)
|
||||
return int(response.text)
|
||||
|
||||
def enable_gg_factor(self):
|
||||
self.post('enable_gg_factor')
|
||||
|
||||
def disable_gg_factor(self):
|
||||
self.post('disable_gg_factor')
|
||||
|
||||
def update_gg_factor(self, gg_factor: float):
|
||||
self.post('update_gg_factor', data={'factor': gg_factor})
|
||||
|
||||
def disable_all(self):
|
||||
self.post('disable_all')
|
||||
|
||||
@@ -26,6 +26,7 @@ ALL_ENABLE_OPS = [
|
||||
CrackOp.EnableOpsiFastMove,
|
||||
CrackOp.EnableRemoveHardModeShipTypeLimit,
|
||||
CrackOp.EnableRemoveHardModeShipPropertiesLimit,
|
||||
CrackOp.EnableGGFactor,
|
||||
]
|
||||
|
||||
|
||||
@@ -177,6 +178,7 @@ CHAPTER_CRACK_OPS = [
|
||||
CrackOp.EnableGlobalShipProperties,
|
||||
CrackOp.EnableRemoveHardModeLimit,
|
||||
CrackOp.EnableFakePlayer,
|
||||
CrackOp.EnableGGFactor,
|
||||
]
|
||||
|
||||
|
||||
@@ -194,6 +196,7 @@ OPSI_CRACK_OPS = [
|
||||
CrackOp.EnableOpsiFastMove,
|
||||
CrackOp.EnableGlobalShipProperties,
|
||||
CrackOp.EnableFakePlayer,
|
||||
CrackOp.EnableGGFactor,
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ class CrackOp:
|
||||
|
||||
class EnableAll(Op):
|
||||
...
|
||||
|
||||
class DisableAll(Op):
|
||||
...
|
||||
|
||||
@@ -62,4 +63,10 @@ class CrackOp:
|
||||
...
|
||||
|
||||
class IsAlive(Op):
|
||||
...
|
||||
...
|
||||
|
||||
class EnableGGFactor(Op):
|
||||
...
|
||||
|
||||
class DisableGGFactor(Op):
|
||||
...
|
||||
|
||||
Reference in New Issue
Block a user