Exemple #1
0
        // パーティー整合性チェック
        private bool PrepareParty(PartyManegementModel party)
        {
            List <int> partyList = new List <int>();

            for (int i = 0; i < 6; i++)
            {
                partyList.Add(party.GetPokemonId(i));
            }

            // 存在するポケモンが3匹未満の場合保存できない
            var partyExistList = partyList.Where(pokemonId => ImageFactoryModel.ExistPokemonImage(pokemonId)).ToArray();

            if (partyExistList.Length < 3)
            {
                _mainWindowModel.AddLog("パーティーには3匹ポケモンが必要です。");
                return(false);
            }

            // ポケモン重複チェック
            var duplicatedList = partyExistList.GroupBy(pokemonId => pokemonId).Where(g => g.Count() > 1).ToArray();

            if (duplicatedList.Length > 0)
            {
                _mainWindowModel.AddLog("パーティーのポケモンが重複しています。");
                return(false);
            }

            return(true);
        }
        // ポケモンID変更に伴い選出も修正する
        private void CorrectOrder(int pokemonIndex)
        {
            int pokemonId = _pokemonIdList[pokemonIndex];

            // not exist
            if (!ImageFactoryModel.ExistPokemonImage(pokemonId))
            {
                // 選出・非選出からも削除
                _selectedOrder.Remove(pokemonIndex);
                _notSelectedOrder.Remove(pokemonIndex);
                return;
            }

            // 存在するのに選出・非選出のどちらにもidがない場合
            if (!_selectedOrder.Contains(pokemonIndex) & !_notSelectedOrder.Contains(pokemonIndex))
            {
                _notSelectedOrder.Add(pokemonIndex);
            }

            // 更新
            UpdateOrder();
        }
        // オーダー変更
        public void ChangeOrder(int pokemonIndex)
        {
            // 存在しないポケモンの場合は変更なし
            int pokemonId = _pokemonIdList[pokemonIndex];

            if (!ImageFactoryModel.ExistPokemonImage(pokemonId))
            {
                return;
            }

            // 選出されている場合
            if (_selectedOrder.Contains(pokemonIndex))
            {
                // 選出リストから削除
                _selectedOrder.Remove(pokemonIndex);

                // 非選出リストに追加
                _notSelectedOrder.Add(pokemonIndex);

                // 選出変更を反映
                UpdateOrder();

                return;
            }

            // 非選出の場合
            // 既に3匹選出されている場合は変更なし
            if (_selectedOrder.Count >= 3)
            {
                return;
            }

            // 3匹選出されていなければ追加
            _selectedOrder.Add(pokemonIndex);

            // 選出変更を反映
            UpdateOrder();
        }
