Skip to content

Commit f304ae3

Browse files
authored
[GOMPS-330] Pillars do not stun the boss (#206)
* [GOMPS-330] Pillars do not stun the boss - IDamageable now has a "flags" field, and a flag for "stuns the boss". - BreakablePillar now has the flag indicating that it stuns the boss. Also gave the pillar prefab a (nonmoving) rigidbody so that the boss can collide with it - refactored TrampleAction to remove repetitive code. (The flow between functions is still kinda choppy, but I don't see an easy fix there.) - added the Stunned action to the GameDataSource again. (Who keeps removing it?!) * Trying to revert these weird changes... testing one ability first * Reverting more changes that shouldnt be in this PR * get this TankShieldBuff out of here * Trying again to get an LFS file out of my PR I can't see the diffs so I can't tell what's going to work * Manually copied the version from Develop into this PR These LFS files are not easy to work with * Remove [Flags] from enum with one value to work around Unity bug * typo * More boss-stun refinements * boost boss base-health from 100 to 200
1 parent c87111e commit f304ae3

File tree

9 files changed

+133
-19
lines changed

9 files changed

+133
-19
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:042274c3870033c4f5bf81bb62fed2740a97a9541df03ab5cc7a885000dc9bcc
3-
size 935
2+
oid sha256:818857ebae4fad947db07995cf25acf9838d60e6c8c60ec16c9238c1b16546b3
3+
size 955
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:f657f7081f4fb2c005104ef7612e7c8816ac8ce2aa6485b146767190c7264841
2+
oid sha256:d3026ee5a68e09d7653227c668997ab9b0b38255444254da1ffbfe025ebcf619
33
size 408

Assets/BossRoom/Models/Animation Controllers/CharacterSetController.controller

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ AnimatorStateTransition:
273273
m_TransitionDuration: 0.12049153
274274
m_TransitionOffset: 0
275275
m_ExitTime: 0.1350613
276-
m_HasExitTime: 1
276+
m_HasExitTime: 0
277277
m_HasFixedDuration: 1
278278
m_InterruptionSource: 0
279279
m_OrderedInterruption: 1
@@ -1851,6 +1851,7 @@ AnimatorState:
18511851
m_CycleOffset: 0
18521852
m_Transitions:
18531853
- {fileID: -5472320550880040946}
1854+
- {fileID: 8725031495282662693}
18541855
m_StateMachineBehaviours: []
18551856
m_Position: {x: 50, y: 50, z: 0}
18561857
m_IKOnFeet: 0
@@ -2477,7 +2478,7 @@ AnimatorStateTransition:
24772478
m_TransitionDuration: 0.07605173
24782479
m_TransitionOffset: 0
24792480
m_ExitTime: 0.042834345
2480-
m_HasExitTime: 1
2481+
m_HasExitTime: 0
24812482
m_HasFixedDuration: 1
24822483
m_InterruptionSource: 0
24832484
m_OrderedInterruption: 1
@@ -3054,6 +3055,31 @@ AnimatorStateTransition:
30543055
m_InterruptionSource: 0
30553056
m_OrderedInterruption: 1
30563057
m_CanTransitionToSelf: 1
3058+
--- !u!1101 &8725031495282662693
3059+
AnimatorStateTransition:
3060+
m_ObjectHideFlags: 1
3061+
m_CorrespondingSourceObject: {fileID: 0}
3062+
m_PrefabInstance: {fileID: 0}
3063+
m_PrefabAsset: {fileID: 0}
3064+
m_Name:
3065+
m_Conditions:
3066+
- m_ConditionMode: 1
3067+
m_ConditionEvent: Stunned
3068+
m_EventTreshold: 0
3069+
m_DstStateMachine: {fileID: 0}
3070+
m_DstState: {fileID: -1989540649778147493}
3071+
m_Solo: 0
3072+
m_Mute: 0
3073+
m_IsExit: 0
3074+
serializedVersion: 3
3075+
m_TransitionDuration: 0.25
3076+
m_TransitionOffset: 0
3077+
m_ExitTime: 0.8214297
3078+
m_HasExitTime: 0
3079+
m_HasFixedDuration: 1
3080+
m_InterruptionSource: 0
3081+
m_OrderedInterruption: 1
3082+
m_CanTransitionToSelf: 1
30573083
--- !u!1101 &8727437690882463675
30583084
AnimatorStateTransition:
30593085
m_ObjectHideFlags: 1

Assets/BossRoom/Prefabs/Game/BreakablePillar.prefab

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ GameObject:
1414
- component: {fileID: -8903857516321632127}
1515
- component: {fileID: 1460791283510277443}
1616
- component: {fileID: 7670444733571025649}
17+
- component: {fileID: 6825752226794478105}
1718
m_Layer: 6
1819
m_Name: BreakablePillar
1920
m_TagString: Untagged
@@ -79,6 +80,10 @@ MonoBehaviour:
7980
m_Script: {fileID: 11500000, guid: eb44a31731a459546bdf01f1af48173c, type: 3}
8081
m_Name:
8182
m_EditorClassIdentifier:
83+
m_MaxHealth: {fileID: 0}
84+
m_NetworkHealthState: {fileID: 0}
85+
m_Collider: {fileID: 1460791283510277443}
86+
m_SpecialDamageFlags: 6
8287
--- !u!65 &1460791283510277443
8388
BoxCollider:
8489
m_ObjectHideFlags: 0
@@ -109,6 +114,22 @@ MonoBehaviour:
109114
m_UnbrokenGameObjects:
110115
- {fileID: 3658718798844854089}
111116
m_NetState: {fileID: 7561466626167410996}
117+
--- !u!54 &6825752226794478105
118+
Rigidbody:
119+
m_ObjectHideFlags: 0
120+
m_CorrespondingSourceObject: {fileID: 0}
121+
m_PrefabInstance: {fileID: 0}
122+
m_PrefabAsset: {fileID: 0}
123+
m_GameObject: {fileID: 884761565141663561}
124+
serializedVersion: 2
125+
m_Mass: 1
126+
m_Drag: 0
127+
m_AngularDrag: 0.05
128+
m_UseGravity: 1
129+
m_IsKinematic: 0
130+
m_Interpolate: 0
131+
m_Constraints: 126
132+
m_CollisionDetection: 0
112133
--- !u!1001 &2926384259182416435
113134
PrefabInstance:
114135
m_ObjectHideFlags: 0

Assets/BossRoom/Prefabs/GameDataSource.prefab

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,4 @@ MonoBehaviour:
7272
- {fileID: 11400000, guid: 90a7c42b138147742a5ef0e724143a74, type: 2}
7373
- {fileID: 11400000, guid: c8770f39d4807a842bea85cfb3b8a649, type: 2}
7474
- {fileID: 11400000, guid: 0626aa2c2ce0d3a4ab4cad814432c2e5, type: 2}
75+
- {fileID: 11400000, guid: 08dc234d2353e0f489e45a0a4a09bf60, type: 2}

Assets/BossRoom/Scripts/Server/Game/Action/TrampleAction.cs

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ private void CollideWithVictim(ServerCharacter victim)
132132
if (chanceToStun > 0 && Random.Range(0,1) < chanceToStun)
133133
{
134134
// we're stunned! No collision behavior for the victim. Stun ourselves and abort.
135-
m_WasStunned = true;
136-
m_Movement.CancelMove();
137-
m_Parent.NetState.RecvCancelAllActionsClientRpc();
135+
StunSelf();
138136
return;
139137
}
140138

@@ -156,23 +154,44 @@ private void CollideWithVictim(ServerCharacter victim)
156154
victimMovement.StartKnockback(m_Parent.transform.position, Description.KnockbackSpeed, Description.KnockbackDuration);
157155
}
158156

157+
// called by owning class when parent's Collider collides with stuff
159158
public override void OnCollisionEnter(Collision collision)
160159
{
161-
var actionStage = GetCurrentStage();
162160
// we only detect other possible victims when we start charging
163-
if (actionStage != ActionStage.Charging)
161+
if (GetCurrentStage() != ActionStage.Charging)
164162
return;
165163

166-
if (m_CollidedAlready.Contains(collision.collider))
164+
Collide(collision.collider);
165+
}
166+
167+
// here we handle colliding with anything (whether a victim or not)
168+
private void Collide(Collider collider)
169+
{
170+
if (m_CollidedAlready.Contains(collider))
167171
return; // already hit them!
168172

169-
m_CollidedAlready.Add(collision.collider);
173+
m_CollidedAlready.Add(collider);
170174

171-
var victim = collision.collider.gameObject.GetComponent<ServerCharacter>();
175+
var victim = collider.gameObject.GetComponent<ServerCharacter>();
172176
if (victim)
173177
{
174178
CollideWithVictim(victim);
175179
}
180+
else if (!m_WasStunned)
181+
{
182+
// they aren't a living, breathing victim, but they might still be destructible...
183+
var damageable = collider.gameObject.GetComponent<IDamageable>();
184+
if (damageable != null)
185+
{
186+
damageable.ReceiveHP(this.m_Parent, -Description.SplashDamage);
187+
188+
// lastly, a special case: if the trampler runs into certain breakables, they are stunned!
189+
if ((damageable.GetSpecialDamageFlags() & IDamageable.SpecialDamageFlags.StunOnTrample) == IDamageable.SpecialDamageFlags.StunOnTrample)
190+
{
191+
StunSelf();
192+
}
193+
}
194+
}
176195
}
177196

178197
private void SimulateCollisionWithNearbyFoes()
@@ -184,13 +203,18 @@ private void SimulateCollisionWithNearbyFoes()
184203
int numResults = ActionUtils.DetectNearbyEntities(true, true, m_Parent.GetComponent<Collider>(), k_PhysicalTouchDistance, out results);
185204
for (int i = 0; i < numResults; i++)
186205
{
187-
m_CollidedAlready.Add(results[i].collider);
188-
var serverChar = results[i].collider.GetComponent<ServerCharacter>();
189-
if (serverChar)
190-
{
191-
CollideWithVictim(serverChar);
192-
}
206+
Collide(results[i].collider);
207+
}
208+
}
209+
210+
private void StunSelf()
211+
{
212+
if (!m_WasStunned)
213+
{
214+
m_Movement.CancelMove();
215+
m_Parent.NetState.RecvCancelAllActionsClientRpc();
193216
}
217+
m_WasStunned = true;
194218
}
195219

