代码拉取完成,页面将自动刷新
import math
import random
import sys
import time
from datetime import datetime
from selenium.webdriver.common.by import By
from libs import config
from libs.action import WebDriverAction
from libs.game import Game
from libs.image import ImageTool
from libs.log import Log
from libs.movement import Movement
from libs.task_helper import TaskHelper
from libs.trade_helper import TradeHelper
from libs.window import AdsWindow
def drink_popberry_wine(energy_target):
log.info(f"drink energy start: energy={game.get_energy()}, need {energy_target}")
home_loc = action.goto_spec()
game.open_backpack()
wine_loc = image_tool.find_target('popberry_wine.png')
if wine_loc is None:
log.info('popberry wine not found')
else:
wine_x, wine_y = wine_loc
action.click_by_offset(wine_x + 20, wine_y + 20)
before_drink_energy = game.get_energy()
no_effect_count = 0
while True:
if energy_target - game.get_energy() < 77:
log.debug('energy full')
action.escape()
break
home_x, home_y = home_loc
action.move_by_offset(home_x + 45, home_y + 180)
action.click()
time.sleep(1)
after_drink_energy = game.get_energy()
if after_drink_energy - before_drink_energy > 10:
before_drink_energy = after_drink_energy
continue
else:
# 体力没增加
log.debug('drink no effect')
no_effect_count += 1
if no_effect_count > 2:
action.escape()
break
continue
log.info(f"drink energy end: energy={game.get_energy()}")
time.sleep(1)
game.close_backpack()
if __name__ == "__main__":
parser = TaskHelper.default_args_parser('Wine')
args = parser.parse_args()
task_helper = TaskHelper.from_args(args)
user_id = args.user_id
log = Log(user_id)
driver = AdsWindow(user_id).open(False)
game = Game(driver, user_id)
action = WebDriverAction(driver)
movement = Movement(driver)
image_tool = ImageTool(driver)
trade_helper = TradeHelper(driver, user_id)
game.enter_game()
game.collect_mail()
game.snapshot(user_id, 'before windmill', include_skills=False)
mill_items = {
'grainbow_flour_12': {
'name': 'Sack of Grainbow Flour',
'sell_item_name': 'Grainbow Flour',
'min_price': 300,
'energy_cost': 120,
'items': {
'Grainbow': 12 * 2,
},
'wait_seconds': 37 * 60,
'max_keep': 1,
},
'4-leaf-colveregano': {
'name': '4-Leaf Cloveregano',
'sell_item_name': '4-Leaf Cloveregano',
'min_price': 600,
'energy_cost': 12,
'items': {
'4-Leaf Clover': 1 * 3,
'Silk Slug Slime': 1 * 3,
},
'wait_seconds': random.randint(31 * 60, 40*60),
'max_keep': 1,
},
}
try:
cooking_item_key = '4-leaf-colveregano'
if user_id in [64,65,66,68,79]:
cooking_item_key = 'grainbow_flour_12'
log.info(f'mill {cooking_item_key}')
cooking_item = mill_items.get(cooking_item_key)
energy_cost = cooking_item.get('energy_cost')
if game.get_energy() < energy_cost + 5:
drink_popberry_wine(energy_cost + 80)
buy_items = {}
need_items = cooking_item.get('items', {})
for need_name in need_items:
need_qty = need_items.get(need_name)
has_qty = game.get_backpack_qty(need_name)
if has_qty < need_qty:
buy_items[need_name] = cooking_item.get('max_keep', 1) * need_qty - has_qty
if len(buy_items) > 0:
sys.exit()
# trade_helper.goto_buy_position()
# filter_input = trade_helper.open_market_buy()
# for buy_name in buy_items:
# buy_qty = buy_items.get(buy_name)
# trade_helper.market_buy_item(filter_input, buy_name, buy_qty)
# action.escape()
# action.escape()
mill_loc = action.goto_mill()
mill_x, mill_y = mill_loc
action.click_by_offset(mill_x, mill_y)
cooking_item_name = cooking_item.get('name')
opt = action.find_element(By.XPATH, f"//span[text()='{cooking_item_name}']", cooking_item_name, 3)
if opt is None:
action.escape()
time.sleep(1)
action.click()
opt = action.find_element(By.XPATH, f"//span[text()='{cooking_item_name}']", cooking_item_name, 10)
opt.click()
time.sleep(1)
craft_button = action.find_element(By.CLASS_NAME, "Crafting_craftingButton__Qd6Ke", 'CraftButton', 2)
if craft_button.text == 'Collect':
if craft_button.is_enabled():
craft_button.click()
time.sleep(3)
craft_button = action.find_element(By.CLASS_NAME, "Crafting_craftingButton__Qd6Ke", 'CraftButton', 2)
if craft_button.text == 'Create':
if craft_button.is_enabled():
craft_button.click()
action.escape()
action.escape()
sell_items = []
for mill_item in mill_items.values():
sell_name = mill_item.get('sell_item_name')
max_keep = mill_item.get('max_keep', 1)
has_qty = game.get_backpack_qty(sell_name)
if has_qty >= max_keep:
sell_items.append(sell_name)
if len(sell_items) > 0:
try:
hour = datetime.now().hour
if 8 < hour < 20:
action.goto_spec()
trade_helper.goto_sell_position()
for sell_item in sell_items:
trade_helper.open_shop_sell()
trade_helper.sell_item(sell_item, 9999)
time.sleep(1)
action.escape()
action.escape()
except Exception as e:
log.info('sell error:' + str(e))
pass
game.snapshot(user_id, 'after willdmill', include_skills=False)
task_helper.task_success()
if user_id%24 == datetime.now().hour:
task_helper.windmill(delay_seconds=random.randint(6 * 60 * 60, 8 * 60 * 60))
else:
task_helper.windmill(delay_seconds=cooking_item.get('wait_seconds'))
except Exception as e:
task_helper.task_fail()
task_helper.windmill(retry=True)
raise e
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。