diff options
author | Andreas Habel <mail@exceptionfault.de> | 2009-08-21 19:43:01 +0200 |
---|---|---|
committer | Andreas Habel <mail@exceptionfault.de> | 2009-08-21 19:43:01 +0200 |
commit | cd7ce31085fdea6549737c056ab5ddeb3aca27ec (patch) | |
tree | 51b287c55990c8838ac771bfb31845a878d7515e | |
parent | 04ebe945e98e397192272d1e3f5e6b91ebd3d795 (diff) | |
parent | c32f2a14736733b94aab1d1b0bd8e6d74396009d (diff) | |
download | manaserv-cd7ce31085fdea6549737c056ab5ddeb3aca27ec.tar.gz manaserv-cd7ce31085fdea6549737c056ab5ddeb3aca27ec.tar.bz2 manaserv-cd7ce31085fdea6549737c056ab5ddeb3aca27ec.tar.xz manaserv-cd7ce31085fdea6549737c056ab5ddeb3aca27ec.zip |
Merge branch 'master' of git@gitorious.org:tmwserv/mainline
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/game-server/attackzone.cpp | 0 | ||||
-rw-r--r-- | src/game-server/attackzone.hpp | 44 | ||||
-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 | 7 | ||||
-rw-r--r-- | src/game-server/character.hpp | 2 | ||||
-rw-r--r-- | src/game-server/item.cpp | 2 | ||||
-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 | 15 | ||||
-rw-r--r-- | src/game-server/monster.hpp | 7 | ||||
-rw-r--r-- | src/game-server/monstermanager.cpp | 8 |
13 files changed, 36 insertions, 128 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 47ce13c8..37a36d38 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -90,8 +90,6 @@ tmwserv_game_SOURCES = \ game-server/accountconnection.cpp \ game-server/actor.hpp \ game-server/actor.cpp \ - game-server/attackzone.hpp \ - game-server/attackzone.cpp \ game-server/being.hpp \ game-server/being.cpp \ game-server/buysell.hpp \ diff --git a/src/game-server/attackzone.cpp b/src/game-server/attackzone.cpp deleted file mode 100644 index e69de29b..00000000 --- a/src/game-server/attackzone.cpp +++ /dev/null diff --git a/src/game-server/attackzone.hpp b/src/game-server/attackzone.hpp deleted file mode 100644 index 1f611ba9..00000000 --- a/src/game-server/attackzone.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * The Mana World Server - * Copyright 2008 The Mana World Development Team - * - * This file is part of The Mana World. - * - * The Mana World 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 World 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 World; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _TMWSERV_ATTACKZONE -#define _TMWSERV_ATTACKZONE - - -/** - * Enumeration of different types of attack damage zones - */ -enum AttackZoneShape -{ - ATTZONESHAPE_CONE, - ATTZONESHAPE_RECT -}; - -struct AttackZone -{ - AttackZoneShape shape; - bool multiTarget; - int range; - int angle; -}; - - -#endif // _TMWSERV_ATTACKZONE diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp index 66a13a60..3993154e 100644 --- a/src/game-server/being.cpp +++ b/src/game-server/being.cpp @@ -23,7 +23,6 @@ #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 +232,22 @@ 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 using the pythagorean theorem + int distx = this->getPosition().x - target->getPosition().x; + int disty = this->getPosition().y - target->getPosition().y; + int distSquare = (distx * distx + disty * disty); + int maxDist = range + target->getSize(); + if (maxDist * maxDist < distSquare) + 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..2d022a1c 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -28,7 +28,6 @@ #include "defines.h" #include "common/configuration.hpp" #include "game-server/accountconnection.hpp" -#include "game-server/attackzone.hpp" #include "game-server/buysell.hpp" #include "game-server/eventlistener.hpp" #include "game-server/inventory.hpp" @@ -158,13 +157,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..357874ff 100644 --- a/src/game-server/item.cpp +++ b/src/game-server/item.cpp @@ -25,7 +25,6 @@ #include "game-server/item.hpp" -#include "game-server/attackzone.hpp" #include "game-server/being.hpp" #include "scripting/script.hpp" @@ -115,7 +114,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..2de90787 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); + + performAttack(mTarget, mCurrentAttack->range, damage); } if (!mAttackTime) { @@ -227,11 +227,11 @@ void Monster::update() i != allAttacks.end(); i++) { - const int attackAngle = directionToAngle(bestAttackDirection); - - if (Collision::diskWithCircleSector( - bestAttackTarget->getPosition(), bestAttackTarget->getSize(), - getPosition(), (*i)->attackZone.range, (*i)->attackZone.angle, attackAngle)) + int distx = this->getPosition().x - bestAttackTarget->getPosition().x; + int disty = this->getPosition().y - bestAttackTarget->getPosition().y; + int distSquare = (distx * distx + disty * disty); + int maxDist = (*i)->range + bestAttackTarget->getSize(); + if (maxDist * maxDist >= distSquare) { prioritySum += (*i)->priority; workingAttacks[prioritySum] = (*i); @@ -243,6 +243,7 @@ void Monster::update() } else { + //prepare for using a random attack which can hit the enemy //stop movement setDestination(getPosition()); //turn into direction of enemy diff --git a/src/game-server/monster.hpp b/src/game-server/monster.hpp index c25d853e..21b6cf2c 100644 --- a/src/game-server/monster.hpp +++ b/src/game-server/monster.hpp @@ -24,7 +24,6 @@ #include <map> #include <vector> -#include "game-server/attackzone.hpp" #include "game-server/being.hpp" #include "game-server/eventlistener.hpp" @@ -52,9 +51,9 @@ struct MonsterAttack float damageFactor; int element; int type; - int preDelay; - int aftDelay; - AttackZone attackZone; + unsigned preDelay; + unsigned aftDelay; + unsigned range; }; typedef std::vector< MonsterAttack *> MonsterAttacks; diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp index d7f301c8..426a2249 100644 --- a/src/game-server/monstermanager.cpp +++ b/src/game-server/monstermanager.cpp @@ -24,7 +24,6 @@ #include "game-server/monstermanager.hpp" #include "defines.h" -#include "game-server/attackzone.hpp" #include "game-server/itemmanager.hpp" #include "game-server/monster.hpp" #include "game-server/resourcemanager.hpp" @@ -222,17 +221,12 @@ void MonsterManager::reload() else if (xmlStrEqual(subnode->name, BAD_CAST "attack")) { MonsterAttack *att = new MonsterAttack; - AttackZone attackZone; att->id = XML::getProperty(subnode, "id", 0); att->priority = XML::getProperty(subnode, "priority", 1); att->damageFactor = XML::getFloatProperty(subnode, "damage-factor", 1.0f); att->preDelay = XML::getProperty(subnode, "pre-delay", 1); att->aftDelay = XML::getProperty(subnode, "aft-delay", 0); - attackZone.multiTarget = true; - attackZone.shape = ATTZONESHAPE_CONE; - attackZone.range = XML::getProperty(subnode, "range", 1); - attackZone.angle = XML::getProperty(subnode, "angle", 1); - att->attackZone = attackZone; + att->range = XML::getProperty(subnode, "range", 0); std::string sElement = XML::getProperty(subnode, "element", "neutral"); att->element = elementFromString(sElement); std::string sType = XML::getProperty(subnode, "type", "physical"); |