summaryrefslogtreecommitdiff
path: root/src/game-server/attack.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game-server/attack.cpp')
-rw-r--r--src/game-server/attack.cpp135
1 files changed, 135 insertions, 0 deletions
diff --git a/src/game-server/attack.cpp b/src/game-server/attack.cpp
new file mode 100644
index 00000000..9118b10c
--- /dev/null
+++ b/src/game-server/attack.cpp
@@ -0,0 +1,135 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "attack.h"
+
+#include "common/defines.h"
+
+#include "game-server/character.h"
+#include "game-server/skillmanager.h"
+
+AttackInfo *AttackInfo::readAttackNode(xmlNodePtr node)
+{
+ std::string skill = XML::getProperty(node, "skill", std::string());
+ unsigned skillId;
+ if (utils::isNumeric(skill))
+ {
+ skillId = utils::stringToInt(skill);
+ }
+ else
+ {
+ skillId = skillManager->getId(skill);
+ if (skillId == 0)
+ {
+ LOG_WARN("Error parsing Attack node: Invalid skill " << skill
+ << " taking default skill");
+ skillId = skillManager->getDefaultSkillId();
+ }
+ }
+ unsigned id = XML::getProperty(node, "id", 0);
+ unsigned priority = XML::getProperty(node, "priority", 0);
+ unsigned warmupTime = XML::getProperty(node, "warmuptime", 0);
+ unsigned cooldownTime = XML::getProperty(node, "cooldowntime", 0);
+ unsigned reuseTime = XML::getProperty(node, "reusetime", 0);
+ unsigned short baseDamange = XML::getProperty(node, "basedamage", 0);
+ unsigned short deltaDamage = XML::getProperty(node, "deltadamage", 0);
+ unsigned short chanceToHit = XML::getProperty(node, "chancetohit", 0);
+ unsigned short range = XML::getProperty(node, "range", 0);
+ Element element = elementFromString(
+ XML::getProperty(node, "element", "neutral"));
+ DamageType type = damageTypeFromString(
+ XML::getProperty(node, "type", "other"));
+
+ Damage dmg;
+ dmg.id = id;
+ dmg.base = baseDamange;
+ dmg.delta = deltaDamage;
+ dmg.cth = chanceToHit;
+ dmg.range = range;
+ dmg.element = element;
+ dmg.type = type;
+ AttackInfo *attack = new AttackInfo(priority, dmg, warmupTime, cooldownTime,
+ reuseTime);
+ return attack;
+}
+
+void Attacks::add(AttackInfo *attackInfo)
+{
+ mAttacks.push_back(Attack(attackInfo));
+}
+
+void Attacks::remove(AttackInfo *attackInfo)
+{
+ for (std::vector<Attack>::iterator it = mAttacks.begin(),
+ it_end = mAttacks.end(); it != it_end; ++it)
+ {
+ if ((*it).getAttackInfo() == attackInfo)
+ {
+ if (mCurrentAttack && mCurrentAttack->getAttackInfo() == attackInfo)
+ mCurrentAttack = 0;
+ mAttacks.erase(it);
+ return;
+ }
+ }
+}
+
+void Attacks::markAttackAsTriggered()
+{
+ mCurrentAttack->markAsTriggered();
+ mCurrentAttack = 0;
+}
+
+Attack *Attacks::getTriggerableAttack()
+{
+ if (!mCurrentAttack)
+ return 0;
+
+ int cooldownTime = mCurrentAttack->getAttackInfo()->getCooldownTime();
+ if (mAttackTimer.remaining() <= cooldownTime)
+ {
+ return mCurrentAttack;
+ }
+
+ return 0;
+}
+
+void Attacks::startAttack(Attack *attack)
+{
+ mCurrentAttack = attack;
+ mAttackTimer.set(attack->getAttackInfo()->getWarmupTime() +
+ attack->getAttackInfo()->getCooldownTime());
+}
+
+void Attacks::tick(std::vector<Attack *> *ret)
+{
+ // we have a current Attack
+ if (!mAttackTimer.expired() && mCurrentAttack)
+ return;
+ for (std::vector<Attack>::iterator it = mAttacks.begin();
+ it != mAttacks.end(); ++it)
+ {
+ Attack &attack = *it;
+
+ if (ret && attack.isUsuable())
+ {
+ ret->push_back(&attack);
+ }
+ }
+}