Exemplo n.º 1
0
    private void extractGameInfos(JSONObject json)
    {
        max_cards_action_played = JSONTools.GetIntValue(json, "max_cards_action_played", GameStateReader.INVALID_INT);
        tablespeed = JSONTools.GetIntValue(json, "tablespeed", GameStateReader.INVALID_INT);
        rtc_mode   = JSONTools.GetIntValue(json, "rtc_mode", GameStateReader.INVALID_INT);
        game_result_neutralized = JSONTools.GetStrValue(json, "game_result_neutralized");
        neutralized_player_id   = JSONTools.GetStrValue(json, "neutralized_player_id");

        Debug.Assert(JSONTools.HasFieldOfTypeObject(json, "actions"));
        JSONObject actions = json.GetField("actions");

        action_nbr = JSONTools.GetIntValue(actions, "action_nbr", GameStateReader.INVALID_INT);

        playerorder = new List <string>();
        Debug.Assert(JSONTools.HasFieldOfTypeArray(json, "playerorder"));
        foreach (JSONObject id in json.GetField("playerorder").list)
        {
            Debug.Assert(id.IsString || id.IsNumber);
            if (id.IsString)
            {
                playerorder.Add(id.str);
            }
            else
            {
                playerorder.Add(Mathf.RoundToInt(id.n).ToString());
            }
        }
        Debug.Assert(playerorder.Count == 2);
    }
Exemplo n.º 2
0
 private void extractTokens(JSONObject json)
 {
     tokens = new List <GameStateReaderToken>();
     Debug.Assert(JSONTools.HasFieldOfTypeArray(json, "tokens"));
     foreach (JSONObject token in json.GetField("tokens").list)
     {
         tokens.Add(new GameStateReaderToken(token));
     }
     Debug.Assert(tiles.Count == 8);
 }
Exemplo n.º 3
0
 private void extractTiles(JSONObject json)
 {
     tiles = new List <GameStateReaderTile>();
     Debug.Assert(JSONTools.HasFieldOfTypeArray(json, "map_tiles"));
     foreach (JSONObject tile in json.GetField("map_tiles").list)
     {
         tiles.Add(new GameStateReaderTile(tile));
     }
     Debug.Assert(tiles.Count == 8);
 }
Exemplo n.º 4
0
 private int GetHerseManipulatedCell(int side, string key)
 {
     if (JSONTools.HasFieldOfTypeArray(GetArg(0), "hers"))
     {
         JSONObject herse = GetArg(0).GetField("hers");
         if (side < herse.Count)
         {
             return(GetIntValue(herse[side], key));
         }
     }
     return(-1);
 }
Exemplo n.º 5
0
            private List <int> GetVictimIds(string group)
            {
                List <int> victims = new List <int>();
                JSONObject arg     = GetArg(0);

                Debug.Assert(JSONTools.HasFieldOfTypeArray(arg, group));
                foreach (var victim in arg.GetField(group).list)
                {
                    Debug.Assert(JSONTools.GetIntValue(victim, "id", -1) != -1);
                    victims.Add(JSONTools.GetIntValue(victim, "id"));
                }
                return(victims);
            }
Exemplo n.º 6
0
 private void extractMap(JSONObject json)
 {
     map = new List <List <GameStateReaderCell> >();
     Debug.Assert(JSONTools.HasFieldOfTypeArray(json, "map"));
     foreach (JSONObject column in json.GetField("map").list)
     {
         var cells = new List <GameStateReaderCell>();
         Debug.Assert(JSONTools.HasFieldOfTypeArray(json, "map"));
         foreach (JSONObject cell in column.list)
         {
             cells.Add(new GameStateReaderCell(cell));
         }
         Debug.Assert(cells.Count == 10);
         map.Add(cells);
     }
     Debug.Assert(map.Count == 22);
 }
Exemplo n.º 7
0
            private bool ParseData(JSONObject json)
            {
                if (JSONTools.HasFieldOfTypeString(json, "time"))
                {
                    time = json.GetField("time").str;
                }
                if (JSONTools.HasFieldOfTypeString(json, "channel"))
                {
                    channel = json.GetField("channel").str;
                }
                if (JSONTools.HasFieldOfTypeString(json, "table_id"))
                {
                    tableId = json.GetField("table_id").str;
                }
                if (JSONTools.HasFieldOfTypeString(json, "packet_id"))
                {
                    int.TryParse(json.GetField("packet_id").str, out packetId);
                }
                if (JSONTools.HasFieldOfTypeString(json, "packet_type"))
                {
                    packetTypeStr = json.GetField("packet_type").str; packetType = StringToType(packetTypeStr);
                }
                if (packetType == Type.HISTORY && JSONTools.HasFieldOfTypeString(json, "move_id"))
                {
                    int.TryParse(json.GetField("move_id").str, out moveId);
                }

                notifications = new List <NotificationData>();
                if (JSONTools.HasFieldOfTypeArray(json, "data"))
                {
                    for (int i = 0; i < json.GetField("data").Count; ++i)
                    {
                        notifications.Add(new NotificationData(json.GetField("data")[i]));
                    }
                }

                if (CheckValidity())
                {
                    _status = Status.SLEEPING;
                }

                return(isValid);
            }
