/************************************************************************/ /* 内部処理 */ /************************************************************************/ //============================================================================ //! 指定したメンバーIDからリーフ番号を取得 private int _GetLeafIndex(BattleManager.SBattleInfo iBattleInfo, int iMemberID) { //参加番号を取得 int join_ID = _GetJoinID(iBattleInfo, iMemberID); if (join_ID == -1) { return -1; } //チーム戦の場合はチーム番号 int check_ID = join_ID; if (iBattleInfo.mTeamList.Count != 0) { check_ID = _GetTeamID(iBattleInfo, join_ID); if (check_ID == -1) { return -1; } } //リーフ番号を取得する var obj = (SimpleTournamentObject)iBattleInfo.mBattleObject; var leaf_list = obj.GetLeafInfoIndexList(); foreach (var iIndex in System.Linq.Enumerable.Range(0, leaf_list.Count)) { if (leaf_list[iIndex] == check_ID) { return iIndex; } } //ありえないけど一応-1返す return -1; }
//============================================================================ //! 指定したメンバーIDの参加IDを取得する private int _GetJoinID(BattleManager.SBattleInfo iBattleInfo, int iMemberID) { foreach (var iJoinInfo in iBattleInfo.mJoinList) { if (iJoinInfo.mMemberID == iMemberID) { return iJoinInfo.mJoinID; } } //未参加 return -1; }
//============================================================================ //! 指定した参加IDからチームIDを取得する private int _GetTeamID(BattleManager.SBattleInfo iBattleInfo, int iCheckJoinID) { foreach (var iTeamInfo in iBattleInfo.mTeamList) { foreach (var iJoinID in iTeamInfo.mJoinIDList) { if (iCheckJoinID == iJoinID) { return iTeamInfo.mTeamID; } } } //無し return -1; }
/************************************************************************/ /* 個人用の結果取得用 */ /************************************************************************/ /// <summary> /// 指定した大会の結果情報を取得 /// </summary> /// <param name="iBattleInfo">大会情報</param> /// <returns></returns> public SSimpleTournamentResult GetSimpleTournamentResult(BattleManager.SBattleInfo iBattleInfo) { var info = new SSimpleTournamentResult(); info.mTeamBattleFlg = (iBattleInfo.mTeamList.Count != 0); info.mRankMap = new Dictionary<int, int>(); foreach (var iJoinInfo in iBattleInfo.mJoinList) { var rank = GetSimpleTournamentResult(iBattleInfo, iJoinInfo.mMemberID).mRank; if (rank == 1) { info.mWinnerID = (info.mTeamBattleFlg) ? _GetTeamID(iBattleInfo, iJoinInfo.mJoinID) : iJoinInfo.mMemberID; } info.mRankMap.Add(iJoinInfo.mMemberID, rank); } return info; }
/************************************************************************/ /* 基本処理 */ /************************************************************************/ /// <summary> /// 大会を実行する /// </summary> public void BeginBattle(BattleManager.EBattleKind iBattleKind) { if (mBeginBattleFlg) { SystemUtility.DisplayErrorDialog("大会管理の二重起動が発生しました"); return; } mCurrentBattleInfo = new BattleManager.SBattleInfo(); mCurrentBattleInfo.mBattleKind = iBattleKind; mCurrentBattleInfo.mDate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); mCurrentBattleInfo.mJoinList = new List <BattleManager.SBattleJoinInfo>(); mCurrentBattleInfo.mTeamList = new List <BattleManager.SBattleTeamInfo>(); mLockJoinMemberFlg = false; mBeginBattleFlg = true; mLockTeamFlg = false; }
/// <summary> /// 指定した大会で指定したメンバーの情報を取得 /// </summary> /// <param name="iBattleInfo">大会情報</param> /// <param name="iMemberID">メンバーID</param> /// <returns>情報</returns> public SMemberResult GetSimpleTournamentResult(BattleManager.SBattleInfo iBattleInfo, int iMemberID) { var info = new SMemberResult(); //リーフ番号取得 int leaf_index = _GetLeafIndex(iBattleInfo, iMemberID); if (leaf_index == -1) { return info; } //何回戦かの初期化 int depth = 0; var join_val = ((iBattleInfo.mTeamList.Count == 0) ? iBattleInfo.mJoinList.Count : iBattleInfo.mTeamList.Count); while (true) { int val = (int)Math.Pow(2, (int)depth); if (val >= join_val) { break; } ++depth; } var check_val = ((int)Math.Pow(2, (int)depth) - join_val); bool just_tournament_flg = (check_val == 0); //偶数の場合 if ((check_val % 2) == 0) { check_val /= 2; info.mVersusVal = (check_val == 0 || leaf_index < check_val || leaf_index >= (join_val - check_val)) ? 1 : 0; } //奇数の場合 else { check_val /= 2; info.mVersusVal = (leaf_index < check_val || leaf_index >= (join_val - (check_val + 1))) ? 1 : 0; } info.mBeginVersus = info.mVersusVal; //勝利数から結果を算出 var obj = (SimpleTournamentObject)iBattleInfo.mBattleObject; var win_val = _GetSimpleTournamentWinVal(leaf_index); if (win_val == 0) { //初戦敗退 info.mRank = join_val; } else { //回戦数を取得 var versus_val = info.mVersusVal; info.mVersusVal += win_val; //順位の計算 if (just_tournament_flg) { //割り切れるトーナメントの場合は単純に int pow = (int)depth - info.mVersusVal + 1; info.mRank = (int)Math.Pow(2, pow); } else { //自分が0回戦スタートで1勝の場合順位の計算方法が変わる if (versus_val == 0 && win_val == 1) { //初戦敗退者の数を計算する int first_versus_lost_val = 0; foreach (var iIndex in System.Linq.Enumerable.Range(0, join_val)) { foreach (var iResult in obj.GetResultList()) { //無視 if (iResult.mIgnoreTournament) { continue; } //上方向にある var check_index = -1; if (iResult.mReafLabelIndexList[0] == iIndex) { check_index = 1; } //下方向にある else if (iResult.mReafLabelIndexList[1] == iIndex) { check_index = 0; } //存在する if (check_index != -1) { if (iResult.mWinTeamIndex == check_index) { ++first_versus_lost_val; } break; } } } info.mRank = join_val - first_versus_lost_val; } //優勝 else if (info.mVersusVal == depth) { info.mRank = 1; } else { int pow = (int)depth - info.mVersusVal; info.mRank = (int)Math.Pow(2, pow); } } } return info; }
/************************************************************************/ /* 基本処理 */ /************************************************************************/ /// <summary> /// コンストラクタ /// </summary> public SimpleTournamentResultControl(int iMemberID, BattleManager.SMemberBattleResult iResult, BattleManager.SBattleInfo iBattleInfo) { InitializeComponent(); //情報登録 bool team_flg = (iBattleInfo.mTeamList.Count != 0); MainGroupBox.Header = "大会No." + iResult.mIndex.ToString() + " - " + iBattleInfo.mName + " -"; TournamentKindTextBlock.Text = "種別:" + (team_flg ? "チーム戦" : "シングル戦"); JoinNumTextBlock.Text = "参加人数:" + iBattleInfo.mJoinList.Count.ToString() + "人"; DateTextBlock.Text = "開催日時 " + iBattleInfo.mDate; JoinTeamNumTextBlock.Text = team_flg ? "参加チーム数:" + iBattleInfo.mTeamList.Count.ToString() + "チーム" : ""; ResultTextBlock.Text = "- "; var obj = (SimpleTournamentObject)iBattleInfo.mBattleObject; var result = obj.GetSimpleTournamentResult(iBattleInfo, iMemberID); if (result.mRank == 1) { ResultTextBlock.Text += "優勝"; } else if (result.mRank == 2) { ResultTextBlock.Text += "準優勝"; ResultTextBlock.Foreground = SystemUtility.CreateLinearGradientBrash(SystemUtility.StringToColor("#FFFFFF00"), SystemUtility.StringToColor("#FFFFFFF55")); } else { ResultTextBlock.Text += ("第" + result.mRank + "位"); ResultTextBlock.Foreground = new SolidColorBrush(SystemUtility.StringToColor("#FF5555FF")); } ResultTextBlock.Text += " -"; BeginVersusNumTextBlock.Text = result.mBeginVersus.ToString() + "回戦からの開始"; var character_Info = PresetManager.GetInstance().GetCharacterInfo(iResult.mUseCharacterID); CharacterIcon.Source = character_Info.mIconImage; UseCharacterTextBlock.Text = "使用キャラ:" + character_Info.mName; }