Example #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);
    }
Example #2
0
    public GameStateReaderToken(JSONObject json, bool initialState = false)
    {
        id        = JSONTools.GetIntValue(json, "id", GameStateReader.INVALID_INT);
        player_id = JSONTools.GetStrValue(json, "player_id");
        category  = JSONTools.GetStrValue(json, "category");
        type      = JSONTools.GetStrValue(json, "type");

        if (!initialState)
        {
            location           = JSONTools.GetStrValue(json, "location");
            location_arg       = JSONTools.GetStrValue(json, "location_arg");
            x                  = JSONTools.GetIntValue(json, "x", GameStateReader.INVALID_INT);
            y                  = JSONTools.GetIntValue(json, "y", GameStateReader.INVALID_INT);
            wounded            = JSONTools.GetBoolValue(json, "wounded", 1);
            wounded_this_turn  = JSONTools.GetBoolValue(json, "wounded_this_turn", 1);
            blocked_this_turn  = JSONTools.GetBoolValue(json, "blocked_this_turn", 1);
            additional_actions = JSONTools.GetIntValue(json, "additional_actions", GameStateReader.INVALID_INT);
        }
        else
        {
            location           = JSONTools.GetStrValue(json, "initial_location");
            location_arg       = JSONTools.GetStrValue(json, "initial_location_arg");
            x                  = JSONTools.GetIntValue(json, "initial_x", GameStateReader.INVALID_INT);
            y                  = JSONTools.GetIntValue(json, "initial_y", GameStateReader.INVALID_INT);
            wounded            = false;
            wounded_this_turn  = false;
            blocked_this_turn  = false;
            additional_actions = 0;
        }

        Debug.Assert(isValid);
    }
Example #3
0
 public GameStateReaderPlayer(JSONObject json)
 {
     id    = JSONTools.GetStrValue(json, "id");
     score = JSONTools.GetIntValue(json, "score", GameStateReader.INVALID_INT);
     color = JSONTools.GetStrValue(json, "color");
     order = JSONTools.GetIntValue(json, "player_no", GameStateReader.INVALID_INT);
     Debug.Assert(isValid);
 }
Example #4
0
    private void extractNotifications(JSONObject json)
    {
        Debug.Assert(JSONTools.HasFieldOfTypeObject(json, "notifications"));
        JSONObject notifications = json.GetField("notifications");

        last_packet_id = JSONTools.GetIntValue(notifications, "last_packet_id", GameStateReader.INVALID_INT);
        move_nbr       = JSONTools.GetIntValue(notifications, "move_nbr", GameStateReader.INVALID_INT);
    }
Example #5
0
 public GameStateReaderCard(JSONObject json)
 {
     id           = JSONTools.GetIntValue(json, "id", GameStateReader.INVALID_INT);
     type         = JSONTools.GetStrValue(json, "type");
     type_arg     = JSONTools.GetIntValue(json, "type_arg", GameStateReader.INVALID_INT);
     location     = JSONTools.GetStrValue(json, "location");
     location_arg = JSONTools.GetStrValue(json, "location_arg");
     Debug.Assert(isValid);
 }
Example #6
0
 public GameStateReaderTile(JSONObject json)
 {
     id          = JSONTools.GetIntValue(json, "id", GameStateReader.INVALID_INT);
     type        = JSONTools.GetIntValue(json, "type", GameStateReader.INVALID_INT);
     x           = JSONTools.GetIntValue(json, "x", GameStateReader.INVALID_INT);
     y           = JSONTools.GetIntValue(json, "y", GameStateReader.INVALID_INT);
     orientation = JSONTools.GetIntValue(json, "orientation", GameStateReader.INVALID_INT);
     discovered  = JSONTools.GetBoolValue(json, "discovered", 1);
     Debug.Assert(isValid);
 }
Example #7
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);
            }
Example #8
0
    public List <string> walls; // n, w, s, e  (0=haut, 1=gauche, 2=bas, 3=droite)

    public GameStateReaderCell(JSONObject json)
    {
        x        = JSONTools.GetIntValue(json, "x", GameStateReader.INVALID_INT);
        y        = JSONTools.GetIntValue(json, "y", GameStateReader.INVALID_INT);
        type     = JSONTools.GetStrValue(json, "type");
        type_arg = JSONTools.GetStrValue(json, "type_arg");
        walls    = new List <string>();
        walls.Add(JSONTools.GetStrValue(json, "wall_n"));
        walls.Add(JSONTools.GetStrValue(json, "wall_w"));
        walls.Add(JSONTools.GetStrValue(json, "wall_s"));
        walls.Add(JSONTools.GetStrValue(json, "wall_e"));
        Debug.Assert(isValid);
    }
Example #9
0
 private int GetIntValue(JSONObject obj, string key)
 {
     return(JSONTools.GetIntValue(obj, key, -1));
 }
Example #10
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;
        }
    }