コード例 #1
0
        public override IEnumerable <Status> Run()
        {
            if (!Creature.Faction.WallBuilder.IsDesignation(Voxel))
            {
                yield return(Status.Fail);

                yield break;
            }

            foreach (Status status in Creature.HitAndWait(1.0f, true))
            {
                if (status == Status.Running)
                {
                    yield return(status);
                }
            }

            Body grabbed = Creature.Inventory.RemoveAndCreate(Resource).FirstOrDefault();

            if (grabbed == null)
            {
                yield return(Status.Fail);

                yield break;
            }
            else
            {
                if (Creature.Faction.WallBuilder.IsDesignation(Voxel))
                {
                    TossMotion motion = new TossMotion(1.0f, 2.0f, grabbed.LocalTransform, Voxel.Position + new Vector3(0.5f, 0.5f, 0.5f));
                    motion.OnComplete += grabbed.Die;
                    grabbed.AnimationQueue.Add(motion);

                    WallBuilder put = Creature.Faction.WallBuilder.GetDesignation(Voxel);
                    put.Put(PlayState.ChunkManager);


                    Creature.Faction.WallBuilder.Designations.Remove(put);
                    Creature.Stats.NumBlocksPlaced++;
                    Creature.AI.AddXP(1);
                    yield return(Status.Success);
                }
                else
                {
                    Creature.Inventory.Resources.AddItem(grabbed);
                    grabbed.Die();

                    yield return(Status.Fail);
                }
            }
        }
コード例 #2
0
        public override IEnumerable <Status> Run()
        {
            if (!Creature.Faction.WallBuilder.IsDesignation(Voxel))
            {
                yield return(Status.Fail);

                yield break;
            }

            foreach (Status status in Creature.HitAndWait(1.0f, true, Voxel.Position))
            {
                if (status == Status.Running)
                {
                    yield return(status);
                }
            }

            Body grabbed = Creature.Inventory.RemoveAndCreate(Resource).FirstOrDefault();

            if (grabbed == null)
            {
                yield return(Status.Fail);

                yield break;
            }
            else
            {
                if (Creature.Faction.WallBuilder.IsDesignation(Voxel))
                {
                    // If the creature intersects the box, find a voxel adjacent to it that is free, and jump there to avoid getting crushed.
                    if (Creature.Physics.BoundingBox.Intersects(Voxel.GetBoundingBox()))
                    {
                        List <Voxel> neighbors   = Voxel.Chunk.GetNeighborsEuclidean(Voxel);
                        Voxel        closest     = null;
                        float        closestDist = float.MaxValue;
                        foreach (Voxel voxel in neighbors)
                        {
                            float dist = (voxel.Position - Creature.Physics.Position).LengthSquared();
                            if (dist < closestDist && voxel.IsEmpty)
                            {
                                closestDist = dist;
                                closest     = voxel;
                            }
                        }

                        if (closest != null)
                        {
                            TossMotion teleport = new TossMotion(0.5f, 1.0f, Creature.Physics.GlobalTransform, closest.Position + Vector3.One * 0.5f);
                            Creature.Physics.AnimationQueue.Add(teleport);
                        }
                    }
                    TossMotion motion = new TossMotion(1.0f, 2.0f, grabbed.LocalTransform, Voxel.Position + new Vector3(0.5f, 0.5f, 0.5f));
                    motion.OnComplete += grabbed.Die;
                    grabbed.GetComponent <Physics>().CollideMode = Physics.CollisionMode.None;
                    grabbed.AnimationQueue.Add(motion);

                    WallBuilder put = Creature.Faction.WallBuilder.GetDesignation(Voxel);
                    put.Put(Creature.Manager.World.ChunkManager);


                    Creature.Faction.WallBuilder.Designations.Remove(put);
                    Creature.Stats.NumBlocksPlaced++;
                    Creature.AI.AddXP(1);
                    yield return(Status.Success);
                }
                else
                {
                    Creature.Inventory.Resources.AddItem(grabbed);
                    grabbed.Die();

                    yield return(Status.Fail);
                }
            }
        }