164 lines
8.7 KiB
C#
164 lines
8.7 KiB
C#
using Audio;
|
|
using Platform;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Harmony.ItemActionUseOtherPatches
|
|
{
|
|
[HarmonyPatch(typeof(ItemActionUseOther))]
|
|
[HarmonyPatch("ExecuteAction")]
|
|
public class ExecuteActionPatch
|
|
{
|
|
public static bool Prefix(ItemActionUseOther __instance, ItemActionData _actionData, bool _bReleased,
|
|
float ___Delay,
|
|
FastTags<TagGroup.Global> ___medicalItemTag,
|
|
FastTags<TagGroup.Global> ___stopBleed,
|
|
FastTags<TagGroup.Global> ___noMedBuffsTag,
|
|
string ___soundStart,
|
|
string ___CreateItem,
|
|
int ___CreateItemCount,
|
|
ref List<string> ___BuffActions,
|
|
float ___SphereRadius
|
|
)
|
|
{
|
|
if (!_bReleased)
|
|
{
|
|
return false;
|
|
}
|
|
if (Time.time - _actionData.lastUseTime < ___Delay)
|
|
{
|
|
return false;
|
|
}
|
|
ItemActionUseOther.FeedInventoryData feedInventoryData = (ItemActionUseOther.FeedInventoryData)_actionData;
|
|
EntityAlive holdingEntity = feedInventoryData.invData.holdingEntity;
|
|
if (EffectManager.GetValue(PassiveEffects.DisableItem, holdingEntity.inventory.holdingItemItemValue, 0f, holdingEntity, null, _actionData.invData.item.ItemTags, true, true, true, true, true, 1, false) > 0f)
|
|
{
|
|
_actionData.lastUseTime = Time.time + 1f;
|
|
Manager.PlayInsidePlayerHead("twitch_no_attack", -1, 0f, false);
|
|
return false;
|
|
}
|
|
_actionData.lastUseTime = Time.time;
|
|
feedInventoryData.bFeedingStarted = true;
|
|
float distance = 4f;
|
|
feedInventoryData.ray = holdingEntity.GetLookRay();
|
|
int modelLayer = holdingEntity.GetModelLayer();
|
|
holdingEntity.SetModelLayer(2, false, null);
|
|
EntityAlive entityAlive = null;
|
|
if (Voxel.Raycast(feedInventoryData.invData.world, feedInventoryData.ray, distance, -538750981, 128, ___SphereRadius))
|
|
{
|
|
entityAlive = (ItemActionUseOther.GetEntityFromHit(Voxel.voxelRayHitInfo) as EntityAlive);
|
|
}
|
|
if (entityAlive == null || !entityAlive.IsAlive() || !(entityAlive is EntityPlayer))
|
|
{
|
|
Voxel.Raycast(feedInventoryData.invData.world, feedInventoryData.ray, distance, -538488837, 128, ___SphereRadius);
|
|
}
|
|
if (entityAlive == null && _actionData.invData.holdingEntity is EntityPlayerLocal)
|
|
{
|
|
LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(_actionData.invData.holdingEntity as EntityPlayerLocal);
|
|
NGUIWindowManager nguiWindowManager = uiforPlayer.nguiWindowManager;
|
|
XUiC_FocusedBlockHealth.SetData(uiforPlayer, null, 0f);
|
|
}
|
|
holdingEntity.SetModelLayer(modelLayer, false, null);
|
|
if (feedInventoryData.TargetEntity == null)
|
|
{
|
|
feedInventoryData.TargetEntity = entityAlive;
|
|
}
|
|
if (feedInventoryData.TargetEntity == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
List<string> buffActions = new List<string>();
|
|
|
|
if (___BuffActions != null)
|
|
{
|
|
buffActions = ___BuffActions;
|
|
}
|
|
|
|
if (feedInventoryData.TargetEntity != null)
|
|
{
|
|
//Log.Out("ItemActionUseOtherPatches-ExecuteAction 6c");
|
|
string itemName = _actionData.invData.itemValue.ItemClass.GetItemName();
|
|
|
|
if (feedInventoryData.invData.item.HasAnyTags(___medicalItemTag))
|
|
{
|
|
//Log.Out("ItemActionUseOtherPatches-ExecuteAction 6d");
|
|
if (!RebirthUtilities.CanHeal(itemName, feedInventoryData.TargetEntity, _actionData.invData.holdingEntity))
|
|
{
|
|
//Log.Out("ItemActionUseOtherPatches-ExecuteAction 6e");
|
|
return false;
|
|
}
|
|
|
|
feedInventoryData.TargetEntity.Buffs.AddBuff("FuriousRamsayHealParticle");
|
|
}
|
|
}
|
|
|
|
if (feedInventoryData.invData.item.HasAnyTags(___medicalItemTag) && !(feedInventoryData.TargetEntity is EntityPlayer || feedInventoryData.TargetEntity is EntityNPCRebirth))
|
|
{
|
|
//Log.Out("ItemActionUseOtherPatches-ExecuteAction 7");
|
|
feedInventoryData.bFeedingStarted = false;
|
|
feedInventoryData.TargetEntity = null;
|
|
return false;
|
|
}
|
|
if (feedInventoryData.invData.item.HasAnyTags(___medicalItemTag) && feedInventoryData.TargetEntity.HasAnyTags(___noMedBuffsTag))
|
|
{
|
|
//Log.Out("ItemActionUseOtherPatches-ExecuteAction 8");
|
|
feedInventoryData.bFeedingStarted = false;
|
|
feedInventoryData.TargetEntity = null;
|
|
return false;
|
|
}
|
|
_actionData.invData.holdingEntity.RightArmAnimationUse = true;
|
|
if (___soundStart != null)
|
|
{
|
|
//Log.Out("ItemActionUseOtherPatches-ExecuteAction 9");
|
|
_actionData.invData.holdingEntity.PlayOneShot(___soundStart, false);
|
|
}
|
|
_actionData.invData.holdingEntity.MinEventContext.Other = feedInventoryData.TargetEntity;
|
|
_actionData.invData.holdingEntity.MinEventContext.ItemValue = _actionData.invData.itemValue;
|
|
_actionData.invData.holdingEntity.FireEvent(MinEventTypes.onSelfHealedOther, true);
|
|
_actionData.invData.holdingEntity.FireEvent((_actionData.indexInEntityOfAction == 0) ? MinEventTypes.onSelfPrimaryActionEnd : MinEventTypes.onSelfSecondaryActionEnd, true);
|
|
if (_actionData.invData.itemValue.ItemClass.HasAnyTags(___stopBleed) && feedInventoryData.TargetEntity.entityType == EntityType.Player && feedInventoryData.TargetEntity.Buffs.HasBuff("buffInjuryBleeding"))
|
|
{
|
|
//Log.Out("ItemActionUseOtherPatches-ExecuteAction 10");
|
|
IAchievementManager achievementManager = PlatformManager.NativePlatform.AchievementManager;
|
|
if (achievementManager != null)
|
|
{
|
|
//Log.Out("ItemActionUseOtherPatches-ExecuteAction 11");
|
|
achievementManager.SetAchievementStat(EnumAchievementDataStat.BleedOutStopped, 1);
|
|
}
|
|
}
|
|
|
|
ItemAction.ExecuteBuffActions(buffActions, feedInventoryData.TargetEntity.entityId, feedInventoryData.TargetEntity, false, EnumBodyPartHit.None, null);
|
|
EntityPlayer entityPlayer = _actionData.invData.holdingEntity as EntityPlayer;
|
|
if (__instance.Consume)
|
|
{
|
|
//Log.Out("ItemActionUseOtherPatches-ExecuteAction 12");
|
|
if (_actionData.invData.itemValue.MaxUseTimes > 0 && _actionData.invData.itemValue.UseTimes + 1f < (float)_actionData.invData.itemValue.MaxUseTimes)
|
|
{
|
|
//Log.Out("ItemActionUseOtherPatches-ExecuteAction 13");
|
|
ItemValue itemValue = _actionData.invData.itemValue;
|
|
itemValue.UseTimes += EffectManager.GetValue(PassiveEffects.DegradationPerUse, feedInventoryData.invData.itemValue, 1f, _actionData.invData.holdingEntity, null, _actionData.invData.itemValue.ItemClass.ItemTags, true, true, true, true, true, 1, false);
|
|
feedInventoryData.invData.itemValue = itemValue;
|
|
return false;
|
|
}
|
|
_actionData.invData.holdingEntity.inventory.DecHoldingItem(1);
|
|
}
|
|
if (___CreateItem != null && ___CreateItemCount > 0)
|
|
{
|
|
//Log.Out("ItemActionUseOtherPatches-ExecuteAction 14");
|
|
ItemStack itemStack = new ItemStack(ItemClass.GetItem(___CreateItem, false), ___CreateItemCount);
|
|
LocalPlayerUI uiforPlayer2 = LocalPlayerUI.GetUIForPlayer(entityPlayer as EntityPlayerLocal);
|
|
if (null != uiforPlayer2 && !uiforPlayer2.xui.PlayerInventory.AddItem(itemStack))
|
|
{
|
|
//Log.Out("ItemActionUseOtherPatches-ExecuteAction 15");
|
|
_actionData.invData.holdingEntity.world.gameManager.ItemDropServer(itemStack, _actionData.invData.holdingEntity.GetPosition(), Vector3.zero, -1, 60f, false);
|
|
}
|
|
}
|
|
feedInventoryData.bFeedingStarted = false;
|
|
feedInventoryData.TargetEntity = null;
|
|
|
|
//Log.Out("ItemActionUseOtherPatches-ExecuteAction END");
|
|
return false;
|
|
}
|
|
}
|
|
}
|