Пример #1
0
        /// <summary>Loads all <see cref="Guild"/>s from the database.</summary>
        /// <returns>All <see cref="Guild"/>s</returns>
        public async Task <List <Guild> > LoadGuilds()
        {
            DataSet ds = await SQLiteHelper.FillDataSet(_con, "SELECT * FROM Guilds");

            List <Guild> allGuilds = new List <Guild>();

            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    Guild   newGuild  = new Guild(Int32Helper.Parse(dr["ID"]), dr["GuildName"].ToString(), dr["Guildmaster"].ToString(), dr["DefaultGuildmaster"].ToString(), Int32Helper.Parse(dr["GuildFee"]), Int32Helper.Parse(dr["GuildGold"]), new List <string>(), new Henchmen(Int32Helper.Parse(dr["HenchmenLevel1"]), Int32Helper.Parse(dr["HenchmenLevel2"]), Int32Helper.Parse(dr["HenchmenLevel3"]), Int32Helper.Parse(dr["HenchmenLevel4"]), Int32Helper.Parse(dr["HenchmenLevel5"])));
                    string  members   = $"Guild{Int32Helper.Parse(dr["ID"])}Members";
                    DataSet membersDS = await SQLiteHelper.FillDataSet(_con, $"SELECT * FROM {members}");

                    if (membersDS.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow drM in membersDS.Tables[0].Rows)
                        {
                            newGuild.Members.Add(drM["Username"].ToString());
                        }
                    }
                    allGuilds.Add(newGuild);
                }
            }
            return(allGuilds.OrderBy(guild => guild.ID).ToList());
        }
Пример #2
0
        private async void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            _copyOfGuild.Name   = TxtGuildName.Text.Trim();
            _copyOfGuild.Fee    = Int32Helper.Parse(TxtEntranceFee.Text.Trim());
            _copyOfGuild.Master = CmbMaster.Text;
            if (GameState.CurrentGuild != _copyOfGuild)
            {
                if (_copyOfGuild.Name != GameState.CurrentGuild.Name)
                {
                    GameState.CurrentGuild.Name = _copyOfGuild.Name;
                    Functions.AddTextToTextBox(TxtOptions, $"You change the name of the guild to {GameState.CurrentGuild.Name}.");
                }
                if (_copyOfGuild.Fee != GameState.CurrentGuild.Fee)
                {
                    GameState.CurrentGuild.Fee = _copyOfGuild.Fee;
                    Functions.AddTextToTextBox(TxtOptions, $"You change the entrance fee of the guild to {GameState.CurrentGuild.FeeToString}.");
                }
                if (_copyOfGuild.Master != GameState.CurrentGuild.Master)
                {
                    GameState.CurrentGuild.Master = _copyOfGuild.Master;
                    Functions.AddTextToTextBox(TxtOptions, $"You resign as the guildmaster of {GameState.CurrentGuild.Name}, and hand leadership over to {GameState.CurrentGuild.Master}.");
                    DisableControls();
                }

                await GameState.DatabaseInteraction.SaveGuild(GameState.CurrentGuild);
            }
        }
Пример #3
0
        internal Vector2 Center()
        {
            int centerx = Int32Helper.Parse(Math.Floor((Position.x + Width) / 2));
            int centery = Int32Helper.Parse(Math.Floor((Position.y + Height) / 2));

            return(new Vector2(centerx, centery));
        }
Пример #4
0
        public void TestDecodeL()
        {
            Assertion.AssertEquals(0, Int32Helper.Decode("0"));
            Assertion.AssertEquals(1, Int32Helper.Decode("1"));
            Assertion.AssertEquals(-1, Int32Helper.Decode("-1"));
            Assertion.AssertEquals(0xF, Int32Helper.Decode("0xF"));
            Assertion.AssertEquals(0xF, Int32Helper.Decode("#F"));
            Assertion.AssertEquals(0xF, Int32Helper.Decode("0XF"));
            Assertion.AssertEquals(07, Int32Helper.Decode("07"));

            try
            {
                Int32Helper.Decode("9.2");
                Assertion.Fail("Expected NumberFormatException with floating point string.");
            }
            catch (Exception) { }

            try
            {
                Int32Helper.Decode("");
                Assertion.Fail("Expected NumberFormatException with empty string.");
            }
            catch (Exception) { }

            try
            {
                Int32Helper.Decode(null);
                //undocumented NPE, but seems consistent across JREs
                Assertion.Fail("Expected NullPointerException with null string.");
            }
            catch (NullReferenceException) { }
        }
