Skip to content

Commit

Permalink
fix: remove checkMonsters and improve items_take (#3802)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonrag authored Oct 10, 2023
1 parent d29adb2 commit 620bc63
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 56 deletions.
9 changes: 4 additions & 5 deletions control/timeouts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ reconnect_random 20
poseidon_wait_reply 15

# Activate AI after x seconds after the map's loaded
ai 2
ai 1

ai_move_retry 0.25
ai_move_giveup 1
Expand Down Expand Up @@ -57,7 +57,6 @@ ai_attack_failedLOS 12
# Give up attacking a monster if it can't be reached within x seconds
ai_attack_giveup 6

ai_check_monster_auto 0.4
ai_homunculus_check_monster_auto 0.2
ai_mercenary_check_monster_auto 0.2

Expand All @@ -76,13 +75,13 @@ ai_route_unstuck 2
# Pause for the specified number of seconds after taking something,
# it increases the interval between taking several items and between
# taking the last item and continuing the actions.
ai_items_take_delay 1.4
ai_items_take_delay 1

# When your monster died, start checking for loot after x seconds
ai_items_take_start 0.4
ai_items_take_start 0.3

# Stop checking for loot x seconds after it has begun checking
ai_items_take_end 1.2
ai_items_take_end 0.6

# When standing near an item, send the 'take' packet every x seconds until
# the item has been taken.
Expand Down
11 changes: 2 additions & 9 deletions src/AI/Attack.pm
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,8 @@ sub finishAttacking {
Plugins::callHook('target_died', {monster => $monsters_old{$ID}});
monKilled();

# Pickup loot when monster's dead
if (AI::state == AI::AUTO && $config{'itemsTakeAuto'} && $monsters_old{$ID}{dmgFromYou} > 0 && !$monsters_old{$ID}{ignore}) {
AI::clear("items_take");
ai_items_take($monsters_old{$ID}{pos}{x}, $monsters_old{$ID}{pos}{y},
$monsters_old{$ID}{pos_to}{x}, $monsters_old{$ID}{pos_to}{y});
} else {
# Cheap way to suspend all movement to make it look real
ai_clientSuspend(0, $timeout{'ai_attack_waitAfterKill'}{'timeout'});
}
# Cheap way to suspend all movement to make it look real
ai_clientSuspend(0, $timeout{'ai_attack_waitAfterKill'}{'timeout'});

## kokal start
## mosters counting
Expand Down
18 changes: 2 additions & 16 deletions src/AI/CoreLogic.pm
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ sub iterate {
Misc::checkValidity("AI part 3");
processAutoEquip();
processAutoAttack();
processCheckMonster();
processItemsTake();
processItemsAutoGather();
processItemsGather();
Expand Down Expand Up @@ -3106,7 +3105,7 @@ sub processAutoAttack {
Benchmark::begin("ai_autoAttack") if DEBUG;

return if (!$field);
if ((AI::isIdle || AI::is(qw/route checkMonsters follow sitAuto take items_gather items_take/) || (AI::action eq "mapRoute" && AI::args->{stage} eq 'Getting Map Solution'))
if ((AI::isIdle || AI::is(qw/route follow sitAuto take items_gather items_take/) || (AI::action eq "mapRoute" && AI::args->{stage} eq 'Getting Map Solution'))
# Don't auto-attack monsters while taking loot, and itemsTake/GatherAuto >= 2
&& !($config{'itemsTakeAuto'} >= 2 && AI::is("take", "items_take"))
&& !($config{'itemsGatherAuto'} >= 2 && AI::is("take", "items_gather"))
Expand Down Expand Up @@ -3305,7 +3304,7 @@ sub processItemsTake {
sub processItemsAutoGather {
return if (AI::inQueue("gather", "take", "items_gather"));
if ( (AI::isIdle || AI::action eq "follow"
|| ( AI::is("route", "mapRoute", "checkMonsters") && (!AI::args->{ID} || $config{'itemsGatherAuto'} >= 2) ))
|| ( AI::is("route", "mapRoute") && (!AI::args->{ID} || $config{'itemsGatherAuto'} >= 2) ))
&& $config{'itemsGatherAuto'}
&& (!$config{itemsGatherAuto_notInTown} || !$field->isCity)
&& !$ai_v{sitAuto_forcedBySitCommand}
Expand Down Expand Up @@ -3726,17 +3725,4 @@ sub processPartyShareAuto {
}
}

sub processCheckMonster {
return if AI::inQueue("attack");
return if !AI::inQueue("checkMonsters");
return if !AI::is("checkMonsters");

$timeout{'ai_check_monster_auto'}{'time'} = time if !$timeout{'ai_check_monster_auto'}{'time'};

if (timeOut($timeout{'ai_check_monster_auto'})) {
AI::dequeue;
undef $timeout{'ai_check_monster_auto'}{'time'};
}
}

1;
17 changes: 1 addition & 16 deletions src/AI/Slave.pm
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ sub iterate {
$slave->processWasFound;
$slave->processTeleportToMaster;
$slave->processAutoAttack;
$slave->processCheckMonster;
$slave->processFollow;
$slave->processIdleWalk;
}
Expand Down Expand Up @@ -362,7 +361,7 @@ sub processAutoAttack {

return if (!$field);
if (
($slave->isIdle || $slave->is(qw/route checkMonsters/))
($slave->isIdle || $slave->is(qw/route/))
&& (
AI::isIdle
|| AI::is(qw(follow sitAuto attack skill_use))
Expand Down Expand Up @@ -508,20 +507,6 @@ sub processAutoAttack {
#Benchmark::end("ai_homunculus_autoAttack") if DEBUG;
}

sub processCheckMonster {
my $slave = shift;
return if ($slave->inQueue("attack"));
return if (!$slave->inQueue("checkMonsters"));
return if (!$slave->is("checkMonsters"));

$timeout{$slave->{ai_check_monster_auto}}{'time'} = time if !$timeout{$slave->{ai_check_monster_auto}}{'time'};

if(timeOut($timeout{$slave->{ai_check_monster_auto}})) {
$slave->dequeue;
undef $timeout{$slave->{ai_check_monster_auto}}{'time'};
}
}

sub sendAttack {
my ($slave, $targetID) = @_;
$messageSender->sendSlaveAttack ($slave->{ID}, $targetID);
Expand Down
10 changes: 1 addition & 9 deletions src/AI/SlaveAttack.pm
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,7 @@ sub finishAttacking {
});
monKilled();

# Pickup loot when monster's dead
if (AI::state == AI::AUTO && $config{itemsTakeAuto} && $monsters_old{$ID}{dmgFromPlayer}{$slave->{ID}} > 0 && !$monsters_old{$ID}{slave_ignore}) {
AI::clear("items_take");
AI::ai_items_take($monsters_old{$ID}{pos}{x}, $monsters_old{$ID}{pos}{y},
$monsters_old{$ID}{pos_to}{x}, $monsters_old{$ID}{pos_to}{y});
} elsif ($timeout{$slave->{ai_attack_waitAfterKill_timeout}}{'timeout'} > 0) {
# Cheap way to suspend all movement to make it look real
$slave->clientSuspend(0, $timeout{$slave->{ai_attack_waitAfterKill_timeout}}{'timeout'});
}
$slave->clientSuspend(0, $timeout{$slave->{ai_attack_waitAfterKill_timeout}}{'timeout'});

## kokal start
## mosters counting
Expand Down
1 change: 0 additions & 1 deletion src/Actor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,6 @@ sub attack {
pos_to => { %{$target->{pos_to}} },
);

$self->queue('checkMonsters') if !AI::inQueue("checkMonsters");
$self->queue('attack', \%args);

message sprintf($self->verb(T("%s are now attacking %s\n"), T("%s is now attacking %s\n")), $self, $target);
Expand Down

0 comments on commit 620bc63

Please sign in to comment.