summaryrefslogtreecommitdiffstats
path: root/lib/Games
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-05-25 11:40:12 -0400
committerJesse Luehrs <doy@tozt.net>2014-05-25 11:40:12 -0400
commit3915741eccf2c74b7be8043dce10b81161bf4854 (patch)
tree000e11dd0565770efec2cf45c79c293895a2f8c6 /lib/Games
parent32e9180698185015a09210012d8ee982d01e5c56 (diff)
downloadgames-smtnocturne-demons-3915741eccf2c74b7be8043dce10b81161bf4854.tar.gz
games-smtnocturne-demons-3915741eccf2c74b7be8043dce10b81161bf4854.zip
implement element fusion
Diffstat (limited to 'lib/Games')
-rw-r--r--lib/Games/SMTNocturne/Demons.pm21
-rw-r--r--lib/Games/SMTNocturne/Demons/Demon.pm15
-rw-r--r--lib/Games/SMTNocturne/Demons/FusionChart.pm12
3 files changed, 41 insertions, 7 deletions
diff --git a/lib/Games/SMTNocturne/Demons.pm b/lib/Games/SMTNocturne/Demons.pm
index b5da3d1..386ce0c 100644
--- a/lib/Games/SMTNocturne/Demons.pm
+++ b/lib/Games/SMTNocturne/Demons.pm
@@ -69,9 +69,20 @@ sub _fuse_mitama {
}
sub _element_fusion {
- my ($element, $demon) = @_;
+ my ($element, $demon, $options) = @_;
- die "element fusion nyi";
+ my $direction = Games::SMTNocturne::Demons::FusionChart::element_fusion(
+ $demon->type, $element->name
+ );
+ return unless $direction;
+
+ return Games::SMTNocturne::Demons::Demon->from_fusion_stats({
+ type => $demon->type,
+ level => $demon->level,
+ fusion_type => 'normal',
+ offset => $direction,
+ %{ $options || {} },
+ });
}
sub _mitama_fusion {
@@ -83,7 +94,11 @@ sub _mitama_fusion {
sub _fuse_element {
my ($demon1, $demon2) = @_;
- die "element fusion nyi";
+ my $element = Games::SMTNocturne::Demons::FusionChart::fuse_element(
+ $demon1->type
+ );
+ return unless $element;
+ return Games::SMTNocturne::Demons::Demon->from_name($element);
}
sub _normal_fusion {
diff --git a/lib/Games/SMTNocturne/Demons/Demon.pm b/lib/Games/SMTNocturne/Demons/Demon.pm
index 104d141..03b8773 100644
--- a/lib/Games/SMTNocturne/Demons/Demon.pm
+++ b/lib/Games/SMTNocturne/Demons/Demon.pm
@@ -43,13 +43,20 @@ sub from_fusion_stats {
my %bosses = map { $_ => 1 } @{ $options->{bosses} || [] };
@possible = grep { !$_->boss || $bosses{$_->name} } @possible;
- my $found;
- for my $demon (@possible) {
- $found = $demon;
+ my $found_idx;
+ for my $i (0..$#possible) {
+ $found_idx = $i;
+ my $demon = $possible[$i];
last if $demon->level >= $options->{level};
}
- return $found;
+ if ($options->{offset}) {
+ $found_idx += $options->{offset} eq 'up' ? 1 : -1;
+ $found_idx = 0 if $found_idx < 0;
+ $found_idx = $#possible if $found_idx > $#possible;
+ }
+
+ return $possible[$found_idx];
}
sub from_type {
diff --git a/lib/Games/SMTNocturne/Demons/FusionChart.pm b/lib/Games/SMTNocturne/Demons/FusionChart.pm
index ec8c67f..294092d 100644
--- a/lib/Games/SMTNocturne/Demons/FusionChart.pm
+++ b/lib/Games/SMTNocturne/Demons/FusionChart.pm
@@ -31,6 +31,18 @@ sub unfuse {
return @combinations;
}
+sub fuse_element {
+ my ($type) = @_;
+
+ return $TYPES{$type}{self_fusion};
+}
+
+sub element_fusion {
+ my ($type, $element) = @_;
+
+ return $TYPES{$type}{element_fusions}{$element};
+}
+
1;
__DATA__