Пример #5
0
        public void TestBitCount()
        {
            Assertion.AssertEquals(0, Int32Helper.BitCount(0x0));
            Assertion.AssertEquals(1, Int32Helper.BitCount(0x1));
            Assertion.AssertEquals(1, Int32Helper.BitCount(0x2));
            Assertion.AssertEquals(2, Int32Helper.BitCount(0x3));
            Assertion.AssertEquals(1, Int32Helper.BitCount(0x4));
            Assertion.AssertEquals(2, Int32Helper.BitCount(0x5));
            Assertion.AssertEquals(2, Int32Helper.BitCount(0x6));
            Assertion.AssertEquals(3, Int32Helper.BitCount(0x7));
            Assertion.AssertEquals(1, Int32Helper.BitCount(0x8));
            Assertion.AssertEquals(2, Int32Helper.BitCount(0x9));
            Assertion.AssertEquals(2, Int32Helper.BitCount(0xA));
            Assertion.AssertEquals(3, Int32Helper.BitCount(0xB));
            Assertion.AssertEquals(2, Int32Helper.BitCount(0xC));
            Assertion.AssertEquals(3, Int32Helper.BitCount(0xD));
            Assertion.AssertEquals(3, Int32Helper.BitCount(0xE));
            Assertion.AssertEquals(4, Int32Helper.BitCount(0xF));

            Assertion.AssertEquals(8, Int32Helper.BitCount(0xFF));
            Assertion.AssertEquals(12, Int32Helper.BitCount(0xFFF));
            Assertion.AssertEquals(16, Int32Helper.BitCount(0xFFFF));
            Assertion.AssertEquals(20, Int32Helper.BitCount(0xFFFFF));
            Assertion.AssertEquals(24, Int32Helper.BitCount(0xFFFFFF));
            Assertion.AssertEquals(28, Int32Helper.BitCount(0xFFFFFFF));
            // Assertion.AssertEquals(32, Int32Helper.BitCount(0xFFFFFFFF));
        }
Пример #6
0
        public void TestDecodeOctal()
        {
            String pattern = "0234";
            int    res     = Int32Helper.Decode(pattern);

            Assert.AreEqual(res, 156);
        }
Пример #7
0
        public void TestDecodeHexadecimal()
        {
            String pattern = "0xA";
            int    res     = Int32Helper.Decode(pattern);

            Assert.AreEqual(res, 10);
        }
Пример #8
0
        private void HandleIntTextBox(ref object sender, int maxValue)
        {
            TextBox txt = sender as TextBox;

            if (txt.Text.Trim().Length > 0 && Int32Helper.Parse(txt.Text.Trim()) > maxValue)
            {
                txt.Text = maxValue.ToString();
            }
        }
Пример #9
0
 internal void CreateRoom(Rect room)
 {
     for (int y = Int32Helper.Parse(room.Position.y); y < room.Height; y++)
     {
         for (int x = Int32Helper.Parse(room.Position.x); x < room.Width; x++)
         {
             map.SetCell(x, y, 0);
         }
     }
 }
Пример #10
0
        private void TxtSimulator_TextChanged(object sender, TextChangedEventArgs e)
        {
            Functions.TextBoxTextChanged(sender, KeyType.Integers);

            if (Int32Helper.Parse(TxtSimulator.Text) > 1000000)
            {
                TxtSimulator.Text = "1000000";
            }
            BtnSimulate.IsEnabled = TxtSimulator.Text.Length > 0;
        }
        /// <summary>Gets the next <see cref="Vehicle"/> ID autoincrement value in the database for the Vehicle table.</summary>
        /// <returns>Next <see cref="Vehicle"/> ID value</returns>
        public async Task <int> GetNextVehicleIndex()
        {
            DataSet ds = await SQLiteHelper.FillDataSet(_con, "SELECT * FROM SQLITE_SEQUENCE WHERE name = 'Vehicles'");

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(Int32Helper.Parse(ds.Tables[0].Rows[0]["seq"]) + 1);
            }
            return(1);
        }
Пример #12
0
        private void BtnBribe_Click(object sender, RoutedEventArgs e)
        {
            if (CheckHungerThirst())
            {
                if (_blnBribe)
                {
                    string bribeText     = GameState.InputDialog("The inkeeper asks, \"How much gold would you give me to have this key?\"", "Assassin").Trim();
                    int    bribe         = Int32Helper.Parse(bribeText);
                    int    bribeRequired = Functions.GenerateRandomNumber(_selectedUser.Level * 50, _selectedUser.Level * 200);

                    if (bribe > 0 && bribe <= GameState.CurrentUser.GoldOnHand)
                    {
                        GameState.CurrentUser.GoldOnHand -= bribe;
                        if (bribe < bribeRequired)
                        {
                            Functions.AddTextToTextBox(RefToInnPage.TxtInn, "The innkeeper takes your gold and walks away.");
                            GameState.GoBack();
                        }
                        else
                        {
                            BattleFromInn("The innkeeper takes your gold and hands you a key. You creep upstairs.");
                        }
                    }
                    else if (bribeText.Trim().Length > 0)
                    {
                        GameState.DisplayNotification($"Please enter a positive integer value less than {GameState.CurrentUser.GoldOnHand}.", "Assassin");
                    }
                    else if (bribe > GameState.CurrentUser.GoldOnHand)
                    {
                        Functions.AddTextToTextBox(RefToInnPage.TxtInn, "You don't have that much gold to bribe the innkeeper with.");
                    }
                }
                else
                {
                    if (GameState.CurrentUser.Lockpicks > 0)
                    {
                        GameState.CurrentUser.Lockpicks--;

                        if (Functions.GenerateRandomNumber(1, 100) <= GameState.CurrentUser.Stealth)
                        {
                            BattleFromInn("You successfully pick the lock! You enter the room...");
                        }
                        else
                        {
                            GameState.DisplayNotification("You broke your lockpick! Hopefully you didn't make too much noise and awaken your intended victim...", "Assassin");
                        }
                        //TODO Consider actually being surprised by your victim if you fail a lockpick.
                    }
                    else
                    {
                        GameState.DisplayNotification("You do not have any lockpicks.", "Assassin");
                    }
                }
            }
        }
