Add player sparring command
This commit is contained in:
1 parent
1b9f973db3
commit
dbd2831dda
3 files changed
+30
-5
No files matched your search
@@ -477,6 +477,11 @@ class Commands:
|
|||||||
self.g.job.state = self.g.job.combat
|
self.g.job.state = self.g.job.combat
|
||||||
reply = 'ok'
|
reply = 'ok'
|
||||||
|
|
||||||
|
## 1kill - spars with nearby players within 16 blocks
|
||||||
|
if command == 'kill':
|
||||||
|
self.g.job.state = self.g.job.kill
|
||||||
|
reply = 'ok'
|
||||||
|
|
||||||
## 1sleep [new] - use a bed; `new` forces bed placement
|
## 1sleep [new] - use a bed; `new` forces bed placement
|
||||||
if command == 'sleep':
|
if command == 'sleep':
|
||||||
self.g.job.sleep_with_bed_states.force_new_bed = (
|
self.g.job.sleep_with_bed_states.force_new_bed = (
|
||||||
|
|||||||
@@ -266,6 +266,8 @@ class JobStates(LegacyJobStates):
|
|||||||
def __init__(self, global_state):
|
def __init__(self, global_state):
|
||||||
self.g = global_state
|
self.g = global_state
|
||||||
self.combat_states = combat.CombatStates(global_state)
|
self.combat_states = combat.CombatStates(global_state)
|
||||||
|
self.kill_states = combat.CombatStates(
|
||||||
|
global_state, target_players=True)
|
||||||
self.gather_wood_states = gather_wood.GatherWoodStates(global_state)
|
self.gather_wood_states = gather_wood.GatherWoodStates(global_state)
|
||||||
self.gather_crop_states = gather_crop.GatherCropStates(global_state)
|
self.gather_crop_states = gather_crop.GatherCropStates(global_state)
|
||||||
self.gather_wart_states = gather_wart.GatherWartStates(global_state)
|
self.gather_wart_states = gather_wart.GatherWartStates(global_state)
|
||||||
@@ -333,6 +335,9 @@ class JobStates(LegacyJobStates):
|
|||||||
def combat(self):
|
def combat(self):
|
||||||
return [self.combat_states]
|
return [self.combat_states]
|
||||||
|
|
||||||
|
def kill(self):
|
||||||
|
return [self.kill_states]
|
||||||
|
|
||||||
def eat(self):
|
def eat(self):
|
||||||
return [self.eat_food_states]
|
return [self.eat_food_states]
|
||||||
|
|
||||||
@@ -362,6 +367,8 @@ class JobStates(LegacyJobStates):
|
|||||||
self.g.game.leave_bed()
|
self.g.game.leave_bed()
|
||||||
self.combat_states.state = self.combat_states.idle
|
self.combat_states.state = self.combat_states.idle
|
||||||
self.combat_states.target_id = None
|
self.combat_states.target_id = None
|
||||||
|
self.kill_states.state = self.kill_states.idle
|
||||||
|
self.kill_states.target_id = None
|
||||||
self.gather_wood_states.state = self.gather_wood_states.idle
|
self.gather_wood_states.state = self.gather_wood_states.idle
|
||||||
self.gather_crop_states.state = self.gather_crop_states.idle
|
self.gather_crop_states.state = self.gather_crop_states.idle
|
||||||
self.gather_sand_states.state = self.gather_sand_states.idle
|
self.gather_sand_states.state = self.gather_sand_states.idle
|
||||||
|
|||||||
+18
-5
@@ -59,6 +59,10 @@ class CombatStates:
|
|||||||
self._log('no main-hand sword available; fighting unarmed')
|
self._log('no main-hand sword available; fighting unarmed')
|
||||||
self.state = self.find_target
|
self.state = self.find_target
|
||||||
|
|
||||||
|
def _target_entities(self):
|
||||||
|
key = 'players' if self.target_players else 'mobs'
|
||||||
|
return self.g.get(key, {})
|
||||||
|
|
||||||
def _coordinates(self, mob):
|
def _coordinates(self, mob):
|
||||||
return (float(mob.x), float(mob.y), float(mob.z))
|
return (float(mob.x), float(mob.y), float(mob.z))
|
||||||
|
|
||||||
@@ -102,14 +106,21 @@ class CombatStates:
|
|||||||
return utils.phyp(approach, grounded_target)
|
return utils.phyp(approach, grounded_target)
|
||||||
|
|
||||||
def _describe(self, mob):
|
def _describe(self, mob):
|
||||||
|
if self.target_players:
|
||||||
|
player_uuid = str(mob.get('player_uuid', ''))
|
||||||
|
return self.g.get('player_names', {}).get(player_uuid, 'player')
|
||||||
return mobs.MOB_NAMES.get(mob.get('type'), 'unknown mob')
|
return mobs.MOB_NAMES.get(mob.get('type'), 'unknown mob')
|
||||||
|
|
||||||
def find_target(self):
|
def find_target(self):
|
||||||
search_started = time.monotonic()
|
search_started = time.monotonic()
|
||||||
candidates = []
|
candidates = []
|
||||||
for entity_id, mob in self.g.get('mobs', {}).items():
|
for entity_id, mob in self._target_entities().items():
|
||||||
if entity_id in self.skipped_ids:
|
if entity_id in self.skipped_ids:
|
||||||
continue
|
continue
|
||||||
|
if self.target_players:
|
||||||
|
if entity_id == self.g.get('eid'):
|
||||||
|
continue
|
||||||
|
else:
|
||||||
mob_type = mob.get('type')
|
mob_type = mob.get('type')
|
||||||
if (mob_type not in mobs.MOB_NAMES or
|
if (mob_type not in mobs.MOB_NAMES or
|
||||||
mob_type in mobs.NON_MOB_ENTITY_IDS):
|
mob_type in mobs.NON_MOB_ENTITY_IDS):
|
||||||
@@ -120,8 +131,9 @@ class CombatStates:
|
|||||||
|
|
||||||
search_elapsed = time.monotonic() - search_started
|
search_elapsed = time.monotonic() - search_started
|
||||||
if not candidates:
|
if not candidates:
|
||||||
self._log('no mobs within 16 blocks (scan {:.3f}s)'.format(
|
noun = 'players' if self.target_players else 'mobs'
|
||||||
search_elapsed))
|
self._log('no {} within 16 blocks (scan {:.3f}s)'.format(
|
||||||
|
noun, search_elapsed))
|
||||||
self.cleanup()
|
self.cleanup()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -220,7 +232,7 @@ class CombatStates:
|
|||||||
self.next_path_at = time.monotonic() + self.PATH_RETRY_INTERVAL
|
self.next_path_at = time.monotonic() + self.PATH_RETRY_INTERVAL
|
||||||
|
|
||||||
def engage(self):
|
def engage(self):
|
||||||
target = self.g.get('mobs', {}).get(self.target_id)
|
target = self._target_entities().get(self.target_id)
|
||||||
if target is None:
|
if target is None:
|
||||||
self._log_target_end('lost target entity')
|
self._log_target_end('lost target entity')
|
||||||
self.target_id = None
|
self.target_id = None
|
||||||
@@ -317,8 +329,9 @@ class CombatStates:
|
|||||||
self._log('state {} took {:.3f}s'.format(
|
self._log('state {} took {:.3f}s'.format(
|
||||||
getattr(state, '__name__', 'unknown'), duration))
|
getattr(state, '__name__', 'unknown'), duration))
|
||||||
|
|
||||||
def __init__(self, global_state):
|
def __init__(self, global_state, target_players=False):
|
||||||
self.g = global_state
|
self.g = global_state
|
||||||
|
self.target_players = target_players
|
||||||
self.state = self.idle
|
self.state = self.idle
|
||||||
self.target_id = None
|
self.target_id = None
|
||||||
self.path_target = None
|
self.path_target = None
|
||||||
|
|||||||
Reference in new issue
Block a user