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); }
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); }
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); }
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); }
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); }
private List <string> GetFighterNames(string group) { List <string> fighters = new List <string>(); JSONObject arg = GetArg(0); Debug.Assert(JSONTools.HasFieldOfTypeObject(arg, group)); JSONObject figthers = arg.GetField(group); Debug.Assert(JSONTools.HasFieldOfTypeObject(figthers, "args")); JSONObject args = figthers.GetField("args"); foreach (var key in args.keys) { fighters.Add(JSONTools.GetStrValue(args, key)); } return(fighters); }
private void extractTokenTypes(JSONObject json) { tokenTypes = new List <List <GameStateReaderTokenType> >(); tokenTypes.Add(new List <GameStateReaderTokenType>()); // player 1 tokenTypes.Add(new List <GameStateReaderTokenType>()); // player 2 Debug.Assert(JSONTools.HasFieldOfTypeObject(json, "token_types")); JSONObject jsontokens = json.GetField("token_types"); foreach (string key in jsontokens.keys) { Debug.Assert(JSONTools.HasFieldOfTypeObject(jsontokens, key)); JSONObject jsontoken = jsontokens.GetField(key); string category = JSONTools.GetStrValue(jsontoken, "category"); Debug.Assert(category != null); Multi.Logger.Instance.Log("LOG", "READER: register " + key + " " + category); tokenTypes[0].Add(new GameStateReaderTokenType(key, category)); tokenTypes[1].Add(new GameStateReaderTokenType(key, category)); } Debug.Assert(tokenTypes[0].Count == 14 && tokenTypes[1].Count == 14); }
private string GetStrValue(JSONObject obj, string key) { return(JSONTools.GetStrValue(obj, key)); }
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; } }