Пример #13
0
        /// <summary>Adds credit score to database.</summary>
        private async Task <bool> AddCreditScore()
        {
            if (await AppState.AddCreditScore(new CreditScore(DateTimeHelper.Parse(ScoreDate.SelectedDate),
                                                              TxtSource.Text.Trim(), Int32Helper.Parse(TxtScore.Text.Trim()),
                                                              EnumHelper.Parse <Providers>(CmbProvider.SelectedItem.ToString()), ChkFICO?.IsChecked ?? false)))
            {
                return(true);
            }

            AppState.DisplayNotification("Unable to add credit score.", "Finances");
            return(false);
        }
Пример #14
0
 public void TestDecodeError()
 {
     try
     {
         String pattern = "toto";
         int    res     = Int32Helper.Decode(pattern);
         Assert.Fail();
     }
     catch (ArgumentException)
     {
     }
 }
Пример #15
0
        /// <summary>Sends a <see cref="Message"/> between <see cref="User"/>s.</summary>
        /// <param name="message"><see cref="Message"/> sent</param>
        /// <returns>True if successful</returns>
        public async Task <bool> SendMessage(Message message)
        {
            SQLiteCommand cmd = new SQLiteCommand {
                CommandText = "INSERT INTO Messages([UserTo], [UserFrom], [Message], [DateSent], [GuildMessage])VALUES(@userTo, @userFrom, @message, @dateSent, @guildMessage)"
            };

            cmd.Parameters.AddWithValue("@userTo", message.UserTo);
            cmd.Parameters.AddWithValue("@userFrom", message.UserFrom);
            cmd.Parameters.AddWithValue("@message", message.Contents);
            cmd.Parameters.AddWithValue("@dateSent", message.DateSent);
            cmd.Parameters.AddWithValue("@guildMessage", Int32Helper.Parse(message.GuildMessage));
            return(await SQLiteHelper.ExecuteCommand(_con, cmd));
        }
Пример #16
0
 private void _on_BtnDealHand_pressed()
 {
     // if can afford bet, set the bet, deal the hand
     // else can't afford
     MainBet = Int32Helper.Parse(TxtBet.Text);
     if (MainBet > 0 && MainBet <= GameState.CurrentHero.Gold)
     {
         DealHand();
     }
     else
     {
         AddTextToTextBox(MainBet > GameState.CurrentHero.Gold ? "You can't bet more gold than you have!" : "Please enter a valid bet.");
     }
 }
Пример #17
0
        private void _on_BtnInsurance_pressed()
        {
            int sidePot = Int32Helper.Parse(TxtInsurance.Text);

            if (sidePot <= MainBet / 2 && GameState.CurrentHero.Gold >= MainBet + SplitBet + sidePot)
            {
                SidePot = sidePot;
                ToggleInsurance(true);
            }
            else
            {
                AddTextToTextBox("Your insurance bet must be less than or equal to half your main bet.");
            }
        }
Пример #18
0
        /// <summary>Assigns all the Controls' data to the _selectedUser <see cref="User"/>.</summary>
        private void AssignSelectedUser(bool hashPassword = false)
        {
            _selectedUser.Name = TxtName.Text.Trim();
            if (hashPassword)
            {
                _selectedUser.Password = PBKDF2.HashPassword(PswdPassword.Password.Trim());
            }

            // character
            _selectedUser.Level            = Int32Helper.Parse(TxtLevel.Text.Trim());
            _selectedUser.Experience       = Int32Helper.Parse(TxtExperience.Text.Trim());
            _selectedUser.SkillPoints      = Int32Helper.Parse(TxtSkillPoints.Text.Trim());
            _selectedUser.Alive            = ChkAlive.IsChecked != null && ChkAlive.IsChecked.Value;
            _selectedUser.CurrentEndurance = Int32Helper.Parse(TxtCurrentEndurance.Text.Trim());
            _selectedUser.CurrentLocation  = EnumHelper.Parse <SleepLocation>(CmbLocation.SelectedItem.ToString());
            _selectedUser.MaximumEndurance = Int32Helper.Parse(TxtMaximumEndurance.Text.Trim());
            _selectedUser.Hunger           = Int32Helper.Parse(TxtHunger.Text.Trim());
            _selectedUser.Thirst           = Int32Helper.Parse(TxtThirst.Text.Trim());

            // inventory
            _selectedUser.CurrentWeaponType = EnumHelper.Parse <WeaponType>(CmbCurrentWeapon.SelectedItem.ToString());
            _selectedUser.LightWeapon       = (Weapon)CmbLightWeapon.SelectedItem;
            _selectedUser.HeavyWeapon       = (Weapon)CmbHeavyWeapon.SelectedItem;
            _selectedUser.TwoHandedWeapon   = (Weapon)CmbTwoHWeapon.SelectedItem;
            _selectedUser.Armor             = (Armor)CmbArmor.SelectedItem;
            _selectedUser.Potion            = (Potion)CmbPotion.SelectedItem;
            _selectedUser.Lockpicks         = Int32Helper.Parse(TxtLockpicks.Text.Trim());
            _selectedUser.GoldOnHand        = Int32Helper.Parse(TxtGoldOnHand.Text.Trim());
            _selectedUser.GoldInBank        = Int32Helper.Parse(TxtGoldInBank.Text.Trim());
            _selectedUser.GoldOnLoan        = Int32Helper.Parse(TxtGoldOnLoan.Text.Trim());
            _selectedUser.Shovel            = ChkShovel.IsChecked != null && ChkShovel.IsChecked.Value;
            _selectedUser.Lantern           = ChkLantern.IsChecked != null && ChkLantern.IsChecked.Value;
            _selectedUser.Amulet            = ChkAmulet.IsChecked != null && ChkAmulet.IsChecked.Value;

            // skills
            _selectedUser.LightWeaponSkill     = Int32Helper.Parse(TxtLightWeaponSkill.Text.Trim());
            _selectedUser.HeavyWeaponSkill     = Int32Helper.Parse(TxtHeavyWeaponSkill.Text.Trim());
            _selectedUser.TwoHandedWeaponSkill = Int32Helper.Parse(TxtTwoHWeaponSkill.Text.Trim());
            _selectedUser.Blocking             = Int32Helper.Parse(TxtBlockingSkill.Text.Trim());
            _selectedUser.Slipping             = Int32Helper.Parse(TxtSlippingSkill.Text.Trim());
            _selectedUser.Stealth = Int32Helper.Parse(TxtStealthSkill.Text.Trim());

            // henchmen
            _selectedUser.Henchmen.Level1 = Int32Helper.Parse(TxtHenchmenLevel1.Text.Trim());
            _selectedUser.Henchmen.Level2 = Int32Helper.Parse(TxtHenchmenLevel2.Text.Trim());
            _selectedUser.Henchmen.Level3 = Int32Helper.Parse(TxtHenchmenLevel3.Text.Trim());
            _selectedUser.Henchmen.Level4 = Int32Helper.Parse(TxtHenchmenLevel4.Text.Trim());
            _selectedUser.Henchmen.Level5 = Int32Helper.Parse(TxtHenchmenLevel5.Text.Trim());
        }
