diff options
Diffstat (limited to 'src/game-server/item.cpp')
-rw-r--r-- | src/game-server/item.cpp | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/src/game-server/item.cpp b/src/game-server/item.cpp index 03aeebcb..cfb1cd9a 100644 --- a/src/game-server/item.cpp +++ b/src/game-server/item.cpp @@ -25,7 +25,7 @@ #include "game-server/item.h" #include "common/configuration.h" -#include "game-server/autoattack.h" +#include "game-server/attack.h" #include "game-server/attributemanager.h" #include "game-server/being.h" #include "game-server/state.h" @@ -47,15 +47,15 @@ void ItemEffectAttrMod::dispell(Being *itemUser) mId, !mDuration); } -bool ItemEffectAutoAttack::apply(Being * /* itemUser */) +bool ItemEffectAttack::apply(Being *itemUser) { - // TODO - STUB + itemUser->addAttack(mAttackInfo); return false; } -void ItemEffectAutoAttack::dispell(Being * /* itemUser */) +void ItemEffectAttack::dispell(Being *itemUser) { - // TODO + itemUser->removeAttack(mAttackInfo); } ItemEffectScript::~ItemEffectScript() @@ -98,26 +98,45 @@ void ItemEffectScript::dispell(Being *itemUser) } } +ItemClass::~ItemClass() +{ + resetEffects(); + for (std::vector<AttackInfo *>::iterator it = mAttackInfos.begin(), + it_end = mAttackInfos.end(); + it != it_end; ++it) + { + delete *it; + } +} + bool ItemClass::useTrigger(Being *itemUser, ItemTriggerType trigger) { if (!trigger) return false; - std::pair<std::multimap< ItemTriggerType, ItemEffectInfo * >::iterator, - std::multimap< ItemTriggerType, ItemEffectInfo * >::iterator> - rn = mEffects.equal_range(trigger); + std::multimap<ItemTriggerType, ItemEffectInfo *>::iterator it, it_end; + bool ret = false; - while (rn.first != rn.second) - if (rn.first++->second->apply(itemUser)) - ret = true; + for (it = mEffects.begin(), it_end = mEffects.end(); it != it_end; ++it) + if (it->first == trigger) + if (it->second->apply(itemUser)) + ret = true; - rn = mDispells.equal_range(trigger); - while (rn.first != rn.second) - rn.first++->second->dispell(itemUser); + for (it = mDispells.begin(), it_end = mDispells.end(); it != it_end; ++it) + if (it->first == trigger) + it->second->dispell(itemUser); return ret; } +void ItemClass::addAttack(AttackInfo *attackInfo, + ItemTriggerType applyTrigger, + ItemTriggerType dispellTrigger) +{ + mAttackInfos.push_back(attackInfo); + addEffect(new ItemEffectAttack(attackInfo), applyTrigger, dispellTrigger); +} + Item::Item(ItemClass *type, int amount) : Actor(OBJECT_ITEM), mType(type), mAmount(amount) |