Exemplo n.º 8
0
            public List <int> GetRemoveTokenIds()
            {
                Debug.Assert(type == Type.CHARACTER_GET_OUT || type == Type.REMOVE_TOKENS);
                var tokensField = "";

                if (type == Type.CHARACTER_GET_OUT)
                {
                    tokensField = "remove_tokens";
                }
                else if (type == Type.REMOVE_TOKENS)
                {
                    tokensField = "tokens";
                }
                else
                {
                    Debug.Assert(false);
                }
                List <int> ids = new List <int>();
                JSONObject arg = GetArg(0);

                Debug.Assert(JSONTools.HasFieldOfTypeArray(arg, tokensField));
                foreach (var obj in arg.GetField(tokensField).list)
                {
                    int id = 0;
                    if (obj.IsString)
                    {
                        int.TryParse(obj.str, out id);
                    }
                    else if (obj.IsNumber)
                    {
                        id = Mathf.RoundToInt(obj.n);
                    }
                    Debug.Assert(id > 0);
                    ids.Add(id);
                }
                return(ids);
            }
Exemplo n.º 9
0
    private void extractGameState(JSONObject json)
    {
        Debug.Assert(JSONTools.HasFieldOfTypeObject(json, "gamestate"));
        JSONObject gamestate = json.GetField("gamestate");

        name = JSONTools.GetStrValue(gamestate, "name");
        type = JSONTools.GetStrValue(gamestate, "type");

        active_players = new List <string>();
        switch (type)
        {
        case "manager":
        case "game":
        case "activeplayer":
            active_players.Add(JSONTools.GetStrValue(gamestate, "active_player"));
            break;

        case "multipleactiveplayer":
            Debug.Assert(JSONTools.HasFieldOfTypeArray(gamestate, "multiactive"));
            foreach (JSONObject id in gamestate.GetField("multiactive").list)
            {
                Debug.Assert(id.IsString || id.IsNumber);
                if (id.IsString)
                {
                    active_players.Add(id.str);
                }
                else
                {
                    active_players.Add(Mathf.RoundToInt(id.n).ToString());
                }
            }
            Debug.Assert(active_players.Count <= 2);
            break;

        default:
            Debug.Assert(false, "unhandled gamestate type");
            break;
        }

        current_player      = null;
        discoveredRoom      = GameStateReader.INVALID_INT;
        selectedCharacterId = GameStateReader.INVALID_INT;
        targetId            = GameStateReader.INVALID_INT;
        pointsRemaining     = GameStateReader.INVALID_INT;
        modifiedTokens      = new Dictionary <int, GameStateReaderToken>();

        Debug.Assert(gamestate.HasField("args"));
        JSONObject args = gamestate.GetField("args");

        switch (name)
        {
        case "movingCharacter":
        case "movingCharacterContinue":
        {
            Debug.Assert(args.IsObject);
            selectedCharacterId = JSONTools.GetIntValue(args, "character_id");
            pointsRemaining     = JSONTools.GetIntValue(args, "points");
            if (JSONTools.HasFieldOfTypeArray(args, "inital_objects"))
            {
                foreach (var token in args.GetField("inital_objects").list)
                {
                    var tokenData = new GameStateReaderToken(token, true);
                    Debug.Assert(!modifiedTokens.ContainsKey(tokenData.id));
                    modifiedTokens[tokenData.id] = tokenData;
                }
            }
        }
        break;

        case "discoverRoomPlaceToken":
        {
            Debug.Assert(args.IsObject);
            current_player = JSONTools.GetStrValue(args, "turn");
            discoveredRoom = JSONTools.GetIntValue(args, "room", GameStateReader.INVALID_INT);
        }
        break;

        case "combatChooseCard":
        {
            Debug.Assert(args.IsObject);
            selectedCharacterId = JSONTools.GetIntValue(args, "character_id");
            targetId            = JSONTools.GetIntValue(args, "target_id");
        }
        break;
        }
    }