Пример #19
0
        /// <summary>Attempts to add a <see cref="FuelTransaction"/> to the database.</summary>
        /// <returns>Returns true if successfully added</returns>
        private async Task <bool> ModifyTransaction()
        {
            ModifiedTransaction = new FuelTransaction(UnmodifiedTransaction.TranscationID,
                                                      UnmodifiedTransaction.VehicleID, DateTimeHelper.Parse(TransactionDate.SelectedDate), TxtStore.Text,
                                                      Int32Helper.Parse(TxtOctane.Text), DecimalHelper.Parse(TxtDistance.Text),
                                                      DecimalHelper.Parse(TxtGallons.Text), DecimalHelper.Parse(TxtPrice.Text),
                                                      DecimalHelper.Parse(TxtOdometer.Text), Int32Helper.Parse(TxtRange.Text));

            if (await AppState.DatabaseInteraction.ModifyTransaction(UnmodifiedTransaction, ModifiedTransaction))
            {
                CurrentVehicle.ModifyTransaction(UnmodifiedTransaction, ModifiedTransaction);
                return(true);
            }
            return(false);
        }
Пример #20
0
        public override void _Ready()
        {
            map = (TileMap)GetNode("TileMap");

            for (int y = 0; y < FLOOR_HEIGHT; y++)
            {
                for (int x = 0; y < FLOOR_WIDTH; x++)
                {
                    map.SetCell(x, y, 1);
                }
            }

            List <Rect> rooms = new List <Rect>();

            for (int i = 0; i < MAX_ROOM_COUNT; i++)
            {
                Rect r      = CreateRandomRect(FLOOR_WIDTH, FLOOR_HEIGHT);
                var  failed = false;
                foreach (Rect j in rooms)
                {
                    if (r.Intersect(j))
                    {
                        failed = true;
                    }
                }
                if (!failed && rooms.Count > 0)
                {
                    Vector2 nr = r.Center();
                    Vector2 pr = new Vector2(rooms.Last().Center());

                    RandomNumberGenerator ran = new RandomNumberGenerator();
                    if (ran.Randf() > 0.5)
                    {
                        H_Tunnel(Int32Helper.Parse(pr.x), Int32Helper.Parse(nr.x), Int32Helper.Parse(pr.y));
                        V_Tunnel(Int32Helper.Parse(pr.y), Int32Helper.Parse(nr.y), Int32Helper.Parse(nr.x));
                    }
                    else
                    {
                        V_Tunnel(Int32Helper.Parse(pr.y), Int32Helper.Parse(nr.y), Int32Helper.Parse(nr.x));
                        H_Tunnel(Int32Helper.Parse(pr.x), Int32Helper.Parse(nr.x), Int32Helper.Parse(pr.y));
                    }
                }
            }
            foreach (Rect room in rooms)
            {
                CreateRoom(room);
            }
        }
        /// <summary>Deletes a <see cref="CreditScore"/> from the database</summary>
        /// <param name="deleteScore"><see cref="CreditScore"/> to be deleted</param>
        /// <returns>True if successful</returns>
        public Task <bool> DeleteCreditScore(CreditScore deleteScore)
        {
            SQLiteCommand cmd = new SQLiteCommand
            {
                CommandText =
                    "DELETE FROM CreditScores WHERE [Date] = @date AND [Source] = @source AND [Score] = @score AND [Provider] = @provider AND [FICO] = @fico"
            };

            cmd.Parameters.AddWithValue("@date", deleteScore.DateToString);
            cmd.Parameters.AddWithValue("@source", deleteScore.Source);
            cmd.Parameters.AddWithValue("@score", deleteScore.Score);
            cmd.Parameters.AddWithValue("@provider", deleteScore.ProviderToString);
            cmd.Parameters.AddWithValue("@fico", Int32Helper.Parse(deleteScore.FICO));

            return(SQLiteHelper.ExecuteCommand(_con, cmd));
        }
        /// <summary>Adds a new <see cref="CreditScore"/> to the database.</summary>
        /// <param name="newScore"><see cref="CreditScore"/> to be added</param>
        /// <returns>True if successful</returns>
        public Task <bool> AddCreditScore(CreditScore newScore)
        {
            SQLiteCommand cmd = new SQLiteCommand
            {
                CommandText =
                    "INSERT INTO CreditScores([Date], [Source], [Score], [Provider], [FICO])VALUES(@date, @source, @score, @provider, @fico)"
            };

            cmd.Parameters.AddWithValue("@date", newScore.DateToString);
            cmd.Parameters.AddWithValue("@source", newScore.Source);
            cmd.Parameters.AddWithValue("@score", newScore.Score);
            cmd.Parameters.AddWithValue("@provider", newScore.ProviderToString);
            cmd.Parameters.AddWithValue("@fico", Int32Helper.Parse(newScore.FICO));

            return(SQLiteHelper.ExecuteCommand(_con, cmd));
        }
