diff options
author | Roderic Morris <roderic@ccs.neu.edu> | 2008-10-27 15:44:56 +0000 |
---|---|---|
committer | Roderic Morris <roderic@ccs.neu.edu> | 2008-10-27 15:44:56 +0000 |
commit | bbb9a98aeefaa1609dbd2455c102750c5005e05f (patch) | |
tree | 640b15c6b06a08d8fcd0f34102cf8dfebfafd66d /src/game-server | |
parent | ff9438ab94d19f0957a264ff79def01f9855b707 (diff) | |
download | manaserv-bbb9a98aeefaa1609dbd2455c102750c5005e05f.tar.gz manaserv-bbb9a98aeefaa1609dbd2455c102750c5005e05f.tar.xz manaserv-bbb9a98aeefaa1609dbd2455c102750c5005e05f.zip |
add effects sending system (by Chuck Miller)
Diffstat (limited to 'src/game-server')
-rw-r--r-- | src/game-server/being.cpp | 8 | ||||
-rw-r--r-- | src/game-server/effect.cpp | 47 | ||||
-rw-r--r-- | src/game-server/effect.hpp | 63 | ||||
-rw-r--r-- | src/game-server/state.cpp | 58 | ||||
-rw-r--r-- | src/game-server/thing.hpp | 1 |
5 files changed, 158 insertions, 19 deletions
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp index bcbbc6d..130f1a7 100644 --- a/src/game-server/being.cpp +++ b/src/game-server/being.cpp @@ -29,6 +29,7 @@ #include "game-server/collisiondetection.hpp" #include "game-server/eventlistener.hpp" #include "game-server/mapcomposite.hpp" +#include "game-server/effect.hpp" #include "utils/logger.h" Being::Being(int type, int id): @@ -158,13 +159,16 @@ void Being::performAttack(Damage const &damage, AttackZone const *attackZone) i(getMap()->getAroundObjectIterator(this, attackZone->range)); i; ++i) { MovingObject *o = *i; + Point opos = o->getPosition(); + + Effects::show(Effects::FIRE_BURST,getMap(),opos); if (o == this) continue; int type = o->getType(); if (type != OBJECT_CHARACTER && type != OBJECT_MONSTER) continue; - Point opos = o->getPosition(); + switch (attackZone->shape) { @@ -172,7 +176,7 @@ void Being::performAttack(Damage const &damage, AttackZone const *attackZone) if (Collision::diskWithCircleSector( opos, o->getSize(), ppos, attackZone->range, - attackZone->angle/2, attackAngle) + attackZone->angle, attackAngle) ) { victims.push_back(static_cast< Being * >(o)); diff --git a/src/game-server/effect.cpp b/src/game-server/effect.cpp new file mode 100644 index 0000000..f4a6b15 --- /dev/null +++ b/src/game-server/effect.cpp @@ -0,0 +1,47 @@ +/* + * The Mana World Server + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + + +#include "game-server/effect.hpp" + +#include "game-server/mapcomposite.hpp" +#include "game-server/state.hpp" + +void Effect::update() +{ + if(mHasBeenShown == true) + GameState::enqueueRemove(this); +} + + +namespace Effects +{ + // Added for convince + void show(int id, MapComposite *map, Point pos) + { + Effect *effect = new Effect(id); + effect->setMap(map); + effect->setPosition(pos); + GameState::enqueueInsert(effect); + } +}; + diff --git a/src/game-server/effect.hpp b/src/game-server/effect.hpp new file mode 100644 index 0000000..c17928a --- /dev/null +++ b/src/game-server/effect.hpp @@ -0,0 +1,63 @@ +/* + * The Mana World Server + * Copyright 2004 The Mana World Development Team + * + * This file is part of The Mana World. + * + * The Mana World is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * The Mana World is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with The Mana World; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _TMWSERV_EFFECT_H +#define _TMWSERV_EFFECT_H + +#include "game-server/object.hpp" + +class Effect : public Object +{ + + public: + Effect(int id) + : Object(OBJECT_EFFECT), mEffectId(id), mHasBeenShown(false) + {} + + int getEffectId() const + { return mEffectId; } + + // Removes effect after it has been shown + virtual void update(); + + // Called when the object has been shown to a player in the state loop + void show() + { mHasBeenShown = true; } + + private: + int mEffectId; + bool mHasBeenShown; +}; + + +namespace Effects +{ + // Added for convince + void show(int id, MapComposite *map, Point pos); + + // TODO: get this in sync with effects.xml + enum { + FIRE_BURST = 15 + }; +}; + +#endif diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp index 8beb089..9866d58 100644 --- a/src/game-server/state.cpp +++ b/src/game-server/state.cpp @@ -32,6 +32,7 @@ #include "game-server/inventory.hpp" #include "game-server/item.hpp" #include "game-server/itemmanager.hpp" +#include "game-server/effect.hpp" #include "game-server/map.hpp" #include "game-server/mapcomposite.hpp" #include "game-server/mapmanager.hpp" @@ -345,8 +346,9 @@ static void informPlayer(MapComposite *map, Character *p) MessageOut itemMsg(GPMSG_ITEMS); for (FixedObjectIterator i(map->getAroundCharacterIterator(p, AROUND_AREA)); i; ++i) { - assert((*i)->getType() == OBJECT_ITEM); - Item *o = static_cast< Item * >(*i); + assert((*i)->getType() == OBJECT_ITEM || (*i)->getType() == OBJECT_EFFECT); + + Object *o = static_cast< Object * >(*i); Point opos = o->getPosition(); int oflags = o->getUpdateFlags(); bool willBeInRange = ppos.inRangeOf(opos, AROUND_AREA); @@ -355,22 +357,44 @@ static void informPlayer(MapComposite *map, Character *p) if (willBeInRange ^ wereInRange) { - if (oflags & UPDATEFLAG_NEW_ON_MAP) + switch(o->getType()) { - /* Send a specific message to the client when an item appears - out of nowhere, so that a sound/animation can be performed. */ - MessageOut appearMsg(GPMSG_ITEM_APPEAR); - appearMsg.writeShort(o->getItemClass()->getDatabaseID()); - appearMsg.writeShort(opos.x); - appearMsg.writeShort(opos.y); - gameHandler->sendTo(p, appearMsg); - } - else - { - itemMsg.writeShort(willBeInRange ? o->getItemClass()->getDatabaseID() : 0); - itemMsg.writeShort(opos.x); - itemMsg.writeShort(opos.y); - } + case OBJECT_ITEM: + { + Item *o = static_cast< Item * >(*i); + if (oflags & UPDATEFLAG_NEW_ON_MAP) + { + /* Send a specific message to the client when an item appears + out of nowhere, so that a sound/animation can be performed. */ + MessageOut appearMsg(GPMSG_ITEM_APPEAR); + appearMsg.writeShort(o->getItemClass()->getDatabaseID()); + appearMsg.writeShort(opos.x); + appearMsg.writeShort(opos.y); + gameHandler->sendTo(p, appearMsg); + } + else + { + itemMsg.writeShort(willBeInRange ? o->getItemClass()->getDatabaseID() : 0); + itemMsg.writeShort(opos.x); + itemMsg.writeShort(opos.y); + } + } + break; + case OBJECT_EFFECT: + { + Effect *o = static_cast< Effect * >(*i); + o->show(); + if(!(oflags & UPDATEFLAG_NEW_ON_MAP)) //don't show old effects + break; + MessageOut effectMsg(GPMSG_CREATE_EFFECT); + effectMsg.writeShort(o->getEffectId()); + effectMsg.writeShort(opos.x); + effectMsg.writeShort(opos.y); + gameHandler->sendTo(p, effectMsg); + } + break; + default: break; + } // Switch } } diff --git a/src/game-server/thing.hpp b/src/game-server/thing.hpp index 3c6b82d..3497835 100644 --- a/src/game-server/thing.hpp +++ b/src/game-server/thing.hpp @@ -41,6 +41,7 @@ enum OBJECT_MONSTER, /**< A monster (moving actor with AI. Should be able to toggle map/quest actions, too). */ OBJECT_CHARACTER, /**< A normal being. */ + OBJECT_EFFECT, /**< A effect to be shown */ OBJECT_OTHER /**< Server-only object. */ }; |