r2mods/ilspy_dump/ror2_csproj/RoR2.Items/SiphonOnLowHealthItemBodyBe...

44 lines
1.1 KiB
C#
Raw Normal View History

2024-10-04 07:26:37 +00:00
using UnityEngine;
namespace RoR2.Items;
public class SiphonOnLowHealthItemBodyBehavior : BaseItemBodyBehavior
{
private NetworkedBodyAttachment attachment;
private SiphonNearbyController siphonNearbyController;
[ItemDefAssociation(useOnServer = true, useOnClient = false)]
private static ItemDef GetItemDef()
{
return RoR2Content.Items.SiphonOnLowHealth;
}
private void OnEnable()
{
attachment = Object.Instantiate(LegacyResourcesAPI.Load<GameObject>("Prefabs/NetworkedObjects/BodyAttachments/SiphonNearbyBodyAttachment")).GetComponent<NetworkedBodyAttachment>();
attachment.AttachToGameObjectAndSpawn(base.body.gameObject);
siphonNearbyController = attachment.GetComponent<SiphonNearbyController>();
}
private void OnDisable()
{
DestroyAttachment();
}
private void FixedUpdate()
{
siphonNearbyController.NetworkmaxTargets = (base.body.healthComponent.alive ? stack : 0);
}
private void DestroyAttachment()
{
if ((bool)attachment)
{
Object.Destroy(attachment.gameObject);
}
attachment = null;
siphonNearbyController = null;
}
}