Code: Select all
Index: AI/Attack.pm
===================================================================
--- AI/Attack.pm (revision 7694)
+++ AI/Attack.pm (working copy)
@@ -87,10 +87,10 @@
if (AI::action eq "attack") {
my $ID = $args->{ID};
- if (targetGone()) {
- finishAttacking();
- } elsif (shouldGiveUp()) {
- giveUp();
+ if (targetGone($char)) {
+ finishAttacking($char);
+ } elsif (shouldGiveUp($char)) {
+ giveUp($char);
} else {
if (timeOut($args->{attackMainTimeout}, 0.1)) {
$args->{attackMainTimeout} = time;
@@ -108,7 +108,7 @@
# Check for kill steal while moving
if ($monster && !Misc::checkMonsterCleanness($ID)) {
- dropTargetWhileMoving();
+ dropTargetWhileMoving($char);
}
# Mob-training, stop attacking the monster if it is already aggressive
@@ -136,45 +136,59 @@
}
sub shouldGiveUp {
- my $args = AI::args;
- return !$config{attackNoGiveup} && (timeOut($args->{ai_attack_giveup}) || $args->{unstuck}{count} > 5);
+ my ($actor) = @_;
+
+ my $args = $actor->args;
+ return !$config{$actor->{configPrefix}.'attackNoGiveup'} && (timeOut($args->{ai_attack_giveup}) || $args->{unstuck}{count} > 5);
}
sub giveUp {
- my $ID = AI::args->{ID};
+ my ($actor) = @_;
+
+ my $ID = $actor->args->{ID};
my $target = Actor::get($ID);
- $target->{attack_failed} = time if ($monsters{$ID});
- AI::dequeue;
- message T("Can't reach or damage target, dropping target\n"), "ai_attack";
- if ($config{'teleportAuto_dropTarget'}) {
+ $target->{$actor->{configPrefix}.'attack_failed'} = time if ($monsters{$ID});
+ $actor->dequeue;
+ message TF("%s can't reach or damage target, dropping target\n", $actor), "ai_attack";
+ if ($config{$actor->{configPrefix}.'teleportAuto_dropTarget'}) {
message T("Teleport due to dropping attack target\n");
useTeleport(1);
}
}
sub targetGone {
- my $args = AI::args;
+ my ($actor) = @_;
+
+ my $args = $actor->args;
return !$monsters{$args->{ID}} && (!$players{$args->{ID}} || $players{$args->{ID}}{dead});
}
sub finishAttacking {
- my $args = AI::args;
- $timeout{'ai_attack'}{'time'} -= $timeout{'ai_attack'}{'timeout'};
- my $ID = $args->{ID};
- AI::dequeue;
+ my ($actor) = @_;
+
+ my $args = $actor->args;
+ $_->{time} -= $_->{timeout} for $timeout{'ai_'.$actor->{configPrefix}.'attack'};
+ #$timeout{'ai_'.$actor->{configPrefix}.'attack'}{'time'} -= $timeout{'ai_'.$actor->{configPrefix}.'attack'}{'timeout'};
+ my $ID = $actor->args->{ID};
+ $actor->dequeue;
if ($monsters_old{$ID} && $monsters_old{$ID}{dead}) {
message T("Target died\n"), "ai_attack";
- Plugins::callHook("target_died");
+ Plugins::callHook($actor->{configPrefix}.'target_died');
monKilled();
# Pickup loot when monster's dead
- if ($AI == AI::AUTO && $config{'itemsTakeAuto'} && $monsters_old{$ID}{dmgFromYou} > 0 && !$monsters_old{$ID}{ignore}) {
+ # TODO: separate from attack
+ if (
+ $AI == AI::AUTO && $config{itemsTakeAuto}
+ && ($actor->isa('Actor::You') ? $monsters_old{$ID}{dmgFromYou} : $monsters_old{$ID}{dmgFromPlayer}{$actor->{ID}}) > 0
+ && !$monsters_old{$ID}{$actor->{configPrefix}.'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'});
+ $actor->clientSuspend(0, $timeout{ai_attack_waitAfterKill}{timeout});
}
## kokal start
@@ -198,31 +212,36 @@
}
## kokal end
- } elsif ($config{teleportAuto_lostTarget}) {
- message T("Target lost, teleporting.\n"), "ai_attack";
+ } elsif ($config{$actor->{configPrefix}.'teleportAuto_lostTarget'}) {
+ message TF("%s lost target, teleporting.\n", $actor), "ai_attack";
useTeleport(1);
} else {
- message T("Target lost\n"), "ai_attack";
+ message TF("% lost target\n", $actor), "ai_attack";
}
- Plugins::callHook('attack_end', {ID => $ID})
+ Plugins::callHook($actor->{configPrefix}.'attack_end', {ID => $ID})
}
sub dropTargetWhileMoving {
- my $ID = AI::args->{attackID};
- message T("Dropping target - you will not kill steal others\n");
- $char->sendAttackStop;
- $monsters{$ID}{ignore} = 1;
+ my ($actor) = @_;
+
+ my $ID = $actor->args->{attackID};
+ message TF("Dropping target - %s will not kill steal others\n", $actor), 'ai_attack';
+ $actor->sendAttackStop;
+ if (my $target = $monsters{$ID}) {
+ $target->{$actor->{configPrefix}.'attack_failed'} = time;
+ $target->{$actor->{configPrefix}.'ignore'} = 1;
+ }
# Right now, the queue is either
# move, route, attack
# -or-
# route, attack
- AI::dequeue;
- AI::dequeue;
- AI::dequeue if (AI::action eq "attack");
- if ($config{teleportAuto_dropTargetKS}) {
+ $actor->dequeue;
+ $actor->dequeue;
+ $actor->dequeue if $actor->action eq 'attack';
+ if ($config{$actor->{configPrefix}.'teleportAuto_dropTargetKS'}) {
message T("Teleport due to dropping attack target\n");
useTeleport(1);
}
Index: AI/Slave.pm
===================================================================
--- AI/Slave.pm (revision 7694)
+++ AI/Slave.pm (working copy)
@@ -304,66 +304,12 @@
$slave->{slave_attack_route_adjust} = time;
}
- if ($slave->action eq "attack" &&
- (timeOut($slave->args->{ai_attack_giveup}) ||
- $slave->args->{unstuck}{count} > 5) &&
- !$config{$slave->{configPrefix}.'attackNoGiveup'}) {
- my $ID = $slave->args->{ID};
- my $target = Actor::get($ID);
- $target->{homunculus_attack_failed} = time if $monsters{$ID};
- $slave->dequeue;
- message TF("%s can't reach or damage target, dropping target\n", $slave), 'homunculus_attack';
- if ($config{$slave->{configPrefix}.'teleportAuto_dropTarget'}) {
- message TF("Teleport due to dropping %s attack target\n", $slave), 'teleport';
- useTeleport(1);
- }
+ if ($slave->action eq 'attack' && AI::Attack::shouldGiveUp($slave)) {
+ AI::Attack::giveUp($slave);
- } elsif ($slave->action eq "attack" && !$monsters{$slave->args->{ID}} && (!$players{$slave->args->{ID}} || $players{$slave->args->{ID}}{dead})) {
- # Monster died or disappeared
- $timeout{'ai_homunculus_attack'}{'time'} -= $timeout{'ai_homunculus_attack'}{'timeout'};
- my $ID = $slave->args->{ID};
- $slave->dequeue;
+ } elsif ($slave->action eq "attack" && AI::Attack::targetGone($slave)) {
+ AI::Attack::finishAttacking($slave);
- if ($monsters_old{$ID} && $monsters_old{$ID}{dead}) {
- message TF("%s target died\n", $slave), 'homunculus_attack';
- Plugins::callHook("homonulus_target_died");
- monKilled();
-
- # Pickup loot when monster's dead
- if ($AI == AI::AUTO && $config{itemsTakeAuto} && $monsters_old{$ID}{dmgFromPlayer}{$slave->{ID}} > 0 && !$monsters_old{$ID}{homunculus_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});
- } else {
- # Cheap way to suspend all movement to make it look real
- $slave->clientSuspend(0, $timeout{'ai_attack_waitAfterKill'}{'timeout'});
- }
-
- ## kokal start
- ## mosters counting
- my $i = 0;
- my $found = 0;
- while ($monsters_Killed[$i]) {
- if ($monsters_Killed[$i]{'nameID'} eq $monsters_old{$ID}{'nameID'}) {
- $monsters_Killed[$i]{'count'}++;
- monsterLog($monsters_Killed[$i]{'name'});
- $found = 1;
- last;
- }
- $i++;
- }
- if (!$found) {
- $monsters_Killed[$i]{'nameID'} = $monsters_old{$ID}{'nameID'};
- $monsters_Killed[$i]{'name'} = $monsters_old{$ID}{'name'};
- $monsters_Killed[$i]{'count'} = 1;
- monsterLog($monsters_Killed[$i]{'name'})
- }
- ## kokal end
-
- } else {
- message TF("%s target lost\n", $slave), 'homunculus_attack';
- }
-
} elsif ($slave->action eq "attack") {
# The attack sequence hasn't timed out and the monster is on screen
@@ -621,22 +567,7 @@
if ($slave->is("move", "route") && $slave->args->{attackID} && $slave->inQueue("attack")) {
my $ID = $slave->args->{attackID};
if ((my $target = $monsters{$ID}) && !checkMonsterCleanness($ID)) {
- $target->{homunculus_attack_failed} = time;
- message TF("Dropping target - %s will not kill steal others\n", $slave), 'homunculus_attack';
- $slave->sendAttackStop;
- $monsters{$ID}{homunculus_ignore} = 1;
-
- # Right now, the queue is either
- # move, route, attack
- # -or-
- # route, attack
- $slave->dequeue;
- $slave->dequeue;
- $slave->dequeue if ($slave->action eq "attack");
- if ($config{$slave->{configPrefix}.'teleportAuto_dropTargetKS'}) {
- message TF("Teleport due to dropping %s attack target\n", $slave), 'teleport';
- useTeleport(1);
- }
+ AI::Attack::dropTargetWhileMoving($slave);
}
}
Actor->{configPrefix} becomes not only config prefix, but also a prefix for hooks and timeouts.