Пример #1
0
        private static IEnumerator Perform2StepAction(BgoSessionObject sessionObject, BgoGame game, String actionValue,
                                                      Action <List <PlayerAction> > callback)
        {
            var postUrl = RemoveCharacterEntities(game.ActionFormSubmitUrl);

            WWWForm myPostData = new WWWForm();

            var actionSp = actionValue.Split(";".ToCharArray());
            var idCarte  = "0";

            foreach (var pair in game.ActionForm)
            {
                if (pair.Key == "action")
                {
                    myPostData.AddField("action", actionValue);
                }
                else if (pair.Key == "idCarteAction")
                {
                    if (actionSp.Length > 1 && actionSp[0] == "12")
                    {
                        idCarte = actionSp[1];
                        myPostData.AddField("idCarteAction", actionSp[1]);
                    }
                    else
                    {
                        myPostData.AddField("idCarteAction", pair.Value);
                    }
                }
                else
                {
                    myPostData.AddField(pair.Key, pair.Value);
                }
            }

            var cookieHeaders = myPostData.headers;

            cookieHeaders.Add("Cookie", "PHPSESSID=" + sessionObject._phpSession + "; identifiant=" + sessionObject._identifiant + "; mot_de_passe=" + sessionObject._motDePasse);

            //var data = Encoding.UTF8.GetString(myPostData.data);

            var www = new WWW(BgoBaseUrl + postUrl, myPostData.data, cookieHeaders);

            yield return(www);

            if (www.error != null)
            {
                Assets.CSharpCode.UI.Util.LogRecorder.Log(www.error);

                yield break;
            }

            var responseText = www.text;

            //Step1 Complete

            var labelMatches = BgoRegexpCollections.ExtractActionChoice.Matches(responseText);

            if (labelMatches.Count <= 0)
            {
                callback(new List <PlayerAction>());
                yield break;
            }
            var actions = new List <PlayerAction>();

            foreach (Match m in labelMatches)
            {
                var msg      = m.Groups[2].Value;
                var optValue = m.Groups[1].Value;

                BgoPlayerAction pa = new BgoPlayerAction {
                    ActionType = PlayerActionType.Unknown
                };
                pa.Data[0] = msg;
                pa.Data[1] = optValue;
                pa.Data[2] = idCarte;
                actions.Add(pa);
            }
            BgoActionFormater.FormatInternalAction(actions, responseText);

            if (callback != null)
            {
                callback(actions);
            }
        }
