using AX.InputSystem; using AX.MessageSystem; using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using System.Linq; using AX.NetworkSystem; /// /// 处理伤员被困人员救援的脚本 /// public class WoundedSave : MonoBehaviour { //private List fireManList = new List(); CloneObjType type = CloneObjType.None; public static long FireManlastID; private List> freeFiremanAround = new List>(); private Transform p_fireman; ForcibleEntryCmdArgs data; public bool OverMoveOrGuidance = false; public bool isBefirstAirOrMoving; private GameObject nestestfireman; private Transform P_SafeArea; /// /// 营救该被困人员的消防员userId,报告里要用到 /// public long SaveFrirmanUserId; public bool IsBefirstAirOrMoving { get { return isBefirstAirOrMoving; } set { isBefirstAirOrMoving = value; WounderFirstAidOrMoveStateSyncData arg = new WounderFirstAidOrMoveStateSyncData(); arg.SendUserID = CurrentUserInfo.mySelf.Id; arg.gameObjID = GetComponent().gameObjID; arg.IsBeFristAidOrMove = value; NetworkManager.Default.SendAsync("WOUNDER_FRISTAID_OR_MOVE_STATE_SYNC",arg); } } // Use this for initialization void Start () { //fireManList = GetComponentInChildren().FireMenList; type = GetComponent().gameObjType; p_fireman = GameObject.Find("P_AllParent/P_Person/P_Fireman").transform; P_SafeArea = GameObject.Find("P_AllParent/P_Tools/P_SafeArea").transform; } private void OnEnable() { MessageDispatcher.AddListener("MOVE_MAN_COMMAND", MoveWounded); MessageDispatcher.AddListener("GUIDANCE_MAN_COMMAND",GuidanceWounded); MessageDispatcher.AddListener("FRISTAID_MAN_COMMAND", FristAidWounded); WoundedInfo.getAllWoundedCount += addMyWounded; //火场信息-疏散救生 WoundedInfo.getWoundedRescuedCount += addMyRescue; //火场信息-疏散救生 RescuedValue.getAllRescuedWounded += addMyRescue; //战报-营救人数 TrappedTime.getAllWoundedTrappedCount += addMyUnrescued; //火场信息-疏散救生-统计未被救援的伤员数 DrillBeginButton.getUnrescuedCount += addMyUnrescued; //判断胜利-统计未营救人员 } private void OnDisable() { MessageDispatcher.RemoveListener("MOVE_MAN_COMMAND", MoveWounded); MessageDispatcher.RemoveListener("GUIDANCE_MAN_COMMAND", GuidanceWounded); MessageDispatcher.RemoveListener("FRISTAID_MAN_COMMAND", FristAidWounded); WoundedInfo.getAllWoundedCount -= addMyWounded; WoundedInfo.getWoundedRescuedCount -= addMyRescue; RescuedValue.getAllRescuedWounded -= addMyRescue; TrappedTime.getAllWoundedTrappedCount -= addMyUnrescued; DrillBeginButton.getUnrescuedCount -= addMyUnrescued; } private void OnDestroy() { MessageDispatcher.RemoveListener("MOVE_MAN_COMMAND", MoveWounded); MessageDispatcher.RemoveListener("GUIDANCE_MAN_COMMAND", GuidanceWounded); MessageDispatcher.RemoveListener("FRISTAID_MAN_COMMAND", FristAidWounded); WoundedInfo.getAllWoundedCount -= addMyWounded; WoundedInfo.getWoundedRescuedCount -= addMyRescue; RescuedValue.getAllRescuedWounded -= addMyRescue; TrappedTime.getAllWoundedTrappedCount -= addMyUnrescued; DrillBeginButton.getUnrescuedCount -= addMyUnrescued; } private void FristAidWounded(IMessage msg) { data = (ForcibleEntryCmdArgs)msg.Data; if (data == null) return; if ((gameObject.GetComponent().gameObjID != data.gameObjID)) return; //if (GameSettings.othersSettings.playState == PlayState.Playing) //{ // CursorManager.GetInstance.SetClick(data); //} if(GetComponent()) { if (GetComponent().Haemal<=0) { LoadPromptWin.Instance.LoadTextPromptWindow("该人员已死亡,不能操作", 2f); return; } } if (IsBefirstAirOrMoving) { LoadPromptWin.Instance.LoadTextPromptWindow("该人员正在被急救或者移动,不能操作", 2f); return; } GameObject fireMan = EntitiesManager.Instance.GetEntityByID(data.fireManID); if (Vector3.Distance(fireMan.transform.position, transform.position)>3) { string tip = "请靠近需救助人员"; //data = null; LoadPromptWin.Instance.LoadTextPromptWindow(tip, 1f); } else { if (GetComponent()) { GetComponent().skillList.Add(new KeyValuePair(fireMan,FireManSkills.FristAid)); } GetComponent().haemal.GetComponent().FirstAir(fireMan); IsBefirstAirOrMoving = true; fireMan.GetComponent().pathFindEnable = false; if (FireManSkillPanelController.Instance) { if (FireManSkillPanelController.Instance.SelectFireMan == fireMan) { FireManSkillPanelController.Instance.SetSkillDisable(); } } //StartCoroutine(firstAidText(fireMan)); FireManlastID = data.fireManID; } } /// /// 移动伤员 /// /// private void MoveWounded(IMessage msg) { data = (ForcibleEntryCmdArgs)msg.Data; if (data == null) return; if ((gameObject.GetComponent().gameObjID != data.gameObjID)) return; if (GameSettings.othersSettings.playState == PlayState.Playing) { CursorManager.GetInstance.SetClick(data); } if (P_SafeArea.childCount<1) { LoadPromptWin.Instance.LoadTextPromptWindow("尚未设置安全区", 1f); return; } if (IsBefirstAirOrMoving) { LoadPromptWin.Instance.LoadTextPromptWindow("该人员正在被急救或者移动,不能操作", 2f); return; } GameObject fireMan = EntitiesManager.Instance.GetEntityByID(data.fireManID); // Invoke("delaySet", 0.03f); string tip = CheckCondition(); if (string.IsNullOrEmpty(tip)) { FireManlastID = data.fireManID; //正常逻辑 Debug.Log("正常移动处理"); // SavePlacePanel.Instance.OpenPanel(gameObject); if (GetComponent()) { GetComponent().skillList.Add(new KeyValuePair(fireMan, FireManSkills.Move)); } nestestfireman = CheckFiremanAround(fireMan); IsBefirstAirOrMoving = true; GetComponent().haemal.GetComponent().Moving(fireMan,nestestfireman); //IsBefirstAirOrMoving = true; GetComponent().IsMoving = true; } else { //弹框提示错误 LoadPromptWin.Instance.LoadTextPromptWindow(CheckCondition(), 2f); // Debug.Log(CheckCondition()); } } /// /// 引导伤员 /// /// private void GuidanceWounded(IMessage msg) { data = (ForcibleEntryCmdArgs)msg.Data; if (data == null) return; if ((gameObject.GetComponent().gameObjID != data.gameObjID)) return; if (GameSettings.othersSettings.playState == PlayState.Playing) { CursorManager.GetInstance.SetClick(data); } GameObject fireMan = EntitiesManager.Instance.GetEntityByID(data.fireManID); if (Vector3.Distance(fireMan.transform.position, transform.position) > 3) { string tip = "请靠近需救助人员"; //data = null; LoadPromptWin.Instance.LoadTextPromptWindow(tip, 2f); } else { if (GetComponent()) { GetComponent().skillList.Add(new KeyValuePair(fireMan,FireManSkills.Guidance)); } LoadPromptWin.Instance.LoadTextPromptWindow("伤员已失去意识,无法对伤员进行安抚或引导", 2f); FireManlastID = data.fireManID; } } public string CheckCondition() { string tip = null; GameObject fireMan = EntitiesManager.Instance.GetEntityByID(data.fireManID); if (Vector3.Distance(fireMan.transform.position, transform.position) > 3) { tip = "请靠近需救助人员"; //data = null; return tip; } if (type == CloneObjType.wounded) { if (Vector3.Distance(fireMan.transform.position, transform.position) < 3) { if(CheckFiremanAround(fireMan) ==null) tip = "营救伤员需要两名消防员"; return tip; } } //data = null; return tip; } /// /// 重伤员附近是否有同客户端闲置的消防员 /// /// 执行操作的消防员 /// GameObject CheckFiremanAround(GameObject fireman) { GameObject nestest = null; freeFiremanAround.Clear(); long userid = fireman.GetComponent().UserID; for (int i = 0; i < p_fireman.childCount; i++) { if (p_fireman.GetChild(i).GetComponent().UserID==userid) { if (p_fireman.GetChild(i).gameObject!=fireman) { //如果附近有空闲或者开着移动技能但是没有移动人员的消防员 if (p_fireman.GetChild(i).GetComponent().workType==FireManSkills.None|| (p_fireman.GetChild(i).GetComponent().workType == FireManSkills.Move&& p_fireman.GetChild(i).GetComponent().trappedlist.Count<1)) { if (Vector3.Distance(p_fireman.GetChild(i).position,transform.position)<3) { freeFiremanAround.Add(new KeyValuePair(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; } IEnumerator firstAidText(GameObject fireMan) { LoadPromptWin.Instance.LoadTextPromptWindow("正在实施急救", 3f); fireMan.GetComponent().pathFindEnable = false; yield return new WaitForSeconds(3.5f); LoadPromptWin.Instance.LoadTextPromptWindow("实施急救成功", 1f); fireMan.GetComponent().pathFindEnable = true; } /// /// //火场信息-疏散救生-伤员统计 /// /// /// private IntData addMyWounded(IntData data) { data.value += 1; return data; } private IntData addMyUnrescued(IntData data) { if (!OverMoveOrGuidance) { data.value += 1; } return data; } /// /// 火场信息-疏散救生-营救人员统计 /// /// /// private IntData addMyRescue(IntData data) { if (OverMoveOrGuidance) { data.value += 1; } return data; } }