Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
- Moved insurance handling to server
  • Loading branch information
Lacyway committed Jul 8, 2024
1 parent bd649d3 commit 60bb057
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 62 deletions.
5 changes: 0 additions & 5 deletions Fika.Core/Coop/Components/CoopHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -589,11 +589,6 @@ public void SetWeaponInHandsOfNewPlayer(Player player)
item = equipment.GetSlot(EquipmentSlot.Scabbard).ContainedItem;
}

if (item == null)
{
Logger.LogError($"SetWeaponInHandsOfNewPlayer: Unable to find any weapon for {player.Profile.Nickname}, {player.Profile.ProfileId}");
}

player.SetItemInHands(item, (IResult) =>
{
if (IResult.Failed == true)
Expand Down
70 changes: 38 additions & 32 deletions Fika.Core/Coop/GameMode/CoopGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ internal static CoopGame Create(IInputTree inputTree, Profile profile, GameDateT
}

coopGame.timeManager = CoopTimeManager.Create(coopGame);

coopGame.RaidSettings = raidSettings;

return coopGame;
Expand Down Expand Up @@ -894,8 +893,43 @@ public override async Task<LocalPlayer> vmethod_2(int playerId, Vector3 position
GameObject customButton = null;

await NetManagerUtils.SetupGameVariables(isServer, coopPlayer);
customButton = CreateCancelButton(myPlayer, coopPlayer, customButton);

SendCharacterPacket packet = new(new FikaSerialization.PlayerInfoPacket(myPlayer.Profile), myPlayer.HealthController.IsAlive, false, myPlayer.Transform.position, (myPlayer as CoopPlayer).NetId);

if (isServer)
{
await SetStatus(myPlayer, LobbyEntry.ELobbyStatus.COMPLETE);
}
else
{
FikaClient client = Singleton<FikaClient>.Instance;
do
{
await Task.Delay(250);
} while (client.NetClient.FirstPeer == null);

// This creates a "custom" Back button so that we can back out if we get stuck
client.SendData(new NetDataWriter(), ref packet, LiteNetLib.DeliveryMethod.ReliableUnordered);
}

await WaitForPlayers();

fikaDebug = gameObject.AddComponent<FikaDebug>();

Destroy(customButton);

return myPlayer;
}

/// <summary>
/// This creates a "custom" Back button so that we can back out if we get stuck
/// </summary>
/// <param name="myPlayer"></param>
/// <param name="coopPlayer"></param>
/// <param name="customButton"></param>
/// <returns></returns>
private GameObject CreateCancelButton(LocalPlayer myPlayer, CoopPlayer coopPlayer, GameObject customButton)
{
if (MenuUI.Instantiated)
{
MenuUI menuUI = MenuUI.Instance;
Expand All @@ -922,24 +956,7 @@ public override async Task<LocalPlayer> vmethod_2(int playerId, Vector3 position
Traverse.Create(backButtonComponent).Field("OnClick").SetValue(newEvent);
}

SendCharacterPacket packet = new(new FikaSerialization.PlayerInfoPacket(myPlayer.Profile), myPlayer.HealthController.IsAlive, false, myPlayer.Transform.position, (myPlayer as CoopPlayer).NetId);

if (isServer)
{
await SetStatus(myPlayer, LobbyEntry.ELobbyStatus.COMPLETE);
}
else
{
Singleton<FikaClient>.Instance.SendData(new NetDataWriter(), ref packet, LiteNetLib.DeliveryMethod.ReliableUnordered);
}

await WaitForPlayers();

fikaDebug = gameObject.AddComponent<FikaDebug>();

Destroy(customButton);

return myPlayer;
return customButton;
}

/// <summary>
Expand Down Expand Up @@ -1629,12 +1646,6 @@ public void Extract(CoopPlayer player, ExfiltrationPoint point)

extractRoutine = StartCoroutine(ExtractRoutine(player));

// Clear to make sure we don't interfere with SPT logic
if (coopPlayer.Profile.InsuredItems.Length > 0)
{
coopPlayer.Profile.InsuredItems = Array.Empty<InsuredItemClass>();
}

// Prevents players from looting after extracting
CurrentScreenSingleton.Instance.CloseAllScreensForced();

Expand Down Expand Up @@ -1814,12 +1825,7 @@ public override void Stop(string profileId, ExitStatus exitStatus, string exitNa
CoopPlayer[] players = [.. coopHandler.Players.Values];
foreach (CoopPlayer player in players)
{
if (player == null)
{
continue;
}

if (player.IsYourPlayer)
if (player == null || player.IsYourPlayer)
{
continue;
}
Expand Down
18 changes: 0 additions & 18 deletions Fika.Core/Coop/Players/CoopPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,6 @@ public static async Task<LocalPlayer> Create(int playerId, Vector3 position, Qua
questController.Init();
questController.Run();

// Used to communicate what insurance each profile has between clients
if (profile.Side is not EPlayerSide.Savage)
{
if (session.InsuranceCompany?.InsuredItems?.Count > 0)
{
List<InsuredItemClass> itemsToInsure = [];
foreach (ItemClass item in session.InsuranceCompany.InsuredItems)
{
itemsToInsure.Add(new()
{
itemId = item.Id,
tid = item.TemplateId
});
}
profile.InsuredItems = [.. itemsToInsure];
}
}

GClass3233 achievementsController = new(profile, inventoryController, session, true);
achievementsController.Init();
achievementsController.Run();
Expand Down
2 changes: 1 addition & 1 deletion Fika.Core/Coop/Players/ObservedCoopPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ public override void OnPhraseTold(EPhraseTrigger @event, TaggedClip clip, TagBan

public PlayerStatePacket Interpolate(in PlayerStatePacket newState, in PlayerStatePacket lastState)
{
float interpolate = Time.fixedDeltaTime;
float interpolate = 0.3f;

method_58(newState.HasGround, newState.SurfaceSound);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ static FikaRequestHandler()

private static byte[] EncodeBody<T>(T o)
{
var serialized = JsonConvert.SerializeObject(o);
string serialized = JsonConvert.SerializeObject(o);
return Encoding.UTF8.GetBytes(serialized);
}

private static T DecodeBody<T>(byte[] data)
{
var json = Encoding.UTF8.GetString(data);
string json = Encoding.UTF8.GetString(data);
return JsonConvert.DeserializeObject<T>(json);
}

private static async Task<T> GetJsonAsync<T>(string path)
{
var response = await _httpClient.GetAsync(path);
byte[] response = await _httpClient.GetAsync(path);
return DecodeBody<T>(response);
}

Expand All @@ -46,8 +46,8 @@ private static T GetJson<T>(string path)

private static async Task<T2> PostJsonAsync<T1, T2>(string path, T1 o)
{
var data = EncodeBody<T1>(o);
var response = await _httpClient.PostAsync(path, data);
byte[] data = EncodeBody<T1>(o);
byte[] response = await _httpClient.PostAsync(path, data);
return DecodeBody<T2>(response);
}

Expand All @@ -58,7 +58,7 @@ private static T2 PostJson<T1, T2>(string path, T1 o)

private static async Task<byte[]> PutJsonAsync<T>(string path, T o)
{
var data = EncodeBody(o);
byte[] data = EncodeBody(o);
return await _httpClient.PutAsync(path, data);
}

Expand Down

0 comments on commit 60bb057

Please sign in to comment.