コード例 #1
0
        public virtual void RemoveVoxel(Voxel voxel)
        {
            Voxel toRemove = Voxels.FirstOrDefault(store => store.Equals(voxel));

            if (toRemove == null)
            {
                return;
            }

            Voxels.Remove(toRemove);

            if (ReplaceVoxelTypes)
            {
                toRemove.Kill();
            }

            RecalculateMaxResources();
        }
コード例 #2
0
        public static IEnumerable <Act.Status> Dig(this Creature agent, string voxel, float energyLoss)
        {
            Vector3 LocalTarget = agent.AI.Position;

            agent.Sprite.ResetAnimations(Creature.CharacterMode.Attacking);
            while (true)
            {
                agent.CurrentCharacterMode = Creature.CharacterMode.Attacking;
                Voxel blackBoardVoxel = agent.AI.Blackboard.GetData <Voxel>(voxel);

                if (blackBoardVoxel == null)
                {
                    agent.DrawIndicator(IndicatorManager.StandardIndicators.Question);
                    yield return(Act.Status.Fail);

                    break;
                }

                Voxel vox = blackBoardVoxel;
                if (vox.Health <= 0.0f || !agent.Faction.IsDigDesignation(vox))
                {
                    agent.AI.AddXP(Math.Max((int)(VoxelLibrary.GetVoxelType(blackBoardVoxel.TypeName).StartingHealth / 4), 1));
                    if (vox.Health <= 0.0f)
                    {
                        vox.Kill();
                    }
                    agent.Stats.NumBlocksDestroyed++;
                    agent.CurrentCharacterMode = Creature.CharacterMode.Idle;
                    yield return(Act.Status.Success);

                    break;
                }
                agent.Physics.Face(vox.Position + Vector3.One * 0.5f);
                agent.Physics.Velocity *= 0.9f;
                agent.Attacks[0].Perform(agent.Physics.Position, vox, DwarfTime.LastTime, agent.Stats.BaseDigSpeed, agent.Faction.Name);
                yield return(Act.Status.Running);
            }
        }
コード例 #3
0
        public void Update(DwarfTime time)
        {
            RoomBuilder.Faction  = this;
            CraftBuilder.Faction = this;
            WallBuilder.Faction  = this;
            RoomBuilder.CheckRemovals();

            Minions.RemoveAll(m => m.IsDead);
            SelectedMinions.RemoveAll(m => m.IsDead);
            Minions.ForEach(m =>
            {
                m.Creature.SelectionCircle.IsVisible = false;
                m.Creature.Sprite.DrawSilhouette     = false;
            });
            SelectedMinions.ForEach(m => {
                m.Creature.SelectionCircle.IsVisible = true;
                m.Creature.Sprite.DrawSilhouette     = true;
            }

                                    );

            // Turned off until a non-O(n^2) collision method is create.
            //CollideMinions(time);

            List <ulong> removalKeys = new List <ulong>();

            foreach (KeyValuePair <ulong, BuildOrder> kvp in DigDesignations)
            {
                Voxel v = kvp.Value.Vox;
                if (v.IsEmpty || v.Health <= 0.0f || v.Type.Name == "empty" || v.Type.IsInvincible)
                {
                    removalKeys.Add(kvp.Key);
                }
            }

            for (int i = 0; i < removalKeys.Count; i++)
            {
                DigDesignations.Remove(removalKeys[i]);
            }

            List <Body> gatherRemovals = (from b in GatherDesignations
                                          where b == null || b.IsDead
                                          select b).ToList();

            foreach (Body b in gatherRemovals)
            {
                GatherDesignations.Remove(b);
            }


            List <BuildOrder> removals = new List <BuildOrder>();

            foreach (BuildOrder d in GuardDesignations)
            {
                Voxel v = d.Vox;

                if (!v.IsEmpty && !(v.Health <= 0.0f) && v.Type.Name != "empty")
                {
                    continue;
                }

                removals.Add(d);

                if (!v.IsEmpty)
                {
                    v.Kill();
                }
            }

            foreach (BuildOrder v in removals)
            {
                GuardDesignations.Remove(v);
            }

            List <Body> treesToRemove = ChopDesignations.Where(tree => tree.IsDead).ToList();

            foreach (Body tree in treesToRemove)
            {
                ChopDesignations.Remove(tree);
            }

            List <Body> attacksToRemove = AttackDesignations.Where(body => body.IsDead).ToList();

            foreach (Body body in attacksToRemove)
            {
                AttackDesignations.Remove(body);
            }

            HandleThreats();
        }
