From 81d8168bb5796ccb1704bcce9f5327c35e55d281 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sat, 17 Jul 2010 23:10:05 -0600 Subject: Move more from LocalPlayer to PlayerInfo Also cleanup PlayerInfo a bit. Reviewed-by: Chuck Miller --- src/playerinfo.h | 192 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 150 insertions(+), 42 deletions(-) (limited to 'src/playerinfo.h') diff --git a/src/playerinfo.h b/src/playerinfo.h index 421e93bc..1c722a7c 100644 --- a/src/playerinfo.h +++ b/src/playerinfo.h @@ -24,6 +24,9 @@ #include #include +/** + * Standard attributes for players. + */ enum Attribute { LEVEL, @@ -36,6 +39,9 @@ enum Attribute CHAR_POINTS, CORR_POINTS }; +/** + * Stat information storage structure. + */ struct Stat { int base; @@ -47,59 +53,161 @@ struct Stat typedef std::map IntMap; typedef std::map StatMap; +/** + * Backend for core player information. + */ struct PlayerInfoBackend { - public: IntMap mAttributes; StatMap mStats; }; +class Equipment; +class Inventory; +class Item; + /** - * A database like class which holds global info about the localplayer + * Special information storage structure. */ -class PlayerInfo +struct Special { - // NOTE: All agruements for 'bool notify' is to determine if - // a event is to be triggered - public: - static void setBackend(const PlayerInfoBackend &backend); - - /** - * Attributes for things like money and exp - */ - static int getAttribute(int id); - - static void setAttribute(int id, int value, bool notify = true); - - - /** - * Stats are modifiable attributes basicilly, like str, crit, trade - */ - - static int getStatBase(int id); - - static void setStatBase(int id, int value, bool notify = true); - - static int getStatMod(int id); - - static void setStatMod(int id, int value, bool notify = true); - - // Base + mod - static int getStatEffective(int id); - - static void setStatLevel(int id, int value, bool notify = true); - - static std::pair getStatExperience(int id); - - static void setStatExperience(int id, int have, int need, bool notify = true); + int currentMana; + int neededMana; + int recharge; +}; - private: - // Triggers send events for action. - static void triggerAttr(int id); +typedef std::map SpecialsMap; - static void triggerStat(int id); +/** + * A database like namespace which holds global info about the localplayer + * + * NOTE: 'bool notify' is used to determine if a event is to be triggered. + */ +namespace PlayerInfo +{ - static PlayerInfoBackend mData; -}; +// --- Attributes ------------------------------------------------------------- + + /** + * Returns the value of the given attribute. + */ + int getAttribute(int id); + + /** + * Changes the value of the given attribute. + */ + void setAttribute(int id, int value, bool notify = true); + +// --- Stats ------------------------------------------------------------------ + + /** + * Returns the base value of the given stat. + */ + int getStatBase(int id); + + /** + * Changes the base value of the given stat. + */ + void setStatBase(int id, int value, bool notify = true); + + /** + * Returns the modifier for the given stat. + */ + int getStatMod(int id); + + /** + * Changes the modifier for the given stat. + */ + void setStatMod(int id, int value, bool notify = true); + + /** + * Returns the current effective value of the given stat. Effective is base + * + mod + */ + int getStatEffective(int id); + + /** + * Changes the level of the given stat. + */ + void setStatLevel(int id, int value, bool notify = true); + + /** + * Returns the experience of the given stat. + */ + std::pair getStatExperience(int id); + + /** + * Changes the experience of the given stat. + */ + void setStatExperience(int id, int have, int need, bool notify = true); + +// --- Inventory / Equipment -------------------------------------------------- + + /** + * Returns the player's inventory. + */ + Inventory *getInventory(); + + /** + * Clears the player's inventory and equipment. + */ + void clearInventory(); + + /** + * Changes the inventory item at the given slot. + */ + void setInventoryItem(int index, int id, int amount); + + /** + * Returns the player's equipment. + */ + Equipment *getEquipment(); + + /** + * Returns the player's equipment at the given slot. + */ + Item *getEquipment(unsigned int slot); + +// --- Specials --------------------------------------------------------------- + + /** + * Changes the status of the given special. + */ + void setSpecialStatus(int id, int current, int max, int recharge); + + /** + * Returns the status of the given special. + */ + const SpecialsMap &getSpecialStatus(); + +// --- Misc ------------------------------------------------------------------- + + /** + * Changes the internal PlayerInfoBackend reference; + */ + void setBackend(const PlayerInfoBackend &backend); + + /** + * Does necessary updates every tick. + */ + void logic(); + + /** + * Returns true if the player is involved in a trade at the moment, false + * otherwise. + */ + bool isTrading(); + + /** + * Sets whether the player is currently involved in trade or not. + */ + void setTrading(bool trading); + + /** + * Initializes some internals. + */ + void init(); + +} // namespace PlayerInfo #endif -- cgit v1.2.3-70-g09d2