Beispiel #1
0
        /// <remarks>
        /// This Packet is sent to the Client when a Player or Monster got Hit and damaged.
        /// It includes which Player/Monster got hit by who, and the Damage Type.
        /// It is obvious that the mu online protocol only supports 16 bits for each damage value. To prevent bugs (own player health)
        /// and to make it somehow visible that the damage exceeds 65k, we send more than one packet, if the 16bits are not enough.
        /// </remarks>
        /// <inheritdoc/>
        public void ShowHit(IAttackable target, HitInfo hitInfo)
        {
            var targetId = target.GetId(this.player);
            var remainingHealthDamage = hitInfo.HealthDamage;
            var remainingShieldDamage = hitInfo.ShieldDamage;

            while (remainingHealthDamage > 0 || remainingShieldDamage > 0)
            {
                var healthDamage = (ushort)System.Math.Min(0xFFFF, remainingHealthDamage);
                var shieldDamage = (ushort)System.Math.Min(0xFFFF, remainingShieldDamage);
                using var writer = this.player.Connection.StartSafeWrite(ObjectHit.HeaderType, ObjectHit.Length);
                _ = new ObjectHit(writer.Span)
                {
                    HeaderCode     = this.operation,
                    ObjectId       = targetId,
                    HealthDamage   = healthDamage,
                    ShieldDamage   = shieldDamage,
                    IsDoubleDamage = hitInfo.Attributes.HasFlag(DamageAttributes.Double),
                    IsTripleDamage = hitInfo.Attributes.HasFlag(DamageAttributes.Triple),
                    Kind           = this.GetDamageKind(hitInfo.Attributes),
                };

                writer.Commit();

                remainingShieldDamage -= shieldDamage;
                remainingHealthDamage -= healthDamage;
            }
        }
 void OnTriggerEnter(Collider other)
 {
     ObjectHit      = other.gameObject;
     ObjectToDamage = ObjectHit.GetComponent <IDamagable>();
     if (ObjectToDamage != null)
     {
         ObjectToDamage.TakeDamage(ProjectileDamage);
     }
 }
Beispiel #3
0
        private void OnTriggerEnter2D(Collider2D other)
        {
            var character = other.GetComponent <Stats>();

            if (character == null)
            {
                return;
            }

            ObjectHit?.Invoke(character);
        }
Beispiel #4
0
 public void Add( ObjectHit Hit )
 {
     ObjectHits.Add( Hit );
 }