From 0b666dc724f34df42b38b17f80a486dbf0d1365b Mon Sep 17 00:00:00 2001 From: Simon Wang <60266027+WangXin1507@users.noreply.github.com> Date: Sun, 22 Dec 2024 12:03:31 -0800 Subject: [PATCH 01/13] Initial implementation of idol passive Need to be able to register for enemy death to trigger buff. --- .../Specific Ghosts/Idol/IdolPassive.cs | 100 ++++++++++++++++++ .../Specific Ghosts/Idol/IdolPassive.cs.meta | 11 ++ 2 files changed, 111 insertions(+) create mode 100644 Assets/Scripts/Ghosts/Specific Ghosts/Idol/IdolPassive.cs create mode 100644 Assets/Scripts/Ghosts/Specific Ghosts/Idol/IdolPassive.cs.meta diff --git a/Assets/Scripts/Ghosts/Specific Ghosts/Idol/IdolPassive.cs b/Assets/Scripts/Ghosts/Specific Ghosts/Idol/IdolPassive.cs new file mode 100644 index 0000000..ce9b59a --- /dev/null +++ b/Assets/Scripts/Ghosts/Specific Ghosts/Idol/IdolPassive.cs @@ -0,0 +1,100 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// +/// Passive for the Idol Ghost, boosts player speed when enemy dies. +/// +/// TODO hook up enemy death event to call IncrementTempo +public class IdolPassive : MonoBehaviour +{ + [SerializeField] public int tempoStack = 0; // Buff count, maxes at 3 stacks + [SerializeField] public int runSpeedMod = 20; // Run speed modifier for each buff stack, in percentage + [SerializeField] public int glideSpeedMod = 8; // Glide speed modifier for each buff stack, in percentage + [SerializedField] public float tempoDuration = 8.0f; // Duration before 1 stack of tempo expires + + // Reference to player stats + private Stats stats; + private int maxRunningSpeedIdx; + private int runningAccelIdx; + private int runningDeaccelIdx; + + private int maxGlideSpeedIdx; + private int glideAccelIdx; + private int glideDeaccelIdx; + + void Start() + { + stats = GetComponent(); + maxRunningSpeedIdx = stats.GetStatIndex("Max Running Speed"); + runningAccelIdx = stats.GetStatIndex("Running Acceleration"); + runningDeaccelIdx = stats.GetStatIndex("Running Deacceleration"); + + maxGlideSpeedIdx = stats.GetStatIndex("Max Glide Speed"); + glideAccelIdx = stats.GetStatIndex("Glide Acceleration"); + glideDeaccelIdx = stats.GetStatIndex("Glide Deacceleration"); + } + + /// + /// Increases the Idol buff count by one + /// + public void IncrementTempo() + { + StartCoroutine(TempoCoroutine()); + } + + /// + /// Increases the Idol buff count (max 3) + /// + /// number of buff stacks to add + public void IncrementTempo(int count) + { + for (int i = 0; i < count; i++) + { + StartCoroutine(TempoCoroutine()); + } + } + + /// + /// Remove all buff stacks. + /// Please use when switching ghost + /// + public void ResetTempo() + { + StopAllCoroutines(); + tempoStack = 0; + } + + /// + /// Modify player speed stats by changes in player stack count + /// + /// + private void UpdateSpeed(int deltaStack) + { + stats.ModifyStat(maxRunningSpeedIdx, runSpeedMod * deltaStack); + stats.ModifyStat(runningAccelIdx, runSpeedMod * deltaStack); + stats.ModifyStat(runningDeaccelIdx, runSpeedMod * deltaStack); + + stats.ModifyStat(maxGlideSpeedIdx, glideSpeedMod * deltaStack); + stats.ModifyStat(glideAccelIdx, glideSpeedMod * deltaStack); + stats.ModifyStat(glideDeaccelIdx, glideSpeedMod * deltaStack); + } + + /// + /// Gain 1 stack of tempo + /// + /// + private IEnumerator TempoCoroutine() + { + if (tempoStack == 3) + { + yield break; + } + tempoStack ++; + UpdateSpeed(1); + + yield return new WaitForSeconds(tempoDuration); + tempoStack --; + UpdateSpeed(-1); + } +} diff --git a/Assets/Scripts/Ghosts/Specific Ghosts/Idol/IdolPassive.cs.meta b/Assets/Scripts/Ghosts/Specific Ghosts/Idol/IdolPassive.cs.meta new file mode 100644 index 0000000..cc00d2c --- /dev/null +++ b/Assets/Scripts/Ghosts/Specific Ghosts/Idol/IdolPassive.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 645bc16239d4c9644939b3c962b821e6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From e897264d641912c10acb924aa3b0d6f4617ba462 Mon Sep 17 00:00:00 2001 From: Simon Wang <60266027+WangXin1507@users.noreply.github.com> Date: Sun, 22 Dec 2024 12:25:26 -0800 Subject: [PATCH 02/13] fix --- Assets/Scripts/Ghosts/Specific Ghosts/Idol/IdolPassive.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Scripts/Ghosts/Specific Ghosts/Idol/IdolPassive.cs b/Assets/Scripts/Ghosts/Specific Ghosts/Idol/IdolPassive.cs index ce9b59a..c169e92 100644 --- a/Assets/Scripts/Ghosts/Specific Ghosts/Idol/IdolPassive.cs +++ b/Assets/Scripts/Ghosts/Specific Ghosts/Idol/IdolPassive.cs @@ -11,7 +11,7 @@ public class IdolPassive : MonoBehaviour [SerializeField] public int tempoStack = 0; // Buff count, maxes at 3 stacks [SerializeField] public int runSpeedMod = 20; // Run speed modifier for each buff stack, in percentage [SerializeField] public int glideSpeedMod = 8; // Glide speed modifier for each buff stack, in percentage - [SerializedField] public float tempoDuration = 8.0f; // Duration before 1 stack of tempo expires + [SerializeField] public float tempoDuration = 8.0f; // Duration before 1 stack of tempo expires // Reference to player stats private Stats stats; From 6b7d260c9c7c755d9a149aceee82303d68147fbb Mon Sep 17 00:00:00 2001 From: Simon Wang <60266027+WangXin1507@users.noreply.github.com> Date: Mon, 23 Dec 2024 21:18:10 -0800 Subject: [PATCH 03/13] Optimized enemy cooldown update. Used async tasks instead to count for enemy cooldown --- Assets/Scripts/Enemies/States/Action.cs | 40 ++++++++++--------- Assets/Scripts/Enemies/States/ActionPool.cs | 17 ++------ .../Enemies/States/EnemyStateManager.cs | 4 -- .../Enemies/States/GreedyActionPool.cs | 2 +- 4 files changed, 25 insertions(+), 38 deletions(-) diff --git a/Assets/Scripts/Enemies/States/Action.cs b/Assets/Scripts/Enemies/States/Action.cs index 17a6162..ba2afe0 100644 --- a/Assets/Scripts/Enemies/States/Action.cs +++ b/Assets/Scripts/Enemies/States/Action.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using Unity.VisualScripting.FullSerializer; using UnityEngine; @@ -8,13 +9,14 @@ /// public class Action { - public Transform hitBox; - public float coolDown; - public float priority; - public string anim; - - private float maxCD; + public bool ready = true; // Could change later so certain actions may not be immediately accessible at the start of encounter + private Transform hitBox; + private float maxCD; + private float coolDown; + private float priority; + private string anim; + /// /// Constructs an Action for a particular Enemy /// @@ -38,8 +40,8 @@ public Action(Transform hitBox, float coolDown, float priority, string anim) /// Optional transition duration for the animation public void Play(Animator animator, float fadeDuration = 0.2f) { - ResetCD(); animator.CrossFade(anim, fadeDuration); + DoCoolDown(); } /// @@ -52,25 +54,25 @@ public virtual bool InAttackRange() } /// - /// Finds if Action has finished cool down + /// Resets the Action's cooldown /// - /// True if Action finished cool down - public bool Ready() + public void ResetCD() { - return coolDown <= 0; + coolDown = maxCD; } - /// - /// Updates the Action's cool down - /// - public void UpdateCD() + public float GetPriority() { - coolDown -= Time.deltaTime; + return this.priority; } - // Resets the Action's cool down - private void ResetCD() + /// + /// Make this action go into cooldown + /// + private async Task DoCoolDown() { - coolDown = maxCD; + ready = false; + await Task.Delay((int)(coolDown * 1000)); + ready = true; } } diff --git a/Assets/Scripts/Enemies/States/ActionPool.cs b/Assets/Scripts/Enemies/States/ActionPool.cs index 3b93173..e31b88e 100644 --- a/Assets/Scripts/Enemies/States/ActionPool.cs +++ b/Assets/Scripts/Enemies/States/ActionPool.cs @@ -49,7 +49,7 @@ public Action NextAction() double r = random.NextDouble(); foreach (Action action in avaliableActions) { - r -= action.priority / curWeight; + r -= action.GetPriority() / curWeight; if (r <= 0) { nextAction = action; @@ -76,27 +76,16 @@ public virtual bool HasActionsReady() return false; } - /// - /// Updates the cool down time of all the Actions in pool - /// - public void UpdateAllCD() - { - foreach (Action a in actions) - { - a.UpdateCD(); - } - } - // Return a list of actions that is currently avaliable private List GetAvaliableActions() { List avaliableActions = new List(); foreach (Action a in actions) { - if (a.InAttackRange() & a.Ready()) + if (a.InAttackRange() & a.ready) { avaliableActions.Add(a); - curWeight += a.priority; + curWeight += a.GetPriority(); } } return avaliableActions; diff --git a/Assets/Scripts/Enemies/States/EnemyStateManager.cs b/Assets/Scripts/Enemies/States/EnemyStateManager.cs index 37c1774..6519111 100644 --- a/Assets/Scripts/Enemies/States/EnemyStateManager.cs +++ b/Assets/Scripts/Enemies/States/EnemyStateManager.cs @@ -34,10 +34,6 @@ protected virtual void Awake() protected void FixedUpdate() { - if (curState != IdleState) - { - pool.UpdateAllCD(); // Count down enemy's cool down - } curState.UpdateState(this); } diff --git a/Assets/Scripts/Enemies/States/GreedyActionPool.cs b/Assets/Scripts/Enemies/States/GreedyActionPool.cs index ea9d013..b91a558 100644 --- a/Assets/Scripts/Enemies/States/GreedyActionPool.cs +++ b/Assets/Scripts/Enemies/States/GreedyActionPool.cs @@ -18,7 +18,7 @@ public override bool HasActionsReady() { foreach (Action a in actions) { - if (a.Ready() & a.InAttackRange()) + if (a.ready & a.InAttackRange()) { return true; } From b663dd84f18c310789756aaa62b4a52aacbbca67 Mon Sep 17 00:00:00 2001 From: Simon Wang <60266027+WangXin1507@users.noreply.github.com> Date: Thu, 26 Dec 2024 01:23:31 -0800 Subject: [PATCH 04/13] Initial implementation of drawing damage boxes in editor --- .../Enemies/States/EnemyStateManager.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Assets/Scripts/Enemies/States/EnemyStateManager.cs b/Assets/Scripts/Enemies/States/EnemyStateManager.cs index 6519111..3ce78f9 100644 --- a/Assets/Scripts/Enemies/States/EnemyStateManager.cs +++ b/Assets/Scripts/Enemies/States/EnemyStateManager.cs @@ -83,6 +83,31 @@ public void Flip(bool isFlipped) transform.rotation = Quaternion.Euler(0, 180f, 0); } + /// + /// Do damage to player if they are inside of trigger box + /// + /// Transform component for drawing damage box + /// Points of damage to deal + protected void GenerateDamageFrame(Transform gizmoTrigger, float damage) + { +#if DEBUG // Draw the damage box in the editor + Vector2 center = gizmoTrigger.position; + float hWidth = gizmoTrigger.lossyScale.x/2; + float hHeight = gizmoTrigger.lossyScale.y/2; + + Debug.DrawLine(new Vector2(center.x - hWidth, center.y + hWidth), new Vector2(center.x + hWidth, center.y + hWidth)); // draw top line + Debug.DrawLine(new Vector2(center.x - hWidth, center.y + hWidth), new Vector2(center.x - hWidth, center.y - hWidth)); // draw left line + Debug.DrawLine(new Vector2(center.x - hWidth, center.y - hWidth), new Vector2(center.x + hWidth, center.y - hWidth)); // draw bottom line + Debug.DrawLine(new Vector2(center.x + hWidth, center.y + hWidth), new Vector2(center.x + hWidth, center.y - hWidth)); // draw right line +#endif + // Check for player to do damage + Collider2D hit = Physics2D.OverlapBox(gizmoTrigger.position, gizmoTrigger.lossyScale, 0f, LayerMask.GetMask("Player")); + if (hit) + { + hit.GetComponent().TakeDamage(damage); + } + } + /// /// Produce a list off Actions which randomly generates the next action /// From 9148372d3ee3b8afeda8e42ca4f57f6d003d68bc Mon Sep 17 00:00:00 2001 From: Simon Wang <60266027+WangXin1507@users.noreply.github.com> Date: Thu, 26 Dec 2024 12:16:22 -0800 Subject: [PATCH 05/13] Added stats component to enemy prefab --- .../Enemies/Camera Drone/Camera Drone.prefab | 24 +++++++++++++++-- Assets/Prefabs/Enemies/Cyborg/Cyborg.prefab | 7 +++-- Assets/Prefabs/Enemies/G.R.E.G/G.R.E.G.prefab | 24 +++++++++++++++-- .../Enemies/Riot Police/RiotPolice.prefab | 24 +++++++++++++++-- Assets/Prefabs/Enemies/Roomba/Roomba.prefab | 24 +++++++++++++++-- .../Enemies/Shield Police/ShieldPolice.prefab | 10 ++++--- Assets/Scripts/Enemies/ShieldPolice.cs | 3 ++- .../Enemies/States/EnemyStateManager.cs | 26 ++++++++++--------- Assets/Scripts/Enemies/States/MoveState.cs | 4 ++- 9 files changed, 119 insertions(+), 27 deletions(-) diff --git a/Assets/Prefabs/Enemies/Camera Drone/Camera Drone.prefab b/Assets/Prefabs/Enemies/Camera Drone/Camera Drone.prefab index f4f3e03..cee662d 100644 --- a/Assets/Prefabs/Enemies/Camera Drone/Camera Drone.prefab +++ b/Assets/Prefabs/Enemies/Camera Drone/Camera Drone.prefab @@ -47,6 +47,7 @@ GameObject: - component: {fileID: 3602954514945515610} - component: {fileID: 7679382285400612018} - component: {fileID: 7321790019576285446} + - component: {fileID: 8856570929518799469} m_Layer: 21 m_Name: Camera Drone m_TagString: Untagged @@ -227,9 +228,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 20782b93b693591488b8c308e283c380, type: 3} m_Name: m_EditorClassIdentifier: - speed: 4.83 - aggroRange: 16.76 + stats: {fileID: 0} animator: {fileID: 6400381198355053387} + aggroRange: 16.76 alarmTrigger: {fileID: 7775618551989780944} enemyToSummon: {fileID: 2119936537419083514, guid: 0fedb38f283d38a4faca7620ea8ae537, type: 3} @@ -263,3 +264,22 @@ MonoBehaviour: m_EditorClassIdentifier: health: 0 isAlive: 1 +--- !u!114 &8856570929518799469 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8652318323731026824} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 532320b84239cf640a651fa5709b989a, type: 3} + m_Name: + m_EditorClassIdentifier: + stats: + - name: Speed + value: 1 + modifier: 100 + - name: Max Health + value: 1 + modifier: 100 diff --git a/Assets/Prefabs/Enemies/Cyborg/Cyborg.prefab b/Assets/Prefabs/Enemies/Cyborg/Cyborg.prefab index e01af00..31ce3f2 100644 --- a/Assets/Prefabs/Enemies/Cyborg/Cyborg.prefab +++ b/Assets/Prefabs/Enemies/Cyborg/Cyborg.prefab @@ -262,9 +262,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 03dbe72ab01511e4eb989afdb7a8fadf, type: 3} m_Name: m_EditorClassIdentifier: - speed: 4 - aggroRange: 18.6 + stats: {fileID: 0} animator: {fileID: 7905894014490810442} + aggroRange: 18.6 meleeTrigger: {fileID: 2358971396437510415} tpBackTrigger: {fileID: 1365265030456903513} tpForwardTrigger: {fileID: 3423477219027819224} @@ -286,6 +286,9 @@ MonoBehaviour: - name: Max Health value: 10 modifier: 100 + - name: Speed + value: 10 + modifier: 100 --- !u!114 &8480991602502054467 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/Enemies/G.R.E.G/G.R.E.G.prefab b/Assets/Prefabs/Enemies/G.R.E.G/G.R.E.G.prefab index fced684..b371c9f 100644 --- a/Assets/Prefabs/Enemies/G.R.E.G/G.R.E.G.prefab +++ b/Assets/Prefabs/Enemies/G.R.E.G/G.R.E.G.prefab @@ -107,6 +107,7 @@ GameObject: - component: {fileID: 4071386136463933295} - component: {fileID: 166145500235385066} - component: {fileID: 8152285351237874372} + - component: {fileID: 3440705048582449508} m_Layer: 21 m_Name: G.R.E.G m_TagString: Untagged @@ -289,11 +290,30 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c46f0def17192ce4195c0f554f8184b4, type: 3} m_Name: m_EditorClassIdentifier: - speed: 2 - aggroRange: 9.92 + stats: {fileID: 0} animator: {fileID: 166145500235385066} + aggroRange: 9.92 gunKick: {fileID: 8875514496581505741} gunShoot: {fileID: 6754032986899484797} rangeOrig: {fileID: 6425544609560146439} projectile: {fileID: 1293525611164901038, guid: e64abde8a304ea641afa693f1da4fc8b, type: 3} +--- !u!114 &3440705048582449508 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8433722653154054174} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 532320b84239cf640a651fa5709b989a, type: 3} + m_Name: + m_EditorClassIdentifier: + stats: + - name: Speed + value: 1 + modifier: 100 + - name: Max Health + value: 1 + modifier: 100 diff --git a/Assets/Prefabs/Enemies/Riot Police/RiotPolice.prefab b/Assets/Prefabs/Enemies/Riot Police/RiotPolice.prefab index bb1ff6c..262c7de 100644 --- a/Assets/Prefabs/Enemies/Riot Police/RiotPolice.prefab +++ b/Assets/Prefabs/Enemies/Riot Police/RiotPolice.prefab @@ -45,6 +45,7 @@ GameObject: - component: {fileID: 2458881036478296064} - component: {fileID: 5267342110057752590} - component: {fileID: 2197548027611747354} + - component: {fileID: 9121469439051838776} m_Layer: 21 m_Name: RiotPolice m_TagString: Untagged @@ -225,7 +226,26 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 47a0dd1a6bcc7584d8521953966c8c06, type: 3} m_Name: m_EditorClassIdentifier: - speed: 2 - aggroRange: 7.33 + stats: {fileID: 0} animator: {fileID: 8056966106870366120} + aggroRange: 7.33 batonTrigger: {fileID: 3561678645181035360} +--- !u!114 &9121469439051838776 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1393067818931581941} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 532320b84239cf640a651fa5709b989a, type: 3} + m_Name: + m_EditorClassIdentifier: + stats: + - name: Speed + value: 1 + modifier: 100 + - name: Max Health + value: 1 + modifier: 100 diff --git a/Assets/Prefabs/Enemies/Roomba/Roomba.prefab b/Assets/Prefabs/Enemies/Roomba/Roomba.prefab index fbf0897..7077249 100644 --- a/Assets/Prefabs/Enemies/Roomba/Roomba.prefab +++ b/Assets/Prefabs/Enemies/Roomba/Roomba.prefab @@ -14,6 +14,7 @@ GameObject: - component: {fileID: 9070280046442885385} - component: {fileID: 5620131887818746087} - component: {fileID: 4950017548320773108} + - component: {fileID: -4750325557521470314} m_Layer: 21 m_Name: Roomba m_TagString: Untagged @@ -194,10 +195,29 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 952f5b6ed55837944ba140fdc84331fd, type: 3} m_Name: m_EditorClassIdentifier: - speed: 3 - aggroRange: 7.76 + stats: {fileID: 0} animator: {fileID: 6971829175617292507} + aggroRange: 7.76 kaboomTrigger: {fileID: 2932781976428712665} +--- !u!114 &-4750325557521470314 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1487853512614266132} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 532320b84239cf640a651fa5709b989a, type: 3} + m_Name: + m_EditorClassIdentifier: + stats: + - name: Speed + value: 1 + modifier: 100 + - name: Max Health + value: 1 + modifier: 100 --- !u!1 &4301427481350538189 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/Enemies/Shield Police/ShieldPolice.prefab b/Assets/Prefabs/Enemies/Shield Police/ShieldPolice.prefab index a5a09f4..36e2f6f 100644 --- a/Assets/Prefabs/Enemies/Shield Police/ShieldPolice.prefab +++ b/Assets/Prefabs/Enemies/Shield Police/ShieldPolice.prefab @@ -379,11 +379,12 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 9f2deedc49f7bfd48abc35bdcc0fb1cd, type: 3} m_Name: m_EditorClassIdentifier: - speed: 2 - aggroRange: 9.32 + stats: {fileID: 0} animator: {fileID: 9133294469049910592} + aggroRange: 9.32 batonTrigger: {fileID: 7835333299776145468} chargeTrigger: {fileID: 5532669551329529462} + chargeSpeed: 0 --- !u!255 &2153542378424773396 FixedJoint2D: m_ObjectHideFlags: 0 @@ -400,7 +401,7 @@ FixedJoint2D: m_BreakAction: 3 m_AutoConfigureConnectedAnchor: 1 m_Anchor: {x: 0, y: 0} - m_ConnectedAnchor: {x: 0.64500046, y: 0} + m_ConnectedAnchor: {x: -0.645, y: 0} m_DampingRatio: 0 m_Frequency: 0 --- !u!114 &6887818589130474418 @@ -419,6 +420,9 @@ MonoBehaviour: - name: Max Health value: 10 modifier: 100 + - name: Speed + value: 1 + modifier: 100 --- !u!114 &783357568447536721 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Enemies/ShieldPolice.cs b/Assets/Scripts/Enemies/ShieldPolice.cs index 63ba2ed..4433bea 100644 --- a/Assets/Scripts/Enemies/ShieldPolice.cs +++ b/Assets/Scripts/Enemies/ShieldPolice.cs @@ -11,6 +11,7 @@ public class ShieldPolice : EnemyStateManager { [SerializeField] protected Transform batonTrigger; [SerializeField] protected Transform chargeTrigger; + [SerializeField] protected float chargeSpeed; protected bool isCharging; protected Vector2 chargePos; @@ -19,7 +20,7 @@ void Update() { if (isCharging) { - rb.velocity = new Vector2(speed * 4, rb.velocity.y) * transform.right; + rb.velocity = new Vector2(chargeSpeed, rb.velocity.y) * transform.right; } } diff --git a/Assets/Scripts/Enemies/States/EnemyStateManager.cs b/Assets/Scripts/Enemies/States/EnemyStateManager.cs index 3ce78f9..59b497f 100644 --- a/Assets/Scripts/Enemies/States/EnemyStateManager.cs +++ b/Assets/Scripts/Enemies/States/EnemyStateManager.cs @@ -1,5 +1,7 @@ using System; +using System.Net.Mime; using Unity.VisualScripting; +using UnityEditor.Build; using UnityEngine; /// @@ -12,23 +14,23 @@ public class EnemyStateManager : MonoBehaviour public EnemyStates BusyState = new BusyState(); public EnemyStates MoveState = new MoveState(); - public float speed; // Movement speed - public float aggroRange; // Range for detecting players - - public ActionPool pool; // A pool of attacks to randomly choose from - public EnemyStates curState; // Enemy's current State, defaults to idle - public Animator animator; + [HideInInspector] public Stats stats; // Enemy stats component + [HideInInspector] public ActionPool pool; // A pool of attacks to randomly choose from + [HideInInspector] public Animator animator; + [SerializeField] float aggroRange; // Range for detecting players + protected EnemyStates curState; // Enemy's current State, defaults to idle protected Transform player; protected Rigidbody2D rb; protected virtual void Awake() { player = GameObject.FindGameObjectWithTag("Player").transform; + stats = GetComponent(); animator = GetComponent(); rb = GetComponent(); pool = GenerateActionPool(); - + SwitchState(IdleState); } @@ -74,7 +76,7 @@ public bool HasLineOfSight(bool tracking) /// /// Flip the Enemy object across the Y-axis /// - /// Enemy's current orientation + /// Enemy's current orientation public void Flip(bool isFlipped) { if (isFlipped) @@ -95,10 +97,10 @@ protected void GenerateDamageFrame(Transform gizmoTrigger, float damage) float hWidth = gizmoTrigger.lossyScale.x/2; float hHeight = gizmoTrigger.lossyScale.y/2; - Debug.DrawLine(new Vector2(center.x - hWidth, center.y + hWidth), new Vector2(center.x + hWidth, center.y + hWidth)); // draw top line - Debug.DrawLine(new Vector2(center.x - hWidth, center.y + hWidth), new Vector2(center.x - hWidth, center.y - hWidth)); // draw left line - Debug.DrawLine(new Vector2(center.x - hWidth, center.y - hWidth), new Vector2(center.x + hWidth, center.y - hWidth)); // draw bottom line - Debug.DrawLine(new Vector2(center.x + hWidth, center.y + hWidth), new Vector2(center.x + hWidth, center.y - hWidth)); // draw right line + Debug.DrawLine(new Vector2(center.x - hWidth, center.y + hHeight), new Vector2(center.x + hWidth, center.y + hHeight)); // draw top line + Debug.DrawLine(new Vector2(center.x - hWidth, center.y + hHeight), new Vector2(center.x - hWidth, center.y - hHeight)); // draw left line + Debug.DrawLine(new Vector2(center.x - hWidth, center.y - hHeight), new Vector2(center.x + hWidth, center.y - hHeight)); // draw bottom line + Debug.DrawLine(new Vector2(center.x + hWidth, center.y + hHeight), new Vector2(center.x + hWidth, center.y - hHeight)); // draw right line #endif // Check for player to do damage Collider2D hit = Physics2D.OverlapBox(gizmoTrigger.position, gizmoTrigger.lossyScale, 0f, LayerMask.GetMask("Player")); diff --git a/Assets/Scripts/Enemies/States/MoveState.cs b/Assets/Scripts/Enemies/States/MoveState.cs index c738b46..dd3de25 100644 --- a/Assets/Scripts/Enemies/States/MoveState.cs +++ b/Assets/Scripts/Enemies/States/MoveState.cs @@ -44,6 +44,8 @@ protected void Move(EnemyStateManager enemy) { enemy.Flip(true); } - rb.velocity = new Vector2(enemy.speed * enemy.transform.right.x, rb.velocity.y); + + float speed = enemy.stats.ComputeValue("Speed"); + rb.velocity = new Vector2(speed * enemy.transform.right.x, rb.velocity.y); } } From cfd3af84bc2e7e31d7ace31ed24e53530057343c Mon Sep 17 00:00:00 2001 From: Simon Wang <60266027+WangXin1507@users.noreply.github.com> Date: Thu, 26 Dec 2024 17:13:56 -0800 Subject: [PATCH 06/13] Drawing rectangular damage frames in game view With the gizmo option enabled and compiling in debug mode, all enemies (except roomba) will now draw its damage frame on attacking. --- .../Enemies/Riot Police/RiotPolice.prefab | 2 +- .../Enemies/Shield Police/ShieldPolice.prefab | 4 ++-- Assets/Scripts/Enemies/CameraDrone.cs.meta | 2 +- Assets/Scripts/Enemies/Cyborg.cs | 24 ++++--------------- Assets/Scripts/Enemies/GunWithLegs.cs | 6 +---- Assets/Scripts/Enemies/GunWithLegs.cs.meta | 2 +- Assets/Scripts/Enemies/RiotPolice.cs | 6 +---- Assets/Scripts/Enemies/RiotPolice.cs.meta | 2 +- Assets/Scripts/Enemies/Roomba.cs.meta | 2 +- Assets/Scripts/Enemies/ShieldPolice.cs | 6 +---- Assets/Scripts/Enemies/ShieldPolice.cs.meta | 2 +- .../Enemies/States/EnemyStateManager.cs | 8 +++---- 12 files changed, 19 insertions(+), 47 deletions(-) diff --git a/Assets/Prefabs/Enemies/Riot Police/RiotPolice.prefab b/Assets/Prefabs/Enemies/Riot Police/RiotPolice.prefab index 262c7de..d0a9236 100644 --- a/Assets/Prefabs/Enemies/Riot Police/RiotPolice.prefab +++ b/Assets/Prefabs/Enemies/Riot Police/RiotPolice.prefab @@ -244,7 +244,7 @@ MonoBehaviour: m_EditorClassIdentifier: stats: - name: Speed - value: 1 + value: 4 modifier: 100 - name: Max Health value: 1 diff --git a/Assets/Prefabs/Enemies/Shield Police/ShieldPolice.prefab b/Assets/Prefabs/Enemies/Shield Police/ShieldPolice.prefab index 36e2f6f..ccf8a54 100644 --- a/Assets/Prefabs/Enemies/Shield Police/ShieldPolice.prefab +++ b/Assets/Prefabs/Enemies/Shield Police/ShieldPolice.prefab @@ -384,7 +384,7 @@ MonoBehaviour: aggroRange: 9.32 batonTrigger: {fileID: 7835333299776145468} chargeTrigger: {fileID: 5532669551329529462} - chargeSpeed: 0 + chargeSpeed: 10 --- !u!255 &2153542378424773396 FixedJoint2D: m_ObjectHideFlags: 0 @@ -421,7 +421,7 @@ MonoBehaviour: value: 10 modifier: 100 - name: Speed - value: 1 + value: 4 modifier: 100 --- !u!114 &783357568447536721 MonoBehaviour: diff --git a/Assets/Scripts/Enemies/CameraDrone.cs.meta b/Assets/Scripts/Enemies/CameraDrone.cs.meta index 77d8fa5..e23b123 100644 --- a/Assets/Scripts/Enemies/CameraDrone.cs.meta +++ b/Assets/Scripts/Enemies/CameraDrone.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 7250588514170254948, guid: 0000000000000000d000000000000000, type: 0} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/Scripts/Enemies/Cyborg.cs b/Assets/Scripts/Enemies/Cyborg.cs index 9e626b0..a0ffae3 100644 --- a/Assets/Scripts/Enemies/Cyborg.cs +++ b/Assets/Scripts/Enemies/Cyborg.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.Experimental.Playables; /// /// Enemy AI for the Cyborg @@ -31,18 +32,12 @@ protected override ActionPool GenerateActionPool() // Generate damage frame for melee slash attack protected void OnSlashEvent() { - print("slashing"); - Collider2D hit = Physics2D.OverlapBox(meleeTrigger.position, meleeTrigger.lossyScale, 0f, LayerMask.GetMask("Player")); - if (hit) - { - hit.GetComponent().TakeDamage(1); - } + GenerateDamageFrame(meleeTrigger, 1.0f); } // Teleports the cyborg backwards protected void OnTPBackEvent() { - print("moving back"); RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.right * -1, stingerTrigger.transform.localPosition.x, LayerMask.GetMask("Ground")); if (hit) { @@ -57,7 +52,6 @@ protected void OnTPBackEvent() // Teleprts the cyborg forward protected void OnTPForwardEvent1() { - print("moving forward"); Vector2 dest = new(player.position.x + meleeTrigger.lossyScale.x, player.position.y + 1); gameObject.transform.position = dest; rb.gravityScale = 0; @@ -67,23 +61,13 @@ protected void OnTPForwardEvent1() // Generate damage frame for follow up attack after teleporting forward protected void OnTPForwardEvent2() { - print("stinger spin"); - Collider2D hit = Physics2D.OverlapBox(tpBackTrigger.position, tpBackTrigger.lossyScale, 0f, LayerMask.GetMask("Player")); - if (hit) - { - hit.GetComponent().TakeDamage(1); - } + GenerateDamageFrame(tpBackTrigger, 1.0f); } // Generate damage frame for long range stinger attack protected void OnStingerEvent() { - print("extending stinger"); - Collider2D hit = Physics2D.OverlapBox(stingerHitBox.position, stingerHitBox.lossyScale, 0f, LayerMask.GetMask("Player")); - if (hit) - { - hit.GetComponent().TakeDamage(1); - } + GenerateDamageFrame(stingerHitBox, 1.0f); } protected override void OnFinishAnimation() diff --git a/Assets/Scripts/Enemies/GunWithLegs.cs b/Assets/Scripts/Enemies/GunWithLegs.cs index 4bb0004..62f77b0 100644 --- a/Assets/Scripts/Enemies/GunWithLegs.cs +++ b/Assets/Scripts/Enemies/GunWithLegs.cs @@ -27,11 +27,7 @@ protected override ActionPool GenerateActionPool() // Check for kick collision and do damageg protected void OnKickEvent() { - Collider2D hit = Physics2D.OverlapBox(gunKick.position, gunKick.lossyScale, 0f, LayerMask.GetMask("Player")); - if (hit) - { - hit.GetComponent().TakeDamage(10); - } + GenerateDamageFrame(gunKick, 1.0f); } // Instantiate projectile prefab and push self back diff --git a/Assets/Scripts/Enemies/GunWithLegs.cs.meta b/Assets/Scripts/Enemies/GunWithLegs.cs.meta index dd8d6ad..d074498 100644 --- a/Assets/Scripts/Enemies/GunWithLegs.cs.meta +++ b/Assets/Scripts/Enemies/GunWithLegs.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 7250588514170254948, guid: 0000000000000000d000000000000000, type: 0} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/Scripts/Enemies/RiotPolice.cs b/Assets/Scripts/Enemies/RiotPolice.cs index 53cf514..597214a 100644 --- a/Assets/Scripts/Enemies/RiotPolice.cs +++ b/Assets/Scripts/Enemies/RiotPolice.cs @@ -22,11 +22,7 @@ protected override ActionPool GenerateActionPool() // Check for collision in swing range to deal damage protected void OnBatonEvent() { - Collider2D hit = Physics2D.OverlapBox(batonTrigger.position, batonTrigger.lossyScale, 0f, LayerMask.GetMask("Player")); - if (hit) - { - hit.GetComponent().TakeDamage(15); - } + GenerateDamageFrame(batonTrigger, 1); } // Draws the Enemy attack range in the editor diff --git a/Assets/Scripts/Enemies/RiotPolice.cs.meta b/Assets/Scripts/Enemies/RiotPolice.cs.meta index a0c167b..b0c11a8 100644 --- a/Assets/Scripts/Enemies/RiotPolice.cs.meta +++ b/Assets/Scripts/Enemies/RiotPolice.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 7250588514170254948, guid: 0000000000000000d000000000000000, type: 0} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/Scripts/Enemies/Roomba.cs.meta b/Assets/Scripts/Enemies/Roomba.cs.meta index 68374b5..c45b0cb 100644 --- a/Assets/Scripts/Enemies/Roomba.cs.meta +++ b/Assets/Scripts/Enemies/Roomba.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 7250588514170254948, guid: 0000000000000000d000000000000000, type: 0} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/Scripts/Enemies/ShieldPolice.cs b/Assets/Scripts/Enemies/ShieldPolice.cs index 4433bea..11faa69 100644 --- a/Assets/Scripts/Enemies/ShieldPolice.cs +++ b/Assets/Scripts/Enemies/ShieldPolice.cs @@ -39,11 +39,7 @@ protected override ActionPool GenerateActionPool() // Generate damage frame for baton swing protected void OnBatonEvent() { - Collider2D hit = Physics2D.OverlapBox(batonTrigger.position, batonTrigger.lossyScale, 0f, LayerMask.GetMask("Player")); - if (hit) - { - hit.GetComponent().TakeDamage(15); - } + GenerateDamageFrame(batonTrigger, 1.0f); } // Ask police to begin charging and enable shield damage diff --git a/Assets/Scripts/Enemies/ShieldPolice.cs.meta b/Assets/Scripts/Enemies/ShieldPolice.cs.meta index 6e1b90a..34cb16b 100644 --- a/Assets/Scripts/Enemies/ShieldPolice.cs.meta +++ b/Assets/Scripts/Enemies/ShieldPolice.cs.meta @@ -5,7 +5,7 @@ MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 - icon: {instanceID: 0} + icon: {fileID: 7250588514170254948, guid: 0000000000000000d000000000000000, type: 0} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/Scripts/Enemies/States/EnemyStateManager.cs b/Assets/Scripts/Enemies/States/EnemyStateManager.cs index 59b497f..f94ba3d 100644 --- a/Assets/Scripts/Enemies/States/EnemyStateManager.cs +++ b/Assets/Scripts/Enemies/States/EnemyStateManager.cs @@ -97,10 +97,10 @@ protected void GenerateDamageFrame(Transform gizmoTrigger, float damage) float hWidth = gizmoTrigger.lossyScale.x/2; float hHeight = gizmoTrigger.lossyScale.y/2; - Debug.DrawLine(new Vector2(center.x - hWidth, center.y + hHeight), new Vector2(center.x + hWidth, center.y + hHeight)); // draw top line - Debug.DrawLine(new Vector2(center.x - hWidth, center.y + hHeight), new Vector2(center.x - hWidth, center.y - hHeight)); // draw left line - Debug.DrawLine(new Vector2(center.x - hWidth, center.y - hHeight), new Vector2(center.x + hWidth, center.y - hHeight)); // draw bottom line - Debug.DrawLine(new Vector2(center.x + hWidth, center.y + hHeight), new Vector2(center.x + hWidth, center.y - hHeight)); // draw right line + Debug.DrawLine(new Vector2(center.x - hWidth, center.y + hHeight), new Vector2(center.x + hWidth, center.y + hHeight), Color.white, 0.2f); // draw top line + Debug.DrawLine(new Vector2(center.x - hWidth, center.y + hHeight), new Vector2(center.x - hWidth, center.y - hHeight), Color.white, 0.2f); // draw left line + Debug.DrawLine(new Vector2(center.x - hWidth, center.y - hHeight), new Vector2(center.x + hWidth, center.y - hHeight), Color.white, 0.2f); // draw bottom line + Debug.DrawLine(new Vector2(center.x + hWidth, center.y + hHeight), new Vector2(center.x + hWidth, center.y - hHeight), Color.white, 0.2f); // draw right line #endif // Check for player to do damage Collider2D hit = Physics2D.OverlapBox(gizmoTrigger.position, gizmoTrigger.lossyScale, 0f, LayerMask.GetMask("Player")); From bfe3849dc616b119ee0262304b811226d2101197 Mon Sep 17 00:00:00 2001 From: Simon Wang <60266027+WangXin1507@users.noreply.github.com> Date: Thu, 26 Dec 2024 18:03:28 -0800 Subject: [PATCH 07/13] Enabled drawing circular damage frame in game view All enemies should now be able to draw their damage frame inside of gameview. Overloaded GenerateDamageFrame() to allow for drawing circular damage frames if needed. --- Assets/Prefabs/Enemies/Roomba/kaboom.anim | 11 ++-- Assets/Scripts/Enemies/CameraDrone.cs | 3 + Assets/Scripts/Enemies/Cyborg.cs | 6 +- Assets/Scripts/Enemies/GunWithLegs.cs | 2 +- Assets/Scripts/Enemies/RiotPolice.cs | 2 +- Assets/Scripts/Enemies/Roomba.cs | 6 +- Assets/Scripts/Enemies/ShieldPolice.cs | 2 +- .../Enemies/States/EnemyStateManager.cs | 59 +++++++++++++++---- 8 files changed, 63 insertions(+), 28 deletions(-) diff --git a/Assets/Prefabs/Enemies/Roomba/kaboom.anim b/Assets/Prefabs/Enemies/Roomba/kaboom.anim index 66070b6..48f093a 100644 --- a/Assets/Prefabs/Enemies/Roomba/kaboom.anim +++ b/Assets/Prefabs/Enemies/Roomba/kaboom.anim @@ -31,7 +31,7 @@ AnimationClip: m_AdditiveReferencePoseClip: {fileID: 0} m_AdditiveReferencePoseTime: 0 m_StartTime: 0 - m_StopTime: 1 + m_StopTime: 1.4166666 m_OrientationOffsetY: 0 m_Level: 0 m_CycleOffset: 0 @@ -51,14 +51,15 @@ AnimationClip: m_HasGenericRootTransform: 0 m_HasMotionFloatCurves: 0 m_Events: - - time: 0.8333333 - functionName: onKaboomEvent + - time: 1 + functionName: OnKaboomEvent data: - objectReferenceParameter: {fileID: 0} + objectReferenceParameter: {fileID: 9100000, guid: 011ef813dd4f8f0438ec0652b18c4b0d, + type: 2} floatParameter: 0 intParameter: 0 messageOptions: 0 - - time: 1 + - time: 1.4166666 functionName: OnFinishAnimation data: objectReferenceParameter: {fileID: 0} diff --git a/Assets/Scripts/Enemies/CameraDrone.cs b/Assets/Scripts/Enemies/CameraDrone.cs index f663a5e..171414d 100644 --- a/Assets/Scripts/Enemies/CameraDrone.cs +++ b/Assets/Scripts/Enemies/CameraDrone.cs @@ -18,6 +18,9 @@ protected override ActionPool GenerateActionPool() protected void OnCallAlarm() { +#if DEBUG + GenerateDamageFrame(alarmTrigger.position, alarmTrigger.lossyScale.x, alarmTrigger.lossyScale.y, 0); +#endif Vector3 dest = transform.position + new Vector3(transform.right.x*transform.lossyScale.x, -transform.lossyScale.y, 0); Instantiate(enemyToSummon, dest, transform.rotation); } diff --git a/Assets/Scripts/Enemies/Cyborg.cs b/Assets/Scripts/Enemies/Cyborg.cs index a0ffae3..2f2344b 100644 --- a/Assets/Scripts/Enemies/Cyborg.cs +++ b/Assets/Scripts/Enemies/Cyborg.cs @@ -32,7 +32,7 @@ protected override ActionPool GenerateActionPool() // Generate damage frame for melee slash attack protected void OnSlashEvent() { - GenerateDamageFrame(meleeTrigger, 1.0f); + GenerateDamageFrame(meleeTrigger.position, meleeTrigger.lossyScale.x, meleeTrigger.lossyScale.y, 1.0f); } // Teleports the cyborg backwards @@ -61,13 +61,13 @@ protected void OnTPForwardEvent1() // Generate damage frame for follow up attack after teleporting forward protected void OnTPForwardEvent2() { - GenerateDamageFrame(tpBackTrigger, 1.0f); + GenerateDamageFrame(tpBackTrigger.position, tpBackTrigger.lossyScale.x, tpBackTrigger.lossyScale.y, 1.0f); } // Generate damage frame for long range stinger attack protected void OnStingerEvent() { - GenerateDamageFrame(stingerHitBox, 1.0f); + GenerateDamageFrame(stingerHitBox.position, stingerHitBox.lossyScale.x, stingerHitBox.lossyScale.y, 1.0f); } protected override void OnFinishAnimation() diff --git a/Assets/Scripts/Enemies/GunWithLegs.cs b/Assets/Scripts/Enemies/GunWithLegs.cs index 62f77b0..75e59c2 100644 --- a/Assets/Scripts/Enemies/GunWithLegs.cs +++ b/Assets/Scripts/Enemies/GunWithLegs.cs @@ -27,7 +27,7 @@ protected override ActionPool GenerateActionPool() // Check for kick collision and do damageg protected void OnKickEvent() { - GenerateDamageFrame(gunKick, 1.0f); + GenerateDamageFrame(gunKick.position, gunKick.lossyScale.x, gunKick.lossyScale.y, 1.0f); } // Instantiate projectile prefab and push self back diff --git a/Assets/Scripts/Enemies/RiotPolice.cs b/Assets/Scripts/Enemies/RiotPolice.cs index 597214a..1e8c14c 100644 --- a/Assets/Scripts/Enemies/RiotPolice.cs +++ b/Assets/Scripts/Enemies/RiotPolice.cs @@ -22,7 +22,7 @@ protected override ActionPool GenerateActionPool() // Check for collision in swing range to deal damage protected void OnBatonEvent() { - GenerateDamageFrame(batonTrigger, 1); + GenerateDamageFrame(batonTrigger.position, batonTrigger.lossyScale.x, batonTrigger.lossyScale.y, 1); } // Draws the Enemy attack range in the editor diff --git a/Assets/Scripts/Enemies/Roomba.cs b/Assets/Scripts/Enemies/Roomba.cs index 41d1ad6..2b6dc79 100644 --- a/Assets/Scripts/Enemies/Roomba.cs +++ b/Assets/Scripts/Enemies/Roomba.cs @@ -22,11 +22,7 @@ protected override ActionPool GenerateActionPool() // Check for player in blast radius and do damage protected void OnKaboomEvent() { - Collider2D hit = Physics2D.OverlapCircle(kaboomTrigger.position, kaboomTrigger.lossyScale.x, LayerMask.GetMask("Player")); - if (hit) - { - hit.GetComponent().TakeDamage(20); - } + GenerateDamageFrame(kaboomTrigger.position, kaboomTrigger.lossyScale.x, 5.0f); } protected override void OnFinishAnimation() diff --git a/Assets/Scripts/Enemies/ShieldPolice.cs b/Assets/Scripts/Enemies/ShieldPolice.cs index 11faa69..4e8101b 100644 --- a/Assets/Scripts/Enemies/ShieldPolice.cs +++ b/Assets/Scripts/Enemies/ShieldPolice.cs @@ -39,7 +39,7 @@ protected override ActionPool GenerateActionPool() // Generate damage frame for baton swing protected void OnBatonEvent() { - GenerateDamageFrame(batonTrigger, 1.0f); + GenerateDamageFrame(batonTrigger.position, batonTrigger.lossyScale.x, batonTrigger.lossyScale.y, 1.0f); } // Ask police to begin charging and enable shield damage diff --git a/Assets/Scripts/Enemies/States/EnemyStateManager.cs b/Assets/Scripts/Enemies/States/EnemyStateManager.cs index f94ba3d..68dfccc 100644 --- a/Assets/Scripts/Enemies/States/EnemyStateManager.cs +++ b/Assets/Scripts/Enemies/States/EnemyStateManager.cs @@ -88,22 +88,57 @@ public void Flip(bool isFlipped) /// /// Do damage to player if they are inside of trigger box /// - /// Transform component for drawing damage box + /// Position of the trigger box + /// X value of the lossyscale of the trigger box + /// Y value of the lossyscale of the trigger box /// Points of damage to deal - protected void GenerateDamageFrame(Transform gizmoTrigger, float damage) + protected void GenerateDamageFrame(Vector2 pos, float width, float height, float damage) { -#if DEBUG // Draw the damage box in the editor - Vector2 center = gizmoTrigger.position; - float hWidth = gizmoTrigger.lossyScale.x/2; - float hHeight = gizmoTrigger.lossyScale.y/2; - - Debug.DrawLine(new Vector2(center.x - hWidth, center.y + hHeight), new Vector2(center.x + hWidth, center.y + hHeight), Color.white, 0.2f); // draw top line - Debug.DrawLine(new Vector2(center.x - hWidth, center.y + hHeight), new Vector2(center.x - hWidth, center.y - hHeight), Color.white, 0.2f); // draw left line - Debug.DrawLine(new Vector2(center.x - hWidth, center.y - hHeight), new Vector2(center.x + hWidth, center.y - hHeight), Color.white, 0.2f); // draw bottom line - Debug.DrawLine(new Vector2(center.x + hWidth, center.y + hHeight), new Vector2(center.x + hWidth, center.y - hHeight), Color.white, 0.2f); // draw right line +#if DEBUG // Draw the damage box in the editor + float hWidth = width/2; + float hHeight = height/2; + float duration = 0.2f; + + Debug.DrawLine(new Vector2(pos.x - hWidth, pos.y + hHeight), new Vector2(pos.x + hWidth, pos.y + hHeight), Color.white, duration); // draw top line + Debug.DrawLine(new Vector2(pos.x - hWidth, pos.y + hHeight), new Vector2(pos.x - hWidth, pos.y - hHeight), Color.white, duration); // draw left line + Debug.DrawLine(new Vector2(pos.x - hWidth, pos.y - hHeight), new Vector2(pos.x + hWidth, pos.y - hHeight), Color.white, duration); // draw bottom line + Debug.DrawLine(new Vector2(pos.x + hWidth, pos.y + hHeight), new Vector2(pos.x + hWidth, pos.y - hHeight), Color.white, duration); // draw right line +#endif + // Check for player to do damage + Collider2D hit = Physics2D.OverlapBox(pos, new Vector2(width, height), 0f, LayerMask.GetMask("Player")); + if (hit) + { + hit.GetComponent().TakeDamage(damage); + } + } + + /// + /// Do damage to player if they are inside of trigger circle + /// + /// Position of the trigger box + /// X value of the lossyscale of the trigger circle + /// Points of damage to deal + protected void GenerateDamageFrame(Vector2 pos, float radius, float damage) + { +#if DEBUG // Draw the damage circle in the editor + int segment = 180; + float duration = 0.2f; + + float angleDiv = 360f / segment; + Vector2 p1 = new Vector2(pos.x + radius, pos.y); + Vector2 p2; + + for (int i = 0; i < segment; i++) + { + float angle = angleDiv * i * Mathf.Deg2Rad; + p2 = new Vector2(pos.x + Mathf.Cos(angle) * radius, pos.y + Mathf.Sin(angle) * radius); + + Debug.DrawLine(p1, p2, Color.white, duration); + p1 = p2; + } #endif // Check for player to do damage - Collider2D hit = Physics2D.OverlapBox(gizmoTrigger.position, gizmoTrigger.lossyScale, 0f, LayerMask.GetMask("Player")); + Collider2D hit = Physics2D.OverlapCircle(pos, radius, LayerMask.GetMask("Player")); if (hit) { hit.GetComponent().TakeDamage(damage); From 642560752f63cd7174c22430ef2de93e13ecc744 Mon Sep 17 00:00:00 2001 From: Simon Wang <60266027+WangXin1507@users.noreply.github.com> Date: Fri, 27 Dec 2024 13:04:37 -0800 Subject: [PATCH 08/13] Serialized ActionPool for Riot Police Actions for the riot police is now defined in the editor --- .../Enemies/Riot Police/RiotPolice.prefab | 35 +++++++++++++++ Assets/Scripts/Enemies/CameraDrone.cs | 17 +++++--- Assets/Scripts/Enemies/Cyborg.cs | 20 ++++----- .../Enemies/Dummy Enemy/DummyStates.cs | 24 +++++------ Assets/Scripts/Enemies/GunWithLegs.cs | 18 ++++---- Assets/Scripts/Enemies/RiotPolice.cs | 14 +++--- Assets/Scripts/Enemies/Roomba.cs | 14 +++--- Assets/Scripts/Enemies/ShieldPolice.cs | 16 +++---- Assets/Scripts/Enemies/States/Action.cs | 43 ++++++++++--------- Assets/Scripts/Enemies/States/ActionPool.cs | 31 +++++++------ .../Enemies/States/EnemyStateManager.cs | 4 +- .../Enemies/States/GreedyActionPool.cs | 4 +- 12 files changed, 143 insertions(+), 97 deletions(-) diff --git a/Assets/Prefabs/Enemies/Riot Police/RiotPolice.prefab b/Assets/Prefabs/Enemies/Riot Police/RiotPolice.prefab index d0a9236..cc110ab 100644 --- a/Assets/Prefabs/Enemies/Riot Police/RiotPolice.prefab +++ b/Assets/Prefabs/Enemies/Riot Police/RiotPolice.prefab @@ -46,6 +46,7 @@ GameObject: - component: {fileID: 5267342110057752590} - component: {fileID: 2197548027611747354} - component: {fileID: 9121469439051838776} + - component: {fileID: 628772375253420757} m_Layer: 21 m_Name: RiotPolice m_TagString: Untagged @@ -227,6 +228,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: stats: {fileID: 0} + pool: {fileID: 0} animator: {fileID: 8056966106870366120} aggroRange: 7.33 batonTrigger: {fileID: 3561678645181035360} @@ -249,3 +251,36 @@ MonoBehaviour: - name: Max Health value: 1 modifier: 100 +--- !u!114 &628772375253420757 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1393067818931581941} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 872d96247465fd541bea93e36537b26f, type: 3} + m_Name: + m_EditorClassIdentifier: + actions: + - name: Baton Swing + ready: 0 + hitBox: {fileID: 3561678645181035360} + maxCoolDown: 2 + priority: 1 + animationClip: {fileID: 7400000, guid: f612aa8e9cc4b4a488df5b9e1c8237d2, type: 2} + move: + name: + ready: 0 + hitBox: {fileID: 0} + maxCoolDown: 0 + priority: 0 + animationClip: {fileID: 7400000, guid: e1d9f2c18293436429c8a1403b4ada95, type: 2} + idle: + name: + ready: 0 + hitBox: {fileID: 0} + maxCoolDown: 0 + priority: 0 + animationClip: {fileID: 7400000, guid: 968e5750ed810fb418cf0add49c4620a, type: 2} diff --git a/Assets/Scripts/Enemies/CameraDrone.cs b/Assets/Scripts/Enemies/CameraDrone.cs index 171414d..9581dc6 100644 --- a/Assets/Scripts/Enemies/CameraDrone.cs +++ b/Assets/Scripts/Enemies/CameraDrone.cs @@ -6,16 +6,19 @@ public class CameraDrone : EnemyStateManager { [SerializeField] protected Transform alarmTrigger; [SerializeField] protected GameObject enemyToSummon; - protected override ActionPool GenerateActionPool() - { - Action callAlarm = new(alarmTrigger, 5.0f, 1f, "Call Alarm"); + //protected override ActionPool GenerateActionPool() + //{ + // Action callAlarm = new(alarmTrigger, 5.0f, 1f, "Call Alarm"); - Action move = new(null, 0.0f, 0.0f, "move"); - Action idle = new(null, 0.0f, 0.0f, "idle"); + // Action move = new(null, 0.0f, 0.0f, "move"); + // Action idle = new(null, 0.0f, 0.0f, "idle"); - return new ActionPool(new List { callAlarm }, move, idle); - } + // return new ActionPool(new List { callAlarm }, move, idle); + //} + /// + /// Summons an enemy + /// protected void OnCallAlarm() { #if DEBUG diff --git a/Assets/Scripts/Enemies/Cyborg.cs b/Assets/Scripts/Enemies/Cyborg.cs index 2f2344b..db53253 100644 --- a/Assets/Scripts/Enemies/Cyborg.cs +++ b/Assets/Scripts/Enemies/Cyborg.cs @@ -16,18 +16,18 @@ public class Cyborg : EnemyStateManager [SerializeField] protected Transform stingerHitBox; // Area in which the stinger attack will do damage // Cybor will draw actions greedily - protected override ActionPool GenerateActionPool() - { - Action cyborgSlash = new(meleeTrigger, 0.0f, 7f, "Cyborg Slash"); - Action cyborgBack = new(tpBackTrigger, 7.0f, 1f, "TP Back"); - Action cyborgForward = new(tpForwardTrigger, 18.0f, 5f, "TP Forward"); - Action cyborgStinger = new(stingerTrigger, 4.0f, 1f, "Cyborg Stinger"); + //protected override ActionPool GenerateActionPool() + //{ + // Action cyborgSlash = new(meleeTrigger, 0.0f, 7f, "Cyborg Slash"); + // Action cyborgBack = new(tpBackTrigger, 7.0f, 1f, "TP Back"); + // Action cyborgForward = new(tpForwardTrigger, 18.0f, 5f, "TP Forward"); + // Action cyborgStinger = new(stingerTrigger, 4.0f, 1f, "Cyborg Stinger"); - Action move = new(null, 0.0f, 0.0f, "move"); - Action idle = new(null, 0.0f, 0.0f, "idle"); + // Action move = new(null, 0.0f, 0.0f, "move"); + // Action idle = new(null, 0.0f, 0.0f, "idle"); - return new GreedyActionPool(new List { cyborgSlash, cyborgBack, cyborgForward, cyborgStinger }, move, idle); - } + // return new GreedyActionPool(new List { cyborgSlash, cyborgBack, cyborgForward, cyborgStinger }, move, idle); + //} // Generate damage frame for melee slash attack protected void OnSlashEvent() diff --git a/Assets/Scripts/Enemies/Dummy Enemy/DummyStates.cs b/Assets/Scripts/Enemies/Dummy Enemy/DummyStates.cs index 14dc7b1..326152d 100644 --- a/Assets/Scripts/Enemies/Dummy Enemy/DummyStates.cs +++ b/Assets/Scripts/Enemies/Dummy Enemy/DummyStates.cs @@ -22,21 +22,21 @@ public class DummyStates : EnemyStateManager, IDamageable public GameObject projectile; // Dummy Enemy's all possible actions - protected override ActionPool GenerateActionPool() - { - // Declare the Enemy's attacks - Action dummySlash = new(meleeTrigger, 4.0f, 3f, "HeroKnight_Attack1"); - Action dummyShoot = new(rangeTrigger, 4.0f, 7f, "Dummy_Shoot"); + //protected override ActionPool GenerateActionPool() + //{ + // // Declare the Enemy's attacks + // Action dummySlash = new(meleeTrigger, 4.0f, 3f, "HeroKnight_Attack1"); + // Action dummyShoot = new(rangeTrigger, 4.0f, 7f, "Dummy_Shoot"); - // Most Enemy should also add their Run and Idle animations to the ActionPool - Action move = new(null, 0.0f, 0.0f, "HeroKnight_Run"); - Action idle = new(null, 0.0f, 0.0f, "HeroKnight_Idle"); + // // Most Enemy should also add their Run and Idle animations to the ActionPool + // Action move = new(null, 0.0f, 0.0f, "HeroKnight_Run"); + // Action idle = new(null, 0.0f, 0.0f, "HeroKnight_Idle"); - //Future stunned state --> Stun Hit (NOT IMPLEMENTED YET) - Action stunned = new(null, 0.0f, 0.0f, "HeroKnight_Idle"); + // //Future stunned state --> Stun Hit (NOT IMPLEMENTED YET) + // Action stunned = new(null, 0.0f, 0.0f, "HeroKnight_Idle"); - return new ActionPool(new List { dummySlash, dummyShoot }, move, idle); - } + // return new ActionPool(new List { dummySlash, dummyShoot }, move, idle); + //} void Start() { diff --git a/Assets/Scripts/Enemies/GunWithLegs.cs b/Assets/Scripts/Enemies/GunWithLegs.cs index 75e59c2..bdcaf69 100644 --- a/Assets/Scripts/Enemies/GunWithLegs.cs +++ b/Assets/Scripts/Enemies/GunWithLegs.cs @@ -13,18 +13,18 @@ public class GunWithLegs : EnemyStateManager [SerializeField] protected Transform projectile; - protected override ActionPool GenerateActionPool() - { - Action kick = new(gunKick, 4.0f, 3f, "Gun_W_Leg_Kick"); - Action shoot = new(gunShoot, 4.0f, 7f, "Gun_W_Leg_Shoot"); + //protected override ActionPool GenerateActionPool() + //{ + // Action kick = new(gunKick, 4.0f, 3f, "Gun_W_Leg_Kick"); + // Action shoot = new(gunShoot, 4.0f, 7f, "Gun_W_Leg_Shoot"); - Action move = new(null, 0.0f, 0.0f, "move"); - Action idle = new(null, 0.0f, 0.0f, "idle"); + // Action move = new(null, 0.0f, 0.0f, "move"); + // Action idle = new(null, 0.0f, 0.0f, "idle"); - return new ActionPool(new List { kick, shoot }, move, idle); - } + // return new ActionPool(new List { kick, shoot }, move, idle); + //} - // Check for kick collision and do damageg + // Check for kick collision and do damage protected void OnKickEvent() { GenerateDamageFrame(gunKick.position, gunKick.lossyScale.x, gunKick.lossyScale.y, 1.0f); diff --git a/Assets/Scripts/Enemies/RiotPolice.cs b/Assets/Scripts/Enemies/RiotPolice.cs index 1e8c14c..8ad2218 100644 --- a/Assets/Scripts/Enemies/RiotPolice.cs +++ b/Assets/Scripts/Enemies/RiotPolice.cs @@ -9,15 +9,15 @@ public class RiotPolice : EnemyStateManager { [SerializeField] protected Transform batonTrigger; - protected override ActionPool GenerateActionPool() - { - Action batonSwing = new(batonTrigger, 2.0f, 1f, "Riot_Police_Swing"); + //protected override ActionPool GenerateActionPool() + //{ + // Action batonSwing = new(batonTrigger, 2.0f, 1f, "Riot_Police_Swing"); - Action move = new(null, 0.0f, 0.0f, "Riot_Police_Run"); - Action idle = new(null, 0.0f, 0.0f, "Riot_Police_Idle"); + // Action move = new(null, 0.0f, 0.0f, "Riot_Police_Run"); + // Action idle = new(null, 0.0f, 0.0f, "Riot_Police_Idle"); - return new ActionPool(new List { batonSwing }, move, idle); - } + // return new ActionPool(new List { batonSwing }, move, idle); + //} // Check for collision in swing range to deal damage protected void OnBatonEvent() diff --git a/Assets/Scripts/Enemies/Roomba.cs b/Assets/Scripts/Enemies/Roomba.cs index 2b6dc79..dfe00e9 100644 --- a/Assets/Scripts/Enemies/Roomba.cs +++ b/Assets/Scripts/Enemies/Roomba.cs @@ -9,15 +9,15 @@ public class Roomba : EnemyStateManager { [SerializeField] protected Transform kaboomTrigger; - protected override ActionPool GenerateActionPool() - { - Action kaboom = new(kaboomTrigger, 0.0f, 1f, "kaboom"); + //protected override ActionPool GenerateActionPool() + //{ + // Action kaboom = new(kaboomTrigger, 0.0f, 1f, "kaboom"); - Action move = new(null, 0.0f, 0.0f, "move"); - Action idle = new(null, 0.0f, 0.0f, "idle"); + // Action move = new(null, 0.0f, 0.0f, "move"); + // Action idle = new(null, 0.0f, 0.0f, "idle"); - return new ActionPool(new List { kaboom }, move, idle); - } + // return new ActionPool(new List { kaboom }, move, idle); + //} // Check for player in blast radius and do damage protected void OnKaboomEvent() diff --git a/Assets/Scripts/Enemies/ShieldPolice.cs b/Assets/Scripts/Enemies/ShieldPolice.cs index 4e8101b..a50e957 100644 --- a/Assets/Scripts/Enemies/ShieldPolice.cs +++ b/Assets/Scripts/Enemies/ShieldPolice.cs @@ -25,16 +25,16 @@ void Update() } // Shielded Police will draw actions greedily - protected override ActionPool GenerateActionPool() - { - Action batonSwing = new(batonTrigger, 0.0f, 3f, "Shield_Police_Swing"); - Action shieldCharge = new(chargeTrigger, 10.0f, 3f, "Shield_Police_Charge_1"); + //protected override ActionPool GenerateActionPool() + //{ + // Action batonSwing = new(batonTrigger, 0.0f, 3f, "Shield_Police_Swing"); + // Action shieldCharge = new(chargeTrigger, 10.0f, 3f, "Shield_Police_Charge_1"); - Action move = new(null, 0.0f, 0.0f, "Shield_Police_Run"); - Action idle = new(null, 0.0f, 0.0f, "Shield_Police_Idle"); + // Action move = new(null, 0.0f, 0.0f, "Shield_Police_Run"); + // Action idle = new(null, 0.0f, 0.0f, "Shield_Police_Idle"); - return new GreedyActionPool(new List { batonSwing, shieldCharge }, move, idle); - } + // return new GreedyActionPool(new List { batonSwing, shieldCharge }, move, idle); + //} // Generate damage frame for baton swing protected void OnBatonEvent() diff --git a/Assets/Scripts/Enemies/States/Action.cs b/Assets/Scripts/Enemies/States/Action.cs index ba2afe0..dafbcaf 100644 --- a/Assets/Scripts/Enemies/States/Action.cs +++ b/Assets/Scripts/Enemies/States/Action.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; @@ -7,30 +8,30 @@ /// /// An Action that an Enemy can take /// +[Serializable] public class Action { - public bool ready = true; // Could change later so certain actions may not be immediately accessible at the start of encounter + [SerializeField] private string name; + [SerializeField] private Transform hitBox; // The area in which if a player is inside, the action will be performed + [SerializeField] private float coolDown; + [SerializeField] private AnimationClip animationClip; + public float priority; + public bool ready = true; - private Transform hitBox; - private float maxCD; - private float coolDown; - private float priority; - private string anim; - /// /// Constructs an Action for a particular Enemy /// - /// Range of the Action + /// The area in which if a player is inside, the action will be performed /// Length of the Action's cool down - /// Tendancy to do this Action (1-10) + /// Tendency to do this Action (1-10) /// Name of the animation to be played - public Action(Transform hitBox, float coolDown, float priority, string anim) + public Action(Transform hitBox, float coolDown, float priority, AnimationClip anim) { this.hitBox = hitBox; - this.maxCD = coolDown; - this.coolDown = 0; + this.coolDown = coolDown; this.priority = priority; - this.anim = anim; + this.animationClip = anim; + this.ready = true; } /// @@ -40,7 +41,8 @@ public Action(Transform hitBox, float coolDown, float priority, string anim) /// Optional transition duration for the animation public void Play(Animator animator, float fadeDuration = 0.2f) { - animator.CrossFade(anim, fadeDuration); + Debug.Log(animationClip.name + " is " + ready); + animator.CrossFade(animationClip.name, fadeDuration); DoCoolDown(); } @@ -53,17 +55,15 @@ public virtual bool InAttackRange() return Physics2D.OverlapBox(hitBox.position, hitBox.lossyScale, 0f, LayerMask.GetMask("Player")); } - /// - /// Resets the Action's cooldown - /// - public void ResetCD() + public float GetPriority() { - coolDown = maxCD; + return this.priority; } - public float GetPriority() + public bool IsReady() { - return this.priority; + Debug.Log(name + " ready is " + ready); + return ready; } /// @@ -74,5 +74,6 @@ private async Task DoCoolDown() ready = false; await Task.Delay((int)(coolDown * 1000)); ready = true; + Debug.Log(name + " has finished cooldown "); } } diff --git a/Assets/Scripts/Enemies/States/ActionPool.cs b/Assets/Scripts/Enemies/States/ActionPool.cs index e31b88e..c5356d7 100644 --- a/Assets/Scripts/Enemies/States/ActionPool.cs +++ b/Assets/Scripts/Enemies/States/ActionPool.cs @@ -10,14 +10,21 @@ /// A list of possible Actions an Enemy can take. /// An Action Pool is used to randomly output an avaliable action. /// -public class ActionPool +public class ActionPool : MonoBehaviour { - protected List actions; + [SerializeField] protected List actions; public Action move; public Action idle; - + private float curWeight = 0f; - private System.Random random = new System.Random(); + + void Start() + { + foreach (Action a in actions) + { + a.ready = true; // default each action is ready on start, subject to change + } + } /// /// Constructs a new Action Pool @@ -25,12 +32,12 @@ public class ActionPool /// List of Attack Actions /// Action containing moving animation /// Action containing idling animation - public ActionPool(List actions, Action move, Action idle) - { - this.actions = actions; - this.move = move; - this.idle = idle; - } + // public ActionPool(List actions, Action move, Action idle) + //{ + // this.actions = actions; + // this.move = move; + // this.idle = idle; + //} /// /// Choose an action randomly out of all the currently avaliable actions @@ -46,7 +53,7 @@ public Action NextAction() } Action nextAction = avaliableActions[0]; - double r = random.NextDouble(); + double r = Random.value; foreach (Action action in avaliableActions) { r -= action.GetPriority() / curWeight; @@ -82,7 +89,7 @@ private List GetAvaliableActions() List avaliableActions = new List(); foreach (Action a in actions) { - if (a.InAttackRange() & a.ready) + if (a.InAttackRange() & a.IsReady()) { avaliableActions.Add(a); curWeight += a.GetPriority(); diff --git a/Assets/Scripts/Enemies/States/EnemyStateManager.cs b/Assets/Scripts/Enemies/States/EnemyStateManager.cs index 68dfccc..ca22c99 100644 --- a/Assets/Scripts/Enemies/States/EnemyStateManager.cs +++ b/Assets/Scripts/Enemies/States/EnemyStateManager.cs @@ -29,7 +29,7 @@ protected virtual void Awake() stats = GetComponent(); animator = GetComponent(); rb = GetComponent(); - pool = GenerateActionPool(); + pool = GetComponent(); SwitchState(IdleState); } @@ -97,7 +97,7 @@ protected void GenerateDamageFrame(Vector2 pos, float width, float height, float #if DEBUG // Draw the damage box in the editor float hWidth = width/2; float hHeight = height/2; - float duration = 0.2f; + float duration = 0.1f; Debug.DrawLine(new Vector2(pos.x - hWidth, pos.y + hHeight), new Vector2(pos.x + hWidth, pos.y + hHeight), Color.white, duration); // draw top line Debug.DrawLine(new Vector2(pos.x - hWidth, pos.y + hHeight), new Vector2(pos.x - hWidth, pos.y - hHeight), Color.white, duration); // draw left line diff --git a/Assets/Scripts/Enemies/States/GreedyActionPool.cs b/Assets/Scripts/Enemies/States/GreedyActionPool.cs index b91a558..fc510de 100644 --- a/Assets/Scripts/Enemies/States/GreedyActionPool.cs +++ b/Assets/Scripts/Enemies/States/GreedyActionPool.cs @@ -11,14 +11,14 @@ public class GreedyActionPool : ActionPool // It is strongly recomended for an enemy implmenting this AI to have an attack that is: // 1. Have no cool down. // 2. Can reach the player even if they are really close (e.g. melee) - public GreedyActionPool(List actions, Action move, Action idle) : base(actions, move, idle) { } + //public GreedyActionPool(List actions, Action move, Action idle) : base(actions, move, idle) { } // Check if an action exists that both can reach the player and is not under cool down. public override bool HasActionsReady() { foreach (Action a in actions) { - if (a.ready & a.InAttackRange()) + if (a.IsReady() & a.InAttackRange()) { return true; } From 78a0a8404c19fe43b98ac30319310cdf9ad9e6c2 Mon Sep 17 00:00:00 2001 From: Simon Wang <60266027+WangXin1507@users.noreply.github.com> Date: Fri, 27 Dec 2024 17:32:03 -0800 Subject: [PATCH 09/13] Serialized the ActionPool for each enemy prefab --- .../Enemies/Camera Drone/Camera Drone.prefab | 52 ++++++++++++------ Assets/Prefabs/Enemies/Cyborg/Cyborg.prefab | 53 +++++++++++++++++++ Assets/Prefabs/Enemies/G.R.E.G/G.R.E.G.prefab | 41 ++++++++++++++ Assets/Prefabs/Enemies/Roomba/Roomba.prefab | 35 ++++++++++++ .../Enemies/Shield Police/ShieldPolice.prefab | 41 ++++++++++++++ Assets/Scripts/Enemies/States/Action.cs | 5 +- Assets/Scripts/Enemies/States/ActionPool.cs | 43 ++++++--------- .../Enemies/States/GreedyActionPool.cs | 5 -- 8 files changed, 221 insertions(+), 54 deletions(-) diff --git a/Assets/Prefabs/Enemies/Camera Drone/Camera Drone.prefab b/Assets/Prefabs/Enemies/Camera Drone/Camera Drone.prefab index cee662d..cbe1fce 100644 --- a/Assets/Prefabs/Enemies/Camera Drone/Camera Drone.prefab +++ b/Assets/Prefabs/Enemies/Camera Drone/Camera Drone.prefab @@ -45,9 +45,9 @@ GameObject: - component: {fileID: 1467948147633493128} - component: {fileID: 1603849808541719507} - component: {fileID: 3602954514945515610} - - component: {fileID: 7679382285400612018} - component: {fileID: 7321790019576285446} - component: {fileID: 8856570929518799469} + - component: {fileID: 3715663957954540872} m_Layer: 21 m_Name: Camera Drone m_TagString: Untagged @@ -229,27 +229,12 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: stats: {fileID: 0} + pool: {fileID: 0} animator: {fileID: 6400381198355053387} aggroRange: 16.76 alarmTrigger: {fileID: 7775618551989780944} enemyToSummon: {fileID: 2119936537419083514, guid: 0fedb38f283d38a4faca7620ea8ae537, type: 3} ---- !u!114 &7679382285400612018 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 8652318323731026824} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 532320b84239cf640a651fa5709b989a, type: 3} - m_Name: - m_EditorClassIdentifier: - stats: - - name: Max Health - value: 10 - modifier: 100 --- !u!114 &7321790019576285446 MonoBehaviour: m_ObjectHideFlags: 0 @@ -283,3 +268,36 @@ MonoBehaviour: - name: Max Health value: 1 modifier: 100 +--- !u!114 &3715663957954540872 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8652318323731026824} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 872d96247465fd541bea93e36537b26f, type: 3} + m_Name: + m_EditorClassIdentifier: + actions: + - name: Call Alarm + hitBox: {fileID: 7775618551989780944} + coolDown: 5 + animationClip: {fileID: 7400000, guid: 6be99b37274953c40b797d9e1744a2a7, type: 2} + priority: 1 + ready: 0 + move: + name: Move + hitBox: {fileID: 0} + coolDown: 0 + animationClip: {fileID: 7400000, guid: 4739459637a37884c8ebb6a3ce1e90ce, type: 2} + priority: 0 + ready: 0 + idle: + name: + hitBox: {fileID: 0} + coolDown: 0 + animationClip: {fileID: 7400000, guid: 468a49c330cf0294486adcfa8c854b6e, type: 2} + priority: 0 + ready: 0 diff --git a/Assets/Prefabs/Enemies/Cyborg/Cyborg.prefab b/Assets/Prefabs/Enemies/Cyborg/Cyborg.prefab index 31ce3f2..ba0470a 100644 --- a/Assets/Prefabs/Enemies/Cyborg/Cyborg.prefab +++ b/Assets/Prefabs/Enemies/Cyborg/Cyborg.prefab @@ -78,6 +78,7 @@ GameObject: - component: {fileID: 953836412094399138} - component: {fileID: 8868405178309692734} - component: {fileID: 8480991602502054467} + - component: {fileID: 7261880397543917784} m_Layer: 21 m_Name: Cyborg m_TagString: Untagged @@ -263,6 +264,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: stats: {fileID: 0} + pool: {fileID: 0} animator: {fileID: 7905894014490810442} aggroRange: 18.6 meleeTrigger: {fileID: 2358971396437510415} @@ -303,6 +305,57 @@ MonoBehaviour: m_EditorClassIdentifier: health: 0 isAlive: 1 +--- !u!114 &7261880397543917784 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2119936537419083514} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 20d794b3ea5a6da42ac5b8feade20f68, type: 3} + m_Name: + m_EditorClassIdentifier: + actions: + - name: Slash + hitBox: {fileID: 2358971396437510415} + coolDown: 0 + animationClip: {fileID: 7400000, guid: d69a7e64e120bf14a9aa1e57c15eeb6a, type: 2} + priority: 7 + ready: 0 + - name: Teleport Backwards + hitBox: {fileID: 1365265030456903513} + coolDown: 7 + animationClip: {fileID: 7400000, guid: a5a8d9d16988a1f499f24e6107fe9dff, type: 2} + priority: 1 + ready: 0 + - name: Teleport Forwards + hitBox: {fileID: 3423477219027819224} + coolDown: 18 + animationClip: {fileID: 7400000, guid: 012a586afaa024e44ab554a7584bd561, type: 2} + priority: 5 + ready: 0 + - name: Stinger Attack + hitBox: {fileID: 6623908715604477131} + coolDown: 4 + animationClip: {fileID: 7400000, guid: 1414bb1595d35334baa24da1ab98026c, type: 2} + priority: 2 + ready: 0 + move: + name: Move + hitBox: {fileID: 0} + coolDown: 0 + animationClip: {fileID: 7400000, guid: 106e624640ffb024a911166cfd9df3ac, type: 2} + priority: 0 + ready: 0 + idle: + name: Idle + hitBox: {fileID: 0} + coolDown: 0 + animationClip: {fileID: 7400000, guid: d9b9bb522aca7c043b7f8568e51360fa, type: 2} + priority: 0 + ready: 0 --- !u!1 &2960955476441126688 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/Enemies/G.R.E.G/G.R.E.G.prefab b/Assets/Prefabs/Enemies/G.R.E.G/G.R.E.G.prefab index b371c9f..7b17d86 100644 --- a/Assets/Prefabs/Enemies/G.R.E.G/G.R.E.G.prefab +++ b/Assets/Prefabs/Enemies/G.R.E.G/G.R.E.G.prefab @@ -108,6 +108,7 @@ GameObject: - component: {fileID: 166145500235385066} - component: {fileID: 8152285351237874372} - component: {fileID: 3440705048582449508} + - component: {fileID: 310345646144262094} m_Layer: 21 m_Name: G.R.E.G m_TagString: Untagged @@ -291,6 +292,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: stats: {fileID: 0} + pool: {fileID: 0} animator: {fileID: 166145500235385066} aggroRange: 9.92 gunKick: {fileID: 8875514496581505741} @@ -317,3 +319,42 @@ MonoBehaviour: - name: Max Health value: 1 modifier: 100 +--- !u!114 &310345646144262094 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8433722653154054174} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 872d96247465fd541bea93e36537b26f, type: 3} + m_Name: + m_EditorClassIdentifier: + actions: + - name: Kick + hitBox: {fileID: 8875514496581505741} + coolDown: 4 + animationClip: {fileID: 7400000, guid: 8c897a8a0dede6440a96aac7136b23fc, type: 2} + priority: 7 + ready: 0 + - name: Shoot + hitBox: {fileID: 6754032986899484797} + coolDown: 4 + animationClip: {fileID: 7400000, guid: e06dacd5cab3a6349968796d2cef56de, type: 2} + priority: 3 + ready: 0 + move: + name: Move + hitBox: {fileID: 0} + coolDown: 0 + animationClip: {fileID: 7400000, guid: 50188f8587fb1d944acdb9fdcc0b1425, type: 2} + priority: 0 + ready: 0 + idle: + name: Idle + hitBox: {fileID: 0} + coolDown: 0 + animationClip: {fileID: 7400000, guid: ff1895b71cbdcc8408401395813d5733, type: 2} + priority: 0 + ready: 0 diff --git a/Assets/Prefabs/Enemies/Roomba/Roomba.prefab b/Assets/Prefabs/Enemies/Roomba/Roomba.prefab index 7077249..afa66b1 100644 --- a/Assets/Prefabs/Enemies/Roomba/Roomba.prefab +++ b/Assets/Prefabs/Enemies/Roomba/Roomba.prefab @@ -15,6 +15,7 @@ GameObject: - component: {fileID: 5620131887818746087} - component: {fileID: 4950017548320773108} - component: {fileID: -4750325557521470314} + - component: {fileID: 8922106226278131008} m_Layer: 21 m_Name: Roomba m_TagString: Untagged @@ -196,6 +197,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: stats: {fileID: 0} + pool: {fileID: 0} animator: {fileID: 6971829175617292507} aggroRange: 7.76 kaboomTrigger: {fileID: 2932781976428712665} @@ -218,6 +220,39 @@ MonoBehaviour: - name: Max Health value: 1 modifier: 100 +--- !u!114 &8922106226278131008 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1487853512614266132} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 872d96247465fd541bea93e36537b26f, type: 3} + m_Name: + m_EditorClassIdentifier: + actions: + - name: Kaboom + hitBox: {fileID: 2932781976428712665} + coolDown: 0 + animationClip: {fileID: 7400000, guid: 92ad5adfcb80c584282d7d47fcaf3fdd, type: 2} + priority: 1 + ready: 0 + move: + name: Move + hitBox: {fileID: 0} + coolDown: 0 + animationClip: {fileID: 7400000, guid: b9d7f051e662c1a4194355e44cb4b865, type: 2} + priority: 0 + ready: 0 + idle: + name: Idle + hitBox: {fileID: 0} + coolDown: 0 + animationClip: {fileID: 7400000, guid: fac5a37b0d3e17043920d1176804a9d1, type: 2} + priority: 0 + ready: 0 --- !u!1 &4301427481350538189 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/Enemies/Shield Police/ShieldPolice.prefab b/Assets/Prefabs/Enemies/Shield Police/ShieldPolice.prefab index ccf8a54..a524327 100644 --- a/Assets/Prefabs/Enemies/Shield Police/ShieldPolice.prefab +++ b/Assets/Prefabs/Enemies/Shield Police/ShieldPolice.prefab @@ -197,6 +197,7 @@ GameObject: - component: {fileID: 2153542378424773396} - component: {fileID: 6887818589130474418} - component: {fileID: 783357568447536721} + - component: {fileID: 8825911081079385304} m_Layer: 21 m_Name: ShieldPolice m_TagString: Untagged @@ -380,6 +381,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: stats: {fileID: 0} + pool: {fileID: 0} animator: {fileID: 9133294469049910592} aggroRange: 9.32 batonTrigger: {fileID: 7835333299776145468} @@ -437,3 +439,42 @@ MonoBehaviour: m_EditorClassIdentifier: health: 0 isAlive: 1 +--- !u!114 &8825911081079385304 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5499330591125181409} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 20d794b3ea5a6da42ac5b8feade20f68, type: 3} + m_Name: + m_EditorClassIdentifier: + actions: + - name: Baton Swing + hitBox: {fileID: 7835333299776145468} + coolDown: 0 + animationClip: {fileID: 7400000, guid: e1d9d9dad2b0cbc459e43540f42e4eb2, type: 2} + priority: 3 + ready: 0 + - name: Shield Charge + hitBox: {fileID: 7835333299776145468} + coolDown: 10 + animationClip: {fileID: 7400000, guid: eb1df1c681087954eb5856c1fc5b1ac6, type: 2} + priority: 3 + ready: 0 + move: + name: Move + hitBox: {fileID: 0} + coolDown: 0 + animationClip: {fileID: 7400000, guid: ba7699e38c76f1d4795bcb3af0b15454, type: 2} + priority: 0 + ready: 0 + idle: + name: Idle + hitBox: {fileID: 0} + coolDown: 0 + animationClip: {fileID: 7400000, guid: bc4a8229d1d0f3244bdb56bfc380f945, type: 2} + priority: 0 + ready: 0 diff --git a/Assets/Scripts/Enemies/States/Action.cs b/Assets/Scripts/Enemies/States/Action.cs index dafbcaf..b1dc7d3 100644 --- a/Assets/Scripts/Enemies/States/Action.cs +++ b/Assets/Scripts/Enemies/States/Action.cs @@ -11,7 +11,7 @@ [Serializable] public class Action { - [SerializeField] private string name; + [SerializeField] public string name; [SerializeField] private Transform hitBox; // The area in which if a player is inside, the action will be performed [SerializeField] private float coolDown; [SerializeField] private AnimationClip animationClip; @@ -41,7 +41,6 @@ public Action(Transform hitBox, float coolDown, float priority, AnimationClip an /// Optional transition duration for the animation public void Play(Animator animator, float fadeDuration = 0.2f) { - Debug.Log(animationClip.name + " is " + ready); animator.CrossFade(animationClip.name, fadeDuration); DoCoolDown(); } @@ -62,7 +61,6 @@ public float GetPriority() public bool IsReady() { - Debug.Log(name + " ready is " + ready); return ready; } @@ -74,6 +72,5 @@ private async Task DoCoolDown() ready = false; await Task.Delay((int)(coolDown * 1000)); ready = true; - Debug.Log(name + " has finished cooldown "); } } diff --git a/Assets/Scripts/Enemies/States/ActionPool.cs b/Assets/Scripts/Enemies/States/ActionPool.cs index c5356d7..8ee87e9 100644 --- a/Assets/Scripts/Enemies/States/ActionPool.cs +++ b/Assets/Scripts/Enemies/States/ActionPool.cs @@ -8,7 +8,7 @@ /// /// A list of possible Actions an Enemy can take. -/// An Action Pool is used to randomly output an avaliable action. +/// An Action Pool is used to randomly output an available action. /// public class ActionPool : MonoBehaviour { @@ -23,38 +23,25 @@ void Start() foreach (Action a in actions) { a.ready = true; // default each action is ready on start, subject to change + if (a.priority == 0) + { + Debug.LogWarning(a.name + " should have a non-zero priority."); + } } } /// - /// Constructs a new Action Pool - /// - /// List of Attack Actions - /// Action containing moving animation - /// Action containing idling animation - // public ActionPool(List actions, Action move, Action idle) - //{ - // this.actions = actions; - // this.move = move; - // this.idle = idle; - //} - - /// - /// Choose an action randomly out of all the currently avaliable actions + /// Choose an action randomly out of all the currently available actions /// /// the next action to be played public Action NextAction() { - List avaliableActions = GetAvaliableActions(); - int count = avaliableActions.Count; - if (count == 0) - { - return null; - } + List availableActions = GetAvailableActions(); + if (availableActions.Count == 0) { return null; } - Action nextAction = avaliableActions[0]; + Action nextAction = availableActions[0]; double r = Random.value; - foreach (Action action in avaliableActions) + foreach (Action action in availableActions) { r -= action.GetPriority() / curWeight; if (r <= 0) @@ -83,18 +70,18 @@ public virtual bool HasActionsReady() return false; } - // Return a list of actions that is currently avaliable - private List GetAvaliableActions() + // Return a list of actions that is currently available + private List GetAvailableActions() { - List avaliableActions = new List(); + List availableActions = new List(); foreach (Action a in actions) { if (a.InAttackRange() & a.IsReady()) { - avaliableActions.Add(a); + availableActions.Add(a); curWeight += a.GetPriority(); } } - return avaliableActions; + return availableActions; } } diff --git a/Assets/Scripts/Enemies/States/GreedyActionPool.cs b/Assets/Scripts/Enemies/States/GreedyActionPool.cs index fc510de..28c0086 100644 --- a/Assets/Scripts/Enemies/States/GreedyActionPool.cs +++ b/Assets/Scripts/Enemies/States/GreedyActionPool.cs @@ -8,11 +8,6 @@ /// public class GreedyActionPool : ActionPool { - // It is strongly recomended for an enemy implmenting this AI to have an attack that is: - // 1. Have no cool down. - // 2. Can reach the player even if they are really close (e.g. melee) - //public GreedyActionPool(List actions, Action move, Action idle) : base(actions, move, idle) { } - // Check if an action exists that both can reach the player and is not under cool down. public override bool HasActionsReady() { From bbdbf27636cf5ed7879d81745ddff28647418268 Mon Sep 17 00:00:00 2001 From: Simon Wang <60266027+WangXin1507@users.noreply.github.com> Date: Sat, 28 Dec 2024 11:10:46 -0800 Subject: [PATCH 10/13] Removed extraneous code --- Assets/Prefabs/Enemies/G.R.E.G/G.R.E.G.prefab | 18 ++++++------- Assets/Scripts/Enemies/CameraDrone.cs | 9 ------- Assets/Scripts/Enemies/Cyborg.cs | 14 +--------- .../Enemies/Dummy Enemy/DummyStates.cs | 17 ------------ Assets/Scripts/Enemies/GunWithLegs.cs | 11 -------- Assets/Scripts/Enemies/RiotPolice.cs | 9 ------- Assets/Scripts/Enemies/Roomba.cs | 10 ------- Assets/Scripts/Enemies/ShieldPolice.cs | 12 --------- Assets/Scripts/Enemies/States/Action.cs | 27 +++---------------- Assets/Scripts/Enemies/States/ActionPool.cs | 2 +- .../Enemies/States/EnemyStateManager.cs | 9 ------- .../Enemies/States/GreedyActionPool.cs | 2 +- 12 files changed, 15 insertions(+), 125 deletions(-) diff --git a/Assets/Prefabs/Enemies/G.R.E.G/G.R.E.G.prefab b/Assets/Prefabs/Enemies/G.R.E.G/G.R.E.G.prefab index 7b17d86..b733ef2 100644 --- a/Assets/Prefabs/Enemies/G.R.E.G/G.R.E.G.prefab +++ b/Assets/Prefabs/Enemies/G.R.E.G/G.R.E.G.prefab @@ -333,28 +333,28 @@ MonoBehaviour: m_EditorClassIdentifier: actions: - name: Kick + priority: 7 + ready: 0 hitBox: {fileID: 8875514496581505741} coolDown: 4 animationClip: {fileID: 7400000, guid: 8c897a8a0dede6440a96aac7136b23fc, type: 2} - priority: 7 - ready: 0 - name: Shoot + priority: 3 + ready: 0 hitBox: {fileID: 6754032986899484797} coolDown: 4 animationClip: {fileID: 7400000, guid: e06dacd5cab3a6349968796d2cef56de, type: 2} - priority: 3 - ready: 0 move: - name: Move + name: + priority: 0 + ready: 0 hitBox: {fileID: 0} coolDown: 0 animationClip: {fileID: 7400000, guid: 50188f8587fb1d944acdb9fdcc0b1425, type: 2} + idle: + name: priority: 0 ready: 0 - idle: - name: Idle hitBox: {fileID: 0} coolDown: 0 animationClip: {fileID: 7400000, guid: ff1895b71cbdcc8408401395813d5733, type: 2} - priority: 0 - ready: 0 diff --git a/Assets/Scripts/Enemies/CameraDrone.cs b/Assets/Scripts/Enemies/CameraDrone.cs index 9581dc6..b99aef2 100644 --- a/Assets/Scripts/Enemies/CameraDrone.cs +++ b/Assets/Scripts/Enemies/CameraDrone.cs @@ -6,15 +6,6 @@ public class CameraDrone : EnemyStateManager { [SerializeField] protected Transform alarmTrigger; [SerializeField] protected GameObject enemyToSummon; - //protected override ActionPool GenerateActionPool() - //{ - // Action callAlarm = new(alarmTrigger, 5.0f, 1f, "Call Alarm"); - - // Action move = new(null, 0.0f, 0.0f, "move"); - // Action idle = new(null, 0.0f, 0.0f, "idle"); - - // return new ActionPool(new List { callAlarm }, move, idle); - //} /// /// Summons an enemy diff --git a/Assets/Scripts/Enemies/Cyborg.cs b/Assets/Scripts/Enemies/Cyborg.cs index db53253..b1949c5 100644 --- a/Assets/Scripts/Enemies/Cyborg.cs +++ b/Assets/Scripts/Enemies/Cyborg.cs @@ -15,19 +15,7 @@ public class Cyborg : EnemyStateManager [SerializeField] protected Transform stingerTrigger; // Area in which enemy will attempt to use stinger attack [SerializeField] protected Transform stingerHitBox; // Area in which the stinger attack will do damage - // Cybor will draw actions greedily - //protected override ActionPool GenerateActionPool() - //{ - // Action cyborgSlash = new(meleeTrigger, 0.0f, 7f, "Cyborg Slash"); - // Action cyborgBack = new(tpBackTrigger, 7.0f, 1f, "TP Back"); - // Action cyborgForward = new(tpForwardTrigger, 18.0f, 5f, "TP Forward"); - // Action cyborgStinger = new(stingerTrigger, 4.0f, 1f, "Cyborg Stinger"); - - // Action move = new(null, 0.0f, 0.0f, "move"); - // Action idle = new(null, 0.0f, 0.0f, "idle"); - - // return new GreedyActionPool(new List { cyborgSlash, cyborgBack, cyborgForward, cyborgStinger }, move, idle); - //} + // Cyborg will draw actions greedily // Generate damage frame for melee slash attack protected void OnSlashEvent() diff --git a/Assets/Scripts/Enemies/Dummy Enemy/DummyStates.cs b/Assets/Scripts/Enemies/Dummy Enemy/DummyStates.cs index 326152d..fa73b51 100644 --- a/Assets/Scripts/Enemies/Dummy Enemy/DummyStates.cs +++ b/Assets/Scripts/Enemies/Dummy Enemy/DummyStates.cs @@ -21,23 +21,6 @@ public class DummyStates : EnemyStateManager, IDamageable private Stats stats; public GameObject projectile; - // Dummy Enemy's all possible actions - //protected override ActionPool GenerateActionPool() - //{ - // // Declare the Enemy's attacks - // Action dummySlash = new(meleeTrigger, 4.0f, 3f, "HeroKnight_Attack1"); - // Action dummyShoot = new(rangeTrigger, 4.0f, 7f, "Dummy_Shoot"); - - // // Most Enemy should also add their Run and Idle animations to the ActionPool - // Action move = new(null, 0.0f, 0.0f, "HeroKnight_Run"); - // Action idle = new(null, 0.0f, 0.0f, "HeroKnight_Idle"); - - // //Future stunned state --> Stun Hit (NOT IMPLEMENTED YET) - // Action stunned = new(null, 0.0f, 0.0f, "HeroKnight_Idle"); - - // return new ActionPool(new List { dummySlash, dummyShoot }, move, idle); - //} - void Start() { // Stats grab diff --git a/Assets/Scripts/Enemies/GunWithLegs.cs b/Assets/Scripts/Enemies/GunWithLegs.cs index bdcaf69..026c838 100644 --- a/Assets/Scripts/Enemies/GunWithLegs.cs +++ b/Assets/Scripts/Enemies/GunWithLegs.cs @@ -13,17 +13,6 @@ public class GunWithLegs : EnemyStateManager [SerializeField] protected Transform projectile; - //protected override ActionPool GenerateActionPool() - //{ - // Action kick = new(gunKick, 4.0f, 3f, "Gun_W_Leg_Kick"); - // Action shoot = new(gunShoot, 4.0f, 7f, "Gun_W_Leg_Shoot"); - - // Action move = new(null, 0.0f, 0.0f, "move"); - // Action idle = new(null, 0.0f, 0.0f, "idle"); - - // return new ActionPool(new List { kick, shoot }, move, idle); - //} - // Check for kick collision and do damage protected void OnKickEvent() { diff --git a/Assets/Scripts/Enemies/RiotPolice.cs b/Assets/Scripts/Enemies/RiotPolice.cs index 8ad2218..4441eee 100644 --- a/Assets/Scripts/Enemies/RiotPolice.cs +++ b/Assets/Scripts/Enemies/RiotPolice.cs @@ -9,15 +9,6 @@ public class RiotPolice : EnemyStateManager { [SerializeField] protected Transform batonTrigger; - //protected override ActionPool GenerateActionPool() - //{ - // Action batonSwing = new(batonTrigger, 2.0f, 1f, "Riot_Police_Swing"); - - // Action move = new(null, 0.0f, 0.0f, "Riot_Police_Run"); - // Action idle = new(null, 0.0f, 0.0f, "Riot_Police_Idle"); - - // return new ActionPool(new List { batonSwing }, move, idle); - //} // Check for collision in swing range to deal damage protected void OnBatonEvent() diff --git a/Assets/Scripts/Enemies/Roomba.cs b/Assets/Scripts/Enemies/Roomba.cs index dfe00e9..0828a31 100644 --- a/Assets/Scripts/Enemies/Roomba.cs +++ b/Assets/Scripts/Enemies/Roomba.cs @@ -9,16 +9,6 @@ public class Roomba : EnemyStateManager { [SerializeField] protected Transform kaboomTrigger; - //protected override ActionPool GenerateActionPool() - //{ - // Action kaboom = new(kaboomTrigger, 0.0f, 1f, "kaboom"); - - // Action move = new(null, 0.0f, 0.0f, "move"); - // Action idle = new(null, 0.0f, 0.0f, "idle"); - - // return new ActionPool(new List { kaboom }, move, idle); - //} - // Check for player in blast radius and do damage protected void OnKaboomEvent() { diff --git a/Assets/Scripts/Enemies/ShieldPolice.cs b/Assets/Scripts/Enemies/ShieldPolice.cs index a50e957..75776a6 100644 --- a/Assets/Scripts/Enemies/ShieldPolice.cs +++ b/Assets/Scripts/Enemies/ShieldPolice.cs @@ -24,18 +24,6 @@ void Update() } } - // Shielded Police will draw actions greedily - //protected override ActionPool GenerateActionPool() - //{ - // Action batonSwing = new(batonTrigger, 0.0f, 3f, "Shield_Police_Swing"); - // Action shieldCharge = new(chargeTrigger, 10.0f, 3f, "Shield_Police_Charge_1"); - - // Action move = new(null, 0.0f, 0.0f, "Shield_Police_Run"); - // Action idle = new(null, 0.0f, 0.0f, "Shield_Police_Idle"); - - // return new GreedyActionPool(new List { batonSwing, shieldCharge }, move, idle); - //} - // Generate damage frame for baton swing protected void OnBatonEvent() { diff --git a/Assets/Scripts/Enemies/States/Action.cs b/Assets/Scripts/Enemies/States/Action.cs index b1dc7d3..5635143 100644 --- a/Assets/Scripts/Enemies/States/Action.cs +++ b/Assets/Scripts/Enemies/States/Action.cs @@ -11,28 +11,12 @@ [Serializable] public class Action { - [SerializeField] public string name; + public string name; + public float priority; + public bool ready = true; [SerializeField] private Transform hitBox; // The area in which if a player is inside, the action will be performed [SerializeField] private float coolDown; [SerializeField] private AnimationClip animationClip; - public float priority; - public bool ready = true; - - /// - /// Constructs an Action for a particular Enemy - /// - /// The area in which if a player is inside, the action will be performed - /// Length of the Action's cool down - /// Tendency to do this Action (1-10) - /// Name of the animation to be played - public Action(Transform hitBox, float coolDown, float priority, AnimationClip anim) - { - this.hitBox = hitBox; - this.coolDown = coolDown; - this.priority = priority; - this.animationClip = anim; - this.ready = true; - } /// /// Executes the Action @@ -59,11 +43,6 @@ public float GetPriority() return this.priority; } - public bool IsReady() - { - return ready; - } - /// /// Make this action go into cooldown /// diff --git a/Assets/Scripts/Enemies/States/ActionPool.cs b/Assets/Scripts/Enemies/States/ActionPool.cs index 8ee87e9..f88af6e 100644 --- a/Assets/Scripts/Enemies/States/ActionPool.cs +++ b/Assets/Scripts/Enemies/States/ActionPool.cs @@ -76,7 +76,7 @@ private List GetAvailableActions() List availableActions = new List(); foreach (Action a in actions) { - if (a.InAttackRange() & a.IsReady()) + if (a.InAttackRange() & a.ready) { availableActions.Add(a); curWeight += a.GetPriority(); diff --git a/Assets/Scripts/Enemies/States/EnemyStateManager.cs b/Assets/Scripts/Enemies/States/EnemyStateManager.cs index ca22c99..fcd79f5 100644 --- a/Assets/Scripts/Enemies/States/EnemyStateManager.cs +++ b/Assets/Scripts/Enemies/States/EnemyStateManager.cs @@ -145,15 +145,6 @@ protected void GenerateDamageFrame(Vector2 pos, float radius, float damage) } } - /// - /// Produce a list off Actions which randomly generates the next action - /// - /// - protected virtual ActionPool GenerateActionPool() - { - return null; - } - /// /// Draws the Enemy's line of sight in editor /// diff --git a/Assets/Scripts/Enemies/States/GreedyActionPool.cs b/Assets/Scripts/Enemies/States/GreedyActionPool.cs index 28c0086..866d2d3 100644 --- a/Assets/Scripts/Enemies/States/GreedyActionPool.cs +++ b/Assets/Scripts/Enemies/States/GreedyActionPool.cs @@ -13,7 +13,7 @@ public override bool HasActionsReady() { foreach (Action a in actions) { - if (a.IsReady() & a.InAttackRange()) + if (a.ready & a.InAttackRange()) { return true; } From a4d82b76fa95615189da1bfa9b4a502cb09c7c31 Mon Sep 17 00:00:00 2001 From: Simon Wang <60266027+WangXin1507@users.noreply.github.com> Date: Sat, 28 Dec 2024 17:25:23 -0800 Subject: [PATCH 11/13] Serialized enemy attack damage --- Assets/Scripts/Enemies/CameraDrone.cs | 9 +++++++-- Assets/Scripts/Enemies/Cyborg.cs | 20 ++++++++++++-------- Assets/Scripts/Enemies/GunWithLegs.cs | 14 +++++++++----- Assets/Scripts/Enemies/PoliceShield.cs | 3 ++- Assets/Scripts/Enemies/RiotPolice.cs | 7 +++++-- Assets/Scripts/Enemies/Roomba.cs | 6 ++++-- Assets/Scripts/Enemies/ShieldPolice.cs | 11 +++++++---- 7 files changed, 46 insertions(+), 24 deletions(-) diff --git a/Assets/Scripts/Enemies/CameraDrone.cs b/Assets/Scripts/Enemies/CameraDrone.cs index b99aef2..f0ac350 100644 --- a/Assets/Scripts/Enemies/CameraDrone.cs +++ b/Assets/Scripts/Enemies/CameraDrone.cs @@ -1,11 +1,16 @@ +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; +/// +/// Enemy AI for Camera Drone +/// +[Serializable] public class CameraDrone : EnemyStateManager { - [SerializeField] protected Transform alarmTrigger; - [SerializeField] protected GameObject enemyToSummon; + protected Transform alarmTrigger; + protected GameObject enemyToSummon; /// /// Summons an enemy diff --git a/Assets/Scripts/Enemies/Cyborg.cs b/Assets/Scripts/Enemies/Cyborg.cs index b1949c5..e3b813d 100644 --- a/Assets/Scripts/Enemies/Cyborg.cs +++ b/Assets/Scripts/Enemies/Cyborg.cs @@ -6,21 +6,25 @@ /// /// Enemy AI for the Cyborg /// +[SerializeField] public class Cyborg : EnemyStateManager { - [SerializeField] protected Transform meleeTrigger; // Area in which enemy will attempt to melee - [SerializeField] protected Transform tpBackTrigger; // Area in which enemy will attempt to teleport backward - [SerializeField] protected Transform tpForwardTrigger; // Area in which enemy will attempt to teleport forward + protected Transform meleeTrigger; // Area in which enemy will attempt to melee + protected float meleeDamage; + protected Transform tpBackTrigger; // Area in which enemy will attempt to teleport backward + protected float spinDamage; + protected Transform tpForwardTrigger; // Area in which enemy will attempt to teleport forward - [SerializeField] protected Transform stingerTrigger; // Area in which enemy will attempt to use stinger attack - [SerializeField] protected Transform stingerHitBox; // Area in which the stinger attack will do damage + protected Transform stingerTrigger; // Area in which enemy will attempt to use stinger attack + protected Transform stingerHitBox; // Area in which the stinger attack will do damage + protected float stingerDamage; // Cyborg will draw actions greedily // Generate damage frame for melee slash attack protected void OnSlashEvent() { - GenerateDamageFrame(meleeTrigger.position, meleeTrigger.lossyScale.x, meleeTrigger.lossyScale.y, 1.0f); + GenerateDamageFrame(meleeTrigger.position, meleeTrigger.lossyScale.x, meleeTrigger.lossyScale.y, meleeDamage); } // Teleports the cyborg backwards @@ -49,13 +53,13 @@ protected void OnTPForwardEvent1() // Generate damage frame for follow up attack after teleporting forward protected void OnTPForwardEvent2() { - GenerateDamageFrame(tpBackTrigger.position, tpBackTrigger.lossyScale.x, tpBackTrigger.lossyScale.y, 1.0f); + GenerateDamageFrame(tpBackTrigger.position, tpBackTrigger.lossyScale.x, tpBackTrigger.lossyScale.y, spinDamage); } // Generate damage frame for long range stinger attack protected void OnStingerEvent() { - GenerateDamageFrame(stingerHitBox.position, stingerHitBox.lossyScale.x, stingerHitBox.lossyScale.y, 1.0f); + GenerateDamageFrame(stingerHitBox.position, stingerHitBox.lossyScale.x, stingerHitBox.lossyScale.y, stingerDamage); } protected override void OnFinishAnimation() diff --git a/Assets/Scripts/Enemies/GunWithLegs.cs b/Assets/Scripts/Enemies/GunWithLegs.cs index 026c838..90710ef 100644 --- a/Assets/Scripts/Enemies/GunWithLegs.cs +++ b/Assets/Scripts/Enemies/GunWithLegs.cs @@ -1,22 +1,26 @@ +using System; using System.Collections; using System.Collections.Generic; +using Unity.VisualScripting; using UnityEngine; /// /// Enemy AI for gun with legs /// +[Serializable] public class GunWithLegs : EnemyStateManager { - [SerializeField] protected Transform gunKick; - [SerializeField] protected Transform gunShoot; - [SerializeField] protected Transform rangeOrig; + protected Transform gunKick; + protected float kickDamage; + protected Transform gunShoot; + protected Transform rangeOrig; - [SerializeField] protected Transform projectile; + protected GameObject projectile; // Check for kick collision and do damage protected void OnKickEvent() { - GenerateDamageFrame(gunKick.position, gunKick.lossyScale.x, gunKick.lossyScale.y, 1.0f); + GenerateDamageFrame(gunKick.position, gunKick.lossyScale.x, gunKick.lossyScale.y, kickDamage); } // Instantiate projectile prefab and push self back diff --git a/Assets/Scripts/Enemies/PoliceShield.cs b/Assets/Scripts/Enemies/PoliceShield.cs index 8540a92..7f44ee7 100644 --- a/Assets/Scripts/Enemies/PoliceShield.cs +++ b/Assets/Scripts/Enemies/PoliceShield.cs @@ -7,6 +7,7 @@ /// public class PoliceShield : MonoBehaviour { + [SerializeField] protected float chargeDamage; private bool isCharging = false; private void OnCollisionEnter2D(Collision2D collision) @@ -18,7 +19,7 @@ private void OnCollisionEnter2D(Collision2D collision) } GameObject player = collision.gameObject; - player.GetComponent().TakeDamage(10); + player.GetComponent().TakeDamage(chargeDamage); gameObject.GetComponentInParent().SetBool("HasCollided", true); ToggleCollision(); diff --git a/Assets/Scripts/Enemies/RiotPolice.cs b/Assets/Scripts/Enemies/RiotPolice.cs index 4441eee..2c77f96 100644 --- a/Assets/Scripts/Enemies/RiotPolice.cs +++ b/Assets/Scripts/Enemies/RiotPolice.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; @@ -6,14 +7,16 @@ /// /// Enemy AI for Riot Police /// +[Serializable] public class RiotPolice : EnemyStateManager { - [SerializeField] protected Transform batonTrigger; + protected Transform batonTrigger; + protected float batonDamage; // Check for collision in swing range to deal damage protected void OnBatonEvent() { - GenerateDamageFrame(batonTrigger.position, batonTrigger.lossyScale.x, batonTrigger.lossyScale.y, 1); + GenerateDamageFrame(batonTrigger.position, batonTrigger.lossyScale.x, batonTrigger.lossyScale.y, batonDamage); } // Draws the Enemy attack range in the editor diff --git a/Assets/Scripts/Enemies/Roomba.cs b/Assets/Scripts/Enemies/Roomba.cs index 0828a31..a58f380 100644 --- a/Assets/Scripts/Enemies/Roomba.cs +++ b/Assets/Scripts/Enemies/Roomba.cs @@ -5,14 +5,16 @@ /// /// Enemy AI for Roomba /// +[SerializeField] public class Roomba : EnemyStateManager { - [SerializeField] protected Transform kaboomTrigger; + protected Transform kaboomTrigger; + protected float kaboomDamage; // Check for player in blast radius and do damage protected void OnKaboomEvent() { - GenerateDamageFrame(kaboomTrigger.position, kaboomTrigger.lossyScale.x, 5.0f); + GenerateDamageFrame(kaboomTrigger.position, kaboomTrigger.lossyScale.x, kaboomDamage); } protected override void OnFinishAnimation() diff --git a/Assets/Scripts/Enemies/ShieldPolice.cs b/Assets/Scripts/Enemies/ShieldPolice.cs index 75776a6..df6912f 100644 --- a/Assets/Scripts/Enemies/ShieldPolice.cs +++ b/Assets/Scripts/Enemies/ShieldPolice.cs @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; @@ -7,11 +8,13 @@ /// /// Enemy AI for a Shielded Riot Police /// +[Serializable] public class ShieldPolice : EnemyStateManager { - [SerializeField] protected Transform batonTrigger; - [SerializeField] protected Transform chargeTrigger; - [SerializeField] protected float chargeSpeed; + protected Transform batonTrigger; + protected float batonDamage; + protected Transform chargeTrigger; + protected float chargeSpeed; protected bool isCharging; protected Vector2 chargePos; @@ -27,7 +30,7 @@ void Update() // Generate damage frame for baton swing protected void OnBatonEvent() { - GenerateDamageFrame(batonTrigger.position, batonTrigger.lossyScale.x, batonTrigger.lossyScale.y, 1.0f); + GenerateDamageFrame(batonTrigger.position, batonTrigger.lossyScale.x, batonTrigger.lossyScale.y, batonDamage); } // Ask police to begin charging and enable shield damage From 96c886ea30a64cb38d464502628cdad23b9a9913 Mon Sep 17 00:00:00 2001 From: Simon Wang <60266027+WangXin1507@users.noreply.github.com> Date: Sat, 28 Dec 2024 17:32:15 -0800 Subject: [PATCH 12/13] Revert "Serialized enemy attack damage" This reverts commit a4d82b76fa95615189da1bfa9b4a502cb09c7c31. --- Assets/Scripts/Enemies/CameraDrone.cs | 9 ++------- Assets/Scripts/Enemies/Cyborg.cs | 20 ++++++++------------ Assets/Scripts/Enemies/GunWithLegs.cs | 14 +++++--------- Assets/Scripts/Enemies/PoliceShield.cs | 3 +-- Assets/Scripts/Enemies/RiotPolice.cs | 7 ++----- Assets/Scripts/Enemies/Roomba.cs | 6 ++---- Assets/Scripts/Enemies/ShieldPolice.cs | 11 ++++------- 7 files changed, 24 insertions(+), 46 deletions(-) diff --git a/Assets/Scripts/Enemies/CameraDrone.cs b/Assets/Scripts/Enemies/CameraDrone.cs index f0ac350..b99aef2 100644 --- a/Assets/Scripts/Enemies/CameraDrone.cs +++ b/Assets/Scripts/Enemies/CameraDrone.cs @@ -1,16 +1,11 @@ -using System; using System.Collections; using System.Collections.Generic; using UnityEngine; -/// -/// Enemy AI for Camera Drone -/// -[Serializable] public class CameraDrone : EnemyStateManager { - protected Transform alarmTrigger; - protected GameObject enemyToSummon; + [SerializeField] protected Transform alarmTrigger; + [SerializeField] protected GameObject enemyToSummon; /// /// Summons an enemy diff --git a/Assets/Scripts/Enemies/Cyborg.cs b/Assets/Scripts/Enemies/Cyborg.cs index e3b813d..b1949c5 100644 --- a/Assets/Scripts/Enemies/Cyborg.cs +++ b/Assets/Scripts/Enemies/Cyborg.cs @@ -6,25 +6,21 @@ /// /// Enemy AI for the Cyborg /// -[SerializeField] public class Cyborg : EnemyStateManager { - protected Transform meleeTrigger; // Area in which enemy will attempt to melee - protected float meleeDamage; - protected Transform tpBackTrigger; // Area in which enemy will attempt to teleport backward - protected float spinDamage; - protected Transform tpForwardTrigger; // Area in which enemy will attempt to teleport forward + [SerializeField] protected Transform meleeTrigger; // Area in which enemy will attempt to melee + [SerializeField] protected Transform tpBackTrigger; // Area in which enemy will attempt to teleport backward + [SerializeField] protected Transform tpForwardTrigger; // Area in which enemy will attempt to teleport forward - protected Transform stingerTrigger; // Area in which enemy will attempt to use stinger attack - protected Transform stingerHitBox; // Area in which the stinger attack will do damage - protected float stingerDamage; + [SerializeField] protected Transform stingerTrigger; // Area in which enemy will attempt to use stinger attack + [SerializeField] protected Transform stingerHitBox; // Area in which the stinger attack will do damage // Cyborg will draw actions greedily // Generate damage frame for melee slash attack protected void OnSlashEvent() { - GenerateDamageFrame(meleeTrigger.position, meleeTrigger.lossyScale.x, meleeTrigger.lossyScale.y, meleeDamage); + GenerateDamageFrame(meleeTrigger.position, meleeTrigger.lossyScale.x, meleeTrigger.lossyScale.y, 1.0f); } // Teleports the cyborg backwards @@ -53,13 +49,13 @@ protected void OnTPForwardEvent1() // Generate damage frame for follow up attack after teleporting forward protected void OnTPForwardEvent2() { - GenerateDamageFrame(tpBackTrigger.position, tpBackTrigger.lossyScale.x, tpBackTrigger.lossyScale.y, spinDamage); + GenerateDamageFrame(tpBackTrigger.position, tpBackTrigger.lossyScale.x, tpBackTrigger.lossyScale.y, 1.0f); } // Generate damage frame for long range stinger attack protected void OnStingerEvent() { - GenerateDamageFrame(stingerHitBox.position, stingerHitBox.lossyScale.x, stingerHitBox.lossyScale.y, stingerDamage); + GenerateDamageFrame(stingerHitBox.position, stingerHitBox.lossyScale.x, stingerHitBox.lossyScale.y, 1.0f); } protected override void OnFinishAnimation() diff --git a/Assets/Scripts/Enemies/GunWithLegs.cs b/Assets/Scripts/Enemies/GunWithLegs.cs index 90710ef..026c838 100644 --- a/Assets/Scripts/Enemies/GunWithLegs.cs +++ b/Assets/Scripts/Enemies/GunWithLegs.cs @@ -1,26 +1,22 @@ -using System; using System.Collections; using System.Collections.Generic; -using Unity.VisualScripting; using UnityEngine; /// /// Enemy AI for gun with legs /// -[Serializable] public class GunWithLegs : EnemyStateManager { - protected Transform gunKick; - protected float kickDamage; - protected Transform gunShoot; - protected Transform rangeOrig; + [SerializeField] protected Transform gunKick; + [SerializeField] protected Transform gunShoot; + [SerializeField] protected Transform rangeOrig; - protected GameObject projectile; + [SerializeField] protected Transform projectile; // Check for kick collision and do damage protected void OnKickEvent() { - GenerateDamageFrame(gunKick.position, gunKick.lossyScale.x, gunKick.lossyScale.y, kickDamage); + GenerateDamageFrame(gunKick.position, gunKick.lossyScale.x, gunKick.lossyScale.y, 1.0f); } // Instantiate projectile prefab and push self back diff --git a/Assets/Scripts/Enemies/PoliceShield.cs b/Assets/Scripts/Enemies/PoliceShield.cs index 7f44ee7..8540a92 100644 --- a/Assets/Scripts/Enemies/PoliceShield.cs +++ b/Assets/Scripts/Enemies/PoliceShield.cs @@ -7,7 +7,6 @@ /// public class PoliceShield : MonoBehaviour { - [SerializeField] protected float chargeDamage; private bool isCharging = false; private void OnCollisionEnter2D(Collision2D collision) @@ -19,7 +18,7 @@ private void OnCollisionEnter2D(Collision2D collision) } GameObject player = collision.gameObject; - player.GetComponent().TakeDamage(chargeDamage); + player.GetComponent().TakeDamage(10); gameObject.GetComponentInParent().SetBool("HasCollided", true); ToggleCollision(); diff --git a/Assets/Scripts/Enemies/RiotPolice.cs b/Assets/Scripts/Enemies/RiotPolice.cs index 2c77f96..4441eee 100644 --- a/Assets/Scripts/Enemies/RiotPolice.cs +++ b/Assets/Scripts/Enemies/RiotPolice.cs @@ -1,4 +1,3 @@ -using System; using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; @@ -7,16 +6,14 @@ /// /// Enemy AI for Riot Police /// -[Serializable] public class RiotPolice : EnemyStateManager { - protected Transform batonTrigger; - protected float batonDamage; + [SerializeField] protected Transform batonTrigger; // Check for collision in swing range to deal damage protected void OnBatonEvent() { - GenerateDamageFrame(batonTrigger.position, batonTrigger.lossyScale.x, batonTrigger.lossyScale.y, batonDamage); + GenerateDamageFrame(batonTrigger.position, batonTrigger.lossyScale.x, batonTrigger.lossyScale.y, 1); } // Draws the Enemy attack range in the editor diff --git a/Assets/Scripts/Enemies/Roomba.cs b/Assets/Scripts/Enemies/Roomba.cs index a58f380..0828a31 100644 --- a/Assets/Scripts/Enemies/Roomba.cs +++ b/Assets/Scripts/Enemies/Roomba.cs @@ -5,16 +5,14 @@ /// /// Enemy AI for Roomba /// -[SerializeField] public class Roomba : EnemyStateManager { - protected Transform kaboomTrigger; - protected float kaboomDamage; + [SerializeField] protected Transform kaboomTrigger; // Check for player in blast radius and do damage protected void OnKaboomEvent() { - GenerateDamageFrame(kaboomTrigger.position, kaboomTrigger.lossyScale.x, kaboomDamage); + GenerateDamageFrame(kaboomTrigger.position, kaboomTrigger.lossyScale.x, 5.0f); } protected override void OnFinishAnimation() diff --git a/Assets/Scripts/Enemies/ShieldPolice.cs b/Assets/Scripts/Enemies/ShieldPolice.cs index df6912f..75776a6 100644 --- a/Assets/Scripts/Enemies/ShieldPolice.cs +++ b/Assets/Scripts/Enemies/ShieldPolice.cs @@ -1,4 +1,3 @@ -using System; using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; @@ -8,13 +7,11 @@ /// /// Enemy AI for a Shielded Riot Police /// -[Serializable] public class ShieldPolice : EnemyStateManager { - protected Transform batonTrigger; - protected float batonDamage; - protected Transform chargeTrigger; - protected float chargeSpeed; + [SerializeField] protected Transform batonTrigger; + [SerializeField] protected Transform chargeTrigger; + [SerializeField] protected float chargeSpeed; protected bool isCharging; protected Vector2 chargePos; @@ -30,7 +27,7 @@ void Update() // Generate damage frame for baton swing protected void OnBatonEvent() { - GenerateDamageFrame(batonTrigger.position, batonTrigger.lossyScale.x, batonTrigger.lossyScale.y, batonDamage); + GenerateDamageFrame(batonTrigger.position, batonTrigger.lossyScale.x, batonTrigger.lossyScale.y, 1.0f); } // Ask police to begin charging and enable shield damage From efc250c760dedf9e28741a8c9c488b21ba7d8ec2 Mon Sep 17 00:00:00 2001 From: Simon Wang <60266027+WangXin1507@users.noreply.github.com> Date: Sat, 28 Dec 2024 17:43:49 -0800 Subject: [PATCH 13/13] Modified enemy serialization --- Assets/Scripts/Enemies/CameraDrone.cs | 1 + Assets/Scripts/Enemies/Cyborg.cs | 17 +++++++++++++---- Assets/Scripts/Enemies/GunWithLegs.cs | 7 +++++-- Assets/Scripts/Enemies/PoliceShield.cs | 3 ++- Assets/Scripts/Enemies/RiotPolice.cs | 4 +++- Assets/Scripts/Enemies/Roomba.cs | 4 +++- Assets/Scripts/Enemies/ShieldPolice.cs | 6 +++++- 7 files changed, 32 insertions(+), 10 deletions(-) diff --git a/Assets/Scripts/Enemies/CameraDrone.cs b/Assets/Scripts/Enemies/CameraDrone.cs index b99aef2..ad9b807 100644 --- a/Assets/Scripts/Enemies/CameraDrone.cs +++ b/Assets/Scripts/Enemies/CameraDrone.cs @@ -4,6 +4,7 @@ public class CameraDrone : EnemyStateManager { + [Header("Call Reinforcement")] [SerializeField] protected Transform alarmTrigger; [SerializeField] protected GameObject enemyToSummon; diff --git a/Assets/Scripts/Enemies/Cyborg.cs b/Assets/Scripts/Enemies/Cyborg.cs index b1949c5..982fe5c 100644 --- a/Assets/Scripts/Enemies/Cyborg.cs +++ b/Assets/Scripts/Enemies/Cyborg.cs @@ -8,19 +8,28 @@ /// public class Cyborg : EnemyStateManager { + [Header("Melee Attack")] [SerializeField] protected Transform meleeTrigger; // Area in which enemy will attempt to melee + [SerializeField] protected float meleeDamage; + + [Header("Teleporting Backwards")] [SerializeField] protected Transform tpBackTrigger; // Area in which enemy will attempt to teleport backward + + [Header("Teleporting Forwards")] [SerializeField] protected Transform tpForwardTrigger; // Area in which enemy will attempt to teleport forward - + [SerializeField] protected float spinDamage; + + [Header("Extend Stingers")] [SerializeField] protected Transform stingerTrigger; // Area in which enemy will attempt to use stinger attack [SerializeField] protected Transform stingerHitBox; // Area in which the stinger attack will do damage + [SerializeField] protected float stingerDamage; // Cyborg will draw actions greedily // Generate damage frame for melee slash attack protected void OnSlashEvent() { - GenerateDamageFrame(meleeTrigger.position, meleeTrigger.lossyScale.x, meleeTrigger.lossyScale.y, 1.0f); + GenerateDamageFrame(meleeTrigger.position, meleeTrigger.lossyScale.x, meleeTrigger.lossyScale.y, meleeDamage); } // Teleports the cyborg backwards @@ -49,13 +58,13 @@ protected void OnTPForwardEvent1() // Generate damage frame for follow up attack after teleporting forward protected void OnTPForwardEvent2() { - GenerateDamageFrame(tpBackTrigger.position, tpBackTrigger.lossyScale.x, tpBackTrigger.lossyScale.y, 1.0f); + GenerateDamageFrame(tpBackTrigger.position, tpBackTrigger.lossyScale.x, tpBackTrigger.lossyScale.y, spinDamage); } // Generate damage frame for long range stinger attack protected void OnStingerEvent() { - GenerateDamageFrame(stingerHitBox.position, stingerHitBox.lossyScale.x, stingerHitBox.lossyScale.y, 1.0f); + GenerateDamageFrame(stingerHitBox.position, stingerHitBox.lossyScale.x, stingerHitBox.lossyScale.y, stingerDamage); } protected override void OnFinishAnimation() diff --git a/Assets/Scripts/Enemies/GunWithLegs.cs b/Assets/Scripts/Enemies/GunWithLegs.cs index 026c838..84da08e 100644 --- a/Assets/Scripts/Enemies/GunWithLegs.cs +++ b/Assets/Scripts/Enemies/GunWithLegs.cs @@ -7,16 +7,19 @@ /// public class GunWithLegs : EnemyStateManager { + [Header("Kick")] [SerializeField] protected Transform gunKick; + [SerializeField] protected float kickDamage; + + [Header("Shoot")] [SerializeField] protected Transform gunShoot; [SerializeField] protected Transform rangeOrig; - [SerializeField] protected Transform projectile; // Check for kick collision and do damage protected void OnKickEvent() { - GenerateDamageFrame(gunKick.position, gunKick.lossyScale.x, gunKick.lossyScale.y, 1.0f); + GenerateDamageFrame(gunKick.position, gunKick.lossyScale.x, gunKick.lossyScale.y, kickDamage); } // Instantiate projectile prefab and push self back diff --git a/Assets/Scripts/Enemies/PoliceShield.cs b/Assets/Scripts/Enemies/PoliceShield.cs index 8540a92..9525d87 100644 --- a/Assets/Scripts/Enemies/PoliceShield.cs +++ b/Assets/Scripts/Enemies/PoliceShield.cs @@ -7,6 +7,7 @@ /// public class PoliceShield : MonoBehaviour { + [SerializeField] private float chargeDamage; private bool isCharging = false; private void OnCollisionEnter2D(Collision2D collision) @@ -18,7 +19,7 @@ private void OnCollisionEnter2D(Collision2D collision) } GameObject player = collision.gameObject; - player.GetComponent().TakeDamage(10); + player.GetComponent().TakeDamage(chargeDamage); gameObject.GetComponentInParent().SetBool("HasCollided", true); ToggleCollision(); diff --git a/Assets/Scripts/Enemies/RiotPolice.cs b/Assets/Scripts/Enemies/RiotPolice.cs index 4441eee..d060c5d 100644 --- a/Assets/Scripts/Enemies/RiotPolice.cs +++ b/Assets/Scripts/Enemies/RiotPolice.cs @@ -8,12 +8,14 @@ /// public class RiotPolice : EnemyStateManager { + [Header("Baton Attack")] [SerializeField] protected Transform batonTrigger; + [SerializeField] protected float batonDamage; // Check for collision in swing range to deal damage protected void OnBatonEvent() { - GenerateDamageFrame(batonTrigger.position, batonTrigger.lossyScale.x, batonTrigger.lossyScale.y, 1); + GenerateDamageFrame(batonTrigger.position, batonTrigger.lossyScale.x, batonTrigger.lossyScale.y, batonDamage); } // Draws the Enemy attack range in the editor diff --git a/Assets/Scripts/Enemies/Roomba.cs b/Assets/Scripts/Enemies/Roomba.cs index 0828a31..0943e7b 100644 --- a/Assets/Scripts/Enemies/Roomba.cs +++ b/Assets/Scripts/Enemies/Roomba.cs @@ -7,12 +7,14 @@ /// public class Roomba : EnemyStateManager { + [Header("Self Detonate")] [SerializeField] protected Transform kaboomTrigger; + [SerializeField] protected float kaboomDamage; // Check for player in blast radius and do damage protected void OnKaboomEvent() { - GenerateDamageFrame(kaboomTrigger.position, kaboomTrigger.lossyScale.x, 5.0f); + GenerateDamageFrame(kaboomTrigger.position, kaboomTrigger.lossyScale.x, kaboomDamage); } protected override void OnFinishAnimation() diff --git a/Assets/Scripts/Enemies/ShieldPolice.cs b/Assets/Scripts/Enemies/ShieldPolice.cs index 75776a6..73f7190 100644 --- a/Assets/Scripts/Enemies/ShieldPolice.cs +++ b/Assets/Scripts/Enemies/ShieldPolice.cs @@ -9,7 +9,11 @@ /// public class ShieldPolice : EnemyStateManager { + [Header("Baton Attack")] [SerializeField] protected Transform batonTrigger; + [SerializeField] protected float batonDamage; + + [Header("Charge Attack (See shield to define damage)")] [SerializeField] protected Transform chargeTrigger; [SerializeField] protected float chargeSpeed; @@ -27,7 +31,7 @@ void Update() // Generate damage frame for baton swing protected void OnBatonEvent() { - GenerateDamageFrame(batonTrigger.position, batonTrigger.lossyScale.x, batonTrigger.lossyScale.y, 1.0f); + GenerateDamageFrame(batonTrigger.position, batonTrigger.lossyScale.x, batonTrigger.lossyScale.y, batonDamage); } // Ask police to begin charging and enable shield damage