public static void MyAction(Thing doer, string actionString) { //Debug.WriteLineIf(MessagesSwitch.Verbose, "MyAction(Thing doer = '" + doer + "', string actionString = '" + actionString + "')", "Messages"); List<Thing> things = new List<Thing>(); things.Add(doer); doer.Tell(PersonalAction(doer, actionString, things)); }
public virtual bool Release(Thing thing) { this.Remove(thing); OnReleased(thing); return true; }
public static void OtherAction(Thing doer, string actionString, List<Thing> targets) { //Debug.WriteLineIf(MessagesSwitch.Verbose, "OtherAction(Thing doer = '" + doer + "', string actionString = '" + actionString + "', List<Thing> targets = '" + targets + "')", "Messages"); List<Thing> listeners = doer.GetObservers(); string message = PersonalAction(null, actionString, targets); foreach (Thing thing in listeners) if (targets.Contains(thing)) thing.Tell(PersonalAction(thing, actionString, targets)); else thing.Tell(message); }
protected virtual bool WillAllowRelease(Thing destination, string location) { return true; }
protected void Remove(Thing thing, string location) { if (this[location] == null) throw new Exception("Bad location"); if (!(this[location].Contains(thing))) return; this[location].Remove(thing); }
protected void OnReleased(Thing releasedThing) { if (Released != null) Released(this, releasedThing); }
protected void OnMoved(Thing destination) { if (Moved != null) Moved(this, destination); }
public virtual bool WillRelease(Thing thing, string location) { return true; }
public void Remove(Thing thing) { foreach (List<Thing> things in innerHash.Values) things.Remove(thing); }
public string GetDescription(Thing observer) { string output = ""; foreach (Inventory inventory in innerHash.Keys) { if ((inventory.Opacity & Opacity.In) == Opacity.None) continue; if (inventory.Name != "in") continue; List<Thing> things = (List<Thing>)innerHash[inventory]; if (things.Contains(observer)) { things = Thing.CloneList(things); things.Remove(observer); } if (things.Count == 0) continue; output += "You see " + Thing.IndefiniteStringsPrintable(things) + " here."; } return output; }
public static void MyAction(Thing doer, string actionString, List<Thing> targets) { //Debug.WriteLineIf(MessagesSwitch.Verbose, "MyAction(Thing doer = '" + doer + "', string actionString = '" + actionString + "', List<Thing> targets = '" + targets + "')", "Messages"); doer.Tell(PersonalAction(doer, actionString, targets)); }
public static void MyAction(Thing doer, string actionString, params Thing[] things) { doer.Tell(PersonalAction(doer, actionString, things.ToList<Thing>())); }
public static string PersonalAction(Thing thing, string actionString, List<Thing> things) { //Debug.WriteLineIf(MessagesSwitch.Verbose, "PersonalAction(Thing thing = '" + thing + "', string actionString = '" + actionString + "', List<Thing> things = '" + things + "')", "Messages"); //^vn MatchCollection matches = RegExps.verbs.Matches(actionString); foreach (Match match in matches) { string targetnum = match.Value.Substring(2); string verb = targetnum.Substring(2, match.Value.Length - 5); targetnum = targetnum.Substring(0, 1); int i = System.Int32.Parse(targetnum); if (things[i] == thing) verb = Verb.SecondPerson(verb); else verb = Verb.ThirdPerson(verb); actionString = actionString.Replace(match.Value, verb); } //^Vn matches = RegExps.Verbs.Matches(actionString); foreach (Match match in matches) { string targetnum = match.Value.Substring(2); string verb = targetnum.Substring(2, match.Value.Length - 5); targetnum = targetnum.Substring(0, 1); int i = System.Int32.Parse(targetnum); if (things[i] == thing) verb = Verb.SecondPerson(verb); else verb = Verb.ThirdPerson(verb); actionString = actionString.Replace(match.Value, Capitalize(verb)); } //^hn matches = RegExps.nominativePronouns.Matches(actionString); foreach (Match match in matches) { int i = System.Int32.Parse(match.Value.Substring(2)); if (things[i] == thing) { actionString = actionString.Replace(match.Value, "your"); continue; } actionString = actionString.Replace(match.Value, things[i].NominativePronoun); } //^Hn matches = RegExps.NominativePronouns.Matches(actionString); foreach (Match match in matches) { int i = System.Int32.Parse(match.Value.Substring(2)); if (things[i] == thing) { actionString = actionString.Replace(match.Value, "Your"); continue; } actionString = actionString.Replace(match.Value, Capitalize(things[i].NominativePronoun)); } //^pn matches = RegExps.possessivePronouns.Matches(actionString); foreach (Match match in matches) { int i = System.Int32.Parse(match.Value.Substring(2, match.Value.Length - 3)); if (things[i] == thing) { actionString = actionString.Replace(match.Value, "your"); continue; } actionString = actionString.Replace(match.Value, things[i].PossessivePronoun); } //^Pn matches = RegExps.PossessivePronouns.Matches(actionString); foreach (Match match in matches) { int i = System.Int32.Parse(match.Value.Substring(2, match.Value.Length - 3)); if (things[i] == thing) { actionString = actionString.Replace(match.Value, "Your"); continue; } actionString = actionString.Replace(match.Value, Capitalize(things[i].PossessivePronoun)); } //{o<n>} matches = RegExps.objects.Matches(actionString); foreach (Match match in matches) { int i = System.Int32.Parse(match.Value.Substring(2, match.Value.Length - 3)); if (things[i] == thing) { actionString = actionString.Replace(match.Value, "you"); continue; } actionString = actionString.Replace(match.Value, things[i].Name); } //^O matches = RegExps.Objects.Matches(actionString); foreach (Match match in matches) { int i = System.Int32.Parse(match.Value.Substring(2, match.Value.Length - 3)); if (things[i] == thing) { actionString = actionString.Replace(match.Value, "You"); continue; } actionString = actionString.Replace(match.Value, Capitalize(things[i].Name)); } //^dt matches = RegExps.definiteObjects.Matches(actionString); foreach (Match match in matches) { int i = System.Int32.Parse(match.Value.Substring(3, match.Value.Length - 4)); if (things[i] == thing) { actionString = actionString.Replace(match.Value, "you"); continue; } actionString = actionString.Replace(match.Value, things[i].DefiniteName); } //^Dt matches = RegExps.DefiniteObjects.Matches(actionString); foreach (Match match in matches) { int i = System.Int32.Parse(match.Value.Substring(3, match.Value.Length - 4)); if (things[i] == thing) { actionString = actionString.Replace(match.Value, "You"); continue; } actionString = actionString.Replace(match.Value, Capitalize(things[i].DefiniteName)); } //^it matches = RegExps.indefiniteObjects.Matches(actionString); foreach (Match match in matches) { int i = System.Int32.Parse(match.Value.Substring(3, match.Value.Length - 4)); if (things[i] == thing) { actionString = actionString.Replace(match.Value, "you"); continue; } actionString = actionString.Replace(match.Value, things[i].IndefiniteName); } //^It matches = RegExps.IndefiniteObjects.Matches(actionString); foreach (Match match in matches) { int i = System.Int32.Parse(match.Value.Substring(3, match.Value.Length - 4)); if (things[i] == thing) { actionString = actionString.Replace(match.Value, "You"); continue; } actionString = actionString.Replace(match.Value, Capitalize(things[i].IndefiniteName)); } //^dn matches = RegExps.dativePronouns.Matches(actionString); foreach (Match match in matches) { int i = System.Int32.Parse(match.Value.Substring(2)); if (things[i] == thing) { actionString = actionString.Replace(match.Value, "you"); continue; } actionString = actionString.Replace(match.Value, things[i].DativePronoun); } //^Dn matches = RegExps.DativePronouns.Matches(actionString); foreach (Match match in matches) { int i = System.Int32.Parse(match.Value.Substring(2)); if (things[i] == thing) { actionString = actionString.Replace(match.Value, "You"); continue; } actionString = actionString.Replace(match.Value, Capitalize(things[i].DativePronoun)); } //^rn matches = RegExps.reflexivePronouns.Matches(actionString); foreach (Match match in matches) { int i = System.Int32.Parse(match.Value.Substring(2)); if (things[i] == thing) { actionString = actionString.Replace(match.Value, "yourself"); continue; } actionString = actionString.Replace(match.Value, things[i].ReflexivePronoun); } //^Rn matches = RegExps.ReflexivePronouns.Matches(actionString); foreach (Match match in matches) { int i = System.Int32.Parse(match.Value.Substring(2)); if (things[i] == thing) { actionString = actionString.Replace(match.Value, "Yourself"); continue; } actionString = actionString.Replace(match.Value, Capitalize(things[i].ReflexivePronoun)); } //^sn matches = RegExps.possessiveNouns.Matches(actionString); foreach (Match match in matches) { int i = System.Int32.Parse(match.Value.Substring(2)); if (things[i] == thing) { actionString = actionString.Replace(match.Value, "your"); continue; } actionString = actionString.Replace(match.Value, things[i].PossessiveName); } //^Sn matches = RegExps.PossessiveNouns.Matches(actionString); foreach (Match match in matches) { int i = System.Int32.Parse(match.Value.Substring(2)); if (things[i] == thing) { actionString = actionString.Replace(match.Value, "Your"); continue; } actionString = actionString.Replace(match.Value, Capitalize(things[i].PossessiveName)); } //^sin matches = RegExps.possessiveIndefiniteNouns.Matches(actionString); foreach (Match match in matches) { int i = System.Int32.Parse(match.Value.Substring(3)); if (things[i] == thing) { actionString = actionString.Replace(match.Value, "your"); continue; } actionString = actionString.Replace(match.Value, things[i].PossessiveIndefiniteName); } //^Sin matches = RegExps.PossessiveIndefiniteNouns.Matches(actionString); foreach (Match match in matches) { int i = System.Int32.Parse(match.Value.Substring(3)); if (things[i] == thing) { actionString = actionString.Replace(match.Value, "Your"); continue; } actionString = actionString.Replace(match.Value, Capitalize(things[i].PossessiveIndefiniteName)); } //^sdn matches = RegExps.possessiveDefiniteNouns.Matches(actionString); foreach (Match match in matches) { int i = System.Int32.Parse(match.Value.Substring(3)); if (things[i] == thing) actionString = actionString.Replace(match.Value, "your"); else actionString = actionString.Replace(match.Value, things[i].PossessiveDefiniteName); } //^Sdn matches = RegExps.PossessiveDefiniteNouns.Matches(actionString); foreach (Match match in matches) { int i = System.Int32.Parse(match.Value.Substring(3)); if (things[i] == thing) actionString = actionString.Replace(match.Value, "Your"); else actionString = actionString.Replace(match.Value, Capitalize(things[i].PossessiveDefiniteName)); } actionString = Capitalize(actionString); return actionString; }
public static string PersonalAction(Thing thing, string actionString, params Thing[] things) { return PersonalAction(thing, actionString, things.ToList<Thing>()); }
public virtual bool WillAccept(Thing thing, string location) { return true; }
public virtual void Accept(Thing thing, string location) { thing.Container = this; thing.Locations = new List<string>(); thing.Locations.Add(location); this[location].Add(thing); OnAccepted(thing); }
public virtual bool WillRelease(Thing thing) { return true; }
public Thing Clone() { Thing thing = new Thing(); thing.Name = this.Name; thing.Inventory = this.Inventory.Clone(); return thing; }
protected void OnAccepted(Thing acceptedThing) { if (Accepted != null) Accepted(this, null); }
public virtual string GetDescription(Thing observer) { return base.Description + "\n" + Inventory.GetDescription(observer); }
protected void OnMoving(Thing destination) { if (Moving != null) Moving(this, destination); }
/// <summary> /// Gets the observers for the specified Thing. /// </summary> public virtual List<Thing> GetObserversFor(Thing thing) { List<Thing> output = new List<Thing>(); foreach (Thing otherThing in ShallowInventory) if (otherThing.IsObserver) if (otherThing != thing) output.Add(otherThing); return output; }
protected void Remove(Thing thing) { locationMap.Remove(thing); }
public virtual bool Move(Thing destination) { return Move(destination, destination.DefaultKey); }
protected virtual bool WillAllowAccept(Thing destination, string location) { return true; }
public virtual bool Move(Thing destination, string location) { if (destination[location] == null) destination.Add(location); //Chain of Responsibility... if (!WillAllowRelease(destination, location)) return false; if (container != null && !container.WillRelease(this)) return false; if (!destination.WillAccept(this, location)) return false; if (!WillAllowAccept(destination, location)) return false; //End of Chain OnMoving(destination); if (container != null) container.Release(this); destination.Accept(this, location); OnMoved(destination); return true; }
private void Add(string location, Thing thing) { if (locationMap[location] == null) locationMap.Add(location); locationMap[location].Add(thing); }
/* public static void ExecuteMyVerbalAction(Thing doer, string actionString, string garbleString, params Thing[] Things) { Action action = new Action(doer, actionString, garbleString, Things); action.ExecuteFirst(); }*/ /// <summary> /// Broadcasts an action to all observers except the doer of the action. /// </summary> public static void OtherAction(Thing doer, string actionString) { List<Thing> things = new List<Thing>(); things.Add(doer); List<Thing> listeners = doer.Container.GetObserversFor(doer); string message = PersonalAction(null, actionString, things); foreach (Thing thing in listeners) thing.Tell(message); }