Files
JJBB/Assets/Project/Script/Obj/Obj_Characters/Obj_TeleportPoint.cs
2024-08-23 15:49:34 +08:00

177 lines
5.7 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/********************************************************************************
* 文件名: TeleportPoint.cs
* 全路径: \Script\Player\TeleportPoint.cs
* 创建人: 李嘉
* 创建时间2013-10-25
*
* 功能说明:游戏传送点逻辑
* 修改记录:
*********************************************************************************/
using Games.Events;
using Games.GlobeDefine;
using GCGame;
using GCGame.Table;
using Module.Log;
using UnityEngine;
namespace Games.LogicObj
{
public class Obj_Teleport_Init_Data : ObjParent_Init_Data
{
public Tab_Teleport Teleport;
public Obj_Teleport_Init_Data()
{
CleanUp();
}
public override void CleanUp()
{
base.CleanUp();
Teleport = null;
}
}
public class Obj_TeleportPoint : ObjParent
{
public Tab_Teleport teleportData;
private bool _active;
private TeleportDistanceModule _distanceModule;
private bool m_bEnterPKSceneCancel;
private GameObject _rootObj;
public Obj_TeleportPoint()
{
m_ObjType = GameDefine_Globe.OBJ_TYPE.OBJ_TELEPORTPOINT;
}
public override UIPathData HeadUiPath
{
get { return Obj_NPCHeadUI.pathData; }
}
public override bool Init(ObjParent_Init_Data initData)
{
var result = base.Init(initData);
if (!result)
return false;
var teleport = initData as Obj_Teleport_Init_Data;
if (teleport == null || teleport.Teleport == null)
{
gameObject.SetActive(false);
Destroy(gameObject);
return false;
}
enabled = false;
teleportData = teleport.Teleport;
gameObject.name = "Teleport_" + teleportData.Id;
_distanceModule = new TeleportDistanceModule(m_ObjTransform, teleportData.ActiveRadius);
_active = true;
return true;
}
protected override void Awake()
{
base.Awake();
_rootObj = transform.GetChild(0).gameObject;
}
protected void OnBecameVisible()
{
enabled = true;
if (_rootObj)
_rootObj.SetActive(true);
}
protected void OnBecameInvisible()
{
enabled = false;
if (_rootObj)
_rootObj.SetActive(false);
}
private void Update()
{
if (_active)
{
var mainPlayer = _distanceModule.UpdateDistance();
// 仅允许走路触发传送机制
// 客户端跟随的玩家不主动发起传送。如果之后修改为走路流程,也应该由服务器发起传送,以减少意料外情况的发生
if (mainPlayer != null && !mainPlayer.IsFollowTeam && mainPlayer.MovementState <= MoveState.MainPlayMove && !mainPlayer.IsMountClient())
if (teleportData.DstSceneID < 0)
{
LogModule.ErrorLog("同场景传送已经改为JumpPoint处理检查Teleport配表并移动到Jump表中");
}
// 跨场景传送
else if (Utils.IsCanPK(teleportData.DstSceneID) &&
!Utils.IsIncPKValue(teleportData.DstSceneID))
{
if (!m_bEnterPKSceneCancel)
{
// 永久锁定传送点,直到玩家做出决策
_active = false;
MessageBoxLogic.OpenOKCancelBox(StrDictionary.GetClientDictionaryString("#{2672}"), "",
EnterNonePKValueSceneOK, EnterNonePKValueSceneCancel);
}
}
else
{
SendChangeScene();
}
}
}
private void EnterNonePKValueSceneOK()
{
if (_distanceModule != null)
{
_distanceModule.RefreshTime();
_active = true;
}
if (teleportData != null)
{
SendChangeScene();
teleportData = null;
m_bEnterPKSceneCancel = false;
}
}
private void EnterNonePKValueSceneCancel()
{
if (_distanceModule != null)
{
_distanceModule.RefreshTime();
_active = true;
}
m_bEnterPKSceneCancel = true;
}
private void SendChangeScene()
{
//向服务器发起切场景请求
if (GameManager.gameManager.OnLineState)
{
//自动寻路处理
GameManager.gameManager.AutoSearch.ProcessTelepoint(this);
Singleton<ObjManager>.Instance.MainPlayer.startGhost = Time.unscaledTime + 5;
var sceneData =
CommonUtility.TryGetTable(teleportData.DstSceneID, a => TableManager.GetSceneClassByID(a, 0));
if (sceneData != null)
{
SceneData.RequestChangeScene((int)CG_REQ_CHANGE_SCENE.CHANGETYPE.TELEPORT, teleportData.Id,teleportData.DstSceneID, -1, (int)teleportData.DstPosX, (int)teleportData.DstPosZ);
}
}
else
{
//自动寻路处理
GameManager.gameManager.AutoSearch.ProcessTelepoint(this);
LoadingWindow.LoadScene((GameDefine_Globe.SCENE_DEFINE) teleportData.DstSceneID);
}
}
}
}