Skip to content

Commit e63f6e2

Browse files
fix: making key press 1 revive and pickup/drop pots [MTT-4802] (#770)
* source of truth for action button resides inside ClientInputSender
1 parent f27bf7e commit e63f6e2

File tree

7 files changed

+225
-147
lines changed

7 files changed

+225
-147
lines changed

Assets/Prefabs/Character/PlayerAvatar.prefab

+5
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ PrefabInstance:
176176
propertyPath: animator
177177
value:
178178
objectReference: {fileID: 1829276847453002016}
179+
- target: {fileID: 7420593339233078707, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3}
180+
propertyPath: m_ClientCharacter
181+
value:
182+
objectReference: {fileID: 7209204667172237188}
179183
- target: {fileID: 7420593339233078707, guid: 0d2d836e2e83b754fa1a1c4022d6d65d, type: 3}
180184
propertyPath: m_ClientVisualization
181185
value:
@@ -278,6 +282,7 @@ MonoBehaviour:
278282
m_Script: {fileID: 11500000, guid: 331c67f15523ad7419792662b9768f44, type: 3}
279283
m_Name:
280284
m_EditorClassIdentifier:
285+
m_ServerCharacter: {fileID: 741733315856861890}
281286
m_PhysicsWrapper: {fileID: 6116655102486013040}
282287
--- !u!114 &4887850889182527394
283288
MonoBehaviour:

Assets/Scripts/Gameplay/GameplayObjects/RuntimeDataContainers/GameDataSource.cs

+15
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ public Action GetActionPrototypeByID(ActionID index)
8484
return m_AllActions[index.ID];
8585
}
8686

87+
public bool TryGetActionPrototypeByID(ActionID index, out Action action)
88+
{
89+
for (int i = 0; i < m_AllActions.Count; i++)
90+
{
91+
if (m_AllActions[i].ActionID == index)
92+
{
93+
action = m_AllActions[i];
94+
return true;
95+
}
96+
}
97+
98+
action = null;
99+
return false;
100+
}
101+
87102
/// <summary>
88103
/// Contents of the CharacterData list, indexed by CharacterType for convenience.
89104
/// </summary>

Assets/Scripts/Gameplay/UI/HeroActionBar.cs

+34-104
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using Unity.BossRoom.Gameplay.UserInput;
44
using Unity.BossRoom.Gameplay.GameplayObjects;
55
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
6-
using Unity.Netcode;
76
using UnityEngine;
87
using Action = Unity.BossRoom.Gameplay.Actions.Action;
98
using SkillTriggerStyle = Unity.BossRoom.Gameplay.UserInput.ClientInputSender.SkillTriggerStyle;
@@ -41,22 +40,6 @@ public class HeroActionBar : MonoBehaviour
4140
/// </summary>
4241
ClientInputSender m_InputSender;
4342

44-
/// <summary>
45-
/// Cached reference to local player's net state.
46-
/// We find the Sprites to use by checking the Skill1, Skill2, and Skill3 members of our chosen CharacterClass
47-
/// </summary>
48-
ServerCharacter m_ServerCharacter;
49-
50-
/// <summary>
51-
/// If we have another player selected, this is a reference to their stats; if anything else is selected, this is null
52-
/// </summary>
53-
ServerCharacter m_SelectedPlayerServerCharacter;
54-
55-
/// <summary>
56-
/// If m_SelectedPlayerNetState is non-null, this indicates whether we think they're alive. (Updated every frame)
57-
/// </summary>
58-
bool m_WasSelectedPlayerAliveDuringLastUpdate;
59-
6043
/// <summary>
6144
/// Identifiers for the buttons on the action bar.
6245
/// </summary>
@@ -139,26 +122,46 @@ void RegisterInputSender(ClientPlayerAvatar clientPlayerAvatar)
139122
}
140123

141124
m_InputSender = inputSender;
142-
m_ServerCharacter = m_InputSender.GetComponent<ServerCharacter>();
143-
m_ServerCharacter.TargetId.OnValueChanged += OnSelectionChanged;
144-
m_ServerCharacter.HeldNetworkObject.OnValueChanged += OnHeldNetworkObjectChanged;
145-
UpdateAllActionButtons();
125+
m_InputSender.action1ModifiedCallback += Action1ModifiedCallback;
126+
127+
Action action1 = null;
128+
if (m_InputSender.actionState1 != null)
129+
{
130+
GameDataSource.Instance.TryGetActionPrototypeByID(m_InputSender.actionState1.actionID, out action1);
131+
}
132+
UpdateActionButton(m_ButtonInfo[ActionButtonType.BasicAction], action1);
133+
134+
Action action2 = null;
135+
if (m_InputSender.actionState2 != null)
136+
{
137+
GameDataSource.Instance.TryGetActionPrototypeByID(m_InputSender.actionState2.actionID, out action2);
138+
}
139+
UpdateActionButton(m_ButtonInfo[ActionButtonType.Special1], action2);
140+
141+
Action action3 = null;
142+
if (m_InputSender.actionState3 != null)
143+
{
144+
GameDataSource.Instance.TryGetActionPrototypeByID(m_InputSender.actionState3.actionID, out action3);
145+
}
146+
UpdateActionButton(m_ButtonInfo[ActionButtonType.Special2], action3);
146147
}
147148

