Skip to content

Commit

Permalink
Merge pull request #104 from stayintarkov/Minor-General-Fixes-2
Browse files Browse the repository at this point in the history
Minor general fixes 2
  • Loading branch information
dounai2333 authored Dec 16, 2023
2 parents 1f0a322 + d346e5f commit fc3e2f4
Show file tree
Hide file tree
Showing 18 changed files with 481 additions and 413 deletions.
Binary file modified References/Assembly-CSharp.dll
Binary file not shown.
4 changes: 2 additions & 2 deletions Source/Coop/Components/ActionPacketHandlerComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ namespace StayInTarkov.Coop.Components
{
public class ActionPacketHandlerComponent : MonoBehaviour
{
public BlockingCollection<Dictionary<string, object>> ActionPackets { get; } = new(9999);
public readonly BlockingCollection<Dictionary<string, object>> ActionPackets = new(9999);
public BlockingCollection<Dictionary<string, object>> ActionPacketsMovement { get; private set; } = new(9999);
public BlockingCollection<Dictionary<string, object>> ActionPacketsDamage { get; private set; } = new(9999);
public ConcurrentDictionary<string, EFT.Player> Players => CoopGameComponent.Players;
public ConcurrentDictionary<string, CoopPlayer> Players => CoopGameComponent.Players;
public ManualLogSource Logger { get; private set; }

private List<string> RemovedFromAIPlayers = new();
Expand Down
165 changes: 87 additions & 78 deletions Source/Coop/Components/CoopGameComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
using EFT.Interactive;
using EFT.InventoryLogic;
using EFT.UI;
using Newtonsoft.Json.Linq;
using StayInTarkov.Configuration;
using StayInTarkov.Coop.Components;
using StayInTarkov.Coop.Matchmaker;
using StayInTarkov.Coop.NetworkPacket;
using StayInTarkov.Coop.Player;
using StayInTarkov.Coop.Web;
using StayInTarkov.Core.Player;
Expand Down Expand Up @@ -44,7 +46,7 @@ public class CoopGameComponent : MonoBehaviour
/// <summary>
/// ProfileId to Player instance
/// </summary>
public ConcurrentDictionary<string, EFT.Player> Players { get; } = new();
public ConcurrentDictionary<string, CoopPlayer> Players { get; } = new();

//public EFT.Player[] PlayerUsers
public IEnumerable<EFT.Player> PlayerUsers
Expand Down Expand Up @@ -177,7 +179,7 @@ async void Start()
OwnPlayer = (LocalPlayer)Singleton<GameWorld>.Instance.MainPlayer;

// Add own Player to Players list
Players.TryAdd(OwnPlayer.ProfileId, OwnPlayer);
Players.TryAdd(OwnPlayer.ProfileId, (CoopPlayer)OwnPlayer);

// Instantiate the Requesting Object for Aki Communication
RequestingObj = AkiBackendCommunication.GetRequestInstance(false, Logger);
Expand Down Expand Up @@ -469,7 +471,9 @@ public EQuitState GetQuitState()
quitState = EQuitState.YouHaveExtractedOnlyAsHost;
}

if (numberOfPlayersAlive == numberOfPlayersExtracted || PlayerUsers.Count() == numberOfPlayersExtracted)
// If there are any players alive. Number of players Alive Equals Numbers of players Extracted
// OR Number of Players Equals Number of players Extracted
if ((numberOfPlayersAlive > 0 && numberOfPlayersAlive == numberOfPlayersExtracted) || PlayerUsers.Count() == numberOfPlayersExtracted)
{
quitState = EQuitState.YourTeamHasExtracted;
}
Expand Down Expand Up @@ -562,9 +566,12 @@ void Update()
if (RequestingObj == null)
return;

List<Dictionary<string, object>> playerStates = new();
JObject playerStates = new();
playerStates.Add(AkiBackendCommunication.PACKET_TAG_METHOD, "PlayerStates");
playerStates.Add(AkiBackendCommunication.PACKET_TAG_SERVERID, GetServerId());
if (LastPlayerStateSent < DateTime.Now.AddMilliseconds(-PluginConfigSettings.Instance.CoopSettings.SETTING_PlayerStateTickRateInMS))
{
JArray playerStateArray = new JArray();
foreach (var player in Players.Values)
{
if (player == null)
Expand All @@ -582,12 +589,12 @@ void Update()
if (!player.isActiveAndEnabled)
continue;

CreatePlayerStatePacketFromPRC(ref playerStates, player, prc);
CreatePlayerStatePacketFromPRC(ref playerStateArray, player, prc);
}


playerStates.Add("dataList", playerStateArray);
//Logger.LogDebug(playerStates.SITToJson());
RequestingObj.SendListDataToPool(string.Empty, playerStates);
RequestingObj.SendDataToPool(playerStates.SITToJson());

LastPlayerStateSent = DateTime.Now;
}
Expand Down Expand Up @@ -1026,7 +1033,7 @@ private LocalPlayer CreateLocalPlayer(Profile profile, Vector3 position, int pla
// ----------------------------------------------------------------------------------------------------
// Add the player to the custom Players list
if (!Players.ContainsKey(profile.ProfileId))
Players.TryAdd(profile.ProfileId, otherPlayer);
Players.TryAdd(profile.ProfileId, (CoopPlayer)otherPlayer);

if (!Singleton<GameWorld>.Instance.RegisteredPlayers.Any(x => x.Profile.ProfileId == profile.ProfileId))
Singleton<GameWorld>.Instance.RegisteredPlayers.Add(otherPlayer);
Expand Down Expand Up @@ -1154,69 +1161,9 @@ public void SetWeaponInHandsOfNewPlayer(EFT.Player person, Action successCallbac
});
}

