Problem about porting AvoidSkill.pl to SVN version

Forum closed. All further discussion to be discussed at https://github.com/OpenKore/

Moderator: Moderators

Message
Author
oMeLca
Noob
Noob
Posts: 6
Joined: 26 May 2009, 21:04
Noob?: No

Problem about porting AvoidSkill.pl to SVN version

#1 Post by oMeLca »

hi there, i've been trying to porting avoidSkill.pl so i can use it in SVN version, but i got few problem..

here is the old version

Code: Select all

# avoidSkill by Joseph
# original code from MessyKoreXP
# licensed under GPL
 
package avoidSkill;
 
use strict;
#use warnings;
 
use Time::HiRes qw(time);
 
use Globals;
use Utils;
use Misc;
use Network::Send;
use Log qw(debug message warning error);
 
Plugins::register('avoidSkill', 'React to skills.', \&onUnload);
 
my $hooks = Plugins::addHooks(
            ['is_casting', \&avoidSkill, undef],
            ['packet_skilluse', \&avoidSkill, undef]
);
 
sub onUnload {
   Plugins::delHooks($hooks);
}
 
sub avoidSkill {
   my (undef, $args) = @_;
   my $sourceID = $args->{sourceID};
   my $targetID = $args->{targetID};
   my $skillID = $args->{skillID};
   my $x = $args->{x};
   my $y = $args->{y};
 
   my $skill = new Skills(id => $skillID);
   $skill = $skill->name;
 
   my $source = Actor::get($sourceID);
 
   debug "avoid $skill from $source\n";
 
   for (my $i = 0; exists $config{"avoidSkill_$i"}; $i++) {
      next if (!$config{"avoidSkill_$i"});
 
      if (existsInList($config{"avoidSkill_$i"}, $skill)) {
         # if source is specified, make sure type is correct
         next if ($config{"avoidSkill_$i"."_source"} && $config{"avoidSkill_$i"."_source"} ne $source->{type});
 
         debug "checking avoid radius on $skill\n";
 
         # check if we are inside the skill area of effect
         my $inRange;
         my ($left,$right,$top,$bottom);
         if ($x != 0 || $y != 0) {
            $left = $x - $config{"avoidSkill_$i"."_radius"};
            $right = $x + $config{"avoidSkill_$i"."_radius"};
            $top = $y - $config{"avoidSkill_$i"."_radius"};
            $bottom = $y + $config{"avoidSkill_$i"."_radius"};
            $inRange = 1 if ($left <= $char->{pos_to}{x} && $right >= $char->{pos_to}{x} && $top <= $char->{pos_to}{y} && $bottom >= $char->{pos_to}{y});
 
         } elsif ($targetID eq $accountID) {
            $inRange = 1;
         }
 
         if ($inRange) {
            if ($char->{sitting}) {
               main::stand();
            }
 
            if ($config{"avoidSkill_$i"."_method"} == 0) {
               my $found = 1;
               my $count = 0;
               my %move;
               do {
                  ($move{x}, $move{y}) = getRandPosition($config{"avoidSkill_${i}_step"});
                  $count++;
                  if ($count > 100) {
                     $found = 0;
                     last;
                  }
               } while ($left <= $move{x} && $right >= $move{x} && $top <= $move{y} && $bottom >= $move{y});
 
               if ($found) {
                  stopAttack();
                  sendMove(\$remote_socket, $move{x}, $move{y});
                  message "Avoid skill $skill, random move to $move{x}, $move{y}.";
               }
 
            } elsif ($config{"avoidSkill_$i"."_method"} == 1) {
               my $dx = $x - $char->{pos_to}{x};
               my $dy = $y - $char->{pos_to}{y};
               my %random;
               my %move;
 
               my $found = 1;
               my $count = 0;
               do {
                  $random{x} = int(rand($config{"avoidSkill_$i"."_step"})) + 1;
                  $random{y} = int(rand($config{"avoidSkill_$i"."_step"})) + 1;
 
                  if ($dx >= 0) {
                     $move{x} = $char->{pos_to}{x} - $random{x};
                  } else {
                     $move{x} = $char->{pos_to}{x} + $random{x};
                  }
 
                  if ($dy >= 0) {
                     $move{y} = $char->{pos_to}{y} - $random{y};
                  } else {
                     $move{y} = $char->{pos_to}{y} + $random{y};
                  }
 
                  $count++;
                  if ($count > 100) {
                     $found = 0;
                     last;
                  }
               } while (!checkFieldWalkable(\%field, $x, $y));
 
               if ($found) {
                  stopAttack();
                  sendMove(\$remote_socket, $move{x}, $move{y});
                  message "Avoid skill $skill, move to $move{x}, $move{y}.";
               }
 
            } elsif ($config{"avoidSkill_$i"."_method"} == 2) {
               my %src;
               $src{x} = $source->{pos_to}{x};
               $src{y} = $source->{pos_to}{y};
 
               my $found = 0;
               my $count = 0;
               my ($ex_left, $ex_right, $ex_top, $ex_bottom);
               my ($in_left, $in_right, $in_top, $in_bottom);
               my %move;
               my %nearest;
 
               do {
                  $ex_left = $src{'x'} - $count;
                  $ex_right = $src{'x'} + $count;
                  $ex_top = $src{'y'} - $count;
                  $ex_bottom = $src{'y'} + $count;
 
                  $count++;
 
                  $in_left = $src{'x'} - $count;
                  $in_right = $src{'x'} + $count;
                  $in_top = $src{'y'} - $count;
                  $in_bottom = $src{'y'} + $count;
 
                  my $nearest_dist = 9999;
                  for ($move{'y'} = $in_top; $move{'y'} <= $in_bottom; $move{'y'}++) {
                     for ($move{'x'} = $in_left; $move{'x'} <= $in_right; $move{'x'}++) {
                        if (($move{'x'} < $ex_left || $move{'x'} > $ex_right) && ($move{'y'} < $ex_top || $move{'y'} > $ex_bottom)) {
                           next if (($left <= $move{'x'} && $right >= $move{'x'} && $top <= $move{'y'} && $bottom >= $move{'y'}) ||
                              !checkFieldWalkable(\%field, $move{x}, $move{y}));
 
                           my $dist = distance(\%move, \%src);
 
                           if ($dist < $nearest_dist) {
                              $nearest_dist = $dist;
                              $nearest{'x'} = $move{'x'};
                              $nearest{'y'} = $move{'y'};
                              $found = 1;
                           }
                        }
                     }
                  }
               } while (($count < 100) && (!$found));
 
               if ($found) {
                  stopAttack();
                  sendMove(\$remote_socket, $nearest{x}, $nearest{y});
                  message "Avoid skill $skill, move to nearest position $nearest{'x'}, $nearest{'y'}.";
               }
 
            } elsif ($config{"avoidSkill_$i"."_method"} == 3) {
               message "Avoid skill $skill, use random teleport.\n";
               main::useTeleport(1);
 
            } elsif ($config{"avoidSkill_$i"."_method"} == 4) {
               return unless ($source->{type} eq 'Monster');
               message "Avoid skill $skill, attack to $source->{name}\n";
               # may not care about portal distance, oh well
               stopAttack();
               main::attack($sourceID);
 
            } elsif ($config{"avoidSkill_$i"."_method"} == 5 && timeOut($AI::Timeouts::avoidSkill_skill, 3)) {
               return unless ($source->{type} eq 'Monster');
               message "Avoid skill $skill, use ".$config{"avoidSkill_$i"."_skill"}." to $source->{name}\n";
 
               $skill = new Skills(name => $config{"avoidSkill_$i"."_skill"});
 
               message "Use ".$skill->handle." on target\n";
 
               if (main::ai_getSkillUseType($skill->handle)) {
                  my $pos = ($config{"avoidSkill_${i}_isSelfSkill"}) ? $char->{pos_to} : $monsters{$sourceID}{pos_to};
                  main::ai_skillUse(
                     $skill->handle,
                     $config{"avoidSkill_$i"."_lvl"},
                     $config{"avoidSkill_$i"."_maxCastTime"},
                     $config{"avoidSkill_$i"."_minCastTime"},
                     $pos->{x},
                     $pos->{y});
               } else {
                  main::ai_skillUse(
                     $skill->handle,
                     $config{"avoidSkill_$i"."_lvl"},
                     $config{"avoidSkill_$i"."_maxCastTime"},
                     $config{"avoidSkill_$i"."_minCastTime"},
                     $config{"avoidSkill_${i}_isSelfSkill"} ? $accountID : $sourceID);
               }
               $AI::Timeouts::avoidSkill_skill = time;
            }
 
         }
 
         last;
      }
   }
}
 
