From 0f0004ff3e286270c0425642a5669661ef6cb592 Mon Sep 17 00:00:00 2001 From: Erik Schilling Date: Sun, 10 Jun 2012 09:54:03 +0200 Subject: Rename AutoAttack to Attack --- example/items.xml | 6 +- gameserver.cbp | 4 +- src/CMakeLists.txt | 4 +- src/common/defines.h | 2 +- src/game-server/attack.cpp | 77 ++++++++++++++++++++ src/game-server/attack.h | 153 ++++++++++++++++++++++++++++++++++++++++ src/game-server/autoattack.cpp | 77 -------------------- src/game-server/autoattack.h | 153 ---------------------------------------- src/game-server/being.cpp | 2 +- src/game-server/being.h | 4 +- src/game-server/character.cpp | 18 ++--- src/game-server/item.cpp | 6 +- src/game-server/item.h | 6 +- src/game-server/itemmanager.cpp | 2 +- 14 files changed, 257 insertions(+), 257 deletions(-) create mode 100644 src/game-server/attack.cpp create mode 100644 src/game-server/attack.h delete mode 100644 src/game-server/autoattack.cpp delete mode 100644 src/game-server/autoattack.h diff --git a/example/items.xml b/example/items.xml index cdbc3e4..e58949e 100644 --- a/example/items.xml +++ b/example/items.xml @@ -117,7 +117,7 @@ - @@ -134,7 +134,7 @@ - @@ -152,7 +152,7 @@ - diff --git a/gameserver.cbp b/gameserver.cbp index 409b871..ef0fc32 100644 --- a/gameserver.cbp +++ b/gameserver.cbp @@ -118,8 +118,8 @@ - - + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c1a5bd0..5a4b38f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -193,12 +193,12 @@ SET(SRCS_MANASERVGAME game-server/accountconnection.cpp game-server/actor.h game-server/actor.cpp + game-server/attack.h + game-server/attack.cpp game-server/attribute.h game-server/attribute.cpp game-server/attributemanager.h game-server/attributemanager.cpp - game-server/autoattack.h - game-server/autoattack.cpp game-server/being.h game-server/being.cpp game-server/buysell.h diff --git a/src/common/defines.h b/src/common/defines.h index 3c7d846..dab5b03 100644 --- a/src/common/defines.h +++ b/src/common/defines.h @@ -178,7 +178,7 @@ enum /** * Temporary attributes. - * @todo Use AutoAttacks instead. + * @todo Use Attacks instead. */ MOB_ATTR_PHY_ATK_MIN = 20, MOB_ATTR_PHY_ATK_DELTA = 21, diff --git a/src/game-server/attack.cpp b/src/game-server/attack.cpp new file mode 100644 index 0000000..4f04255 --- /dev/null +++ b/src/game-server/attack.cpp @@ -0,0 +1,77 @@ +/* + * The Mana Server + * Copyright (C) 2010 The Mana 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 . + */ + +#include "attack.h" + +void Attacks::add(const Attack &attack) +{ + mAttacks.push_back(attack); + // Slow, but safe. + mAttacks.sort(); +} + +void Attacks::clear() +{ + mAttacks.clear(); +} + +void Attacks::stop() +{ + for (std::list::iterator it = mAttacks.begin(); + it != mAttacks.end(); ++it) + { + it->halt(); + } + mActive = false; +} + +void Attacks::start() +{ + for (std::list::iterator it = mAttacks.begin(); + it != mAttacks.end(); ++it) + { + // If the attack is inactive, we hard reset it. + if (!it->getTimer()) + it->reset(); + else + it->softReset(); + } + mActive = true; +} + +void Attacks::tick(std::list *ret) +{ + for (std::list::iterator it = mAttacks.begin(); + it != mAttacks.end(); ++it) + { + if (it->tick()) + { + if (mActive) + it->reset(); + else + it->halt(); + } + + if (ret && it->isReady()) + { + ret->push_back(*it); + } + } +} diff --git a/src/game-server/attack.h b/src/game-server/attack.h new file mode 100644 index 0000000..f9ddf6a --- /dev/null +++ b/src/game-server/attack.h @@ -0,0 +1,153 @@ +/* + * The Mana Server + * Copyright (C) 2010 The Mana 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 . + */ + +#ifndef ATTACK_H +#define ATTACK_H + +#include +#include + +#include "common/defines.h" + +/** + * Structure that describes the severity and nature of an attack a being can + * be hit by. + */ +struct Damage +{ + unsigned int skill; /**< Skill used by source (needed for exp calculation) */ + 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. */ + DamageType type; /**< Damage type: Physical or magical? */ + bool trueStrike; /**< Override dodge calculation */ + unsigned short range; /**< Maximum distance that this attack can be used from, in pixels */ + + Damage(): + skill(0), + base(0), + delta(0), + cth(0), + element(ELEMENT_NEUTRAL), + type(DAMAGE_OTHER), + trueStrike(false), + range(DEFAULT_TILE_LENGTH) + {} +}; + +/** + * Class that stores information about an auto-attack + */ + +class Attack +{ + public: + Attack(Damage &damage, unsigned int warmup, unsigned int cooldown): + mDamage(damage), + mTimer(0), + mAspd(cooldown), + mWarmup(warmup && warmup < cooldown ? warmup : cooldown >> 2) + {} + + unsigned short getTimer() const { return mTimer; } + bool tick() { return mTimer ? !--mTimer : false; } + void reset() { mTimer = mAspd; } + void softReset() { if (mTimer >= mWarmup) mTimer = mAspd; } + void halt() { if (mTimer >= mWarmup) mTimer = 0; } + bool isReady() const { return !(mTimer - mWarmup); } + + bool operator<(const Attack &rhs) const + { return mTimer < rhs.mTimer; } + + 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; + + /** + * Value to reset the timer to (warmup + cooldown) + */ + unsigned short mAspd; + + /** + * 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 Attacks +{ + public: + /** + * Whether the being has at least one auto attack that is ready. + */ + void add(const Attack &); + 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 *ret = 0); + + /** + * Tells the number of attacks available + */ + unsigned getNumber() + { return mAttacks.size(); } + + /** + * Tells whether the attacks are active. + */ + bool areActive() + { return mActive; } + + private: + /** + * Marks whether or not to keep auto-attacking. Cooldowns still need + * to be processed when false. + */ + bool mActive; + std::list mAttacks; +}; + +#endif // ATTACK_H diff --git a/src/game-server/autoattack.cpp b/src/game-server/autoattack.cpp deleted file mode 100644 index d8425d5..0000000 --- a/src/game-server/autoattack.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2010 The Mana 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 . - */ - -#include "autoattack.h" - -void AutoAttacks::add(const AutoAttack &autoAttack) -{ - mAutoAttacks.push_back(autoAttack); - // Slow, but safe. - mAutoAttacks.sort(); -} - -void AutoAttacks::clear() -{ - mAutoAttacks.clear(); -} - -void AutoAttacks::stop() -{ - for (std::list::iterator it = mAutoAttacks.begin(); - it != mAutoAttacks.end(); ++it) - { - it->halt(); - } - mActive = false; -} - -void AutoAttacks::start() -{ - for (std::list::iterator it = mAutoAttacks.begin(); - it != mAutoAttacks.end(); ++it) - { - // If the attack is inactive, we hard reset it. - if (!it->getTimer()) - it->reset(); - else - it->softReset(); - } - mActive = true; -} - -void AutoAttacks::tick(std::list *ret) -{ - for (std::list::iterator it = mAutoAttacks.begin(); - it != mAutoAttacks.end(); ++it) - { - if (it->tick()) - { - if (mActive) - it->reset(); - else - it->halt(); - } - - if (ret && it->isReady()) - { - ret->push_back(*it); - } - } -} diff --git a/src/game-server/autoattack.h b/src/game-server/autoattack.h deleted file mode 100644 index a1e22ae..0000000 --- a/src/game-server/autoattack.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2010 The Mana 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 . - */ - -#ifndef AUTOATTACK_H -#define AUTOATTACK_H - -#include -#include - -#include "common/defines.h" - -/** - * Structure that describes the severity and nature of an attack a being can - * be hit by. - */ -struct Damage -{ - unsigned int skill; /**< Skill used by source (needed for exp calculation) */ - 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. */ - DamageType type; /**< Damage type: Physical or magical? */ - bool trueStrike; /**< Override dodge calculation */ - unsigned short range; /**< Maximum distance that this attack can be used from, in pixels */ - - Damage(): - skill(0), - base(0), - delta(0), - cth(0), - element(ELEMENT_NEUTRAL), - type(DAMAGE_OTHER), - trueStrike(false), - range(DEFAULT_TILE_LENGTH) - {} -}; - -/** - * Class that stores information about an auto-attack - */ - -class AutoAttack -{ - public: - AutoAttack(Damage &damage, unsigned int warmup, unsigned int cooldown): - mDamage(damage), - mTimer(0), - mAspd(cooldown), - mWarmup(warmup && warmup < cooldown ? warmup : cooldown >> 2) - {} - - unsigned short getTimer() const { return mTimer; } - bool tick() { return mTimer ? !--mTimer : false; } - void reset() { mTimer = mAspd; } - void softReset() { if (mTimer >= mWarmup) mTimer = mAspd; } - void halt() { if (mTimer >= mWarmup) mTimer = 0; } - bool isReady() const { return !(mTimer - mWarmup); } - - bool operator<(const AutoAttack &rhs) const - { return mTimer < rhs.mTimer; } - - 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; - - /** - * Value to reset the timer to (warmup + cooldown) - */ - unsigned short mAspd; - - /** - * 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(const AutoAttack &); - 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 *ret = 0); - - /** - * Tells the number of attacks available - */ - unsigned getAutoAttacksNumber() - { return mAutoAttacks.size(); } - - /** - * Tells whether the autoattacks are active. - */ - bool areActive() - { return mActive; } - - private: - /** - * Marks whether or not to keep auto-attacking. Cooldowns still need - * to be processed when false. - */ - bool mActive; - std::list mAutoAttacks; -}; - -#endif // AUTOATTACK_H diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp index 2f4e677..7ae01a0 100644 --- a/src/game-server/being.cpp +++ b/src/game-server/being.cpp @@ -440,7 +440,7 @@ void Being::setAction(BeingAction action) { // Stops the auto-attacks when changing action if (mAction == ATTACK && action != ATTACK) - mAutoAttacks.stop(); + mAttacks.stop(); mAction = action; if (action != ATTACK && // The players are informed about these actions diff --git a/src/game-server/being.h b/src/game-server/being.h index 8e7d619..be1e570 100644 --- a/src/game-server/being.h +++ b/src/game-server/being.h @@ -29,7 +29,7 @@ #include "game-server/actor.h" #include "game-server/attribute.h" -#include "game-server/autoattack.h" +#include "game-server/attack.h" #include "game-server/timeout.h" class Being; @@ -290,7 +290,7 @@ class Being : public Actor BeingAction mAction; AttributeMap mAttributes; - AutoAttacks mAutoAttacks; + Attacks mAttacks; StatusEffects mStatus; Being *mTarget; Point mOld; /**< Old coordinates. */ diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index a482587..d2b694c 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -170,12 +170,12 @@ void Character::update() void Character::processAttacks() { // Ticks attacks even when not attacking to permit cooldowns and warmups. - std::list attacksReady; - mAutoAttacks.tick(&attacksReady); + std::list attacksReady; + mAttacks.tick(&attacksReady); if (mAction != ATTACK || !mTarget) { - mAutoAttacks.stop(); + mAttacks.stop(); return; } @@ -183,7 +183,7 @@ void Character::processAttacks() // Install default bare knuckle attack if no attacks were added from config. // TODO: Get this from configuration. - if (!mAutoAttacks.getAutoAttacksNumber()) + if (!mAttacks.getNumber()) { int damageBase = getModifiedAttribute(ATTR_STR); int damageDelta = damageBase / 2; @@ -197,19 +197,19 @@ void Character::processAttacks() knuckleDamage.range = (getSize() < DEFAULT_TILE_LENGTH) ? DEFAULT_TILE_LENGTH : getSize(); - AutoAttack knuckleAttack(knuckleDamage, 7, 3); - mAutoAttacks.add(knuckleAttack); + Attack knuckleAttack(knuckleDamage, 7, 3); + mAttacks.add(knuckleAttack); } if (attacksReady.empty()) { - if (!mAutoAttacks.areActive()) - mAutoAttacks.start(); + if (!mAttacks.areActive()) + mAttacks.start(); } else { // Performs all ready attacks. - for (std::list::iterator it = attacksReady.begin(); + for (std::list::iterator it = attacksReady.begin(); it != attacksReady.end(); ++it) { performAttack(mTarget, it->getDamage()); diff --git a/src/game-server/item.cpp b/src/game-server/item.cpp index d85a161..15041ad 100644 --- a/src/game-server/item.cpp +++ b/src/game-server/item.cpp @@ -25,7 +25,7 @@ #include "game-server/item.h" #include "common/configuration.h" -#include "game-server/autoattack.h" +#include "game-server/attack.h" #include "game-server/attributemanager.h" #include "game-server/being.h" #include "game-server/state.h" @@ -47,13 +47,13 @@ void ItemEffectAttrMod::dispell(Being *itemUser) mId, !mDuration); } -bool ItemEffectAutoAttack::apply(Being * /* itemUser */) +bool ItemEffectAttack::apply(Being * /* itemUser */) { // TODO - STUB return false; } -void ItemEffectAutoAttack::dispell(Being * /* itemUser */) +void ItemEffectAttack::dispell(Being * /* itemUser */) { // TODO } diff --git a/src/game-server/item.h b/src/game-server/item.h index bfc0c80..872e52c 100644 --- a/src/game-server/item.h +++ b/src/game-server/item.h @@ -67,7 +67,7 @@ enum SET_STATE_NOT_FLOATING }; -struct ItemAutoAttackInfo +struct ItemAttackInfo { unsigned int base; unsigned int range; @@ -93,7 +93,7 @@ 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 + IET_ATTACK, // Give the associated being an attack // 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 @@ -128,7 +128,7 @@ class ItemEffectAttrMod : public ItemEffectInfo unsigned int mId; }; -class ItemEffectAutoAttack : public ItemEffectInfo +class ItemEffectAttack : public ItemEffectInfo { public: bool apply(Being *itemUser); diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp index 8c74680..2b6056b 100644 --- a/src/game-server/itemmanager.cpp +++ b/src/game-server/itemmanager.cpp @@ -385,7 +385,7 @@ void ItemManager::readEffectNode(xmlNodePtr effectNode, ItemClass *item) duration), triggerTypes.first, triggerTypes.second); } - else if (xmlStrEqual(subNode->name, BAD_CAST "autoattack")) + else if (xmlStrEqual(subNode->name, BAD_CAST "attack")) { // TODO - URGENT } -- cgit