Пример #1
0
        public IEnumerable <Act.Status> SummonSkeletons()
        {
            while (true)
            {
                Skeletons.RemoveAll(skeleton => skeleton.IsDead);
                if (SummonTimer.HasTriggered && Skeletons.Count < MaxSkeletons)
                {
                    SummonTimer.Reset(SummonTimer.TargetTimeSeconds);
                    for (int i = Skeletons.Count; i < MaxSkeletons; i += 2)
                    {
                        SummonSkeleton();
                    }
                    yield return(Act.Status.Success);
                }
                else if (SummonTimer.HasTriggered)
                {
                    yield return(Act.Status.Success);
                }
                SummonTimer.Update(DwarfTime.LastTime);

                if (WanderTimer.HasTriggered)
                {
                    Physics.ApplyForce(MathFunctions.RandVector3Box(-5f, 5f, 0.01f, 0.01f, -5f, 5f), 1f);
                    GatherSkeletons();
                }
                WanderTimer.Update(DwarfTime.LastTime);

                if (AttackTimer.HasTriggered)
                {
                    OrderSkeletonsToAttack();
                }
                AttackTimer.Update(DwarfTime.LastTime);
                yield return(Act.Status.Running);
            }
        }
Пример #2
0
        public IEnumerable <Act.Status> GoToRandomTarget(float radius)
        {
            Vector3 randomVector = MathFunctions.RandVector3Cube() * radius;
            Vector3 target       = Physics.ClampToBounds(Position + randomVector);
            float   dist         = (target - Position).Length();
            Timer   timout       = new Timer(3.0f, false);

            while (dist > 3.0f)
            {
                timout.Update(DwarfTime.LastTime);
                if (timout.HasTriggered)
                {
                    break;
                }
                Vector3 output = Creature.Controller.GetOutput(DwarfTime.Dt, target, Position);
                output.Normalize();
                output *= 10;
                Physics.ApplyForce(new Vector3(output.X, 0.0f, output.Z), DwarfTime.Dt);
                dist = (target - Position).Length();
                yield return(Act.Status.Running);
            }
            yield return(Act.Status.Success);
        }
Пример #3
0
        public void DoDamage(Creature performer, GameComponent other, float bonus)
        {
            if (!String.IsNullOrEmpty(Weapon.DiseaseToSpread))
            {
                if (other.GetRoot().GetComponent <Creature>().HasValue(out var otherCreature))
                {
                    var disease = DiseaseLibrary.GetDisease(Weapon.DiseaseToSpread);
                    if (disease != null)
                    {
                        if (MathFunctions.RandEvent(disease.LikelihoodOfSpread))
                        {
                            otherCreature.Stats.AcquireDisease(disease);
                        }
                    }
                }
            }

            var health = other.GetRoot().EnumerateAll().OfType <Health>().FirstOrDefault();

            if (health != null)
            {
                health.Damage(Weapon.DamageAmount + bonus);
                var injury = DiseaseLibrary.GetRandomInjury();

                if (MathFunctions.RandEvent(injury.LikelihoodOfSpread))
                {
                    if (other.GetRoot().GetComponent <Creature>().HasValue(out var creature))
                    {
                        creature.Stats.AcquireDisease(injury);
                    }
                }

                Vector3 knock = other.Position - performer.Physics.Position;
                knock.Normalize();
                knock *= 0.2f;
                if (other.AnimationQueue.Count == 0)
                {
                    other.AnimationQueue.Add(new KnockbackAnimation(0.15f, other.LocalTransform, knock));
                }
            }
            else
            {
                other.GetRoot().Die();
            }

            PlayNoise(other.GlobalTransform.Translation);
            if (Weapon.HitParticles != "")
            {
                performer.Manager.World.ParticleManager.Trigger(Weapon.HitParticles, other.LocalTransform.Translation, Color.White, 5);

                if (Weapon.ShootLaser)
                {
                    performer.Manager.World.ParticleManager.TriggerRay(Weapon.HitParticles, performer.AI.Position, other.LocalTransform.Translation);
                }
            }

            if (Weapon.HitAnimation != null)
            {
                IndicatorManager.DrawIndicator(Weapon.HitAnimation, 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 - performer.AI.Position;

                if (force.LengthSquared() > 0.01f)
                {
                    force.Normalize();
                    physics.ApplyForce(force * Weapon.Knockback, 1.0f);
                }
            }
        }
Пример #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);
        }
Пример #5
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)
                {
                    HasTriggered = false;
                    return(false);
                }
                break;

            case AttackTrigger.Animation:
                if (!performer.Sprite.AnimPlayer.HasValidAnimation() ||
                    performer.Sprite.AnimPlayer.CurrentFrame != TriggerFrame)
                {
                    HasTriggered = false;
                    return(false);
                }
                break;
            }

            if (HasTriggered)
            {
                return(true);
            }

            HasTriggered = true;
            switch (Mode)
            {
            case AttackMode.Melee:
            case AttackMode.Dogfight:
            {
                var otherCreature = other.GetRoot().GetComponent <Creature>();
                if (otherCreature != null && !String.IsNullOrEmpty(DiseaseToSpread))
                {
                    var disease = DiseaseLibrary.GetDisease(DiseaseToSpread);
                    if (MathFunctions.RandEvent(disease.LikelihoodOfSpread))
                    {
                        otherCreature.AcquireDisease(DiseaseToSpread);
                    }
                }
                var health = other.GetRoot().EnumerateAll().OfType <Health>().FirstOrDefault();
                if (health != null)
                {
                    health.Damage(DamageAmount + bonus);
                    var injury = DiseaseLibrary.GetRandomInjury();

                    if (MathFunctions.RandEvent(injury.LikelihoodOfSpread))
                    {
                        var creature = other.GetRoot().GetComponent <Creature>();
                        if (creature != null)
                        {
                            creature.AcquireDisease(injury.Name);
                        }
                    }
                    Vector3 knock = other.Position - performer.Physics.Position;
                    knock.Normalize();
                    knock *= 0.2f;
                    if (other.AnimationQueue.Count == 0)
                    {
                        other.AnimationQueue.Add(new KnockbackAnimation(0.15f, other.LocalTransform, knock));
                    }
                }

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

                if (HitAnimation != null)
                {
                    IndicatorManager.DrawIndicator(HitAnimation, 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);

                var injury = DiseaseLibrary.GetRandomInjury();

                if (MathFunctions.RandEvent(injury.LikelihoodOfSpread))
                {
                    var creature = other.GetRoot().GetComponent <Creature>();
                    if (creature != null)
                    {
                        creature.AcquireDisease(injury.Name);
                    }
                }
                break;
            }
            }

            return(true);
        }