From e7df358099b2a47acb356164c3eef88dce1354ce Mon Sep 17 00:00:00 2001 From: Elvis Date: Wed, 18 Oct 2023 12:15:59 +0200 Subject: [PATCH 1/4] Update comboSpam plugin --- .../needs-review/comboSpam/trunk/comboSpam.pl | 116 ++++++++++++------ src/Network/Receive.pm | 15 ++- 2 files changed, 90 insertions(+), 41 deletions(-) diff --git a/plugins/needs-review/comboSpam/trunk/comboSpam.pl b/plugins/needs-review/comboSpam/trunk/comboSpam.pl index 59b056162f..eaf6af6712 100644 --- a/plugins/needs-review/comboSpam/trunk/comboSpam.pl +++ b/plugins/needs-review/comboSpam/trunk/comboSpam.pl @@ -3,46 +3,92 @@ package comboSpam; use strict; use Plugins; use Globals; -use Skills; -use Misc; -use Network; -use Network::Send; -use Utils; -use Time::HiRes qw(time usleep); - - -Plugins::register('comboSpam', 'spam combo packets', \&on_unload); -my $hook1 = Plugins::addHook('packet/actor_status_active', \&combo); -my $hook2 = Plugins::addHook('AI_pre', \&AI_pre); -my $combo = 0; -my $delay = .2; -my $time = time; - -sub on_unload { - # This plugin is about to be unloaded; remove hooks - Plugins::delHook("packet/actor_status_active", $hook1); - Plugins::delHook("AI_pre", $hook1); -} +use Commands; +use Log qw(message); +use List::Util qw(max); +use Time::HiRes qw(&time); + +Plugins::register('comboSpam', 'spam combo packets', \&Unload, \&Reload); + +my $hooks = Plugins::addHooks( + ['AI_pre', \&onLoop], + ['is_casting', \&onSkillCast], + ['packet_skilluse', \&onSkillUse], + ['packet_skillfail', \&onSkillFail] +); + +my %report = (); +my %sequence = ( + 263 => new Skill(idn => 272), # Raging Trifecta Blow > Raging Quadruple Blow + 272 => new Skill(idn => 273), # Raging Quadruple Blow > Raging Thrust + 273 => new Skill(idn => 371), # Raging·Thrust > Glacier·Fist + 371 => new Skill(idn => 372), # Glacier·Fist > Chain·Crush·Combo +); -sub combo { - my ($packet, $args) = @_; - my ($type, $ID, $flag) = @{$args}{qw(type ID flag)}; - - if ($skillsStatus{$type} eq "Triple Attack Delay") { - $combo = $flag; +my $time; +my $skillId; +my $delay = 0.2; +my $commands = Commands::register( + ['combos', '', sub { + foreach my $skill (sort %sequence) { + next unless $skill->isa('Skill') && $report{$skill->getIDN()}; + message sprintf("%s: %s\n", $skill->getName(), $report{$skill->getIDN()}), 'info'; + } + }] +); + +sub Unload { + foreach my $hook (@{$hooks}) { + Plugins::delHook($hook); } + Commands::unregister($commands); + undef @{$hooks}; } -sub AI_pre { +sub Reload { + &Unload; +} + +sub onLoop { my ($self, $args) = @_; - - if ($combo && main::timeOut($time, $delay)) { - sendSkillUse($net, 272, 5, $accountID); # Chain Combo - if ($char->{spirits}) { # Make sure there is a spirit sphere - sendSkillUse($net, 273, 5, $accountID); # Combo Finish - } - $time = time; - } + + return unless Utils::timeOut($time, $delay); + $time = time; + + # return if($char->{statuses}->{EFST_POSTDELAY}); + return unless defined $skillId && exists $sequence{$skillId}; + return unless AI::inQueue('attack'); + + my $skill = $sequence{$skillId}; + my $level = $char->getSkillLevel($skill); + my $handle = $skill->getHandle(); + return unless $level > 0; + + # SP Cost: (Skill Level + 10) || 2 + (Skill Level × 2) + my $skillSp = $char->{skills}{$handle}{sp} || max(10 + $level, 2 + ($level * 2)); + return unless $char->{sp} >= $skillSp; + return unless $handle eq 'MO_CHAINCOMBO' || $char->{spirits} > 0; + + $messageSender->sendSkillUse($skill->getIDN(), $level, $accountID); +} + +sub onSkillCast { + my ($self, $args) = @_; + undef $skillId; +} + +sub onSkillFail { + my ($hookName, $args) = @_; + $args->{warn} = 0; +} + +sub onSkillUse { + my ($self, $args) = @_; + + $skillId = $args->{skillID}; + + $report{$skillId} ||= 0; + $report{$skillId}++; } 1; diff --git a/src/Network/Receive.pm b/src/Network/Receive.pm index 4e4f904718..626b7cb462 100644 --- a/src/Network/Receive.pm +++ b/src/Network/Receive.pm @@ -11800,12 +11800,15 @@ sub skill_use_failed { delete $char->{casting}; - warning TF("Skill %s failed: %s (error number %s)\n", Skill->new(idn => $skillID)->getName(), $errorMessage, $type), "skill"; - Plugins::callHook('packet_skillfail', { - skillID => $skillID, - failType => $type, - failMessage => $errorMessage - }); + my %hookArgs; + $hookArgs{skillID} = $skillID; + $hookArgs{failType} = $type; + $hookArgs{failMessage} = $errorMessage; + $hookArgs{warn} = 1; + + Plugins::callHook('packet_skillfail', \%hookArgs); + + warning(TF("Skill %s failed: %s (error number %s)\n", Skill->new(idn => $skillID)->getName(), $errorMessage, $type), "skill") if ($hookArgs{warn}); } sub open_store_status { From 5cec522a7bc8cd3894e51d60e4a1e8ffa6b96317 Mon Sep 17 00:00:00 2001 From: Elvis Date: Wed, 18 Oct 2023 12:19:41 +0200 Subject: [PATCH 2/4] Fix typo --- plugins/needs-review/comboSpam/trunk/comboSpam.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/needs-review/comboSpam/trunk/comboSpam.pl b/plugins/needs-review/comboSpam/trunk/comboSpam.pl index eaf6af6712..07e5466213 100644 --- a/plugins/needs-review/comboSpam/trunk/comboSpam.pl +++ b/plugins/needs-review/comboSpam/trunk/comboSpam.pl @@ -21,8 +21,8 @@ package comboSpam; my %sequence = ( 263 => new Skill(idn => 272), # Raging Trifecta Blow > Raging Quadruple Blow 272 => new Skill(idn => 273), # Raging Quadruple Blow > Raging Thrust - 273 => new Skill(idn => 371), # Raging·Thrust > Glacier·Fist - 371 => new Skill(idn => 372), # Glacier·Fist > Chain·Crush·Combo + 273 => new Skill(idn => 371), # Raging Thrust > Glacier Fist + 371 => new Skill(idn => 372), # Glacier Fist > Chain Crush Combo ); my $time; From c3fc6b4a4fa3ccb387d4f0068a2c7bbb0ba4c27f Mon Sep 17 00:00:00 2001 From: Elvis Date: Wed, 18 Oct 2023 14:21:17 +0200 Subject: [PATCH 3/4] Filter out warning messages only for combos skill fail --- plugins/needs-review/comboSpam/trunk/comboSpam.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/needs-review/comboSpam/trunk/comboSpam.pl b/plugins/needs-review/comboSpam/trunk/comboSpam.pl index 07e5466213..b000e9251c 100644 --- a/plugins/needs-review/comboSpam/trunk/comboSpam.pl +++ b/plugins/needs-review/comboSpam/trunk/comboSpam.pl @@ -23,6 +23,7 @@ package comboSpam; 272 => new Skill(idn => 273), # Raging Quadruple Blow > Raging Thrust 273 => new Skill(idn => 371), # Raging Thrust > Glacier Fist 371 => new Skill(idn => 372), # Glacier Fist > Chain Crush Combo + 372 => undef ); my $time; @@ -60,6 +61,8 @@ sub onLoop { return unless AI::inQueue('attack'); my $skill = $sequence{$skillId}; + return unless defined $skill && $skill->isa('Skill'); + my $level = $char->getSkillLevel($skill); my $handle = $skill->getHandle(); return unless $level > 0; @@ -79,7 +82,8 @@ sub onSkillCast { sub onSkillFail { my ($hookName, $args) = @_; - $args->{warn} = 0; + my $skillId = $args->{skillID}; + $args->{warn} = exists $sequence{$skillId} ? 0 : 1; } sub onSkillUse { From 64d7bc341e6d0f3f18bd5b70efb10a0d5b9294a0 Mon Sep 17 00:00:00 2001 From: Elvis Date: Wed, 18 Oct 2023 14:28:39 +0200 Subject: [PATCH 4/4] Fix command --- plugins/needs-review/comboSpam/trunk/comboSpam.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/needs-review/comboSpam/trunk/comboSpam.pl b/plugins/needs-review/comboSpam/trunk/comboSpam.pl index b000e9251c..eefb87711e 100644 --- a/plugins/needs-review/comboSpam/trunk/comboSpam.pl +++ b/plugins/needs-review/comboSpam/trunk/comboSpam.pl @@ -32,7 +32,7 @@ package comboSpam; my $commands = Commands::register( ['combos', '', sub { foreach my $skill (sort %sequence) { - next unless $skill->isa('Skill') && $report{$skill->getIDN()}; + next unless defined $skill && $skill->isa('Skill') && $report{$skill->getIDN()}; message sprintf("%s: %s\n", $skill->getName(), $report{$skill->getIDN()}), 'info'; } }]