zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Server/Hotfix/Game/AI/BuyInShopNode.cs

45 lines
1.5 KiB
C#
Raw Normal View History

2021-04-09 00:48:56 +08:00
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)
2021-04-10 19:49:32 +08:00
{
if (!unit.GetComponent<AIComponent>().GetData<bool>("hasBuyInShop"))
return true;
}
2021-04-09 00:48:56 +08:00
return false;
}
public override async ETVoid Run(Unit unit, ETCancellationToken cancelToken)
{
2021-04-10 19:49:32 +08:00
while (true)
2021-04-09 00:48:56 +08:00
{
2021-04-10 19:49:32 +08:00
NPCBase nPCBase = NPCBaseCategory.Instance.Get(NPCBaseId.);
2021-04-11 19:50:39 +08:00
Vector2 targetPos = new Vector2(nPCBase.PosX, nPCBase.PosY);
2021-04-10 19:49:32 +08:00
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);
2021-04-09 00:48:56 +08:00
}
}
}
}