Exemplo n.º 1
0
 internal override void PostInitialize()
 {
     Modules.Roles = this;
     Debug.WriteLine("Loading role definitions.");
     foreach (var f in (from file in Directory.EnumerateFiles(@"data/definitions/roles", "*.json", SearchOption.AllDirectories) select new { File = file }))
     {
         Debug.WriteLine($"- Loading role definition {f.File}.");
         try
         {
             JObject            r               = JObject.Parse(File.ReadAllText(f.File));
             string             roleName        = (string)r["name"];
             string             roleDescription = (string)r["description"];
             List <GameCommand> roleCommands    = new List <GameCommand>();
             foreach (string cmd in r["commands"].Select(t => (string)t).ToList())
             {
                 GameCommand _cmd = Modules.Commands.Get(cmd);
                 if (_cmd != null)
                 {
                     if (!roleCommands.Contains(_cmd))
                     {
                         roleCommands.Add(_cmd);
                     }
                 }
                 else
                 {
                     Debug.WriteLine($"Could not find command '{cmd}' for role '{roleName}'.");
                 }
             }
             GameRole role = new GameRole(roleName, roleDescription, roleCommands);
             roles.Add(role.name.ToLower(), role);
         }
         catch (Exception e)
         {
             Debug.WriteLine($"Exception when loading role from file {f.File} - {e.Message}");
         }
     }
     Debug.WriteLine("Done.");
 }