summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Sehmisch <crush@themanaworld.org>2009-09-23 20:06:16 +0200
committerPhilipp Sehmisch <crush@themanaworld.org>2009-09-23 20:15:52 +0200
commitb2bbb73f3fab10b238a61bf3aa185d80e6d2070f (patch)
tree91d26f1d93fd81d9378894f63b66ac7409ddb23b
parent5ae62661c90389d6456e5be75d240fb95b68b2cb (diff)
downloadmanaserv-b2bbb73f3fab10b238a61bf3aa185d80e6d2070f.tar.gz
manaserv-b2bbb73f3fab10b238a61bf3aa185d80e6d2070f.tar.bz2
manaserv-b2bbb73f3fab10b238a61bf3aa185d80e6d2070f.tar.xz
manaserv-b2bbb73f3fab10b238a61bf3aa185d80e6d2070f.zip
added script functions for monster attacks
-rw-r--r--src/game-server/being.cpp11
-rw-r--r--src/game-server/being.hpp3
-rw-r--r--src/game-server/monster.cpp14
-rw-r--r--src/game-server/monster.hpp1
-rw-r--r--src/game-server/monstermanager.cpp1
5 files changed, 23 insertions, 7 deletions
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp
index 3993154e..c21d2540 100644
--- a/src/game-server/being.cpp
+++ b/src/game-server/being.cpp
@@ -232,14 +232,14 @@ int Being::directionToAngle(int direction)
}
}
-void Being::performAttack(Being *target, unsigned range, const Damage &damage)
+int Being::performAttack(Being *target, unsigned range, const Damage &damage)
{
// check target legality
if (!target || target == this || target->getAction() == Being::DEAD || !target->canFight())
- return;
+ return -1;
if (getMap()->getPvP() == PVP_NONE && target->getType() == OBJECT_CHARACTER &&
getType() == OBJECT_CHARACTER)
- return;
+ return -1;
// check if target is in range using the pythagorean theorem
int distx = this->getPosition().x - target->getPosition().x;
@@ -247,10 +247,11 @@ void Being::performAttack(Being *target, unsigned range, const Damage &damage)
int distSquare = (distx * distx + disty * disty);
int maxDist = range + target->getSize();
if (maxDist * maxDist < distSquare)
- return;
+ return -1;
- mTarget->damage(this, damage);
mActionTime += 1000; // set to 10 ticks wait time
+
+ return (mTarget->damage(this, damage));
}
void Being::setAction(Action action)
diff --git a/src/game-server/being.hpp b/src/game-server/being.hpp
index c3319523..d78ca78a 100644
--- a/src/game-server/being.hpp
+++ b/src/game-server/being.hpp
@@ -213,8 +213,9 @@ class Being : public Actor
/**
* Performs an attack.
+ * Return Value: damage inflicted or -1 when illegal target
*/
- void performAttack(Being *target, unsigned range, const Damage &damage);
+ int performAttack(Being *target, unsigned range, const Damage &damage);
/**
* Sets the current action.
diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp
index 1cb6806b..68cfa88e 100644
--- a/src/game-server/monster.cpp
+++ b/src/game-server/monster.cpp
@@ -132,7 +132,19 @@ void Monster::perform()
damage.element = mCurrentAttack->element;
damage.type = mCurrentAttack->type;
- performAttack(mTarget, mCurrentAttack->range, damage);
+ int hit = performAttack(mTarget, mCurrentAttack->range, damage);
+
+ if (! mCurrentAttack->scriptFunction.empty()
+ && mScript
+ && hit > -1)
+ {
+ mScript->setMap(getMap());
+ mScript->prepare(mCurrentAttack->scriptFunction);
+ mScript->push(this);
+ mScript->push(mTarget);
+ mScript->push(hit);
+ mScript->execute();
+ }
}
if (!mAttackTime)
{
diff --git a/src/game-server/monster.hpp b/src/game-server/monster.hpp
index d99f77d3..2278e8fd 100644
--- a/src/game-server/monster.hpp
+++ b/src/game-server/monster.hpp
@@ -56,6 +56,7 @@ struct MonsterAttack
unsigned preDelay;
unsigned aftDelay;
unsigned range;
+ std::string scriptFunction;
};
typedef std::vector< MonsterAttack *> MonsterAttacks;
diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp
index 080dcbfc..1f2bfbac 100644
--- a/src/game-server/monstermanager.cpp
+++ b/src/game-server/monstermanager.cpp
@@ -227,6 +227,7 @@ void MonsterManager::reload()
att->preDelay = XML::getProperty(subnode, "pre-delay", 1);
att->aftDelay = XML::getProperty(subnode, "aft-delay", 0);
att->range = XML::getProperty(subnode, "range", 0);
+ att->scriptFunction = XML::getProperty(subnode, "script-function", "");
std::string sElement = XML::getProperty(subnode, "element", "neutral");
att->element = elementFromString(sElement);
std::string sType = XML::getProperty(subnode, "type", "physical");