diff options
author | Freeyorp <Freeyorp101@hotmail.com> | 2010-05-17 20:55:06 +1200 |
---|---|---|
committer | Freeyorp <Freeyorp101@hotmail.com> | 2010-07-10 21:51:07 +1200 |
commit | 98cdcb1de4f422255aa5ef924042ae7d00a5b968 (patch) | |
tree | 1746776580502fb007581f171fa89638ab6bc64f /src/game-server/item.hpp | |
parent | 26d8eba0ad906cd9b4a95bbd94fc1556719fd5d2 (diff) | |
download | manaserv-98cdcb1de4f422255aa5ef924042ae7d00a5b968.tar.gz manaserv-98cdcb1de4f422255aa5ef924042ae7d00a5b968.tar.bz2 manaserv-98cdcb1de4f422255aa5ef924042ae7d00a5b968.tar.xz manaserv-98cdcb1de4f422255aa5ef924042ae7d00a5b968.zip |
New attribute system and major changes to many low-level areas.
Attribute system:
Structure is no longer completely hardcoded. Attributes and structure is
defined by new xml file (defaulting to stats.xml)
Structure defines non-base modifications to an attribute, to be used by
modifiers from items, effects, etc.
Calculating the base value for core attributes is still done in C++ (and for
such fundamental elements the only reason I can think of to do it any other
way is perhaps being able to quickly change scripts without a compile could be
useful for testing, but such things are a low priority anyway)
Item structure:
Modifiers are now through triggers rather than single events. This also
removes hardcoded types - an item could be both able to be equipped and be
able to be activated.
Item activation no longer consumes by default, this must be specified by the
property <consumes /> inside the trigger.
Currently only attribute modifications, autoattacks, and consumes are defined
as effects, but stubs for others do exist. Autoattacks are currently
non-functional, and this should be rectified with some urgency.
Auto Attacks:
AutoAttacks are now separate entities, though not fully complete, nor fully
integrated with all beings yet. Integration with the Character class is
urgent, integration with other Being children less so.
When fully integrated this will allow for multiple autoattacks, through
equipping multiple items with this as an equip effect or even through other
means if needed.
Equipment structure:
As ItemClass types are no longer hardcoded, so too are equip types. An item
have multiple ways to be equipped across multiple equipment slots with any
number in each slot. Character maximums are global but configurable.
Miscellaneous:
Speed, money, and weight are now attributes.
Some managers have been changed into classes such that their associated
classes can have them as friends, to avoid (ab)use of public accessors.
The serialise procedure should also be set as a friend of Character (both in
the account- and game- server) as well; having public accessors returning
iterators is simply ridiculous.
Some start for such cleanups have been made, but this is not the primary focus
here. Significant work will need to be done before this is resolved
completely, but the start is there.
BuySell::registerPlayerItems() has been completely disabled temporarily. The
previous function iterated through equipment, yet in the context I think it is
intended to fill items? I have been unable to update this function to fit the
modifications made to the Inventory/Equipment/Possessions, as I am unsure what
exactly what it should be doing.
ItemClass::mSpriteId was previously unused, so had been removed, but I
notice that it was used when transmitting equipment to nearby clients.
Experimentation showed that this value was never set to anything other than
0, and so has been left out of the ItemManager rewrite.
I am not entirely sure what is happening here, but it should be worth looking
into at a later time, as I am not sure how equipment appearences would be sent
otherwise.
Diffstat (limited to 'src/game-server/item.hpp')
-rw-r--r-- | src/game-server/item.hpp | 256 |
1 files changed, 115 insertions, 141 deletions
diff --git a/src/game-server/item.hpp b/src/game-server/item.hpp index 98d1fd88..6fb7c380 100644 --- a/src/game-server/item.hpp +++ b/src/game-server/item.hpp @@ -26,32 +26,9 @@ #include "game-server/actor.hpp" class Being; -class Script; -/** - * Enumeration of available Item types. - */ -enum ItemType -{ - ITEM_UNUSABLE = 0, - ITEM_USABLE, // 1 - ITEM_EQUIPMENT_ONE_HAND_WEAPON, // 2 - ITEM_EQUIPMENT_TWO_HANDS_WEAPON,// 3 - ITEM_EQUIPMENT_TORSO,// 4 - ITEM_EQUIPMENT_ARMS,// 5 - ITEM_EQUIPMENT_HEAD,// 6 - ITEM_EQUIPMENT_LEGS,// 7 - ITEM_EQUIPMENT_SHIELD,// 8 - ITEM_EQUIPMENT_RING,// 9 - ITEM_EQUIPMENT_NECKLACE,// 10 - ITEM_EQUIPMENT_FEET,// 11 - ITEM_EQUIPMENT_AMMO,// 12 - ITEM_HAIRSPRITE, - ITEM_RACESPRITE, - ITEM_UNKNOWN -}; - -ItemType itemTypeFromString (const std::string &name); +typedef std::list< std::pair< unsigned int, unsigned int> > ItemEquipInfo; +typedef std::list< ItemEquipInfo > ItemEquipsInfo; /** * State effects to beings, and actors. @@ -81,68 +58,74 @@ enum SET_STATE_NOT_FLOATING }; -/** - * Item modifier types. - */ -enum -{ - MOD_WEAPON_TYPE = 0, - MOD_WEAPON_RANGE, - MOD_WEAPON_DAMAGE, - MOD_ELEMENT_TYPE, - MOD_LIFETIME, - MOD_ATTRIBUTE +struct ItemAutoAttackInfo { + unsigned int base; + unsigned int range; + unsigned int baseSpeed; + unsigned int skillId; + /// attribute id -> damage bonus per point + std::map< unsigned int, double > attrBonus; }; -/** - * Characteristic of an item. - */ -struct ItemModifier -{ - unsigned char type; - short value; +enum ItemTriggerType { + ITT_NULL = 0, + ITT_IN_INVY, // Associated effects apply when the item is in the inventory + ITT_ACTIVATE, // Associated effects apply when the item is activated + ITT_EQUIP, // Assosciated effects apply when the item is equipped + ITT_LEAVE_INVY, // Associated effects apply when the item leaves the inventory + ITT_UNEQUIP, // Associated effects apply when the item is unequipped + ITT_EQUIPCHG // When the item is still equipped, but in a different way }; -/** - * Set of item characteristics. - */ -class ItemModifiers +enum ItemEffectType { + // Effects that are removed automatically when the trigger ends + // (ie. item no longer exists in invy, unequipped) + IET_ATTR_MOD = 0, // Modify a given attribute with a given value + IET_AUTOATTACK, // Give the associated being an autoattack + // Effects that do not need any automatic removal + IET_COOLDOWN, // Set a cooldown to this item, preventing activation for n ticks + IET_G_COOLDOWN, // Set a cooldown to all items of this type for this being + IET_SCRIPT // Call an associated lua script with given variables +}; + +class ItemEffectInfo { public: + virtual bool apply(Being *itemUser); + virtual void dispell(Being *itemUser) {} +}; - /** - * Gets the value associated to a modifier type, or zero if none. - */ - int getValue(int type) const; - - /** - * Sets the value associated to a modifier type. - */ - void setValue(int type, int amount); - - /** - * Gets the value associated to a MOD_ATTRIBUTE class, or zero if none. - */ - int getAttributeValue(int attr) const; +class ItemEffectAttrMod : public ItemEffectInfo +{ + public: + ItemEffectAttrMod(unsigned int attrId, unsigned int layer, double value, + unsigned int id, unsigned int duration = 0) : + mAttributeId(attrId), mAttributeLayer(layer), + mMod(value), mDuration(duration), mId(id) {} - /** - * Sets the value associated to a MOD_ATTRIBUTE class. - */ - void setAttributeValue(int attr, int amount); + bool apply(Being *itemUser); + void dispell(Being *itemUser); - /** - * Applies all the attribute modifiers to a given Being. - */ - void applyAttributes(Being *) const; + private: + unsigned int mAttributeId; + unsigned int mAttributeLayer; + double mMod; + unsigned int mDuration; + unsigned int mId; +}; - /** - * Cancels all the applied modifiers to a given Being. - * Only meant for equipment. - */ - void cancelAttributes(Being *) const; +class ItemEffectAutoAttack : public ItemEffectInfo +{ + public: + bool apply(Being *itemUser); + void dispell(Being *itemUser); +}; - private: - std::vector< ItemModifier > mModifiers; +class ItemEffectConsumes : public ItemEffectInfo +{ + public: + bool apply(Being *itemUser) { return true; } + void dispell(Being *itemUser) {} }; /** @@ -151,23 +134,17 @@ class ItemModifiers class ItemClass { public: - ItemClass(int id, ItemType type, Script *s = NULL) - : mScript(NULL), mDatabaseID(id), mType(type), mAttackRange(0) + ItemClass(int id, unsigned int maxperslot) + : mDatabaseID(id), mSpriteID(0), mMaxPerSlot(maxperslot) {} - ~ItemClass(); + ~ItemClass() { resetEffects(); } /** * Applies the modifiers of an item to a given user. - * @return true if the item was sucessfully used and should be removed. + * @return true if item should be removed. */ - bool use(Being *itemUser); - - /** - * Gets item type. - */ - ItemType getType() const - { return mType; } + bool useTrigger(Being *itemUser, ItemTriggerType trigger); /** * Gets item weight. @@ -176,46 +153,19 @@ class ItemClass { return mWeight; } /** - * Sets item weight. - */ - void setWeight(int weight) - { mWeight = weight; } - - /** * Gets unit cost of these items. */ int getCost() const { return mCost; } /** - * Sets unit cost of these items. - */ - void setCost(int cost) - { mCost = cost; } - - /** * Gets max item per slot. */ - int getMaxPerSlot() const + unsigned int getMaxPerSlot() const { return mMaxPerSlot; } - /** - * Sets max item per slot. - */ - void setMaxPerSlot(int perSlot) - { mMaxPerSlot = perSlot; } - - /** - * Gets item modifiers. - */ - const ItemModifiers &getModifiers() const - { return mModifiers; } - - /** - * Sets item modifiers. - */ - void setModifiers(const ItemModifiers &modifiers) - { mModifiers = modifiers; } + bool hasTrigger(ItemTriggerType id) + { return mEffects.count(id); } /** * Gets database ID. @@ -224,49 +174,73 @@ class ItemClass { return mDatabaseID; } /** - * Sets the sprite ID. - */ - void setSpriteID(int spriteID) - { mSpriteID = spriteID; } - - /** * Gets the sprite ID. + * @note At present this is only a stub, and will always return zero. + * When you would want to extend serializeLooks to be more + * efficient, keep track of a sprite id here. */ int getSpriteID() const { return mSpriteID; } /** - * Sets the script that is to be used + * Returns equip requirements. */ - void setScript(Script *s) - { mScript = s; } + const ItemEquipsInfo &getItemEquipData() const { return mEquip; } - /** - * Set attack range (only needed when the item is a weapon) - */ - void setAttackRange(unsigned range) { mAttackRange = range; } + + private: /** - * Gets attack zone of weapon (returns NULL for non-weapon items) + * Add an effect to a trigger + * @param effect The effect to be run when the trigger is hit. + * @param id The trigger type. + * @param dispell The trigger that the effect should be dispelled on. + * @note FIXME: Should be more than one trigger that an effect + * can be dispelled from. */ - const unsigned getAttackRange() const - { return mAttackRange ; } - - - private: - Script *mScript; /**< Script for using items */ + void addEffect(ItemEffectInfo *effect, + ItemTriggerType id, + ItemTriggerType dispell = ITT_NULL) + { + mEffects.insert(std::make_pair(id, effect)); + if (dispell) + mDispells.insert(std::make_pair(dispell, effect)); + } + + void resetEffects() + { + while (mEffects.begin() != mEffects.end()) + { + delete mEffects.begin()->second; + mEffects.erase(mEffects.begin()); + } + while (mDispells.begin() != mDispells.end()) + { + delete mDispells.begin()->second; + mDispells.erase(mDispells.begin()); + } + } unsigned short mDatabaseID; /**< Item reference information */ /** The sprite that should be shown to the character */ unsigned short mSpriteID; - ItemType mType; /**< Type: usable, equipment etc. */ unsigned short mWeight; /**< Weight of the item. */ unsigned short mCost; /**< Unit cost the item. */ /** Max item amount per slot in inventory. */ - unsigned short mMaxPerSlot; + unsigned int mMaxPerSlot; + + std::multimap< ItemTriggerType, ItemEffectInfo * > mEffects; + std::multimap< ItemTriggerType, ItemEffectInfo * > mDispells; + + /** + * List of list of requirements for equipping. Only one inner list + * need be satisfied to sucessfully equip. Checks occur in order + * from outer front to back. + * All conditions in an inner list must be met for success. + */ + ItemEquipsInfo mEquip; - ItemModifiers mModifiers; /**< Item modifiers. */ - unsigned mAttackRange; /**< Attack range when used as a weapon */ + friend class ItemManager; }; /** |