Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evil fumo item + lowpoly fumo tooltip #55

Merged
merged 6 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions SCHIZO/Items/FumoItem/EvilFumoItemTool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
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)
{
LOGGER.LogWarning(active);
if (active)
{
float dmg = damageOnPoke;
if (stealKnife && TryFindKnife(out Knife knife)
&& Inventory.main.InternalDropItem(knife.pickupable))
{
stolenKnife = knife;
YoinkKnife();
dmg *= 4;
}
usingPlayer.liveMixin.TakeDamage(dmg);
damageOnPoke *= 1.25f; // negative reward function
}
else
{
if (!ReturnKnife())
LOGGER.LogError("Could not return stolen knife");
}
}

private bool TryFindKnife(out Knife knife)
{
knife = default;

QuickSlots slots = Inventory.main.quickSlots;
for (int i = 0; i < 5; i++)
{
InventoryItem item = slots.GetSlotItem(i);
if (item is null || !item.item)
continue;
knife = item.item.GetComponent<Knife>();
if (!knife) continue;
return true;
}
return false;
}

private void YoinkKnife()
{
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()
{
if (!stolenKnife) return true;
DropKnife();

if (!Inventory.main.Pickup(stolenKnife.pickupable)) return false;
return true;
}

private void DropKnife()
{
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.BelowZero.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SCHIZO.Items.FumoItem;

public partial class FumoItemTool
partial class FumoItemTool
{
private (Transform parent, Vector3 localPosOffset) GetHugOffset(float distScale)
{
Expand Down
70 changes: 38 additions & 32 deletions SCHIZO/Items/FumoItem/FumoItemTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace SCHIZO.Items.FumoItem;
partial class FumoItemTool
{
public bool IsHugging => _isHugging;
public bool IsFlushed => _isFlushed;
public bool IsAltEffectActive => isAltEffectActive;
private Transform FumoModel => RetargetHelpers.Pick(fumoModelSN, fumoModelBZ);

private const float _hugTransitionDuration = 0.2f;
Expand All @@ -22,40 +22,47 @@ partial class FumoItemTool
private bool _hugEffectApplied;
private const float _hugMoveSpeedMulti = 0.7f;

private bool _flushOnAltUse;
private bool _flushOnHug;
private bool _isFlushed;
protected bool altUseEnabled;
protected bool _altEffectOnHug;
protected bool isAltEffectActive;
private float _altEffectTimeRemaining;
private float _flushedZscalar = 1.5f;

private GroundMotor _groundMotor;

public new void Awake()
{
_flushOnAltUse = Random.Range(0f, 1f) < 0.05f;
hasAltUse = _flushOnAltUse;
_flushOnHug = !_flushOnAltUse && Random.Range(0f, 1f) < 0.5f;
if (hasAltUse)
{
altUseEnabled = Random.Range(0f, 1f) < altUsableChance;
hasAltUse = altUseEnabled;
_altEffectOnHug = !altUseEnabled && Random.Range(0f, 1f) < altEffectOnHugChance;
}

base.Awake();
}

public void FixedUpdate()
{
if (!usingPlayer) return;
if (!_flushOnHug) return;

if (_isHugging)
{
_hugTime += Time.fixedDeltaTime;
if (_hugTime > 10f) SetFlushed(true);
}
else
if (_altEffectOnHug)
{
_hugTime = 0;
if (_hugDistScale == 0f) SetFlushed(false);
if (_isHugging)
{
_hugTime += Time.fixedDeltaTime;
if (_hugTime > altEffectMinHugTime) SetAltEffect(true);
}
else
{
_hugTime = 0;
}
}
_altEffectTimeRemaining -= Time.fixedDeltaTime;
if (_altEffectTimeRemaining < 0f) SetAltEffect(false);
}

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

Expand Down Expand Up @@ -88,7 +95,7 @@ public override void OnHolster()
// need to reset immediately, otherwise PDA opens in the wrong location
UpdateHugPos(0);
StopHugging();
if (_isFlushed) SetFlushed(false);
if (isAltEffectActive) SetAltEffect(false);
base.OnHolster();
}

Expand All @@ -107,18 +114,11 @@ public override bool OnRightHandUp()
return base.OnRightHandUp();
}

public override bool OnAltDown()
public override bool OnAltHeld()
{
if (!_flushOnAltUse) return false;
if (!altUseEnabled) return false;

return SetFlushed(true) && base.OnAltDown();
}

public override bool OnAltUp()
{
if (!_flushOnAltUse) return false;

return SetFlushed(false) && base.OnAltUp();
return SetAltEffect(true) && base.OnAltHeld();
}

public void StartHugging()
Expand Down Expand Up @@ -175,15 +175,21 @@ private void ApplyGroundMoveSpeedMulti(float multi)
_groundMotor.backwardMaxSpeed *= multi;
}

public bool SetFlushed(bool flushed)
private bool SetAltEffect(bool active)
{
if (_isFlushed == flushed) return false;
if (active) _altEffectTimeRemaining = altEffectDuration;
if (isAltEffectActive == active) return false;

_isFlushed = flushed;
ApplyZScaleMulti(flushed ? _flushedZscalar : 1 / _flushedZscalar);
isAltEffectActive = active;
ApplyAltEffect(active);
return true;
}

protected virtual void ApplyAltEffect(bool active)
{
ApplyZScaleMulti(active ? _flushedZscalar : 1 / _flushedZscalar);
}

private void ApplyZScaleMulti(float multi)
{
Vector3 scale = FumoModel.localScale;
Expand Down
23 changes: 23 additions & 0 deletions Unity/Assets/Mod/Evil Fumo/Evil Fumo Spawns.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a6ccb8c039e34e44ebdee40c7d89e4a4, type: 3}
m_Name: Evil Fumo Spawns
m_EditorClassIdentifier:
spawns:
- game: 2
locations:
- position: {x: -327, y: 15, z: 265.5}
Alexejhero marked this conversation as resolved.
Show resolved Hide resolved
rotation: {x: 0, y: 120, z: 0}
item:
isCustom: 1
techType: 2007
itemData: {fileID: 11400000, guid: 7783c6be943946e49b6d4a4982e601d6, type: 2}
8 changes: 8 additions & 0 deletions Unity/Assets/Mod/Evil Fumo/Evil Fumo Spawns.asset.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: df4563dc669f9794796a4ad61212cb60, type: 3}
m_Name: Evil Fumo data
m_Name: Evil Fumo buildable data
m_EditorClassIdentifier:
prefab: {fileID: 2351523049876982568, guid: 494d51939a4d56f47a65310c2d52e286, type: 3}
loader:
Expand Down
Loading