/// <summary> /// Get an activity that will meet the goal /// </summary> /// <param name="motivator">the goal at hand</param> /// <returns>an activity to meet it</returns> public Accomplisher HowToDo(Motivator motivator) { short motivation = (short)motivator; Accomplisher todo = Accomplisher.Wander; Array activities = Enum.GetValues(typeof(Accomplisher)); if (activities.Length >= motivation) { todo = (Accomplisher)motivation; } return(todo); }
/// <summary> /// Add pressure to a need, can also be negative, wont go below zero /// </summary> /// <param name="need">the need to apply pressure to</param> /// <param name="amount">how much pressure</param> /// <returns>the highest current need after application</returns> public Motivator ApplyPressure(Motivator need, int amount) { Tuple <Motivator, int> currentNeed = Needs.FirstOrDefault(nd => nd.Item1 == need); if (currentNeed != null) { amount += currentNeed.Item2; Needs.Remove(currentNeed); } Needs.Add(new Tuple <Motivator, int>(need, Math.Max(0, amount))); return(Needs.OrderByDescending(nd => nd.Item2).FirstOrDefault().Item1); }
public void DoTheThing(Motivator motivator) { Accomplisher action = Hypothalamus.HowToDo(motivator); bool wander = false; switch (action) { case Accomplisher.Drink: IInanimate waterBottle = Inventory.EntitiesContained().FirstOrDefault(ent => ent.GetQuality("Water") > 0); if (waterBottle != null) { waterBottle.SetQuality(-1, "Water", true); Hypothalamus.ApplyPressure(Motivator.Thirst, -10); Exhaust(-10); } else { wander = true; } break; case Accomplisher.Eat: IInanimate food = Inventory.EntitiesContained().FirstOrDefault(ent => ent.GetQuality("Food") > 0); if (food != null) { //TODO: turn this into an eat command int foodValue = food.GetQuality("Food"); food.Remove(); Hypothalamus.ApplyPressure(Motivator.Hunger, -1 * foodValue); Harm(-1 * foodValue); } else { wander = true; } break; case Accomplisher.Sleep: //Can't sleep yet break; case Accomplisher.Speak: if (CurrentLocation.CurrentZone != null) { CurrentLocation.CurrentZone.BroadcastEvent("$A$ moos.", this); } break; case Accomplisher.Wander: wander = true; break; } if (wander) { Random rand = new Random(); MovementDirectionType direction = (MovementDirectionType)rand.Next(0, 7); //Run the command like anyone else //Interpret.Render(direction.ToString(), this); } }