Changed timer to 60 seconds
This commit is contained in:
Binary file not shown.
@@ -62,18 +62,30 @@ class BotAssignmentManager:
|
||||
pass
|
||||
print("Bot assignment stopped")
|
||||
|
||||
def friendly_has_active_target(self, friendly_id: int) -> bool:
|
||||
"""Check if a friendly player already has an active target assigned"""
|
||||
for target_data in self.active_targets.values():
|
||||
if target_data["friendly_id"] == friendly_id:
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_next_friendly_in_group(self, group_id: str, friendly_ids: list) -> Optional[int]:
|
||||
"""
|
||||
Get the next friendly in the group who should receive a target.
|
||||
Prioritizes members with fewer hits.
|
||||
Only returns friendlies who DON'T already have an active assignment.
|
||||
"""
|
||||
if not friendly_ids:
|
||||
return None
|
||||
|
||||
# Get hit counts for all friendlies in this group
|
||||
# Get hit counts for all friendlies in this group who DON'T have active targets
|
||||
friendly_hits = []
|
||||
for fid in friendly_ids:
|
||||
if fid in STATE.friendly:
|
||||
# Skip if this friendly already has an active target
|
||||
if self.friendly_has_active_target(fid):
|
||||
continue
|
||||
|
||||
hits = STATE.friendly[fid].hits
|
||||
friendly_hits.append((fid, hits))
|
||||
|
||||
@@ -83,7 +95,7 @@ class BotAssignmentManager:
|
||||
# Sort by hit count (ascending) - members with fewer hits first
|
||||
friendly_hits.sort(key=lambda x: x[1])
|
||||
|
||||
# Return the friendly with the fewest hits
|
||||
# Return the friendly with the fewest hits who doesn't have an active target
|
||||
return friendly_hits[0][0]
|
||||
|
||||
def get_next_enemy_in_group(self, group_id: str, enemy_ids: list) -> Optional[int]:
|
||||
@@ -101,7 +113,7 @@ class BotAssignmentManager:
|
||||
async def assignment_loop(self):
|
||||
"""Main loop that assigns targets and monitors status"""
|
||||
await self.bot.wait_until_ready()
|
||||
print("✓ Bot is ready, assignment loop running")
|
||||
print("Bot is ready, assignment loop running")
|
||||
|
||||
first_run = True
|
||||
while self.running:
|
||||
@@ -109,13 +121,13 @@ class BotAssignmentManager:
|
||||
# Check if bot is enabled via STATE
|
||||
if not STATE.bot_running:
|
||||
if first_run:
|
||||
print("⏸ Bot paused - waiting for Start Bot button to be clicked")
|
||||
print("Bot paused - waiting for Start Bot button to be clicked")
|
||||
first_run = False
|
||||
await asyncio.sleep(5)
|
||||
continue
|
||||
|
||||
if first_run:
|
||||
print("▶ Bot activated - processing assignments")
|
||||
print("Bot activated - processing assignments")
|
||||
first_run = False
|
||||
|
||||
# Process each group
|
||||
@@ -139,7 +151,7 @@ class BotAssignmentManager:
|
||||
await self.assign_target(group_id, friendly_id, enemy_id)
|
||||
|
||||
if not has_assignments and STATE.bot_running:
|
||||
print("⚠ No group assignments found - drag members into groups first!")
|
||||
print("No group assignments found - drag members into groups first!")
|
||||
|
||||
# Monitor active targets for status changes or timeouts
|
||||
await self.monitor_active_targets()
|
||||
@@ -148,7 +160,7 @@ class BotAssignmentManager:
|
||||
await asyncio.sleep(5)
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error in assignment loop: {e}")
|
||||
print(f"Error in assignment loop: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
await asyncio.sleep(5)
|
||||
@@ -187,7 +199,7 @@ class BotAssignmentManager:
|
||||
|
||||
# Send Discord message
|
||||
enemy_link = f"https://www.torn.com/profiles.php?XID={enemy_id}"
|
||||
message = f"🎯 **New target for {discord_user.mention}!**\n\nAttack **{enemy.name}** (Level {enemy.level})\n{enemy_link}\n\n⏰ You have 30 seconds!"
|
||||
message = f"**New target for {discord_user.mention}!**\n\nAttack **{enemy.name}** (Level {enemy.level})\n{enemy_link}\n\n⏰ You have 60 seconds!"
|
||||
|
||||
try:
|
||||
await discord_user.send(message)
|
||||
@@ -229,8 +241,8 @@ class BotAssignmentManager:
|
||||
except:
|
||||
pass
|
||||
|
||||
# Reassign after 30 seconds
|
||||
if elapsed >= 30:
|
||||
# Reassign after 60 seconds
|
||||
if elapsed >= 60:
|
||||
to_reassign.append((data["group_id"], enemy_id))
|
||||
del self.active_targets[key]
|
||||
|
||||
@@ -239,7 +251,7 @@ class BotAssignmentManager:
|
||||
friendly_ids = STATE.groups[group_id].get("friendly", [])
|
||||
friendly_id = self.get_next_friendly_in_group(group_id, friendly_ids)
|
||||
if friendly_id:
|
||||
print(f"⚠ Reassigning enemy {enemy_id} (timeout)")
|
||||
print(f"Reassigning enemy {enemy_id} (timeout)")
|
||||
await self.assign_target(group_id, friendly_id, enemy_id)
|
||||
|
||||
# Global instance (will be initialized with bot in main.py)
|
||||
|
||||
Reference in New Issue
Block a user