From f38fc9b0f8c6b90b3d93518357d894be5864892e Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 25 May 2014 02:45:51 -0400 Subject: function to get possible demons that can be fused into a given demon --- lib/Games/SMTNocturne/Demons.pm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lib/Games') diff --git a/lib/Games/SMTNocturne/Demons.pm b/lib/Games/SMTNocturne/Demons.pm index b648bf6..336a12a 100644 --- a/lib/Games/SMTNocturne/Demons.pm +++ b/lib/Games/SMTNocturne/Demons.pm @@ -23,4 +23,25 @@ sub fuse { ); } +sub fusions_for { + my ($demon) = @_; + + $demon = Games::SMTNocturne::Demons::Demon->from_name($demon) + unless ref($demon); + + my @fusions; + my %seen; + for my $types (Games::SMTNocturne::Demons::FusionChart::unfuse($demon->type)) { + my ($type1, $type2) = @$types; + for my $demon1 (Games::SMTNocturne::Demons::Demon->from_type($type1)) { + for my $demon2 (Games::SMTNocturne::Demons::Demon->from_type($type2)) { + push @fusions, [ $demon1, $demon2 ] + if fuse($demon1, $demon2) eq $demon; + } + } + } + + return @fusions; +} + 1; -- cgit v1.2.3