11using System . Collections ;
22using System . Collections . Generic ;
3+ using MiraAPI . Events ;
4+ using MiraAPI . Events . Vanilla . Gameplay ;
35using MiraAPI . GameOptions ;
6+ using MiraAPI . Modifiers ;
47using MiraAPI . Modifiers . Types ;
58using NewMod . Options ;
69using NewMod . Options . Modifiers ;
@@ -15,6 +18,7 @@ public class StickyModifier : GameModifier
1518 public override bool HideOnUi => false ;
1619 public override bool ShowInFreeplay => true ;
1720 public static List < PlayerControl > linkedPlayers = [ ] ;
21+ public static bool _IsActive = false ;
1822 public override int GetAmountPerGame ( )
1923 {
2024 return ( int ) OptionGroupSingleton < ModifiersOptions > . Instance . StickyAmount ;
@@ -29,62 +33,74 @@ public override int GetAssignmentChance()
2933 }
3034 public override string GetDescription ( )
3135 {
32- float distance = OptionGroupSingleton < StickyModifierOptions > . Instance . StickyDistance . Value ;
33- float duration = OptionGroupSingleton < StickyModifierOptions > . Instance . StickyDuration . Value ;
36+ float distance = ( int ) OptionGroupSingleton < StickyModifierOptions > . Instance . StickyDistance ;
37+ float duration = ( int ) OptionGroupSingleton < StickyModifierOptions > . Instance . StickyDuration ;
3438
3539 return $ "{ ModifierName } : Pulls nearby players within { distance } units for { duration } seconds.";
3640 }
3741 public override void FixedUpdate ( )
3842 {
3943 base . FixedUpdate ( ) ;
4044
41- if ( ! Player . CanMove ) return ;
45+ if ( _IsActive ) return ;
46+
47+ if ( ! Player . CanMove || Player . Data . IsDead ) return ;
4248
4349 foreach ( var player in PlayerControl . AllPlayerControls )
4450 {
45- if ( player == Player || linkedPlayers . Contains ( player ) ) continue ;
51+ if ( player == Player ) continue ;
4652
47- float distance = OptionGroupSingleton < StickyModifierOptions > . Instance . StickyDistance . Value ;
53+ float distance = ( int ) OptionGroupSingleton < StickyModifierOptions > . Instance . StickyDistance ;
4854
4955 if ( Vector2 . Distance ( player . GetTruePosition ( ) , Player . GetTruePosition ( ) ) < distance )
5056 {
57+ _IsActive = true ;
5158 linkedPlayers . Add ( player ) ;
5259 Coroutines . Start ( CoFollowStickyPlayer ( player ) ) ;
60+ break ;
5361 }
5462 }
5563 }
5664 public IEnumerator CoFollowStickyPlayer ( PlayerControl player )
5765 {
58- var info = new StickyState
66+ float duration = ( int ) OptionGroupSingleton < StickyModifierOptions > . Instance . StickyDuration ;
67+ float timer = 0f ;
68+ float pullStrength = ( int ) OptionGroupSingleton < StickyModifierOptions > . Instance . PullStrength ;
69+ float stopDistance = 1f ;
70+
71+ while ( timer < duration )
5972 {
60- StickyOwner = Player ,
61- LinkedPlayer = player ,
62- velocity = Vector3 . zero ,
63- } ;
73+ if ( player . Data . IsDead || player . Data . Disconnected ) break ;
6474
65- yield return HudManager . Instance . StartCoroutine (
66- Effects . Overlerp ( 0.5f , new System . Action < float > ( ( t ) =>
67- {
68- Vector3 targetPos = info . LinkedPlayer . transform . position ;
69- Vector3 currentPos = info . StickyOwner . transform . position ;
75+ timer += Time . deltaTime ;
7076
71- info . LinkedPlayer . transform . position = Vector3 . SmoothDamp (
72- targetPos ,
73- currentPos ,
74- ref info . velocity ,
75- t
76- ) ;
77- } )
78- ) ) ;
77+ var ownerPos = Player . transform . position ;
78+ var targetPos = player . transform . position ;
7979
80+ float distance = Vector3 . Distance ( ownerPos , targetPos ) ;
81+
82+ if ( distance > stopDistance )
83+ {
84+ Vector3 direction = ( ownerPos - targetPos ) . normalized ;
85+ Vector3 leashPoint = ownerPos - ( direction * stopDistance ) ;
86+
87+ player . transform . position = Vector3 . Lerp ( targetPos , leashPoint , Time . deltaTime * pullStrength ) ;
88+ }
89+ yield return null ;
90+ }
8091 linkedPlayers . Remove ( player ) ;
81- }
82- }
8392
84- class StickyState
85- {
86- public PlayerControl StickyOwner ;
87- public PlayerControl LinkedPlayer ;
88- public Vector3 velocity ;
93+ _IsActive = true ;
94+
95+ if ( Player . AmOwner )
96+ {
97+ PlayerControl . LocalPlayer . RpcRemoveModifier < StickyModifier > ( ) ;
98+ }
99+ }
100+ [ RegisterEvent ]
101+ public static void OnRoundStart ( RoundStartEvent evt )
102+ {
103+ linkedPlayers . Clear ( ) ;
104+ }
89105 }
90106}
0 commit comments