Skip to content

Commit

Permalink
Update to latest dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed Jul 20, 2024
2 parents 1a5c148 + 2d59d56 commit 6c9cb47
Show file tree
Hide file tree
Showing 45 changed files with 967 additions and 302 deletions.
Binary file modified Fika.Core/Bundles/Files/newmatchmakerui.bundle
Binary file not shown.
Binary file modified Fika.Core/Bundles/Files/playerui.bundle
Binary file not shown.
Binary file modified Fika.Core/Bundles/Files/senditemmenu.bundle
Binary file not shown.
2 changes: 1 addition & 1 deletion Fika.Core/Console/FikaCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static void DespawnAllAI()

CoopHandler.TryGetCoopHandler(out CoopHandler coopHandler);

List<IPlayer> Bots = new List<IPlayer>(game.BotsController.Players);
List<IPlayer> Bots = new(game.BotsController.Players);

foreach (Player bot in Bots)
{
Expand Down
1 change: 1 addition & 0 deletions Fika.Core/Coop/Airdrops/FikaAirdropsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ protected async void Start()
AirdropParameters.DropHeight, AirdropParameters.Config.PlaneVolume,
AirdropParameters.Config.PlaneSpeed);
AirdropBox = await AirdropBox.Init(AirdropParameters.Config.CrateFallSpeed);
AirdropBox.container.Id = "FikaAirdropContainer";
factory = new FikaItemFactoryUtil();
}
catch
Expand Down
38 changes: 38 additions & 0 deletions Fika.Core/Coop/ClientClasses/ClientMovementContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using EFT;
using System;
using UnityEngine;

namespace Fika.Core.Coop.ClientClasses
{
public class ClientMovementContext : MovementContext
{
private bool doGravity;

public new static ClientMovementContext Create(Player player, Func<IAnimator> animatorGetter, Func<ICharacterController> characterControllerGetter, LayerMask groundMask)
{
ClientMovementContext movementContext = Create<ClientMovementContext>(player, animatorGetter, characterControllerGetter, groundMask);
return movementContext;
}

public override void Init()
{
doGravity = true;
base.Init();
}

public override void ApplyGravity(ref Vector3 motion, float deltaTime, bool stickToGround)
{
if (!doGravity)
{
return;
}

base.ApplyGravity(ref motion, deltaTime, stickToGround);
}

public void SetGravity(bool enabled)
{
doGravity = enabled;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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.SendQuestItemPacket(ref packet);
CoopPlayer.PacketSender.SendQuestPacket(ref packet);
}
}
base.Execute(operation, callback);
Expand Down
79 changes: 74 additions & 5 deletions Fika.Core/Coop/ClientClasses/CoopClientSharedQuestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
using EFT.Quests;
using Fika.Core.Coop.Players;
using Fika.Core.Networking.Packets;
using SPT.Custom.BTR.Patches;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Fika.Core.Coop.ClientClasses
{
Expand All @@ -16,6 +16,7 @@ public sealed class CoopClientSharedQuestController(Profile profile, InventoryCo
private readonly List<string> lastFromNetwork = [];
private readonly HashSet<string> acceptedTypes = [];
private readonly HashSet<string> lootedTemplateIds = [];
private readonly HashSet<string> droppedZoneIds = [];
private bool canSendAndReceive = true;

public override void Init()
Expand Down Expand Up @@ -48,6 +49,32 @@ public override void Init()
}
}

/// <summary>
/// Used to prevent errors when subscribing to the event
/// </summary>
public void LateInit()
{
if (acceptedTypes.Contains("PlaceBeacon"))
{
player.Profile.OnItemZoneDropped += Profile_OnItemZoneDropped;
}
}

private void Profile_OnItemZoneDropped(string itemId, string zoneId)
{
if (droppedZoneIds.Contains(itemId))
{
return;
}

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

public override void OnConditionValueChanged(IConditionCounter conditional, EQuestStatus status, Condition condition, bool notify = true)
{
base.OnConditionValueChanged(conditional, status, condition, notify);
Expand Down Expand Up @@ -93,6 +120,11 @@ public void ToggleQuestSharing(bool state)

private void SendQuestPacket(IConditionCounter conditional, Condition condition)
{
if (!canSendAndReceive)
{
return;
}

if (conditional is QuestClass quest)
{
TaskConditionCounterClass counter = quest.ConditionCountersManager.GetCounter(condition.id);
Expand Down Expand Up @@ -135,8 +167,8 @@ internal void ReceiveQuestPacket(ref QuestConditionPacket packet)
counter.Value++;
if (FikaPlugin.QuestSharingNotifications.Value)
{
NotificationManagerClass.DisplayMessageNotification($"Received shared quest progression from {packet.Nickname}",
iconType: EFT.Communications.ENotificationIconType.Quest);
NotificationManagerClass.DisplayMessageNotification($"Received shared quest progression from <color=#32a852>{packet.Nickname}</color>",
iconType: EFT.Communications.ENotificationIconType.Quest);
}
}
}
Expand Down Expand Up @@ -166,14 +198,51 @@ internal void ReceiveQuestItemPacket(ref QuestItemPacket packet)
playerInventory.RunNetworkTransaction(pickupResult.Value);
if (FikaPlugin.QuestSharingNotifications.Value)
{
NotificationManagerClass.DisplayMessageNotification($"{packet.Nickname} picked up {item.Name.Localized()}",
iconType: EFT.Communications.ENotificationIconType.Quest);
NotificationManagerClass.DisplayMessageNotification($"<color=#32a852>{packet.Nickname}</color> picked up <color=#51c6db>{item.Name.Localized()}</color>",
iconType: EFT.Communications.ENotificationIconType.Quest);
}
}
}
}
}

internal void ReceiveQuestDropItemPacket(ref QuestDropItemPacket packet)
{
if (!canSendAndReceive)
{
return;
}

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

if (DroppedItemAlreadyExists(itemId, zoneId))
{
return;
}

if (FikaPlugin.QuestSharingNotifications.Value)
{
NotificationManagerClass.DisplayMessageNotification($"<color=#32a852>{packet.Nickname}</color> planted an item.",
iconType: EFT.Communications.ENotificationIconType.Quest);
}

droppedZoneIds.Add(zoneId);
player.Profile.ItemDroppedAtPlace(itemId, zoneId);
}

private bool DroppedItemAlreadyExists(string itemId, string zoneId)
{
if (player.Profile.EftStats.DroppedItems.Any(x => x.ItemId == itemId && x.ZoneId == zoneId) || droppedZoneIds.Contains(zoneId))
{
#if DEBUG
FikaPlugin.Instance.FikaLogger.LogWarning($"Quest already existed in 'DroppedItems', itemId: {itemId}, zoneId: {zoneId}");
#endif
return true;
}
return false;
}

/// <summary>
/// Validates quest typing, some quests use CounterCreator which we also need to validate.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Fika.Core/Coop/ClientClasses/NoInertiaMovementContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Fika.Core.Coop.ClientClasses
/// <summary>
/// Used to simulate having near no inertia
/// </summary>
public class NoInertiaMovementContext : MovementContext
public class NoInertiaMovementContext : ClientMovementContext
{
public new static NoInertiaMovementContext Create(Player player, Func<IAnimator> animatorGetter, Func<ICharacterController> characterControllerGetter, LayerMask groundMask)
{
Expand Down
1 change: 0 additions & 1 deletion Fika.Core/Coop/Components/CoopHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ private async Task ReadFromServerCharactersLoop()
if (Players == null)
{
continue;

}

ReadFromServerCharacters();
Expand Down
Loading

0 comments on commit 6c9cb47

Please sign in to comment.