示例#1
0
        public Skill(SkillLeader leader)
        {
            if ((int)leader < 0 || (int)leader > Constants.EnumMaxAllowedValues.SkillLeader)
            {
                throw new ArgumentOutOfRangeException(nameof(leader), leader, "Must be defined in SkillLeader");
            }
            if (leader == SkillLeader.None)
            {
                throw new ArgumentException("Can't be None (0)", nameof(leader));
            }

            Leader = leader;
        }
示例#2
0
        private static SkillLeader CalculateLeader(List <CardDrawed> cards)
        {
            int         numberOfLeaders = 0;
            SkillLeader result          = SkillLeader.None;

            foreach (CardDrawed card in cards)
            {
                if (card.Ability.Leader != SkillLeader.None)
                {
                    result = card.Ability.Leader;
                    numberOfLeaders++;
                }
            }
            if (numberOfLeaders == 1)
            {
                return(result);
            }
            return(SkillLeader.None);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="id">Must be an existing id on the database</param>
        /// <returns></returns>
        public CardBase GetCardBase(int id)
        {
            if (id <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(id), id, "Must be greater than 0");
            }

            DataTable       table;
            SQLiteErrorCode returnCode;

            // Look up for CardLevel's
            SQLiteCommand command = new SQLiteCommand("SELECT * FROM cardlevel WHERE baseid == ? ORDER BY level;");

            command.Parameters.AddWithValue("@p1", id);
            returnCode = ExecuteSelect(command, FilepathManagerInstance.PersistentDatabase, out table);
            if (returnCode != SQLiteErrorCode.Ok)
            {
                throw new SQLiteException(returnCode, "Failed executing CardLevel SELECT");
            }

            // CardLevel's
            var levels = new List <CardLevel>();

            foreach (DataRow cardLevelRow in table.Rows)
            {
                int level  = Convert.ToInt32(cardLevelRow["level"]);
                int power  = Convert.ToInt32(cardLevelRow["power"]);
                int damage = Convert.ToInt32(cardLevelRow["damage"]);
                levels.Add(new CardLevel(level, power, damage));
            }

            // Look up for CardBase
            command = new SQLiteCommand("SELECT * FROM cardbase WHERE baseid == ?;");
            command.Parameters.AddWithValue("@p1", id);
            returnCode = ExecuteSelect(command, FilepathManagerInstance.PersistentDatabase, out table);
            if (returnCode != SQLiteErrorCode.Ok)
            {
                throw new SQLiteException(returnCode, "Failed executing CardBase SELECT");
            }
            DataRow row = table.Rows[0];

            // Clan
            ClanId clanid = (ClanId)Convert.ToInt32(row["clanid"]);
            Clan   clan   = Clan.GetClanById(clanid);

            // Ability
            Skill       ability;
            SkillLeader leader = (SkillLeader)Convert.ToInt32(row["leader"]);

            if (leader != SkillLeader.None)
            {
                ability = new Skill(leader);
            }
            else
            {
                SkillSuffix suffix = (SkillSuffix)Convert.ToInt32(row["suffix"]);
                if (suffix == SkillSuffix.None)
                {
                    ability = Skill.NoAbility;
                }
                else
                {
                    SkillPrefix prefix = (SkillPrefix)Convert.ToInt32(row["prefix"]);
                    int         x      = Convert.ToInt32(row["x"]);
                    int         y      = Convert.ToInt32(row["y"]);
                    ability = new Skill(prefix, suffix, x, y);
                }
            }

            // Other CardBase details
            string     name        = row["name"].ToString();
            int        minlevel    = Convert.ToInt32(row["minlevel"]);
            int        maxlevel    = Convert.ToInt32(row["maxlevel"]);
            int        unlocklevel = Convert.ToInt32(row["unlocklevel"]);
            CardRarity rarity      = (CardRarity)Convert.ToInt32(row["rarity"]);
            DateTime   releasedate = (Convert.ToDateTime(row["releasedate"]));

            return(new CardBase(id, name, clan, minlevel, maxlevel, levels, ability, unlocklevel, rarity, releasedate));
        }