Пример #23
0
        public async Task Roll([Remainder] string rolledDice)
        {
            if (rolledDice.Length > 0)
            {
                string[] dice = rolledDice.ToLower().Split('d');
                if (dice.Length == 2)
                {
                    int numberOfDice = Int32Helper.Parse(dice[0]);
                    int sidesOnDice  = Int32Helper.Parse(dice[1]);

                    try
                    {
                        checked
                        {
                            if (numberOfDice == 0 && sidesOnDice != 0)
                            {
                                numberOfDice = 1;
                            }

                            if (numberOfDice > 0 && sidesOnDice > 0)
                            {
                                string output = Context.User.Username + " rolls";
                                output += RollDice(numberOfDice, sidesOnDice);
                                await ReplyAsync(output);
                            }
                            else
                            {
                                await ReplyAsync("Please enter a valid dice roll. (e.g. 2d10)");
                            }
                        }
                    }
                    catch (Exception)
                    {
                        await ReplyAsync("That combination of amount of dice and sides on the dice exceeds the maximum integer value of 2,147,483,647.");
                    }
                }
                else
                {
                    await ReplyAsync("Please enter a valid dice roll. (e.g. 2d10)");
                }
            }
            else
            {
                await ReplyAsync("Please enter a valid dice roll. (e.g. 2d10)");
            }
        }
Пример #24
0
        /// <summary>Adds a new <see cref="User"/> to the database.</summary>
        /// <param name="newUser"><see cref="User"/> to be added</param>
        /// <returns>True if successful</returns>
        public async Task <bool> NewUser(User newUser)
        {
            SQLiteCommand cmd = new SQLiteCommand
            {
                CommandText =
                    "INSERT INTO Users([Username], [Password], [Level], [Experience], [SkillPoints], [Alive], [Location], [CurrentEndurance], [MaximumEndurance], [Hunger], [Thirst], [CurrentWeapon], [LightWeapon], [HeavyWeapon], [TwoHandedWeapon], [Armor], [Potion], [Lockpicks], [GoldOnHand], [GoldInBank], [GoldOnLoan], [Shovel], [Lantern], [Amulet], [LightWeaponSkill], [HeavyWeaponSkill], [TwoHandedWeaponSkill], [Blocking], [Slipping], [Stealth], [HenchmenLevel1], [HenchmenLevel2], [HenchmenLevel3], [HenchmenLevel4], [HenchmenLevel5])VALUES(@name, @password, @level, @experience, @skillPoints, @alive, @location, @currentEndurance, @maximumEndurance, @hunger, @thirst, @currentWeapon, @lightWeapon, @heavyWeapon, @twoHandedWeapon, @armor, @potion, @lockpicks, @goldOnHand, @goldInBank, @goldOnLoan, @shovel, @lantern, @amulet, @lightWeaponSkill, @heavyWeaponSkill, @twoHandedWeaponSkill, @blocking, @slipping, @stealth, @henchmenLevel1, @henchmenLevel2, @henchmenLevel3, @henchmenLevel4, @henchmenLevel5)"
            };

            cmd.Parameters.AddWithValue("@name", newUser.Name);
            cmd.Parameters.AddWithValue("@password", newUser.Password);
            cmd.Parameters.AddWithValue("@level", newUser.Level);
            cmd.Parameters.AddWithValue("@experience", newUser.Experience.ToString());
            cmd.Parameters.AddWithValue("@skillPoints", newUser.SkillPoints.ToString());
            cmd.Parameters.AddWithValue("@alive", Int32Helper.Parse(newUser.Alive));
            cmd.Parameters.AddWithValue("@location", newUser.CurrentLocation.ToString());
            cmd.Parameters.AddWithValue("@currentEndurance", newUser.CurrentEndurance.ToString());
            cmd.Parameters.AddWithValue("@maximumEndurance", newUser.MaximumEndurance.ToString());
            cmd.Parameters.AddWithValue("@hunger", newUser.Hunger.ToString());
            cmd.Parameters.AddWithValue("@thirst", newUser.Thirst.ToString());
            cmd.Parameters.AddWithValue("@currentWeapon", newUser.CurrentWeaponType.ToString());
            cmd.Parameters.AddWithValue("@lightWeapon", newUser.LightWeapon.Name);
            cmd.Parameters.AddWithValue("@heavyWeapon", newUser.HeavyWeapon.Name);
            cmd.Parameters.AddWithValue("@twoHandedWeapon", newUser.TwoHandedWeapon.Name);
            cmd.Parameters.AddWithValue("@armor", newUser.Armor.Name);
            cmd.Parameters.AddWithValue("@potion", newUser.Potion.Name);
            cmd.Parameters.AddWithValue("@lockpicks", newUser.Lockpicks.ToString());
            cmd.Parameters.AddWithValue("@goldOnHand", newUser.GoldOnHand.ToString());
            cmd.Parameters.AddWithValue("@goldInBank", newUser.GoldInBank.ToString());
            cmd.Parameters.AddWithValue("@goldOnLoan", newUser.GoldOnLoan.ToString());
            cmd.Parameters.AddWithValue("@shovel", Int32Helper.Parse(newUser.Shovel));
            cmd.Parameters.AddWithValue("@lantern", Int32Helper.Parse(newUser.Lantern));
            cmd.Parameters.AddWithValue("@amulet", Int32Helper.Parse(newUser.Amulet));
            cmd.Parameters.AddWithValue("@lightWeaponSkill", newUser.LightWeaponSkill.ToString());
            cmd.Parameters.AddWithValue("@heavyWeaponSkill", newUser.HeavyWeaponSkill.ToString());
            cmd.Parameters.AddWithValue("@twoHandedWeaponSkill", newUser.TwoHandedWeaponSkill.ToString());
            cmd.Parameters.AddWithValue("@blocking", newUser.Blocking.ToString());
            cmd.Parameters.AddWithValue("@slipping", newUser.Slipping.ToString());
            cmd.Parameters.AddWithValue("@stealth", newUser.Stealth.ToString());
            cmd.Parameters.AddWithValue("@henchmenLevel1", newUser.Henchmen.Level1.ToString());
            cmd.Parameters.AddWithValue("@henchmenLevel2", newUser.Henchmen.Level2.ToString());
            cmd.Parameters.AddWithValue("@henchmenLevel3", newUser.Henchmen.Level3.ToString());
            cmd.Parameters.AddWithValue("@henchmenLevel4", newUser.Henchmen.Level4.ToString());
            cmd.Parameters.AddWithValue("@henchmenLevel5", newUser.Henchmen.Level5.ToString());

            return(await SQLiteHelper.ExecuteCommand(_con, cmd));
        }
