Skip to content

Commit

Permalink
Merge pull request #122 from project-fika/dev
Browse files Browse the repository at this point in the history
Dev > main
  • Loading branch information
Lacyway authored Aug 2, 2024
2 parents 3e5a1e9 + dcfcb39 commit 93efecb
Show file tree
Hide file tree
Showing 39 changed files with 394 additions and 213 deletions.
20 changes: 19 additions & 1 deletion Fika.Core/Console/FikaCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static void Extract()
coopGame.Extract(localPlayer, null);
}

[ConsoleCommand("despawnallai", "", null, "Despawns all AI Bots", [])]
[ConsoleCommand("despawnallai", "", null, "Despawns all AI bots", [])]
public static void DespawnAllAI()
{
if (Singleton<IFikaGame>.Instance is CoopGame game)
Expand Down Expand Up @@ -144,6 +144,24 @@ public static void DespawnAllAI()
}
}

[ConsoleCommand("stoptimer", "", null, "Stops the game timer", [])]
public static void StopTimer()
{
if (Singleton<IFikaGame>.Instance is CoopGame game)
{
if (game.GameTimer.Status == GameTimerClass.EGameTimerStatus.Stopped)
{
ConsoleScreen.LogError("GameTimer is already stopped at: " + game.GameTimer.PastTime.ToString());
return;
}
game.GameTimer.TryStop();
if (game.GameTimer.Status == GameTimerClass.EGameTimerStatus.Stopped)
{
ConsoleScreen.Log("GameTimer stopped at: " + game.GameTimer.PastTime.ToString());
}
}
}

#endif

[ConsoleCommand("debug", "", null, "Toggle debug window", [])]
Expand Down
6 changes: 6 additions & 0 deletions Fika.Core/Coop/ClientClasses/CoopClientGameWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,11 @@ public override GClass676 CreateGrenadeFactory()
{
return new GClass677();
}

public override void Start()
{
base.Start();
RegisterBorderZones();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override void Execute(GClass2854 operation, [CanBeNull] Callback callback

// We use templateId because each client gets a unique itemId
QuestItemPacket packet = new(CoopPlayer.Profile.Info.MainProfileNickname, lootedItem.TemplateId);
CoopPlayer.PacketSender.SendQuestPacket(ref packet);
CoopPlayer.PacketSender.SendPacket(ref packet);
}
}
base.Execute(operation, callback);
Expand Down
14 changes: 11 additions & 3 deletions Fika.Core/Coop/ClientClasses/CoopClientSharedQuestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public sealed class CoopClientSharedQuestController(Profile profile, InventoryCo
private readonly HashSet<string> acceptedTypes = [];
private readonly HashSet<string> lootedTemplateIds = [];
private bool canSendAndReceive = true;
private bool isItemBeingDropped = false;

public override void Init()
{
Expand Down Expand Up @@ -66,11 +67,16 @@ public void LateInit()

private void Profile_OnItemZoneDropped(string itemId, string zoneId)
{
if (isItemBeingDropped)
{
return;
}

QuestDropItemPacket packet = new(player.Profile.Info.MainProfileNickname, itemId, zoneId);
#if DEBUG
FikaPlugin.Instance.FikaLogger.LogInfo("Profile_OnItemZoneDropped: Sending quest progress");
FikaPlugin.Instance.FikaLogger.LogInfo($"Profile_OnItemZoneDropped: Sending quest progress itemId:{itemId} zoneId:{zoneId}");
#endif
player.PacketSender.SendQuestPacket(ref packet);
player.PacketSender.SendPacket(ref packet);
}

public override void OnConditionValueChanged(IConditionCounter conditional, EQuestStatus status, Condition condition, bool notify = true)
Expand Down Expand Up @@ -141,7 +147,7 @@ private void SendQuestPacket(IConditionCounter conditional, Condition condition)
#if DEBUG
FikaPlugin.Instance.FikaLogger.LogInfo("SendQuestPacket: Sending quest progress");
#endif
player.PacketSender.SendQuestPacket(ref packet);
player.PacketSender.SendPacket(ref packet);
}
}
}
Expand Down Expand Up @@ -221,6 +227,7 @@ internal void ReceiveQuestDropItemPacket(ref QuestDropItemPacket packet)
return;
}