196220
public override bool ChainIntoNewAction(ref ActionRequestData newAction)

Assets/BossRoom/Scripts/Server/Game/Character/ServerCharacter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,5 +270,10 @@ private void OnStoppedChargingUp()
270270
{
271271
m_ActionPlayer.OnGameplayActivity(Action.GameplayActivity.StoppedChargingUp);
272272
}
273+
274+
public IDamageable.SpecialDamageFlags GetSpecialDamageFlags()
275+
{
276+
return IDamageable.SpecialDamageFlags.None;
277+
}
273278
}
274279
}

Assets/BossRoom/Scripts/Server/Game/Entity/IDamageable.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using UnityEngine;
23

34
namespace BossRoom.Server
@@ -24,6 +25,23 @@ public interface IDamageable
2425
/// The transform of this object.
2526
/// </summary>
2627
Transform transform { get; }
28+
29+
[Flags]
30+
public enum SpecialDamageFlags
31+
{
32+
None = 0,
33+
UnusedFlag = 1 << 0, // does nothing; see comments below
34+
StunOnTrample = 1 << 1,
35+
NotDamagedByPlayers = 1 << 2,
36+
37+
// The "UnusedFlag" flag does nothing. It exists to work around a Unity editor quirk involving [Flags] enums:
38+
// if you enable all the flags, Unity stores the value as 0xffffffff (labeled "Everything"), meaning that not
39+
// only are all the currently-existing flags enabled, but any future flags you added later would also be enabled!
40+
// This is not future-proof and can cause hard-to-track-down problems, when prefabs magically inherit a new flag
41+
// you just added. So we have the Unused flag, which should NOT do anything, and shouldn't be selected on prefabs.
42+
// It's just there so that we can select all the "real" flags and not get it turned into "Everything" in the editor.
43+
}
44+
SpecialDamageFlags GetSpecialDamageFlags();
2745
}
2846
}
2947

