diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-04-27 21:09:23 +0200 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-08-26 22:56:46 +0200 |
commit | f31277b327df701361391b1d4b8bd6f89f4e3109 (patch) | |
tree | 0fd2b85c13cb11654ff6cd027e0be7ff6b61c2d6 | |
parent | 960d40d819afb65387469591bdb02e6819d72294 (diff) | |
download | manaserv-f31277b327df701361391b1d4b8bd6f89f4e3109.tar.gz manaserv-f31277b327df701361391b1d4b8bd6f89f4e3109.tar.bz2 manaserv-f31277b327df701361391b1d4b8bd6f89f4e3109.tar.xz manaserv-f31277b327df701361391b1d4b8bd6f89f4e3109.zip |
[Abilities] Removed the old autoattack system
As a side effect i had to remove the monster attack AI for now. I will
readd this as next thing.
30 files changed, 15 insertions, 2013 deletions
diff --git a/example/items.xml b/example/items.xml index 9d862a93..5d2db93d 100644 --- a/example/items.xml +++ b/example/items.xml @@ -117,12 +117,6 @@ </equip> <effect trigger="equip"> <modifier attribute="acc1" value="1.0" /> - <attack skill="102" warmuptime="1" cooldowntime="5" reusetime="1" - basedamage="1" deltadamage="10" chancetohit="200" range="320" - element="fire" type="physical" /> - <attack skill="102" priority="2" warmuptime="100" cooldowntime="10" reusetime="100" - basedamage="50" deltadamage="10" chancetohit="200" range="320" - element="neutral" type="physical" /> </effect> <effect trigger="in-inventory"> <modifier attribute="vit" value="100" /> @@ -137,9 +131,6 @@ <slot type="hand" required="2" /> </equip> <effect trigger="equip"> - <attack skill="106" warmuptime="10" cooldowntime="166" - basedamage="50" deltadamage="10" chancetohit="2" range="160" - element="neutral" type="physical" /> <modifier attribute="acc1" value="1.5" /> </effect> <effect trigger="in-inventory"> @@ -155,9 +146,6 @@ <slot type="hand" required="1" /> </equip> <effect trigger="equip"> - <attack skill="100" warmuptime="10" cooldowntime="10" reusetime="20" - basedamage="50" deltadamage="10" chancetohit="2" range="32" - element="neutral" type="physical" /> <modifier attribute="acc1" value="1.5" /> </effect> <effect trigger="in-inventory"> diff --git a/example/monsters.xml b/example/monsters.xml index 75438c8a..f577c69f 100644 --- a/example/monsters.xml +++ b/example/monsters.xml @@ -63,32 +63,6 @@ exp<TAG>: Tells how much experience point a monster is giving up stroll-range="32" attack-distance="32" /> - <attack id="1" - priority="1" - type="physical" - warmuptime="10" - cooldowntime="10" - reusetime="10" - basedamage="10" - deltadamage="1" - chancetohit="1000" - element="neutral" - range="32" - animation="attack" - /> - <attack id="2" - priority="2" - type="physical" - warmuptime="0" - cooldowntime="100" - reusetime="100" - basedamage="100" - deltadamage="1" - chancetohit="1000" - element="neutral" - range="32" - animation="attack" - /> </monster> <monster id="2" name="Scorpion"> @@ -121,34 +95,6 @@ exp<TAG>: Tells how much experience point a monster is giving up stroll-range="64" attack-distance="64" /> - <!-- slow, strong, long-range tail attack--> - <attack id="1" - priority="1" - type="physical" - warmuptime="10" - cooldowntime="100" - reusetime="100" - basedamage="20" - deltadamage="1" - chancetohit="1000" - element="neutral" - range="32" - animation="attack" - /> - <!-- fast, weak, short-range scissor attack --> - <attack id="2" - priority="2" - type="physical" - warmuptime="0" - cooldowntime="5" - reusetime="1" - basedamage="5" - deltadamage="1" - chancetohit="1000" - element="neutral" - range="32" - animation="attack" - /> </monster> <monster id="3" name="Red Scorpion"> @@ -184,19 +130,6 @@ exp<TAG>: Tells how much experience point a monster is giving up stroll-range="32" attack-distance="64" /> - <attack id="1" - priority="1" - type="physical" - warmuptime="0" - cooldowntime="100" - reusetime="100" - basedamage="100" - deltadamage="1" - chancetohit="1000" - element="neutral" - range="32" - animation="attack" - /> </monster> <monster id="4" name="Green Slime"> @@ -220,19 +153,6 @@ exp<TAG>: Tells how much experience point a monster is giving up physical-defence="0" magical-defence="0" /> - <attack id="1" - priority="1" - type="physical" - warmuptime="0" - cooldowntime="100" - reusetime="100" - basedamage="100" - deltadamage="1" - chancetohit="1000" - element="neutral" - range="32" - animation="attack" - /> <!-- Is fulfilling some unknown purpose that requires it to move around a lot and leaves no time for pursing attackers --> <behavior diff --git a/example/scripts/maps/desert.lua b/example/scripts/maps/desert.lua index 5f7f2d28..343ee6c4 100644 --- a/example/scripts/maps/desert.lua +++ b/example/scripts/maps/desert.lua @@ -130,13 +130,11 @@ function Tamer(npc, ch, list) end local m1 = monster_create("Maggot", ch:position()) - m1:change_anger(ch, 100) -- (The following is not safe, since the being might have been removed by -- the time this function gets executed (especially with the above code)) -- --schedule_in(0.5, function() -- m1:say("Roaaarrrr!!!") - -- m1:change_anger(ch, 100) -- end) end diff --git a/example/scripts/monster/testmonster.lua b/example/scripts/monster/testmonster.lua index 21b6a7b2..42cf1d2d 100644 --- a/example/scripts/monster/testmonster.lua +++ b/example/scripts/monster/testmonster.lua @@ -14,19 +14,5 @@ local function update(mob) end end -local function strike(mob, victim, hit) - if hit > 0 then - mob:say("Take this! "..hit.." damage!") - victim:say("Oh Noez!") - else - mob:say("Oh no, my attack missed!") - victim:say("Whew...") - end -end - local maggot = get_monster_class("maggot") maggot:on_update(update) -local attacks = maggot:attacks(); -for i, attack in ipairs(attacks) do - attack:on_attack(strike) -end diff --git a/gameserver.cbp b/gameserver.cbp index 7c6534a2..90bed40f 100644 --- a/gameserver.cbp +++ b/gameserver.cbp @@ -121,8 +121,6 @@ <Unit filename="src/game-server/accountconnection.h" /> <Unit filename="src/game-server/actor.cpp" /> <Unit filename="src/game-server/actor.h" /> - <Unit filename="src/game-server/attack.cpp" /> - <Unit filename="src/game-server/attack.h" /> <Unit filename="src/game-server/attribute.cpp" /> <Unit filename="src/game-server/attribute.h" /> <Unit filename="src/game-server/attributemanager.cpp" /> @@ -135,8 +133,6 @@ <Unit filename="src/game-server/character.h" /> <Unit filename="src/game-server/collisiondetection.cpp" /> <Unit filename="src/game-server/collisiondetection.h" /> - <Unit filename="src/game-server/combatcomponent.cpp" /> - <Unit filename="src/game-server/combatcomponent.h" /> <Unit filename="src/game-server/commandhandler.cpp" /> <Unit filename="src/game-server/commandhandler.h" /> <Unit filename="src/game-server/effect.cpp" /> @@ -165,8 +161,6 @@ <Unit filename="src/game-server/mapreader.h" /> <Unit filename="src/game-server/monster.cpp" /> <Unit filename="src/game-server/monster.h" /> - <Unit filename="src/game-server/monstercombatcomponent.cpp" /> - <Unit filename="src/game-server/monstercombatcomponent.h" /> <Unit filename="src/game-server/monstermanager.cpp" /> <Unit filename="src/game-server/monstermanager.h" /> <Unit filename="src/game-server/npc.cpp" /> diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2a665774..4eac8517 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -211,8 +211,6 @@ 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 @@ -225,8 +223,6 @@ SET(SRCS_MANASERVGAME game-server/character.cpp game-server/collisiondetection.h game-server/collisiondetection.cpp - game-server/combatcomponent.h - game-server/combatcomponent.cpp game-server/commandhandler.cpp game-server/commandhandler.h game-server/component.h @@ -254,8 +250,6 @@ SET(SRCS_MANASERVGAME game-server/mapreader.cpp game-server/monster.h game-server/monster.cpp - game-server/monstercombatcomponent.h - game-server/monstercombatcomponent.cpp game-server/monstermanager.h game-server/monstermanager.cpp game-server/npc.h diff --git a/src/common/manaserv_protocol.h b/src/common/manaserv_protocol.h index 73837b10..4e584137 100644 --- a/src/common/manaserv_protocol.h +++ b/src/common/manaserv_protocol.h @@ -145,8 +145,6 @@ enum { GPMSG_ITEMS = 0x0281, // { W item id, W*2 position }* GPMSG_BEING_ABILITY_POINT = 0x0282, // W being id, B abilityId, W*2 point GPMSG_BEING_ABILITY_BEING = 0x0283, // W being id, B abilityId, W target being id - PGMSG_ATTACK = 0x0290, // W being id - GPMSG_BEING_ATTACK = 0x0291, // W being id, B direction, B attack Id PGMSG_USE_ABILITY_ON_BEING = 0x0292, // B abilityID, W being id GPMSG_ABILITY_STATUS = 0x0293, // { B abilityID, D current, D max, D recharge } PGMSG_USE_ABILITY_ON_POINT = 0x0294, // B abilityID, W*2 position @@ -425,27 +423,12 @@ enum BeingAction { STAND, WALK, - ATTACK, SIT, DEAD, HURT }; /** - * Moves enum for beings and actors for others players attack types. - * WARNING: Has to be in sync with the same enum in the Being class - * of the client! - */ -enum AttackType -{ - HIT = 0x00, - CRITICAL = 0x0a, - MULTI = 0x08, - REFLECT = 0x04, - FLEE = 0x0b -}; - -/** * Beings and actors directions * WARNING: Has to be in sync with the same enum in the Being class * of the client! diff --git a/src/game-server/actor.h b/src/game-server/actor.h index d1201aa7..80f6bbb0 100644 --- a/src/game-server/actor.h +++ b/src/game-server/actor.h @@ -33,14 +33,13 @@ enum { UPDATEFLAG_NEW_ON_MAP = 1, UPDATEFLAG_NEW_DESTINATION = 2, - UPDATEFLAG_ATTACK = 4, - UPDATEFLAG_ACTIONCHANGE = 8, - UPDATEFLAG_LOOKSCHANGE = 16, - UPDATEFLAG_DIRCHANGE = 32, - UPDATEFLAG_HEALTHCHANGE = 64, - UPDATEFLAG_EMOTE = 128, - UPDATEFLAG_ABILITY_ON_POINT = 256, - UPDATEFLAG_ABILITY_ON_BEING = 512 + UPDATEFLAG_ACTIONCHANGE = 4, + UPDATEFLAG_LOOKSCHANGE = 8, + UPDATEFLAG_DIRCHANGE = 16, + UPDATEFLAG_HEALTHCHANGE = 32, + UPDATEFLAG_EMOTE = 64, + UPDATEFLAG_ABILITY_ON_POINT = 128, + UPDATEFLAG_ABILITY_ON_BEING = 256 }; /** diff --git a/src/game-server/attack.cpp b/src/game-server/attack.cpp deleted file mode 100644 index 6ca85fb8..00000000 --- a/src/game-server/attack.cpp +++ /dev/null @@ -1,141 +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 <http://www.gnu.org/licenses/>. - */ - -#include "attack.h" - -#include <cassert> - -#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 (!skill.empty() && !skillManager->exists(skillId)) - { - 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.skill = skillId; - 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(CombatComponent *combatComponent, AttackInfo *attackInfo) -{ - mAttacks.push_back(Attack(attackInfo)); - attack_added.emit(combatComponent, *mAttacks.rbegin()); -} - -void Attacks::remove(CombatComponent *combatComponent, 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; - attack_removed.emit(combatComponent, *it); - 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::getUsuableAttacks(std::vector<Attack *> *ret) -{ - assert(ret != 0); - - // 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 (attack.isUsuable()) - { - ret->push_back(&attack); - } - } -} diff --git a/src/game-server/attack.h b/src/game-server/attack.h deleted file mode 100644 index 8dc62629..00000000 --- a/src/game-server/attack.h +++ /dev/null @@ -1,213 +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 <http://www.gnu.org/licenses/>. - */ - -#ifndef ATTACK_H -#define ATTACK_H - -#include <cassert> -#include <cstddef> -#include <list> - -#include <sigc++/signal.h> -#include <sigc++/trackable.h> - -#include "common/defines.h" - -#include "scripting/script.h" - -#include "utils/xml.h" - -#include "game-server/timeout.h" - -class CombatComponent; - -/** - * Structure that describes the severity and nature of an attack a being can - * be hit by. - */ -struct Damage -{ - unsigned id; /**< Id of the attack (needed for displaying animation clientside */ - unsigned 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. */ - Element 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(): - id(0), - 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 CharacterComponent; - -struct AttackInfo -{ - public: - AttackInfo(unsigned priority, const Damage &damage, - unsigned short warmupTime, unsigned short cooldownTime, - unsigned short reuseTime): - mDamage(damage), - mCooldownTime(cooldownTime), - mWarmupTime(warmupTime), - mReuseTime(reuseTime), - mPriority(priority) - {} - - unsigned short getWarmupTime() const - { return mWarmupTime; } - - unsigned short getCooldownTime() const - { return mCooldownTime; } - - unsigned short getReuseTime() const - { return mReuseTime; } - - static AttackInfo *readAttackNode(xmlNodePtr node); - - Damage &getDamage() - { return mDamage; } - - const Script::Ref &getScriptCallback() const - { return mCallback; } - - void setCallback(Script *script) - { script->assignCallback(mCallback); } - - unsigned getPriority() const - { return mPriority; } - - private: - Damage mDamage; - - /** - * Value to reset the timer to (warmup + cooldown) - */ - unsigned short mCooldownTime; - - /** - * 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 mWarmupTime; - - /** - * The global cooldown that needs to be finished before the being can - * use the next attack. - */ - unsigned short mReuseTime; - - /** - * Name of the script callback - */ - Script::Ref mCallback; - - /** - * Priority of the attack - */ - unsigned mPriority; -}; - -class Attack -{ - public: - Attack(AttackInfo *info): - mInfo(info) - {assert(info);} - - AttackInfo *getAttackInfo() - { return mInfo; } - - void markAsTriggered() - { mReuseTimer.set(mInfo->getCooldownTime() + mInfo->getReuseTime()); } - - bool isUsuable() const - { return mReuseTimer.expired(); } - - - private: - /** - * Contains infos about cooldown/damage/etc - */ - AttackInfo *mInfo; - - /** - * Internal timer that checks time for reuse - */ - Timeout mReuseTimer; -}; - -/** - * Helper class for storing multiple auto-attacks. - */ -class Attacks : public sigc::trackable -{ - public: - Attacks(): - mCurrentAttack(0) - {} - - void add(CombatComponent *combatComponent, AttackInfo *); - void remove(CombatComponent *combatComponent, AttackInfo *); - void markAttackAsTriggered(); - Attack *getTriggerableAttack(); - void startAttack(Attack *attack); - void getUsuableAttacks(std::vector<Attack *> *ret); - - /** - * Tells the number of attacks available - */ - unsigned getNumber() - { return mAttacks.size(); } - - sigc::signal<void, CombatComponent *, Attack &> attack_added; - sigc::signal<void, CombatComponent *, Attack &> attack_removed; - - private: - std::vector<Attack> mAttacks; - - Attack *mCurrentAttack; - - /** - * when greater than cooldown -> warming up - * when equals cooldown -> trigger attack - * when smaller -> cooling down - */ - Timeout mAttackTimer; -}; - -#endif // ATTACK_H diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp index f3d45305..22ce30d4 100644 --- a/src/game-server/being.cpp +++ b/src/game-server/being.cpp @@ -27,7 +27,6 @@ #include "game-server/attributemanager.h" #include "game-server/character.h" #include "game-server/collisiondetection.h" -#include "game-server/combatcomponent.h" #include "game-server/mapcomposite.h" #include "game-server/effect.h" #include "game-server/skillmanager.h" @@ -310,8 +309,8 @@ int BeingComponent::directionToAngle(int direction) void BeingComponent::setAction(Entity &entity, BeingAction action) { mAction = action; - if (action != ATTACK && // The players are informed about these actions - action != WALK) // by other messages + // The players are informed about these actions by other messages + if (action != WALK) { entity.getComponent<ActorComponent>()->raiseUpdateFlags( UPDATEFLAG_ACTIONCHANGE); diff --git a/src/game-server/being.h b/src/game-server/being.h index 5827ad17..aeb5697b 100644 --- a/src/game-server/being.h +++ b/src/game-server/being.h @@ -29,9 +29,10 @@ #include "game-server/actor.h" #include "game-server/attribute.h" -#include "game-server/attack.h" #include "game-server/timeout.h" +#include "scripting/script.h" + class BeingComponent; class MapComposite; class StatusEffect; diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index 3d23e3a8..8831e501 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -22,10 +22,8 @@ #include "common/configuration.h" #include "game-server/accountconnection.h" -#include "game-server/attack.h" #include "game-server/attributemanager.h" #include "game-server/buysell.h" -#include "game-server/combatcomponent.h" #include "game-server/inventory.h" #include "game-server/item.h" #include "game-server/itemmanager.h" @@ -87,7 +85,6 @@ CharacterComponent::CharacterComponent(Entity &entity, MessageIn &msg): mTransaction(TRANS_NONE), mTalkNpcId(0), mNpcThread(0), - mKnuckleAttackInfo(0), mBaseEntity(&entity) { auto *beingComponent = entity.getComponent<BeingComponent>(); @@ -106,29 +103,6 @@ CharacterComponent::CharacterComponent(Entity &entity, MessageIn &msg): actorComponent->setSize(16); - CombatComponent *combatcomponent = new CombatComponent(entity); - entity.addComponent(combatcomponent); - combatcomponent->getAttacks().attack_added.connect( - sigc::mem_fun(this, &CharacterComponent::attackAdded)); - combatcomponent->getAttacks().attack_removed.connect( - sigc::mem_fun(this, &CharacterComponent::attackRemoved)); - - // Default knuckle attack - int damageBase = beingComponent->getModifiedAttribute(ATTR_STR); - int damageDelta = damageBase / 2; - Damage knuckleDamage; - knuckleDamage.skill = skillManager->getDefaultSkillId(); - knuckleDamage.base = damageBase; - knuckleDamage.delta = damageDelta; - knuckleDamage.cth = 2; - knuckleDamage.element = ELEMENT_NEUTRAL; - knuckleDamage.type = DAMAGE_PHYSICAL; - knuckleDamage.range = DEFAULT_TILE_LENGTH; - - mKnuckleAttackInfo = new AttackInfo(0, knuckleDamage, 7, 3, 0); - combatcomponent->addAttack(mKnuckleAttackInfo); - - auto *abilityComponent = new AbilityComponent(entity); entity.addComponent(abilityComponent); abilityComponent->signal_ability_changed.connect( @@ -157,7 +131,6 @@ CharacterComponent::CharacterComponent(Entity &entity, MessageIn &msg): CharacterComponent::~CharacterComponent() { delete mNpcThread; - delete mKnuckleAttackInfo; } void CharacterComponent::update(Entity &entity) @@ -198,8 +171,6 @@ void CharacterComponent::respawn(Entity &entity) // Make it alive again beingComponent->setAction(entity, STAND); - // Reset target - entity.getComponent<CombatComponent>()->clearTarget(); // Execute respawn callback when set if (executeCallback(mDeathAcceptedCallback, entity)) @@ -379,15 +350,6 @@ void CharacterComponent::attributeChanged(Entity *entity, unsigned attr) beingComponent->getAttributeBase(attr), beingComponent->getModifiedAttribute(attr)); mModifiedAttributes.insert(attr); - - // Update the knuckle Attack if required - if (attr == ATTR_STR && mKnuckleAttackInfo) - { - // TODO: dehardcode this - Damage &knuckleDamage = mKnuckleAttackInfo->getDamage(); - knuckleDamage.base = beingComponent->getModifiedAttribute(ATTR_STR); - knuckleDamage.delta = knuckleDamage.base / 2; - } } int CharacterComponent::expForLevel(int level) @@ -602,23 +564,6 @@ void CharacterComponent::resumeNpcThread() } } -void CharacterComponent::attackAdded(CombatComponent *combatComponent, - Attack &attack) -{ - // Remove knuckle attack - if (attack.getAttackInfo() != mKnuckleAttackInfo) - combatComponent->removeAttack(mKnuckleAttackInfo); -} - -void CharacterComponent::attackRemoved(CombatComponent *combatComponent, - Attack &attack) -{ - // Add knuckle attack - // 1 since the attack is not really removed yet. - if (combatComponent->getAttacks().getNumber() == 1) - combatComponent->addAttack(mKnuckleAttackInfo); -} - void CharacterComponent::disconnected(Entity &entity) { mConnected = false; diff --git a/src/game-server/character.h b/src/game-server/character.h index 78d27ec1..6f090aa6 100644 --- a/src/game-server/character.h +++ b/src/game-server/character.h @@ -131,8 +131,6 @@ class CharacterComponent : public Component */ void update(Entity &entity); - void processAttacks(); - /** * Executes the global die script */ @@ -386,9 +384,6 @@ class CharacterComponent : public Component void triggerLoginCallback(Entity &entity); - void attackAdded(CombatComponent *combatComponent, Attack &attackInfo); - void attackRemoved(CombatComponent *combatComponent, Attack &attackInfo); - sigc::signal<void, Entity &> signal_disconnected; private: @@ -482,8 +477,6 @@ class CharacterComponent : public Component Timeout mMuteTimeout; /**< Time until the character is no longer muted */ - AttackInfo *mKnuckleAttackInfo; - Entity *mBaseEntity; /**< The entity this component is part of this is ONLY required to allow using the serialization routine without many diff --git a/src/game-server/combatcomponent.cpp b/src/game-server/combatcomponent.cpp deleted file mode 100644 index 65eddc46..00000000 --- a/src/game-server/combatcomponent.cpp +++ /dev/null @@ -1,226 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2013 The Mana Developers - * - * 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 "combatcomponent.h" - -#include "game-server/being.h" -#include "game-server/mapcomposite.h" - -#include "utils/logger.h" - -CombatComponent::CombatComponent(Entity &being): - mTarget(nullptr), - mCurrentAttack(nullptr) -{ - being.getComponent<BeingComponent>()->signal_died.connect(sigc::mem_fun( - this, &CombatComponent::diedOrRemoved)); - being.signal_removed.connect(sigc::mem_fun(this, - &CombatComponent::diedOrRemoved)); -} - -CombatComponent::~CombatComponent() -{ -} - -void CombatComponent::update(Entity &entity) -{ - auto *beingComponent = entity.getComponent<BeingComponent>(); - - if (beingComponent->getAction() != ATTACK || !mTarget) - return; - - std::vector<Attack *> attacksReady; - mAttacks.getUsuableAttacks(&attacksReady); - - if (Attack *triggerableAttack = mAttacks.getTriggerableAttack()) - { - processAttack(entity, *triggerableAttack); - mAttacks.markAttackAsTriggered(); - } - - // Deal with the ATTACK action. - if (attacksReady.empty()) - return; - - Attack *highestPriorityAttack = 0; - // Performs all ready attacks. - for (std::vector<Attack *>::const_iterator it = attacksReady.begin(), - it_end = attacksReady.end(); it != it_end; ++it) - { - const Point &attackerPosition = - entity.getComponent<ActorComponent>()->getPosition(); - const Point &targetPosition = - mTarget->getComponent<ActorComponent>()->getPosition(); - - // check if target is in range using the pythagorean theorem - int distx = attackerPosition.x - targetPosition.x; - int disty = attackerPosition.y - targetPosition.y; - int distSquare = (distx * distx + disty * disty); - AttackInfo *info = (*it)->getAttackInfo(); - int maxDist = info->getDamage().range + - entity.getComponent<ActorComponent>()->getSize(); - - if (distSquare <= maxDist * maxDist && - (!highestPriorityAttack || - highestPriorityAttack->getAttackInfo()->getPriority() - < info->getPriority())) - { - highestPriorityAttack = *it; - } - } - if (highestPriorityAttack) - { - mAttacks.startAttack(highestPriorityAttack); - mCurrentAttack = highestPriorityAttack; - const Point &point = - entity.getComponent<ActorComponent>()->getPosition(); - beingComponent->setDestination(entity, point); - // TODO: Turn into direction of enemy - entity.getComponent<ActorComponent>()->raiseUpdateFlags( - UPDATEFLAG_ATTACK); - } -} - -/** - * Takes a damage structure, computes the real damage based on the - * stats, deducts the result from the hitpoints and adds the result to - * the HitsTaken list. - */ -int CombatComponent::damage(Entity &target, - Entity *source, - const Damage &damage) -{ - auto *beingComponent = target.getComponent<BeingComponent>(); - - int HPloss = damage.base; - if (damage.delta) - HPloss += rand() * (damage.delta + 1) / RAND_MAX; - - // TODO magical attacks and associated elemental modifiers - switch (damage.type) - { - case DAMAGE_PHYSICAL: - { - const double dodge = - beingComponent->getModifiedAttribute(ATTR_DODGE); - if (!damage.trueStrike && rand()%((int)dodge + 1) > - rand()%(damage.cth + 1)) - { - HPloss = 0; - // TODO Process triggers for a dodged physical attack here. - // If there is an attacker included, also process triggers for the attacker (failed physical strike) - } - else - { - const double defense = - beingComponent->getModifiedAttribute(ATTR_DEFENSE); - HPloss = HPloss * (1.0 - (0.0159375f * defense) / - (1.0 + 0.017 * defense)) + - (rand()%((HPloss / 16) + 1)); - // TODO Process triggers for receiving damage here. - // If there is an attacker included, also process triggers for the attacker (successful physical strike) - } - break; - } - case DAMAGE_MAGICAL: -#if 0 - beingComponent.getModifiedAttribute(BASE_ELEM_BEGIN + damage.element); -#else - LOG_WARN("Attempt to use magical type damage! This has not been" - "implemented yet and should not be used!"); - HPloss = 0; -#endif - break; - case DAMAGE_DIRECT: - break; - default: - LOG_WARN("Unknown damage type '" << damage.type << "'!"); - break; - } - - if (HPloss > 0) - { - const Attribute *HP = beingComponent->getAttribute(ATTR_HP); - LOG_DEBUG("Being " - << target.getComponent<ActorComponent>()->getPublicID() - << " suffered " << HPloss - << " damage. HP: " - << HP->getModifiedAttribute() << "/" - << beingComponent->getModifiedAttribute(ATTR_MAX_HP)); - beingComponent->setAttribute(target, ATTR_HP, HP->getBase() - HPloss); - // No HP regen after being hit if this is set. - // TODO: Reenable this once the attributes are available as a component - // A bit too fuzzy to implement at the moment - //mHealthRegenerationTimeout.setSoft( - // Configuration::getValue("game_hpRegenBreakAfterHit", 0)); - } - else - { - HPloss = 0; - } - - signal_damaged.emit(source, damage, HPloss); - return HPloss; -} - -/** - * Performs an attack - */ -void CombatComponent::processAttack(Entity &source, Attack &attack) -{ - performAttack(source, attack.getAttackInfo()->getDamage()); -} - -/** - * Adds an attack to the available attacks - */ -void CombatComponent::addAttack(AttackInfo *attackInfo) -{ - mAttacks.add(this, attackInfo); -} - -/** - * Removes an attack from the available attacks - */ -void CombatComponent::removeAttack(AttackInfo *attackInfo) -{ - mAttacks.remove(this, attackInfo); -} - -/** - * Performs an attack. - */ -int CombatComponent::performAttack(Entity &source, const Damage &dmg) -{ - // check target legality - if (!mTarget - || mTarget == &source - || mTarget->getComponent<BeingComponent>()->getAction() == DEAD - || !mTarget->canFight()) - return -1; - - if (source.getMap()->getPvP() == PVP_NONE - && mTarget->getType() == OBJECT_CHARACTER - && source.getType() == OBJECT_CHARACTER) - return -1; - - return mTarget->getComponent<CombatComponent>()->damage(*mTarget, - &source, dmg); -} diff --git a/src/game-server/combatcomponent.h b/src/game-server/combatcomponent.h deleted file mode 100644 index 1a4f3102..00000000 --- a/src/game-server/combatcomponent.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2013 The Mana Developers - * - * 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/>. - */ - -#ifndef COMBATCOMPONENT_H -#define COMBATCOMPONENT_H - -#include "component.h" - -#include <vector> - -#include <sigc++/trackable.h> - -#include "game-server/attack.h" - -class Entity; - -class CombatComponent: public Component -{ -public: - static const ComponentType type = CT_Fighting; - - CombatComponent(Entity &being); - virtual ~CombatComponent(); - - void update(Entity &entity); - - void addAttack(AttackInfo *attack); - void removeAttack(AttackInfo *attackInfo); - Attacks &getAttacks(); - - int performAttack(Entity &source, const Damage &dmg); - virtual int damage(Entity &target, Entity *source, const Damage &damage); - - int getAttackId() const; - - Entity *getTarget() const; - void setTarget(Entity *target); - void clearTarget(); - - void diedOrRemoved(Entity *entity); - - sigc::signal<void, Entity *, const Damage &, int> signal_damaged; - -protected: - virtual void processAttack(Entity &source, Attack &attack); - - Entity *mTarget; - Attacks mAttacks; - Attack *mCurrentAttack; // Last used attack - -}; - -inline Attacks &CombatComponent::getAttacks() -{ - return mAttacks; -} - -/** - * Gets the attack id the being is currently performing. - * For being, this is defaulted to the first one (1). - */ -inline int CombatComponent::getAttackId() const -{ - return mCurrentAttack ? - mCurrentAttack->getAttackInfo()->getDamage().id : 0; -} - -/** - * Get Target - */ -inline Entity *CombatComponent::getTarget() const -{ - return mTarget; -} - -/** - * Set Target - */ -inline void CombatComponent::setTarget(Entity *target) -{ - mTarget = target; -} - -/** - * Clears the target - */ -inline void CombatComponent::clearTarget() -{ - mTarget = nullptr; -} - -/** - * Handler for the died and removed event of the targeting being - * @param entity The removed/died being (not used here) - */ -inline void CombatComponent::diedOrRemoved(Entity *entity) -{ - clearTarget(); -} - -#endif // COMBATCOMPONENT_H diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp index b1a87a24..e9890c66 100644 --- a/src/game-server/gamehandler.cpp +++ b/src/game-server/gamehandler.cpp @@ -27,7 +27,6 @@ #include "common/transaction.h" #include "game-server/accountconnection.h" #include "game-server/buysell.h" -#include "game-server/combatcomponent.h" #include "game-server/commandhandler.h" #include "game-server/emotemanager.h" #include "game-server/inventory.h" @@ -254,10 +253,6 @@ void GameHandler::processMessage(NetComputer *computer, MessageIn &message) handleMoveItem(client, message); break; - case PGMSG_ATTACK: - handleAttack(client, message); - break; - case PGMSG_USE_ABILITY_ON_BEING: handleUseAbilityOnBeing(client, message); break; @@ -671,22 +666,6 @@ void GameHandler::handleMoveItem(GameClient &client, MessageIn &message) TRANS_ITEM_MOVE, str.str()); } -void GameHandler::handleAttack(GameClient &client, MessageIn &message) -{ - int id = message.readInt16(); - const int publicId = - client.character->getComponent<ActorComponent>()->getPublicID(); - LOG_DEBUG("Character " << publicId << " attacked being " << id); - - Entity *being = findBeingNear(client.character, id); - if (being && being->getType() != OBJECT_NPC) - { - client.character->getComponent<CombatComponent>()->setTarget(being); - client.character->getComponent<BeingComponent>()->setAction( - *client.character, ATTACK); - } -} - void GameHandler::handleUseAbilityOnBeing(GameClient &client, MessageIn &message) { if (client.character->getComponent<BeingComponent>()->getAction() == DEAD) @@ -719,7 +698,7 @@ void GameHandler::handleUseAbilityOnPoint(GameClient &client, MessageIn &message const int publicId = client.character->getComponent<ActorComponent>()->getPublicID(); LOG_DEBUG("Character " << publicId - << " tries to use his ability attack " << abilityID); + << " tries to use his ability " << abilityID); auto *abilityComponent = client.character ->getComponent<AbilityComponent>(); abilityComponent->useAbilityOnPoint(*client.character, abilityID, x, y); diff --git a/src/game-server/gamehandler.h b/src/game-server/gamehandler.h index 0abc287c..2f44a3c9 100644 --- a/src/game-server/gamehandler.h +++ b/src/game-server/gamehandler.h @@ -134,7 +134,6 @@ class GameHandler: public ConnectionHandler void handleUnequip(GameClient &client, MessageIn &message); void handleMoveItem(GameClient &client, MessageIn &message); - void handleAttack(GameClient &client, MessageIn &message); void handleUseAbilityOnBeing(GameClient &client, MessageIn &message); void handleUseAbilityOnPoint(GameClient &client, MessageIn &message); void handleActionChange(GameClient &client, MessageIn &message); diff --git a/src/game-server/item.cpp b/src/game-server/item.cpp index 444576f2..589fc011 100644 --- a/src/game-server/item.cpp +++ b/src/game-server/item.cpp @@ -22,10 +22,8 @@ #include "game-server/item.h" #include "common/configuration.h" -#include "game-server/attack.h" #include "game-server/attributemanager.h" #include "game-server/being.h" -#include "game-server/combatcomponent.h" #include "game-server/state.h" #include "scripting/script.h" #include "scripting/scriptmanager.h" @@ -53,17 +51,6 @@ void ItemEffectAttrMod::dispell(Entity *itemUser) mId, !mDuration); } -bool ItemEffectAttack::apply(Entity *itemUser) -{ - itemUser->getComponent<CombatComponent>()->addAttack(mAttackInfo); - return false; -} - -void ItemEffectAttack::dispell(Entity *itemUser) -{ - itemUser->getComponent<CombatComponent>()->removeAttack(mAttackInfo); -} - ItemEffectScript::~ItemEffectScript() { } @@ -110,13 +97,6 @@ ItemClass::~ItemClass() delete mEffects.begin()->second; mEffects.erase(mEffects.begin()); } - - for (std::vector<AttackInfo *>::iterator it = mAttackInfos.begin(), - it_end = mAttackInfos.end(); - it != it_end; ++it) - { - delete *it; - } } void ItemClass::addEffect(ItemEffectInfo *effect, @@ -148,14 +128,6 @@ bool ItemClass::useTrigger(Entity *itemUser, ItemTriggerType trigger) return ret; } -void ItemClass::addAttack(AttackInfo *attackInfo, - ItemTriggerType applyTrigger, - ItemTriggerType dispellTrigger) -{ - mAttackInfos.push_back(attackInfo); - addEffect(new ItemEffectAttack(attackInfo), applyTrigger, dispellTrigger); -} - ItemComponent::ItemComponent(ItemClass *type, int amount) : mType(type), mAmount(amount) diff --git a/src/game-server/item.h b/src/game-server/item.h index 76242094..e627b42b 100644 --- a/src/game-server/item.h +++ b/src/game-server/item.h @@ -25,7 +25,6 @@ #include <vector> #include "game-server/actor.h" -#include "game-server/attack.h" #include "scripting/script.h" class Entity; @@ -86,7 +85,6 @@ 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_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 @@ -129,19 +127,6 @@ class ItemEffectAttrMod : public ItemEffectInfo unsigned mId; }; -class ItemEffectAttack : public ItemEffectInfo -{ - public: - ItemEffectAttack(AttackInfo *attackInfo) : - mAttackInfo(attackInfo) - {} - - bool apply(Entity *itemUser); - void dispell(Entity *itemUser); - private: - AttackInfo *mAttackInfo; -}; - class ItemEffectConsumes : public ItemEffectInfo { public: @@ -250,12 +235,6 @@ class ItemClass Script::Ref getEventCallback(const std::string &event) const { return mEventCallbacks.value(event); } - void addAttack(AttackInfo *attackInfo, ItemTriggerType applyTrigger, - ItemTriggerType dispellTrigger); - - std::vector<AttackInfo *> &getAttackInfos() - { return mAttackInfos; } - private: /** * Add an effect to a trigger @@ -290,8 +269,6 @@ class ItemClass */ utils::NameMap<Script::Ref> mEventCallbacks; - std::vector<AttackInfo *> mAttackInfos; - friend class ItemManager; }; diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp index 05dd0d0c..0362c5d9 100644 --- a/src/game-server/itemmanager.cpp +++ b/src/game-server/itemmanager.cpp @@ -346,12 +346,6 @@ void ItemManager::readEffectNode(xmlNodePtr effectNode, ItemClass *item) duration), triggerType.apply, triggerType.dispell); } - else if (xmlStrEqual(subNode->name, BAD_CAST "attack")) - { - AttackInfo *attackInfo = AttackInfo::readAttackNode(subNode); - item->addAttack(attackInfo, triggerType.apply, triggerType.dispell); - - } // Having a dispell for the next three is nonsensical. else if (xmlStrEqual(subNode->name, BAD_CAST "cooldown")) { diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp index 2b12a39b..83c63fa3 100644 --- a/src/game-server/mapcomposite.cpp +++ b/src/game-server/mapcomposite.cpp @@ -26,7 +26,6 @@ #include "common/configuration.h" #include "common/resourcemanager.h" #include "game-server/character.h" -#include "game-server/combatcomponent.h" #include "game-server/mapcomposite.h" #include "game-server/map.h" #include "game-server/mapmanager.h" @@ -596,13 +595,6 @@ void MapComposite::remove(Entity *ptr) for (std::vector<Entity*>::iterator i = mContent->entities.begin(), i_end = mContent->entities.end(); i != i_end; ++i) { - if ((*i)->canFight()) - { - if ((*i)->getComponent<CombatComponent>()->getTarget() == ptr) - { - (*i)->getComponent<CombatComponent>()->clearTarget(); - } - } if (*i == ptr) { i = mContent->entities.erase(i); diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp index 5d77db40..e0feed9e 100644 --- a/src/game-server/monster.cpp +++ b/src/game-server/monster.cpp @@ -28,7 +28,6 @@ #include "game-server/item.h" #include "game-server/map.h" #include "game-server/mapcomposite.h" -#include "game-server/monstercombatcomponent.h" #include "game-server/state.h" #include "scripting/scriptmanager.h" #include "utils/logger.h" @@ -36,15 +35,6 @@ #include <cmath> -MonsterClass::~MonsterClass() -{ - for (std::vector<AttackInfo *>::iterator it = mAttacks.begin(), - it_end = mAttacks.end(); it != it_end; ++it) - { - delete *it; - } -} - double MonsterClass::getVulnerability(Element element) const { Vulnerabilities::const_iterator it = mVulnerabilities.find(element); @@ -98,24 +88,6 @@ MonsterComponent::MonsterComponent(Entity &entity, MonsterClass *specy): beingComponent->signal_died.connect(sigc::mem_fun(this, &MonsterComponent::monsterDied)); - - // Set positions relative to target from which the monster can attack - int dist = specy->getAttackDistance(); - mAttackPositions.push_back(AttackPosition(dist, 0, LEFT)); - mAttackPositions.push_back(AttackPosition(-dist, 0, RIGHT)); - mAttackPositions.push_back(AttackPosition(0, -dist, DOWN)); - mAttackPositions.push_back(AttackPosition(0, dist, UP)); - - MonsterCombatComponent *combatComponent = - new MonsterCombatComponent(entity, specy); - entity.addComponent(combatComponent); - - double damageMutation = mutation ? - (100.0 + (rand() % (mutation * 2)) - mutation) / 100.0 : 1.0; - combatComponent->setDamageMutation(damageMutation); - - combatComponent->signal_damaged.connect( - sigc::mem_fun(this, &MonsterComponent::receivedDamage)); } MonsterComponent::~MonsterComponent() @@ -146,12 +118,6 @@ void MonsterComponent::update(Entity &entity) script->execute(entity.getMap()); } - refreshTarget(entity); - - // Cancel the rest when we have a target - if (entity.getComponent<CombatComponent>()->getTarget()) - return; - const Point &position = entity.getComponent<ActorComponent>()->getPosition(); @@ -176,97 +142,6 @@ void MonsterComponent::update(Entity &entity) } } -void MonsterComponent::refreshTarget(Entity &entity) -{ - auto *beingComponent = entity.getComponent<BeingComponent>(); - - // We are dead and sadly not possible to keep attacking :( - if (beingComponent->getAction() == DEAD) - return; - - // Check potential attack positions - int bestTargetPriority = 0; - Entity *bestTarget = 0; - Point bestAttackPosition; - - // reset Target. We will find a new one if possible - entity.getComponent<CombatComponent>()->clearTarget(); - - // Iterate through objects nearby - int aroundArea = Configuration::getValue("game_visualRange", 448); - for (BeingIterator i(entity.getMap()->getAroundBeingIterator(&entity, - aroundArea)); - i; ++i) - { - // We only want to attack player characters - if ((*i)->getType() != OBJECT_CHARACTER) - continue; - - Entity *target = *i; - - // Dead characters are ignored - if (beingComponent->getAction() == DEAD) - continue; - - // Determine how much we hate the target - int targetPriority = 0; - std::map<Entity *, AggressionInfo>::iterator angerIterator = - mAnger.find(target); - if (angerIterator != mAnger.end()) - { - const AggressionInfo &aggressionInfo = angerIterator->second; - targetPriority = aggressionInfo.anger; - } - else if (mSpecy->isAggressive()) - { - targetPriority = 1; - } - else - { - continue; - } - - // Check all attack positions - for (std::list<AttackPosition>::iterator j = mAttackPositions.begin(); - j != mAttackPositions.end(); j++) - { - Point attackPosition = - target->getComponent<ActorComponent>()->getPosition(); - attackPosition.x += j->x; - attackPosition.y += j->y; - - int posPriority = calculatePositionPriority(entity, - attackPosition, - targetPriority); - if (posPriority > bestTargetPriority) - { - bestTargetPriority = posPriority; - bestTarget = target; - bestAttackPosition = attackPosition; - } - } - } - if (bestTarget) - { - const Point &ownPosition = - entity.getComponent<ActorComponent>()->getPosition(); - const Point &targetPosition = - bestTarget->getComponent<ActorComponent>()->getPosition(); - - entity.getComponent<CombatComponent>()->setTarget(bestTarget); - if (bestAttackPosition == ownPosition) - { - beingComponent->setAction(entity, ATTACK); - beingComponent->updateDirection(entity, ownPosition, - targetPosition); - } - else - { - beingComponent->setDestination(entity, bestAttackPosition); - } - } -} - int MonsterComponent::calculatePositionPriority(Entity &entity, Point position, int targetPriority) @@ -301,133 +176,8 @@ int MonsterComponent::calculatePositionPriority(Entity &entity, return targetPriority * (range - path.size()); } } - -void MonsterComponent::forgetTarget(Entity *entity) -{ - { - AggressionInfo &aggressionInfo = mAnger[entity]; - aggressionInfo.removedConnection.disconnect(); - aggressionInfo.diedConnection.disconnect(); - } - mAnger.erase(entity); - - if (entity->getType() == OBJECT_CHARACTER) - { - mExpReceivers.erase(entity); - mLegalExpReceivers.erase(entity); - } -} - -void MonsterComponent::changeAnger(Entity *target, int amount) -{ - const EntityType type = target->getType(); - if (type != OBJECT_MONSTER && type != OBJECT_CHARACTER) - return; - - if (mAnger.find(target) != mAnger.end()) - { - mAnger[target].anger += amount; - } - else - { - AggressionInfo &aggressionInfo = mAnger[target]; - aggressionInfo.anger = amount; - - // Forget target either when it's removed or died, whichever - // happens first. - aggressionInfo.removedConnection = - target->signal_removed.connect(sigc::mem_fun(this, &MonsterComponent::forgetTarget)); - aggressionInfo.diedConnection = target->getComponent<BeingComponent>() - ->signal_died.connect( - sigc::mem_fun(this, &MonsterComponent::forgetTarget)); - } -} - -std::map<Entity *, int> MonsterComponent::getAngerList() const -{ - std::map<Entity *, int> result; - std::map<Entity *, AggressionInfo>::const_iterator i, i_end; - - for (i = mAnger.begin(), i_end = mAnger.end(); i != i_end; ++i) - { - const AggressionInfo &aggressionInfo = i->second; - result.insert(std::make_pair(i->first, aggressionInfo.anger)); - } - - return result; -} - void MonsterComponent::monsterDied(Entity *monster) { mDecayTimeout.set(DECAY_TIME); - - if (mExpReceivers.size() > 0) - { - // If the monster was killed by players, randomly drop items. - const unsigned size = mSpecy->mDrops.size(); - for (unsigned i = 0; i < size; i++) - { - const int p = rand() / (RAND_MAX / 10000); - const MonsterDrop &drop = mSpecy->mDrops[i]; - - if (p <= drop.probability) - { - const Point &position = - monster->getComponent<ActorComponent>()->getPosition(); - Entity *item = Item::create(monster->getMap(), position, - drop.item, 1); - GameState::enqueueInsert(item); - } - } - - // Distribute exp reward. - std::map<Entity *, std::set <size_t> > ::iterator iChar; - std::set<size_t>::iterator iSkill; - - - float expPerChar = (float)mSpecy->getExp() / mExpReceivers.size(); - - for (iChar = mExpReceivers.begin(); iChar != mExpReceivers.end(); - iChar++) - { - auto *character = (*iChar).first; - const std::set<size_t> &skillSet = (*iChar).second; - - if (mLegalExpReceivers.find(character) == mLegalExpReceivers.end() - || skillSet.empty()) - continue; - - auto characterComponent = - character->getComponent<CharacterComponent>(); - - int expPerSkill = int(expPerChar / skillSet.size()); - for (iSkill = skillSet.begin(); iSkill != skillSet.end(); - iSkill++) - { - characterComponent->receiveExperience(*iSkill, expPerSkill, - mSpecy->getOptimalLevel()); - } - characterComponent->incrementKillCount(mSpecy->getId()); - } - } } - -void MonsterComponent::receivedDamage(Entity *source, const Damage &damage, int hpLoss) -{ - if (source) - changeAnger(source, hpLoss); - - if (hpLoss && source && source->getType() == OBJECT_CHARACTER) - { - mExpReceivers[source].insert(damage.skill); - if (mKillStealProtectedTimeout.expired() || mOwner == source - || mOwner->getComponent<CharacterComponent>()->getParty() == - source->getComponent<CharacterComponent>()->getParty()) - { - mOwner = source; - mLegalExpReceivers.insert(source); - mKillStealProtectedTimeout.set(KILLSTEAL_PROTECTION_TIME); - } - } -} diff --git a/src/game-server/monster.h b/src/game-server/monster.h index 2e238201..4949d4c7 100644 --- a/src/game-server/monster.h +++ b/src/game-server/monster.h @@ -49,22 +49,6 @@ struct MonsterDrop typedef std::vector< MonsterDrop > MonsterDrops; -/** - * Structure containing different attack types of a monster type - */ -struct MonsterAttack -{ - unsigned id; - int priority; - float damageFactor; - Element element; - DamageType type; - int preDelay; - int aftDelay; - int range; - std::string scriptEvent; -}; - typedef std::map<Element, double> Vulnerabilities; /** @@ -88,8 +72,6 @@ class MonsterClass mOptimalLevel(0) {} - ~MonsterClass(); - /** * Returns monster type. This is the Id of the monster class. */ @@ -195,12 +177,6 @@ class MonsterClass /** Returns preferred combat distance in pixels. */ unsigned getAttackDistance() const { return mAttackDistance; } - /** Adds an attack to the monsters repertoire. */ - void addAttack(AttackInfo *info) { mAttacks.push_back(info); } - - /** Returns all attacks of the monster. */ - std::vector<AttackInfo *> &getAttackInfos() { return mAttacks; } - void setVulnerability(Element element, double factor) { mVulnerabilities[element] = factor; } @@ -235,7 +211,6 @@ class MonsterClass int mMutation; int mAttackDistance; int mOptimalLevel; - std::vector<AttackInfo *> mAttacks; Vulnerabilities mVulnerabilities; /** @@ -253,23 +228,6 @@ class MonsterClass }; /** - * Structure holding possible positions relative to the target from which - * the monster can attack - */ -struct AttackPosition -{ - AttackPosition(int posX, int posY, BeingDirection dir): - x(posX), - y(posY), - direction(dir) - {} - - int x; - int y; - BeingDirection direction; -}; - -/** * The component for a fightable monster with its own AI */ class MonsterComponent : public Component @@ -294,15 +252,11 @@ class MonsterComponent : public Component */ void update(Entity &entity); - void refreshTarget(Entity &entity); - /** * Signal handler */ void monsterDied(Entity *monster); - void receivedDamage(Entity *attacker, const Damage &damage, int hpLoss); - /** * Alters hate for the monster */ @@ -334,27 +288,18 @@ class MonsterComponent : public Component sigc::connection removedConnection; sigc::connection diedConnection; }; - std::map<Entity *, AggressionInfo> mAnger; /** * Character who currently owns this monster (killsteal protection). */ Entity *mOwner; - /** List of characters and their skills that attacked this monster. */ - std::map<Entity *, std::set <size_t> > mExpReceivers; - /** * List of characters who are entitled to receive exp (killsteal * protection). */ std::set<Entity *> mLegalExpReceivers; - /** - * Set positions relative to target from which the monster can attack. - */ - std::list<AttackPosition> mAttackPositions; - /** Time until monster strolls to new location */ Timeout mStrollTimeout; /** Kill steal protection time */ diff --git a/src/game-server/monstercombatcomponent.cpp b/src/game-server/monstercombatcomponent.cpp deleted file mode 100644 index 35e2f249..00000000 --- a/src/game-server/monstercombatcomponent.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2013 The Mana Developers - * - * 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 "game-server/monstercombatcomponent.h" - -#include "game-server/monster.h" -#include "scripting/scriptmanager.h" - -MonsterCombatComponent::MonsterCombatComponent(Entity &monster, - MonsterClass *specy): - CombatComponent(monster), - mDamageMutation(0) -{ - for (auto &attack : specy->getAttackInfos()) - { - addAttack(attack); - } -} - -/** - * Performs an attack - */ -void MonsterCombatComponent::processAttack(Entity *source, Attack &attack) -{ - if (!mTarget) - { - source->getComponent<BeingComponent>()->setAction(*source, STAND); - return; - } - - Damage dmg = attack.getAttackInfo()->getDamage(); - dmg.skill = 0; - dmg.base *= mDamageMutation; - dmg.delta *= mDamageMutation; - - int hit = performAttack(*mTarget, attack.getAttackInfo()->getDamage()); - - const Script::Ref &scriptCallback = - attack.getAttackInfo()->getScriptCallback(); - - if (scriptCallback.isValid() && hit > -1) - { - Script *script = ScriptManager::currentState(); - script->prepare(scriptCallback); - script->push(source); - script->push(mTarget); - script->push(hit); - script->execute(source->getMap()); - } -} - -/** - * Calls the damage function in Being and updates the aggro list - */ -int MonsterCombatComponent::damage(Entity &target, - Entity *source, - const Damage &damage) -{ - Damage newDamage = damage; - MonsterClass *specy = target.getComponent<MonsterComponent>()->getSpecy(); - float factor = specy->getVulnerability(newDamage.element); - newDamage.base = newDamage.base * factor; - newDamage.delta = newDamage.delta * factor; - int hpLoss = CombatComponent::damage(target, source, newDamage); - - - if (specy->getDamageCallback().isValid()) - { - Script *script = ScriptManager::currentState(); - script->prepare(specy->getDamageCallback()); - script->push(&target); - script->push(source); - script->push(hpLoss); - // TODO: add exact damage parameters as well - script->execute(target.getMap()); - } - return hpLoss; -} diff --git a/src/game-server/monstercombatcomponent.h b/src/game-server/monstercombatcomponent.h deleted file mode 100644 index 36afa26e..00000000 --- a/src/game-server/monstercombatcomponent.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * The Mana Server - * Copyright (C) 2013 The Mana Developers - * - * 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/>. - */ - -#ifndef MONSTERCOMBATCOMPONENT_H -#define MONSTERCOMBATCOMPONENT_H - -#include "game-server/combatcomponent.h" - -#include "game-server/attack.h" -#include "game-server/being.h" - -class MonsterClass; - -class MonsterCombatComponent: public CombatComponent -{ -public: - MonsterCombatComponent(Entity &monster, MonsterClass *specy); - - void processAttack(Entity *source, Attack &attack); - int damage(Entity &target, Entity *source, const Damage &damage); - - void setDamageMutation(double mutation); - -private: - double mDamageMutation; -}; - -/** - * Sets the mutation of the damage compared to the default damage of the specy - * @param mutation - */ -inline void MonsterCombatComponent::setDamageMutation(double mutation) -{ - mDamageMutation = mutation; -} - -#endif /* MONSTERCOMBATCOMPONENT_H */ diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp index 3a9d791b..df8c6906 100644 --- a/src/game-server/monstermanager.cpp +++ b/src/game-server/monstermanager.cpp @@ -235,45 +235,6 @@ void MonsterManager::readMonsterNode(xmlNodePtr node, const std::string &filenam monster->setAttackDistance( XML::getProperty(subnode, "attack-distance", 0)); } - else if (xmlStrEqual(subnode->name, BAD_CAST "attack")) - { - AttackInfo *att = AttackInfo::readAttackNode(subnode); - bool validMonsterAttack = true; - - if (att->getDamage().id < 1) - { - LOG_WARN(filename - << ": Attack without ID for monster Id:" - << id << " (" << name << ") - attack ignored"); - validMonsterAttack = false; - } - else if (att->getDamage().element == ELEMENT_ILLEGAL) - { - LOG_WARN(filename - << ": Attack with unknown element for monster Id:" - << id << " (" << name << ") - attack ignored"); - validMonsterAttack = false; - } - else if (att->getDamage().type == DAMAGE_OTHER) - { - LOG_WARN(filename - << ": Attack with unknown damage type " - << "for monster Id:" << id - << " (" << name << ")"); - validMonsterAttack = false; - } - - if (validMonsterAttack) - { - monster->addAttack(att); - } - else - { - delete att; - att = 0; - } - - } else if (xmlStrEqual(subnode->name, BAD_CAST "vulnerability")) { Element element = elementFromString( diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp index 3e2e4ab7..d2aaff4e 100644 --- a/src/game-server/state.cpp +++ b/src/game-server/state.cpp @@ -23,7 +23,6 @@ #include "common/configuration.h" #include "game-server/accountconnection.h" #include "game-server/effect.h" -#include "game-server/combatcomponent.h" #include "game-server/gamehandler.h" #include "game-server/inventory.h" #include "game-server/item.h" @@ -166,19 +165,6 @@ static void informPlayer(MapComposite *map, Entity *p) if (wereInRange && willBeInRange) { - // Send attack messages. - if ((oflags & UPDATEFLAG_ATTACK) && oid != pid) - { - MessageOut AttackMsg(GPMSG_BEING_ATTACK); - AttackMsg.writeInt16(oid); - AttackMsg.writeInt8( - o->getComponent<BeingComponent>()->getDirection()); - CombatComponent *combatComponent = - o->getComponent<CombatComponent>(); - AttackMsg.writeInt8(combatComponent->getAttackId()); - gameHandler->sendTo(p, AttackMsg); - } - // Send action change messages. if ((oflags & UPDATEFLAG_ACTIONCHANGE)) { diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp index 11a3feea..87568087 100644 --- a/src/scripting/lua.cpp +++ b/src/scripting/lua.cpp @@ -33,7 +33,6 @@ extern "C" { #include "game-server/buysell.h" #include "game-server/character.h" #include "game-server/collisiondetection.h" -#include "game-server/combatcomponent.h" #include "game-server/effect.h" #include "game-server/gamehandler.h" #include "game-server/inventory.h" @@ -1381,144 +1380,6 @@ static int entity_walk(lua_State *s) return 0; } -/** LUA entity:damage (being) - * entity:damage(int damage, int delta, - * int accuracy, int type, int element) - * entity:damage(int damage, int delta, int accuracy, - * int type, int element, handle source) - * entity:damage(int damage, int delta, int accuracy, - * int type, int element, handle source, int skill) - * entity:damage(int damage, int delta, int accuracy, - * int type, int element, handle source, string skillname) - ** - * Valid only for being entities. - * - * Inflicts damage to the being. The severity of the attack is between - * `damage` and (`damage` + `delta`) and is calculated using the normal - * damage calculation rules. The being has a chance to - * dodge the attack with its - * [agility attribute](attributes.xml.html). The `accuracy` decides how hard this is. - * - * If `source` is provided the attack is handled as if the `source` - * triggered the damage. - * - * If `skill` is given the `owner` can also recieve XP for the attack. The - * `skill` should be defined in the [skills.xml](skills.xml.html). If the skill - * is provided as string (`skillname`) you have to use this format: - * <setname>_<skillname>. So for example: "Weapons_Unarmed" - * - * `type` affects which kind of armor and character attributes reduce the - * damage. It can be one of the following values: - * <table class="table table-bordered table-hover"> - * <thead> - * <tr> - * <th>Id</th> - * <th>Name</th> - * </tr> - * </thead> - * <tbody> - * <tr> - * <td>0</td> - * <td>DAMAGE_PHYSICAL</td> - * </tr> - * <tr> - * <td>1</td> - * <td>DAMAGE_MAGICAL</td> - * </tr> - * <tr> - * <td>0</td> - * <td>DAMAGE_OTHER</td> - * </tr> - * </tbody> - * </table> - * - * `element` decides how the element system changes the damage. The - * following values are possible: - * <table class="table table-bordered table-hover"> - * <thead> - * <tr> - * <th>Id</th> - * <th>Name</th> - * </tr> - * </thead> - * <tbody> - * <tr> - * <td>0</td> - * <td>ELEMENT_NEUTRAL</td> - * </tr> - * <tr> - * <td>1</td> - * <td>ELEMENT_FIRE</td> - * </tr> - * <tr> - * <td>2</td> - * <td>ELEMENT_WATER</td> - * </tr> - * <tr> - * <td>3</td> - * <td>ELEMENT_EARTH</td> - * </tr> - * <tr> - * <td>4</td> - * <td>ELEMENT_AIR</td> - * </tr> - * <tr> - * <td>5</td> - * <td>ELEMENT_LIGHTNING</td> - * </tr> - * <tr> - * <td>6</td> - * <td>ELEMENT_METAL</td> - * </tr> - * <tr> - * <td>7</td> - * <td>ELEMENT_WOOD</td> - * </tr> - * <tr> - * <td>8</td> - * <td>ELEMENT_ICE</td> - * </tr> - * </tbody> - * </table> - * - * **Return Value**: Actual HP reduction resulting from the attack. - */ -static int entity_damage(lua_State *s) -{ - Entity *being = checkBeing(s, 1); - - if (!being->canFight()) - { - luaL_error(s, "damage called with victim that cannot fight"); - return 0; - } - - Damage dmg; - dmg.base = luaL_checkint(s, 2); - dmg.delta = luaL_checkint(s, 3); - dmg.cth = luaL_checkint(s, 4); - dmg.type = (DamageType)luaL_checkint(s, 5); - dmg.element = (Element)luaL_checkint(s, 6); - Entity *source = 0; - if (lua_gettop(s) >= 7) - { - source = checkBeing(s, 7); - - if (!source->canFight()) - { - luaL_error(s, "damage called with source that cannot fight"); - return 0; - } - } - if (lua_gettop(s) >= 8) - { - dmg.skill = checkSkill(s, 8); - } - being->getComponent<CombatComponent>()->damage(*being, source, dmg); - - return 0; -} - /** LUA entity:heal (being) * entity:heal([int value]) ** @@ -1587,10 +1448,9 @@ static int entity_get_type(lua_State *s) * * | 0 | ACTION_STAND | * | 1 | ACTION_WALK | - * | 2 | ACTION_ATTACK | - * | 3 | ACTION_SIT | - * | 4 | ACTION_DEAD | - * | 5 | ACTION_HURT | + * | 2 | ACTION_SIT | + * | 3 | ACTION_DEAD | + * | 4 | ACTION_HURT | */ static int entity_get_action(lua_State *s) { @@ -2453,55 +2313,6 @@ static int entity_get_monster_id(lua_State *s) return 1; } -/** LUA entity:change_anger (monster) - * entity:change_anger(handle being, int anger) - ** - * Valid only for monster entities. - * - * Makes the monster more angry about the `being` by adding `anger` to the - * being. - */ -static int entity_change_anger(lua_State *s) -{ - Entity *monster = checkMonster(s, 1); - Entity *being = checkBeing(s, 2); - const int anger = luaL_checkint(s, 3); - monster->getComponent<MonsterComponent>()->changeAnger(being, anger); - return 0; -} - -/** LUA entity:drop_anger (monster) - * entity:drop_anger(handle target) - ** - * Valid only for monster entities. - * - * Will drop all anger against the `target`. - */ -static int entity_drop_anger(lua_State *s) -{ - Entity *monster = checkMonster(s, 1); - Entity *being = checkBeing(s, 2); - monster->getComponent<MonsterComponent>()->forgetTarget(being); - return 0; -} - -/** LUA entity:get_angerlist (monster) - * entity:get_angerlist() - ** - * Valid only for monster entities. - * - * **Return value:** A table with the beings as key and the anger against them - * as values. - */ -static int entity_get_angerlist(lua_State *s) -{ - Entity *monster = checkMonster(s, 1); - MonsterComponent *monsterComponent = - monster->getComponent<MonsterComponent>(); - pushSTLContainer(s, monsterComponent->getAngerList()); - return 1; -} - /** LUA_CATEGORY Status effects (statuseffects) */ @@ -3130,38 +2941,6 @@ static int monster_class_on_update(lua_State *s) return 0; } -/** LUA monsterclass:on_damage (monsterclass) - * monsterclass:on_damage(function callback) - ** - * Assigns the `callback` as callback for the monster damage event. - * This callback will be called every time when a monster takes damage. - * The damage can be either invoked from scripts or from other beings such - * as players. The parameters of the callback are: the attacked monster, - * the being dealing the damage and the hp loss - * - * **Note:** See [get_monster_class](scripting.html#get_monster_class) for getting - * a monsterclass object. - * - * **Example:** - * {% highlight lua %} - * local function damage(mob, aggressor, hploss) - * mob:say("I took damage -.- ".. hploss) - * if aggressor then - * mob:say("Curse you, ".. aggressor:name()) - * end - * end - * local maggot = get_monster_class("maggot") - * maggot:on_damage(damage) - * {% endhighlight %} - */ -static int monster_class_on_damage(lua_State *s) -{ - MonsterClass *monsterClass = LuaMonsterClass::check(s, 1); - luaL_checktype(s, 2, LUA_TFUNCTION); - monsterClass->setDamageCallback(getScript(s)); - return 0; -} - /** LUA monsterclass:name (monsterclass) * monsterclass:name() ** @@ -3174,234 +2953,6 @@ static int monster_class_get_name(lua_State *s) return 1; } -/** LUA monsterclass:attacks (monsterclass) - * monsterclass:attacks() - ** - * **Return value:** This function returns a table with all attacks of the - * monster. See the [Attack Info](scripting.html#attackinfo_class) section. - */ -static int monster_class_attacks(lua_State *s) -{ - MonsterClass *monsterClass = LuaMonsterClass::check(s, 1); - pushSTLContainer(s, monsterClass->getAttackInfos()); - return 1; -} - - -/** LUA_CATEGORY AttackInfo class (attackinfoclass) - * The AttackInfo class reveals info about attacks and provides functions to - * register callbacks on attacks. See the - * [Attack Configuration](attackconfiguration.html) for more info. - * To get an AttackInfo use - * [monsterclass:attacks](scripting.html#monsterclassattacks) or - * [itemclass:attacks](scripting.html#itemclassattacks) - */ - -/** LUA attackinfo:priority (attackinfoclass) - * attackinfo:priority() - ** - * **Return value:** This function returns the priority of the attack. - */ -static int attack_get_priority(lua_State *s) -{ - AttackInfo *attack = LuaAttackInfo::check(s, 1); - lua_pushinteger(s, attack->getPriority()); - return 1; -} - -/** LUA attackinfo:cooldowntime (attackinfoclass) - * attackinfo:cooldowntime() - ** - * **Return value:** This function returns the cooldowntime (time after dealing - * damage after which a new attack can be used) of the attack. - */ -static int attack_get_cooldowntime(lua_State *s) -{ - AttackInfo *attack = LuaAttackInfo::check(s, 1); - lua_pushinteger(s, attack->getCooldownTime()); - return 1; -} - -/** LUA attackinfo:warmuptime (attackinfoclass) - * attackinfo:warmuptime() - ** - * **Return value:** This function returns the warmuptime (time before a attack - * triggers damage after being used) of the attack. - */ -static int attack_get_warmuptime(lua_State *s) -{ - AttackInfo *attack = LuaAttackInfo::check(s, 1); - lua_pushinteger(s, attack->getWarmupTime()); - return 1; -} - -/** LUA attackinfo:reusetime (attackinfoclass) - * attackinfo:reusetime() - ** - * **Return value:** This function returns the reusetime (time after which the - * same attack can be used again) of the attack. - */ -static int attack_get_reusetime(lua_State *s) -{ - AttackInfo *attack = LuaAttackInfo::check(s, 1); - lua_pushinteger(s, attack->getReuseTime()); - return 1; -} - -/** LUA attackinfo:damage (attackinfoclass) - * attackinfo:damage() - ** - * **Return value:** This function returns the damage info of the attack. - * - * **See also:** [Damage Class](scripting.html#damage_class) - */ -static int attack_get_damage(lua_State *s) -{ - AttackInfo *attack = LuaAttackInfo::check(s, 1); - LuaDamage::push(s, &attack->getDamage()); - return 1; -} - -/** LUA attackinfo:on_attack (attackinfoclass) - * attackinfo:on_attack(function callback) - ** - * Assigns a callback to the attack that will be called as soon the attack is - * used. The callback will get called with the following parameters: - * being user, being target, int damage_dealt. - */ -static int attack_on_attack(lua_State *s) -{ - AttackInfo *attack = LuaAttackInfo::check(s, 1); - luaL_checktype(s, 2, LUA_TFUNCTION); - attack->setCallback(getScript(s)); - return 0; -} - - -/** LUA_CATEGORY Damage Class (damageclass) - * The Damage class provides info about the kind of damage attack deals. - */ - -/** LUA damage:id (damageclass) - * damage:id() - ** - * **Return value:** This function returns the id of the attack. - */ -static int damage_get_id(lua_State *s) -{ - Damage *damage = LuaDamage::check(s, 1); - lua_pushinteger(s, damage->id); - return 1; -} - -/** LUA damage:skill (damageclass) - * damage:skill() - ** - * **Return value:** This function returns the skill id of the attack. If the - * damage dealer is a character is a character this skill will recieve exp. - */ -static int damage_get_skill(lua_State *s) -{ - Damage *damage = LuaDamage::check(s, 1); - lua_pushinteger(s, damage->skill); - return 1; -} - -/** LUA damage:base (damageclass) - * damage:base() - ** - * **Return value:** This function returns the base damage of the attack. - * It is the minimum of damage dealt. - */ -static int damage_get_base(lua_State *s) -{ - Damage *damage = LuaDamage::check(s, 1); - lua_pushinteger(s, damage->base); - return 1; -} - -/** LUA damage:delta (damageclass) - * damage:delta() - ** - * **Return value:** This function returns the damage delta of the attack. - * base damage + delta damage is the maximum of damage the attack can cause. - * A number in between will be picked by random. - */ -static int damage_get_delta(lua_State *s) -{ - Damage *damage = LuaDamage::check(s, 1); - lua_pushinteger(s, damage->delta); - return 1; -} - -/** LUA damage:cth (damageclass) - * damage:cth() - ** - * **Return value:** This function returns the chance to hit of the attack. - * This number is not a percent value but some factor. Higher means a better - * chance to hit. FIXME: Add info about the factor. - */ -static int damage_get_cth(lua_State *s) -{ - Damage *damage = LuaDamage::check(s, 1); - lua_pushinteger(s, damage->cth); - return 1; -} - -/** LUA damage:element (damageclass) - * damage:element() - ** - * **Return value:** This function returns the element of the attack. - * - * **See:** [entity:damage](scripting.html#entitydamage) for possible values. - */ -static int damage_get_element(lua_State *s) -{ - Damage *damage = LuaDamage::check(s, 1); - lua_pushinteger(s, damage->element); - return 1; -} - -/** LUA damage:type (damageclass) - * damage:type() - ** - * **Return value:** This function returns the type of the attack. - * - * **See:** [entity:damage](scripting.html#entitydamage) for possible values. - */ -static int damage_get_type(lua_State *s) -{ - Damage *damage = LuaDamage::check(s, 1); - lua_pushinteger(s, damage->type); - return 1; -} - -/** LUA damage:is_truestrike (damageclass) - * damage:is_truestrike() - ** - * **Return value:** This function returns whether the attack is a true strike. - * A true strike is not effected by chance of hit or anything that could - * prevent the hit. - */ -static int damage_is_truestrike(lua_State *s) -{ - Damage *damage = LuaDamage::check(s, 1); - lua_pushboolean(s, damage->trueStrike); - return 1; -} - -/** LUA damage:range (damageclass) - * damage:range() - ** - * **Return value:** This function returns the range of the attack in pixels. - */ -static int damage_get_range(lua_State *s) -{ - Damage *damage = LuaDamage::check(s, 1); - lua_pushinteger(s, damage->range); - return 1; -} - /** LUA_CATEGORY Map object class (mapobjectclass) */ @@ -3570,23 +3121,6 @@ static int item_class_get_name(lua_State *s) return 1; } -/** LUA itemclass:attacks (itemclass) - * itemclass:attacks() - ** - * **Return value:** Returns a list of all attacks the item offers. - * - * **See:** the [AttackInfo class](scripting.html#attackinfo_class) for more info - * about how to use the values in the list. - */ -static int item_class_attacks(lua_State *s) -{ - ItemClass *itemClass = LuaItemClass::check(s, 1); - std::vector<AttackInfo *> attacks = itemClass->getAttackInfos(); - pushSTLContainer<AttackInfo *>(s, attacks); - return 1; -} - - /** * Returns four useless tables for testing the STL container push wrappers. * This function can be removed when there are more useful functions which use @@ -3745,29 +3279,6 @@ LuaScript::LuaScript(): #endif lua_pop(mRootState, 1); // pop the globals table - static luaL_Reg const members_AttackInfo[] = { - { "priority", attack_get_priority }, - { "cooldowntime", attack_get_cooldowntime }, - { "warmuptime", attack_get_warmuptime }, - { "reusetime", attack_get_reusetime }, - { "damage", attack_get_damage }, - { "on_attack", attack_on_attack }, - { nullptr, nullptr } - }; - - static luaL_Reg const members_Damage[] = { - { "id", damage_get_id }, - { "skill", damage_get_skill }, - { "base", damage_get_base }, - { "delta", damage_get_delta }, - { "cth", damage_get_cth }, - { "element", damage_get_element }, - { "type", damage_get_type }, - { "is_truestrike", damage_is_truestrike }, - { "range", damage_get_range }, - { nullptr, nullptr } - }; - static luaL_Reg const members_Entity[] = { { "remove", entity_remove }, { "say", entity_say }, @@ -3784,7 +3295,6 @@ LuaScript::LuaScript(): { "ability_mana", entity_get_ability_mana }, { "cooldown_ability", entity_cooldown_ability }, { "walk", entity_walk }, - { "damage", entity_damage }, { "heal", entity_heal }, { "name", entity_get_name }, { "type", entity_get_type }, @@ -3823,9 +3333,6 @@ LuaScript::LuaScript(): { "has_ability", entity_has_ability }, { "take_ability", entity_take_ability }, { "monster_id", entity_get_monster_id }, - { "change_anger", entity_change_anger }, - { "drop_anger", entity_drop_anger }, - { "angerlist", entity_get_angerlist }, { "apply_status", entity_apply_status }, { "remove_status", entity_remove_status }, { "has_status", entity_has_status }, @@ -3838,7 +3345,6 @@ LuaScript::LuaScript(): static luaL_Reg const members_ItemClass[] = { { "on", item_class_on }, { "name", item_class_get_name }, - { "attacks", item_class_attacks }, { nullptr, nullptr } }; @@ -3852,9 +3358,7 @@ LuaScript::LuaScript(): static luaL_Reg const members_MonsterClass[] = { { "on_update", monster_class_on_update }, - { "on_damage", monster_class_on_damage }, { "name", monster_class_get_name }, - { "attacks", monster_class_attacks }, { nullptr, nullptr } }; @@ -3873,8 +3377,6 @@ LuaScript::LuaScript(): { nullptr, nullptr} }; - LuaAttackInfo::registerType(mRootState, "Attack", members_AttackInfo); - LuaDamage::registerType(mRootState, "Damage", members_Damage); LuaEntity::registerType(mRootState, "Entity", members_Entity); LuaItemClass::registerType(mRootState, "ItemClass", members_ItemClass); LuaMapObject::registerType(mRootState, "MapObject", members_MapObject); diff --git a/src/scripting/luautil.h b/src/scripting/luautil.h index 9ea11c07..e7cbc754 100644 --- a/src/scripting/luautil.h +++ b/src/scripting/luautil.h @@ -34,7 +34,6 @@ extern "C" { #include <set> #include <vector> -#include "game-server/attack.h" #include "game-server/abilitymanager.h" class CharacterComponent; @@ -159,8 +158,6 @@ private: template <typename T> const char * LuaUserData<T>::mTypeName; -typedef LuaUserData<AttackInfo> LuaAttackInfo; -typedef LuaUserData<Damage> LuaDamage; typedef LuaUserData<Entity> LuaEntity; typedef LuaUserData<ItemClass> LuaItemClass; typedef LuaUserData<MapObject> LuaMapObject; @@ -210,11 +207,6 @@ inline void push(lua_State *s, double val) lua_pushnumber(s, val); } -inline void push(lua_State *s, AttackInfo *val) -{ - LuaAttackInfo::push(s, val); -} - inline void push(lua_State *s, MapObject *val) { LuaMapObject::push(s, val); |