Пример #25
0
        /// <summary>Displays an InputDialog and attempts to get a value.</summary>
        /// <param name="text">Text to be displayed in the dialog</param>
        /// <returns>Value from the InputDialog</returns>
        private int DisplayDialog(string text, int maximum)
        {
            string dialogAmount = GameState.InputDialog(text, "Assassin").Trim();

            if (dialogAmount.Length > 0)
            {
                int amount = Int32Helper.Parse(dialogAmount);
                if (amount > 0 && amount <= maximum)
                {
                    return(amount);
                }
                else
                {
                    GameState.DisplayNotification($"Please enter a positive integer value above 0 and below {maximum:N0}.", "Assassin");
                }
            }
            return(0);
        }
Пример #26
0
        /// <summary>Verifies a password with its hashed counterpart.</summary>
        /// <param name="plaintext">Plaintext password</param>
        /// <param name="hashed">Already hashed password</param>
        public static bool VerifyHash(string plaintext, string hashed)
        {
            string[] pieces = hashed.Split('$');
            if (pieces.Length == 0 || pieces[1] != "argon2")
            {
                return(false);
            }
            int    saltLength  = Int32Helper.Parse(pieces[2].Substring(3));
            int    parallelism = Int32Helper.Parse(pieces[3].Substring(2));
            int    iterations  = Int32Helper.Parse(pieces[4].Substring(2));
            int    memorySize  = Int32Helper.Parse(pieces[5].Substring(2));
            string saltString  = pieces[6];

            byte[] salt    = Convert.FromBase64String(saltString);
            string newHash = HashPassword(plaintext, salt, saltLength, parallelism, iterations, memorySize);

            return(hashed.SequenceEqual(newHash));
        }
