package LasTres::PJAction::DefaultHeal; use v5.36.0; use strict; use warnings; use utf8; use Moo; with 'LasTres::PJAction'; ## OVERRIDE sub name { return 'Dormir aquí.'; } ## OVERRIDE sub identifier { return 'dormir'; } ## OVERRIDE (Always use $self->SUPER::is_disabled.) sub is_disabled($self, $pj) { my $team = $pj->team; if (!$team->leader->uuid eq $pj->uuid) { return 1; } if (!$self->_check_if_someone_needs_to_restore($pj)) { return 1; } return 0; } ## OVERRIDE (Always use $self->SUPER::disabled_reason($self, $pj).) sub disabled_reason($self, $pj) { my $team = $pj->team; if (!$team->leader->uuid eq $pj->uuid) { return 'No eres el líder del equipo.'; } if (!$self->_check_if_someone_needs_to_restore($pj)) { return 'Todo tu equipo esta lleno de vitalidad y listo para la aventura.'; } return undef; } sub _check_if_someone_needs_to_restore($self, $pj) { my $team = $pj->team; for my $member ($team->combat_members->@*) { if ($member->health < $member->max_health) { return 1; } if ($member->mana < $member->max_mana) { return 1; } } return 0; } ## OVERRIDE (Always use $self->SUPER::callback($self, $pj).) # Possibly for all the healing actions you would want to # extend this Action, if you want something special in the callback # remember to call super. sub callback($self, $pj) { my $team = $pj->team; for my $member ($team->combat_members->@*) { $member->health($member->max_health); $member->mana($member->max_mana); $member->update; } if (Scalar::Util::blessed($self) eq __PACKAGE__) { $self->_callback_unique_sleep($pj); } } sub _callback_unique_sleep($self, $pj) { my $team = $pj->team; $team->append_log_line([ { text => 'Tras dormir os sentís mucho mejor, a por más aventuras.' } ]); } 1;