diff options
-rw-r--r-- | lib/Games/SMTNocturne/Demons.pm | 21 | ||||
-rw-r--r-- | lib/Games/SMTNocturne/Demons/Demon.pm | 3 | ||||
-rw-r--r-- | t/basic.t | 2 | ||||
-rw-r--r-- | t/lib/Test/Games/SMTNocturne/Demons.pm | 12 |
4 files changed, 27 insertions, 11 deletions
diff --git a/lib/Games/SMTNocturne/Demons.pm b/lib/Games/SMTNocturne/Demons.pm index d4aff76..b5da3d1 100644 --- a/lib/Games/SMTNocturne/Demons.pm +++ b/lib/Games/SMTNocturne/Demons.pm @@ -6,7 +6,7 @@ use Games::SMTNocturne::Demons::Demon; use Games::SMTNocturne::Demons::FusionChart; sub fuse { - my ($demon1, $demon2) = @_; + my ($demon1, $demon2, $options) = @_; $demon1 = Games::SMTNocturne::Demons::Demon->from_name($demon1) unless ref($demon1); @@ -14,12 +14,13 @@ sub fuse { unless ref($demon2); if ($demon1->type eq 'Element' && $demon2->type eq 'Element') { - return _fuse_mitama($demon1, $demon2); + return _fuse_mitama($demon1, $demon2, $options); } elsif ($demon1->type eq 'Element' || $demon2->type eq 'Element') { return _element_fusion( - $demon1->type eq 'Element' - ? ($demon1, $demon2) : ($demon2, $demon1) + ($demon1->type eq 'Element' + ? ($demon1, $demon2) : ($demon2, $demon1)), + $options ); } elsif ($demon1->type eq 'Mitama' && $demon2->type eq 'Mitama') { @@ -27,15 +28,16 @@ sub fuse { } elsif ($demon1->type eq 'Mitama' || $demon2->type eq 'Mitama') { return _mitama_fusion( - $demon1->type eq 'Mitama' - ? ($demon1, $demon2) : ($demon2, $demon1) + ($demon1->type eq 'Mitama' + ? ($demon1, $demon2) : ($demon2, $demon1)), + $options ); } elsif ($demon1->type eq $demon2->type) { - return _fuse_element($demon1, $demon2); + return _fuse_element($demon1, $demon2, $options); } else { - return _normal_fusion($demon1, $demon2); + return _normal_fusion($demon1, $demon2, $options); } } @@ -85,7 +87,7 @@ sub _fuse_element { } sub _normal_fusion { - my ($demon1, $demon2) = @_; + my ($demon1, $demon2, $options) = @_; my $new_type = Games::SMTNocturne::Demons::FusionChart::fuse( $demon1->type, $demon2->type @@ -98,6 +100,7 @@ sub _normal_fusion { type => $new_type, level => $new_level, fusion_type => 'normal', + %{ $options || {} }, }); } diff --git a/lib/Games/SMTNocturne/Demons/Demon.pm b/lib/Games/SMTNocturne/Demons/Demon.pm index 41b689a..1185f2d 100644 --- a/lib/Games/SMTNocturne/Demons/Demon.pm +++ b/lib/Games/SMTNocturne/Demons/Demon.pm @@ -40,6 +40,9 @@ sub from_fusion_stats { @possible = grep { $_->fusion_type eq $options->{fusion_type} } @possible if $options->{fusion_type}; + my %bosses = map { $_ => 1 } @{ $options->{bosses} || [] }; + @possible = grep { !$_->boss || $bosses{$_->name} } @possible; + my $found; for my $demon (@possible) { $found = $demon; @@ -6,6 +6,8 @@ use lib 't/lib'; use Test::Games::SMTNocturne::Demons; +set_fusion_options({ bosses => ['Forneus', 'Troll'] }); + fusion_is('Uzume', 'Uzume', undef); fusion_is('Uzume', 'Jack Frost', 'Forneus'); fusion_is('Uzume', 'Mou-Ryo', undef); diff --git a/t/lib/Test/Games/SMTNocturne/Demons.pm b/t/lib/Test/Games/SMTNocturne/Demons.pm index 5ccd8ac..92ad93c 100644 --- a/t/lib/Test/Games/SMTNocturne/Demons.pm +++ b/t/lib/Test/Games/SMTNocturne/Demons.pm @@ -6,13 +6,21 @@ use Exporter 'import'; use Games::SMTNocturne::Demons; use Test::More; -our @EXPORT = ('fusion_is'); +our @EXPORT = ('fusion_is', 'set_fusion_options'); + +my $FUSION_OPTIONS = {}; + +sub set_fusion_options { + $FUSION_OPTIONS = $_[0]; +} sub fusion_is { local $Test::Builder::Level = $Test::Builder::Level + 1; my ($demon1, $demon2, $expected) = @_; - my $fused = eval { Games::SMTNocturne::Demons::fuse($demon1, $demon2) }; + my $fused = eval { + Games::SMTNocturne::Demons::fuse($demon1, $demon2, $FUSION_OPTIONS) + }; die $@ if $@ && $@ !~ /\bnyi\b/; local $TODO = $@ if $@; |