Assets/BossRoom/Scripts/Server/Game/Entity/ServerBreakableLogic.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public class ServerBreakableLogic : NetworkBehaviour, IDamageable
2121
[SerializeField]
2222
Collider m_Collider;
2323

24+
[SerializeField]
25+
[Tooltip("Indicate which special interaction behaviors are needed for this breakable")]
26+
IDamageable.SpecialDamageFlags m_SpecialDamageFlags;
27+
2428
private NetworkBreakableState m_State;
2529

2630
private void Awake()
@@ -47,6 +51,16 @@ public void ReceiveHP(ServerCharacter inflicter, int HP)
4751
{
4852
if (HP < 0)
4953
{
54+
if (inflicter && !inflicter.IsNpc)
55+
{
56+
bool isNotDamagedByPlayers = (GetSpecialDamageFlags() & IDamageable.SpecialDamageFlags.NotDamagedByPlayers) == IDamageable.SpecialDamageFlags.NotDamagedByPlayers;
57+
if (isNotDamagedByPlayers)
58+
{
59+
// a player tried to damage us, but we are immune to player damage!
60+
return;
61+
}
62+
}
63+
5064
if (m_NetworkHealthState)
5165
{
5266
m_NetworkHealthState.HitPoints.Value = Mathf.Max(m_NetworkHealthState.HitPoints.Value + HP, 0);
@@ -79,6 +93,11 @@ public void Unbreak()
7993
m_NetworkHealthState.HitPoints.Value = m_MaxHealth.Value;
8094
}
8195

96+
public IDamageable.SpecialDamageFlags GetSpecialDamageFlags()
97+
{
98+
return m_SpecialDamageFlags;
99+
}
100+
82101
#if UNITY_EDITOR
83102
private void OnValidate()
84103
{

0 commit comments

Comments
 (0)