Skip to content

Commit

Permalink
Re-calculate enchantment based on card database states
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Shih committed Dec 2, 2016
1 parent 9054f08 commit 6a48407
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
28 changes: 15 additions & 13 deletions include/FlowControl/Manipulators/Helpers/EnchantmentHelper-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <assert.h>
#include "FlowControl/Manipulate.h"
#include "FlowControl/Manipulators/Helpers/EnchantmentHelper.h"
#include "Cards/Database.h"

namespace FlowControl
{
Expand All @@ -16,36 +17,37 @@ namespace FlowControl

if (!data.need_update) return;

state::Cards::EnchantableStates states = data.origin_states;
data.enchantments.ApplyAll(states);
state::Cards::EnchantableStates origin_states = Cards::Database::GetInstance().Get(card_.GetCardId()).enchantable_states;
state::Cards::EnchantableStates new_states = origin_states;
data.enchantments.ApplyAll(new_states);

auto card_manipulator = Manipulate(state_, flow_context_).Card(card_ref_);

static_assert(state::Cards::EnchantableStates::kFieldChangeId == 1, "enchantable fields changed");

// update states field by field
bool update_zone = false;
if (states.player != data.origin_states.player) {
if (new_states.player != origin_states.player) {
switch (card_.GetCardType()) {
case state::kCardTypeMinion:
ChangeMinionPlayer(states.player);
ChangeMinionPlayer(new_states.player);
break;
default:
throw std::exception("unsupported enchantment type");
}
}

if (states.cost != data.origin_states.cost) {
card_manipulator.Cost(states.cost);
assert(card_.GetCost() == states.cost);
if (new_states.cost != origin_states.cost) {
card_manipulator.Cost(new_states.cost);
assert(card_.GetCost() == new_states.cost);
}
if (states.attack != data.origin_states.attack) {
card_manipulator.Attack(states.attack);
assert(card_.GetAttack() == states.attack);
if (new_states.attack != origin_states.attack) {
card_manipulator.Attack(new_states.attack);
assert(card_.GetAttack() == new_states.attack);
}
if (states.max_hp != data.origin_states.max_hp) {
card_manipulator.MaxHP(states.max_hp);
assert(card_.GetMaxHP() == states.max_hp);
if (new_states.max_hp != origin_states.max_hp) {
card_manipulator.MaxHP(new_states.max_hp);
assert(card_.GetMaxHP() == new_states.max_hp);
}

data.need_update = false;
Expand Down
1 change: 0 additions & 1 deletion include/State/Cards/EnchantmentAuxData.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace state
}

TieredEnchantments enchantments;
EnchantableStates origin_states;
bool need_update;
};
}
Expand Down

0 comments on commit 6a48407

Please sign in to comment.