diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2012-06-10 15:11:01 +0200 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2012-07-07 21:56:14 +0200 |
commit | 4cf22065e9f2b24eb481959aa65667ef1bd0724d (patch) | |
tree | b7bfe1214fd1a0c6bfe99be35204c537a050cac9 /src/game-server/character.cpp | |
parent | 576431fb11a3dbc256fbd1f5a853a5be719f1879 (diff) | |
download | manaserv-4cf22065e9f2b24eb481959aa65667ef1bd0724d.tar.gz manaserv-4cf22065e9f2b24eb481959aa65667ef1bd0724d.tar.bz2 manaserv-4cf22065e9f2b24eb481959aa65667ef1bd0724d.tar.xz manaserv-4cf22065e9f2b24eb481959aa65667ef1bd0724d.zip |
Work on (Auto)Attack system.
During the implementation bjorn and I agreed to limit the number of attacks that
can be used in the same tick to one. This makes a lot of stuff easier and the
client cannot display two frames at the same time
Things done:
- Implemented setting of attacks when equipping/unequipping items
- Single place where the xml attack node is parsed
- Finished attack logic
- Unified the attack handling of monsters and characters
- Added a global cooldown after attack use
(not only for next use of same attack)
- Removed the temponary attributes for the monster attack values
- Priorities for all attacks
- Rewrote the attack core:
- Attacks now have this attributes:
- warmup -> time a attack needs after starting it to actually deal the damage
- cooldown -> time a attack needs after dealing damage before another attack
can be used
- reuse -> time before the same attack can be used again
- If no attack is performed at the moment the following is done:
- make a list with all ready attacks
- check for attack that has the necessarily range and highest priority
- start this attack (inform client about it)
- when warmup is finished -> trigger damage
- when cooldown is finished -> allow to use other (or the same if reusetimer
allows) attacks
TODO:
- sync client with this to allow better timed animations
Diffstat (limited to 'src/game-server/character.cpp')
-rw-r--r-- | src/game-server/character.cpp | 98 |
1 files changed, 45 insertions, 53 deletions
diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index 35a9e967..bf7c1909 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -87,7 +87,8 @@ Character::Character(MessageIn &msg): mParty(0), mTransaction(TRANS_NONE), mTalkNpcId(0), - mNpcThread(0) + mNpcThread(0), + mKnuckleAttackInfo(0) { const AttributeManager::AttributeScope &attr = attributeManager->getAttributeScope(CharacterScope); @@ -107,11 +108,27 @@ Character::Character(MessageIn &msg): Inventory(this).initialize(); modifiedAllAttribute(); setSize(16); + + // Default knuckle attack + int damageBase = this->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); + addAttack(mKnuckleAttackInfo); } Character::~Character() { delete mNpcThread; + delete mKnuckleAttackInfo; } void Character::update() @@ -163,58 +180,6 @@ void Character::update() mStatusEffects[it->first] = it->second.time; it++; } - - processAttacks(); -} - -void Character::processAttacks() -{ - // Ticks attacks even when not attacking to permit cooldowns and warmups. - std::list<Attack> attacksReady; - mAttacks.tick(&attacksReady); - - if (mAction != ATTACK || !mTarget) - { - mAttacks.stop(); - return; - } - - // Deal with the ATTACK action. - - // Install default bare knuckle attack if no attacks were added from config. - // TODO: Get this from configuration. - if (!mAttacks.getNumber()) - { - int damageBase = 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 = (getSize() < DEFAULT_TILE_LENGTH) ? - DEFAULT_TILE_LENGTH : getSize(); - - Attack knuckleAttack(knuckleDamage, 7, 3); - mAttacks.add(knuckleAttack); - } - - if (attacksReady.empty()) - { - if (!mAttacks.areActive()) - mAttacks.start(); - } - else - { - // Performs all ready attacks. - for (std::list<Attack>::iterator it = attacksReady.begin(); - it != attacksReady.end(); ++it) - { - performAttack(mTarget, it->getDamage()); - } - } } void Character::died() @@ -537,6 +502,14 @@ bool Character::recalculateBaseAttribute(unsigned int attr) newBase = 0.0; // TODO break; + case ATTR_STR: + if (mKnuckleAttackInfo) + { + Damage &knuckleDamage = mKnuckleAttackInfo->getDamage(); + knuckleDamage.base = getModifiedAttribute(ATTR_STR); + knuckleDamage.delta = knuckleDamage.base / 2; + } + break; default: return Being::recalculateBaseAttribute(attr); } @@ -794,6 +767,25 @@ void Character::resumeNpcThread() } } +void Character::addAttack(AttackInfo *attackInfo) +{ + // Remove knuckle attack + Being::removeAttack(mKnuckleAttackInfo); + Being::addAttack(attackInfo); +} + +void Character::removeAttack(AttackInfo *attackInfo) +{ + // Add knuckle attack + if (mAttacks.getNumber() == 1) + { + + Being::addAttack(mKnuckleAttackInfo); + } + Being::removeAttack(attackInfo); +} + + void Character::disconnected() { mConnected = false; |