Skip to content

Commit

Permalink
feat: add support to AP (#3902)
Browse files Browse the repository at this point in the history
* feat: ap support

---------

Co-authored-by: ya4ept <[email protected]>
  • Loading branch information
alisonrag and ya4ept authored Dec 16, 2024
1 parent 388d0e0 commit 5b53cf5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 18 deletions.
6 changes: 6 additions & 0 deletions control/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ attackSkillSlot {
minCastTime 0
hp
sp > 10
ap
homunculus
homunculus_hp
homunculus_sp
Expand Down Expand Up @@ -608,6 +609,7 @@ attackComboSlot {
doCommand {
hp
sp
ap
homunculus
homunculus_hp
homunculus_sp
Expand Down Expand Up @@ -657,6 +659,7 @@ useSelf_skill {
minCastTime 0
hp
sp
ap
homunculus
homunculus_hp
homunculus_sp
Expand Down Expand Up @@ -710,6 +713,7 @@ partySkill {
minCastTime 0
hp
sp
ap
homunculus
homunculus_hp
homunculus_sp
Expand Down Expand Up @@ -809,6 +813,7 @@ equipAuto {
whileSitting 0
hp
sp
ap
homunculus
homunculus_hp
homunculus_sp
Expand Down Expand Up @@ -849,6 +854,7 @@ equipAuto {
useSelf_item {
hp
sp
ap
homunculus
homunculus_hp
homunculus_sp
Expand Down
41 changes: 26 additions & 15 deletions src/Actor/You.pm
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,23 @@ sub new {

sub has_homunculus {
my ($self) = @_;

if ($self && $self->{homunculus} && $self->{slaves} && scalar(keys(%{$self->{slaves}})) && $self->{homunculus}{ID} && exists $self->{slaves}{$self->{homunculus}{ID}}) {
return 1;
}

return 0;
}

sub has_mercenary {
my ($self) = @_;

if ($self && $self->{mercenary} && $self->{slaves} && scalar(keys(%{$self->{slaves}})) && $self->{mercenary}{ID} && exists $self->{slaves}{$self->{mercenary}{ID}}) {
return 1;
}

return 0;
}
}

sub nameString {
my ($self, $otherActor) = @_;
Expand Down Expand Up @@ -189,6 +189,17 @@ sub sp_percent {
return main::percent_sp($self);
}

##
# float $char->ap_percent()
#
# Returns your AP percentage (between 0 and 100).
sub ap_percent {
my ($self) = @_;

return main::percent_ap($self);
}


##
# float $char->weight_percent()
#
Expand All @@ -199,7 +210,7 @@ sub weight_percent {
if ($self->{weight_max}) {
return $self->{weight} / $self->{weight_max} * 100;
}

return 0;
}

Expand All @@ -209,11 +220,11 @@ sub weight_percent {
# Returns your base exp percentage (between 0 and 100).
sub exp_base_percent {
my ($self) = @_;

if ($self->{exp_max}) {
return ($self->{exp} / $self->{exp_max} * 100);
}

return 0;
}

Expand All @@ -223,11 +234,11 @@ sub exp_base_percent {
# Returns your job exp percentage (between 0 and 100).
sub exp_job_percent {
my ($self) = @_;

if ($self->{exp_job_max}) {
return ($self->{exp_job} / $self->{exp_job_max} * 100);
}

return 0;
}

Expand Down Expand Up @@ -272,11 +283,11 @@ sub dequeue { shift; goto &AI::dequeue }

sub attack {
my ($self, $targetID) = @_;

return unless $self->SUPER::attack($targetID);

my $target = Actor::get($targetID);

$startedattack = 1;

Plugins::callHook('attack_start', {ID => $targetID});
Expand All @@ -296,7 +307,7 @@ sub attack {
next;
}

if (existsInList($config{"autoSwitch_$i"}, $monsters{$targetID}{'name'}) ||
if (existsInList($config{"autoSwitch_$i"}, $monsters{$targetID}{'name'}) ||
existsInList($config{"autoSwitch_$i"}, $monsters{$targetID}{nameID})) {
message TF("Encounter Monster : %s\n", $monsters{$targetID}{'name'});
if ($config{"autoSwitch_$i"."_rightHand"}) {
Expand Down Expand Up @@ -431,7 +442,7 @@ sub attack {
} #END OF BLOCK AUTOEQUIP
}

sub sendSit {
sub sendSit {
if ($config{'sitTensionRelax'} > 0 && $char->{skills}{LK_TENSIONRELAX}{lv} > 0) {
my $skill = new Skill(handle => 'LK_TENSIONRELAX');
AI::ai_skillUse2($skill, $char->{skills}{LK_TENSIONRELAX}{lv}, 1, 0, $char, "LK_TENSIONRELAX");
Expand Down
10 changes: 7 additions & 3 deletions src/Commands.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5450,7 +5450,7 @@ sub cmdStats {
"Sta: \@<<< #\@<< S.Matk: \@<<< Mres: \@<<<\n" .
"Wis: \@<<< #\@<< H.Plus: \@<<<\n" .
"Spl: \@<<< #\@<< C.Rate: \@<<<\n" .
"Con: \@<<< #\@<< T.Status Points: \@<<<\n" .
"Con: \@<<< #\@<< T.Status Points: \@<<<\n" .
"Crt: \@<<< #\@<<" ),
[$char->{'pow'} ? $char->{'pow'} : 0, $char->{'need_pow'}, $char->{'patk'}, $char->{'res'},
$char->{'sta'} ? $char->{'sta'} : 0, $char->{'need_sta'}, $char->{'smatk'}, $char->{'mres'},
Expand Down Expand Up @@ -5491,14 +5491,17 @@ sub cmdStatus {
}


my ($hp_string, $sp_string, $base_string, $job_string, $weight_string, $job_name_string, $zeny_string);
my ($hp_string, $sp_string, $ap_string, $base_string, $job_string, $weight_string, $job_name_string, $zeny_string);

$hp_string = $char->{'hp'}."/".$char->{'hp_max'}." ("
.int($char->{'hp'}/$char->{'hp_max'} * 100)
."%)" if $char->{'hp_max'};
$sp_string = $char->{'sp'}."/".$char->{'sp_max'}." ("
.int($char->{'sp'}/$char->{'sp_max'} * 100)
."%)" if $char->{'sp_max'};
$ap_string = $char->{'ap'}."/".$char->{'ap_max'}." ("
.int($char->{'ap'}/$char->{'ap_max'} * 100)
."%)" if $char->{'ap_max'};
$base_string = formatNumber($char->{'exp'})."/".formatNumber($char->{'exp_max'})." /$baseEXPKill ("
.sprintf("%.2f",$char->{'exp'}/$char->{'exp_max'} * 100)
."%)"
Expand All @@ -5522,6 +5525,7 @@ sub cmdStatus {
swrite(
TF("\@<<<<<<<<<<<<<<<<<<<<<<< HP: \@>>>>>>>>>>>>>>>>>>\n" .
"\@<<<<<<<<<<<<<<<<<<<<<<< SP: \@>>>>>>>>>>>>>>>>>>\n" .
" AP: \@>>>>>>>>>>>>>>>>>>\n" .
"Base: \@<< \@>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" .
"Job : \@<< \@>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" .
"Zeny: \@<<<<<<<<<<<<<<<<< Weight: \@>>>>>>>>>>>>>>>>>>\n" .
Expand All @@ -5530,7 +5534,7 @@ sub cmdStatus {
"Total Time spent (sec): \@>>>>>>>>\n" .
"Last Monster took (sec): \@>>>>>>>",
(exists $char->{spirits} && $char->{spirits} != 0 ? ($char->{amuletType} ? $char->{spirits} . "\tType: " . $char->{amuletType} : $char->{spirits}) : 0)),
[$char->{'name'}, $hp_string, $job_name_string, $sp_string,
[$char->{'name'}, $hp_string, $job_name_string, $sp_string, $ap_string,
$char->{'lv'}, $base_string, $char->{'lv_job'}, $job_string, $zeny_string, $weight_string,
$totaldmg, $dmgpsec_string, $totalelasped_string, $elasped_string]).
('-'x56) . "\n";
Expand Down
18 changes: 18 additions & 0 deletions src/Misc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ our @EXPORT = (
qw/lineIntersection
percent_hp
percent_sp
percent_ap
percent_weight/,

# Misc Functions
Expand Down Expand Up @@ -4164,6 +4165,15 @@ sub percent_sp {
}
}

sub percent_ap {
my $r_hash = shift;
if (!$$r_hash{'ap_max'}) {
return 0;
} else {
return ($$r_hash{'ap'} / $$r_hash{'ap_max'} * 100);
}
}

sub percent_weight {
my $r_hash = shift;
if (!$$r_hash{'weight_max'}) {
Expand Down Expand Up @@ -4614,6 +4624,14 @@ sub checkSelfCondition {
}
}

if ($config{$prefix . "_ap"}) {
if ($config{$prefix."_ap"} =~ /^(.*)\%$/) {
return 0 if (!inRange($char->ap_percent, $1));
} else {
return 0 if (!inRange($char->{ap}, $config{$prefix."_ap"}));
}
}

if ($config{$prefix."_weight"}) {
if ($config{$prefix."_weight"} =~ /^(.*)\%$/) {
return 0 if $char->{weight_max} && !inRange($char->weight_percent, $1);
Expand Down

0 comments on commit 5b53cf5

Please sign in to comment.