Пример #2
0
        /// <summary>
        /// 填充面板的帮助方法
        /// </summary>
        /// <param name="html"></param>
        /// <param name="game"></param>
        // ReSharper disable once FunctionComplexityOverflow
        internal static void FillGameBoard(String html, BgoGame game)
        {
            //分析用户面板

            game.PossibleActions = new List <PlayerAction>();

            //解出卡牌列
            var matches = BgoRegexpCollections.ExtractCardRow.Matches(html);

            game.CardRow = new List <CardRowCardInfo>();

            foreach (Match mc in matches)
            {
                var card = civilopedia.GetCardInfoByName((Age)Enum.Parse(typeof(Age), mc.Groups[5].Value),
                                                         mc.Groups[6].Value);

                BgoCardRowCardInfo cardRowCardInfo = new BgoCardRowCardInfo
                {
                    Card            = card,
                    CanPutBack      = mc.Groups[4].Value.Contains("carteEnMain"),
                    CanTake         = mc.Groups[2].Value != "" && (!mc.Groups[4].Value.Contains("carteEnMain")),
                    CivilActionCost =
                        BgoRegexpCollections.ExtractGovenrmentAndActionPointsMissing.Matches(mc.Groups[8].Value).Count
                };

                //LogRecorder.Log(card.CardName + mc.Groups[2].Value);

                BgoPlayerAction pa = new BgoPlayerAction
                {
                    ActionType = PlayerActionType.TakeCardFromCardRow
                };
                pa.Data[0] = cardRowCardInfo;
                pa.Data[1] = game.CardRow.Count; //Card Row Pos
                pa.Data[2] = mc.Groups[3].Value; //idNote
                pa.Data[3] = mc.Groups[2].Value; //PostUrl

                //能拿能放回去,才能有Action
                if (cardRowCardInfo.CanPutBack || cardRowCardInfo.CanTake)
                {
                    game.PossibleActions.Add(pa);
                }

                game.CardRow.Add(cardRowCardInfo);
            }

            //当前事件
            var matchCurrentEvent = BgoRegexpCollections.ExtractCurrentEvent.Match(html);

            if (matchCurrentEvent.Groups[3].Value == "")
            {
                game.CurrentEventAge  = (Age)Enum.Parse(typeof(Age), matchCurrentEvent.Groups[5].Value);
                game.CurrentEventCard =
                    civilopedia.GetCardInfoByName(game.CurrentEventAge, matchCurrentEvent.Groups[6].Value);
                game.CurrentEventCount = matchCurrentEvent.Groups[7].Value;
            }
            else
            {
                game.CurrentEventAge   = (Age)Enum.Parse(typeof(Age), matchCurrentEvent.Groups[3].Value);
                game.CurrentEventCard  = null;
                game.CurrentEventCount = matchCurrentEvent.Groups[7].Value;
            }

            //未来事件
            var matchFutureEvent = BgoRegexpCollections.ExtractFutureEvent.Match(html);

            if (matchFutureEvent.Groups[1].Value.Length > 4)
            {
                game.FutureEventAge   = Age.A;
                game.FutureEventCount = "0";
            }
            else
            {
                game.FutureEventAge   = (Age)Enum.Parse(typeof(Age), matchFutureEvent.Groups[1].Value);
                game.FutureEventCount = matchFutureEvent.Groups[2].Value;
            }

            //卡牌剩余
            var matchCivilRemain = BgoRegexpCollections.ExtractCivilCardRemains.Match(html);

            game.CivilCardsRemain = Convert.ToInt32(matchCivilRemain.Groups[2].Value);
            var matchMilitaryRemain = BgoRegexpCollections.ExtractMilitryCardRemains.Match(html);

            game.MilitaryCardsRemain = Convert.ToInt32(matchMilitaryRemain.Groups[2].Value);

            //当前阶段
            var matchPhase = BgoRegexpCollections.ExtractGamePhase.Match(html);
            var phase      = matchPhase.Groups[1].Value;

            switch (phase.Trim())
            {
            case "Political Phase":
                game.CurrentPhase = TtaPhase.PoliticalPhase;
                break;

            case "Action Phase":
                game.CurrentPhase = TtaPhase.ActionPhase;
                break;

            case "Event Resolution":
                game.CurrentPhase = TtaPhase.EventResolution;
                break;

            case "Discard Phase":
                game.CurrentPhase = TtaPhase.DiscardPhase;
                break;

            default:
                game.CurrentPhase = TtaPhase.OtherPhase;
                break;
            }

            //时代和回合
            var matchAgeAndRound = BgoRegexpCollections.ExtractAgeAndRound.Match(html);

            game.CurrentAge   = (Age)Enum.Parse(typeof(Age), matchAgeAndRound.Groups[1].Value);
            game.CurrentRound = Convert.ToInt32(matchAgeAndRound.Groups[2].Value);

            //可抄袭阵型
            var sharedTacticsMatch = BgoRegexpCollections.ExtractSharedTactics.Match(html);

            game.SharedTactics = new List <CardInfo>();
            foreach (Match m in BgoRegexpCollections.ExtractSharedTacticsItem.Matches(sharedTacticsMatch.Groups[1].Value))
            {
                if (m.Groups[1].Value == "&nbsp;")
                {
                    continue;
                }
                game.SharedTactics.Add(civilopedia.GetCardInfoByName((Age)Enum.Parse(typeof(Age), m.Groups[1].Value),
                                                                     m.Groups[2].Value));
            }

            //拆开玩家面板

            matches     = BgoRegexpCollections.ExtractPlayerPlate.Matches(html);
            game.Boards = new List <TtaBoard>();

            int plateStart = -1;

            foreach (Match mc in matches)
            {
                if (plateStart != -1)
                {
                    String plate = html.Substring(plateStart, mc.Index - plateStart);

                    TtaBoard board = new TtaBoard();
                    game.Boards.Add(board);

                    FillPlayerBoard(board, plate);
                }

                plateStart = mc.Index;


                if (mc.Groups[2].Value != "")
                {
                    break;
                }
            }

            #region 校准名字和资源

            ExtractPlayerNameAndResource(html, game);

            #endregion


            //可用行动
            var subDropdown = BgoRegexpCollections.ExtractSubDropDown("action").Match(html);
            if (subDropdown.Success)
            {
                matches = BgoRegexpCollections.ExtractActions.Matches(subDropdown.Groups[1].Value);
                foreach (Match mc in matches)
                {
                    BgoPlayerAction pa = new BgoPlayerAction {
                        ActionType = PlayerActionType.Unknown
                    };
                    pa.Data[0] = mc.Groups[2].Value;
                    pa.Data[1] = mc.Groups[1].Value;

                    game.PossibleActions.Add(pa);
                }

                Match mSubmitForm = BgoRegexpCollections.ExtractSubmitForm.Match(html);
                game.ActionForm = new Dictionary <string, string>();

                if (mSubmitForm.Success)
                {
                    game.ActionFormSubmitUrl = mSubmitForm.Groups[1].Value;
                    matches = BgoRegexpCollections.ExtractSubmitFormDetail.Matches(mSubmitForm.Groups[2].Value);
                    foreach (Match mc in matches)
                    {
                        if (mc.Groups[2].Value != "")
                        {
                            game.ActionForm[mc.Groups[2].Value] = "";
                        }
                        else
                        {
                            game.ActionForm[mc.Groups[4].Value] = mc.Groups[5].Value;
                        }
                    }
                }
            }

            BgoActionFormater.Format((BgoGame)game, html);
        }