152 lines
4.8 KiB
C#
152 lines
4.8 KiB
C#
using Thousandto.Code.Center;
|
|
using Thousandto.Code.Logic.LocalPlayerBT;
|
|
using UnityEngine;
|
|
|
|
namespace Thousandto.Code.Logic
|
|
{
|
|
//寻路系统
|
|
public class PathSearchSystem
|
|
{
|
|
#region //私有变量
|
|
private PathFindType Type; //寻路类型
|
|
private bool IsCrossMap; //是否跨地图
|
|
#endregion
|
|
|
|
#region //NPC
|
|
private int NpcID = 0; //寻路到的NPC的id
|
|
#endregion
|
|
|
|
#region //Monster
|
|
private int MonsterID; //寻路到的Monster的id
|
|
private int TaskID; //Taskid
|
|
#endregion
|
|
|
|
#region //Pos
|
|
private int TargetMapId; //寻路到指定地图
|
|
private Vector3 TargetPos; //寻路到指定位置
|
|
#endregion
|
|
|
|
#region //公共函数
|
|
//跨地图寻路回调
|
|
public void CrossMapCallBack()
|
|
{
|
|
if(IsCrossMap)
|
|
{
|
|
IsCrossMap = false;
|
|
switch (Type)
|
|
{
|
|
case PathFindType.NPC:
|
|
SearchPathToNpcTalk(NpcID);
|
|
break;
|
|
case PathFindType.Monster:
|
|
SearchPathToKillMonster(MonsterID, TaskID);
|
|
break;
|
|
case PathFindType.Pos:
|
|
SearchPathToPos(TargetMapId, TargetPos);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
//寻路到NPC对话
|
|
public void SearchPathToNpcTalk(int npcid)
|
|
{
|
|
LocalPlayer lp = GameCenter.GameSceneSystem.GetLocalPlayer();
|
|
if (lp == null)
|
|
return;
|
|
MapPathInfo.Position mapPos = GameCenter.PathFinderSystem.GetNpcPosition(npcid);
|
|
if(mapPos == null)
|
|
{
|
|
//Debug.LogError(string.Format("=====npcid {0} not exist====", npcid));
|
|
return;
|
|
}
|
|
int currentMapId = GameCenter.GameSceneSystem.ActivedScene.Cfg.MapId;
|
|
if (currentMapId == mapPos.MapId)
|
|
{
|
|
IsCrossMap = false;
|
|
PlayerBT.Task.TaskTalkToNpc(npcid);
|
|
}
|
|
else
|
|
{
|
|
NpcID = npcid;
|
|
IsCrossMap = true;
|
|
Type = PathFindType.NPC;
|
|
lp.Action_CrossMapTran(mapPos.MapId);
|
|
}
|
|
}
|
|
//寻路到打Monster
|
|
public void SearchPathToKillMonster(int monsterid,int taskid = 0)
|
|
{
|
|
LocalPlayer lp = GameCenter.GameSceneSystem.GetLocalPlayer();
|
|
if (lp == null)
|
|
return;
|
|
int campId = 1;// lp.PropMoudle.BirthGroup;
|
|
MapPathInfo.Position mapPos = GameCenter.PathFinderSystem.GetMonsterPosition(monsterid,campId);
|
|
int currentMapId = GameCenter.GameSceneSystem.ActivedScene.Cfg.MapId;
|
|
if (currentMapId == mapPos.MapId)
|
|
{
|
|
IsCrossMap = false;
|
|
PlayerBT.Task.TaskKillMonster(monsterid,taskid);
|
|
}
|
|
else
|
|
{
|
|
MonsterID = monsterid;
|
|
TaskID = taskid;
|
|
IsCrossMap = true;
|
|
Type = PathFindType.Monster;
|
|
lp.Action_CrossMapTran(mapPos.MapId);
|
|
}
|
|
}
|
|
//寻路到指定地图和位置
|
|
public void SearchPathToPos(int mapid,Vector3 pos, long cloneMapId = 0)
|
|
{
|
|
LocalPlayer lp = GameCenter.GameSceneSystem.GetLocalPlayer();
|
|
if (lp == null)
|
|
return;
|
|
TargetMapId = mapid;
|
|
TargetPos = pos;
|
|
int currentMapId = GameCenter.GameSceneSystem.ActivedScene.Cfg.MapId;
|
|
if (currentMapId == mapid)
|
|
{
|
|
IsCrossMap = false;
|
|
lp.Action_MoveTo(pos);
|
|
}
|
|
else
|
|
{
|
|
IsCrossMap = true;
|
|
Type = PathFindType.Pos;
|
|
lp.Action_CrossMapTran(mapid, null, cloneMapId);
|
|
}
|
|
}
|
|
//寻路去打指定位置的boss
|
|
public void SearchPathToPosBoss(bool state,Vector2 pos,int monsterId)
|
|
{
|
|
LocalPlayer lp = GameCenter.GameSceneSystem.GetLocalPlayer();
|
|
if (lp == null)
|
|
return;
|
|
if (state)
|
|
{
|
|
//先停止挂机
|
|
GameCenter.LuaSystem.Adaptor.EndMandate();
|
|
PlayerBT.FightBoss.Write(pos,monsterId);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region //消除寻路状态
|
|
public void EraseAll()
|
|
{
|
|
IsCrossMap = false;
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
//寻路的类型
|
|
public enum PathFindType
|
|
{
|
|
None,
|
|
NPC, //寻NPC
|
|
Monster, //寻Monster
|
|
Pos, //寻位置点
|
|
}
|
|
}
|