diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-03-30 09:29:08 +0100 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-04-02 13:19:11 +0200 |
commit | 585a33e221a7ee392791f4fd5a5ec9214b8fe868 (patch) | |
tree | 3aa60a57ff7cdd8f57761d620352fd2ad4d0dd6f /src/game-server/state.cpp | |
parent | 4dfc82415691fe298f21bb2f81fed5c168ee14e5 (diff) | |
download | manaserv-585a33e221a7ee392791f4fd5a5ec9214b8fe868.tar.gz manaserv-585a33e221a7ee392791f4fd5a5ec9214b8fe868.tar.bz2 manaserv-585a33e221a7ee392791f4fd5a5ec9214b8fe868.tar.xz manaserv-585a33e221a7ee392791f4fd5a5ec9214b8fe868.zip |
Moved fighting code into a component
All damage dealing is now handeled via CombatComponent.
Monsters use a derived MonsterCombatComponent since they can have a damage
mutation and have a seperate script callback.
The wirering with Being is still not optional since most of the stuff does
not exist as components.
Things done:
- Seperated the fighting code from Being and only let Characters and Monsters
add the Component (less overhead for npcs)
- Added a getter for Attribute values to prevent searching it all the time in
non Being members
- Fixed the type if the damage mutation to double (no idea why it was int)
I did not want to copy it over incorrectly
- Removed the addAttack/removeAttack overrides in Character and made the
knuckleAttack being added based on newly added signals
Future TODOS:
- Remove depedency on Being as soon all needed dependencies are available
as components of Entity
- Move the monster script callback into the general combatcomponent and
make it usuable for characters too
Diffstat (limited to 'src/game-server/state.cpp')
-rw-r--r-- | src/game-server/state.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp index 673d48fa..eaffe772 100644 --- a/src/game-server/state.cpp +++ b/src/game-server/state.cpp @@ -22,11 +22,12 @@ #include "common/configuration.h" #include "game-server/accountconnection.h" +#include "game-server/effect.h" +#include "game-server/combatcomponent.h" #include "game-server/gamehandler.h" #include "game-server/inventory.h" #include "game-server/item.h" #include "game-server/itemmanager.h" -#include "game-server/effect.h" #include "game-server/map.h" #include "game-server/mapcomposite.h" #include "game-server/mapmanager.h" @@ -166,7 +167,9 @@ static void informPlayer(MapComposite *map, Character *p) MessageOut AttackMsg(GPMSG_BEING_ATTACK); AttackMsg.writeInt16(oid); AttackMsg.writeInt8(o->getDirection()); - AttackMsg.writeInt8(static_cast< Being * >(o)->getAttackId()); + CombatComponent *combatComponent = + o->getComponent<CombatComponent>(); + AttackMsg.writeInt8(combatComponent->getAttackId()); gameHandler->sendTo(p, AttackMsg); } @@ -217,8 +220,9 @@ static void informPlayer(MapComposite *map, Character *p) // Send damage messages. if (o->canFight()) { - Being *victim = static_cast< Being * >(o); - const Hits &hits = victim->getHitsTaken(); + CombatComponent *combatComponent = + o->getComponent<CombatComponent>(); + const Hits &hits = combatComponent->getHitsTaken(); for (Hits::const_iterator j = hits.begin(), j_end = hits.end(); j != j_end; ++j) { @@ -462,7 +466,7 @@ void GameState::update(int tick) a->clearUpdateFlags(); if (a->canFight()) { - static_cast< Being * >(a)->clearHitsTaken(); + a->getComponent<CombatComponent>()->clearHitsTaken(); } } } |