Skip to content

Commit

Permalink
general attackspeed tuning for all mobs
Browse files Browse the repository at this point in the history
  • Loading branch information
Haikp committed May 2, 2024
1 parent 0e9975f commit 2c9235c
Show file tree
Hide file tree
Showing 17 changed files with 194 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

public class ArcherAttackState : ArcherBaseState
{
private float attackTime = 1.0f;
private float attackTime;
private Animator animator;
public override void EnterState(ArcherStateManager archer)
{
//Debug.Log("Entering Attack State");
attackTime = 1.0f;
attackTime = archer.attackTime / archer.attackSpeed;
animator = archer.GetComponent<Animator>();
animator.SetBool("attacking", true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class ArcherStateManager : MonoBehaviour
private Transform player;
public float attackDamage = 1f;
public float movementSpeed = 1f;
public float attackSpeed = 1f;
[System.NonSerialized] public float attackTime;

// Start is called before the first frame update
void Start()
Expand All @@ -30,6 +32,8 @@ void Start()
currentState.EnterState(this);
animator = this.GetComponent<Animator>();
player = GameObject.Find("Player").GetComponent<Transform>();
findAnimationTimes();
animator.SetFloat("attackSpeed", attackSpeed);
}

// Update is called once per frame
Expand Down Expand Up @@ -73,7 +77,25 @@ private void OnDrawGizmosSelected(){
if (attackPointX == null){
return;
}

Gizmos.DrawWireSphere(attackPointX.position, attackRangeX);
Gizmos.DrawWireSphere(attackPointY.position, attackRangeY);
}

private void findAnimationTimes()
{
AnimationClip[] clips = animator.runtimeAnimatorController.animationClips;
foreach (AnimationClip clip in clips)
{
switch (clip.name)
{
case "attack":
attackTime = clip.length;
break;
default:
Debug.Log(clip.name + " is not accounted for.");
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

public class BomberAttackState : BomberBaseState
{
private float attackTime = 0.9f;
private float attackTime;
private Animator animator;
private bool isProperlyPositionedToAttack = false;

public override void EnterState(BomberStateManager bomber)
{
Debug.Log("Bomber Entering Attack State...");
attackTime = 1f; // Reset the attack timer
attackTime = bomber.attackTime / bomber.attackSpeed;

animator = bomber.GetComponent<Animator>();

Expand All @@ -35,10 +35,8 @@ public override void UpdateState(BomberStateManager bomber)
bomber.SwitchState(bomber.IdleState); // Go back to Idle after attacking or if not properly positioned
animator.SetBool("isAttacking", false);
}
else
{
attackTime -= Time.deltaTime;
}

attackTime -= Time.deltaTime;
}

private void UpdateAttackPermission(BomberStateManager bomber)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ public class BomberStateManager : MonoBehaviour
[SerializeField] private float attackHeight = 3f; // The point from where bombs will be dropped
[SerializeField] private float moveSpeed = 3f; // Default speed
[SerializeField] private int attackDamage = 5; // Default damage value
[SerializeField] private float attackTime = 2f; // Default damage value
public float MoveSpeed => moveSpeed; // Public getter for moveSpeed so it can be accessed but not directly modified by states
public int AttackDamage => attackDamage; // Public getter to access the damage value
public float AttackTime => attackTime; // Public getter to access the attack time value

public Transform Player; // Public getter for the player's transform
public float AttackHeight => attackHeight; // Public getter for the attack height

Expand All @@ -32,14 +29,17 @@ public class BomberStateManager : MonoBehaviour
public BomberIdleState IdleState = new BomberIdleState();
public BomberHitState HitState = new BomberHitState();
public BomberSpawnState SpawnState = new BomberSpawnState();

public float attackSpeed = 1f;
[System.NonSerialized] public float attackTime;
void Start()
{
playerController = GameObject.Find("Player").GetComponent<PlayerController>();
currentState = SpawnState;
currentState.EnterState(this);
animator = this.GetComponent<Animator>();
Player = GameObject.Find("Player").GetComponent<Transform>();
findAnimationTimes();
animator.SetFloat("attackSpeed", attackSpeed);
}

void Update()
Expand Down Expand Up @@ -94,4 +94,22 @@ private void OnDrawGizmosSelected()
Gizmos.DrawWireSphere(attackPointX.position, attackRange);
Gizmos.DrawWireSphere(attackPointY.position, attackHeight);
}

private void findAnimationTimes()
{
AnimationClip[] clips = animator.runtimeAnimatorController.animationClips;
foreach (AnimationClip clip in clips)
{
switch (clip.name)
{
case "BomberAttack":
attackTime = clip.length;
Debug.Log(attackTime + " attackTime");
break;
default:
Debug.Log(clip.name + " is not accounted for.");
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

public class CagedShockerAttackState : CagedShockerBaseState
{
private float attackTime = 1.333f;
private float attackTime;
private Animator animator;
public override void EnterState(CagedShockerStateManager CagedShocker)
{
//Debug.Log("Entering Attack State");
attackTime = 1.333f;
attackTime = CagedShocker.attackTime / CagedShocker.attackSpeed;
animator = CagedShocker.GetComponent<Animator>();
animator.SetTrigger("attacking");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class CagedShockerStateManager : MonoBehaviour
public float attackDamage = 1f;
public float lurch1Dist = 1f;
public float lurch2Dist = 1f;
public float attackSpeed = 1f;
[System.NonSerialized] public float attackTime;

// Start is called before the first frame update
void Start()
Expand All @@ -34,6 +36,8 @@ void Start()
currentState.EnterState(this);
animator = this.GetComponent<Animator>();
player = GameObject.Find("Player").GetComponent<Transform>();
findAnimationTimes();
animator.SetFloat("attackSpeed", attackSpeed);
}

// Update is called once per frame
Expand Down Expand Up @@ -80,4 +84,21 @@ private void OnDrawGizmosSelected(){
Gizmos.DrawWireSphere(attackPointX.position, attackRange);
Gizmos.DrawWireSphere(attackPointY.position, attackHeight);
}

private void findAnimationTimes()
{
AnimationClip[] clips = animator.runtimeAnimatorController.animationClips;
foreach (AnimationClip clip in clips)
{
switch (clip.name)
{
case "Attack":
attackTime = clip.length;
break;
default:
Debug.Log(clip.name + " is not accounted for.");
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

public class SpiderAttackState : SpiderBaseState
{
private float attackTime = 5.0f;
private float attackTime;
private Animator animator;
public override void EnterState(SpiderStateManager Spider)
{
//Debug.Log("Entering Attack State");
attackTime = 2.0f;
attackTime = Spider.attackTime / Spider.attackSpeed;
animator = Spider.GetComponent<Animator>();
animator.SetBool("attacking", true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class SpiderStateManager : MonoBehaviour
private Transform player;
public float attackDamage = 1f;
public float movementSpeed = 1f;
public float attackSpeed = 1f;
[System.NonSerialized] public float attackTime;

// Start is called before the first frame update
void Start()
Expand All @@ -28,6 +30,8 @@ void Start()
currentState.EnterState(this);
animator = this.GetComponent<Animator>();
player = GameObject.Find("Player").GetComponent<Transform>();
findAnimationTimes();
animator.SetFloat("attackSpeed", attackSpeed);
}

// Update is called once per frame
Expand Down Expand Up @@ -73,4 +77,21 @@ private void OnDrawGizmosSelected(){
}
Gizmos.DrawWireSphere(attackPoint.position, attackRange);
}

private void findAnimationTimes()
{
AnimationClip[] clips = animator.runtimeAnimatorController.animationClips;
foreach (AnimationClip clip in clips)
{
switch (clip.name)
{
case "Touch target":
attackTime = clip.length;
break;
default:
Debug.Log(clip.name + " is not accounted for.");
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

public class DaggerMushroomAttackState : DaggerMushroomBaseState
{
private float attackTime = 4.0f;
private float attackTime;
private Animator animator;
public override void EnterState(DaggerMushroomStateManager mush)
{
//Debug.Log("Entering Attack State");
attackTime = 4.0f;
attackTime = mush.attackTime / mush.attackSpeed;
animator = mush.GetComponent<Animator>();
animator.SetBool("attacking", true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class DaggerMushroomStateManager : MonoBehaviour
private Transform player;
public float attackDamage = 1f;
public float movementSpeed = 1f;
public float attackSpeed = 1f;
[System.NonSerialized] public float attackTime;

// Start is called before the first frame update
void Start()
Expand All @@ -28,6 +30,8 @@ void Start()
currentState.EnterState(this);
animator = this.GetComponent<Animator>();
player = GameObject.Find("Player").GetComponent<Transform>();
findAnimationTimes();
animator.SetFloat("attackSpeed", attackSpeed);
}

// Update is called once per frame
Expand Down Expand Up @@ -73,4 +77,21 @@ private void OnDrawGizmosSelected(){
}
Gizmos.DrawWireSphere(attackPoint.position, attackRange);
}

private void findAnimationTimes()
{
AnimationClip[] clips = animator.runtimeAnimatorController.animationClips;
foreach (AnimationClip clip in clips)
{
switch (clip.name)
{
case "attack":
attackTime = clip.length;
break;
default:
Debug.Log(clip.name + " is not accounted for.");
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class GhoulAggroState : GhoulBaseState

public override void EnterState(GhoulStateManager ghoul)
{
//Debug.Log("Entering Aggro State...");
// Debug.Log("Entering Aggro State...");
player = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
rb = ghoul.GetComponent<Rigidbody2D>();
animator = ghoul.GetComponent<Animator>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

public class GhoulAttackState : GhoulBaseState
{
private float attackTime = .9f;
private float attackTime;
private Animator animator;
public override void EnterState(GhoulStateManager ghoul)
{
//Debug.Log("Entering Attack State");
attackTime = .3f;
// Debug.Log("Entering Attack State");
attackTime = ghoul.attackTime / ghoul.attackSpeed;
animator = ghoul.GetComponent<Animator>();
animator.SetBool("attacking", true);
}
Expand All @@ -16,7 +16,7 @@ public override void UpdateState(GhoulStateManager ghoul)
{
if(attackTime <= 0)
{
ghoul.SwitchState(ghoul.IdleState);
ghoul.SwitchState(ghoul.AggroState);
animator.SetBool("attacking", false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class GhoulStateManager : MonoBehaviour
private Transform player;
public float attackDamage = 1f;
public float movementSpeed = 1f;
public float attackSpeed = 1f;
[System.NonSerialized] public float attackTime;

// Start is called before the first frame update
void Start()
Expand All @@ -29,6 +31,8 @@ void Start()
currentState.EnterState(this);
animator = this.GetComponent<Animator>();
player = GameObject.Find("Player").GetComponent<Transform>();
findAnimationTimes();
animator.SetFloat("attackSpeed", attackSpeed);
}

// Update is called once per frame
Expand Down Expand Up @@ -88,4 +92,21 @@ public void TriggerTesting(Collider2D collider2D)
{
OnTriggerStay2D(collider2D);
}

private void findAnimationTimes()
{
AnimationClip[] clips = animator.runtimeAnimatorController.animationClips;
foreach (AnimationClip clip in clips)
{
switch (clip.name)
{
case "GhoulAttack":
attackTime = clip.length;
break;
default:
Debug.Log(clip.name + " is not accounted for.");
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class SpitterAttackState : SpitterBaseState
private Transform playerTransform;
private SpitterStateManager spitter;

public float attackCooldown = 0.7f; // Cooldown between attacks
public float attackCooldown;
private bool isAttackInitiated = false; // To control attack initiation
private Coroutine attackCoroutine; // To keep track of the coroutine

Expand All @@ -16,6 +16,7 @@ public override void EnterState(SpitterStateManager spitter)
this.spitter = spitter;
playerTransform = GameObject.FindGameObjectWithTag("Player")?.transform; // Use null-conditional to prevent error
animator = spitter.GetComponent<Animator>();
attackCooldown = spitter.attackTime/spitter.attackSpeed;

if (playerTransform != null)
{
Expand Down
Loading

0 comments on commit 2c9235c

Please sign in to comment.