public static GameOrderPlayCardDiplomacy Create(CardInstanceIDType cardInstanceID, PlayerIDType playerID, PlayerIDType playerOne, PlayerIDType playerTwo)
        {
            var o = new GameOrderPlayCardDiplomacy();

            o.CardInstanceID = cardInstanceID;
            o.PlayerID       = (PlayerIDType)playerID;
            o.PlayerOne      = playerOne;
            o.PlayerTwo      = playerTwo;
            return(o);
        }
Пример #2
0
        public static GameOrder ReadOrder(JToken jOrder)
        {
            var type = (string)jOrder["type"];

            var playerID = (PlayerIDType)(int)jOrder["playerID"];

            if (type == "GameOrderDeploy")
            {
                var terrID = (TerritoryIDType)(int)jOrder["deployOn"];
                var armies = (int)jOrder["armies"];
                return(GameOrderDeploy.Create(armies, playerID, terrID));
            }

            if (type == "GameOrderAttackTransfer")
            {
                var from            = (TerritoryIDType)(int)jOrder["from"];
                var to              = (TerritoryIDType)(int)jOrder["to"];
                var armies          = ToArmies((string)jOrder["numArmies"]);
                var attackTeammates = (bool)jOrder["attackTeammates"];
                var byPercent       = (bool)jOrder["byPercent"];
                var attackTransfer  = (AttackTransferEnum)Enum.Parse(typeof(AttackTransferEnum), (string)jOrder["attackTransfer"]);
                return(GameOrderAttackTransfer.Create(playerID, from, to, attackTransfer, byPercent, armies, attackTeammates));
            }

            if (type.StartsWith("GameOrderPlayCard"))
            {
                var cardInstanceID = (CardInstanceIDType)Guid.Parse((string)jOrder["cardInstanceID"]);
                switch (type)
                {
                case "GameOrderPlayCardReinforcement":
                    return(GameOrderPlayCardReinforcement.Create(cardInstanceID, playerID));

                case "GameOrderPlayCardAbandon":
                    return(GameOrderPlayCardAbandon.Create(cardInstanceID, playerID, (TerritoryIDType)(int)jOrder["targetTerritoryID"]));

                case "GameOrderPlayCardAirlift":
                    return(GameOrderPlayCardAirlift.Create(cardInstanceID, playerID, (TerritoryIDType)(int)jOrder["from"], (TerritoryIDType)(int)jOrder["to"], ToArmies((string)jOrder["armiesToAirlift"])));

                case "GameOrderPlayCardBlockade":
                    return(GameOrderPlayCardBlockade.Create(cardInstanceID, playerID, (TerritoryIDType)(int)jOrder["targetTerritoryID"]));

                case "GameOrderPlayCardBomb":
                    return(GameOrderPlayCardBomb.Create(cardInstanceID, playerID, (TerritoryIDType)(int)jOrder["targetTerritoryID"]));

                case "GameOrderPlayCardDiplomacy":
                    return(GameOrderPlayCardDiplomacy.Create(cardInstanceID, playerID, (PlayerIDType)(int)jOrder["playerOne"], (PlayerIDType)(int)jOrder["playerTwo"]));

                case "GameOrderPlayCardGift":
                    return(GameOrderPlayCardGift.Create(cardInstanceID, playerID, (TerritoryIDType)(int)jOrder["territoryID"], (PlayerIDType)(int)jOrder["giftTo"]));

                case "GameOrderPlayCardOrderDelay":
                    return(GameOrderPlayCardOrderDelay.Create(cardInstanceID, playerID));

                case "GameOrderPlayCardOrderPriority":
                    return(GameOrderPlayCardOrderPriority.Create(cardInstanceID, playerID));

                case "GameOrderPlayCardReconnaissance":
                    return(GameOrderPlayCardReconnaissance.Create(cardInstanceID, playerID, (TerritoryIDType)(int)jOrder["targetTerritory"]));

                case "GameOrderPlayCardSanctions":
                    return(GameOrderPlayCardSanctions.Create(cardInstanceID, playerID, (PlayerIDType)(int)jOrder["sanctionedPlayerID"]));

                case "GameOrderPlayCardSpy":
                    return(GameOrderPlayCardSpy.Create(cardInstanceID, playerID, (PlayerIDType)(int)jOrder["targetPlayerID"]));

                case "GameOrderPlayCardSurveillance":
                    return(GameOrderPlayCardSurveillance.Create(cardInstanceID, playerID, (BonusIDType)(int)jOrder["targetBonus"]));

                case "GameOrderPlayCardFogged":
                    return(GameOrderPlayCardFogged.Create(playerID, cardInstanceID));
                }
            }


            switch (type)
            {
            case "GameOrderReceiveCard":

                var ret = new GameOrderReceiveCard();
                ret.PlayerID         = (PlayerIDType)(int)jOrder["playerID"];
                ret.InstancesCreated = new List <CardInstance>();
                foreach (var card in (JArray)jOrder["cardsMadeWhole"])
                {
                    var inst = new CardInstance();
                    inst.ID     = (CardInstanceIDType)Guid.Parse((string)card["cardInstanceID"]);
                    inst.CardID = (CardIDType)(int)card["cardID"];
                    ret.InstancesCreated.Add(inst);
                }
                return(ret);

            case "GameOrderStateTransition":
                var stateTrans = new GameOrderStateTransition();
                stateTrans.PlayerID = (PlayerIDType)(int)jOrder["playerID"];
                stateTrans.NewState = (GamePlayerState)Enum.Parse(typeof(GamePlayerState), (string)jOrder["newState"]);
                return(stateTrans);

            case "ActiveCardWoreOff":
                var active = new ActiveCardWoreOff();
                active.PlayerID       = (PlayerIDType)(int)jOrder["playerID"];
                active.CardInstanceID = (CardInstanceIDType)Guid.Parse((string)jOrder["cardInstanceID"]);
                return(active);

            case "GameOrderDiscard":
                return(GameOrderDiscard.Create((PlayerIDType)(int)jOrder["playerID"], (CardInstanceIDType)Guid.Parse((string)jOrder["cardInstanceID"])));
            }

            throw new Exception("Need handler for order type " + type);
        }