Exemple #4
0
        public List <BattleRecord> SelectBattleRecords()
        {
            StringBuilder query = new StringBuilder();

            query.AppendLine("SELECT");
            query.AppendLine("record.battle_record_id,");
            query.AppendLine("my_party.battle_result_id AS result,");
            query.AppendLine("CASE WHEN");
            query.AppendLine("  EXISTS (SELECT * FROM trainer_master WHERE trainer_id = my_party.trainer_id)");
            query.AppendLine("  THEN (SELECT name FROM trainer_master WHERE trainer_id = my_party.trainer_id)");
            query.AppendLine("  ELSE ''");
            query.AppendLine("  END my_trainer_name,");

            query.AppendLine("(");
            query.AppendLine("  SELECT");
            query.AppendLine("  GROUP_CONCAT(pokemon_id)");
            query.AppendLine("  FROM battle_pokemons");
            query.AppendLine("  WHERE battle_party_id = my_party.battle_party_id");
            query.AppendLine(") AS my_pokemon_id,");

            query.AppendLine("(");
            query.AppendLine("  SELECT");
            query.AppendLine("  GROUP_CONCAT(pokemon_icon_id)");
            query.AppendLine("  FROM battle_pokemons");
            query.AppendLine("  WHERE battle_party_id = my_party.battle_party_id");
            query.AppendLine(") AS my_pokemon_icon_id,");

            query.AppendLine("(");
            query.AppendLine("  SELECT");
            query.AppendLine("  GROUP_CONCAT(election)");
            query.AppendLine("  FROM battle_pokemons");
            query.AppendLine("  WHERE battle_party_id = my_party.battle_party_id");
            query.AppendLine(") AS my_election,");

            query.AppendLine("CASE WHEN");
            query.AppendLine("  EXISTS (SELECT * FROM trainer_master WHERE trainer_id = opponent_party.trainer_id)");
            query.AppendLine("  THEN (SELECT name FROM trainer_master WHERE trainer_id = opponent_party.trainer_id)");
            query.AppendLine("  ELSE ''");
            query.AppendLine("  END my_trainer_name,");

            query.AppendLine("(");
            query.AppendLine("  SELECT");
            query.AppendLine("  GROUP_CONCAT(pokemon_id)");
            query.AppendLine("  FROM battle_pokemons");
            query.AppendLine("  WHERE battle_party_id = opponent_party.battle_party_id");
            query.AppendLine(") AS opponent_pokemon_id,");

            query.AppendLine("(");
            query.AppendLine("  SELECT");
            query.AppendLine("  GROUP_CONCAT(pokemon_icon_id)");
            query.AppendLine("  FROM battle_pokemons");
            query.AppendLine("  WHERE battle_party_id = opponent_party.battle_party_id");
            query.AppendLine(") AS opponent_pokemon_icon_id,");
            query.AppendLine("(");
            query.AppendLine("  SELECT");
            query.AppendLine("  GROUP_CONCAT(election)");
            query.AppendLine("  FROM battle_pokemons");
            query.AppendLine("  WHERE battle_party_id = opponent_party.battle_party_id");
            query.AppendLine(") AS opponent_election,");
            query.AppendLine("record.insert_at");
            query.AppendLine("FROM");
            query.AppendLine(" battle_records AS record");
            query.AppendLine(" INNER JOIN battle_parties AS my_party");
            query.AppendLine(" ON record.battle_record_id = my_party.battle_record_id");
            query.AppendLine(" INNER JOIN battle_parties AS opponent_party");
            query.AppendLine(" ON record.battle_record_id = opponent_party.battle_record_id AND");
            query.AppendLine(" opponent_party.battle_party_id <> my_party.battle_party_id");
            query.AppendLine("WHERE (1=1)");



            string query1 = @"
                SELECT
                record.battle_record_id,
                my_party.battle_result_id AS result,

                CASE WHEN
                    EXISTS (SELECT * FROM trainer_master WHERE trainer_id = my_party.trainer_id)
                    THEN (SELECT name FROM trainer_master WHERE trainer_id = my_party.trainer_id)
                    ELSE ''
                    END my_trainer_name,

                (
                    SELECT
                    GROUP_CONCAT(pokemon_icon_id)
                    FROM battle_pokemons
                    WHERE battle_party_id = my_party.battle_party_id
                ) AS my_pokemon_icon_id,

                (
                    SELECT
                    GROUP_CONCAT(election)
                    FROM battle_pokemons
                    WHERE battle_party_id = my_party.battle_party_id
                ) AS my_election,

                CASE WHEN
                    EXISTS (SELECT * FROM trainer_master WHERE trainer_id = opponent_party.trainer_id)
                    THEN (SELECT name FROM trainer_master WHERE trainer_id = opponent_party.trainer_id)
                    ELSE ''
                    END opponent_trainer_name,

                (
                    SELECT
                    GROUP_CONCAT(pokemon_icon_id)
                    FROM battle_pokemons
                    WHERE battle_party_id = opponent_party.battle_party_id
                ) AS opponent_pokemon_icon_id,

                (
                    SELECT
                    GROUP_CONCAT(election)
                    FROM battle_pokemons
                    WHERE battle_party_id = opponent_party.battle_party_id
                ) AS opponent_election,

                record.insert_at

                FROM
                    battle_records AS record
                    INNER JOIN battle_parties AS my_party
                    ON record.battle_record_id = my_party.battle_record_id
                    INNER JOIN battle_parties AS opponent_party
                    ON record.battle_record_id = opponent_party.battle_record_id AND
                    opponent_party.battle_party_id <> my_party.battle_party_id
                WHERE (1=1)
            ";

            // トレーナー指定
            if (IsWhereTrainerId)
            {
                string addQuery = string.Format(" AND my_party.trainer_id = {0} ", TrainerId);
                query.AppendLine(addQuery);
            }

            // 勝敗条件
            if (IsWhereBattleResultId)
            {
                string addQuery = string.Format(" AND my_party.battle_result_id = {0} ", BattleResultId);
                query.AppendLine(addQuery);
            }

            // having
            StringBuilder havingQuery = new StringBuilder();

            // 自分のパーティー
            foreach (int myPokemonId in MyPokemonIdList)
            {
                // 存在しなければ飛ばす
                if (!ImageFactoryModel.ExistPokemonImage(myPokemonId))
                {
                    continue;
                }

                havingQuery.AppendLine("AND FIND_IN_SET(");
                havingQuery.AppendLine("   (SELECT");
                havingQuery.AppendLine("       pokemon_id");
                havingQuery.AppendLine("   FROM");
                havingQuery.AppendLine("       pokemon_icon_master");
                havingQuery.AppendLine("   WHERE");
                havingQuery.AppendLine(string.Format("pokemon_icon_id = {0}),", myPokemonId));
                havingQuery.AppendLine("my_pokemon_id)");
            }

            // 相手のパーティー
            foreach (int opponentPokemonId in OpponentPokemonIdList)
            {
                // 存在しなければ飛ばす
                if (!ImageFactoryModel.ExistPokemonImage(opponentPokemonId))
                {
                    continue;
                }

                havingQuery.AppendLine("AND FIND_IN_SET(");
                havingQuery.AppendLine("   (SELECT");
                havingQuery.AppendLine("       pokemon_id");
                havingQuery.AppendLine("   FROM");
                havingQuery.AppendLine("       pokemon_icon_master");
                havingQuery.AppendLine("   WHERE");
                havingQuery.AppendLine(string.Format("pokemon_icon_id = {0}),", opponentPokemonId));
                havingQuery.AppendLine("opponent_pokemon_id)");
            }

            // having句追加
            if (havingQuery.Length > 0)
            {
                query.AppendLine("HAVING (1=1)");
                query.AppendLine(havingQuery.ToString());
            }

            //// レコードが重複するので削除
            //query.AppendLine("GROUP BY record.battle_record_id");

            // ソート
            query.AppendLine("ORDER BY record.insert_at DESC");

            // 取得件数
            query.AppendLine(string.Format(" LIMIT {0} ", BattleRecordNumber));

            var data = Select(query.ToString());

            List <BattleRecord> BattleRecordList = new List <BattleRecord>();

            foreach (DataRow dataRow in data.Rows)
            {
                // 構造体に入れる
                BattleRecord battleRecord = new BattleRecord();

                battleRecord.BattleRecordId = ObjectConverter.ToInt(dataRow[0]);
                battleRecord.BattleResultId = ObjectConverter.ToInt(dataRow[1]);

                // 自分のトレーナー名
                battleRecord.MyTrainerName = ObjectConverter.ToString(dataRow[2]);

                // 自分のパーティー
                ObjectConverter.ToString(dataRow[4])
                .Split(',')
                .Select((id, index) => new { Id = ObjectConverter.ToInt(id), Index = index })
                .ToList().ForEach(e => battleRecord.ChangeMyPokemonId(e.Index, e.Id));

                // 自分のオーダー
                ObjectConverter.ToString(dataRow[5])
                .Split(',')
                .Select((order, index) => new { Order = ObjectConverter.ToInt(order), Index = index })
                .ToList().ForEach(e => battleRecord.ChangeMyPokemonOrder(e.Index, e.Order));

                // 相手のトレーナー名
                battleRecord.OpponentTrainerName = ObjectConverter.ToString(dataRow[6]);


                // 相手のパーティー
                ObjectConverter.ToString(dataRow[8])
                .Split(',')
                .Select((id, index) => new { Id = ObjectConverter.ToInt(id), Index = index })
                .ToList().ForEach(e => battleRecord.ChangeOpponentPokemonId(e.Index, e.Id));

                // 相手のオーダー
                ObjectConverter.ToString(dataRow[9])
                .Split(',')
                .Select((order, index) => new { Order = ObjectConverter.ToInt(order), Index = index })
                .ToList().ForEach(e => battleRecord.ChangeOpponentPokemonOrder(e.Index, e.Order));

                BattleRecordList.Add(battleRecord);
            }

            return(BattleRecordList);
        }