summaryrefslogtreecommitdiff
path: root/src/game-server/autoattack.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/autoattack.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/autoattack.hpp')
-rw-r--r--src/game-server/autoattack.hpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/game-server/autoattack.hpp b/src/game-server/autoattack.hpp
new file mode 100644
index 00000000..a931d924
--- /dev/null
+++ b/src/game-server/autoattack.hpp
@@ -0,0 +1,100 @@
+#ifndef AUTOATTACK_HPP
+#define AUTOATTACK_HPP
+
+#include <list>
+#include <limits>
+
+/**
+ * Methods of damage calculation
+ */
+enum DMG_TY
+{
+ DAMAGE_PHYSICAL = 0,
+ DAMAGE_MAGICAL,
+ DAMAGE_DIRECT,
+ DAMAGE_OTHER = -1
+};
+
+/**
+ * Structure that describes the severity and nature of an attack a being can
+ * be hit by.
+ */
+struct Damage
+{
+ unsigned short base; /**< Base amount of damage. */
+ unsigned short delta; /**< Additional damage when lucky. */
+ unsigned short cth; /**< Chance to hit. Opposes the evade attribute. */
+ unsigned char element; /**< Elemental damage. */
+ DMG_TY type; /**< Damage type: Physical or magical? */
+ unsigned trueStrike : 1; /**< Override dodge calculation */
+ std::list<size_t> usedSkills; /**< Skills used by source (needed for exp calculation) */
+ unsigned short range; /**< Maximum distance that this attack can be used from */
+ Damage(unsigned short base, unsigned short delta, unsigned short cth,
+ unsigned char element, DMG_TY type = DAMAGE_OTHER,
+ unsigned short range = std::numeric_limits<unsigned short>::max())
+ : base(base), delta(delta), cth(cth), element(element), type(type),
+ trueStrike(false), range(range) {}
+};
+
+/**
+ * Class that stores information about an auto-attack
+ */
+
+class AutoAttack
+{
+ public:
+ AutoAttack(Damage &damage, unsigned int delay, unsigned int warmup)
+ : mDamage(damage), mTimer(0), mAspd(delay),
+ mWarmup(warmup && warmup < delay ? warmup : delay >> 2) {}
+ unsigned short getTimer() const { return mTimer; }
+ bool tick() { return mTimer ? !--mTimer : false; }
+ void reset() { mTimer = mAspd; }
+ bool operator<(const AutoAttack &rhs) const
+ { return mTimer < rhs.getTimer(); }
+ bool isReady() const { return !(mTimer - mWarmup); }
+ void halt() { if (mTimer >= mWarmup) mTimer = 0; }
+ void softReset() { if (mTimer >= mWarmup) mTimer = mAspd; }
+ const Damage &getDamage() const { return mDamage; }
+ private:
+ Damage mDamage;
+ /**
+ * Internal timer that is modified each tick.
+ * When > warmup, the attack is warming up before a strike
+ * When = warmup, the attack triggers, dealing damage to the target *if* the target is still in range.
+ * (The attack is canceled when the target moves out of range before the attack can hit, there should be a trigger for scripts here too)
+ * (Should the character automatically persue when the target is still visible in this case?)
+ * When < warmup, the attack is cooling down after a strike. When in cooldown, the timer should not be soft-reset.
+ * When 0, the attack is inactive (the character is doing something other than attacking and the attack is not in cooldown)
+ */
+ unsigned short mTimer;
+ unsigned short mAspd; // Value to reset the timer to (warmup + cooldown)
+ /**
+ * Pre-attack delay tick.
+ * This MUST be smaller than or equal to the aspd!
+ * So the attack triggers where timer == warmup, having gone through aspd - warmup ticks.
+ */
+ unsigned short mWarmup;
+};
+
+/**
+ * Helper class for storing multiple auto-attacks.
+ */
+class AutoAttacks
+{
+ public:
+
+ /**
+ * Whether the being has at least one auto attack that is ready.
+ */
+ void add(AutoAttack n);
+ void clear(); // Wipe the list completely (used in place of remove for now; FIXME)
+ void start();
+ void stop(); // If the character does some action other than attacking, reset all warmups (NOT cooldowns!)
+ void tick(std::list<AutoAttack> *ret = 0);
+ private:
+ bool mActive; /**< Marks whether or not to keep auto-attacking. Cooldowns still need to be processed when false. */
+ std::list < AutoAttack > mAutoAttacks;
+
+};
+
+#endif // AUTOATTACK_HPP