public void AttackTest(string attackType)
        {
            AttackConditions tryEnum = AttackConditions.Nothing;

            System.Enum.TryParse(attackType, true, out tryEnum);

            Debug.Log($"enum = {tryEnum}");
        }
Exemple #2
0
        public DamageEvent DamageTarget(Creature target, WorldObject damageSource)
        {
            if (target.Health.Current <= 0)
            {
                return(null);
            }

            // check PK status
            var targetPlayer = target as Player;

            if (targetPlayer != null)
            {
                var pkError = CheckPKStatusVsTarget(this, targetPlayer, null);
                if (pkError != null)
                {
                    Session.Network.EnqueueSend(new GameEventWeenieErrorWithString(Session, pkError[0], target.Name));
                    targetPlayer.Session.Network.EnqueueSend(new GameEventWeenieErrorWithString(targetPlayer.Session, pkError[1], Name));
                    return(null);
                }
            }

            var damageEvent = DamageEvent.CalculateDamage(this, target, damageSource);

            if (damageEvent.HasDamage)
            {
                OnDamageTarget(target, damageEvent.CombatType, damageEvent.IsCritical);

                if (targetPlayer != null)
                {
                    targetPlayer.TakeDamage(this, damageEvent.DamageType, damageEvent.Damage, damageEvent.BodyPart, damageEvent.IsCritical);
                }
                else
                {
                    target.TakeDamage(this, damageEvent.DamageType, damageEvent.Damage, damageEvent.IsCritical);
                }
            }
            else
            {
                if (targetPlayer != null && targetPlayer.UnderLifestoneProtection)
                {
                    Session.Network.EnqueueSend(new GameMessageSystemChat($"The Lifestone's magic protects {target.Name} from the attack!", ChatMessageType.Magic));
                }
                else
                {
                    Session.Network.EnqueueSend(new GameMessageSystemChat($"{target.Name} evaded your attack.", ChatMessageType.CombatSelf));
                }
            }

            if (damageEvent.HasDamage && target.IsAlive)
            {
                var attackConditions = new AttackConditions();
                if (damageEvent.RecklessnessMod > 1.0f)
                {
                    attackConditions |= AttackConditions.Recklessness;
                }
                if (damageEvent.SneakAttackMod > 1.0f)
                {
                    attackConditions |= AttackConditions.SneakAttack;
                }

                // notify attacker
                var intDamage = (uint)Math.Round(damageEvent.Damage);

                Session.Network.EnqueueSend(new GameEventAttackerNotification(Session, target.Name, damageEvent.DamageType, (float)intDamage / target.Health.MaxValue, intDamage, damageEvent.IsCritical, attackConditions));

                // splatter effects
                if (targetPlayer == null)
                {
                    Session.Network.EnqueueSend(new GameMessageSound(target.Guid, Sound.HitFlesh1, 0.5f));
                    if (damageEvent.Damage >= target.Health.MaxValue * 0.25f)
                    {
                        var painSound = (Sound)Enum.Parse(typeof(Sound), "Wound" + ThreadSafeRandom.Next(1, 3), true);
                        Session.Network.EnqueueSend(new GameMessageSound(target.Guid, painSound, 1.0f));
                    }
                    var splatter = (PlayScript)Enum.Parse(typeof(PlayScript), "Splatter" + GetSplatterHeight() + GetSplatterDir(target));
                    Session.Network.EnqueueSend(new GameMessageScript(target.Guid, splatter));
                }

                // handle Dirty Fighting
                if (GetCreatureSkill(Skill.DirtyFighting).AdvancementClass >= SkillAdvancementClass.Trained)
                {
                    FightDirty(target);
                }
            }

            if (damageEvent.Damage > 0.0f)
            {
                Session.Network.EnqueueSend(new GameEventUpdateHealth(Session, target.Guid.Full, (float)target.Health.Current / target.Health.MaxValue));
            }

            if (targetPlayer == null)
            {
                OnAttackMonster(target);
            }

            return(damageEvent);
        }
