Created
August 24, 2017 23:35
-
-
Save allanon/492cd72bfdd774acdefb821700739ff5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package OpenKore::Plugin::ProtectPriest; | |
use strict; | |
use Plugins; | |
use Globals; | |
use Utils; | |
use Misc; | |
use Log qw(message warning error); | |
use AI; | |
use DBI; | |
use Time::HiRes; | |
Plugins::register( 'protectpriest', 'switch targets to keep priest from being attacked', \&Unload, \&Unload ); | |
our $dirty_inventory = 0; | |
our $dirty_storage = 0; | |
our $dirty_cart = 0; | |
our $priest_regex = qr/^(PriestName1|PriestName2|StarPriest|Heals4You)$/; | |
my @hooks = ( | |
[ packet_attack => \&onPacketAttack ], | |
); | |
my $hooks = Plugins::addHooks(@hooks); | |
$timeout{protectpriest}{timeout} ||= 3; | |
sub Unload { | |
Plugins::delHooks($hooks); | |
message "protectpriest unloaded.\n"; | |
} | |
sub onPacketAttack { | |
my ( $name, $args ) = @_; | |
return if !$config{attackAuto} && !$config{attackAuto_party}; | |
# Make sure we get a chance to hit the monster before we switch targets. | |
return if !timeOut($timeout{protectpriest}); | |
my $target = Actor::get( $args->{targetID} ); | |
return if !$target || !$target->{name}; | |
return if $target->{name} !~ $priest_regex; | |
# Priests don't need to protect other priests. | |
return if $char->{name} =~ $priest_regex; | |
return if AI::args->{ID} eq $args->{sourceID}; | |
my $source = Actor::get( $args->{sourceID} ); | |
return if !$source || !$source->{name} || !$source->{pos_to}; | |
message sprintf( "ProtectPriest: switch Target to : %s (%d)\n", | |
$source->name, $source->{binID} ); | |
# Remove all commands up to (and including) the first attack. | |
# Try to keep routing, because it might be manual. | |
my $changed = 0; | |
my @new_seq = @AI::ai_seq; | |
my @new_args = @AI::ai_seq_args; | |
my $route; | |
while (@new_seq) { | |
if ( $new_seq[0] eq 'route' ) { | |
$route = $new_args[0]; | |
} | |
shift @new_seq; | |
shift @new_args; | |
if ( $new_seq[0] eq 'attack' ) { | |
$changed = 1; | |
last; | |
} | |
} | |
if ( $changed ) { | |
# Stop moving. | |
$char->sendAttackStop; | |
if ( $route ) { | |
unshift @new_seq, 'route'; | |
unshift @new_args, $route; | |
} | |
@AI::ai_seq = @new_seq; | |
@AI::ai_seq_args = @new_args; | |
} | |
# Send the new attack command. | |
AI::attack( $args->{sourceID} ); | |
# Make sure we get a chance to hit the monster before we switch targets. | |
$timeout{protectpriest}{time} = time; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment