Esempio n. 1
0
        public override void OnVoxelsSelected(SpellTree tree, List <VoxelHandle> voxels)
        {
            bool placed = false;

            foreach (var selected in voxels)
            {
                if (selected.IsValid && ((!Transmute && selected.IsEmpty) || Transmute && !selected.IsEmpty) && OnCast(tree))
                {
                    Vector3 p = selected.WorldPosition + Vector3.One * 0.5f;
                    IndicatorManager.DrawIndicator("-" + ManaCost + " M", p, 1.0f, GameSettings.Default.Colors.GetColor("Negative", Color.Red));
                    World.ParticleManager.Trigger("star_particle", p, Color.White, 4);
                    var lSelected = selected;
                    lSelected.Type = VoxelLibrary.GetVoxelType(VoxelType);
                    lSelected.QuickSetLiquid(LiquidType.None, 0);

                    if (VoxelType == "Magic")
                    {
                        World.ComponentManager.RootComponent.AddChild(new DestroyOnTimer(World.ComponentManager, World.ChunkManager, selected)
                        {
                            DestroyTimer = new Timer(5.0f + MathFunctions.Rand(-0.5f, 0.5f), true)
                        });
                    }
                    placed = true;
                }
            }

            if (placed)
            {
                SoundManager.PlaySound(ContentPaths.Audio.tinkle, World.CursorLightPos, true, 1.0f);
            }

            RechargeTimer.Reset(RechargeTimer.TargetTimeSeconds);
            base.OnVoxelsSelected(tree, voxels);
        }
Esempio n. 2
0
 public DroidBayModel(Button deploy, Button upgrade, Button remove, Button recharge,
                      Button repair, Text statusText, Text droidTypeText, Text deployTimeText, Image droidImage, Text droidHealthText, Text droidEnergyText)
 {
     _timer        = new RechargeTimer();
     _droidBayView = new DroidBayView(deploy, upgrade, remove, recharge, repair, statusText, droidTypeText, deployTimeText, droidImage, droidHealthText, droidEnergyText);
     _droidBayView.CleanBay();
 }
Esempio n. 3
0
        public bool Perform(Creature performer, Vector3 pos, Voxel other, DwarfTime time, float bonus, string faction)
        {
            if (other == null)
            {
                return(false);
            }

            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:
            {
                other.Health -= DamageAmount + bonus;
                PlayNoise(other.Position);
                if (HitParticles != "")
                {
                    PlayState.ParticleManager.Trigger(HitParticles, other.Position, Color.White, 5);
                }

                if (HitAnimation != null)
                {
                    HitAnimation.Reset();
                    HitAnimation.Play();
                    IndicatorManager.DrawIndicator(HitAnimation, other.Position + Vector3.One * 0.5f, 0.6f, 2.0f, MathFunctions.RandVector2Circle(), Color.White, MathFunctions.Rand() > 0.5f);
                }
                break;
            }

            case AttackMode.Ranged:
            {
                LaunchProjectile(pos, other.Position, faction);
                break;
            }
            }
            return(true);
        }
Esempio n. 4
0
        public override void OnVoxelsSelected(SpellTree tree, List <Voxel> voxels)
        {
            HashSet <Point3> chunksToRebuild = new HashSet <Point3>();
            bool             placed          = false;

            foreach (Voxel selected in voxels)
            {
                if (selected != null && ((!Transmute && selected.IsEmpty) || Transmute && !selected.IsEmpty) && OnCast(tree))
                {
                    Vector3 p = selected.Position + Vector3.One * 0.5f;
                    IndicatorManager.DrawIndicator("-" + ManaCost + " M", p, 1.0f, Color.Red);
                    World.ParticleManager.Trigger("star_particle", p, Color.White, 4);
                    VoxelLibrary.PlaceType(VoxelLibrary.GetVoxelType(VoxelType), selected);

                    if (VoxelType == "Magic")
                    {
                        new VoxelListener(World.ComponentManager, World.ComponentManager.RootComponent, World.ChunkManager, selected)
                        {
                            DestroyOnTimer = true,
                            DestroyTimer   = new Timer(5.0f + MathFunctions.Rand(-0.5f, 0.5f), true)
                        };
                    }
                    placed = true;
                    chunksToRebuild.Add(selected.ChunkID);
                }
            }

            foreach (Point3 point in chunksToRebuild)
            {
                VoxelChunk chunk = World.ChunkManager.ChunkData.ChunkMap[point];
                chunk.ShouldRebuild = true;
                chunk.NotifyTotalRebuild(true);
            }

            if (placed)
            {
                SoundManager.PlaySound(ContentPaths.Audio.tinkle, World.CursorLightPos, true, 1.0f);
            }

            RechargeTimer.Reset(RechargeTimer.TargetTimeSeconds);
            base.OnVoxelsSelected(tree, voxels);
        }
Esempio n. 5
0
        public bool PerformNoDamage(Creature performer, DwarfTime time, Vector3 pos)
        {
            switch (TriggerMode)
            {
            case AttackTrigger.Timer:
                RechargeTimer.Update(time);
                if (!RechargeTimer.HasTriggered)
                {
                    HasTriggered = false;
                    return(false);
                }
                break;

            case AttackTrigger.Animation:
                if (performer.Sprite.CurrentAnimation == null ||
                    performer.Sprite.CurrentAnimation.CurrentFrame != TriggerFrame)
                {
                    HasTriggered = false;
                    return(false);
                }
                break;
            }
            if (Mode == AttackMode.Melee)
            {
                if (HitParticles != "")
                {
                    performer.Manager.World.ParticleManager.Trigger(HitParticles, pos, Color.White, 5);
                }


                if (HitAnimation != null && !HasTriggered)
                {
                    HitAnimation.Reset();
                    HitAnimation.Play();
                    IndicatorManager.DrawIndicator(HitAnimation.Clone(), pos, 10.0f, 1.0f, MathFunctions.RandVector2Circle(), Color.White, MathFunctions.Rand() > 0.5f);
                    PlayNoise(pos);
                }
            }
            HasTriggered = true;
            return(true);
        }
Esempio n. 6
0
        public void PerformNoDamage(Creature performer, DwarfTime time, Vector3 pos)
        {
            switch (TriggerMode)
            {
            case AttackTrigger.Timer:
                RechargeTimer.Update(time);
                if (!RechargeTimer.HasTriggered)
                {
                    return;
                }
                break;

            case AttackTrigger.Animation:
                if (performer.Sprite.CurrentAnimation == null ||
                    performer.Sprite.CurrentAnimation.CurrentFrame != TriggerFrame)
                {
                    return;
                }
                break;
            }

            if (Mode == AttackMode.Melee)
            {
                PlayNoise(pos);
                if (HitParticles != "")
                {
                    PlayState.ParticleManager.Trigger(HitParticles, pos, Color.White, 5);
                }


                if (HitAnimation != null)
                {
                    HitAnimation.Reset();
                    HitAnimation.Play();
                    IndicatorManager.DrawIndicator(HitAnimation, pos, 0.6f, 2.0f, MathFunctions.RandVector2Circle(), Color.White, MathFunctions.Rand() > 0.5f);
                }
            }
        }
Esempio n. 7
0
        public virtual void Update(DwarfTime time, VoxelSelector voxSelector, BodySelector bodySelector)
        {
            if (Recharges)
            {
                RechargeTimer.Update(time);
            }

            switch (Mode)
            {
            case SpellMode.Button:
                break;

            case SpellMode.Continuous:
                OnContinuousUpdate(time);
                break;

            case SpellMode.SelectEmptyVoxels:
                voxSelector.SelectionType = VoxelSelectionType.SelectEmpty;
                voxSelector.Enabled       = true;
                bodySelector.Enabled      = false;
                break;

            case SpellMode.SelectFilledVoxels:
                voxSelector.SelectionType = VoxelSelectionType.SelectFilled;
                voxSelector.Enabled       = true;
                bodySelector.Enabled      = false;
                break;

            case SpellMode.SelectEntities:
                bodySelector.Enabled = true;
                break;
            }

            if (!Recharges || RechargeTimer.HasTriggered)
            {
                World.ParticleManager.Trigger("star_particle", World.CursorLightPos + Vector3.Up * 0.5f, Color.White, 2);
            }
        }
 public ManuModel(Text name, Text description, Button button, Text cost)
 {
     _view  = new ManuView(name, description, button, cost);
     _timer = new RechargeTimer();
 }
Esempio n. 9
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);
        }
Esempio n. 10
0
        public IEnumerable <Act.Status> Perform(Creature performer, Vector3 pos, Voxel other, DwarfTime time, float bonus, string faction)
        {
            while (true)
            {
                if (other == null)
                {
                    yield return(Act.Status.Fail);

                    yield break;
                }

                switch (TriggerMode)
                {
                case AttackTrigger.Timer:
                    RechargeTimer.Update(time);
                    if (!RechargeTimer.HasTriggered)
                    {
                        yield return(Act.Status.Running);

                        continue;
                    }
                    break;

                case AttackTrigger.Animation:
                    if (performer.Sprite.CurrentAnimation == null ||
                        performer.Sprite.CurrentAnimation.CurrentFrame != TriggerFrame)
                    {
                        if (performer.Sprite.CurrentAnimation != null)
                        {
                            performer.Sprite.CurrentAnimation.Play();
                        }
                        yield return(Act.Status.Running);

                        continue;
                    }
                    break;
                }

                switch (Mode)
                {
                case AttackMode.Melee:
                {
                    other.Health -= DamageAmount + bonus;
                    PlayNoise(other.Position);
                    if (HitParticles != "")
                    {
                        PlayState.ParticleManager.Trigger(HitParticles, other.Position, Color.White, 5);
                    }

                    if (HitAnimation != null)
                    {
                        HitAnimation.Reset();
                        HitAnimation.Play();
                        IndicatorManager.DrawIndicator(HitAnimation.Clone(), other.Position + Vector3.One * 0.5f,
                                                       10.0f, 1.0f, MathFunctions.RandVector2Circle() * 10, HitColor, MathFunctions.Rand() > 0.5f);
                    }
                    break;
                }

                case AttackMode.Ranged:
                {
                    LaunchProjectile(pos, other.Position, null);
                    break;
                }
                }
                yield return(Act.Status.Success);

                yield break;
            }
        }
Esempio n. 11
0
 public ResearchModel(Text name, Text description, Button button, Text timerText)
 {
     _researchView = new ResearchView(name, description, button, timerText);
     _timer        = new RechargeTimer();
 }
Esempio n. 12
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);
        }
Esempio n. 13
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:
            {
                DoDamage(performer, other, bonus);
                break;
            }

            case AttackMode.Area:
            {
                BoundingBox box = new BoundingBox(performer.AI.Position - Vector3.One * Range, performer.AI.Position + Vector3.One * Range);
                foreach (var body in performer.World.EnumerateIntersectingObjects(box, CollisionType.Both))
                {
                    var creature = body.GetRoot().GetComponent <CreatureAI>();
                    if (creature == null)
                    {
                        var health = body.GetRoot().GetComponent <Health>();
                        if (health != null)
                        {
                            DoDamage(performer, body, bonus);
                        }
                        continue;
                    }
                    if (creature.Faction == performer.Faction)
                    {
                        continue;
                    }
                    var alliance = performer.World.Diplomacy.GetPolitics(creature.Faction, performer.Faction).GetCurrentRelationship() != Relationship.Hateful;
                    if (alliance)
                    {
                        continue;
                    }

                    DoDamage(performer, body, bonus);
                }
                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);
        }
Esempio n. 14
0
        public IEnumerable <Act.Status> PerformOnVoxel(Creature performer, Vector3 pos, KillVoxelTask DigAct, DwarfTime time, float bonus, string faction)
        {
            while (true)
            {
                if (!DigAct.Voxel.IsValid)
                {
                    yield return(Act.Status.Fail);

                    yield break;
                }

                Drawer2D.DrawLoadBar(performer.World.Camera, DigAct.Voxel.WorldPosition + Vector3.One * 0.5f, Color.White, Color.Black, 32, 1, (float)DigAct.VoxelHealth / DigAct.Voxel.Type.StartingHealth);

                switch (TriggerMode)
                {
                case AttackTrigger.Timer:
                    RechargeTimer.Update(time);
                    if (!RechargeTimer.HasTriggered)
                    {
                        yield return(Act.Status.Running);

                        continue;
                    }
                    break;

                case AttackTrigger.Animation:
                    if (!performer.Sprite.AnimPlayer.HasValidAnimation() ||
                        performer.Sprite.AnimPlayer.CurrentFrame < TriggerFrame)
                    {
                        if (performer.Sprite.AnimPlayer.HasValidAnimation())
                        {
                            performer.Sprite.AnimPlayer.Play();
                        }
                        yield return(Act.Status.Running);

                        continue;
                    }
                    break;
                }

                switch (Mode)
                {
                case AttackMode.Melee:
                {
                    DigAct.VoxelHealth -= (DamageAmount + bonus);

                    DigAct.Voxel.Type.HitSound.Play(DigAct.Voxel.WorldPosition);
                    if (HitParticles != "")
                    {
                        performer.Manager.World.ParticleManager.Trigger(HitParticles, DigAct.Voxel.WorldPosition, Color.White, 5);
                    }

                    if (HitAnimation != null)
                    {
                        IndicatorManager.DrawIndicator(HitAnimation, DigAct.Voxel.WorldPosition + Vector3.One * 0.5f,
                                                       10.0f, 1.0f, MathFunctions.RandVector2Circle() * 10, HitColor, MathFunctions.Rand() > 0.5f);
                    }

                    break;
                }

                case AttackMode.Ranged:
                {
                    throw new InvalidOperationException("Ranged attacks should never be used for digging.");
                    //LaunchProjectile(pos, DigAct.GetTargetVoxel().WorldPosition, null);
                    //break;
                }
                }
                yield return(Act.Status.Success);

                yield break;
            }
        }