/// <summary> /// Calls a skill to be used, and applies the respective cooldown values. /// </summary> /// <param name="skill">The skill to be used.</param> /// <param name="target">The optional character to use the skill on. Can be null.</param> /// <param name="castedImmediately">True if this skill was casted immediately (that is, there was no delay before casting); /// false if the skill had a delay before casting.</param> void UseSkill(ISkill <SkillType, StatType, Character> skill, Character target, bool castedImmediately) { Debug.Assert(skill != null); Debug.Assert(castedImmediately || _currentCastingSkill == skill); Debug.Assert(castedImmediately || _castingSkillTarget == target); // Clear the casting status variables _currentCastingSkill = null; _castingSkillTarget = null; // Tell the caster that they stopped casting if (_character is INetworkSender) { using (var pw = ServerPacket.SkillStopCasting_ToUser()) { ((INetworkSender)_character).Send(pw, ServerMessageType.GUIUserStatus); } } // If the skill had a casting time, tell everyone that the casting stopped if (!castedImmediately) { using (var pw = ServerPacket.SkillStopCasting_ToMap(_character.MapEntityIndex)) { _character.Map.Send(pw, ServerMessageType.MapDynamicEntityProperty); } } // Actually use the skill var skillSuccessfullyUsed = skill.Use(_character, target); // If the skill was not used for whatever reason, then return if (!skillSuccessfullyUsed) { return; } // Only set the cooldown if it was successfully used _cooldownManager.SetCooldown(skill.CooldownGroup, skill.CooldownTime, _character.GetTime()); // Update the character's skill cooldown if (_character is INetworkSender) { using (var pw = ServerPacket.SkillSetGroupCooldown(skill.CooldownGroup, skill.CooldownTime)) { ((INetworkSender)_character).Send(pw, ServerMessageType.GUIUserStatus); } } // Notify the clients on the map that the character used the skill var targetEntityIndex = target != null ? (MapEntityIndex?)target.MapEntityIndex : null; using (var pw = ServerPacket.SkillUse(_character.MapEntityIndex, targetEntityIndex, skill.SkillType)) { _character.Map.Send(pw, ServerMessageType.MapDynamicEntityProperty); } }