protected override IInteraction Apply(HengeInteraction interaction) { if (!interaction.Finished && this.Validate(interaction)) { Item food = interaction.Antagonist as Item; Actor actor = interaction.Protagonist as Actor; double nutrition = food.Traits["Nutrition"].Value; if (nutrition > 0) { interaction.Success(string.Format("You eat the {0} with relish", food.Inspect(actor))); } else { if (nutrition == 0) interaction.Success(string.Format("You eat the {0}", food.Inspect(actor))); else interaction.Success(string.Format("You eat the {0}. You feel queasy.", food.Inspect(actor))); } if (food.Owner == actor) { Trait weight = actor.Traits["Weight"]; Trait constitution = actor.Traits["Constitution"]; using (interaction.Lock(actor.Inventory, weight, constitution)) { weight.SetValue(weight.Value - food.Traits["Weight"].Value); constitution.SetValue(constitution.Value + nutrition); actor.Inventory.Remove(food); } interaction.Delete(food); } else interaction.Failure("You no longer have that", true); } return interaction; }
private void AddTracks(Location location, Actor actor, bool inbound, string flavour, double strength, HengeInteraction interaction) { IList<Trait> list = inbound? location.TracesIn : location.TracesOut; foreach(Trait track in list) { if ((DateTime)(track.Expiry) >= DateTime.Now) { list.Remove(track); interaction.Delete(track); } } if (strength > 0) { if (list.Count >= Constants.MaximumTracks) { Constants.Randomise(list); Trait overwritten = list[0]; list.RemoveAt(0); interaction.Delete(overwritten); } list.Add(new Trait(Constants.MaximumTrackValue, 0, strength){ Subject=actor, Flavour = flavour, Expiry = DateTime.Now + Constants.TraceLife }); } }