网上演练贵港万达广场(人员密集)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1300 lines
48 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using AX.NetworkSystem;
using AX.MessageSystem;
using System;
using UnityEngine.AI;
using AX.InputSystem;
using UnityEngine.EventSystems;
using System.Linq;
public enum MoveState
{
IDLE,
MOVEFREE,
//GUIDED,
FALLDOWN,
//FIREMANCLOSE
}
public class TrappedMoveFree : MonoBehaviour
{
//private Ray ray = new Ray();
/// <summary>
/// 随机移动位置点
/// </summary>
private Vector3 randomVector = Vector3.zero;
/// <summary>
/// 最近一次遇到的火的位置
/// </summary>
private Vector3 DangerousLastmet = Vector3.zero;
/// <summary>
/// 检测危险的距离
/// </summary>
public float MetDangerousDistance = 10;
/// <summary>
/// 每次随机点位的最大移动距离
/// </summary>
private float MaxRange = 15;
private bool DrillStart;
public bool FireManNear = false;
private NavMeshAgent nav;
/// <summary>
/// 是否被急救
/// </summary>
//public bool First_Aid;
/// <summary>
/// 是否已被安抚
/// </summary>
//public bool Pacify;
/// <summary>
/// 是否被引导
/// </summary>
public bool Guidance;
/// <summary>
/// 引导点索引
/// </summary>
// private int GuidIndex = 0;
/// <summary>
/// 是否遇到危险
/// </summary>
public bool MeetDangerous;
/// <summary>
/// 最后一个操作该被困人员的消防员
/// </summary>
public long FireManlastID;
public float arrive;
private Transform P_SafeArea;
[SerializeField]
/// <summary>
/// 消防员设置的寻路点
/// </summary>
public List<Vector3> guidPoint = new List<Vector3>();
RaycastHit hit;
/// <summary>
/// 是否被消防员移动
/// </summary>
public bool IsMoveState;
//移动跟随的消防员
public GameObject MoveFireman;
public bool firemanHit;
public float Haemal;
private Animator anim;
[SerializeField]
public MoveState movestate;
/// <summary>
/// 寻路目标点,如果为消防员移动后,将该点设为消防员发来的点,将其设置为寻路点之后再重置为zero用以做移动状态的判断
/// </summary>
private Vector3 targetPosition;
public SceneType scenetype;
//触发器里面的消防员
//public List<GameObject> firemanList = new List<GameObject>();
//结束移动或引导
public bool OverMoveOrGuidance = false;
/// <summary>
/// 附近危险列表
/// </summary>
private List<GameObject> DangerousList = new List<GameObject>();
private Transform P_Disasters;
//private bool DangerousOverTwo=false;
private float timer = 1f;
/// <summary>
/// 自己本客户端,一个是用来控制文字提示,一个是用来控制引导时,会出现不正常引导的情况
/// </summary>
public bool IsselfClient = true;
public float distance;
/// <summary>
/// 营救该被困人员的消防员userId,报告里要用到
/// </summary>
public long SaveFrirmanUserId;
/// <summary>
/// 演练开始时的起始位置点,总在该点周围移动
/// </summary>
public Vector3 originalpoint;
private BaseHaemalController basehaemal;
/// <summary>
/// 是否被移动或者被急救
/// </summary>
public bool isBefirstAirOrMoving = false;
/// <summary>
/// 移动生命少于50的伤员时,周围闲置最近的消防员
/// </summary>
private List<KeyValuePair<GameObject, float>> freeFiremanAround = new List<KeyValuePair<GameObject, float>>();
private Transform p_fireman;
public bool falldownlock = false;
public bool IsSetPoint = false;
public bool IsBefirstAirOrMoving
{
get
{
return isBefirstAirOrMoving;
}
set
{
isBefirstAirOrMoving = value;
if (value)
{
CancelInvokeRandom();
GetComponent<TrappedPathFind>().StopAllCoroutines();
TargetPosition = transform.position;
if (nav.enabled)
nav.SetDestination(transform.position);
GetComponent<TrappedPathFind>().pathFindEnable = false;
if (GetComponent<BaseHaemalController>().Haemal > 50)
{
if (movestate != MoveState.IDLE)
{
movestate = MoveState.IDLE;
anim.SetFloat("Speed", 0f);
}
}
}
else
{
GetComponent<TrappedPathFind>().pathFindEnable = true;
}
WounderFirstAidOrMoveStateSyncData arg = new WounderFirstAidOrMoveStateSyncData();
arg.SendUserID = CurrentUserInfo.mySelf.Id;
arg.gameObjID = GetComponent<BaseGameObjInfo>().gameObjID;
arg.IsBeFristAidOrMove = value;
NetworkManager.Default.SendAsync("WOUNDER_FRISTAID_OR_MOVE_STATE_SYNC", arg);
}
}
public Vector3 TargetPosition
{
get
{
return targetPosition;
}
set
{
Debug.Log("<color=#00aa00ff>" + "dssfsda" + "</color>");
targetPosition = value;
}
}
public void OnEnable()
{
//MessageDispatcher.AddListener("SetGuidpathIndex", AddGuidIndex);
MessageDispatcher.AddListener("MOVE_MAN_COMMAND", MoveExcute);
MessageDispatcher.AddListener("GUIDANCE_MAN_COMMAND", GuidanceTrapped);
MessageDispatcher.AddListener("FRISTAID_MAN_COMMAND", FristAidTrapped);
MessageDispatcher.AddListener("TRAPPED_MOVE_FOLLOW_GUIDE_POINT_COMMAND", MoveFollowGuidPoint);
MessageDispatcher.AddListener("ENDMOVE", EndMove);
RescuedValue.getAllRescuedTrapped += addMyRescue;
DrillBeginButton.getUnrescuedCount += addMyUnrescue;
TrappedInfo.getAllTrappedCount += addMyTrapped;
TrappedInfo.getTrappedRescuedCount += addMyRescue;
TrappedTime.getAllWoundedTrappedCount += addMyUnrescue;
}
public void OnDestroy()
{
// MessageDispatcher.RemoveListener("SetGuidpathIndex", AddGuidIndex);
MessageDispatcher.RemoveListener("MOVE_MAN_COMMAND", MoveExcute);
MessageDispatcher.RemoveListener("GUIDANCE_MAN_COMMAND", GuidanceTrapped);
MessageDispatcher.RemoveListener("FRISTAID_MAN_COMMAND", FristAidTrapped);
MessageDispatcher.RemoveListener("TRAPPED_MOVE_FOLLOW_GUIDE_POINT_COMMAND", MoveFollowGuidPoint);
MessageDispatcher.RemoveListener("ENDMOVE", EndMove);
RescuedValue.getAllRescuedTrapped -= addMyRescue;
DrillBeginButton.getUnrescuedCount -= addMyUnrescue;
TrappedInfo.getAllTrappedCount -= addMyTrapped;
TrappedInfo.getTrappedRescuedCount -= addMyRescue;
TrappedTime.getAllWoundedTrappedCount -= addMyUnrescue;
}
public void OnDisable()
{
//MessageDispatcher.RemoveListener("SetGuidpathIndex", AddGuidIndex);
MessageDispatcher.RemoveListener("MOVE_MAN_COMMAND", MoveExcute);
MessageDispatcher.RemoveListener("GUIDANCE_MAN_COMMAND", GuidanceTrapped);
MessageDispatcher.RemoveListener("FRISTAID_MAN_COMMAND", FristAidTrapped);
MessageDispatcher.RemoveListener("TRAPPED_MOVE_FOLLOW_GUIDE_POINT_COMMAND", MoveFollowGuidPoint);
MessageDispatcher.RemoveListener("ENDMOVE", EndMove);
RescuedValue.getAllRescuedTrapped -= addMyRescue;
DrillBeginButton.getUnrescuedCount -= addMyUnrescue;
TrappedInfo.getAllTrappedCount -= addMyTrapped;
TrappedInfo.getTrappedRescuedCount -= addMyRescue;
TrappedTime.getAllWoundedTrappedCount -= addMyUnrescue;
}
private void EndMove(IMessage obj)
{
var fireman = (GameObject)obj.Data;
if (IsMoveState)
{
if (MoveFireman == fireman)
{
SaveFrirmanUserId = fireman.GetComponent<BaseGameObjInfo>().UserID;
//同步
TrappedMoveFollowFiremanSyncData arg = new TrappedMoveFollowFiremanSyncData();
arg.SendUserID = CurrentUserInfo.mySelf.Id;
arg.IsEnd = true;
arg.SaveFiremanUserID = SaveFrirmanUserId;
arg.TrappedID = GetComponent<BaseGameObjInfo>().gameObjID;
arg.FiremanID = MoveFireman.GetComponent<BaseGameObjInfo>().gameObjID;
NetworkManager.Default.SendAsync("TRAPPED_MOVE_FOLLOW_FIREMAN_SYNC", arg);
TargetPosition = transform.position;
MoveFireman.GetComponent<FiremanMoveTrapped>().trappedlist.Clear();
MoveFireman = null;
IsMoveState = false;
OverMoveOrGuidance = true;
TrappedTime.CheckStopTime();
//MessageDispatcher.SendMessage("SomeoneOutOfTrap"); //通知火场信息-疏散救生-被困时间部分更新,看是否可以停止计时
}
}
}
private void FristAidTrapped(IMessage obj)
{
var info = (ForcibleEntryCmdArgs)obj.Data;
GameObject fireMan = EntitiesManager.Instance.GetEntityByID(info.fireManID);
if (info.gameObjID == GetComponent<BaseGameObjInfo>().gameObjID)
{
if (Haemal <= 0)
{
LoadPromptWin.Instance.LoadTextPromptWindow("该人员已死亡,不能操作", 2f);
return;
}
if (IsBefirstAirOrMoving)
{
LoadPromptWin.Instance.LoadTextPromptWindow("该人员正在被急救或者移动,不能操作", 2f);
return;
}
//if (MeetDangerous)
//{
// LoadPromptWin.Instance.LoadTextPromptWindow("该人员正在逃离灾情,不能操作", 2f);
// return;
//}
if (Vector3.Distance(fireMan.transform.position, transform.position) > 3)
{
LoadPromptWin.Instance.LoadTextPromptWindow("请靠近需救助人员", 1f);
firemanHit = true;
// CancelInvoke("RandomPoint");
// StartCoroutine(WaitForFireman());
}
else
{
if (basehaemal)
{
basehaemal.skillList.Add(new KeyValuePair<GameObject, FireManSkills>(fireMan, FireManSkills.FristAid));
}
//显示急救进度条
GetComponent<CreatHaemalUI>().haemal.GetComponent<HaemalStrand>().FirstAir(fireMan);
IsBefirstAirOrMoving = true;
fireMan.GetComponent<AgentController>().pathFindEnable = false;
if (FireManSkillPanelController.Instance)
{
if (FireManSkillPanelController.Instance.SelectFireMan == fireMan)
{
FireManSkillPanelController.Instance.SetSkillDisable();
}
}
//同步
// StartCoroutine(firstAidText());
FireManlastID = info.fireManID;
}
}
}
private void GuidanceTrapped(IMessage obj)
{
var info = (ForcibleEntryCmdArgs)obj.Data;
GameObject fireMan = EntitiesManager.Instance.GetEntityByID(info.fireManID);
if (info.gameObjID == GetComponent<BaseGameObjInfo>().gameObjID)
{
if (OverMoveOrGuidance)
{
LoadPromptWin.Instance.LoadTextPromptWindow("该人员已被营救,不能再进行操作", 1f);
return;
}
//if (MeetDangerous)
//{
// LoadPromptWin.Instance.LoadTextPromptWindow("该人员正在逃离灾情,不能操作", 2f);
// return;
//}
if (Guidance)
{
LoadPromptWin.Instance.LoadTextPromptWindow("该人员正被引导,不能再进行操作", 1f);
return;
}
if (IsBefirstAirOrMoving)
{
LoadPromptWin.Instance.LoadTextPromptWindow("该人员正在被急救或者移动,不能操作", 2f);
return;
}
if (Vector3.Distance(fireMan.transform.position, transform.position) > 3)
{
LoadPromptWin.Instance.LoadTextPromptWindow("请靠近需救助人员", 1f);
firemanHit = true;
//CancelInvoke("RandomPoint");
// StartCoroutine(WaitForFireman());
}
else
{
if (Haemal <= 50)
{
LoadPromptWin.Instance.LoadTextPromptWindow("该人员已昏迷,不能引导", 1f);
return;
}
Guidance = true;
IsSetPoint = true;
if (MeetDangerous)
{
MeetDangerous = false;
}
CancelInvokeRandom();
StopAllCoroutines();
nav.SetDestination(transform.position);
if (GetComponent<BaseHaemalController>())
{
basehaemal.skillList.Add(new KeyValuePair<GameObject, FireManSkills>(fireMan, FireManSkills.Guidance));
}
FireManlastID = info.fireManID;
//禁用触发器,防止其他消防员再次引导该被困人员
//GetComponent<BoxCollider>().enabled = false;
//if (MeetDangerous)
//{
// MeetDangerous = false;
//}
movestate = MoveState.IDLE;
LoadPromptWin.Instance.LoadTextPromptWindow("即将开始引导,左键点击场景设置引导点,关闭或选择其他技能后被困人员将按照引导点移动", 3f);
fireMan.GetComponent<FiremanMoveTrapped>().GuidanceTrapped = gameObject;
InputManager.IsGuidance = true;
//firemanList.Clear();
//firemanList.Add(fireMan);
//引导同步
TrappedGuidanceSyncData argguide = new TrappedGuidanceSyncData();
argguide.SaveFiremanUserID = SaveFrirmanUserId;
argguide.IsSetPoint = true;
argguide.SendUserID = CurrentUserInfo.mySelf.Id;
argguide.gameObjID = GetComponent<BaseGameObjInfo>().gameObjID;
NetworkManager.Default.SendAsync("TRAPPED_GUIDANCE_SYNC", argguide);
}
}
}
/// <summary>
/// 对被困人员使用移动技能
/// </summary>
/// <param name="obj"></param>
private void MoveExcute(IMessage obj)
{
var info = (ForcibleEntryCmdArgs)obj.Data;
GameObject fireMan = EntitiesManager.Instance.GetEntityByID(info.fireManID);
if (info.gameObjID == GetComponent<BaseGameObjInfo>().gameObjID)
{
if (IsBefirstAirOrMoving)
{
LoadPromptWin.Instance.LoadTextPromptWindow("该人员正在被急救或者移动,不能操作", 2f);
return;
}
//if(MeetDangerous)
//{
// LoadPromptWin.Instance.LoadTextPromptWindow("该人员正在逃离灾情,不能操作", 2f);
// return;
//}
if (OverMoveOrGuidance == true)
{
LoadPromptWin.Instance.LoadTextPromptWindow("该人员被营救,不能再进行操作", 1f);
return;
}
//if (fireMan.GetComponent<FiremanMoveTrapped>().trappedlist.Count > 0)
//{
// if (fireMan.GetComponent<FiremanMoveTrapped>().trappedlist.Contains(info.gameObjID))
// {
// LoadPromptWin.Instance.LoadTextPromptWindow("该人员已跟随移动", 1f);
// return;
// }
// else
// {
// LoadPromptWin.Instance.LoadTextPromptWindow("不能同时移动多名人员", 1f);
// return;
// }
//}
if (!IsMoveState && !OverMoveOrGuidance)
{
if (Haemal > 50)
{
LoadPromptWin.Instance.LoadTextPromptWindow("该被困人员不需要移动", 1f);
return;
}
if (Vector3.Distance(fireMan.transform.position, transform.position) > 3)
{
LoadPromptWin.Instance.LoadTextPromptWindow("请靠近需救助人员", 1f);
firemanHit = true;
// CancelInvoke("RandomPoint");
// StartCoroutine(WaitForFireman());
}
else
{
if (Haemal <= 50)
{
if (CheckFiremanAround(fireMan) == null)
{
LoadPromptWin.Instance.LoadTextPromptWindow("该人员已昏迷,需两名消防员进行移动", 2f);
return;
}
else
{//两名消防员对重伤员移动逻辑
GameObject nestestfireman = CheckFiremanAround(fireMan);
GetComponent<CreatHaemalUI>().haemal.GetComponent<HaemalStrand>().Moving(fireMan, nestestfireman);
IsBefirstAirOrMoving = true;
GetComponent<BaseHaemalController>().IsMoving = true;
falldownlock = true;
IsMoveState = true;
return;
}
}
else
{
IsMoveState = true;
if (basehaemal)
{
basehaemal.skillList.Add(new KeyValuePair<GameObject, FireManSkills>(fireMan, FireManSkills.Move));
}
FireManlastID = info.fireManID;
//GetComponentInChildren<BoxCollider>().enabled = false; //禁用触发器,防止其他消防员再次移动该被困人员
//firemanList.Clear();
//firemanList.Add(fireMan);
LoadPromptWin.Instance.LoadTextPromptWindow("移动成功,该被困人员将跟随该消防员移动,关闭或选择其他技能后将停止移动", 3f);
//将该被困人员加入对应消防员的移动列表
fireMan.GetComponent<FiremanMoveTrapped>().trappedlist.Add(gameObject.GetComponent<BaseGameObjInfo>().gameObjID);
MoveFireman = fireMan;
TargetPosition = Vector3.zero;
GetComponent<TrappedPathFind>().StopAllCoroutines();
GetComponent<NavMeshAgent>().SetDestination(transform.position);
movestate = MoveState.IDLE;
//被困人员移动同步
TrappedMoveFollowFiremanSyncData arg = new TrappedMoveFollowFiremanSyncData();
arg.SendUserID = CurrentUserInfo.mySelf.Id;
arg.IsEnd = false;
arg.TrappedID = GetComponent<BaseGameObjInfo>().gameObjID;
arg.FiremanID = MoveFireman.GetComponent<BaseGameObjInfo>().gameObjID;
NetworkManager.Default.SendAsync("TRAPPED_MOVE_FOLLOW_FIREMAN_SYNC", arg);
}
}
}
else
{
LoadPromptWin.Instance.LoadTextPromptWindow("被困人员已被其他消防员移动或引导", 1f);
}
}
}
/// <summary>
/// 返回该轻伤员附近空闲的消防员
/// </summary>
/// <param name="fireman"></param>
/// <returns></returns>
GameObject CheckFiremanAround(GameObject fireman)
{
GameObject nestest = null;
freeFiremanAround.Clear();
long userid = fireman.GetComponent<BaseGameObjInfo>().UserID;
for (int i = 0; i < p_fireman.childCount; i++)
{
if (p_fireman.GetChild(i).GetComponent<BaseGameObjInfo>().UserID == userid)
{
if (p_fireman.GetChild(i).gameObject != fireman)
{
//如果附近有空闲或者开着移动技能但是没有移动人员的消防员
if (p_fireman.GetChild(i).GetComponent<FireManControl>().workType == FireManSkills.None ||
(p_fireman.GetChild(i).GetComponent<FireManControl>().workType == FireManSkills.Move &&
p_fireman.GetChild(i).GetComponent<FiremanMoveTrapped>().trappedlist.Count < 1))
{
if (Vector3.Distance(p_fireman.GetChild(i).position, transform.position) < 3)
{
freeFiremanAround.Add(new KeyValuePair<GameObject, float>(p_fireman.GetChild(i).gameObject,
Vector3.Distance(p_fireman.GetChild(i).position, transform.position)));
}
if (freeFiremanAround.Count > 0)
{
var resert = freeFiremanAround.OrderBy(p => p.Value);
nestest = resert.ElementAt(0).Key;
}
}
}
}
}
return nestest;
}
//监听寻路点设置,按寻路点移动
private void MoveFollowGuidPoint(IMessage obj)
{
var info = (GuideLodeCmdArgs)obj.Data;
var fireman = EntitiesManager.Instance.GetEntityByID(info.FireManID);
if (info.TrappedID == GetComponent<BaseGameObjInfo>().gameObjID)
{
IsSetPoint = false;
if (Haemal <= 50)
{
LoadPromptWin.Instance.LoadTextPromptWindow("该人员已昏迷不能引导", 1f);
if (fireman.GetComponent<FiremanMoveTrapped>().GuidanceTrapped != null)
{
fireman.GetComponent<FiremanMoveTrapped>().GuidanceTrapped = null;
}
return;
}
guidPoint.Clear();
//获取引导的点
foreach (var item in info.pathpointList)
{
guidPoint.Add(item);
}
// guidPoint = info.pathpointList;
if (guidPoint.Count < 1)
{
LoadPromptWin.Instance.LoadTextPromptWindow("引导失败,未设置引导点", 1f);
return;
}
Guidance = true;
for (int i = 0; i < guidPoint.Count - 1; i++)
{
for (int k = guidPoint.Count - 2; k > i; k--)
{
float distance = Vector3.Distance(guidPoint[i], guidPoint[k]);//计算两点的距离
if (distance < 5)
{
for (int j = k; j > i; j--)
{
guidPoint.RemoveAt(j);
}
break;
}
}
}
TargetPosition = guidPoint[0];
SaveFrirmanUserId = fireman.GetComponent<BaseGameObjInfo>().UserID;
//引导同步
TrappedGuidanceSyncData argguide = new TrappedGuidanceSyncData();
argguide.SaveFiremanUserID = SaveFrirmanUserId;
argguide.Guidlist = guidPoint;
argguide.IsEnd = false;
argguide.SendUserID = CurrentUserInfo.mySelf.Id;
argguide.gameObjID = GetComponent<BaseGameObjInfo>().gameObjID;
NetworkManager.Default.SendAsync("TRAPPED_GUIDANCE_SYNC", argguide);
//TrappedPathFindingCmdArgs arg = new TrappedPathFindingCmdArgs();
//arg.hitPoint = guidPoint[0];
//targetPosition = arg.hitPoint;
////arg.gameObjID = GetComponent<BaseGameObjInfo>().gameObjID;
//arg.gameObjIdSelf = GetComponent<BaseGameObjInfo>().gameObjID;
//TrappedPathFindingCommand.Instance.Execute(GetComponent<BaseGameObjInfo>().gameObjID, arg);
CloneGameObjInfo msg = GetComponent<CloneGameObjInfo>();
Transform safe = P_SafeArea.transform.GetChild(0);
msg.buildNum = safe.GetComponent<CloneGameObjInfo>().buildNum;
msg.floorNum = safe.GetComponent<CloneGameObjInfo>().floorNum;
msg.interlayerNum = safe.GetComponent<CloneGameObjInfo>().interlayerNum;
//StartCoroutine(checkguide());
}
}
IEnumerator checkguide()
{
while (Guidance && !OverMoveOrGuidance)
{
yield return new WaitForSeconds(10f);
if (Vector3.Distance(transform.position, guidPoint[0]) > 1f)
{
if (CurrentUserInfo.mySelf.Id == CurrentUserInfo.room.Owner.UserInfo.Id)
{
TrappedPathFindingCmdArgs arg = new TrappedPathFindingCmdArgs();
arg.hitPoint = guidPoint[0];
TargetPosition = guidPoint[0];
arg.gameObjIdSelf = GetComponent<BaseGameObjInfo>().gameObjID;
TrappedPathFindingCommand.Instance.Execute(GetComponent<BaseGameObjInfo>().gameObjID, arg);
}
}
}
}
private void AddGuidIndex()
{
//if (!Guidance)
//{
// return;
//}
//if (GuidIndex >= guidPoint.Count - 1)
//{
// //movestate = MoveState.IDLE;
// return;
//}
//GuidIndex++;
guidPoint.Remove(guidPoint[0]);
TargetPosition = guidPoint[0];
if (CurrentUserInfo.room != null && CurrentUserInfo.mySelf.Id == CurrentUserInfo.room.Owner.UserInfo.Id)
{
TrappedPathFindingCmdArgs arg = new TrappedPathFindingCmdArgs();
arg.hitPoint = guidPoint[0];
TargetPosition = guidPoint[0];
arg.gameObjIdSelf = GetComponent<BaseGameObjInfo>().gameObjID;
TrappedPathFindingCommand.Instance.Execute(GetComponent<BaseGameObjInfo>().gameObjID, arg);
}
}
void Start()
{
P_Disasters = GameObject.Find("P_AllParent").transform.Find("P_Disasters");
P_SafeArea = GameObject.Find("P_AllParent/P_Tools/P_SafeArea").transform;
p_fireman = GameObject.Find("P_AllParent/P_Person/P_Fireman").transform;
basehaemal = GetComponent<BaseHaemalController>();
originalpoint = transform.position;
//firemanList = GetComponentInChildren<TriggerCtrl>().FireMenList;
nav = GetComponent<NavMeshAgent>();
anim = GetComponent<Animator>();
anim.SetFloat("Speed", 0);
if (GetComponent<BaseHaemalController>())
{
Haemal = GetComponent<BaseHaemalController>().Haemal;
}
//GameSettings.othersSettings.isStartDrill = true;
DrillStart = GameSettings.othersSettings.isStartDrill;
//被克隆出来时就已经开始演练
if (DrillStart)
{
GetDangerousList();
dangerousDetection();
if (MeetDangerous)
{
if (CurrentUserInfo.room != null && CurrentUserInfo.mySelf.Id == CurrentUserInfo.room.Owner.UserInfo.Id)
{
Vector3 dia = transform.position - DangerousLastmet;
TargetPosition = dia;
TrappedPathFindingCmdArgs arg = new TrappedPathFindingCmdArgs();
arg.hitPoint = transform.position + dia;
arg.gameObjIdSelf = GetComponent<BaseGameObjInfo>().gameObjID;
TrappedPathFindingCommand.Instance.Execute(GetComponent<BaseGameObjInfo>().gameObjID, arg);
}
}
InvokeRepeating("RandomPoint", 0f, 3f/*randominvoketime()*/);
}
}
public void FallDown()
{
if (GetComponent<CapsuleCollider>().enabled)
{
GetComponent<CapsuleCollider>().enabled = false;
// GetComponent<BoxCollider>().enabled = true;
//transform.Find("Trigger").GetComponent<BoxCollider>().center = GetComponent<BoxCollider>().center;
nav.SetDestination(transform.position);
TargetPosition = transform.position;
}
}
void Update()
{
DrillStart = GameSettings.othersSettings.isStartDrill;
//移动
//演练已经开始
if (DrillStart)
{
//if (!IsselfClient)
//{
// return;
//}
if (IsBefirstAirOrMoving)
{
return;
}
distance = Vector3.Distance(transform.position, TargetPosition);
//arrive = Vector3.Distance(targetPosition, transform.position);
Haemal = GetComponent<BaseHaemalController>().Haemal;
if (Haemal <= 50)
{
//被困人员倒下后设置碰撞器
//FallDown();
if (movestate != MoveState.FALLDOWN)
{
movestate = MoveState.FALLDOWN;
anim.SetFloat("Speed", 0);
anim.SetBool("FallDown", true);
nav.SetDestination(transform.position);
TargetPosition = transform.position;
GetComponent<TrappedPathFind>().pathFindEnable = false;
//设置碰撞器
GetComponent<CharacterController>().center = Vector3.zero;
GetComponent<CharacterController>().radius = 0.7f;
GetComponent<CharacterController>().height = 1f;
nav.enabled = false;
}
if (Guidance)
{
Guidance = false;
}
if (falldownlock == false && IsMoveState)
{
IsMoveState = false;
if (MoveFireman != null)
{
MessageDispatcher.SendMessage("Trapped_Down", GetComponent<BaseGameObjInfo>().gameObjID);
}
}
IsMoveState = false;
Guidance = false;
GetComponent<TrappedPathFind>().pathFindEnable = false;
return;
}
if (OverMoveOrGuidance)
{
if (firemanHit)
{
firemanHit = false;
}
if (anim.GetFloat("Speed") > 0)
{
anim.SetFloat("Speed", 0f);
}
if (movestate != MoveState.IDLE)
{
movestate = MoveState.IDLE;
}
return;
}
MoveStateSet();
AniamtorSet();
// arrive = Vector3.Distance(transform.position, targetPosition);
#region
//没有被消防员引导和移动,随机移动
if (!Guidance && !IsMoveState && !firemanHit)
{
GetDangerousList();
dangerousDetection();
////被使用救助技能的消防员点击
//if (firemanHit && !MeetDangerous)
//{
// return;
//}
//消防员不在附近,随机移动
//if (!FireManNear)
{
if (IsInvoking() == false)
{
if (!firemanHit)
InvokeRepeating("RandomPoint", 2f, 8f);
}
//检测范围内是否有危险
//碰到危险,反方向走
if (MeetDangerous)
{
//if (timer == 1)
//{
// if (CurrentUserInfo.room != null && CurrentUserInfo.mySelf.Id == CurrentUserInfo.room.Owner.UserInfo.Id)
// {
// Vector3 dia = transform.position - DangerousLastmet;
// targetPosition = dia;
// TrappedPathFindingCmdArgs arg = new TrappedPathFindingCmdArgs();
// arg.hitPoint = transform.position + dia;
// arg.MeetDangerous = true;
// //arg.gameObjID = GetComponent<BaseGameObjInfo>().gameObjID;
// arg.gameObjIdSelf = GetComponent<BaseGameObjInfo>().gameObjID;
// TrappedPathFindingCommand.Instance.Execute(GetComponent<BaseGameObjInfo>().gameObjID, arg);
// }
//}
//timer -= Time.deltaTime;
//if (timer <= 0)
//{
// timer = 1f;
//}
}
}
////附近有消防员, 暂时停止移动
//else
//{
// CancelInvoke("RandomPoint");
// movestate = MoveState.IDLE;
//}
}
else if (!Guidance && !IsMoveState && firemanHit && !MeetDangerous)
{
if (IsInvoking() == true)
{
// CancelInvokeRandom();
// StartCoroutine(WaitForFireman());
}
}
else if (IsBefirstAirOrMoving)
{
if (firemanHit)
{
firemanHit = false;
}
if (IsInvoking() == true)
{
CancelInvokeRandom();
}
}
//被消防员引导,按规划点位移动
else if (Guidance || IsMoveState)
{
if (firemanHit)
{
firemanHit = false;
}
if (MeetDangerous)
{
Debug.LogError("引导中遇险");
}
CancelInvoke("RandomPoint");
//引导
if (Guidance)
{
if (guidPoint.Count == 1 /*&& Vector3.Distance(transform.position, guidPoint[0]) < 2*/)
{
if (TargetPosition!=guidPoint[0])
{
Debug.Log("<color=#00aa00ff>" + "sssssssss"+ "</color>");
TargetPosition = guidPoint[0];
if (CurrentUserInfo.room != null && CurrentUserInfo.mySelf.Id == CurrentUserInfo.room.Owner.UserInfo.Id)
{
TrappedPathFindingCmdArgs arg = new TrappedPathFindingCmdArgs();
arg.hitPoint = guidPoint[0];
TargetPosition = guidPoint[0];
arg.gameObjIdSelf = GetComponent<BaseGameObjInfo>().gameObjID;
TrappedPathFindingCommand.Instance.Execute(GetComponent<BaseGameObjInfo>().gameObjID, arg);
}
}
if (Vector3.Distance(transform.position, guidPoint[0]) < 2)
{
Guidance = false;
movestate = MoveState.IDLE;
GetComponent<TrappedPathFind>().StopAllCoroutines();
GetComponent<NavMeshAgent>().enabled = false;
OverMoveOrGuidance = true;
TrappedTime.CheckStopTime();
anim.SetFloat("Speed", 0);
//InputManager.GuidanceList.Clear();
//InputManager.IsGuidance = false;
if (IsselfClient)//本客户端触发的引导提示信息
{
LoadPromptWin.Instance.LoadTextPromptWindow("被困人员到达引导目标位置", 1f);
}
TrappedGuidanceSyncData argguide = new TrappedGuidanceSyncData();
argguide.IsEnd = true;
argguide.SendUserID = CurrentUserInfo.mySelf.Id;
argguide.gameObjID = GetComponent<BaseGameObjInfo>().gameObjID;
NetworkManager.Default.SendAsync("TRAPPED_GUIDANCE_SYNC", argguide);
MessageDispatcher.SendMessage("SomeoneOutOfTrap"); //通知火场信息-疏散救生-被困时间部分更新,看是否可以停止计时
return;
}
}
else if (guidPoint.Count > 1)
{
if (!guidPoint.Contains(TargetPosition))
{
AddGuidIndex();
}
if (Vector3.Distance(transform.position, guidPoint[0]) < 2)
{
AddGuidIndex();
}
}
else { }
}
//被移动
if (IsMoveState)
{
if (MoveFireman != null)
{
TargetPosition = transform.position;
if (Vector3.Distance(transform.position, MoveFireman.transform.position) > 2)
{
Vector3 offset = -MoveFireman.transform.forward;
nav.SetDestination(MoveFireman.transform.position + offset);
movestate = MoveState.MOVEFREE;
anim.SetFloat("Speed", 5f);
}
else
{
movestate = MoveState.IDLE;
anim.SetFloat("Speed", 0);
}
}
}
//if (Vector3.Distance(transform.position, targetPosition) < 0.1)
//{
// OverMoveOrGuidance = true;
//}
}
#endregion
}
}
/// <summary>
/// 随机移动点位
/// </summary>
/// <returns></returns>
void RandomPoint()
{
//if (!IsselfClient)
// {
// return;
// }
if (MeetDangerous)
{
MeetDangerous = false;
}
if (IsMoveState)
{
Debug.Log("移动状态调用");
}
if (Guidance)
{
Debug.Log("引导状态调用");
}
if (!firemanHit && !IsBefirstAirOrMoving)
{
if (CurrentUserInfo.room != null && CurrentUserInfo.mySelf.Id == CurrentUserInfo.room.Owner.UserInfo.Id)
{
float rang = UnityEngine.Random.Range(4f, 8f);
StartCoroutine(randompoint(rang));
}
}
else
{
Debug.Log("在消防员点击状态下调用");
}
}
IEnumerator randompoint(float rang)
{
yield return new WaitForSeconds(rang);
Vector2 randomcicle = UnityEngine.Random.insideUnitCircle;
randomVector = new Vector3(originalpoint.x + randomcicle.x * MaxRange,
originalpoint.y, originalpoint.z + randomcicle.y * MaxRange);
TargetPosition = randomVector;
//nav.destination = randomVector;
TrappedPathFindingCmdArgs arg = new TrappedPathFindingCmdArgs();
arg.hitPoint = randomVector;
arg.MeetDangerous = false;
arg.gameObjIdSelf = GetComponent<BaseGameObjInfo>().gameObjID;
TrappedPathFindingCommand.Instance.Execute(GetComponent<BaseGameObjInfo>().gameObjID, arg);
MeetDangerous = false;
}
//延迟方法调用时间间隔
int randominvoketime()
{
return UnityEngine.Random.Range(2, 5);
}
void AniamtorSet()
{
if (Haemal <= 50)
{
return;
}
if (nav.enabled==false)
{
return;
}
if (movestate == MoveState.IDLE)
{
nav.SetDestination(transform.position);
anim.SetFloat("Speed", 0);
}
if (movestate == MoveState.MOVEFREE)
{
if (MeetDangerous && !Guidance && !IsMoveState)
{
anim.SetFloat("Speed", 5);
}
if (!MeetDangerous && !Guidance && !IsMoveState)
{
anim.SetFloat("Speed", 2f);
}
if (Guidance && !IsSetPoint)
{
anim.SetFloat("Speed", 5);
}
}
if (movestate == MoveState.FALLDOWN)
{
anim.SetFloat("Speed", 0);
anim.SetBool("FallDown", true);
nav.SetDestination(transform.position);
TargetPosition = transform.position;
GetComponent<TrappedPathFind>().pathFindEnable = false;
}
if (Haemal > 50)
{
if (anim.GetFloat("Speed") < 0.1f)
{
movestate = MoveState.IDLE;
}
}
}
void MoveStateSet()
{
if (Haemal <= 50)
{
if (movestate != MoveState.FALLDOWN)
{
movestate = MoveState.FALLDOWN;
}
}
else
{
if (OverMoveOrGuidance)
{
movestate = MoveState.IDLE;
}
else
{
if (Vector3.Distance(transform.position, TargetPosition) > 1 &&
TargetPosition != Vector3.zero /*&& !Guidance && !IsMoveState*/)
{
movestate = MoveState.MOVEFREE;
}
if (Vector3.Distance(transform.position, TargetPosition) <= 1 &&
TargetPosition != Vector3.zero /*&& !Guidance && !IsMoveState&&!MeetDangerous*/)
{
movestate = MoveState.IDLE;
}
if (MeetDangerous)
{
movestate = MoveState.MOVEFREE;
}
if (firemanHit)
{
movestate = MoveState.IDLE;
}
//if (FireManNear && !IsMoveState && !Guidance)
//{
// //transform.LookAt(firemanList[0].transform);
// movestate = MoveState.IDLE;
//}
if (Guidance && !IsSetPoint)
{
movestate = MoveState.MOVEFREE;
}
if (Guidance && IsSetPoint)
{
movestate = MoveState.IDLE;
}
if (isBefirstAirOrMoving)
{
movestate = MoveState.IDLE;
}
}
}
//if (Guidance)
//{
// movestate = MoveState.GUIDED;
//}
}
/// <summary>
/// 获取周围的危险列表
/// </summary>
void GetDangerousList()
{
DangerousList.Clear();
CloneGameObjInfo[] allDisaster = P_Disasters.GetComponentsInChildren<CloneGameObjInfo>();
for (int i = 0; i < allDisaster.Length; i++)
{
if (allDisaster[i].gameObjType == CloneObjType.dangerousGoods ||
allDisaster[i].gameObjType == CloneObjType.fireNormal ||
allDisaster[i].gameObjType == CloneObjType.fireBreakThrough ||
allDisaster[i].gameObjType == CloneObjType.LiquidLevel ||
allDisaster[i].gameObjType == CloneObjType.SpreadedFire/* ||
allDisaster[i].gameObjType == CloneObjType.smokeNormal ||
allDisaster[i].gameObjType == CloneObjType.smokeIndoor1 ||
allDisaster[i].gameObjType == CloneObjType.smokeIndoor2*/)
{
if (scenetype != SceneType.)
{
//现检测高度范围为低于1.2(地面下0.2),高于2米(头上1米)
if (transform.position.y - allDisaster[i].transform.position.y < 1.2
|| allDisaster[i].transform.position.y - transform.position.y < 2)
{
//检测范围以内的
if (Vector3.Distance(transform.position, allDisaster[i].transform.position) < MetDangerousDistance)
{
DangerousList.Add(allDisaster[i].gameObject);
}
}
}
else
{
//化工暂时不限高
if (transform.position.y - allDisaster[i].transform.position.y < 1.2)
{
//检测范围以内的
if (Vector3.Distance(transform.position, allDisaster[i].transform.position) < MetDangerousDistance)
{
DangerousList.Add(allDisaster[i].gameObject);
}
}
}
}
}
}
/// <summary>
/// 当前角色能否检测到危险列表中的物体
/// </summary>
void dangerousDetection()
{
if (DangerousList.Count < 1)
{
return;
}
for (int i = 0; i < DangerousList.Count; i++)
{
Vector3 dir = DangerousList[i].transform.position - transform.position;
//目前视角为120度
if (Vector3.Dot(new Vector3(dir.x, 0, dir.z).normalized, transform.forward.normalized) > 0.2)
{
DangerousLastmet = DangerousList[i].transform.position;
if (Haemal > 50)
{
movestate = MoveState.MOVEFREE;
}
MeetDangerous = true;
}
}
}
public void CancelInvokeRandom()
{
CancelInvoke("RandomPoint");
}
IEnumerator firstAidText()
{
LoadPromptWin.Instance.LoadTextPromptWindow("正在实施急救", 5f);
yield return new WaitForSeconds(5.5f);
LoadPromptWin.Instance.LoadTextPromptWindow("实施急救成功", 2f);
}
IEnumerator WaitForFireman()
{
//等待消防员同步
if (IsselfClient)
{
var arg = new TrappedWaitFiremanSyncData();
arg.SendUserID = CurrentUserInfo.mySelf.Id;
arg.gameObjID = GetComponent<BaseGameObjInfo>().gameObjID;
arg.IsWait = true;
arg.Waitposition = transform.position;
NetworkManager.Default.SendAsync("TRAPPED_WAIT_FIREMAN_SYNC", arg);
}
// nav.enabled = false;
//TrappedPathFindingCmdArgs cmdarg = new TrappedPathFindingCmdArgs();
//cmdarg.hitPoint = transform.position;
//cmdarg.gameObjIdSelf = GetComponent<BaseGameObjInfo>().gameObjID;
//TrappedPathFindingCommand.Instance.Execute(GetComponent<BaseGameObjInfo>().gameObjID, cmdarg);
nav.SetDestination(transform.position);
CancelInvokeRandom();
GetComponent<TrappedPathFind>().StopAllCoroutines();
TargetPosition = transform.position;
movestate = MoveState.IDLE;
yield return new WaitForSeconds(3f);
firemanHit = false;
//nav.enabled = true;
if (IsselfClient)
{
var warg = new TrappedWaitFiremanSyncData();
warg.SendUserID = CurrentUserInfo.mySelf.Id;
warg.gameObjID = GetComponent<BaseGameObjInfo>().gameObjID;
warg.IsWait = false;
warg.Waitposition = transform.position;
NetworkManager.Default.SendAsync("TRAPPED_WAIT_FIREMAN_SYNC", warg);
}
//InvokeRepeating("RandomPoint", 0f, 3f);
}
private IntData addMyRescue(IntData data)
{
if (OverMoveOrGuidance == true)
{
data.value += 1;
}
return data;
}
private IntData addMyUnrescue(IntData data)
{
if (OverMoveOrGuidance == false)
{
data.value += 1;
}
return data;
}
private IntData addMyTrapped(IntData data)
{
data.value += 1;
return data;
}
//public IEnumerator WaitForFiremanNotext()
//{
// firemanHit = true;
// CancelInvoke("RandomPoint");
// nav.SetDestination(transform.position);
// targetPosition = transform.position;
// yield return new WaitForSeconds(3f);
// firemanHit = false;
//}
}