45 lines
1.5 KiB
C#
Executable File
45 lines
1.5 KiB
C#
Executable File
using Cal.DataTable;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace ET
|
|
{
|
|
public class BuyInShopNode : 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)
|
|
{
|
|
NPCBase nPCBase = NPCBaseCategory.Instance.Get(NPCBaseId.普通商店);
|
|
Vector2 targetPos = new Vector2(nPCBase.PosX, nPCBase.PosY);
|
|
if (AppConfig.inst.isTest)
|
|
Log.Info($"【{UserComponent.Instance.Get(unit.Id)?.NickName} ({unit.Id})】移动到商人");
|
|
bool ret = await MoveHelper.MoveTo(unit, targetPos, cancelToken); // 移动到目标点, 返回false表示协程取消
|
|
if (!ret)
|
|
{
|
|
return;
|
|
}
|
|
// 停留两秒, 注意这里要能取消,任何协程都要能取消
|
|
ret = await TimerComponent.Instance.WaitAsync(1000, cancelToken);
|
|
if (!ret)
|
|
{
|
|
return;
|
|
}
|
|
unit.GetComponent<AIComponent>().SetData("hasBuyInShop", true);
|
|
}
|
|
}
|
|
}
|
|
}
|