Пример #27
0
        /// <summary>Assigns a <see cref="User"/> from a DataRow.</summary>
        /// <param name="dr">DataRow containing <see cref="User"/></param>
        /// <returns>Assigned <see cref="User"/></returns>
        private User AssignUserFromDataRow(DataRow dr)
        {
            User newUser = new User
            {
                Name                 = dr["Username"].ToString(),
                Password             = dr["Password"].ToString(),
                Level                = Int32Helper.Parse(dr["Level"].ToString()),
                Experience           = Int32Helper.Parse(dr["Experience"].ToString()),
                SkillPoints          = Int32Helper.Parse(dr["SkillPoints"].ToString()),
                Alive                = BoolHelper.Parse(dr["Alive"]),
                CurrentEndurance     = Int32Helper.Parse(dr["CurrentEndurance"].ToString()),
                CurrentLocation      = EnumHelper.Parse <SleepLocation>(dr["Location"].ToString()),
                MaximumEndurance     = Int32Helper.Parse(dr["MaximumEndurance"].ToString()),
                Hunger               = Int32Helper.Parse(dr["Hunger"].ToString()),
                Thirst               = Int32Helper.Parse(dr["Thirst"].ToString()),
                CurrentWeaponType    = EnumHelper.Parse <WeaponType>(dr["CurrentWeapon"].ToString()),
                LightWeapon          = GameState.AllWeapons.Find(newWeapon => newWeapon.Name == dr["LightWeapon"].ToString() && newWeapon.Type == WeaponType.Light),
                HeavyWeapon          = GameState.AllWeapons.Find(newWeapon => newWeapon.Name == dr["HeavyWeapon"].ToString() && newWeapon.Type == WeaponType.Heavy),
                TwoHandedWeapon      = GameState.AllWeapons.Find(newWeapon => newWeapon.Name == dr["TwoHandedWeapon"].ToString() && newWeapon.Type == WeaponType.TwoHanded),
                Armor                = GameState.AllArmor.Find(newArmor => newArmor.Name == dr["Armor"].ToString()),
                Potion               = GameState.AllPotions.Find(newPotion => newPotion.Name == dr["Potion"].ToString()),
                Lockpicks            = Int32Helper.Parse(dr["Lockpicks"].ToString()),
                GoldOnHand           = Int32Helper.Parse(dr["GoldOnHand"].ToString()),
                GoldInBank           = Int32Helper.Parse(dr["GoldInBank"].ToString()),
                GoldOnLoan           = Int32Helper.Parse(dr["GoldOnLoan"].ToString()),
                Shovel               = BoolHelper.Parse(dr["Shovel"]),
                Lantern              = BoolHelper.Parse(dr["Lantern"]),
                Amulet               = BoolHelper.Parse(dr["Amulet"]),
                LightWeaponSkill     = Int32Helper.Parse(dr["LightWeaponSkill"].ToString()),
                HeavyWeaponSkill     = Int32Helper.Parse(dr["HeavyWeaponSkill"].ToString()),
                TwoHandedWeaponSkill = Int32Helper.Parse(dr["TwoHandedWeaponSkill"].ToString()),
                Blocking             = Int32Helper.Parse(dr["Blocking"].ToString()),
                Slipping             = Int32Helper.Parse(dr["Slipping"].ToString()),
                Stealth              = Int32Helper.Parse(dr["Stealth"].ToString()),
                Henchmen             = new Henchmen(Int32Helper.Parse(dr["HenchmenLevel1"].ToString()),
                                                    Int32Helper.Parse(dr["HenchmenLevel2"].ToString()),
                                                    Int32Helper.Parse(dr["HenchmenLevel3"].ToString()),
                                                    Int32Helper.Parse(dr["HenchmenLevel4"].ToString()),
                                                    Int32Helper.Parse(dr["HenchmenLevel5"].ToString()))
            };

            return(newUser);
        }
