Example #1
0
        public GuildCreateStatus CreateGuild(string guildName, out DbGuild guild)
        {
            guild = null;

            if (string.IsNullOrWhiteSpace(guildName))
            {
                return(GuildCreateStatus.InvalidName);
            }

            guildName = guildName.Trim();

            var newGuildId = (int)_db.StringIncrement("nextGuildId");

            if (!_db.HashSet("guilds", guildName.ToUpperInvariant(), newGuildId, When.NotExists))
            {
                return(GuildCreateStatus.UsedName);
            }

            guild = new DbGuild(_db, newGuildId)
            {
                Name      = guildName,
                Level     = 0,
                Fame      = 0,
                TotalFame = 0
            };

            guild.FlushAsync();

            return(GuildCreateStatus.OK);
        }
Example #2
0
        public AddGuildMemberStatus AddGuildMember(DbGuild guild, DbAccount acc, bool founder = false)
        {
            if (acc == null)
            {
                return(AddGuildMemberStatus.Error);
            }

            if (acc.NameChosen == false)
            {
                return(AddGuildMemberStatus.NameNotChosen);
            }

            if (Convert.ToInt32(acc.GuildId) == guild.Id)
            {
                return(AddGuildMemberStatus.AlreadyInGuild);
            }

            if (Convert.ToInt32(acc.GuildId) > 0)
            {
                return(AddGuildMemberStatus.InAnotherGuild);
            }

            int guildSize = 100;

            if (guild.Members?.Length >= guildSize)
            {
                return(AddGuildMemberStatus.GuildFull);
            }

            if (guild.Members == null)
            {
                List <int> gfounder = new List <int>
                {
                    Convert.ToInt32(acc.AccountId)
                };
                guild.Members = gfounder.ToArray();
            }
            else
            {
                List <int> members = guild.Members.ToList();

                if (members.Contains(Convert.ToInt32(acc.AccountId)))
                {
                    return(AddGuildMemberStatus.IsAMember);
                }

                members.Add(Convert.ToInt32(acc.AccountId));
                guild.Members = members.ToArray();
            }

            guild.FlushAsync();

            acc.GuildId   = Convert.ToString(guild.Id);
            acc.GuildRank = (founder) ? 40 : 0;
            Update(acc);

            return(AddGuildMemberStatus.OK);
        }
Example #3
0
        public bool SetGuildBoard(DbGuild guild, string text)
        {
            if (guild.IsNull)
            {
                return(false);
            }

            guild.Board = text;
            guild.FlushAsync();
            return(true);
        }
Example #4
0
        public bool ChangeGuildLevel(DbGuild guild, int level)
        {
            if (level != 1 &&
                level != 2 &&
                level != 3)
            {
                return(false);
            }

            guild.Level = level;
            guild.FlushAsync();
            return(true);
        }