Example #1
0
        private bool Run()
        {
            // TODO トレーナーIDをどうするか 起動時にDBに登録する?

            // 勝敗
            int battleResult = _mainWindowModel.BattleResultId;

            // 世代
            int softGenerationId = _mainWindowModel.SoftGenerationId;

            // 整合性チェック
            if (!PrepareParty(_myPartyManegementModel) || !PrepareParty(_opponentPartyManegementModel))
            {
                return(false);
            }

            // 戦績保存
            battleRecordId = _battleRecordDatabaseModel.InsertBattleRecord(softGenerationId);

            if (battleRecordId == DatabaseConst.INSERT_FAIL)
            {
                return(false);
            }

            // 自分のパーティー保存
            if (!SaveBattleParty(battleRecordId, battleResult, TRAINER_MYSELF, _myPartyManegementModel))
            {
                return(false);
            }

            // 相手のパーティー保存
            if (!SaveBattleParty(battleRecordId, BattleResult.FlipBattleResult(battleResult), TRAINER_UNKNOWN, _opponentPartyManegementModel))
            {
                return(false);
            }

            return(true);
        }
Example #2
0
        public List <BattleAggregate> SelectBattleAggregates(bool myViewPoint = true)
        {
            string query = @"
                SELECT
                    (SELECT
                        pokemon_icon_id
	                FROM
                        pokemon_icon_master
	                WHERE
                        pokemon_id = pokemon.pokemon_id
	                LIMIT 1) AS pokemon_icon_id,
                    count(*) AS overlap_number,
	                SUM( 0 <= election AND election <= 2 ) AS election_num,
	                SUM( election = 0 ) AS top_num,
	                SUM( 0 <= election AND election <= 2 AND battle_result_id = 0) As win_num
                FROM
                    battle_pokemons AS pokemon
                INNER JOIN
                    battle_parties AS party
                ON
                    pokemon.battle_party_id = party.battle_party_id
                WHERE (1=1)
            ";

            // トレーナー指定
            if (IsWhereTrainerId)
            {
                string trainerQuery = (myViewPoint) ? " AND party.trainer_id = {0} " : " AND party.trainer_id <> {0} ";
                query += string.Format(trainerQuery, TrainerId);
            }

            // 勝敗条件
            if (IsWhereBattleResultId)
            {
                int tmpBattleResultId = (myViewPoint) ? BattleResultId : BattleResult.FlipBattleResult(BattleResultId);
                query += string.Format(" AND party.battle_result_id = {0} ", tmpBattleResultId);
            }

            // 集計
            query += "GROUP BY pokemon.pokemon_id";

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

            // データ取得
            var data = Select(query);

            // データ変換
            List <BattleAggregate> battleAggregateList = new List <BattleAggregate>();

            foreach (DataRow dataRow in data.Rows)
            {
                BattleAggregate battleAggregate = new BattleAggregate();
                battleAggregate.PokemonIconId  = ObjectConverter.ToInt(dataRow[0]);
                battleAggregate.OverlapNumber  = ObjectConverter.ToInt(dataRow[1]);
                battleAggregate.ElectionNumber = ObjectConverter.ToInt(dataRow[2]);
                battleAggregate.LeadNumber     = ObjectConverter.ToInt(dataRow[3]);
                battleAggregate.WinNumber      = ObjectConverter.ToInt(dataRow[4]);
                battleAggregateList.Add(battleAggregate);
            }

            return(battleAggregateList);
        }