Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ed86592

Browse files
authored
Move Changelings to ActionsV2 (unitystation#11131)
* Unbrick changelings and move them to V2 actions * notes
1 parent b0ac9c7 commit ed86592

11 files changed

Lines changed: 164 additions & 54 deletions

File tree

UnityProject/Assets/ScriptableObjects/Antagonists/Changeling/AugmentedEyesight.asset

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityProject/Assets/Scripts/US13/Actions/ActionData.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using Logs;
34
using NaughtyAttributes;
45
using UnityEngine;
@@ -9,8 +10,8 @@
910

1011
namespace US13.Actions
1112
{
12-
[System.Serializable]
13-
13+
[Obsolete("ActionData is deprecated, please use ActionButtonData instead. ActionsV2 are the standard now, and older V1 actions can be ported quickly to V2 using ToActionButtonData().")]
14+
[Serializable]
1415
[CreateAssetMenu(fileName = "ActionData", menuName = "ScriptableObjects/ActionData")]
1516
public class ActionData : ScriptableObject
1617
{

UnityProject/Assets/Scripts/US13/HealthV2/Living/EmaggableMob.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public List<TextColor> InteractionsStrings()
7575
{
7676
var result = new List<TextColor>();
7777

78-
var hands = PlayerManager.LocalPlayerScript.Equipment.ItemStorage.GetActiveHandSlot();
78+
var hands = PlayerManager.LocalPlayerScript?.Equipment?.ItemStorage?.GetActiveHandSlot();
7979
if (_canBeEmagged && hands != null && hands.ItemAttributes != null && hands.ItemAttributes.GetTraits().Contains(CommonTraits.Instance.Emag) == false)
8080
{
8181
result.Add(new TextColor() {Text = "Left click while holding an EMAG to sabotage this bot.", Color = Color.red});

UnityProject/Assets/Scripts/US13/Systems/Antagonists/Antags/Changeling/ChangelingAbility/ChangelingAbility.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,23 @@ public class ChangelingAbility : NetworkBehaviour, IActionGUI
2727
private bool isToggled = false;
2828
public bool IsToggled => isToggled;
2929

30+
private bool HasV1ActionUIRegistered()
31+
{
32+
var mgr = UIActionManager.Instance;
33+
if (mgr == null) return false;
34+
if (mgr.DicIActionGUI == null) return false;
35+
return mgr.DicIActionGUI.ContainsKey(this);
36+
}
37+
3038
public virtual void CallActionClient()
3139
{
40+
if (HasV1ActionUIRegistered() == false)
41+
{
42+
// If this ability is triggered via Action V2, it won't exist in the V1 UIAction dictionary.
43+
// V2 buttons should call serverside directly; local abilities can still be invoked via their UI paths.
44+
return;
45+
}
46+
3247
var action = UIActionManager.Instance.DicIActionGUI[this][0];
3348

3449
if (UIManager.Instance.displayControl.hudChangeling.ChangelingMain == null)
@@ -66,8 +81,7 @@ public void CallActionServer(PlayerInfo SentByPlayer, Vector3 clickPosition)
6681
return;
6782
}
6883

69-
if (ValidateAbility(SentByPlayer) == false)
70-
return;
84+
if (ValidateAbility(SentByPlayer) == false) return;
7185
if (CastAbilityServer(SentByPlayer, clickPosition))
7286
{
7387
AfterAbility(SentByPlayer);
@@ -94,6 +108,11 @@ public void CallActionServerToggle(PlayerInfo sentByPlayer, bool toggle)
94108
{
95109
isToggled = toggle;
96110
toggleAbility.UseAbilityToggleServer(changeling, isToggled);
111+
// Run client-side toggle effect (e.g. AugmentedEyesight camera) for the owning player.
112+
if (sentByPlayer.Script != null && sentByPlayer.Script.connectionToClient != null)
113+
{
114+
changeling.TargetRunAbilityToggleClient(sentByPlayer.Script.connectionToClient, AbilityData.Index, isToggled);
115+
}
97116
}
98117
catch (Exception ex)
99118
{
@@ -103,6 +122,8 @@ public void CallActionServerToggle(PlayerInfo sentByPlayer, bool toggle)
103122
}
104123
if (ActionData.Sprites.Count != 2)
105124
return;
125+
if (HasV1ActionUIRegistered() == false)
126+
return;
106127
if (isToggled)
107128
{
108129
UIActionManager.SetServerSpriteSO(this, ActionData.Sprites[1]);
@@ -118,6 +139,8 @@ public void ForceToggleToState(bool toggle)
118139
isToggled = toggle;
119140
if (ActionData.Sprites.Count != 2)
120141
return;
142+
if (HasV1ActionUIRegistered() == false)
143+
return;
121144
if (isToggled)
122145
{
123146
UIActionManager.SetServerSpriteSO(this, ActionData.Sprites[1]);
@@ -191,7 +214,10 @@ private void AfterAbility(PlayerInfo sentByPlayer)
191214
return;
192215
Cooldowns.TryStartServer(sentByPlayer.Script, AbilityData, CooldownTime);
193216

194-
UIActionManager.SetCooldown(this, CooldownTime, sentByPlayer.GameObject);
217+
if (HasV1ActionUIRegistered())
218+
{
219+
UIActionManager.SetCooldown(this, CooldownTime, sentByPlayer.GameObject);
220+
}
195221
}
196222

197223
private void AfterAbilityClient(PlayerScript sentByPlayer)
@@ -200,7 +226,10 @@ private void AfterAbilityClient(PlayerScript sentByPlayer)
200226
return;
201227
Cooldowns.TryStartClient(sentByPlayer, AbilityData, CooldownTime);
202228

203-
UIActionManager.SetCooldown(this, CooldownTime, sentByPlayer.GameObject);
229+
if (HasV1ActionUIRegistered())
230+
{
231+
UIActionManager.SetCooldown(this, CooldownTime, sentByPlayer.GameObject);
232+
}
204233
}
205234

206235
private bool ValidateAbility(PlayerInfo sentByPlayer)

UnityProject/Assets/Scripts/US13/Systems/Antagonists/Antags/Changeling/ChangelingAbility/ChangelingBaseAbility.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using Logs;
23
using Mirror;
34
using UnityEngine;
@@ -8,6 +9,10 @@
89

910
namespace US13.Systems.Antagonists.Antags.Changeling.ChangelingAbility
1011
{
12+
/// <summary>
13+
/// Base class for all changeling abilities.
14+
/// MARKED FOR DEPRECATION: The older version of Changeling is too messy and hard to maintain. It is considered for a future refactor.
15+
/// </summary>
1116
public class ChangelingBaseAbility: ActionData, ICooldown
1217
{
1318
public short Index => (short)ChangelingAbilityList.Instance.Abilites.IndexOf(this);

UnityProject/Assets/Scripts/US13/Systems/Antagonists/Antags/Changeling/ChangelingAbility/ChangelingToggleAbility.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public class ChangelingToggleAbility : ChangelingBaseAbility
2222
public bool IsStopingChemRegeneration => isStopingChemRegeneration;
2323

2424

25-
public virtual bool UseAbilityToggleClient(ChangelingMain changeling, bool toggle)
25+
/// <param name="fromServer">When true, server already applied the toggle; only run client visuals, do not send CmdRequestChangelingAbilitesToggle.</param>
26+
public virtual bool UseAbilityToggleClient(ChangelingMain changeling, bool toggle, bool fromServer = false)
2627
{
2728
return true;
2829
}

UnityProject/Assets/Scripts/US13/Systems/Antagonists/Antags/Changeling/ChangelingAbility/Implementation/AugmentedEyesight.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,20 @@ public class AugmentedEyesight: ChangelingToggleAbility
2020
[SerializeField] private float revertvisibilityAnimationSpeed = 0.2f;
2121
public float RevertvisibilityAnimationSpeed => revertvisibilityAnimationSpeed;
2222

23-
public override bool UseAbilityToggleClient(ChangelingMain changeling, bool toggle)
23+
public override bool UseAbilityToggleClient(ChangelingMain changeling, bool toggle, bool fromServer = false)
2424
{
2525
if (Camera.main == null ||
2626
Camera.main.TryGetComponent<CameraEffectControlScript>(out var effects) == false) return true;
2727

2828
effects.AdjustPlayerVisibility(
2929
toggle ? ExpandedNightVisionVisibility : effects.MinimalVisibilityScale,
3030
toggle ? DefaultvisibilityAnimationSpeed : RevertvisibilityAnimationSpeed);
31-
effects.ToggleNightVisionEffectState(toggle, new Color(255,26,26));
3231
effects.NvgHasMaxedLensRadius(true);
3332

34-
PlayerManager.LocalPlayerScript.PlayerNetworkActions.CmdRequestChangelingAbilitesToggle(Index, toggle);
33+
if (fromServer == false)
34+
{
35+
PlayerManager.LocalPlayerScript.PlayerNetworkActions.CmdRequestChangelingAbilitesToggle(Index, toggle);
36+
}
3537
return true;
3638
}
3739

UnityProject/Assets/Scripts/US13/Systems/Antagonists/Antags/Changeling/ChangelingAbility/Implementation/RevivingStasis.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace US13.Systems.Antagonists.Antags.Changeling.ChangelingAbility.Implement
88
[CreateAssetMenu(menuName = "ScriptableObjects/Systems/ChangelingAbilities/RevivingStasis")]
99
public class RevivingStasis: ChangelingToggleAbility
1010
{
11-
public override bool UseAbilityToggleClient(ChangelingMain changeling, bool toggle)
11+
public override bool UseAbilityToggleClient(ChangelingMain changeling, bool toggle, bool fromServer = false)
1212
{
1313
return false;
1414
}

UnityProject/Assets/Scripts/US13/Systems/Antagonists/Antags/Changeling/ChangelingAbility/Implementation/TransformAbility.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Collections;
22
using System.Collections.Generic;
3+
using Cysharp.Threading.Tasks;
4+
using Logs;
35
using Mirror;
46
using UnityEngine;
57
using UnityEngine.Rendering;
@@ -92,7 +94,7 @@ private IEnumerator ChangelingStartTransformAction(PlayerScript body, CharacterS
9294
body.playerHealth.UpdateBloodPool(true);
9395
var bodyParts = GetBodyParts(body);
9496
SetUpItems(itemsBeforeTransform, bodyParts);
95-
SetUpFakeItems(dna, changeling, body.playerHealth);
97+
_ = SetUpFakeItems(dna, changeling, body.playerHealth);
9698
yield return WaitFor.SecondsRealtime(2f);
9799
UpdateSprites(body.playerHealth.playerSprites, characterSheet);
98100
body.playerHealth.UpdateMeatAndSkinProduce();
@@ -251,11 +253,22 @@ private void SetUpItems(List<(Pickupable, NamedSlot)> itemsBeforeTransform, Dict
251253
}
252254
}
253255

254-
private void SetUpFakeItems(ChangelingDna dna, ChangelingMain changeling, LivingHealthMasterBase health)
256+
private async UniTask SetUpFakeItems(ChangelingDna dna, ChangelingMain changeling, LivingHealthMasterBase health)
255257
{
256258
if (dna != null && changeling != null)
257259
{
258260
var storage = changeling.ChangelingMind.CurrentPlayScript.DynamicItemStorage;
261+
var tries = 0;
262+
while (tries < 10)
263+
{
264+
await UniTask.WaitForEndOfFrame();
265+
tries += 1;
266+
if (tries == 10)
267+
{
268+
Loggy.Error($"Failed to find storage for fake items after 10 tries for {changeling.ChangelingMind.CurrentPlayScript.visibleName}", Category.Changeling);
269+
return;
270+
}
271+
}
259272
// need to firstly create fake uniform for placing id card into fake slot
260273
foreach (var id in dna.BodyClothesPrefabID)
261274
{

0 commit comments

Comments
 (0)