60 lines
1.6 KiB
C#
60 lines
1.6 KiB
C#
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Runtime.CompilerServices;
|
||
|
using BITFALL.Bullet;
|
||
|
using BITFALL.Entities.Equipment;
|
||
|
using BITKit;
|
||
|
using BITKit.Entities;
|
||
|
using BITKit.StateMachine;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace BITFALL.Guns
|
||
|
{
|
||
|
public class AIGunController : AIEquipController
|
||
|
{
|
||
|
[SerializeField] private Transform firePoint;
|
||
|
[SerializeReference,SubclassSelector] private IBulletService bulletService;
|
||
|
[SerializeField] private bool forceFire;
|
||
|
private AssetableGun _gun=>assetableItem as AssetableGun;
|
||
|
|
||
|
private readonly IntervalUpdate fireInterval = new();
|
||
|
|
||
|
public override void Entry()
|
||
|
{
|
||
|
base.Entry();
|
||
|
fireInterval.Interval = _gun.FireMode.FireRate is 0 ? 1 : 1f/_gun.FireMode.FireRate;
|
||
|
UnityEntity.AddListener<BITConstant.Command.AttackCommand>(OnAttack);
|
||
|
}
|
||
|
public override void Exit()
|
||
|
{
|
||
|
base.Exit();
|
||
|
UnityEntity.RemoveListener<BITConstant.Command.AttackCommand>(OnAttack);
|
||
|
}
|
||
|
|
||
|
public override void OnUpdate(float deltaTime)
|
||
|
{
|
||
|
if (forceFire && fireInterval.AllowUpdate)
|
||
|
{
|
||
|
OnAttack(new BITConstant.Command.AttackCommand());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void OnAttack(BITConstant.Command.AttackCommand obj)
|
||
|
{
|
||
|
bulletService.Spawn(new SpawnBullet()
|
||
|
{
|
||
|
forward = firePoint.forward,
|
||
|
initialDamage = _gun.InitialDamage,
|
||
|
initiator = Entity.Id,
|
||
|
pos = firePoint.position,
|
||
|
rot = firePoint.rotation,
|
||
|
startSpeed = _gun.InitialBulletSpeed,
|
||
|
InitialForce = _gun.InitialBulletForce,
|
||
|
});
|
||
|
UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Fire);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|