Skip to content

Commit

Permalink
Sync weapons stored in EquipWeapon triggers.
Browse files Browse the repository at this point in the history
  • Loading branch information
iliadsh committed Nov 18, 2023
1 parent 8b4b13b commit 28923b3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions RavenM/IngameNetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using UnityEngine;
using Ravenfield.SpecOps;
using RavenM.Commands;
using Ravenfield.Mods.Data;

namespace RavenM
{
Expand Down Expand Up @@ -532,6 +533,8 @@ public class AudioContainer

public KeyCode PlaceMarkerKeybind = KeyCode.BackQuote;

public List<WeaponManager.WeaponEntry> MapWeapons = new List<WeaponManager.WeaponEntry>();

private void Awake()
{
instance = this;
Expand Down Expand Up @@ -821,6 +824,7 @@ public void ResetState()
OwnedProjectiles.Clear();
ClientProjectiles.Clear();
ClientDestructibles.Clear();
MapWeapons.Clear();

ClientCanSpawnBot = false;

Expand Down
14 changes: 14 additions & 0 deletions RavenM/LobbySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Ravenfield.Mutator.Configuration;
using SimpleJSON;
using System.Globalization;
using Ravenfield.Trigger;

namespace RavenM
{
Expand Down Expand Up @@ -169,6 +170,19 @@ static void Prefix()

Plugin.logger.LogInfo($"Registered new destructible root with name: {root.name} and id: {id}");
}

IngameNetManager.instance.MapWeapons.Clear();
foreach (var triggerEquipWeapon in Resources.FindObjectsOfTypeAll<TriggerEquipWeapon>())
{
if (triggerEquipWeapon.weaponType == TriggerEquipWeapon.WeaponType.FromWeaponEntry
&& triggerEquipWeapon.weaponEntry != null
&& !WeaponManager.instance.allWeapons.Contains(triggerEquipWeapon.weaponEntry))
{
var entry = triggerEquipWeapon.weaponEntry;
Plugin.logger.LogInfo($"Detected map weapon with name: {entry.name}, and from map: {map.metaData.displayName}.");
IngameNetManager.instance.MapWeapons.Add(entry);
}
}
}

static void Postfix()
Expand Down
4 changes: 4 additions & 0 deletions RavenM/NetActorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ public static WeaponManager.WeaponEntry GetWeaponEntryByHash(int hash)
foreach (var entry in WeaponManager.instance.allWeapons)
if (entry.name.GetHashCode() == hash)
return entry;

foreach (var entry in IngameNetManager.instance.MapWeapons)
if (entry.name.GetHashCode() == hash)
return entry;
return null;
}

Expand Down

0 comments on commit 28923b3

Please sign in to comment.