Пример #1
0
        private bool LoadChoiceMachineList()
        {
            String sql = "select * from choice_machine;";

            bool bSucces = false;

            if (isPlayerLoaded())
            {
                using (MySqlConnection conn = ConnectToDB())
                {
                    conn.Open();

                    using (MySqlCommand comm = new MySqlCommand(sql, conn))
                    {
                        using (MySqlDataReader reader = comm.ExecuteReader())
                        {
                            itsChoiceMachineList.Clear();
                            while (reader.Read())
                            {
                                ChoiceMachine machine = new ChoiceMachine();
                                machine.MachineId         = (int)reader["machine_id"];
                                machine.RankNormal        = (int)reader["rank_normal"];
                                machine.RankRare          = (int)reader["rank_rare"];
                                machine.ChanceRare        = (int)reader["chance_rare"];
                                machine.StartCost         = (int)reader["start_cost"];
                                machine.CostIncMultiplier = (int)reader["cost_inc_multiplier"];

                                LoadPocketmonIdListWithRankToIdList(machine.NormalMonIdArray, machine.RankNormal);
                                LoadPocketmonIdListWithRankToIdList(machine.RareMonIdArray, machine.RankRare);
                                itsChoiceMachineList.Add(machine);

                                machine.btnHit.Click += this.onChoiceMachineClick;
                            }
                            bSucces = true;
                        }
                    }
                }
            }

            return(bSucces);
        }
Пример #2
0
        public int BuyRandomPocketmon(int machine_id)
        {
            int pocketmon_id = -1;

            if (isPlayerLoaded())
            {
                ChoiceMachine machine = null;
                foreach (ChoiceMachine cur in itsChoiceMachineList)
                {
                    if (cur.MachineId == machine_id)
                    {
                        machine = cur;
                        break;
                    }
                }
                if (machine != null)
                {
                    int playerMonCountForMachineRank = SelectPlayerOwnedPocketmonCountByLevel(itsPlayer.Id, machine.RankNormal);

                    int price = machine.CalculateSpinCost(playerMonCountForMachineRank);

                    if (itsPlayer.Coin >= price)
                    {
                        itsPlayer.Coin -= price;
                        int randomGeneratedMonsterId = machine.SpinForRandomMonId();
                        pocketmon_id = CreatePlayerPocketmon(randomGeneratedMonsterId);
                        SavePlayer();
                        LoadPlayerPocketmonList(itsPlayer.Id);
                        int nextBuyCost = 0;
                        nextBuyCost = machine.CalculateSpinCost(playerMonCountForMachineRank);
                        machine.ReloadCostLabel(nextBuyCost.ToString());
                    }
                }
            }
            return(pocketmon_id);
        }
        private bool LoadChoiceMachineList()
        {
            String sql = "select * from choice_machine;";

            bool bSucces = false;

            if (isPlayerLoaded())
            {
                using (MySqlConnection conn = ConnectToDB())
                {
                    conn.Open();

                    using (MySqlCommand comm = new MySqlCommand(sql, conn))
                    {
                        using (MySqlDataReader reader = comm.ExecuteReader())
                        {
                            itsChoiceMachineList.Clear();
                            while (reader.Read())
                            {

                                ChoiceMachine machine = new ChoiceMachine();
                                machine.MachineId   = (int)reader["machine_id"];
                                machine.RankNormal  = (int)reader["rank_normal"];
                                machine.RankRare    = (int)reader["rank_rare"];
                                machine.ChanceRare  = (int)reader["chance_rare"];
                                machine.StartCost   = (int)reader["start_cost"];
                                machine.CostIncMultiplier   = (int)reader["cost_inc_multiplier"];

                                LoadPocketmonIdListWithRankToIdList(machine.NormalMonIdArray, machine.RankNormal);
                                LoadPocketmonIdListWithRankToIdList(machine.RareMonIdArray, machine.RankRare);
                                itsChoiceMachineList.Add(machine);

                                machine.btnHit.Click += this.onChoiceMachineClick;
                            }
                            bSucces = true;
                        }
                    }
                }

            }

            return bSucces;
        }