The Player class in lib/player.py is used to abstract and isolate game-related behaviors (character actions, etc.) from specific libraries like hunter, poco, or airtest. This isolation allows for easier framework upgrades.
Key components:
PROCESS: A variable representing the Hunter project code (e.g., 'g62').NeteasePoco: Used via the poco property to interact with the game UI.Singleton: The Player class is implemented as a Singleton to ensure a single instance manages the connection.
Example implementation structure:
# coding=utf-8
import sys
import re
from airtest_hunter import AirtestHunter, open_platform, wait_for_hunter_connected
from poco.drivers.netease.internal import NeteasePoco as Poco
PROCESS = 'g62' # hunter project code
class Player(object):
__metaclass__ = Singleton
def __init__(self, hunter=None):
self._hunter = hunter or get_hunter_instance()
self._poco_instance = None
@property
def poco(self):
if not self._poco_instance:
self._poco_instance = Poco(PROCESS, self._hunter)
return self._poco_instance
@property
def hunter(self):
return self._hunter
def refresh(self):
wait_for_hunter_connected(PROCESS, timeout=16)
self._hunter = get_hunter_instance()
self._poco_instance = Poco(PROCESS, self._hunter)
def server_call(self, cmd):
self.hunter.script(cmd, lang='text')
class Player(object):
__metaclass__ = Singleton
def __init__(self, hunter=None):
self._hunter = hunter or get_hunter_instance()
self._poco_instance = None
@property
def poco(self):
if not self._poco_instance:
self._poco_instance = Poco(PROCESS, self._hunter)
return self._poco_instance
@property
def hunter(self):
return self._hunter
def refresh(self):
wait_for_hunter_connected(PROCESS, timeout=16)
self._hunter = get_hunter_instance()
self._poco_instance = Poco(PROCESS, self._hunter)
def server_call(self, cmd):
self.hunter.script(cmd, lang='text')