diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-04-23 23:36:09 +0200 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-05-08 14:02:51 +0200 |
commit | 1758acc8e845524071db8996f3dd5d1935a059e1 (patch) | |
tree | 713fef27549712cdb979b096bd82da66a904c672 /src/game-server/character.cpp | |
parent | 62f1e23dff18a00066ce9a9df67e058d5e5d7bbd (diff) | |
download | manaserv-1758acc8e845524071db8996f3dd5d1935a059e1.tar.gz manaserv-1758acc8e845524071db8996f3dd5d1935a059e1.tar.xz manaserv-1758acc8e845524071db8996f3dd5d1935a059e1.zip |
[Abilities] Added support for a global cooldown
Each ability can now define a cooldown that prevents the player from
using other abilities for a while. The time of this cooldown can be set
to any attribute. The modified value of the attribute is the value of
the cooldown in game ticks. The cooldown will be automatically started
if the ability has `autoconsume` set to true. Otherwise a script has to
call entity:cooldown_ability(ability).
Diffstat (limited to 'src/game-server/character.cpp')
-rw-r--r-- | src/game-server/character.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp index 0fa1e10..3d23e3a 100644 --- a/src/game-server/character.cpp +++ b/src/game-server/character.cpp @@ -82,6 +82,7 @@ CharacterComponent::CharacterComponent(Entity &entity, MessageIn &msg): mLevelProgress(0), mUpdateLevelProgress(false), mRecalculateLevel(true), + mSendAbilityCooldown(false), mParty(0), mTransaction(TRANS_NONE), mTalkNpcId(0), @@ -127,10 +128,14 @@ CharacterComponent::CharacterComponent(Entity &entity, MessageIn &msg): mKnuckleAttackInfo = new AttackInfo(0, knuckleDamage, 7, 3, 0); combatcomponent->addAttack(mKnuckleAttackInfo); + auto *abilityComponent = new AbilityComponent(entity); entity.addComponent(abilityComponent); abilityComponent->signal_ability_changed.connect( sigc::mem_fun(this, &CharacterComponent::abilityStatusChanged)); + abilityComponent->signal_cooldown_activated.connect( + sigc::mem_fun(this, + &CharacterComponent::abilityCooldownActivated)); // Get character data. mDatabaseID = msg.readInt32(); @@ -170,6 +175,9 @@ void CharacterComponent::update(Entity &entity) if (!mModifiedAbilities.empty()) sendAbilityUpdate(entity); + + if (mSendAbilityCooldown) + sendAbilityCooldownUpdate(entity); } void CharacterComponent::characterDied(Entity *being) @@ -214,6 +222,11 @@ void CharacterComponent::abilityStatusChanged(int id) mModifiedAbilities.insert(id); } +void CharacterComponent::abilityCooldownActivated() +{ + mSendAbilityCooldown = true; +} + void CharacterComponent::sendAbilityUpdate(Entity &entity) { auto *beingComponent = entity.getComponent<BeingComponent>(); @@ -240,6 +253,15 @@ void CharacterComponent::sendAbilityUpdate(Entity &entity) gameHandler->sendTo(mClient, msg); } +void CharacterComponent::sendAbilityCooldownUpdate(Entity &entity) +{ + MessageOut msg(GPMSG_ABILITY_COOLDOWN); + auto *abilityComponent = entity.getComponent<AbilityComponent>(); + msg.writeInt16(abilityComponent->remainingCooldown()); + gameHandler->sendTo(mClient, msg); + mSendAbilityCooldown = false; +} + void CharacterComponent::cancelTransaction() { TransactionType t = mTransaction; |