r2mods/ilspy_dump/ror2_csproj/RoR2.Items/CrippleWardOnLevelManager.cs

43 lines
1.1 KiB
C#
Raw Normal View History

2024-10-04 07:26:37 +00:00
using System;
using UnityEngine;
using UnityEngine.Networking;
namespace RoR2.Items;
public static class CrippleWardOnLevelManager
{
private static GameObject wardPrefab;
[SystemInitializer(new Type[] { typeof(ItemCatalog) })]
private static void Init()
{
Run.onRunAmbientLevelUp += onRunAmbientLevelUp;
LegacyResourcesAPI.LoadAsyncCallback("Prefabs/NetworkedObjects/CrippleWard", delegate(GameObject operationResult)
{
wardPrefab = operationResult;
});
}
private static void onRunAmbientLevelUp(Run run)
{
if (!NetworkServer.active)
{
return;
}
foreach (CharacterMaster readOnlyInstances in CharacterMaster.readOnlyInstancesList)
{
int itemCount = readOnlyInstances.inventory.GetItemCount(RoR2Content.Items.CrippleWardOnLevel);
if (itemCount > 0)
{
CharacterBody body = readOnlyInstances.GetBody();
if ((bool)body)
{
GameObject gameObject = UnityEngine.Object.Instantiate(wardPrefab, body.transform.position, Quaternion.identity);
gameObject.GetComponent<BuffWard>().Networkradius = 8f + 8f * (float)itemCount;
NetworkServer.Spawn(gameObject);
}
}
}
}
}