Frame/Assets/Scripts/Boss/IBoss.cs

93 lines
2.4 KiB
C#
Raw Normal View History

2024-04-09 13:22:52 +08:00
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
2024-04-09 13:22:52 +08:00
{
public interface IBoss
{
string name { get; }
GameObject self { get; }
BossData data { get; }
BossInfo info { get; }
IRoom room { get; }
bool isMoving { get; }
void SetGameObject(GameObject gameObject, IRoom room);
2024-04-09 13:22:52 +08:00
UniTask<float> WaitMoveRoomAndKillAsync(CancellationToken token);
2024-04-09 13:22:52 +08:00
// UniTask<bool> MoveAsync(List<WayPoint> wayPoint, CancellationToken token);
void Init();
void Dispose();
}
2024-04-09 13:22:52 +08:00
public class BossData
{
}
2024-04-09 13:22:52 +08:00
public class Boss : IBoss
{
private string _name;
private GameObject _self;
private IRoom _room;
private bool _isMoving;
private BossInfo _info;
2024-04-09 13:22:52 +08:00
public string name => this._name;
2024-04-09 13:22:52 +08:00
public GameObject self => this._self;
2024-04-09 13:22:52 +08:00
public BossData data { get; }
2024-04-09 13:22:52 +08:00
public BossInfo info => this._info;
2024-04-09 13:22:52 +08:00
public IRoom room => this._room;
2024-04-09 13:22:52 +08:00
public bool isMoving => this._isMoving;
2024-04-09 13:22:52 +08:00
public void SetGameObject(GameObject gameObject, IRoom room)
{
this._self = gameObject;
this._name = room.roomName;
this._room = room;
this._info = gameObject.GetComponent<BossInfo>();
this._info.SetBoss(this);
this._isMoving = true;
}
2024-04-09 13:22:52 +08:00
public async UniTask<float> WaitMoveRoomAndKillAsync(CancellationToken token)
{
var wayPoints = Game.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;
}
2024-04-09 13:22:52 +08:00
private async UniTask<bool> MoveAsync(List<WayPoint> wayPoint, CancellationToken token)
{
if (!this._isMoving) return false;
2024-04-09 13:22:52 +08:00
_isMoving = false;
2024-04-09 13:22:52 +08:00
// var endPos = this._room.roomInfo.GetJoinPosition();
// await this._info.MoveAsync(wayPoint, endPos, token);
await this._info.MoveAsync(wayPoint, token);
this._isMoving = true;
return true;
}
2024-04-09 13:22:52 +08:00
public virtual void Init()
{
}
2024-04-09 13:22:52 +08:00
public virtual void Dispose()
{
this._info.Dispose();
}
2024-04-09 13:22:52 +08:00
}
}