summaryrefslogtreecommitdiff
path: root/src/game-server/attribute.hpp
diff options
context:
space:
mode:
authorFreeyorp <Freeyorp101@hotmail.com>2010-05-17 20:55:06 +1200
committerFreeyorp <Freeyorp101@hotmail.com>2010-07-10 21:51:07 +1200
commit98cdcb1de4f422255aa5ef924042ae7d00a5b968 (patch)
tree1746776580502fb007581f171fa89638ab6bc64f /src/game-server/attribute.hpp
parent26d8eba0ad906cd9b4a95bbd94fc1556719fd5d2 (diff)
downloadmanaserv-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/attribute.hpp')
-rw-r--r--src/game-server/attribute.hpp178
1 files changed, 178 insertions, 0 deletions
diff --git a/src/game-server/attribute.hpp b/src/game-server/attribute.hpp
new file mode 100644
index 00000000..c5f833f0
--- /dev/null
+++ b/src/game-server/attribute.hpp
@@ -0,0 +1,178 @@
+/*
+ * The Mana Server
+ * Copyright (C) 2004-2010 The Mana World Development Team
+ *
+ * This file is part of The Mana Server.
+ *
+ * The Mana Server 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 Server 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 Server. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ATTRIBUTE_HPP
+#define ATTRIBUTE_HPP
+
+#include "defines.h"
+#include <vector>
+#include <list>
+
+class AttributeModifierState
+{
+ public:
+ AttributeModifierState(unsigned short duration, double value,
+ unsigned int id)
+ : mDuration(duration), mValue(value), mId(id) {}
+ ~AttributeModifierState() {}
+ bool tick() { return mDuration ? !--mDuration : false; }
+ private:
+ /** Number of ticks (0 means permanent, e.g. equipment). */
+ unsigned short mDuration;
+ const double mValue; /**< Positive or negative amount. */
+ /**
+ * Special purpose variable used to identify this effect to
+ * dispells or similar. Exact usage depends on the effect,
+ * origin, etc.
+ */
+ const unsigned int mId;
+ friend bool durationCompare(const AttributeModifierState*,
+ const AttributeModifierState*);
+ friend class AttributeModifiersEffect;
+};
+
+class AttributeModifiersEffect {
+ public:
+ AttributeModifiersEffect(AT_TY sType, AME_TY eType);
+ ~AttributeModifiersEffect();
+ /**
+ * Recalculates the value for this level.
+ * @returns True if the value changed, false if it did not change.
+ * Note that this will not change values at a higher level, nor the
+ * overall modified value for this attribute.
+ * If this returns true, the cached values for *all* modifiers of a
+ * higher level must be recalculated, as well as the final
+ */
+ bool add(unsigned short duration, double value,
+ double prevLayerValue, int level);
+
+ /**
+ * remove() - as with Attribute::remove().
+ */
+
+ bool remove(double value, unsigned int id, bool fullCheck);
+
+ /**
+ * Performs the necessary modifications to mMod when the states change.
+ */
+
+ void updateMod(double value = 0);
+
+ /**
+ * Performs the necessary modifications to mCacheVal when the states
+ * change.
+ */
+
+ bool recalculateModifiedValue(double newPrevLayerValue);
+
+ double getCachedModifiedValue() const { return mCacheVal; }
+
+ bool tick();
+
+ /**
+ * clearMods() - removes all modifications present in this layer.
+ * This only really makes sense when all other layers are being reset too.
+ * @param baseValue the value to reset to - typically an Attribute's mBase
+ */
+
+ void clearMods(double baseValue);
+
+ private:
+ /** List of all modifications present at this level */
+ std::list< AttributeModifierState * > mStates;
+ /**
+ * Stores the value that results from mStates. This takes into
+ * account all previous layers.
+ */
+ double mCacheVal;
+ /**
+ * Stores the effective modifying value from mStates. This defaults to
+ * 0 for additive modifiers and 1 for multiplicative modifiers.
+ */
+ double mMod;
+ const AT_TY mSType;
+ const AME_TY mEType;
+};
+
+class Attribute
+{
+ public:
+ Attribute() {throw;} // DEBUG; Find improper constructions
+
+ Attribute(const std::vector<struct AttributeInfoType> &type);
+
+ ~Attribute();
+
+ void setBase(double base);
+ double getBase() const { return mBase; }
+ double getModifiedAttribute() const
+ { return mMods.empty() ? mBase :
+ (*mMods.rbegin())->getCachedModifiedValue(); }
+
+ /**
+ * add() and remove() are the standard functions used to add and
+ * remove modifiers while keeping track of the modifier state.
+ */
+
+ /**
+ * @param duration The amount of time before the modifier expires
+ * naturally.
+ * When set to 0, the effect does not expire.
+ * @param value The value to be applied as the modifier.
+ * @param layer The id of the layer with which this modifier is to be
+ * applied to.
+ * @param id Used to identify this effect.
+ * @return Whether the modified attribute value was changed.
+ */
+
+ bool add(unsigned short duration, double value, unsigned int layer, int id = 0);
+
+ /**
+ * @param value The value of the modifier to be removed.
+ * - When 0, id is used exclusively to identify modifiers.
+ * @param layer The id of the layer which contains the modifier to be removed.
+ * @param id Used to identify this effect.
+ * - When 0, only the first match will be removed.
+ * - When non-0, all modifiers matching this id and other
+ * parameters will be removed.
+ * @param fullcheck Whether to perform a check for all modifiers,
+ * or only those that are otherwise permanent (ie. duration of 0)
+ * @returns Whether the modified attribute value was changed.
+ */
+ bool remove(double value, unsigned int layer, int id, bool fullcheck);
+
+ /**
+ * clearMods() removes *all* modifications present in this Attribute (!)
+ */
+
+ void clearMods();
+
+ /**
+ * tick() processes all timers associated with modifiers for this attribute.
+ */
+
+ bool tick();
+
+ private:
+ double mBase;
+ std::vector< AttributeModifiersEffect * > mMods;
+};
+
+#endif // ATTRIBUTE_HPP