private bool RequiresUpdate(CharacterStateUpdate oldState, CharacterStateUpdate newState) { if (!lastSavedStateTime.TryGetValue(oldState.UserId, out var date) || DateTime.UtcNow - date > TimeSpan.FromSeconds(ForceSaveInterval)) { return(true); } if (oldState.Health != newState.Health) { return(true); } if (oldState.InArena != newState.InArena) { return(true); } if (oldState.InRaid != newState.InRaid) { return(true); } if (oldState.Island != newState.Island) { return(true); } if (oldState.Task != newState.Task) { return(true); } if (oldState.TaskArgument != newState.TaskArgument) { return(true); } return(oldState.DuelOpponent != newState.DuelOpponent); }
private bool RequiresUpdate(CharacterStateUpdate oldState, CharacterStateUpdate newState) { if (oldState.Health != newState.Health) { return(true); } if (oldState.InArena != newState.InArena) { return(true); } if (oldState.InRaid != newState.InRaid) { return(true); } if (oldState.Island != newState.Island) { return(true); } var op = oldState.Position; var np = newState.Position; if (op.X != np.X || op.Y != np.Y || op.Z != np.Z) { return(true); } if (oldState.Task != newState.Task) { return(true); } if (oldState.TaskArgument != newState.TaskArgument) { return(true); } return(oldState.DuelOpponent != newState.DuelOpponent); }
public async Task <bool> SavePlayerAsync(PlayerController player) { if (IntegrityCheck.IsCompromised) { return(false); } var characterUpdate = new CharacterStateUpdate( player.UserId, player.Stats.Health.CurrentValue, player.Island?.Identifier, player.Duel.Opponent?.UserId, player.Raid.InRaid, player.Arena.InArena, player.GetTask().ToString(), string.Join(",", player.GetTaskArguments()), new Position { X = player.transform.position.x, Y = player.transform.position.y, Z = player.transform.position.z }); if (lastSavedState.TryGetValue(player.UserId, out var lastUpdate)) { if (!RequiresUpdate(lastUpdate, characterUpdate)) { return(false); } } var response = await connection.SendAsync("update_character_state", characterUpdate); if (response != null && response.TryGetValue <bool>(out var result)) { if (result) { lastSavedState[player.UserId] = characterUpdate; return(true); } } return(false); }
public async Task <bool> SavePlayerStateAsync(PlayerController player) { if (client.Desynchronized) { return(false); } if (player == null || !player || string.IsNullOrEmpty(player.UserId)) { return(false); } var pos = player.transform.position; return(await Task.Run(() => { var characterUpdate = new CharacterStateUpdate( player.UserId, player.Id, player.Stats.Health.CurrentValue, player.Island?.Identifier ?? "", player.Duel.InDuel ? player.Duel.Opponent?.UserId ?? "" : "", player.Raid.InRaid, player.Arena.InArena, player.Dungeon.InDungeon, player.GetTask().ToString(), string.Join(",", player.GetTaskArguments()), pos.x, pos.y, pos.z); if (lastSavedState.TryGetValue(player.UserId, out var lastUpdate)) { if (!RequiresUpdate(lastUpdate, characterUpdate)) { return false; } } connection.SendNoAwait("update_character_state", characterUpdate); lastSavedState[player.UserId] = characterUpdate; lastSavedStateTime[player.UserId] = DateTime.UtcNow; return true; })); }
private bool RequiresUpdate(CharacterStateUpdate oldState, CharacterStateUpdate newState) { if (!lastSavedTime.TryGetValue(oldState.UserId, out var date) || DateTime.UtcNow - date > TimeSpan.FromSeconds(ForceSaveInterval)) { return(true); } if (oldState.Health != newState.Health) { return(true); } if (oldState.InArena != newState.InArena) { return(true); } if (oldState.InRaid != newState.InRaid) { return(true); } if (oldState.Island != newState.Island) { return(true); } #warning disabled update player state on position change //var op = oldState.Position; //var np = newState.Position; //if (op.X != np.X || op.Y != np.Y || op.Z != np.Z) return true; if (oldState.Task != newState.Task) { return(true); } if (oldState.TaskArgument != newState.TaskArgument) { return(true); } return(oldState.DuelOpponent != newState.DuelOpponent); }