Attack hostile mobs

This commit is contained in:
Tanner committed 2026-11-19 01:06:19 +00:00
1 parent 9c0db4e4b0
commit 0a499f901a
4 files changed
+165 -7

No files matched your search

+36 -3
View File
@@ -67,6 +67,19 @@ class CombatStates:
self.rush_count = 0
self.seen_projectile_ids = set()
if self.sleep_first:
sleep = self.g.job.sleep_with_bed_states
sleep.refuge_sign = None
sleep.force_new_bed = False
sleep.state = sleep.init
self._log('night detected; trying to sleep before combat')
self.state = self.sleep_before_combat
return
self._select_sword()
self.state = self.find_target
def _select_sword(self):
main_hand_sword = any(
9 <= slot <= 44 and getattr(stack, 'present', False) and
stack.item_id in items.SWORD_IDS
@@ -76,7 +89,16 @@ class CombatStates:
self._log('selected sword')
else:
self._log('no main-hand sword available; fighting unarmed')
self.state = self.find_target
def sleep_before_combat(self):
sleep = self.g.job.sleep_with_bed_states
sleep.run()
if sleep.state == sleep.done:
self._log('sleep attempt finished; starting combat')
sleep.state = sleep.idle
self.sleep_first = False
self._select_sword()
self.state = self.find_target
def _target_entities(self):
key = 'players' if self.target_players else 'mobs'
@@ -137,18 +159,24 @@ class CombatStates:
for entity_id, mob in self._target_entities().items():
if entity_id in self.skipped_ids:
continue
if (self.allowed_target_ids is not None and
entity_id not in self.allowed_target_ids):
continue
if self.target_players:
if entity_id == self.g.get('eid'):
continue
else:
mob_type = mob.get('type')
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 or
(self.hostile_only and
mob_type not in mobs.EVIL_IDS)):
continue
distance = self._distance(mob)
if distance <= self.ACQUIRE_RADIUS:
candidates.append((distance, entity_id, mob))
elif self._has_ranged_weapon(mob):
elif (self.allowed_target_ids is None and
self._has_ranged_weapon(mob)):
ranged_watch_candidates.append((distance, entity_id, mob))
search_elapsed = time.monotonic() - search_started
@@ -629,6 +657,8 @@ class CombatStates:
self.g.look_at = None
self.target_id = None
self.evading = False
self.hostile_only = False
self.sleep_first = False
self.state = self.done
job = self.g.get('job')
if job is not None and getattr(job.state, '__name__', None) == 'combat':
@@ -649,6 +679,9 @@ class CombatStates:
def __init__(self, global_state, target_players=False):
self.g = global_state
self.target_players = target_players
self.allowed_target_ids = None
self.hostile_only = False
self.sleep_first = False
self.state = self.idle
self.target_id = None
self.path_target = None