From ce2e637541f303d2967f7d424c3ea8240e579172 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Tue, 30 Jun 2015 15:44:16 +0200 Subject: [PATCH] sc: reusable function to display cast cost --- sc.plp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sc.plp b/sc.plp index e463310..d1c6fc8 100644 --- a/sc.plp +++ b/sc.plp @@ -119,6 +119,15 @@ sub showrange { return "$min-$max"; } + sub showcost { + my ($row, $unit) = @_; + return join(' ', + sprintf('cost %.0f%%', 100 * $row->{cost} / $unit->{energy}), + !defined $row->{maint} ? () : + sprintf('+%.1f%%/s', 100 * $row->{maint} / $unit->{energy}), + ); + } + sub showattack { my ($row, $area) = @_; my $attack = $row->{attack}->[$area] @@ -219,12 +228,7 @@ sub showrange { (map { $_ && " ($_)" } join ', ', #TODO: apply upgrades $_->{range} ? "range $_->{range}" : (), - $_->{cost} ? sprintf('cost %.0f%%%s', - 100 * $_->{cost} / $row->{energy}, - defined $_->{maint} && sprintf('+%.1f%%/s', - 100 * $_->{maint} / $row->{energy}, - ), - ) : + $_->{cost} ? showcost($_, $row) : $_->{cooldown} ? "cooldown $_->{cooldown}s" : (), ), ), -- 2.30.0