99 lines
2.6 KiB
C#
99 lines
2.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using Cysharp.Threading.Tasks;
|
|
using Game.Pathfinding;
|
|
using Game.Player;
|
|
using Game.Room;
|
|
using UnityEngine;
|
|
|
|
namespace Game.Boss
|
|
{
|
|
public interface IBoss
|
|
{
|
|
string name { get; }
|
|
GameObject self { get; }
|
|
BossData data { get; }
|
|
BossInfo info { get; }
|
|
IRoom room { get; }
|
|
bool isMoving { get; }
|
|
|
|
UniTask<float> WaitMoveRoomAndKillAsync(CancellationToken token);
|
|
|
|
void Init();
|
|
void Dispose();
|
|
}
|
|
|
|
public class BossData
|
|
{
|
|
}
|
|
|
|
public class Boss : IBoss
|
|
{
|
|
private string _name;
|
|
private GameObject _self;
|
|
private IRoom _room;
|
|
private bool _isMoving;
|
|
private BossInfo _info;
|
|
private IBFSManager _bfsManager;
|
|
private BossData _data;
|
|
|
|
public string name => this._name;
|
|
|
|
public GameObject self => this._self;
|
|
|
|
public BossData data => this._data;
|
|
|
|
public BossInfo info => this._info;
|
|
|
|
public IRoom room => this._room;
|
|
|
|
public bool isMoving => this._isMoving;
|
|
|
|
public Boss(GameObject gameObject, IRoom room, IBFSManager bfs)
|
|
{
|
|
this._self = gameObject;
|
|
this._name = room.roomName;
|
|
this._room = room;
|
|
this._info = gameObject.GetComponent<BossInfo>();
|
|
this._info.SetBoss(this);
|
|
this._isMoving = true;
|
|
this._bfsManager = bfs;
|
|
this._data = new BossData();
|
|
this._isMoving = false;
|
|
}
|
|
|
|
public async UniTask<float> WaitMoveRoomAndKillAsync(CancellationToken token)
|
|
{
|
|
var wayPoints = this._bfsManager.FindPath(this._info.birthPoint, _room.roomInfo.room_Center);
|
|
await this.MoveAsync(wayPoints, token);
|
|
Debug.Log("Move finish !!!");
|
|
await this._info.Kill(token);
|
|
return 0;
|
|
}
|
|
|
|
private async UniTask<bool> MoveAsync(List<WayPoint> wayPoint, CancellationToken token)
|
|
{
|
|
if (this._isMoving) return false;
|
|
_isMoving = true;
|
|
|
|
await this._info.MoveAsync(wayPoint, token);
|
|
this._isMoving = false;
|
|
return true;
|
|
}
|
|
|
|
public virtual void Init()
|
|
{
|
|
}
|
|
|
|
public virtual void Dispose()
|
|
{
|
|
this._info.Dispose();
|
|
GameObject.Destroy(this._self);
|
|
this._room = null;
|
|
this._isMoving = false;
|
|
this._info = null;
|
|
this._bfsManager = null;
|
|
this._self = null;
|
|
}
|
|
}
|
|
} |