예제 #1
0
        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));
        }
예제 #2
0
        public virtual bool Release(Thing thing)
        {
            this.Remove(thing);

            OnReleased(thing);
            return true;
        }
예제 #3
0
        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);
        }
예제 #4
0
 protected virtual bool WillAllowRelease(Thing destination, string location)
 {
     return true;
 }
예제 #5
0
        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);
        }
예제 #6
0
 protected void OnReleased(Thing releasedThing)
 {
     if (Released != null)
         Released(this, releasedThing);
 }
예제 #7
0
 protected void OnMoved(Thing destination)
 {
     if (Moved != null)
         Moved(this, destination);
 }
예제 #8
0
 public virtual bool WillRelease(Thing thing, string location)
 {
     return true;
 }
예제 #9
0
 public void Remove(Thing thing)
 {
     foreach (List<Thing> things in innerHash.Values)
         things.Remove(thing);
 }
예제 #10
0
        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;
        }
예제 #11
0
        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));
        }
예제 #12
0
 public static void MyAction(Thing doer, string actionString, params Thing[] things)
 {
     doer.Tell(PersonalAction(doer, actionString, things.ToList<Thing>()));
 }
예제 #13
0
        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;
        }
예제 #14
0
 public static string PersonalAction(Thing thing, string actionString, params Thing[] things)
 {
     return PersonalAction(thing, actionString, things.ToList<Thing>());
 }
예제 #15
0
 public virtual bool WillAccept(Thing thing, string location)
 {
     return true;
 }
예제 #16
0
        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);
        }
예제 #17
0
 public virtual bool WillRelease(Thing thing)
 {
     return true;
 }
예제 #18
0
 public Thing Clone()
 {
     Thing thing = new Thing();
     thing.Name = this.Name;
     thing.Inventory = this.Inventory.Clone();
     return thing;
 }
예제 #19
0
 protected void OnAccepted(Thing acceptedThing)
 {
     if (Accepted != null)
         Accepted(this, null);
 }
예제 #20
0
 public virtual string GetDescription(Thing observer)
 {
     return base.Description + "\n" + Inventory.GetDescription(observer);
 }
예제 #21
0
 protected void OnMoving(Thing destination)
 {
     if (Moving != null)
         Moving(this, destination);
 }
예제 #22
0
        /// <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;
        }
예제 #23
0
 protected void Remove(Thing thing)
 {
     locationMap.Remove(thing);
 }
예제 #24
0
 public virtual bool Move(Thing destination)
 {
     return Move(destination, destination.DefaultKey);
 }
예제 #25
0
 protected virtual bool WillAllowAccept(Thing destination, string location)
 {
     return true;
 }
예제 #26
0
        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;
        }
예제 #27
0
        private void Add(string location, Thing thing)
        {
            if (locationMap[location] == null)
                locationMap.Add(location);

            locationMap[location].Add(thing);
        }
예제 #28
0
        /*
        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);
        }