Пример #28
0
        /// <summary>Saves the current <see cref="User"/>.</summary>
        /// <param name="saveUser"><see cref="User"/> to be saved.</param>
        /// <returns>True if successful</returns>
        public async Task <bool> SaveUser(User saveUser)
        {
            SQLiteCommand cmd = new SQLiteCommand {
                CommandText = "UPDATE Users SET [Level] = @level, [Experience] = @experience, [SkillPoints] = @skillPoints, [Alive] = @alive, [Location] = @location, [CurrentEndurance] = @currentEndurance, [MaximumEndurance] = @maximumEndurance, [Hunger] = @hunger, [Thirst] = @thirst, [CurrentWeapon] = @currentWeapon, [LightWeapon] = @lightWeapon, [HeavyWeapon] = @heavyWeapon, [TwoHandedWeapon] = @twoHandedWeapon, [Armor] = @armor, [Potion] = @potion, [Lockpicks] = @lockpicks, [GoldOnHand] = @goldOnHand, [GoldInBank] = @goldInBank, [GoldOnLoan] = @goldOnLoan, [Shovel] = @shovel, [Lantern] = @lantern, [Amulet] = @amulet, [LightWeaponSkill] = @lightWeaponSkill, [HeavyWeaponSkill] = @heavyWeaponSkill, [TwoHandedWeaponSkill] = @twoHandedWeaponSkill, [Blocking] = @blocking, [Slipping] = @slipping, [Stealth] = @stealth, [HenchmenLevel1] = @henchmenLevel1, [HenchmenLevel2] = @henchmenLevel2, [HenchmenLevel3] = @henchmenLevel3, [HenchmenLevel4] = @henchmenLevel4, [HenchmenLevel5] = @henchmenLevel5 WHERE [Username] = @name"
            };

            cmd.Parameters.AddWithValue("@level", saveUser.Level);
            cmd.Parameters.AddWithValue("@experience", saveUser.Experience.ToString());
            cmd.Parameters.AddWithValue("@skillPoints", saveUser.SkillPoints.ToString());
            cmd.Parameters.AddWithValue("@alive", Int32Helper.Parse(saveUser.Alive));
            cmd.Parameters.AddWithValue("@location", saveUser.CurrentLocation.ToString());
            cmd.Parameters.AddWithValue("@currentEndurance", saveUser.CurrentEndurance.ToString());
            cmd.Parameters.AddWithValue("@maximumEndurance", saveUser.MaximumEndurance.ToString());
            cmd.Parameters.AddWithValue("@hunger", saveUser.Hunger.ToString());
            cmd.Parameters.AddWithValue("@thirst", saveUser.Thirst.ToString());
            cmd.Parameters.AddWithValue("@currentWeapon", saveUser.CurrentWeaponType.ToString());
            cmd.Parameters.AddWithValue("@lightWeapon", saveUser.LightWeapon.Name);
            cmd.Parameters.AddWithValue("@heavyWeapon", saveUser.HeavyWeapon.Name);
            cmd.Parameters.AddWithValue("@twoHandedWeapon", saveUser.TwoHandedWeapon.Name);
            cmd.Parameters.AddWithValue("@armor", saveUser.Armor.Name);
            cmd.Parameters.AddWithValue("@potion", saveUser.Potion.Name);
            cmd.Parameters.AddWithValue("@lockpicks", saveUser.Lockpicks.ToString());
            cmd.Parameters.AddWithValue("@goldOnHand", saveUser.GoldOnHand.ToString());
            cmd.Parameters.AddWithValue("@goldInBank", saveUser.GoldInBank.ToString());
            cmd.Parameters.AddWithValue("@goldOnLoan", saveUser.GoldOnLoan.ToString());
            cmd.Parameters.AddWithValue("@shovel", Int32Helper.Parse(saveUser.Shovel));
            cmd.Parameters.AddWithValue("@lantern", Int32Helper.Parse(saveUser.Lantern));
            cmd.Parameters.AddWithValue("@amulet", Int32Helper.Parse(saveUser.Amulet));
            cmd.Parameters.AddWithValue("@lightWeaponSkill", saveUser.LightWeaponSkill.ToString());
            cmd.Parameters.AddWithValue("@heavyWeaponSkill", saveUser.HeavyWeaponSkill.ToString());
            cmd.Parameters.AddWithValue("@twoHandedWeaponSkill", saveUser.TwoHandedWeaponSkill.ToString());
            cmd.Parameters.AddWithValue("@blocking", saveUser.Blocking.ToString());
            cmd.Parameters.AddWithValue("@slipping", saveUser.Slipping.ToString());
            cmd.Parameters.AddWithValue("@stealth", saveUser.Stealth.ToString());
            cmd.Parameters.AddWithValue("@henchmenLevel1", saveUser.Henchmen.Level1.ToString());
            cmd.Parameters.AddWithValue("@henchmenLevel2", saveUser.Henchmen.Level2.ToString());
            cmd.Parameters.AddWithValue("@henchmenLevel3", saveUser.Henchmen.Level3.ToString());
            cmd.Parameters.AddWithValue("@henchmenLevel4", saveUser.Henchmen.Level4.ToString());
            cmd.Parameters.AddWithValue("@henchmenLevel5", saveUser.Henchmen.Level5.ToString());
            cmd.Parameters.AddWithValue("@name", saveUser.Name);

            return(await SQLiteHelper.ExecuteCommand(_con, cmd));
        }
        /// <summary>Loads all <see cref="Vehicle"/>.</summary>
        /// <returns>All <see cref="Vehicle"/></returns>
        public async Task <List <Vehicle> > LoadVehicles()
        {
            DataSet ds = await SQLiteHelper.FillDataSet(_con, "SELECT * FROM Vehicles");

            List <Vehicle> vehicles = new List <Vehicle>();

            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dataRow in ds.Tables[0].Rows)
                {
                    int     vehicleID  = Int32Helper.Parse(dataRow["VehicleID"]);
                    Vehicle newVehicle = new Vehicle(vehicleID,
                                                     dataRow["Nickname"].ToString(), dataRow["Make"].ToString(), dataRow["Model"].ToString(),
                                                     Int32Helper.Parse(dataRow["Year"]), await LoadTransactions(vehicleID));
                    vehicles.Add(newVehicle);
                }
                vehicles = vehicles.OrderBy(vehicle => vehicle.Nickname).ToList();
            }
            return(vehicles);
        }
        /// <summary>Saves a new <see cref="Television"/> to the database.</summary>
        /// <param name="newSeries"><see cref="Television"/> to be saved</param>
        /// <returns>True if successful</returns>
        public Task <bool> NewSeries(Series newSeries)
        {
            SQLiteCommand cmd = new SQLiteCommand {
                CommandText = "INSERT INTO Television([Name], [PremiereDate], [Rating], [Seasons], [Episodes], [Status], [Channel], [FinaleDate], [Day], [Time], [ReturnDate]) VALUES(@name, @premiereDate, @rating, @seasons, @episodes, @status, @channel, @finaleDate, @day, @time, @returnDate)"
            };

            cmd.Parameters.AddWithValue("@name", newSeries.Name);
            cmd.Parameters.AddWithValue("@premiereDate", newSeries.PremiereDateToString);
            cmd.Parameters.AddWithValue("@rating", newSeries.Rating);
            cmd.Parameters.AddWithValue("@seasons", newSeries.Seasons);
            cmd.Parameters.AddWithValue("@episodes", newSeries.Episodes);
            cmd.Parameters.AddWithValue("@status", Int32Helper.Parse(newSeries.Status));
            cmd.Parameters.AddWithValue("@channel", newSeries.Channel);
            cmd.Parameters.AddWithValue("@finaleDate", newSeries.FinaleDateToString);
            cmd.Parameters.AddWithValue("@day", Int32Helper.Parse(newSeries.Day));
            cmd.Parameters.AddWithValue("@time", newSeries.TimeToString);
            cmd.Parameters.AddWithValue("@returnDate", newSeries.ReturnDate);

            return(SQLiteHelper.ExecuteCommand(_con, cmd));
        }