Example #1
0
        override public void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera)
        {
            if (Target != null && (Target.Position - LocalPosition).LengthSquared() < DamageRadius)
            {
                Health health = Target.GetRoot().GetComponent <Health>();

                if (health != null)
                {
                    health.Damage(Damage.Amount, Damage.DamageType);
                    Vector3 knock = (Target.Position - Position);
                    knock.Normalize();
                    knock *= 0.2f;
                    if (Target.AnimationQueue.Count == 0)
                    {
                        Target.AnimationQueue.Add(new KnockbackAnimation(0.15f, Target.LocalTransform, knock));
                    }
                }

                if (Damage.DamageType == Health.DamageType.Fire)
                {
                    Flammable flammabe = Target.GetRoot().GetComponent <Flammable>();

                    if (flammabe != null)
                    {
                        flammabe.Heat += 50.0f;
                    }
                }

                Die();
            }
            else if (Target != null && (Target.Position.Y - LocalPosition.Y) > 1 && Velocity.Y < 0)
            {
                Die();
            }

            if (Target == null)
            {
                if (LocalPosition.Y < 0)
                {
                    Die();
                }

                if (CurrentVoxel.IsValid && !CurrentVoxel.IsEmpty)
                {
                    Die();
                }
            }

            base.Update(gameTime, chunks, camera);
        }
Example #2
0
        override public void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera)
        {
            if (!Active)
            {
                return;
            }

            var body = Parent as Body;

            System.Diagnostics.Debug.Assert(body != null);

            DamageTimer.Update(gameTime);
            CheckLavaTimer.Update(gameTime);
            SoundTimer.Update(gameTime);
            if (CheckLavaTimer.HasTriggered)
            {
                CheckForLavaAndWater(body, gameTime, chunks);
            }
            Heat *= 0.999f;

            if (Heat > Flashpoint)
            {
                UpdateRate = 1;
                if (DamageTimer.HasTriggered)
                {
                    Health.Damage(Damage, Health.DamageType.Fire);
                }

                if (SoundTimer.HasTriggered)
                {
                    SoundManager.PlaySound(ContentPaths.Audio.fire, body.Position, true, 1.0f);
                }
                double totalSize = (body.BoundingBox.Max - body.BoundingBox.Min).Length();
                int    numFlames = (int)(totalSize / 4.0f) + 1;

                for (int i = 0; i < numFlames; i++)
                {
                    Vector3 extents     = (body.BoundingBox.Max - body.BoundingBox.Min);
                    Vector3 randomPoint = body.BoundingBox.Min + new Vector3(extents.X * MathFunctions.Rand(), extents.Y * MathFunctions.Rand(), extents.Z * MathFunctions.Rand());
                    Manager.World.ParticleManager.Trigger("flame", randomPoint, Color.White, GetNumTrigger(body));
                }
            }
        }
Example #3
0
        public override void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera)
        {
            if (!IsActive)
            {
                return;
            }
            DamageTimer.Update(gameTime);
            CheckLavaTimer.Update(gameTime);
            SoundTimer.Update(gameTime);
            if (CheckLavaTimer.HasTriggered)
            {
                CheckForLavaAndWater(gameTime, chunks);
            }
            Heat *= 0.999f;

            if (Heat > Flashpoint)
            {
                if (DamageTimer.HasTriggered)
                {
                    Health.Damage(Damage, Health.DamageType.Fire);
                }

                if (SoundTimer.HasTriggered)
                {
                    SoundManager.PlaySound(ContentPaths.Audio.fire, LocParent.Position, true, 0.5f);
                }
                double totalSize = (LocParent.BoundingBox.Max - LocParent.BoundingBox.Min).Length();
                int    numFlames = (int)(totalSize / 4.0f) + 1;

                for (int i = 0; i < numFlames; i++)
                {
                    Vector3 extents     = (LocParent.BoundingBox.Max - LocParent.BoundingBox.Min);
                    Vector3 randomPoint = LocParent.BoundingBox.Min + new Vector3(extents.X * MathFunctions.Rand(), extents.Y * MathFunctions.Rand(), extents.Z * MathFunctions.Rand());
                    PlayState.ParticleManager.Trigger("flame", randomPoint, Color.White, GetNumTrigger());
                }
            }

            base.Update(gameTime, chunks, camera);
        }
