public CardDrawedViewSample()
        {
            int              baseId     = 123;
            Clan             clan       = Clan.GetClanById(ClanId.Raptors);
            string           cardName   = "Tester";
            Skill            ability    = new Skill(SkillPrefix.Courage, SkillSuffix.DecreasePillzXMinY, 2, 3);
            int              minLevel   = 2;
            int              maxLevel   = 4;
            List <CardLevel> cardLevels = new List <CardLevel>
            {
                new CardLevel(2, 2, 3),
                new CardLevel(3, 3, 4),
                new CardLevel(4, 6, 5),
            };
            int        abilityUnlockLevel = 3;
            CardRarity rarity             = CardRarity.Legendary;
            int        currentLevel       = 4;
            int        instanceId         = 222;


            CardBase     cardBase     = new CardBase(baseId, cardName, clan, minLevel, maxLevel, cardLevels, ability, abilityUnlockLevel, rarity);
            CardInstance cardInstance = new CardInstance(cardBase, instanceId, currentLevel);

            card = new CardDrawed(cardInstance);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a new instance of <see cref="CardBase"/> using server data.
        /// </summary>
        /// <remark>This method does not do data validation. Parameter names on this function (except <paramref name="cardLevels"/>) use the nomenclature used by the API call "characters.getCharacters" </remark>
        /// <param name="id">Unique identifier of the card.</param>
        /// <param name="name">Name. If this ends in " Rb" it will override <paramref name="rarity"/> and will set it to <seealso cref="UrbanRivalsCore.Model.CardRarity.Rebirth"/>.</param>
        /// <param name="clan_id">Unique identifier of the clan.</param>
        /// <param name="level_min">Level at which the card starts.</param>
        /// <param name="level_max">Maximum level the card can achieve.</param>
        /// <param name="rarity">Rarity.</param>
        /// <param name="ability">Ability text.</param>
        /// <param name="ability_unlock_level">Level at which the card unlocks its ability.</param>
        /// <param name="release_date">Release date of the card.</param>
        /// <param name="cardLevels">Levels of the cards. This must be fabricated using the server data.</param>
        /// <returns></returns>
        public static CardBase ToCardBase(int id, string name, int clan_id, int level_min, int level_max, string rarity, string ability, int ability_unlock_level, int release_date, List <CardLevel> cardLevels)
        {
            if (ability.Contains("Day:") || ability.Contains("Night:"))
            {
                return(null);                                                        // TODO: Remove this line if day/night is implemented, or after 11/2018, whatever happens first
            }
            var parsedClan        = Clan.GetClanById((ClanId)clan_id);
            var parsedAbility     = ParseAbility(ability);
            var parsedRarity      = ParseRarity(rarity);
            var parsedReleaseDate = ParseReleaseDate(release_date);

            // UR says that Rebirth cards have "common" rarity, and I feel like breaking the law ;)
            if (name.EndsWith(" Rb"))
            {
                parsedRarity = CardRarity.Rebirth;
            }

            if (ability == null)
            {
                return(null);                 // TODO: Remove this line if double prefix is implemented, or after 11/2018, whatever happens first
            }
            return(new CardBase(id, name, parsedClan, level_min, level_max, cardLevels, parsedAbility, ability_unlock_level, parsedRarity, parsedReleaseDate));
        }
        /// <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));
        }