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.
320 lines
12 KiB
320 lines
12 KiB
using AX.InputSystem; |
|
using AX.MessageSystem; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using System; |
|
using System.Linq; |
|
using AX.NetworkSystem; |
|
/// <summary> |
|
/// 处理伤员被困人员救援的脚本 |
|
/// </summary> |
|
public class WoundedSave : MonoBehaviour { |
|
|
|
//private List<GameObject> fireManList = new List<GameObject>(); |
|
CloneObjType type = CloneObjType.None; |
|
public static long FireManlastID; |
|
private List<KeyValuePair<GameObject, float>> freeFiremanAround = new List<KeyValuePair<GameObject, float>>(); |
|
private Transform p_fireman; |
|
ForcibleEntryCmdArgs data; |
|
public bool OverMoveOrGuidance = false; |
|
public bool isBefirstAirOrMoving; |
|
private GameObject nestestfireman; |
|
private Transform P_SafeArea; |
|
/// <summary> |
|
/// 营救该被困人员的消防员userId,报告里要用到 |
|
/// </summary> |
|
public long SaveFrirmanUserId; |
|
public bool IsBefirstAirOrMoving |
|
{ |
|
get |
|
{ |
|
return isBefirstAirOrMoving; |
|
} |
|
|
|
set |
|
{ |
|
isBefirstAirOrMoving = value; |
|
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); |
|
} |
|
} |
|
|
|
// Use this for initialization |
|
void Start () { |
|
//fireManList = GetComponentInChildren<TriggerCtrl>().FireMenList; |
|
type = GetComponent<BaseGameObjInfo>().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<BaseGameObjInfo>().gameObjID != data.gameObjID)) return; |
|
//if (GameSettings.othersSettings.playState == PlayState.Playing) |
|
//{ |
|
// CursorManager.GetInstance.SetClick(data); |
|
//} |
|
if(GetComponent<BaseHaemalController>()) |
|
{ |
|
if (GetComponent<BaseHaemalController>().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<BaseHaemalController>()) |
|
{ |
|
GetComponent<BaseHaemalController>().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(fireMan)); |
|
FireManlastID = data.fireManID; |
|
} |
|
} |
|
/// <summary> |
|
/// 移动伤员 |
|
/// </summary> |
|
/// <param name="msg"></param> |
|
private void MoveWounded(IMessage msg) |
|
{ |
|
data = (ForcibleEntryCmdArgs)msg.Data; |
|
if (data == null) return; |
|
if ((gameObject.GetComponent<BaseGameObjInfo>().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<BaseHaemalController>()) |
|
{ |
|
GetComponent<BaseHaemalController>().skillList.Add(new KeyValuePair<GameObject, FireManSkills>(fireMan, FireManSkills.Move)); |
|
} |
|
nestestfireman = CheckFiremanAround(fireMan); |
|
IsBefirstAirOrMoving = true; |
|
GetComponent<CreatHaemalUI>().haemal.GetComponent<HaemalStrand>().Moving(fireMan,nestestfireman); |
|
//IsBefirstAirOrMoving = true; |
|
GetComponent<BaseHaemalController>().IsMoving = true; |
|
} |
|
else |
|
{ |
|
//弹框提示错误 |
|
LoadPromptWin.Instance.LoadTextPromptWindow(CheckCondition(), 2f); |
|
// Debug.Log(CheckCondition()); |
|
} |
|
} |
|
/// <summary> |
|
/// 引导伤员 |
|
/// </summary> |
|
/// <param name="msg"></param> |
|
private void GuidanceWounded(IMessage msg) |
|
{ |
|
data = (ForcibleEntryCmdArgs)msg.Data; |
|
if (data == null) return; |
|
if ((gameObject.GetComponent<BaseGameObjInfo>().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<BaseHaemalController>()) |
|
{ |
|
GetComponent<BaseHaemalController>().skillList.Add(new KeyValuePair<GameObject, FireManSkills>(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; |
|
} |
|
/// <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; |
|
} |
|
IEnumerator firstAidText(GameObject fireMan) |
|
{ |
|
LoadPromptWin.Instance.LoadTextPromptWindow("正在实施急救", 3f); |
|
fireMan.GetComponent<AgentController>().pathFindEnable = false; |
|
yield return new WaitForSeconds(3.5f); |
|
LoadPromptWin.Instance.LoadTextPromptWindow("实施急救成功", 1f); |
|
fireMan.GetComponent<AgentController>().pathFindEnable = true; |
|
} |
|
/// <summary> |
|
/// //火场信息-疏散救生-伤员统计 |
|
/// </summary> |
|
/// <param name="data"></param> |
|
/// <returns></returns> |
|
private IntData addMyWounded(IntData data) |
|
{ |
|
data.value += 1; |
|
return data; |
|
} |
|
|
|
private IntData addMyUnrescued(IntData data) |
|
{ |
|
if (!OverMoveOrGuidance) |
|
{ |
|
data.value += 1; |
|
} |
|
return data; |
|
} |
|
/// <summary> |
|
/// 火场信息-疏散救生-营救人员统计 |
|
/// </summary> |
|
/// <param name="data"></param> |
|
/// <returns></returns> |
|
private IntData addMyRescue(IntData data) |
|
{ |
|
if (OverMoveOrGuidance) |
|
{ |
|
data.value += 1; |
|
} |
|
return data; |
|
} |
|
}
|
|
|