Ejemplo n.º 1
0
        /// <summary>
        /// Called for a spell projectile to damage its target
        /// </summary>
        public void DamageTarget(WorldObject _target, double?damage, bool critical)
        {
            var player = ProjectileSource as Player;

            var target       = _target as Creature;
            var targetPlayer = _target as Player;

            {
                uint amount;
                var  percent        = 0.0f;
                var  sneakAttackMod = 1.0f;

                // handle life projectiles for stamina / mana
                if (Spell.School == MagicSchool.LifeMagic && (Spell.Name.Contains("Blight") || Spell.Name.Contains("Tenacity")))
                {
                    if (Spell.Name.Contains("Blight"))
                    {
                        percent = (float)damage / targetPlayer.Mana.MaxValue;
                        amount  = (uint)-target.UpdateVitalDelta(target.Mana, (int)-Math.Round(damage.Value));
                    }
                    else
                    {
                        percent = (float)damage / targetPlayer.Stamina.MaxValue;
                        amount  = (uint)-target.UpdateVitalDelta(target.Stamina, (int)-Math.Round(damage.Value));
                    }
                }
                else
                {
                    // for possibly applying sneak attack to magic projectiles,
                    // only do this for health-damaging projectiles?
                    if (player != null)
                    {
                        // TODO: use target direction vs. projectile position, instead of player position
                        // could sneak attack be applied to void DoTs?
                        sneakAttackMod = player.GetSneakAttackMod(target);
                        //Console.WriteLine("Magic sneak attack:  + sneakAttackMod);
                        damage *= sneakAttackMod;
                    }

                    // DR / DRR applies for magic too?
                    var damageRatingMod       = Creature.GetRatingMod(ProjectileSource.EnchantmentManager.GetDamageRating());
                    var damageResistRatingMod = Creature.GetNegativeRatingMod(target.EnchantmentManager.GetDamageResistRating());
                    damage *= damageRatingMod * damageResistRatingMod;

                    percent = (float)damage / target.Health.MaxValue;
                    amount  = (uint)-target.UpdateVitalDelta(target.Health, (int)-Math.Round(damage.Value));
                    target.DamageHistory.Add(ProjectileSource, Spell.DamageType, amount);
                }

                amount = (uint)Math.Round(damage.Value);    // full amount for debugging

                if (target.IsAlive)
                {
                    string verb = null, plural = null;
                    Strings.GetAttackVerb(Spell.DamageType, percent, ref verb, ref plural);
                    var type = Spell.DamageType.GetName().ToLower();

                    var critMsg  = critical ? "Critical hit!  " : "";
                    var sneakMsg = sneakAttackMod > 1.0f ? "Sneak Attack! " : "";
                    if (player != null)
                    {
                        var attackerMsg  = new GameMessageSystemChat($"{critMsg}{sneakMsg}You {verb} {target.Name} for {amount} points of {type} damage!", ChatMessageType.Magic);
                        var updateHealth = new GameEventUpdateHealth(player.Session, target.Guid.Full, (float)target.Health.Current / target.Health.MaxValue);

                        player.Session.Network.EnqueueSend(attackerMsg, updateHealth);
                    }

                    if (targetPlayer != null)
                    {
                        targetPlayer.Session.Network.EnqueueSend(new GameMessageSystemChat($"{critMsg}{sneakMsg}{ProjectileSource.Name} {plural} you for {amount} points of {type} damage!", ChatMessageType.Magic));
                    }
                }
                else
                {
                    target.OnDeath(ProjectileSource, Spell.DamageType, critical);
                    target.Die();
                }
            }
        }