148-
void OnHeldNetworkObjectChanged(ulong previousValue, ulong newValue)
149+
void Action1ModifiedCallback()
149150
{
150-
UpdateAllActionButtons();
151+
var action = GameDataSource.Instance.GetActionPrototypeByID(m_InputSender.actionState1.actionID);
152+
153+
UpdateActionButton(m_ButtonInfo[ActionButtonType.BasicAction],
154+
action,
155+
m_InputSender.actionState1.selectable);
151156
}
152157

153158
void DeregisterInputSender()
154159
{
155-
m_InputSender = null;
156-
if (m_ServerCharacter != null)
160+
if (m_InputSender)
157161
{
158-
m_ServerCharacter.TargetId.OnValueChanged -= OnSelectionChanged;
159-
m_ServerCharacter.HeldNetworkObject.OnValueChanged -= OnHeldNetworkObjectChanged;
162+
m_InputSender.action1ModifiedCallback -= Action1ModifiedCallback;
160163
}
161-
m_ServerCharacter = null;
164+
m_InputSender = null;
162165
}
163166

164167
void Awake()
@@ -201,29 +204,10 @@ void OnDestroy()
201204

202205
void Update()
203206
{
204-
// If we have another player selected, see if their aliveness state has changed,
205-
// and if so, update the interactiveness of the basic-action button
206-
207-
if (UnityEngine.Input.GetKeyUp(KeyCode.Alpha4))
207+
if (Input.GetKeyUp(KeyCode.Alpha4))
208208
{
209209
m_ButtonInfo[ActionButtonType.EmoteBar].Button.OnPointerUpEvent.Invoke();
210210
}
211-
212-
if (!m_SelectedPlayerServerCharacter) { return; }
213-
214-
bool isAliveNow = m_SelectedPlayerServerCharacter.NetLifeState.LifeState.Value == LifeState.Alive;
215-
if (isAliveNow != m_WasSelectedPlayerAliveDuringLastUpdate)
216-
{
217-
// this will update the icons so that the basic-action button's interactiveness is correct
218-
UpdateAllActionButtons();
219-
}
220-
221-
m_WasSelectedPlayerAliveDuringLastUpdate = isAliveNow;
222-
}
223-
224-
void OnSelectionChanged(ulong oldSelectionNetworkId, ulong newSelectionNetworkId)
225-
{
226-
UpdateAllActionButtons();
227211
}
228212

229213
void OnButtonClickedDown(ActionButtonType buttonType)
@@ -240,7 +224,7 @@ void OnButtonClickedDown(ActionButtonType buttonType)
240224
}
241225

242226
// send input to begin the action associated with this button
243-
m_InputSender.RequestAction(m_ButtonInfo[buttonType].CurAction, SkillTriggerStyle.UI);
227+
m_InputSender.RequestAction(m_ButtonInfo[buttonType].CurAction.ActionID, SkillTriggerStyle.UI);
244228
}
245229

246230
void OnButtonClickedUp(ActionButtonType buttonType)
@@ -258,61 +242,7 @@ void OnButtonClickedUp(ActionButtonType buttonType)
258242
}
259243