sub getRandPosition {
   my $range = shift;
   my $x_pos = shift;
   my $y_pos = shift;
   my $x_rand;
   my $y_rand;
   my $x;
   my $y;
 
   if ($x_pos eq "" || $y_pos eq "") {
      $x_pos = $char->{'pos_to'}{'x'};
      $y_pos = $char->{'pos_to'}{'y'};
   }
 
   do {
      $x_rand = int(rand($range)) + 1;
      $y_rand = int(rand($range)) + 1;
 
      if (int(rand(2))) {
         $x = $x_pos + $x_rand;
      } else {
         $x = $x_pos - $x_rand;
      }
 
      if (int(rand(2))) {
         $y = $y_pos + $y_rand;
      } else {
         $y = $y_pos - $y_rand;
      }
   } while (!checkFieldWalkable(\%field, $x, $y));
 
   my @ret = ($x, $y);
   return @ret;
}
from the old version, i changed a few string

Code: Select all

my $skill = new Skills(id => $skillID);
   $skill = $skill->name;

Code: Select all

$skill = new Skills(name => $config{"avoidSkill_$i"."_skill"});
become like this

Code: Select all

my $skill = new Skill(idn => $skillID);
   $skill->getIDN();

Code: Select all

$skill = new Skill(name => $config{"avoidSkill_$i"."_skill"});
n with that string, i can login as usual with my SVN version, but the problem is.. kore doesn't initiate when Evil Druid is casting Heaven's Drive on me..

here is my config

Code: Select all

avoidSkill Heaven's Drive {
	radius 2
	source Monster
	method 2
	step 10
}
n i've tried to put use Skill; at the beginning of the plugin.. but it doesn't work either..

i need help from anybody. please help me :|

btw, sorry for my bad english >.<

oMeLca
Noob
Noob
Posts: 6
Joined: 26 May 2009, 21:04
Noob?: No

Re: Problem about porting AvoidSkill.pl to SVN version

#2 Post by oMeLca »

some body help me plz ? i've been waiting for a week but no one reply my post >.<

really confused about this :cry:

Locked