Log threat combat weapon eligibility
This commit is contained in:
1 parent
a1d5c480a1
commit
295f033411
1 file changed
+23
-6
@@ -77,11 +77,12 @@ class ThreatMonitor:
|
||||
return [mob for mob in threats if line_of_sight(
|
||||
(mob.x, mob.y + 1.5, mob.z), target, target_block)]
|
||||
|
||||
def _has_sword(self):
|
||||
return any(
|
||||
9 <= slot <= 44 and getattr(stack, 'present', False) and
|
||||
stack.item_id in items.SWORD_IDS
|
||||
for slot, stack in self.g.get('inv', {}).items())
|
||||
def _sword_slots(self):
|
||||
return sorted(
|
||||
(slot, stack.item_id)
|
||||
for slot, stack in self.g.get('inv', {}).items()
|
||||
if 9 <= slot <= 44 and getattr(stack, 'present', False) and
|
||||
stack.item_id in items.SWORD_IDS)
|
||||
|
||||
def _sleep_before_combat(self):
|
||||
current_time = self.g.get('time')
|
||||
@@ -371,9 +372,25 @@ class ThreatMonitor:
|
||||
for threat in threats)
|
||||
print('[threat] detected {} nearby hostile(s); pausing job: {}'.format(
|
||||
len(threats), descriptions), flush=True)
|
||||
if self._has_sword():
|
||||
sword_slots = self._sword_slots()
|
||||
if sword_slots:
|
||||
descriptions = ', '.join(
|
||||
'{} in slot {}'.format(
|
||||
items.ITEM_NAMES.get(item_id, str(item_id)), slot)
|
||||
for slot, item_id in sword_slots)
|
||||
print('[threat] defensive combat available: {}'.format(
|
||||
descriptions), flush=True)
|
||||
self._start_combat_response()
|
||||
return
|
||||
|
||||
offhand = self.g.get('inv', {}).get(45)
|
||||
if offhand and offhand.present and offhand.item_id in items.SWORD_IDS:
|
||||
reason = 'only sword is in offhand slot 45; attacks need a main-hand sword'
|
||||
else:
|
||||
reason = 'no sword found in main inventory/hotbar slots 9-44'
|
||||
print('[threat] defensive combat unavailable: {}; inventory_partial={}; '
|
||||
'evacuating instead'.format(
|
||||
reason, self.g.get('inventory_partial', False)), flush=True)
|
||||
self._suspend_job()
|
||||
self.g.look_at = None
|
||||
self.safe_since = None
|
||||
|
||||
Reference in new issue
Block a user