Пример #1
0
 internal override void Initialize()
 {
     Modules.Gender = this;
     Debug.WriteLine($"- Loading gender definitions.");
     foreach (var f in (from file in Directory.EnumerateFiles(@"data/definitions/genders", "*.json", SearchOption.AllDirectories) select new { File = file }))
     {
         Debug.WriteLine($"- Loading gender definition {f.File}.");
         try
         {
             Dictionary <string, string> genderStrings = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText(f.File));
             GenderObject gender = new GenderObject();
             gender.He   = genderStrings["He"];
             gender.Him  = genderStrings["Him"];
             gender.His  = genderStrings["His"];
             gender.Is   = genderStrings["Is"];
             gender.Term = genderStrings["Term"];
             gender.Self = genderStrings["Self"];
             genders.Add(gender.Term, gender);
             foreach (string token in new List <string>()
             {
                 gender.He, gender.Him, gender.His, gender.Is, gender.Self
             })
             {
                 if (!Tokens.Contains(token))
                 {
                     Tokens.Add(token);
                 }
             }
         }
         catch (Exception e)
         {
             Debug.WriteLine($"Exception when loading gender from file {f.File} - {e.Message}");
         }
     }
     // 'it' is useless as it is ambiguous, just get rid of it.
     if (Tokens.Contains("it"))
     {
         Tokens.Remove("it");
     }
     Debug.WriteLine($"Done.");
 }
Пример #2
0
        internal void CmdSet(GameObject invoker, CommandData cmd)
        {
            if (cmd.objTarget == null || cmd.strArgs.Length < 3)
            {
                invoker.SendLine("Usage: SET <target> <field> <value>");
                return;
            }
            GameObject editing = invoker.FindGameObjectNearby(cmd.objTarget);

            if (editing == null)
            {
                invoker.SendLine("Cannot find object to modify.");
                return;
            }

            // Do the actual edit.
            string field = cmd.strArgs[1].ToLower();
            string value = "";

            for (int i = 2; i < cmd.strArgs.Length; i++)
            {
                value += $" {cmd.strArgs[i]}";
            }
            value = value.Trim();

            string lastVal      = "";
            string newVal       = value;
            string invalidValue = null;
            bool   unknownValue = false;

            switch (field)
            {
            case "name":
                lastVal      = editing.name;
                editing.name = value;
                break;

            case "gender":
                lastVal = $"{editing.gender.Term}";
                GenderObject newGender = Modules.Gender.GetByTerm(value);
                if (newGender == null)
                {
                    invalidValue = "Non-existent gender.";
                }
                else
                {
                    editing.gender = newGender;
                    newVal         = $"{editing.gender.Term}";
                }
                break;

            default:
                unknownValue = true;
                foreach (KeyValuePair <string, GameComponent> comp in editing.components)
                {
                    if (Modules.Components.builders[comp.Key].editableFields != null &&
                        Modules.Components.builders[comp.Key].editableFields.Contains(field))
                    {
                        unknownValue = false;
                        lastVal      = comp.Value.GetString(field);
                        invalidValue = comp.Value.SetValueOfEditableField(field, value);
                        newVal       = comp.Value.GetString(field);
                    }
                }
                break;
            }

            if (unknownValue)
            {
                invoker.WriteLine($"Unknown field '{field}' of object {editing.name}#{editing.id} ({editing.GetShort()}). Check that the object has the component and field that you are trying to edit.");
            }
            else if (invalidValue != null)
            {
                if (invalidValue != "")
                {
                    invoker.WriteLine($"Invalid value '{value}' for field '{field}' of object {editing.name}#{editing.id} ({editing.GetShort()}). {invalidValue}");
                }
                else
                {
                    invoker.WriteLine($"Invalid value '{value}' for field '{field}' of object {editing.name}#{editing.id} ({editing.GetShort()}).");
                }
            }
            else
            {
                invoker.WriteLine($"Set field '{field}' of object {editing.name}#{editing.id} ({editing.GetShort()}) to '{newVal}'.\nFor reference, previous value was '{lastVal}'.");
            }
            invoker.SendPrompt();
        }
Пример #3
0
 internal GameObject()
 {
     contents   = new List <GameObject>();
     components = new Dictionary <string, GameComponent>();
     gender     = Modules.Gender.GetByTerm(Text.GenderInanimate);
 }