Beispiel #1
0
        public override IEnumerable <Act.Status> Run()
        {
            List <ResourceAmount> foods =
                Agent.Creature.Inventory.GetResources(new Quantitiy <Resource.ResourceTags>(Resource.ResourceTags.Edible), Inventory.RestockType.Any);

            if (foods.Count == 0 && Agent.Creature.Faction == Agent.World.PlayerFaction)
            {
                yield return(Act.Status.Fail);

                yield break;
            }

            FoodBody = null;
            Timer eatTimer = new Timer(3.0f, true);

            foreach (ResourceAmount resourceAmount in foods)
            {
                if (resourceAmount.NumResources > 0)
                {
                    List <Body> bodies = Agent.Creature.Inventory.RemoveAndCreate(new ResourceAmount(resourceAmount.ResourceType, 1),
                                                                                  Inventory.RestockType.Any);
                    var resource = ResourceLibrary.GetResourceByName(resourceAmount.ResourceType);
                    Agent.Creature.NoiseMaker.MakeNoise("Chew", Agent.Creature.AI.Position);
                    if (bodies.Count == 0)
                    {
                        yield return(Act.Status.Fail);
                    }
                    else
                    {
                        FoodBody = bodies[0];


                        while (!eatTimer.HasTriggered)
                        {
                            eatTimer.Update(DwarfTime.LastTime);
                            Matrix rot = Agent.Creature.Physics.LocalTransform;
                            rot.Translation         = Vector3.Zero;
                            FoodBody.LocalTransform = Agent.Creature.Physics.LocalTransform;
                            Vector3 foodPosition = Agent.Creature.Physics.Position + Vector3.Up * 0.05f + Vector3.Transform(Vector3.Forward, rot) * 0.5f;
                            FoodBody.LocalPosition = foodPosition;
                            FoodBody.PropogateTransforms();
                            FoodBody.Active = false;
                            Agent.Creature.Physics.Velocity     = Vector3.Zero;
                            Agent.Creature.CurrentCharacterMode = CharacterMode.Sitting;
                            if (MathFunctions.RandEvent(0.05f))
                            {
                                Agent.Creature.World.ParticleManager.Trigger("crumbs", foodPosition, Color.White, 3);
                            }
                            yield return(Act.Status.Running);
                        }

                        Agent.Creature.Status.Hunger.CurrentValue += resource.FoodContent;
                        Agent.Creature.AddThought(Thought.ThoughtType.AteFood);
                        if (resource.Tags.Contains(Resource.ResourceTags.Alcohol))
                        {
                            Agent.Creature.AddThought(Thought.ThoughtType.HadAle);
                        }
                        FoodBody.GetRoot().Delete();
                        yield return(Act.Status.Success);
                    }
                    yield break;
                }
            }
        }