95 lines
2.5 KiB
C#
95 lines
2.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
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;
|
|
|
|
private Vector2 _movementVector = Vector2.zero;
|
|
private Rigidbody2D _rigidbody;
|
|
private WaveObserver _observer;
|
|
private int _observerIndex;
|
|
private float _toughness;
|
|
private bool _hasMonsterCore = false;
|
|
private bool _isDying = false;
|
|
|
|
|
|
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()
|
|
{
|
|
if (!_isDying)
|
|
{
|
|
if (_hasMonsterCore)
|
|
{
|
|
DropMonsterCore();
|
|
}
|
|
_isDying = true;
|
|
_observer.NotifyDies(_observerIndex, _toughness, gameObject);
|
|
base.Death();
|
|
}
|
|
}
|
|
|
|
private void DropMonsterCore()
|
|
{
|
|
GameObject _monsterCorePrefab = Database.Instance.Prefabs["yieldMonsterCore"];
|
|
|
|
if (_monsterCorePrefab != null)
|
|
{
|
|
Instantiate(_monsterCorePrefab, transform.position, Quaternion.identity);
|
|
_hasMonsterCore = false;
|
|
}
|
|
}
|
|
|
|
public void ActivateMonsterCore()
|
|
{
|
|
_hasMonsterCore = true;
|
|
}
|
|
|
|
}
|