isItemBeingDropped = true;
string itemId = packet.ItemId;
string zoneId = packet.ZoneId;

Expand All @@ -242,6 +249,7 @@ internal void ReceiveQuestDropItemPacket(ref QuestDropItemPacket packet)
player.InventoryControllerClass.TryRunNetworkTransaction(removeResult);
}
player.Profile.ItemDroppedAtPlace(itemId, zoneId);
isItemBeingDropped = false;
}

private bool HasQuestForItem(string itemId, string zoneId, out string questName)
Expand Down
6 changes: 3 additions & 3 deletions Fika.Core/Coop/Components/CoopHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ private void ReadFromServerCharacters()
requestPacket.Characters = [.. Players.Values.Select(p => p.ProfileId), .. queuedProfileIds];
}

NetDataWriter writer = Singleton<FikaClient>.Instance.DataWriter;
NetDataWriter writer = Singleton<FikaClient>.Instance.Writer;
if (writer != null)
{
writer.Reset();
Expand Down Expand Up @@ -311,7 +311,7 @@ private async void SpawnPlayer(SpawnObject spawnObject)
}
}

int playerId = Players.Count + Singleton<GameWorld>.Instance.RegisteredPlayers.Count + 1;
int playerId = LocalGameInstance.method_12();

IEnumerable<ResourceKey> allPrefabPaths = spawnObject.Profile.GetAllPrefabPaths();
if (allPrefabPaths.Count() == 0)
Expand Down Expand Up @@ -408,7 +408,7 @@ private ObservedCoopPlayer SpawnObservedPlayer(Profile profile, Vector3 position
{
bool isDedicatedProfile = !isAI && profile.Info.MainProfileNickname.Contains("dedicated_");

ObservedCoopPlayer otherPlayer = ObservedCoopPlayer.CreateObservedPlayer(playerId, position,
ObservedCoopPlayer otherPlayer = ObservedCoopPlayer.CreateObservedPlayer(netId, position,
Quaternion.identity, "Player", isAI == true ? "Bot_" : $"Player_{profile.Nickname}_",
EPointOfView.ThirdPerson, profile, isAI, EUpdateQueue.Update, Player.EUpdateMode.Manual,
Player.EUpdateMode.Auto, BackendConfigAbstractClass.Config.CharacterController.ObservedPlayerMode,
Expand Down
28 changes: 28 additions & 0 deletions Fika.Core/Coop/Factories/PingFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Comfort.Common;
using EFT;
using EFT.Communications;
using EFT.UI;
using Fika.Core.Bundles;
using Fika.Core.Coop.Players;
Expand All @@ -23,6 +24,33 @@ public enum EPingType : byte
Interactable
}

public static void ReceivePing(Vector3 location, EPingType pingType, Color pingColor, string nickname, string localeId)
{
GameObject prefab = AbstractPing.pingBundle.LoadAsset<GameObject>("BasePingPrefab");
GameObject pingGameObject = UnityEngine.Object.Instantiate(prefab);
AbstractPing abstractPing = FromPingType(pingType, pingGameObject);
if (abstractPing != null)
{
abstractPing.Initialize(ref location, null, pingColor);
Singleton<GUISounds>.Instance.PlayUISound(GetPingSound());
if (string.IsNullOrEmpty(localeId))
{
NotificationManagerClass.DisplayMessageNotification($"Received a ping from {ColorUtils.ColorizeText(Colors.GREEN, nickname)}",
ENotificationDurationType.Default, ENotificationIconType.Friend);
}
else
{
string localizedName = localeId.Localized();
NotificationManagerClass.DisplayMessageNotification($"{ColorUtils.ColorizeText(Colors.GREEN, nickname)} has pinged {LocaleUtils.GetPrefix(localizedName)} {ColorUtils.ColorizeText(Colors.BLUE, localizedName)}",
ENotificationDurationType.Default, ENotificationIconType.Friend);
}
}
else
{
FikaPlugin.Instance.FikaLogger.LogError($"Received {pingType} from {nickname} but factory failed to handle it");
}
}

public static EUISoundType GetPingSound()
{
return FikaPlugin.PingSound.Value switch
Expand Down
16 changes: 15 additions & 1 deletion Fika.Core/Coop/FreeCamera/FreeCameraController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,18 @@ public class FreeCameraController : MonoBehaviour
private CoopHandler coopHandler;

public GameObject CameraParent;
public Camera CameraFreeCamera { get; private set; }
public Camera CameraMain { get; private set; }
public bool IsScriptActive
{
get
{
if (freeCamScript != null)
{
return freeCamScript.IsActive;
}
return false;
}
}

private TextMeshProUGUI extractText = null;
private bool extracted = false;
Expand Down Expand Up @@ -496,6 +506,10 @@ private Player GetLocalPlayerFromWorld()

public void OnDestroy()
{
if (!Singleton<FreeCameraController>.TryRelease(this))
{
FikaPlugin.Instance.FikaLogger.LogWarning("Unable to release FreeCameraController singleton");
}
Destroy(CameraParent);

// Destroy FreeCamScript before FreeCamController if exists
Expand Down
73 changes: 15 additions & 58 deletions Fika.Core/Coop/GameMode/CoopGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,9 @@ private async Task<LocalPlayer> CreateBot(Profile profile, Vector3 position)
return null;
}

while (!this.Status.IsRunned())
while (!Status.IsRunned())
{
if (this.Status == GameStatus.Stopped)
if (Status == GameStatus.Stopped)
{
return null;
}
Expand Down Expand Up @@ -466,7 +466,7 @@ private async Task<LocalPlayer> CreateBot(Profile profile, Vector3 position)
}
else
{
int num = method_12();
//int num = method_12();
profile.SetSpawnedInSession(profile.Info.Side == EPlayerSide.Savage);

FikaServer server = Singleton<FikaServer>.Instance;
Expand All @@ -480,7 +480,7 @@ private async Task<LocalPlayer> CreateBot(Profile profile, Vector3 position)
await WaitForPlayersToLoadBotProfile(netId);
}

localPlayer = await CoopBot.CreateBot(num, position, Quaternion.identity, "Player",
localPlayer = await CoopBot.CreateBot(netId, position, Quaternion.identity, "Player",
"Bot_", EPointOfView.ThirdPerson, profile, true, UpdateQueue, Player.EUpdateMode.Auto,
Player.EUpdateMode.Auto, BackendConfigAbstractClass.Config.CharacterController.BotPlayerMode, new Func<float>(LocalGame.Class1394.class1394_0.method_4),
new Func<float>(LocalGame.Class1394.class1394_0.method_5), GClass1457.Default);
Expand Down Expand Up @@ -1064,7 +1064,7 @@ public void FinishLoading()
/// <returns>A <see cref="Player"/></returns>
private async Task<Player> CreateLocalPlayer()
{
int num = method_12();
int num = 0;

Player.EUpdateMode eupdateMode = Player.EUpdateMode.Auto;
if (BackendConfigAbstractClass.Config.UseHandsFastAnimator)
Expand Down Expand Up @@ -1402,13 +1402,14 @@ public override IEnumerator vmethod_4(BotControllerSettings controllerSettings,
}

// Add FreeCamController to GameWorld GameObject
Singleton<GameWorld>.Instance.gameObject.GetOrAddComponent<FreeCameraController>();
FreeCameraController freeCamController = Singleton<GameWorld>.Instance.gameObject.GetOrAddComponent<FreeCameraController>();
Singleton<FreeCameraController>.Create(freeCamController);
Singleton<GameWorld>.Instance.gameObject.GetOrAddComponent<FikaAirdropsManager>();
FikaAirdropsManager.ContainerCount = 0;

SetupBorderzones();
SetupRaidCode();

// Need to move to separate classes later
if (Singleton<GameWorld>.Instance.MineManager != null)
{
Singleton<GameWorld>.Instance.MineManager.OnExplosion += OnMineExplode;
Expand Down Expand Up @@ -1461,52 +1462,7 @@ private void DynamicAI_SettingChanged(object sender, EventArgs e)
{
DynamicAI.EnabledChange(FikaPlugin.DynamicAI.Value);
}
}

/// <summary>
/// Sets up all the <see cref="BorderZone"/>s on the map
/// </summary>
private void SetupBorderzones()
{
GameWorld gameWorld = Singleton<GameWorld>.Instance;
gameWorld.BorderZones = LocationScene.GetAllObjects<BorderZone>(false).ToArray();
for (int i = 0; i < gameWorld.BorderZones.Length; i++)
{
gameWorld.BorderZones[i].Id = i;
}

if (isServer)
{
foreach (BorderZone borderZone in gameWorld.BorderZones)
{
borderZone.PlayerShotEvent += OnBorderZoneShot;
}
}
else
{
foreach (BorderZone borderZone in gameWorld.BorderZones)
{
borderZone.RemoveAuthority();
}
}
}

/// <summary>
/// Triggered when a <see cref="BorderZone"/> triggers (only runs on host)
/// </summary>
/// <param name="player"></param>
/// <param name="zone"></param>
/// <param name="arg3"></param>
/// <param name="arg4"></param>
private void OnBorderZoneShot(IPlayerOwner player, BorderZone zone, float arg3, bool arg4)
{
BorderZonePacket packet = new()
{
ProfileId = player.iPlayer.ProfileId,
ZoneId = zone.Id
};
Singleton<FikaServer>.Instance.SendDataToAll(new NetDataWriter(), ref packet, LiteNetLib.DeliveryMethod.ReliableOrdered);
}
}

/// <summary>
/// Triggers when a <see cref="MineDirectional"/> explodes
Expand Down Expand Up @@ -1802,7 +1758,7 @@ public void ClearHostAI(Player player)
/// Triggers when the main player dies
/// </summary>
/// <param name="damageType"></param>
private void HealthController_DiedEvent(EDamageType damageType)
private async void HealthController_DiedEvent(EDamageType damageType)
{
Player player = gparam_0.Player;
if (player.AbstractQuestControllerClass is CoopClientSharedQuestController sharedQuestController)
Expand All @@ -1827,7 +1783,7 @@ private void HealthController_DiedEvent(EDamageType damageType)

if (FikaPlugin.Instance.ForceSaveOnDeath)
{
Task.Run(() => SavePlayer((CoopPlayer)player, MyExitStatus, string.Empty, true));
await SavePlayer((CoopPlayer)player, MyExitStatus, string.Empty, true);
}
}

Expand Down Expand Up @@ -2175,6 +2131,7 @@ public override void Dispose()

FikaBackendUtils.Nodes = null;
FikaBackendUtils.HostExpectedNumberOfPlayers = 1;
FikaBackendUtils.RequestFikaWorld = false;

if (CoopHandler.TryGetCoopHandler(out CoopHandler coopHandler))
{
Expand All @@ -2190,7 +2147,7 @@ public override void Dispose()
if (Singleton<FikaAirdropsManager>.Instance != null)
{
Destroy(Singleton<FikaAirdropsManager>.Instance);
}
}

base.Dispose();
}
Expand Down Expand Up @@ -2231,11 +2188,11 @@ public void HandleExit()
staticManager.WaitSeconds(num, EndAction);
}

private void FireCallback()
private async void FireCallback()
{
Callback<ExitStatus, TimeSpan, MetricsClass> endCallback = Traverse.Create(localGame).Field<Callback<ExitStatus, TimeSpan, MetricsClass>>("callback_0").Value;

Task.Run(() => localGame.SavePlayer(localPlayer, exitStatus, exitName, false));
await localGame.SavePlayer(localPlayer, exitStatus, exitName, false);

endCallback(new Result<ExitStatus, TimeSpan, MetricsClass>(exitStatus, EFTDateTimeClass.Now - localGame.dateTime_0, new MetricsClass()));
UIEventSystem.Instance.Enable();
Expand Down
Loading

0 comments on commit 93efecb

Please sign in to comment.