Exemple #3
0
        public float DamageTarget(Creature target, WorldObject damageSource)
        {
            if (target.Health.Current <= 0)
            {
                return(0.0f);
            }

            var critical    = false;
            var sneakAttack = false;

            // check PK status
            var targetPlayer = target as Player;

            if (targetPlayer != null)
            {
                var pkStatus = CheckPKStatusVsTarget(this, targetPlayer, null);
                if (pkStatus != null && pkStatus == false)
                {
                    Session.Network.EnqueueSend(new GameMessageSystemChat($"You fail to affect {targetPlayer.Name} because you are not a player killer!", ChatMessageType.Magic));
                    return(0.0f);
                }
            }

            var damage     = CalculateDamage(target, damageSource, ref critical, ref sneakAttack);
            var damageType = GetDamageType();

            if (damage > 0.0f)
            {
                var attackType = GetAttackType();
                OnDamageTarget(target, attackType);

                target.TakeDamage(this, damageType, damage, critical);
            }
            else
            {
                Session.Network.EnqueueSend(new GameMessageSystemChat($"{target.Name} evaded your attack.", ChatMessageType.CombatSelf));
            }

            if (damage > 0.0f && target.Health.Current > 0)
            {
                var recklessnessMod = critical ? 1.0f : GetRecklessnessMod();

                var attackConditions = new AttackConditions();
                if (recklessnessMod > 1.0f)
                {
                    attackConditions |= AttackConditions.Recklessness;
                }
                if (sneakAttack)
                {
                    attackConditions |= AttackConditions.SneakAttack;
                }

                // notify attacker
                var intDamage = (uint)Math.Round(damage);
                if (damageSource?.ItemType == ItemType.MissileWeapon)
                {
                    Session.Network.EnqueueSend(new GameEventAttackerNotification(Session, target.Name, damageType, (float)intDamage / target.Health.MaxValue, intDamage, critical, attackConditions));
                }
                else
                {
                    Session.Network.EnqueueSend(new GameEventAttackerNotification(Session, target.Name, GetDamageType(), (float)intDamage / target.Health.MaxValue, intDamage, critical, attackConditions));
                }

                // splatter effects
                Session.Network.EnqueueSend(new GameMessageSound(target.Guid, Sound.HitFlesh1, 0.5f));
                if (damage >= target.Health.MaxValue * 0.25f)
                {
                    var painSound = (Sound)Enum.Parse(typeof(Sound), "Wound" + Physics.Common.Random.RollDice(1, 3), true);
                    Session.Network.EnqueueSend(new GameMessageSound(target.Guid, painSound, 1.0f));
                }
                var splatter = (PlayScript)Enum.Parse(typeof(PlayScript), "Splatter" + GetSplatterHeight() + GetSplatterDir(target));
                Session.Network.EnqueueSend(new GameMessageScript(target.Guid, splatter));

                // handle Dirty Fighting
                if (GetCreatureSkill(Skill.DirtyFighting).AdvancementClass >= SkillAdvancementClass.Trained)
                {
                    FightDirty(target);
                }
            }

            if (damage > 0.0f)
            {
                Session.Network.EnqueueSend(new GameEventUpdateHealth(Session, target.Guid.Full, (float)target.Health.Current / target.Health.MaxValue));
            }

            OnAttackMonster(target);
            return(damage);
        }
 public GameEventAttackerNotification(Session session, string defenderName, DamageType damageType, float percent, uint damage, bool criticalHit, AttackConditions attackConditions)
     : base(GameEventType.AttackerNotification, GameMessageGroup.UIQueue, session)
 {
     Writer.WriteString16L(defenderName);
     Writer.Write((uint)damageType);
     Writer.Write((double)percent);
     Writer.Write(damage);
     Writer.Write(Convert.ToUInt32(criticalHit));
     Writer.Write((UInt64)attackConditions);
 }