コード例 #4
0
        public void Update(DwarfTime time)
        {
            RoomBuilder.CheckRemovals();

            Minions.RemoveAll(m => m.IsDead);
            SelectedMinions.RemoveAll(m => m.IsDead);

            CollideMinions(time);

            List <BuildOrder> removals = (from d in DigDesignations
                                          let vref = d.Vox
                                                     let v = vref
                                                             where v.IsEmpty || v.Health <= 0.0f || v.Type.Name == "empty" || v.Type.IsInvincible
                                                             select d).ToList();

            foreach (BuildOrder v in removals)
            {
                DigDesignations.Remove(v);
            }

            List <Body> gatherRemovals = (from b in GatherDesignations
                                          where b == null || b.IsDead
                                          select b).ToList();

            foreach (Body b in gatherRemovals)
            {
                GatherDesignations.Remove(b);
            }


            removals.Clear();
            foreach (BuildOrder d in GuardDesignations)
            {
                Voxel v = d.Vox;

                if (!v.IsEmpty && !(v.Health <= 0.0f) && v.Type.Name != "empty")
                {
                    continue;
                }

                removals.Add(d);

                if (!v.IsEmpty)
                {
                    v.Kill();
                }
            }

            foreach (BuildOrder v in removals)
            {
                GuardDesignations.Remove(v);
            }

            List <Body> treesToRemove = ChopDesignations.Where(tree => tree.IsDead).ToList();

            foreach (Body tree in treesToRemove)
            {
                ChopDesignations.Remove(tree);
            }

            List <Body> attacksToRemove = AttackDesignations.Where(body => body.IsDead).ToList();

            foreach (Body body in attacksToRemove)
            {
                AttackDesignations.Remove(body);
            }

            HandleThreats();
        }
コード例 #5
0
        /// <summary>
        /// This is the underlying Dig behavior that dwarves follow while digging.
        /// </summary>
        /// <param name="agent">The agent.</param>
        /// <param name="voxel">The voxel.</param>
        /// <param name="energyLoss">The energy loss the dwarf gets per block mined.</param>
        /// <returns>Success when the block is mined, fail if it fails to be mined, and running otherwise.</returns>
        public static IEnumerable <Act.Status> Dig(this Creature agent, string voxel, float energyLoss)
        {
            agent.Sprite.ResetAnimations(Creature.CharacterMode.Attacking);

            // Block since we're in a coroutine.
            while (true)
            {
                // Get the voxel stored in the agent's blackboard.
                Voxel blackBoardVoxel = agent.AI.Blackboard.GetData <Voxel>(voxel);

                // Somehow, there wasn't a voxel to mine.
                if (blackBoardVoxel == null)
                {
                    agent.DrawIndicator(IndicatorManager.StandardIndicators.Question);
                    yield return(Act.Status.Fail);

                    break;
                }

                Voxel vox = blackBoardVoxel;

                // If the voxel has already been destroyed, just ignore it and return.
                if (vox.Health <= 0.0f || !agent.Faction.IsDigDesignation(vox))
                {
                    agent.CurrentCharacterMode = Creature.CharacterMode.Idle;
                    yield return(Act.Status.Success);

                    break;
                }

                // Look at the block and slow your velocity down.
                agent.Physics.Face(vox.Position + Vector3.One * 0.5f);
                agent.Physics.Velocity *= 0.9f;

                // Play the attack animations.
                agent.CurrentCharacterMode = Creature.CharacterMode.Attacking;
                agent.Sprite.ResetAnimations(agent.CurrentCharacterMode);
                agent.Sprite.PlayAnimations(agent.CurrentCharacterMode);

                // Wait until an attack was successful...
                foreach (var status in
                         agent.Attacks[0].Perform(agent,
                                                  agent.Physics.Position,
                                                  vox, DwarfTime.LastTime,
                                                  agent.Stats.BaseDigSpeed,
                                                  agent.Faction.Name))
                {
                    if (status == Act.Status.Running)
                    {
                        agent.Physics.Face(vox.Position + Vector3.One * 0.5f);
                        agent.Physics.Velocity *= 0.9f;

                        // Debug drawing.
                        if (agent.AI.DrawPath)
                        {
                            Drawer3D.DrawLine(vox.Position, agent.AI.Position, Color.Green, 0.25f);
                        }
                        yield return(Act.Status.Running);
                    }
                }

                // If the voxel has been destroyed by you, gather it.
                if (vox.Health <= 0.0f)
                {
                    List <Body> items = vox.Kill();

                    if (items != null)
                    {
                        foreach (Body item in items)
                        {
                            agent.Gather(item);
                        }
                    }
                    agent.AI.AddXP(Math.Max((int)(VoxelLibrary.GetVoxelType(blackBoardVoxel.TypeName).StartingHealth / 4), 1));
                    agent.Stats.NumBlocksDestroyed++;
                }

                // Wait until the animation is done playing before continuing.
                while (!agent.Sprite.CurrentAnimation.IsDone() && agent.Sprite.CurrentAnimation.IsPlaying)
                {
                    agent.Physics.Face(vox.Position + Vector3.One * 0.5f);
                    agent.Physics.Velocity *= 0.9f;
                    yield return(Act.Status.Running);
                }

                // Pause the animation and wait for a recharge timer.
                agent.Sprite.PauseAnimations(agent.CurrentCharacterMode);


                // Wait for a recharge timer to trigger.
                agent.Attacks[0].RechargeTimer.Reset();
                while (!agent.Attacks[0].RechargeTimer.HasTriggered)
                {
                    agent.Attacks[0].RechargeTimer.Update(DwarfTime.LastTime);
                    agent.Physics.Face(vox.Position + Vector3.One * 0.5f);
                    agent.Physics.Velocity *= 0.9f;
                    yield return(Act.Status.Running);
                }

                agent.CurrentCharacterMode = Creature.CharacterMode.Idle;

                yield return(Act.Status.Running);
            }
        }