Ejemplo n.º 1
0
        public override bool ShouldReceiveDamage(DamageSource damageSource, float damage)
        {
            EnumGameMode mode = World?.PlayerByUid(PlayerUID)?.WorldData?.CurrentGameMode ?? EnumGameMode.Survival;

            if ((mode == EnumGameMode.Creative || mode == EnumGameMode.Spectator) && damageSource?.Type != EnumDamageType.Heal)
            {
                return(false);
            }

            return(base.ShouldReceiveDamage(damageSource, damage));
        }
Ejemplo n.º 2
0
        public override bool ReceiveDamage(DamageSource damageSource, float damage)
        {
            if (damageSource.Source == EnumDamageSource.Internal && damageSource.Type == EnumDamageType.Fire)
            {
                fireDamage += damage;
            }
            if (fireDamage > 4)
            {
                Die();
            }

            return(base.ReceiveDamage(damageSource, damage));
        }
Ejemplo n.º 3
0
        public override void Die(EnumDespawnReason reason = EnumDespawnReason.Death, DamageSource damageSourceForDeath = null)
        {
            if (Alive && reason == EnumDespawnReason.Death)
            {
                PlayEntitySound("death");
            }
            if (reason != EnumDespawnReason.Death)
            {
                AllowDespawn = true;
            }

            controls.WalkVector.Set(0, 0, 0);
            controls.FlyVector.Set(0, 0, 0);
            ClimbingOnFace = null;

            base.Die(reason, damageSourceForDeath);
        }
Ejemplo n.º 4
0
        public virtual void DidAttack(DamageSource source, EntityAgent targetEntity)
        {
            EnumHandling handled = EnumHandling.PassThrough;

            foreach (EntityBehavior behavior in SidedProperties.Behaviors)
            {
                behavior.DidAttack(source, targetEntity, ref handled);
                if (handled == EnumHandling.PreventSubsequent)
                {
                    break;
                }
            }

            if (handled == EnumHandling.PreventDefault || handled == EnumHandling.PreventSubsequent)
            {
                return;
            }
        }
Ejemplo n.º 5
0
        public override void Die(EnumDespawnReason reason = EnumDespawnReason.Death, DamageSource damageSourceForDeath = null)
        {
            base.Die(reason, damageSourceForDeath);

            DeathReason   = damageSourceForDeath;
            DespawnReason = null;
            DeadNotify    = true;
            TryStopHandAction(true, EnumItemUseCancelReason.Death);
            TryUnmount();
            WatchedAttributes.SetFloat("intoxication", 0);

            // Execute this one frame later so that in case right after this method some other code still returns an item (e.g. BlockMeal), it is also ditched
            Api.Event.EnqueueMainThreadTask(() =>
            {
                if (Properties.Server?.Attributes?.GetBool("keepContents", false) != true)
                {
                    World.PlayerByUid(PlayerUID).InventoryManager.OnDeath();
                }

                if (Properties.Server?.Attributes?.GetBool("dropArmorOnDeath", false) == true)
                {
                    foreach (var slot in GearInventory)
                    {
                        if (slot.Empty)
                        {
                            continue;
                        }
                        if (slot.Itemstack.ItemAttributes?["protectionModifiers"].Exists == true)
                        {
                            Api.World.SpawnItemEntity(slot.Itemstack, ServerPos.XYZ);
                            slot.Itemstack = null;
                            slot.MarkDirty();
                        }
                    }
                }
            }, "dropinventoryondeath");
        }
Ejemplo n.º 6
0
        public override void OnHurt(DamageSource damageSource, float damage)
        {
            if (damage > 0 && World != null && World.Side == EnumAppSide.Client && (World as IClientWorldAccessor).Player.Entity.EntityId == this.EntityId)
            {
                (World as IClientWorldAccessor).AddCameraShake(0.3f);
            }

            if (damage != 0 && World?.Side == EnumAppSide.Server)
            {
                bool   heal = damageSource.Type == EnumDamageType.Heal;
                string msg;

                if (damageSource.Type == EnumDamageType.BluntAttack || damageSource.Type == EnumDamageType.PiercingAttack || damageSource.Type == EnumDamageType.SlashingAttack)
                {
                    msg = Lang.Get(heal ? "Gained {0:0.##} hp through {1}" : "Lost {0:0.##} hp through {1} (source: {2})", damage, damageSource.Type.ToString().ToLowerInvariant(), damageSource.Source);
                }
                else
                {
                    msg = Lang.Get(heal ? "Gained {0:0.##} hp through {1}" : "Lost {0:0.##} hp through {1}", damage, damageSource.Type.ToString().ToLowerInvariant());
                }

                if (damageSource.Source == EnumDamageSource.Player)
                {
                    EntityPlayer eplr = damageSource.SourceEntity as EntityPlayer;
                    msg = Lang.Get(heal ? "Gained {0:0.##} hp by player {1}" : "Lost {0:0.##} hp by player {1}", damage, damageSource.Source.ToString().ToLowerInvariant(), World.PlayerByUid(eplr.PlayerUID).PlayerName);
                }

                if (damageSource.Source == EnumDamageSource.Entity)
                {
                    string creatureName = Lang.Get("prefixandcreature-" + damageSource.SourceEntity.Code.Path.Replace("-", ""));
                    msg = Lang.Get(heal ? "Gained {0:0.##} hp by {1}" : "Lost {0:0.##} hp by {1} (Creature)", damage, creatureName);
                }

                (World.PlayerByUid(PlayerUID) as IServerPlayer).SendMessage(GlobalConstants.DamageLogChatGroup, msg, EnumChatType.Notification);
            }
        }
