diff options
Diffstat (limited to 'src/being.h')
-rw-r--r-- | src/being.h | 385 |
1 files changed, 141 insertions, 244 deletions
diff --git a/src/being.h b/src/being.h index 71b3e2cf..a55e2d3a 100644 --- a/src/being.h +++ b/src/being.h @@ -22,19 +22,19 @@ #ifndef BEING_H #define BEING_H +#include "actorsprite.h" #include "configlistener.h" +#include "listener.h" #include "map.h" #include "particlecontainer.h" #include "position.h" -#include "sprite.h" #include "vector.h" -#include "resources/spritedef.h" - #include <guichan/color.hpp> #include <SDL_types.h> +#include <map> #include <set> #include <string> #include <vector> @@ -45,31 +45,27 @@ #define SPEECH_TIME 500 #define SPEECH_MAX_TIME 1000 -class AnimatedSprite; +class BeingInfo; class FlashText; -class Graphics; -class Image; +class Guild; class ItemInfo; class Item; class Particle; +class Party; class Position; -class SimpleAnimation; class SpeechBubble; class Text; -class StatusEffect; +enum Gender +{ + GENDER_MALE = 0, + GENDER_FEMALE = 1, + GENDER_UNSPECIFIED = 2 +}; -class Being : public Sprite, public ConfigListener +class Being : public ActorSprite, public ConfigListener, public Mana::Listener { public: - enum Type - { - UNKNOWN, - PLAYER, - NPC, - MONSTER - }; - /** * Action the being is currently performing * WARNING: Has to be in sync with the same enum in the Being class @@ -78,21 +74,13 @@ class Being : public Sprite, public ConfigListener enum Action { STAND, - WALK, + MOVE, ATTACK, SIT, DEAD, HURT }; - enum TargetCursorSize - { - TC_SMALL = 0, - TC_MEDIUM, - TC_LARGE, - NUM_TC - }; - enum Speech { NO_SPEECH = 0, @@ -128,29 +116,27 @@ class Being : public Sprite, public ConfigListener * @param subtype partly determines the type of the being * @param map the map the being is on */ - Being(int id, int subtype, Map *map); + Being(int id, Type type, int subtype, Map *map); virtual ~Being(); + Type getType() const { return mType; } + /** * Removes all path nodes from this being. */ void clearPath(); /** - * Returns the walk time. - * Used to know which frame to display and trigger - * the next Tile step. - * TODO: Used by eAthena only? + * Returns the time spent in the current action. */ - int getWalkTime() const { return mWalkTime; } + int getActionTime() const { return mActionTime; } /** - * Set the current WalkTime value. - * TODO: Used by eAthena only? + * Set the current action time. * @see Ea::BeingHandler that set it to tick time. */ - void setWalkTime(int walkTime) { mWalkTime = walkTime; } + void setActionTime(int actionTime) { mActionTime = actionTime; } /** * Makes this being take the next tile of its path. @@ -216,7 +202,7 @@ class Being : public Sprite, public ConfigListener * @param damage the amount of damage recieved (0 means miss) * @param type the attack type */ - virtual void takeDamage(Being *attacker, int damage, AttackType type); + void takeDamage(Being *attacker, int damage, AttackType type); /** * Handles an attack of another being by this being. @@ -238,23 +224,82 @@ class Being : public Sprite, public ConfigListener * * @param name The name that should appear. */ - virtual void setName(const std::string &name); + void setName(const std::string &name); bool getShowName() const { return mShowName; } - virtual void setShowName(bool doShowName); + void setShowName(bool doShowName); /** - * Following are set from the server (mainly for players) + * Sets the name of the party the being is in. Shown in BeingPopup. */ void setPartyName(const std::string &name) { mPartyName = name; } const std::string &getPartyName() const { return mPartyName; } - virtual void setGuildName(const std::string &name); + /** + * Sets the name of the primary guild the being is in. Shown in + * BeingPopup (eventually). + */ + void setGuildName(const std::string &name); + + void setGuildPos(const std::string &pos); - virtual void setGuildPos(const std::string &pos); + /** + * Adds a guild to the being. + */ + void addGuild(Guild *guild); + + /** + * Removers a guild from the being. + */ + void removeGuild(int id); + + /** + * Returns a pointer to the specified guild that the being is in. + */ + Guild *getGuild(const std::string &guildName) const; + + /** + * Returns a pointer to the specified guild that the being is in. + */ + Guild *getGuild(int id) const; + + /** + * Returns all guilds the being is in. + */ + const std::map<int, Guild*> &getGuilds() const + { return mGuilds; } + + /** + * Removes all guilds the being is in. + */ + void clearGuilds(); + + /** + * Get number of guilds the being belongs to. + */ + short getNumberOfGuilds() const + { return mGuilds.size(); } + + bool isInParty() const + { return mParty != NULL; } + + void setParty(Party *party); + + Party *getParty() const + { return mParty; } + + /** + * Sets visible equipments for this being. + */ + void setSprite(unsigned int slot, int id, + const std::string &color = "", bool isWeapon = false); + + void setSpriteID(unsigned int slot, int id); + + void setSpriteColor(unsigned int slot, const std::string &color = ""); /** * Get the number of hairstyles implemented @@ -282,20 +327,27 @@ class Being : public Sprite, public ConfigListener */ void drawEmotion(Graphics *graphics, int offsetX, int offsetY); - /** - * Returns the type of the being. - */ - virtual Type getType() const { return UNKNOWN; } - - /** - * Return Being's current Job (player job, npc, monster, creature ) - */ Uint16 getSubType() const { return mSubType; } /** - * Set Being's current Job (player job, npc, monster, creature ) + * Set Being's subtype (mostly for view for monsters and NPCs) */ - virtual void setSubtype(Uint16 subtype) { mSubType = subtype; } + void setSubtype(Uint16 subtype); + + const BeingInfo *getInfo() const + { return mInfo; } + + TargetCursorSize getTargetCursorSize() const; + + /** + * Gets the way the object is blocked by other objects. + */ + unsigned char getWalkMask() const; + + /** + * Gets the way the monster blocks pathfinding for other objects + */ + Map::BlockType getBlockType() const; /** * Sets the walk speed. @@ -324,18 +376,6 @@ class Being : public Sprite, public ConfigListener int getAttackSpeed() const { return mAttackSpeed; } /** - * Sets the sprite id. - */ - void setId(int id) { mId = id; } - - int getId() const { return mId; } - - /** - * Sets the map the being is on - */ - void setMap(Map *map); - - /** * Sets the current action. */ virtual void setAction(Action action, int attackType = 0); @@ -361,65 +401,11 @@ class Being : public Sprite, public ConfigListener void setDirection(Uint8 direction); /** - * Returns the being's current sprite frame number. - */ - int getCurrentFrame() const { return mFrame; } - - /** - * Set the being's current sprite frame number. - */ - void setFrame(int frame) { mFrame = frame; } - - /** * Returns the direction the being is facing. */ SpriteDirection getSpriteDirection() const { return SpriteDirection(mSpriteDirection); } - /** - * Draws this being to the given graphics context. - * - * @see Sprite::draw(Graphics, int, int) - * - * TODO: The following two functions should be combined. - * at some point draw(), was changed to use mPx and mPy, with arugements - * only for the offset, drawSpriteAt() takes x, and y and draws the sprite - * exactly at those coords (though it does do some computing to work how the - * old draw() worked). - */ - virtual void draw(Graphics *graphics, int offsetX, int offsetY) const; - - virtual void drawSpriteAt(Graphics *graphics, int x, int y) const; - - /** - * Set the alpha opacity used to draw the being. - */ - virtual void setAlpha(float alpha) - { mAlpha = alpha; } - - /** - * Returns the current alpha opacity of the Being. - */ - virtual float getAlpha() const - { return mAlpha; } - - /** - * Returns the X coordinate in pixels. - */ - int getPixelX() const - { return (int) mPos.x; } - - /** - * Returns the Y coordinate in pixels. - * - * @see Sprite::getPixelY() - */ - int getPixelY() const - { return (int) mPos.y; } - - /** - * Sets the position of this being. - */ void setPosition(const Vector &pos); /** @@ -427,17 +413,12 @@ class Being : public Sprite, public ConfigListener * * @see setPosition(const Vector &pos) */ - void setPosition(float x, float y, float z = 0.0f) + inline void setPosition(float x, float y, float z = 0.0f) { setPosition(Vector(x, y, z)); } /** - * Returns the position of this being. - */ - const Vector &getPosition() const { return mPos; } - - /** * Returns the horizontal size of the current base sprite of the being. */ virtual int getWidth() const; @@ -453,45 +434,17 @@ class Being : public Sprite, public ConfigListener virtual int getCollisionRadius() const; /** - * Returns the required size of a target cursor for this being. - */ - virtual Being::TargetCursorSize getTargetCursorSize() const - { return TC_MEDIUM; } - - /** - * Take control of a particle. - */ - void controlParticle(Particle *particle); - - /** * Shoots a missile particle from this being, to target being */ void fireMissile(Being *target, const std::string &particle); /** - * Gets the way the object is blocked by other objects. - */ - virtual unsigned char getWalkMask() const - { return 0x00; } //can walk through everything - - /** * Returns the path this being is following. An empty path is returned * when this being isn't following any path currently. */ const Path &getPath() const { return mPath; } /** - * Sets the target animation for this being. - */ - void setTargetAnimation(SimpleAnimation *animation); - - /** - * Untargets the being - */ - void untarget() { mUsedTargetCursor = NULL; } - - - /** * Set the Emoticon type and time displayed above * the being. */ @@ -507,45 +460,9 @@ class Being : public Sprite, public ConfigListener */ Uint8 getEmotion() const { return mEmotion; } - /** - * Sets the being's stun mode. If zero, the being is `normal', - * otherwise it is `stunned' in some fashion. - */ - void setStunMode(int stunMode) - { - if (mStunMode != stunMode) - updateStunMode(mStunMode, stunMode); - mStunMode = stunMode; - }; - - void setStatusEffect(int index, bool active); - - /** - * A status effect block is a 16 bit mask of status effects. - * We assign each such flag a block ID of offset + bitnr. - * - * These are NOT the same as the status effect indices. - */ - void setStatusEffectBlock(int offset, Uint16 flags); - - /** - * Triggers a visual effect, such as `level up' - * - * Only draws the visual effect, does not play sound effects - * - * \param effectId ID of the effect to trigger - */ - virtual void triggerEffect(int effectId) - { - internalTriggerEffect(effectId, false, true); - } - - virtual AnimatedSprite *getSprite(int index) const - { return mSprites[index]; } - static void load(); - virtual void optionChanged(const std::string &value) {} + virtual void optionChanged(const std::string &value); void flashName(int time); @@ -554,78 +471,65 @@ class Being : public Sprite, public ConfigListener void updateName(); - protected: /** - * Sets the new path for this being. + * Sets the gender of this being. */ - void setPath(const Path &path); + virtual void setGender(Gender gender); - /** - * Updates name's location. - */ - virtual void updateCoords(); + Gender getGender() const + { return mGender; } /** - * Gets the way the object blocks pathfinding for other objects + * Whether or not this player is a GM. */ - virtual Map::BlockType getBlockType() const - { return Map::BLOCKTYPE_NONE; } + bool isGM() const + { return mIsGM; } /** - * Trigger visual effect, with components - * - * \param effectId ID of the effect to trigger - * \param sfx Whether to trigger sound effects - * \param gfx Whether to trigger graphical effects + * Triggers whether or not to show the name as a GM name. */ - void internalTriggerEffect(int effectId, bool sfx, bool gfx); + void setGM(bool gm); - /** - * Notify self that the stun mode has been updated. Invoked by - * setStunMode if something changed. - */ - virtual void updateStunMode(int oldMode, int newMode); + bool canTalk(); + + void talkTo(); + void event(const std::string &channel, const Mana::Event &event); + + protected: /** - * Notify self that a status effect has flipped. - * The new flag is passed. + * Sets the new path for this being. */ - virtual void updateStatusEffect(int index, bool newStatus); + void setPath(const Path &path); /** - * Handle an update to a status or stun effect - * - * \param The StatusEffect to effect - * \param effectId -1 for stun, otherwise the effect index + * Updates name's location. */ - virtual void handleStatusEffect(StatusEffect *effect, int effectId); + void updateCoords(); - virtual void showName(); + void showName(); - /** The current sprite Frame number to be displayed */ - int mFrame; + void updateColors(); - /** Used to trigger the nextStep (walking on next Tile) - * TODO: Used by eAthena only? - */ - int mWalkTime; + BeingInfo *mInfo; + + int mActionTime; /**< Time spent in current action */ int mEmotion; /**< Currently showing emotion */ int mEmotionTime; /**< Time until emotion disappears */ /** Time until the last speech sentence disappears */ int mSpeechTime; + int mAttackType; int mAttackSpeed; /**< Attack speed */ + Action mAction; /**< Action the being is performing */ Uint16 mSubType; /**< Subtype (graphical view, basically) */ - int mId; /**< Unique sprite id */ Uint8 mDirection; /**< Facing direction */ Uint8 mSpriteDirection; /**< Facing direction */ - Map *mMap; /**< Map on which this being resides */ std::string mName; /**< Name of character */ std::string mPartyName; - MapSprite mMapSprite; /** * Holds a text object when the being displays it's name, 0 otherwise @@ -643,20 +547,18 @@ class Being : public Sprite, public ConfigListener std::string mSpeech; Text *mText; const gcn::Color *mTextColor; - Uint16 mStunMode; /**< Stun mode; zero if not stunned */ - std::set<int> mStatusEffects; /**< set of active status effects */ - typedef std::vector<AnimatedSprite*> Sprites; - typedef Sprites::iterator SpriteIterator; - typedef Sprites::const_iterator SpriteConstIterator; - Sprites mSprites; - float mAlpha; /**< Alpha opacity to draw the sprite */ + Vector mDest; /**< destination coordinates. */ - ParticleList mStunParticleEffects; - ParticleVector mStatusParticleEffects; - ParticleList mChildParticleEffects; + std::vector<int> mSpriteIDs; + std::vector<std::string> mSpriteColors; + Gender mGender; - Vector mDest; /**< destination coordinates. */ + // Character guild information + std::map<int, Guild*> mGuilds; + Party *mParty; + + bool mIsGM; private: @@ -667,8 +569,7 @@ class Being : public Sprite, public ConfigListener */ int getOffset(char pos, char neg) const; - /** Reset particle status effects on next redraw? */ - bool mMustResetParticles; + const Type mType; /** Speech Bubble components */ SpeechBubble *mSpeechBubble; @@ -681,13 +582,9 @@ class Being : public Sprite, public ConfigListener */ Vector mWalkSpeed; - Vector mPos; /**< Position coordinates. */ int mX, mY; /**< Position in tile */ int mDamageTaken; - - /** Target cursor being used */ - SimpleAnimation *mUsedTargetCursor; }; #endif |