Skip to content

Commit

Permalink
removed melee-ranged message and check (#3928)
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrybk authored Jan 10, 2025
1 parent c2ebd57 commit 6917fa0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
20 changes: 6 additions & 14 deletions src/AI/Attack.pm
Original file line number Diff line number Diff line change
Expand Up @@ -487,17 +487,10 @@ sub main {
Benchmark::end("ai_attack (part 1.2)") if DEBUG;
Benchmark::end("ai_attack (part 1)") if DEBUG;

my $melee;
my $ranged;
if (defined $args->{attackMethod}{type} && exists $args->{ai_attack_failed_give_up} && defined $args->{ai_attack_failed_give_up}{time}) {
debug "Deleting ai_attack_failed_give_up time.\n";
delete $args->{ai_attack_failed_give_up}{time};

} elsif ($args->{attackMethod}{maxDistance} == 1) {
$melee = 1;

} elsif ($args->{attackMethod}{maxDistance} > 1) {
$ranged = 1;
}

$args->{attackMethod}{maxDistance} += $args->{temporary_extra_range};
Expand All @@ -512,8 +505,7 @@ sub main {
} else {
$canAttack = -2;
}

my $range_type_string = ($melee ? "Melee" : ($ranged ? "Ranged" : "None"));

my $canAttack_fail_string = (($canAttack == -2) ? "No Method" : (($canAttack == -1) ? "No LOS" : (($canAttack == 0) ? "No Range" : "OK")));

# Here we check if the monster which we are waiting to get closer to us is in fact close enough
Expand Down Expand Up @@ -595,7 +587,7 @@ sub main {
}

if ($canAttack == 0 && $youHitTarget) {
debug TF("[%s - %s] We were able to hit target even though it is out of range or LOS, accepting and continuing. (you %s (%d %d), target %s (%d %d) [(%d %d) -> (%d %d)], distance %d, maxDistance %d, dmgFromYou %d)\n", $canAttack_fail_string, $range_type_string, $char, $realMyPos->{x}, $realMyPos->{y}, $target, $realMonsterPos->{x}, $realMonsterPos->{y}, $target->{pos}{x}, $target->{pos}{y}, $target->{pos_to}{x}, $target->{pos_to}{y}, $realMonsterDist, $args->{attackMethod}{maxDistance}, $target->{dmgFromYou}), 'ai_attack';
debug TF("[%s] We were able to hit target even though it is out of range or LOS, accepting and continuing. (you %s (%d %d), target %s (%d %d) [(%d %d) -> (%d %d)], distance %d, maxDistance %d, dmgFromYou %d)\n", $canAttack_fail_string, $char, $realMyPos->{x}, $realMyPos->{y}, $target, $realMonsterPos->{x}, $realMonsterPos->{y}, $target->{pos}{x}, $target->{pos}{y}, $target->{pos_to}{x}, $target->{pos_to}{y}, $realMonsterDist, $args->{attackMethod}{maxDistance}, $target->{dmgFromYou}), 'ai_attack';
if ($clientDist > $args->{attackMethod}{maxDistance} && $clientDist <= ($args->{attackMethod}{maxDistance} + 1) && $args->{temporary_extra_range} == 0) {
debug TF("[%s] Probably extra range provided by the server due to chasing, increasing range by 1.\n", $canAttack_fail_string), 'ai_attack';
$args->{temporary_extra_range} = 1;
Expand Down Expand Up @@ -629,11 +621,11 @@ sub main {
$args->{ai_attack_failed_waitForAgressive_give_up}{time} = time if !$args->{ai_attack_failed_waitForAgressive_give_up}{time};
if (timeOut($args->{ai_attack_failed_waitForAgressive_give_up})) {
delete $args->{ai_attack_failed_waitForAgressive_give_up}{time};
warning TF("[%s - %s] Waited too long for target to get closer, dropping target. (you %s (%d %d), target %s (%d %d) [(%d %d) -> (%d %d)], distance %d, maxDistance %d, dmgFromYou %d)\n", $canAttack_fail_string, $range_type_string, $char, $realMyPos->{x}, $realMyPos->{y}, $target, $realMonsterPos->{x}, $realMonsterPos->{y}, $target->{pos}{x}, $target->{pos}{y}, $target->{pos_to}{x}, $target->{pos_to}{y}, $realMonsterDist, $args->{attackMethod}{maxDistance}, $target->{dmgFromYou}), 'ai_attack';
warning TF("[%s] Waited too long for target to get closer, dropping target. (you %s (%d %d), target %s (%d %d) [(%d %d) -> (%d %d)], distance %d, maxDistance %d, dmgFromYou %d)\n", $canAttack_fail_string, $char, $realMyPos->{x}, $realMyPos->{y}, $target, $realMonsterPos->{x}, $realMonsterPos->{y}, $target->{pos}{x}, $target->{pos}{y}, $target->{pos_to}{x}, $target->{pos_to}{y}, $realMonsterDist, $args->{attackMethod}{maxDistance}, $target->{dmgFromYou}), 'ai_attack';
giveUp($args, $ID, 0);
} else {
$messageSender->sendAction($ID, ($config{'tankMode'}) ? 0 : 7) if ($config{"attackBeyondMaxDistance_sendAttackWhileWaiting"});
debug TF("[%s - %s - Waiting] %s (%d %d), target %s (%d %d) [(%d %d) -> (%d %d)], distance %d, maxDistance %d, dmgFromYou %d.\n", $canAttack_fail_string, $range_type_string, $char, $realMyPos->{x}, $realMyPos->{y}, $target, $realMonsterPos->{x}, $realMonsterPos->{y}, $target->{pos}{x}, $target->{pos}{y}, $target->{pos_to}{x}, $target->{pos_to}{y}, $realMonsterDist, $args->{attackMethod}{maxDistance}, $target->{dmgFromYou}), 'ai_attack';
debug TF("[%s - Waiting] %s (%d %d), target %s (%d %d) [(%d %d) -> (%d %d)], distance %d, maxDistance %d, dmgFromYou %d.\n", $canAttack_fail_string, $char, $realMyPos->{x}, $realMyPos->{y}, $target, $realMonsterPos->{x}, $realMonsterPos->{y}, $target->{pos}{x}, $target->{pos}{y}, $target->{pos_to}{x}, $target->{pos_to}{y}, $realMonsterDist, $args->{attackMethod}{maxDistance}, $target->{dmgFromYou}), 'ai_attack';
}
$found_action = 1;
}
Expand All @@ -646,10 +638,10 @@ sub main {
) {
debug "Attack $char ($realMyPos->{x} $realMyPos->{y}) - target $target ($realMonsterPos->{x} $realMonsterPos->{y})\n";
if ($canAttack == 0) {
debug "[Attack] [$range_type_string] [No range] Too far from us to attack, distance is $realMonsterDist, attack maxDistance is $args->{attackMethod}{maxDistance}\n", 'ai_attack';
debug "[Attack] [No range] Too far from us to attack, distance is $realMonsterDist, attack maxDistance is $args->{attackMethod}{maxDistance}\n", 'ai_attack';

} elsif ($canAttack == -1) {
debug "[Attack] [$range_type_string] [No LOS] No LOS from player to mob\n", 'ai_attack';
debug "[Attack] [No LOS] No LOS from player to mob\n", 'ai_attack';
}

my $pos = meetingPosition($char, 1, $target, $args->{attackMethod}{maxDistance});
Expand Down
24 changes: 8 additions & 16 deletions src/AI/SlaveAttack.pm
Original file line number Diff line number Diff line change
Expand Up @@ -426,17 +426,10 @@ sub main {
$args->{attackMethod}{maxDistance} = $args->{attackMethod}{distance};
}

my $melee;
my $ranged;
if (defined $args->{attackMethod}{type} && exists $args->{ai_attack_failed_give_up} && defined $args->{ai_attack_failed_give_up}{time}) {
debug "[Slave $slave] Deleting ai_attack_failed_give_up time.\n";
delete $args->{ai_attack_failed_give_up}{time};

} elsif ($args->{attackMethod}{maxDistance} == 1) {
$melee = 1;

} elsif ($args->{attackMethod}{maxDistance} > 1) {
$ranged = 1;
}

#$args->{attackMethod}{maxDistance} += $args->{temporary_extra_range};
Expand All @@ -451,8 +444,7 @@ sub main {
} else {
$canAttack = -2;
}

my $range_type_string = ($melee ? "Melee" : ($ranged ? "Ranged" : "None"));

my $canAttack_fail_string = (($canAttack == -2) ? "No Method" : (($canAttack == -1) ? "No LOS" : (($canAttack == 0) ? "No Range" : "OK")));

# Here we check if the monster which we are waiting to get closer to us is in fact close enough
Expand Down Expand Up @@ -534,7 +526,7 @@ sub main {
}

if ($canAttack == 0 && $youHitTarget) {
debug TF("[%s] [%s - %s] We were able to hit target even though it is out of range or LOS, accepting and continuing. (you (%d %d), target %s (%d %d) [(%d %d) -> (%d %d)], distance %d, maxDistance %d)\n", $slave, $canAttack_fail_string, $range_type_string, $realMyPos->{x}, $realMyPos->{y}, $target, $realMonsterPos->{x}, $realMonsterPos->{y}, $target->{pos}{x}, $target->{pos}{y}, $target->{pos_to}{x}, $target->{pos_to}{y}, $realMonsterDist, $args->{attackMethod}{maxDistance}), 'ai_attack';
debug TF("[%s] [%s] We were able to hit target even though it is out of range or LOS, accepting and continuing. (you (%d %d), target %s (%d %d) [(%d %d) -> (%d %d)], distance %d, maxDistance %d)\n", $slave, $canAttack_fail_string, $realMyPos->{x}, $realMyPos->{y}, $target, $realMonsterPos->{x}, $realMonsterPos->{y}, $target->{pos}{x}, $target->{pos}{y}, $target->{pos_to}{x}, $target->{pos_to}{y}, $realMonsterDist, $args->{attackMethod}{maxDistance}), 'ai_attack';
if ($clientDist > $args->{attackMethod}{maxDistance} && $clientDist <= ($args->{attackMethod}{maxDistance} + 1) && $args->{temporary_extra_range} == 0) {
debug TF("[$canAttack_fail_string] Probably extra range provided by the server due to chasing, increasing range by 1.\n"), 'ai_attack';
$args->{temporary_extra_range} = 1;
Expand Down Expand Up @@ -568,11 +560,11 @@ sub main {
$args->{ai_attack_failed_waitForAgressive_give_up}{time} = time if !$args->{ai_attack_failed_waitForAgressive_give_up}{time};
if (timeOut($args->{ai_attack_failed_waitForAgressive_give_up})) {
delete $args->{ai_attack_failed_waitForAgressive_give_up}{time};
warning TF("[%s] [%s - %s] Waited too long for target to get closer, dropping target. (you (%d %d), target %s (%d %d) [(%d %d) -> (%d %d)], distance %d, maxDistance %d)\n", $slave, $canAttack_fail_string, $range_type_string, $realMyPos->{x}, $realMyPos->{y}, $target, $realMonsterPos->{x}, $realMonsterPos->{y}, $target->{pos}{x}, $target->{pos}{y}, $target->{pos_to}{x}, $target->{pos_to}{y}, $realMonsterDist, $args->{attackMethod}{maxDistance}), 'ai_attack';
warning TF("[%s] [%s] Waited too long for target to get closer, dropping target. (you (%d %d), target %s (%d %d) [(%d %d) -> (%d %d)], distance %d, maxDistance %d)\n", $slave, $canAttack_fail_string, $realMyPos->{x}, $realMyPos->{y}, $target, $realMonsterPos->{x}, $realMonsterPos->{y}, $target->{pos}{x}, $target->{pos}{y}, $target->{pos_to}{x}, $target->{pos_to}{y}, $realMonsterDist, $args->{attackMethod}{maxDistance}), 'ai_attack';
giveUp($slave, $args, $ID, 0);
} else {
$slave->sendAttack($ID) if ($config{$slave->{configPrefix}."attackBeyondMaxDistance_sendAttackWhileWaiting"});
debug TF("[%s] [%s - %s] [Waiting] (%d %d), target %s (%d %d) [(%d %d) -> (%d %d)], distance %d, maxDistance %d.\n", $slave, $canAttack_fail_string, $range_type_string, $realMyPos->{x}, $realMyPos->{y}, $target, $realMonsterPos->{x}, $realMonsterPos->{y}, $target->{pos}{x}, $target->{pos}{y}, $target->{pos_to}{x}, $target->{pos_to}{y}, $realMonsterDist, $args->{attackMethod}{maxDistance}), 'ai_attack';
debug TF("[%s] [%s] [Waiting] (%d %d), target %s (%d %d) [(%d %d) -> (%d %d)], distance %d, maxDistance %d.\n", $slave, $canAttack_fail_string, $realMyPos->{x}, $realMyPos->{y}, $target, $realMonsterPos->{x}, $realMonsterPos->{y}, $target->{pos}{x}, $target->{pos}{y}, $target->{pos_to}{x}, $target->{pos_to}{y}, $realMonsterDist, $args->{attackMethod}{maxDistance}), 'ai_attack';
}
$found_action = 1;
}
Expand All @@ -585,10 +577,10 @@ sub main {
) {
debug "Attack $slave ($realMyPos->{x} $realMyPos->{y}) - target $target ($realMonsterPos->{x} $realMonsterPos->{y})\n";
if ($canAttack == 0) {
debug "[Slave $slave] [Attack] [$range_type_string] [No range] Too far from us to attack, distance is $realMonsterDist, attack maxDistance is $args->{attackMethod}{maxDistance}\n", 'ai_attack';
debug "[Slave $slave] [Attack] [No range] Too far from us to attack, distance is $realMonsterDist, attack maxDistance is $args->{attackMethod}{maxDistance}\n", 'ai_attack';

} elsif ($canAttack == -1) {
debug "[Slave $slave] [Attack] [$range_type_string] [No LOS] No LOS from player to mob\n", 'ai_attack';
debug "[Slave $slave] [Attack] [No LOS] No LOS from player to mob\n", 'ai_attack';
}

my $pos = meetingPosition($slave, 2, $target, $args->{attackMethod}{maxDistance});
Expand Down Expand Up @@ -652,7 +644,7 @@ sub main {
}

if ($args->{attackMethod}{type} eq "weapon") {
if ($config{$slave->{configPrefix}.'attack_dance_melee'} && $melee) {
if ($config{$slave->{configPrefix}.'attack_dance_melee'}) {
if (timeOut($timeout{$slave->{ai_dance_attack_melee_timeout}})) {
my $cell = get_dance_position($slave, $target);
debug TF("Slave %s will dance type %d from (%d, %d) to (%d, %d), target %s at (%d, %d).\n", $slave, $config{$slave->{configPrefix}.'attack_dance_melee'}, $realMyPos->{x}, $realMyPos->{y}, $cell->{x}, $cell->{y}, $target, $realMonsterPos->{x}, $realMonsterPos->{y});
Expand All @@ -662,7 +654,7 @@ sub main {
$timeout{$slave->{ai_dance_attack_melee_timeout}}{time} = time;
}

} elsif ($config{$slave->{configPrefix}.'attack_dance_ranged'} && $ranged) {
} elsif ($config{$slave->{configPrefix}.'attack_dance_ranged'}) {
if (timeOut($timeout{$slave->{ai_dance_attack_ranged_timeout}})) {
my $cell = get_dance_position($slave, $target);
debug TF("Slave %s will range dance type %d from (%d, %d) to (%d, %d), target %s at (%d, %d).\n", $slave, $config{$slave->{configPrefix}.'attack_dance_ranged'}, $realMyPos->{x}, $realMyPos->{y}, $cell->{x}, $cell->{y}, $target, $realMonsterPos->{x}, $realMonsterPos->{y});
Expand Down

0 comments on commit 6917fa0

Please sign in to comment.