Beispiel #1
0
 private void OnDamaged(EntityDamageEventArgs e)
 {
     foreach (EventListener el in Plugins)
     {
         if (el.Event == Event.EntityDamage)
         {
             IEntityListener l = el.Listener as IEntityListener;
             l.OnDamaged(e);
         }
     }
 }
Beispiel #2
0
        public virtual void Damage(DamageCause cause, short damageAmount, IEntityBase hitBy = null, params object[] args)
        {
            if (damageAmount <= 0)
            {
                World.Logger.Log(LogLevel.Warning, string.Format("Invalid damage {0} of type {1} caused by {2} to {3}({4})", damageAmount, cause, (hitBy == null ? "null" : hitBy.EntityId.ToString()), Name, EntityId));
                return;
            }
            lock (_damageLock)
            {
                if (World.WorldTicks - LastDamageTick < 10)
                    return;
                LastDamageTick = World.WorldTicks;
                EntityDamageEventArgs e = new EntityDamageEventArgs(this, damageAmount, hitBy, cause);
                Server.PluginManager.CallEvent(Event.EntityDamage, e);
                if (e.EventCanceled) return;
                damageAmount = e.Damage;
                hitBy = e.DamagedBy as EntityBase;
                // Debug
                if (hitBy is Player)
                {
                    var hitByPlayer = hitBy as Player;
                    var itemHeld = hitByPlayer.Inventory.ActiveItem;
                    hitByPlayer.Client.SendMessage("You hit a " + Name + " with a " + itemHeld.Type + " dealing " +
                                                   damageAmount + " damage.");
                }

                Health -= damageAmount;
                SendUpdateOnDamage();

                // TODO: Entity Knockback

                if (Health <= 0)
                    HandleDeath(hitBy as EntityBase);
            }
        }
 public void OnDamaged(EntityDamageEventArgs e)
 {
 }