public static void Save() { if (!CanSave()) { return; } lastSave = Game.GameTime; payerJson = new PlayerJson(); if (!Directory.Exists(saveFilePath)) { Debug.Log("Player save directory not found, creating it..."); Directory.CreateDirectory(saveFilePath); } if (CurrentPlayerVehicle != null) { payerJson.CurrentVehicle = new VehicleJson(); payerJson.CurrentVehicle.SetVehicle(CurrentPlayerVehicle); } SavePlayerData(payerJson.ToJson()); }
public static void Load() { Game.Player.Money = 0; Game.Player.WantedLevel = 0; Game.Player.Character.Weapons.RemoveAll(); if (HasSaveGame()) { string json = LoadPlayerData(); if (json != "") { PlayerJson playerJson = PlayerJson.FromJson(json); playerJson.Spawn(); } } else { Screen.FadeIn(500); if (Main.configSettings.Info_Intro_Screen) { IntroScreen intro = Script.InstantiateScript <IntroScreen>(); intro.Start(); } Notification.Show(NotificationIcon.Multiplayer, "GTAVOverride", "Mod has initialized!", "Mod has initialized a new savegame file, your progress will be saved from now on.", true, true); } loaded = true; lastSave = Game.GameTime; Debug.Log("Player loaded!"); }
public async Task Test_Player_Movement() { PlayerJson player = CreatePlayer("Karolis"); var url = await ws.CreatePlayerAsync(player); player = await ws.GetPlayerAsync(url.PathAndQuery); player.x += 1; var updateStatusCode = await ws.UpdatePlayerAsync(player); PlayerJson playerFromServer = await ws.GetPlayerAsync(url.PathAndQuery); ComparePlayers(player, playerFromServer); player.x -= 1; updateStatusCode = await ws.UpdatePlayerAsync(player); playerFromServer = await ws.GetPlayerAsync(url.PathAndQuery); ComparePlayers(player, playerFromServer); player.y += 1; updateStatusCode = await ws.UpdatePlayerAsync(player); playerFromServer = await ws.GetPlayerAsync(url.PathAndQuery); ComparePlayers(player, playerFromServer); player.y -= 1; updateStatusCode = await ws.UpdatePlayerAsync(player); playerFromServer = await ws.GetPlayerAsync(url.PathAndQuery); ComparePlayers(player, playerFromServer); }
private IEnumerator GetInfoPlayer() { using (UnityWebRequest httpClient = new UnityWebRequest(player.HttpServerAddress + "/api/Player/GetPlayerInfo/" + player.Id, "GET")) { httpClient.SetRequestHeader("Authorization", "bearer " + player.Token); httpClient.SetRequestHeader("Accept", "application/json"); httpClient.downloadHandler = new DownloadHandlerBuffer(); yield return(httpClient.SendWebRequest()); if (httpClient.isNetworkError || httpClient.isHttpError) { throw new System.Exception("GetInfoPlayer > Error: " + httpClient.responseCode + ", Info: " + httpClient.error); } else { string jsonResponse = httpClient.downloadHandler.text; PlayerJson playerJson = JsonUtility.FromJson <PlayerJson>(jsonResponse); player.FirstName = playerJson.FirstName; player.LastName = playerJson.LastName; player.DateOfBirth = playerJson.DateOfBirth; player.NickName = playerJson.NickName; player.Email = playerJson.Email; player.City = playerJson.City; player.DateJoined = playerJson.DateJoined; player.BlobUri = playerJson.BlobUri; } } }
//public string Create(Player player) public ActionResult <Player> Create([FromBody] PlayerJson player) { _context.players.Add(player); _context.SaveChanges(); //return Ok(); //"created - ok"; return(CreatedAtRoute("GetPlayer", new { id = player.id }, player)); }
public async Task Test_PlayerCreation_NewPlayer() { PlayerJson player = CreatePlayer("Jonas"); var url = await ws.CreatePlayerAsync(player); PlayerJson playerFromServer = await ws.GetPlayerAsync(url.PathAndQuery); ComparePlayers(player, playerFromServer); }
public async Task <HttpStatusCode> UpdatePlayerAsync(PlayerJson player) { HttpResponseMessage response = await client.PutAsJsonAsync( requestUri + $"{player.id}", player); response.EnsureSuccessStatusCode(); return(response.StatusCode); }
public void Start(PlayerJson playerJson) { this.playerJson = playerJson; this.vehicleJson = playerJson.CurrentVehicle; this.loadoutJson = playerJson.Weapons; Tick += InitPlayer_Tick; Debug.Log("Starting init player..."); }
public void Save() { myPlayer = new PlayerJson(PlayerInfo.transform.position.x, PlayerInfo.transform.position.y, PlayerInfo.transform.position.z, playerCode.getHP(), playerCode.getBullet()); string json = JsonUtility.ToJson(myPlayer); File.WriteAllText(Application.dataPath + "/MyProject/FinalProject/Player.json", json.ToString()); print("Saved"); }
public ActionResult <PlayerJson> GetById(long id) { PlayerJson p = _context.players.Find(id); if (p == null) { return(NotFound("player not found")); } return(p); }
public async Task <PlayerJson> GetPlayerAsync(string path) { PlayerJson player = null; HttpResponseMessage response = await client.GetAsync(path); if (response.IsSuccessStatusCode) { player = await response.Content.ReadAsAsync <PlayerJson>(); } return(player); }
private void ComparePlayers(PlayerJson player, PlayerJson playerFromServer) { Assert.AreEqual(player.x, playerFromServer.x); Assert.AreEqual(player.y, playerFromServer.y); Assert.AreEqual(player.name, playerFromServer.name); Assert.AreEqual(player.hitpoints, playerFromServer.hitpoints); Assert.AreEqual(player.attack, playerFromServer.attack); Assert.AreEqual(player.defence, playerFromServer.defence); Assert.AreEqual(player.level, playerFromServer.level); Assert.AreEqual(player.experience, playerFromServer.experience); Assert.AreEqual(player.gold, playerFromServer.gold); }
public IActionResult Update(long id, [FromBody] PlayerJson p) { var pp = _context.players.Find(id); if (pp == null) { return(NotFound()); } pp.x = p.x; pp.y = p.y; _context.players.Update(pp); _context.SaveChanges(); return(Ok()); //NoContent(); }
// Use this for initialization void Start() { path = Application.streamingAssetsPath + "/player.json"; jsonString = File.ReadAllText(path); PlayerJson gamePlayer = JsonUtility.FromJson <PlayerJson>(jsonString); Debug.Log(gamePlayer.Attack); Inventory = new List <string>(); // Current position DungeonIndex = new Vector2(2, 2); // Set up the dungeon for navigation and check if it is empty this.CurrentLocation = world.Dungeon[(int)DungeonIndex.x, (int)DungeonIndex.y]; this.CurrentLocation.Empty = true; UIController.OnPlayerStatChange(); UIController.OnPlayerItemsChange(); }
public async Task <Uri> CreatePlayerAsync(PlayerJson player) { HttpResponseMessage response = await client.PostAsJsonAsync( requestUri, player); response.EnsureSuccessStatusCode(); // Deserialize the updated product from the response body. PlayerJson player2 = await response.Content.ReadAsAsync <PlayerJson>(); if (player2 != null) { ShowProduct(player2); } // return URI of the created resource. return(response.Headers.Location); }
void SetLoginData(Dictionary <string, object> main) { var data = GetDic((string)main["data"]); //それぞれのjsonを取得 var pjson = ((Dictionary <string, object>)data ["pjson"])["data"]; var cjson = ((Dictionary <string, object>)data ["cjson"])["data"]; //プレイヤーjson¥ playerJson = JsonMapper.ToObject <PlayerJson> ((string)pjson); //dictionary変換 -> 配列変換 List <object> x = (List <object>)GetDic((string)cjson)["cd"]; cardsJson = new List <Carddata> (); for (int i = 0; i < x.Count; i++) { List <object> y = (List <object>)x [i]; Carddata cd = new Carddata().Set(0, toInt(y[0]), toInt(y[1]), toInt(y[2])); cardsJson.Add(cd); } // Debug.Log( GetDic((string)cjson)["cd"]); //それぞれのdataをDictionaryで取得 // var pdata = GetDic ((string)pjson ["data"]); // var cdata = GetDic ((string)cjson ["data"]); //jsonからclassをつくる // cardsJson = JsonMapper.ToObject<List<CardsJson>> ((string) GetDic((string)cjson)["cd"]); //pjsonから // // // var logind = GetDic ((string)data); // // UserName = (string)logind ["name"]; // playerJson.coin = Convert.ToInt32( logind ["coin"]); // playerJson.uid= Convert.ToInt32( logind ["uid"]); // playerJson.dia = Convert.ToInt32 (logind ["dia"]); // playerJson.loginDays = Convert.ToInt32 (logind ["loginDays"]); // playerJson.rate = Convert.ToInt32 (logind ["rate"]); }
private void Start() { players = new PlayerJson[2]; players[0] = new PlayerJson { id = "0", pos_x = 24, pos_y = 52 }; players[1] = new PlayerJson { id = "1", pos_x = 17, pos_y = 48 }; json = JsonHelper.ToJson <PlayerJson>(players, false); Debug.Log(json); players[0].id = "ss"; players[0].pos_x = 25; players[1].id = "sst"; players = JsonHelper.FromJson <PlayerJson>(json); Debug.Log(players[0].pos_x); Debug.Log(players[1].id); }
static void ShowProduct(PlayerJson player) { Console.WriteLine($"Id: {player.id}\tName: {player.name}\tScore: " + $"{player.experience}\tposX: {player.x}\tposY: {player.y}"); }
//Receive message loop function IEnumerator RecvEvent() { print("Starting RecvEvent coroutine."); //InitWebSocket("ws://ec2-3-84-148-203.compute-1.amazonaws.com:8080"); //First we create the connection. print("Opening web socket to ws://47.144.17.150:8080"); InitWebSocket("ws://47.144.17.150:8080"); //First we create the connection. print("Web socket open"); //InitWebSocket("ws://47.144.8.185"); //InitWebSocket("ws://ec2-3-88-230-113.compute-1.amazonaws.com:8080"); //TEMPORARY TEST CONNECTION FOR CHRISTIAN'S EC2. while (true) { if (recvList.Count > 0) { //When our message queue has string coming. // check message type: play, other_player_connected, move, turn, disconnect string message = recvList.Dequeue(); //print("Message received from server: " + message); if (message == "You are connected to the server!" && !skipPlay) { print("--- Sending play message!"); // send server player name and let server randomly pick spawn point from list of spawn points // spawn point for player List <SpawnPoint> playerSpawnPoints = GetComponent <PlayerSpawner>().playerSpawnPoints; print("Current vehicle selection: " + Player.VehicleLoadout.Item1 + " " + Player.VehicleLoadout.Item2); PlayerJson playerJson = new PlayerJson(playerNameStr, playerSpawnPoints, Player.VehicleLoadout); string data = JsonUtility.ToJson(playerJson); Dispatch("play", data, true); } else { string[] dataArr = message.Split(' '); //print("Client message at [0]: " + dataArr[0]); //print("Client message at [1]: " + dataArr[1]); if (dataArr[0] == "play") { // receive play from server means you need to get the spawn point from here and assign to player. Dispatch("play", dataArr[1], false); } else if (dataArr[0] == "other_player_connected") { // receive other player connected means you need to spawn another player in that spot to represent them Dispatch("other_player_connected", dataArr[1], false); } else if (dataArr[0] == "move") { Dispatch("move", dataArr[1], false); } else if (dataArr[0] == "ackMessage") { Dispatch("ackMessage", dataArr[1], false); } else if (dataArr[0] == "collision") { print("Received collision message! Data: " + dataArr[1]); Dispatch("collision", dataArr[1], false); } else if (dataArr[0] == "collisionAck") { print("Received collisionAck message! Data: " + dataArr[1]); Dispatch("collisionAck", dataArr[1], false); } else if (dataArr[0] == "fire") { Dispatch("fire", dataArr[1], false); } else if (dataArr[0] == "projectile_damage") { Dispatch("projectile_damage", dataArr[1], false); } else if (dataArr[0] == "weapon") { Dispatch("weapon", dataArr[1], false); } else if (dataArr[0] == "health_damage") { print("Received message with data: 0 = " + dataArr[0]); print("Received message with data: 1 = " + dataArr[1]); Dispatch("health_damage", dataArr[1], false); } else if (dataArr[0] == "disconnect" || dataArr[0] == "disconnected") { print("Received message with data: 0 = " + dataArr[0]); print("Received message with data: 1 = " + dataArr[1]); Dispatch("disconnect", dataArr[1], false); } else if (dataArr[0] == "name_registration") { Dispatch("name_registration", dataArr[1], false); } else if (dataArr[0] == "killed") { Dispatch("killed", dataArr[1], false); } else { Dispatch("default", message, false); //We will dequeue message and send to Dispatch function. } } } yield return(null); // yield return new WaitForSeconds(5); if too slow } }