MaximilienBlanchardBizien1 a6636db01c Added Traits List
Added a list of traits to the enemies that the game will use to determine certain actions.

- The trait to have a 25% chance to dodge projectiles has been implemented.
2025-07-08 15:15:09 -04:00

69 lines
1.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEditorInternal;
using UnityEngine;
public class Opponent : Entity
{
public override Vector2 RangeMultiplier => GlobalConfig.Instance.Current.enemyRangeMultiplier;
public override float DamageMultiplier => GlobalConfig.Instance.Current.enemyDamageMultiplier;
public override float AttackSpeedMultiplier => GlobalConfig.Instance.Current.enemyAttackSpeedMultiplier;
public override float HpMultiplier => GlobalConfig.Instance.Current.enemyLifeMultiplier;
public override float SpeedMultiplier => GlobalConfig.Instance.Current.enemySpeedMultiplier;
public List<OpponentTrait.Trait> OpponentTraits = new List<OpponentTrait.Trait>();
private Vector2 _movementVector = Vector2.zero;
private Rigidbody2D _rigidbody;
private WaveObserver _observer;
private int _observerIndex;
private float _toughness;
public override void Start()
{
base.Start();
_rigidbody = GetComponent<Rigidbody2D>();
Animation = gameObject.AddComponent<AnimationEntity>();
_observer = WaveObserver.Instance;
_toughness = Mathf.Round((Hp / 10) / 2);
_observerIndex = _observer.NotifyEnemy(transform.position.y, _toughness);
}
public override void Update()
{
base.Update();
if(IsEnemyDetected)
{
AttackEnemy();
}
else
{
_movementVector.x = -Time.deltaTime * Speed;
transform.position += (Vector3)_movementVector;
Move();
}
}
void AttackEnemy()
{
//Attack Cooldown
if(AttackInterval < AttackSpeedWait)
{
Animation.PlayAttackAnim();
AttackSpeedWait = 0f;
}
AttackSpeedWait += Time.deltaTime;
}
public override void Death()
{
_observer.NotifyDies(_observerIndex, _toughness, gameObject);
base.Death();
}
}