Пример #1
0
        internal override void InstantiateFromRecord(SQLiteDataReader reader, SQLiteConnection dbConnection)
        {
            PlayerAccount acct = (PlayerAccount)CreateRepositoryType((long)reader["id"]);

            acct.userName     = reader["userName"].ToString();
            acct.passwordHash = reader["passwordHash"].ToString();
            acct.objectId     = (long)reader["objectId"];
            foreach (string role in JsonConvert.DeserializeObject <List <string> >(reader["roles"].ToString()))
            {
                GameRole foundRole = Modules.Roles.GetRole(role);
                if (foundRole != null && !acct.roles.Contains(foundRole))
                {
                    acct.roles.Add(foundRole);
                }
            }
            accounts.Add(acct.userName, acct);
            contents.Add(acct.id, acct);
        }
Пример #2
0
        internal void CmdAddrole(GameObject invoker, CommandData cmd)
        {
            if (cmd.objTarget == null)
            {
                invoker.WriteLine("Who do you wish to view the roles of?", true);
                return;
            }
            else if (cmd.strArgs.Length < 1)
            {
                invoker.WriteLine("Which role do you wish to add?", true);
                return;
            }

            PlayerAccount acct = Game.Accounts.FindAccount(cmd.objTarget);

            if (acct == null)
            {
                invoker.WriteLine($"Cannot find account for '{cmd.objTarget}'.", true);
                return;
            }

            GameRole role = Modules.Roles.GetRole(cmd.strArgs[0].ToLower());

            if (role == null)
            {
                invoker.WriteLine($"Cannot find role for '{cmd.strArgs[0]}'.");
            }
            else if (acct.roles.Contains(role))
            {
                invoker.WriteLine($"They already have that role.");
            }
            else
            {
                acct.roles.Add(role);
                Game.Accounts.QueueForUpdate(acct);
                invoker.WriteLine($"Added role '{role.name}' to '{acct.userName}'.");
            }
            invoker.SendPrompt();
        }
Пример #3
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.");
 }