public override void Do(Entity entity) { moveTime++; moveAction.Do(entity); // GotoAction checks collision with destination and hitting walls. bool result = moveAction.IsActive; if (moveTime == changeCount) // Change directions after a set time. { moveTime = 0; double d = Utilities.Rng.NextDouble(); if (d < changeProbability) { // Applies goto to set direction to (x, y). Goto applies Move(). False means the entity hit a wall and needs to head to another square. destination = Utilities.GetRandomPoint(); moveAction = new GotoAction(destination.X, destination.Y, entitySize); } else if (d > 0.75) { entity.Stop(); } } // The entity has hit a wall or reached the destination. else if (!result && entity.CollisionDirection != Direction.None) { destination = Utilities.GetDirectionalPoint(entity.CollisionDirection, entity.Position); moveAction = new GotoAction(destination.X, destination.Y, entitySize); } //entity.ApplyNeedDeltas(UtilityDeltas); // Advertise needs deltas to entities but don't actually give them the reward. This is for a default action. }
// May or may not work. Requires some workarounds for getting food count from EntityController using events. // Entity requests food but may not get it. This will create behavior where the entity starves to death on the house waiting for food. public override void Do(Entity entity) { if (entity is Person person) { if (person.GetItemCount(ItemType.Apple) > 0) { person.Eat(); // Applies hunger adjustment manually. } else if (appleRequested) // Person tried requesting food but failed. { End(); } else { gotoAction.Do(entity); if (!gotoAction.IsActive) // The person has reached the house. { if (!appleRequested) { person.RequestItemByType(ItemType.Apple); appleRequested = true; } else if (!meatRequested) { person.RequestItemByType(ItemType.Meat); meatRequested = true; } } } } else { End(); } }
public override void Do(Entity entity) { moveAction.Do(entity); if (!moveAction.IsActive) // If the entity has reached the item and picked it up. { pickup.TakeAmount(pickup.Amount); End(); } }
public override void Do(Entity entity) { if (!moveActionSet) { // Cannot set the move action in the constructor because the pickup's position might change after creating the pickup. // The PickupAction is created when the Item is constructed to avoid creating a new object every time a pickup advertises an action. moveAction = new GotoAction(target.Position.X, target.Position.Y, entitySize); moveActionSet = true; } else { if (entity is Person person) { // Once an entity decides to pickup an item, it must pick it up if it is still available. // This is forced to make the food gathering behavior more aggressive. I should be able to fix this with the action utilities though. if (!person.ActionLocked) { person.SetActionLockState(true); } if (target.IsPickedUp) { End(); return; } moveAction.Do(entity); if (!moveAction.IsActive) // If the entity has reached the item and picked it up. { person.Pickup(target); entity.ApplyNeedDeltas(UtilityDeltas); End(); } } else { End(); } } }
public override void Do(Entity entity) { if (entity is Person person) { //if (person.ActionLocked) // person.SetActionLockState(true); moveAction.Do(entity); RectangleF entityRectangle = entity.GetRectangleF(); if (entityRectangle.IntersectsWith(home)) // person has reached the house. { person.ApplyNeedDeltas(UtilityDeltas); person.DropAllItems(true); End(); } } else { End(); } }