Skip to content

Commit

Permalink
fix knife stealing
Browse files Browse the repository at this point in the history
  • Loading branch information
Govorunb committed Dec 7, 2023
1 parent 50b5d01 commit c256aae
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 10 deletions.
38 changes: 34 additions & 4 deletions SCHIZO/Items/FumoItem/EvilFumoItemTool.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using Nautilus.Extensions;
using UnityEngine;

namespace SCHIZO.Items.FumoItem;

partial class EvilFumoItemTool
{
public Knife stolenKnife;
private static float _knifeScale = 0.9f;

protected override void ApplyAltEffect(bool active)
{
Expand All @@ -15,13 +19,13 @@ protected override void ApplyAltEffect(bool active)
{
stolenKnife = knife;
YoinkKnife();
damageOnPoke *= 2;
damageOnPoke *= 4;
}
usingPlayer.liveMixin.TakeDamage(dmg);
}
else
{
if (stealKnife && !ReturnKnife())
if (!ReturnKnife())
LOGGER.LogError("Could not return stolen knife");
}
}
Expand All @@ -45,7 +49,25 @@ private bool TryFindKnife(out Knife knife)

private void YoinkKnife()
{
PlugIntoSocket(stolenKnife, transform);
UWE.Utils.SetCollidersEnabled(stolenKnife.gameObject, false);
UWE.Utils.SetIsKinematic(stolenKnife.GetComponent<Rigidbody>(), true);
UWE.Utils.SetEnabled(stolenKnife.GetComponent<LargeWorldEntity>(), false);
stolenKnife.transform.SetParent(knifeSocket.Exists() ?? transform, true);
stolenKnife.transform.localScale *= _knifeScale;
}

protected override void Update()
{
base.Update();
if (stolenKnife)
RepositionKnife(stolenKnife.transform);
}

// i don't know what's rotating things *several frames* after they're unparented but i wish it a very pleasant go commit refactor (in copilot)
private static void RepositionKnife(Transform knife)
{
knife.localRotation = Quaternion.identity;
knife.localPosition = Vector3.zero;
}

private bool ReturnKnife()
Expand All @@ -59,6 +81,14 @@ private bool ReturnKnife()

private void DropKnife()
{
stolenKnife.transform.parent = null;
stolenKnife.transform.localScale /= _knifeScale;
stolenKnife.transform.SetParent(null, true);
GameObject colliderTarget = stolenKnife.gameObject;
FPModel fpModel = stolenKnife.GetComponent<FPModel>();
if (fpModel) colliderTarget = fpModel.propModel;
UWE.Utils.SetCollidersEnabled(colliderTarget, true);
UWE.Utils.SetIsKinematic(stolenKnife.GetComponent<Rigidbody>(), false);
if (stolenKnife.GetComponent<LargeWorldEntity>().Exists() is { } lwe)
LargeWorldStreamer.main!?.cellManager.RegisterEntity(lwe);
}
}
2 changes: 1 addition & 1 deletion SCHIZO/Items/FumoItem/FumoItemTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void FixedUpdate()
if (_altEffectTimeRemaining < 0f) SetAltEffect(false);
}

public void Update()
protected virtual void Update()
{
if (!usingPlayer) return;

Expand Down
61 changes: 56 additions & 5 deletions Unity/Assets/Mod/Evil Fumo/Evil Fumo item.prefab
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &4427810026626581335
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4086069228116111534}
m_Layer: 0
m_Name: Knife socket
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4086069228116111534
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4427810026626581335}
m_LocalRotation: {x: 0.30061084, y: -0.040196054, z: -0.9146508, w: 0.26726663}
m_LocalPosition: {x: 0.16, y: -0.24, z: -1.74}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 8418634198100310474}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 5, y: 325, z: 211}
--- !u!54 &3813723675008832454
Rigidbody:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -87,17 +117,17 @@ MonoBehaviour:
secondaryUseText:
hasAltUse: 1
altUseText: Poke ({0})
altUsableChance: 0.25
altUsableChance: 1
altEffectOnHugChance: 1
altEffectMinHugTime: 2
altEffectDuration: 2
altEffectDuration: 5
hugCooldown: 1
hugColdResistBuff: 40
fumoModelSN: {fileID: 3795415044668019676}
fumoModelBZ: {fileID: 4264099153745794611}
damageOnPoke: 10
stealKnife: 0
knifeSocket: {fileID: 0}
damageOnPoke: 5
stealKnife: 1
knifeSocket: {fileID: 4086069228116111534}
--- !u!114 &2974045779525387420
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -164,11 +194,21 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.y
value: 73
objectReference: {fileID: 0}
- target: {fileID: 1752336031019831118, guid: 494d51939a4d56f47a65310c2d52e286,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2351523049876982568, guid: 494d51939a4d56f47a65310c2d52e286,
type: 3}
propertyPath: m_Name
value: Evil Fumo item
objectReference: {fileID: 0}
- target: {fileID: 3796789029613737883, guid: 494d51939a4d56f47a65310c2d52e286,
type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5277470585440791267, guid: 494d51939a4d56f47a65310c2d52e286,
type: 3}
propertyPath: m_LocalPosition.x
Expand Down Expand Up @@ -324,6 +364,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8775181316061534643, guid: 494d51939a4d56f47a65310c2d52e286,
type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents:
- {fileID: 6545938831321695140, guid: 494d51939a4d56f47a65310c2d52e286, type: 3}
- {fileID: 2416869583082230119, guid: 494d51939a4d56f47a65310c2d52e286, type: 3}
Expand Down Expand Up @@ -382,6 +427,12 @@ GameObject:
type: 3}
m_PrefabInstance: {fileID: 8219148621552729296}
m_PrefabAsset: {fileID: 0}
--- !u!4 &8418634198100310474 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 487716062766548250, guid: 494d51939a4d56f47a65310c2d52e286,
type: 3}
m_PrefabInstance: {fileID: 8219148621552729296}
m_PrefabAsset: {fileID: 0}
--- !u!4 &4264099153745794611 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 5277470585440791267, guid: 494d51939a4d56f47a65310c2d52e286,
Expand Down

0 comments on commit c256aae

Please sign in to comment.