private void CreatePlayerStatePacketFromPRC(ref List<Dictionary<string, object>> playerStates, EFT.Player player, PlayerReplicatedComponent prc)
private void CreatePlayerStatePacketFromPRC(ref JArray playerStates, EFT.Player player, PlayerReplicatedComponent prc)
{
Dictionary<string, object> dictPlayerState = new();

// --- The important Ids
dictPlayerState.Add("profileId", player.ProfileId);
dictPlayerState.Add("serverId", GetServerId());

// --- Positional
dictPlayerState.Add("pX", player.Position.x);
dictPlayerState.Add("pY", player.Position.y);
dictPlayerState.Add("pZ", player.Position.z);
dictPlayerState.Add("rX", player.Rotation.x);
dictPlayerState.Add("rY", player.Rotation.y);

// --- Positional
dictPlayerState.Add("pose", player.MovementContext.PoseLevel);
//dictPlayerState.Add("spd", player.MovementContext.CharacterMovementSpeed);
dictPlayerState.Add("spr", player.Physical.Sprinting);
//if (player.MovementContext.IsSprintEnabled)
//{
// prc.ReplicatedDirection = new Vector2(1, 0);
//}
//dictPlayerState.Add("tp", prc.TriggerPressed);
dictPlayerState.Add("alive", player.HealthController.IsAlive);
dictPlayerState.Add("tilt", player.MovementContext.Tilt);
dictPlayerState.Add("prn", player.MovementContext.IsInPronePose);

dictPlayerState.Add("t", DateTime.Now.Ticks.ToString("G"));
// ----------
//dictPlayerState.Add("p.hs.c", player.Physical.HandsStamina.Current);
//dictPlayerState.Add("p.hs.t", player.Physical.HandsStamina.TotalCapacity.Value);
//dictPlayerState.Add("p.s.c", player.Physical.Stamina.Current);
//dictPlayerState.Add("p.s.t", player.Physical.Stamina.TotalCapacity.Value);
//
if (prc.ReplicatedDirection.HasValue)
{
dictPlayerState.Add("dX", prc.ReplicatedDirection.Value.x);
dictPlayerState.Add("dY", prc.ReplicatedDirection.Value.y);
}

// ----------
/*
if (player.PlayerHealthController != null)
{
foreach (var b in Enum.GetValues(typeof(EBodyPart)))
{
var effects = player.PlayerHealthController
.GetAllActiveEffects((EBodyPart)b).Where(x => !x.ToString().Contains("Exist"))
.Select(x => x.ToString());
if (!effects.Any())
continue;
var k = "hE." + b.ToString();
//Logger.LogInfo(k);
//Logger.LogInfo(effects.ToJson());
dictPlayerState.Add(k, effects.ToJson());
}
}
*/
// ----------
Dictionary<string, object> playerHCSync = new();
if (player.HealthController.IsAlive)
{
foreach (EBodyPart bodyPart in Enum.GetValues(typeof(EBodyPart)))
Expand All @@ -1225,17 +1172,79 @@ private void CreatePlayerStatePacketFromPRC(ref List<Dictionary<string, object>>
continue;

var health = player.HealthController.GetBodyPartHealth(bodyPart);
dictPlayerState.Add($"hp.{bodyPart}", health.Current);
dictPlayerState.Add($"hp.{bodyPart}.m", health.Maximum);
playerHCSync.Add($"{bodyPart}c", health.Current);
playerHCSync.Add($"{bodyPart}m", health.Maximum);
}

dictPlayerState.Add("en", player.HealthController.Energy.Current);
dictPlayerState.Add("hy", player.HealthController.Hydration.Current);
}
// ----------
dictPlayerState.Add("m", "PlayerState");

playerStates.Add(dictPlayerState);
PlayerStatePacket playerStatePacket = new PlayerStatePacket(
player.ProfileId
, player.Position
, player.Rotation
, player.HeadRotation
, player.MovementContext.MovementDirection
, player.MovementContext.CurrentState.Name
, player.MovementContext.Tilt
, player.MovementContext.Step
, player.MovementContext.CurrentAnimatorStateIndex
, player.MovementContext.CharacterMovementSpeed
, player.MovementContext.IsInPronePose
, player.MovementContext.PoseLevel
, player.MovementContext.IsSprintEnabled
, player.InputDirection
, player.ActiveHealthController != null ? player.ActiveHealthController.Energy.Current : 0
, player.ActiveHealthController != null ? player.ActiveHealthController.Hydration.Current : 0
, playerHCSync.SITToJson()
);;
;
playerHCSync = null;
playerStates.Add(playerStatePacket.Serialize());

//Dictionary<string, object> dictPlayerState = new();

//// --- The important Ids
//dictPlayerState.Add("profileId", player.ProfileId);
//dictPlayerState.Add("serverId", GetServerId());

//// --- Positional
//dictPlayerState.Add("pX", player.Position.x);
//dictPlayerState.Add("pY", player.Position.y);
//dictPlayerState.Add("pZ", player.Position.z);
//dictPlayerState.Add("rX", player.Rotation.x);
//dictPlayerState.Add("rY", player.Rotation.y);

//// --- Positional
//dictPlayerState.Add("pose", player.MovementContext.PoseLevel);
//dictPlayerState.Add("spr", player.Physical.Sprinting);
//dictPlayerState.Add("alive", player.HealthController.IsAlive);
//dictPlayerState.Add("tilt", player.MovementContext.Tilt);
//dictPlayerState.Add("prn", player.MovementContext.IsInPronePose);

//// ----------
////
//dictPlayerState.Add("dX", player.InputDirection.x);
//dictPlayerState.Add("dY", player.InputDirection.y);

//// ----------
//if (player.HealthController.IsAlive)
//{
// foreach (EBodyPart bodyPart in Enum.GetValues(typeof(EBodyPart)))
// {
// if (bodyPart == EBodyPart.Common)
// continue;

// var health = player.HealthController.GetBodyPartHealth(bodyPart);
// dictPlayerState.Add($"hp.{bodyPart}", health.Current);
// dictPlayerState.Add($"hp.{bodyPart}.m", health.Maximum);
// }

// dictPlayerState.Add("en", player.HealthController.Energy.Current);
// dictPlayerState.Add("hy", player.HealthController.Hydration.Current);
//}
//// ----------
//dictPlayerState.Add("m", "PlayerState");

//playerStates.Add(dictPlayerState);
}

private DateTime LastPlayerStateSent { get; set; } = DateTime.Now;
Expand Down
Loading

0 comments on commit fc3e2f4

Please sign in to comment.