diff options
author | Philipp Sehmisch <crush@themanaworld.org> | 2009-08-19 17:53:17 +0200 |
---|---|---|
committer | Philipp Sehmisch <crush@themanaworld.org> | 2009-08-19 18:07:56 +0200 |
commit | 3327475b675bf94fd827ffd36838baa42a84f11b (patch) | |
tree | 074d052fec85537f28916c82f1f84f701736753d | |
parent | e6471b3ffc2f4cc049184a979db7b02c41a8e475 (diff) | |
download | manaserv-3327475b675bf94fd827ffd36838baa42a84f11b.tar.gz manaserv-3327475b675bf94fd827ffd36838baa42a84f11b.tar.bz2 manaserv-3327475b675bf94fd827ffd36838baa42a84f11b.tar.xz manaserv-3327475b675bf94fd827ffd36838baa42a84f11b.zip |
Removed attack shape from items. Added distance check on attacks (values still hardcoded). performAttack now takes a target and a range argument instead of determining the target with accumulate&fire
-rw-r--r-- | src/game-server/being.cpp | 18 | ||||
-rw-r--r-- | src/game-server/being.hpp | 3 | ||||
-rw-r--r-- | src/game-server/character.cpp | 6 | ||||
-rw-r--r-- | src/game-server/character.hpp | 2 | ||||
-rw-r--r-- | src/game-server/item.cpp | 1 | ||||
-rw-r--r-- | src/game-server/item.hpp | 13 | ||||
-rw-r--r-- | src/game-server/itemmanager.cpp | 43 | ||||
-rw-r--r-- | src/game-server/monster.cpp | 4 |
8 files changed, 26 insertions, 64 deletions
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp index 66a13a60..e5983ee7 100644 --- a/src/game-server/being.cpp +++ b/src/game-server/being.cpp @@ -19,11 +19,11 @@ */ #include <cassert> +#include <cmath> #include "game-server/being.hpp" #include "defines.h" -#include "game-server/attackzone.hpp" #include "game-server/collisiondetection.hpp" #include "game-server/eventlistener.hpp" #include "game-server/mapcomposite.hpp" @@ -233,17 +233,21 @@ int Being::directionToAngle(int direction) } } -void Being::performAttack(const Damage &damage) +void Being::performAttack(Being *target, unsigned range, const Damage &damage) { - if (!mTarget || mTarget == this || mTarget->getAction() == Being::DEAD || !mTarget->canFight()) + // check target legality + if (!target || target == this || target->getAction() == Being::DEAD || !target->canFight()) return; - - if (getMap()->getPvP() == PVP_NONE && mTarget->getType() == OBJECT_CHARACTER && + if (getMap()->getPvP() == PVP_NONE && target->getType() == OBJECT_CHARACTER && getType() == OBJECT_CHARACTER) return; - LOG_DEBUG("Direction: " << getDirection() << - " Target: " << mTarget->getName()); + // check if target is in range + int distx = this->getPosition().x - target->getPosition().x; + int disty = this->getPosition().y - target->getPosition().y; + int dist = std::sqrt(distx * distx + disty * disty); // pythagoras + if (range + target->getSize() < dist ) + return; mTarget->damage(this, damage); mActionTime += 1000; // set to 10 ticks wait time diff --git a/src/game-server/being.hpp b/src/game-server/being.hpp index 93372b2a..c3319523 100644 --- a/src/game-server/being.hpp +++ b/src/game-server/being.hpp @@ -32,7 +32,6 @@ class Being; class MapComposite; -class AttackZone; class StatusEffect; /** @@ -215,7 +214,7 @@ class Being : public Actor /** * Performs an attack. */ - void performAttack(const Damage &); + void performAttack(Being *target, unsigned range, const Damage &damage); /** * Sets the current action. diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index 88f9aec8..a519686c 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -158,13 +158,15 @@ void Character::perform() // weapon fighting const ItemModifiers &mods = ic->getModifiers(); damage.element = mods.getValue(MOD_ELEMENT_TYPE); - performAttack(damage); + // todo: get attack range of weapon + // (weapon equipping has to be fixed first) + performAttack(mTarget, 64, damage); } else { // No-weapon fighting. damage.element = ELEMENT_NEUTRAL; - performAttack(damage); + performAttack(mTarget, 32, damage); } } diff --git a/src/game-server/character.hpp b/src/game-server/character.hpp index a5616480..603a4a16 100644 --- a/src/game-server/character.hpp +++ b/src/game-server/character.hpp @@ -345,8 +345,6 @@ class Character : public Being static const int CORRECTIONPOINTS_PER_LEVELUP = 2; static const int CORRECTIONPOINTS_MAX = 10; - static const AttackZone UNARMED_ATTACK_ZONE; - /** * Advances the character by one level; */ diff --git a/src/game-server/item.cpp b/src/game-server/item.cpp index 5512a347..3b0296aa 100644 --- a/src/game-server/item.cpp +++ b/src/game-server/item.cpp @@ -115,7 +115,6 @@ void ItemModifiers::cancelAttributes(Being *b) const ItemClass::~ItemClass() { - if (mAttackZone) delete mAttackZone; if (mScript) delete mScript; } diff --git a/src/game-server/item.hpp b/src/game-server/item.hpp index e7483663..f5e12a57 100644 --- a/src/game-server/item.hpp +++ b/src/game-server/item.hpp @@ -26,7 +26,6 @@ #include "game-server/actor.hpp" -class AttackZone; class Being; class Script; @@ -154,7 +153,7 @@ class ItemClass { public: ItemClass(int id, ItemType type, Script *s = NULL) - : mScript(NULL), mDatabaseID(id), mType(type), mAttackZone(NULL) + : mScript(NULL), mDatabaseID(id), mType(type), mAttackRange(0) {} ~ItemClass(); @@ -244,15 +243,15 @@ class ItemClass { mScript = s; } /** - * Set attack zone (only needed when the item is a weapon) + * Set attack range (only needed when the item is a weapon) */ - void setAttackZone(AttackZone* attackZone) { mAttackZone = attackZone; } + void setAttackRange(unsigned range) { mAttackRange = range; } /** * Gets attack zone of weapon (returns NULL for non-weapon items) */ - const AttackZone *getAttackZone() const - { return mAttackZone ; } + const unsigned getAttackRange() const + { return mAttackRange ; } private: @@ -268,7 +267,7 @@ class ItemClass unsigned short mMaxPerSlot; ItemModifiers mModifiers; /**< Item modifiers. */ - AttackZone *mAttackZone; /**< Attack zone when used as a weapon */ + unsigned mAttackRange; /**< Attack range when used as a weapon */ }; class Item : public Actor diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp index 297c5ad3..d86ac665 100644 --- a/src/game-server/itemmanager.cpp +++ b/src/game-server/itemmanager.cpp @@ -25,7 +25,6 @@ #include "game-server/itemmanager.hpp" #include "defines.h" -#include "game-server/attackzone.hpp" #include "game-server/item.hpp" #include "game-server/resourcemanager.hpp" #include "scripting/script.hpp" @@ -136,10 +135,7 @@ void ItemManager::reload() int maxPerSlot = XML::getProperty(node, "max-per-slot", 0); int sprite = XML::getProperty(node, "sprite_id", 0); std::string scriptFile = XML::getProperty(node, "script", ""); - std::string attackShape = XML::getProperty(node, "attack-shape", "cone"); - std::string attackTarget = XML::getProperty(node, "attack-target", "multi"); - int attackRange = XML::getProperty(node, "attack-range", 32); - int attackAngle = XML::getProperty(node, "attack-angle", 90); + unsigned attackRange = XML::getProperty(node, "attack-range", 0); ItemModifiers modifiers; if (itemType == ITEM_EQUIPMENT_ONE_HAND_WEAPON || @@ -212,42 +208,7 @@ void ItemManager::reload() item->setModifiers(modifiers); item->setSpriteID(sprite ? sprite : id); ++nbItems; - - if (itemType == ITEM_EQUIPMENT_ONE_HAND_WEAPON || - itemType == ITEM_EQUIPMENT_TWO_HANDS_WEAPON) - { - AttackZone *zone = new AttackZone; - - if (attackShape == "cone") - { - zone->shape = ATTZONESHAPE_CONE; - } - else - { - LOG_WARN("Item Manager: Unknown attack zone shape \"" << attackShape - <<"\" for weapon " << id << " in " << itemReferenceFile << '.'); - zone->shape = ATTZONESHAPE_CONE; - } - - if (attackTarget == "multi") - { - zone->multiTarget = true; - } - else if (attackTarget == "single") - { - zone->multiTarget = false; - } - else - { - LOG_WARN("Item Manager: Unknown target mode \"" << attackTarget - <<"\" for weapon " << id << " in " << itemReferenceFile << '.'); - zone->multiTarget = true; - } - zone->range = attackRange; - zone->angle = attackAngle; - - item->setAttackZone(zone); - } + item->setAttackRange(attackRange); LOG_DEBUG("Item: ID: " << id << ", itemType: " << itemType << ", weight: " << weight << ", value: " << value << diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp index d2267412..6b57ff42 100644 --- a/src/game-server/monster.cpp +++ b/src/game-server/monster.cpp @@ -115,14 +115,14 @@ void Monster::perform() { if (mAttackTime == mCurrentAttack->aftDelay) { - // Hard-coded values for now. Damage damage; damage.base = (int) (getModifiedAttribute(BASE_ATTR_PHY_ATK_MIN) * mCurrentAttack->damageFactor); damage.delta = (int) (getModifiedAttribute(BASE_ATTR_PHY_ATK_DELTA) * mCurrentAttack->damageFactor); damage.cth = getModifiedAttribute(BASE_ATTR_HIT); damage.element = mCurrentAttack->element; damage.type = mCurrentAttack->type; - performAttack(damage); + // todo: get the attack range from monster DB + performAttack(mTarget, 64, damage); } if (!mAttackTime) { |