Ejemplo n.º 7
0
 public virtual void OnEntityHurt(DamageSource source, float damage)
 {
 }
Ejemplo n.º 8
0
        public override bool ReceiveDamage(DamageSource damageSource, float damage)
        {
            bool ret = base.ReceiveDamage(damageSource, damage);

            return(ret);
        }
Ejemplo n.º 9
0
        public override void OnInteract(EntityAgent byEntity, ItemSlot slot, Vec3d hitPosition, EnumInteractMode mode)
        {
            EnumHandling handled = EnumHandling.PassThrough;

            foreach (EntityBehavior behavior in SidedProperties.Behaviors)
            {
                behavior.OnInteract(byEntity, slot, hitPosition, mode, ref handled);
                if (handled == EnumHandling.PreventSubsequent)
                {
                    break;
                }
            }

            if (handled == EnumHandling.PreventDefault || handled == EnumHandling.PreventSubsequent)
            {
                return;
            }

            if (mode == EnumInteractMode.Attack)
            {
                float damage     = slot.Itemstack == null ? 0.5f : slot.Itemstack.Collectible.GetAttackPower(slot.Itemstack);
                int   damagetier = slot.Itemstack == null ? 0 : slot.Itemstack.Collectible.ToolTier;

                damage *= byEntity.Stats.GetBlended("meleeWeaponsDamage");

                if (Attributes.GetBool("isMechanical", false))
                {
                    damage *= byEntity.Stats.GetBlended("mechanicalsDamage");
                }

                IPlayer byPlayer = null;

                if (byEntity is EntityPlayer && !IsActivityRunning("invulnerable"))
                {
                    byPlayer = (byEntity as EntityPlayer).Player;

                    World.PlaySoundAt(new AssetLocation("sounds/player/slap"), ServerPos.X, ServerPos.Y, ServerPos.Z, byPlayer);
                    slot?.Itemstack?.Collectible.OnAttackingWith(byEntity.World, byEntity, this, slot);
                }

                if (Api.Side == EnumAppSide.Client && damage > 1 && !IsActivityRunning("invulnerable") && Properties.Attributes?["spawnDamageParticles"].AsBool() == true)
                {
                    Vec3d pos    = SidedPos.XYZ + hitPosition;
                    Vec3d minPos = pos.AddCopy(-0.15, -0.15, -0.15);
                    Vec3d maxPos = pos.AddCopy(0.15, 0.15, 0.15);

                    int   textureSubId = this.Properties.Client.FirstTexture.Baked.TextureSubId;
                    Vec3f tmp          = new Vec3f();

                    for (int i = 0; i < 10; i++)
                    {
                        int color = (Api as ICoreClientAPI).EntityTextureAtlas.GetRandomColor(textureSubId);

                        tmp.Set(
                            1f - 2 * (float)World.Rand.NextDouble(),
                            2 * (float)World.Rand.NextDouble(),
                            1f - 2 * (float)World.Rand.NextDouble()
                            );

                        World.SpawnParticles(
                            1, color, minPos, maxPos,
                            tmp, tmp, 1.5f, 1f, 0.25f + (float)World.Rand.NextDouble() * 0.25f,
                            EnumParticleModel.Cube, byPlayer
                            );
                    }
                }

                DamageSource dmgSource = new DamageSource()
                {
                    Source       = (byEntity as EntityPlayer).Player == null ? EnumDamageSource.Entity : EnumDamageSource.Player,
                    SourceEntity = byEntity,
                    Type         = EnumDamageType.BluntAttack,
                    HitPosition  = hitPosition,
                    DamageTier   = damagetier
                };

                if (ReceiveDamage(dmgSource, damage))
                {
                    byEntity.DidAttack(dmgSource, this);
                }
            }
        }
Ejemplo n.º 10
0
 public override bool ShouldReceiveDamage(DamageSource damageSource, float damage)
 {
     return(false);
 }