80 lines
2.8 KiB
C#
Executable File
80 lines
2.8 KiB
C#
Executable File
using Cal.DataTable;
|
|
using ET.EventType;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace ET
|
|
{
|
|
public class MoveToCityTransPointNode : AINode
|
|
{
|
|
public override bool Check(Unit unit)
|
|
{
|
|
UnitScene unitScene = unit.GetComponent<UnitScene>();
|
|
if (unitScene.MapId / 100 == Sys_SceneId.Scene_MainCity)
|
|
{
|
|
if (unit.GetComponent<AIComponent>().GetData<bool>("hasBuyInShop"))
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public override async ETVoid Run(Unit unit, ETCancellationToken cancelToken)
|
|
{
|
|
while (true)
|
|
{
|
|
Vector3 nextPoint = FindNextPoint();
|
|
if (AppConfig.inst.isTest)
|
|
Log.Info($"【{UserComponent.Instance.Get(unit.Id)?.NickName} ({unit.Id})】移动到城镇传送点");
|
|
bool ret = await MoveHelper.MoveTo(unit,nextPoint, cancelToken); // 移动到目标点, 返回false表示协程取消
|
|
if (!ret)
|
|
{
|
|
return;
|
|
}
|
|
// 停留两秒, 注意这里要能取消,任何协程都要能取消
|
|
ret = await TimerComponent.Instance.WaitAsync(1000, cancelToken);
|
|
if (!ret)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (AppConfig.inst.isTest)
|
|
Log.Info($"【{UserComponent.Instance.Get(unit.Id)?.NickName} ({unit.Id})】城镇传送");
|
|
if (!await CityTrans(unit))
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
private async ETTask<bool> CityTrans(Unit unit)
|
|
{
|
|
if (unit.teamState == TeamState.Fight)
|
|
{
|
|
Log.Error($"【{UserComponent.Instance.Get(unit.Id)?.NickName} ({unit.Id})】战斗状态");
|
|
return false;
|
|
}
|
|
PlayerData component = unit.GetComponent<PlayerData>();
|
|
if ((bool)component && component.IsBattleIdle)
|
|
{
|
|
Log.Error($"【{UserComponent.Instance.Get(unit.Id)?.NickName} ({unit.Id})】挂机状态");
|
|
return false;
|
|
}
|
|
int mapId = 1001101;
|
|
await Game.EventSystem.Publish(new ChangeMap
|
|
{
|
|
unit = unit,
|
|
mapId = mapId
|
|
});
|
|
return true;
|
|
}
|
|
|
|
private Vector3 FindNextPoint()
|
|
{
|
|
SceneTransConfig sceneTransConfig = SceneTransConfigCategory.Instance.Get(SceneTransConfigId.Scene_MainCity);
|
|
SceneTransConfig.TransPos transPos = sceneTransConfig.TransPosArr[0];
|
|
return new Vector2(transPos.TransPos_x, transPos.TransPos_y);
|
|
}
|
|
}
|
|
}
|