Example #4
0
        public bool Perform(Creature performer, Body other, DwarfTime time, float bonus, Vector3 pos, string faction)
        {
            switch (TriggerMode)
            {
            case AttackTrigger.Timer:
                RechargeTimer.Update(time);
                if (!RechargeTimer.HasTriggered)
                {
                    return(false);
                }
                break;

            case AttackTrigger.Animation:
                if (performer.Sprite.CurrentAnimation == null ||
                    performer.Sprite.CurrentAnimation.CurrentFrame != TriggerFrame)
                {
                    return(false);
                }
                break;
            }
            switch (Mode)
            {
            case AttackMode.Melee:
            case AttackMode.Dogfight:
            {
                Health health = other.GetRootComponent().GetChildrenOfType <Health>(true).FirstOrDefault();
                if (health != null)
                {
                    health.Damage(DamageAmount + bonus);
                }

                PlayNoise(other.GlobalTransform.Translation);
                if (HitParticles != "")
                {
                    PlayState.ParticleManager.Trigger(HitParticles, other.LocalTransform.Translation, Color.White, 5);
                }

                if (HitAnimation != null)
                {
                    HitAnimation.Reset();
                    HitAnimation.Play();
                    IndicatorManager.DrawIndicator(HitAnimation.Clone(), other.BoundingBox.Center(), 10.0f, 1.0f, MathFunctions.RandVector2Circle(), Color.White, MathFunctions.Rand() > 0.5f);
                }

                Physics physics = other as Physics;

                if (physics != null)
                {
                    Vector3 force = other.Position - pos;

                    if (force.LengthSquared() > 0.01f)
                    {
                        force.Normalize();
                        physics.ApplyForce(force * Knockback, 1.0f);
                    }
                }

                break;
            }

            case AttackMode.Ranged:
            {
                PlayNoise(other.GlobalTransform.Translation);
                LaunchProjectile(pos, other.Position, other);
                break;
            }
            }

            return(true);
        }
Example #5
0
        override public void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera)
        {
            if (!Active)
            {
                return;
            }
            base.Update(gameTime, chunks, camera);
            var body = Parent as GameComponent;

            global::System.Diagnostics.Debug.Assert(body != null);

            DamageTimer.Update(gameTime);
            CheckLavaTimer.Update(gameTime);
            SoundTimer.Update(gameTime);
            if (CheckLavaTimer.HasTriggered)
            {
                CheckSurroundings(body, gameTime, chunks);
            }
            Heat *= 0.999f;

            if (Heat > Flashpoint)
            {
                if (DamageTimer.HasTriggered)
                {
                    Health.Damage(Damage, Health.DamageType.Fire);
                }

                if (SoundTimer.HasTriggered)
                {
                    SoundManager.PlaySound(ContentPaths.Audio.fire, body.Position, true, 1.0f);
                }
                double totalSize = (body.BoundingBox.Max - body.BoundingBox.Min).Length();
                int    numFlames = (int)(totalSize / 4.0f) + 1;
                for (int i = FlameSprites.Count; i < numFlames; i++)
                {
                    CreateFlameSprite(MathFunctions.RandVector3Box(body.BoundingBox));
                }

                if (MathFunctions.RandEvent(0.06f))
                {
                    foreach (var sprite in FlameSprites)
                    {
                        Manager.World.ParticleManager.Trigger("smoke", sprite.Position + Vector3.Up * 0.5f, Color.Black, 1);
                        Manager.World.ParticleManager.Trigger("flame", sprite.Position + Vector3.Up * 0.5f, Color.Black, 1);
                    }
                }

                if (MathFunctions.RandEvent(0.01f))
                {
                    foreach (var sprite in FlameSprites)
                    {
                        sprite.Die();
                    }
                    FlameSprites.Clear();
                }
                var mesh = Parent.GetComponent <InstanceMesh>();

                if (mesh != null)
                {
                    mesh.VertexColorTint = Color.DarkGray;
                }
            }
            else
            {
                foreach (var sprite in FlameSprites)
                {
                    sprite.Die();
                }
                FlameSprites.Clear();
            }
        }