260244
// send input to complete the action associated with this button
261-
m_InputSender.RequestAction(m_ButtonInfo[buttonType].CurAction, SkillTriggerStyle.UIRelease);
262-
}
263-
264-
/// <summary>
265-
/// Updates all the action buttons and caches info about the currently-selected entity (when appropriate):
266-
/// stores info in m_SelectedPlayerNetState and m_WasSelectedPlayerAliveDuringLastUpdate
267-
/// </summary>
268-
void UpdateAllActionButtons()
269-
{
270-
UpdateActionButton(m_ButtonInfo[ActionButtonType.BasicAction], m_ServerCharacter.CharacterClass.Skill1);
271-
UpdateActionButton(m_ButtonInfo[ActionButtonType.Special1], m_ServerCharacter.CharacterClass.Skill2);
272-
UpdateActionButton(m_ButtonInfo[ActionButtonType.Special2], m_ServerCharacter.CharacterClass.Skill3);
273-
274-
var isHoldingNetworkObject =
275-
NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(m_ServerCharacter.HeldNetworkObject.Value,
276-
out var heldNetworkObject);
277-
278-
NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(m_ServerCharacter.TargetId.Value,
279-
out var selection);
280-
281-
if (isHoldingNetworkObject)
282-
{
283-
// show drop!
284-
UpdateActionButton(m_ButtonInfo[ActionButtonType.BasicAction], GameDataSource.Instance.DropActionPrototype, true);
285-
}
286-
if ((m_ServerCharacter.TargetId.Value != 0
287-
&& selection != null
288-
&& selection.TryGetComponent(out PickUpState pickUpState))
289-
)
290-
{
291-
// special case: targeting a pickup-able item or holding a pickup object
292-
UpdateActionButton(m_ButtonInfo[ActionButtonType.BasicAction], GameDataSource.Instance.PickUpActionPrototype, true);
293-
}
294-
else if (m_ServerCharacter.TargetId.Value != 0
295-
&& selection != null
296-
&& selection.NetworkObjectId != m_ServerCharacter.NetworkObjectId
297-
&& selection.TryGetComponent(out ServerCharacter charState)
298-
&& !charState.IsNpc)
299-
{
300-
// special case: when we have a player selected, we change the meaning of the basic action
301-
// we have another player selected! In that case we want to reflect that our basic Action is a Revive, not an attack!
302-
// But we need to know if the player is alive... if so, the button should be disabled (for better player communication)
303-
304-
bool isAlive = charState.NetLifeState.LifeState.Value == LifeState.Alive;
305-
UpdateActionButton(m_ButtonInfo[ActionButtonType.BasicAction], GameDataSource.Instance.ReviveActionPrototype, !isAlive);
306-
307-
// we'll continue to monitor our selected player every frame to see if their life-state changes.
308-
m_SelectedPlayerServerCharacter = charState;
309-
m_WasSelectedPlayerAliveDuringLastUpdate = isAlive;
310-
}
311-
else
312-
{
313-
m_SelectedPlayerServerCharacter = null;
314-
m_WasSelectedPlayerAliveDuringLastUpdate = false;
315-
}
245+
m_InputSender.RequestAction(m_ButtonInfo[buttonType].CurAction.ActionID, SkillTriggerStyle.UIRelease);
316246
}
317247

318248
void UpdateActionButton(ActionButtonInfo buttonInfo, Action action, bool isClickable = true)

Assets/Scripts/Gameplay/UI/HeroEmoteBar.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ public void OnButtonClicked(int buttonIndex)
5555
{
5656
switch (buttonIndex)
5757
{
58-
case 0: m_InputSender.RequestAction(GameDataSource.Instance.Emote1ActionPrototype, SkillTriggerStyle.UI); break;
59-
case 1: m_InputSender.RequestAction(GameDataSource.Instance.Emote2ActionPrototype, SkillTriggerStyle.UI); break;
60-
case 2: m_InputSender.RequestAction(GameDataSource.Instance.Emote3ActionPrototype, SkillTriggerStyle.UI); break;
61-
case 3: m_InputSender.RequestAction(GameDataSource.Instance.Emote4ActionPrototype, SkillTriggerStyle.UI); break;
58+
case 0: m_InputSender.RequestAction(GameDataSource.Instance.Emote1ActionPrototype.ActionID, SkillTriggerStyle.UI); break;
59+
case 1: m_InputSender.RequestAction(GameDataSource.Instance.Emote2ActionPrototype.ActionID, SkillTriggerStyle.UI); break;
60+
case 2: m_InputSender.RequestAction(GameDataSource.Instance.Emote3ActionPrototype.ActionID, SkillTriggerStyle.UI); break;
61+
case 3: m_InputSender.RequestAction(GameDataSource.Instance.Emote4ActionPrototype.ActionID, SkillTriggerStyle.UI); break;
6262
}
6363
}
6464

Assets/Scripts/Gameplay/UI/PartyHUD.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ private void SetHeroSelectFX(ulong target, bool selected)
239239

240240
public void SelectPartyMember(int slot)
241241
{
242-
m_ClientSender.RequestAction(GameDataSource.Instance.GeneralTargetActionPrototype, ClientInputSender.SkillTriggerStyle.UI, m_PartyIds[slot]);
242+
m_ClientSender.RequestAction(GameDataSource.Instance.GeneralTargetActionPrototype.ActionID,
243+
ClientInputSender.SkillTriggerStyle.UI, m_PartyIds[slot]);
243244
}
244245

245246
// helper to initialize the Allies array - safe to call multiple times

0 commit comments

Comments
 (0)