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.
280 lines
10 KiB
280 lines
10 KiB
using AX.NetworkSystem; |
|
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
|
|
public class DrillBeginButton : BaseButton |
|
{ |
|
|
|
public Transform PoliceCallPanel; |
|
public VictoryConditionPanel Victoryconditionpanel; |
|
public ArriveTimeContent Arrivetime; |
|
private Transform P_Disaster; |
|
|
|
public VictoryConditionSetting Victorysetting; |
|
//public static bool Drillbrgin = false; |
|
//public bool hasset = false; |
|
|
|
private static string vicHint = ""; |
|
|
|
void Start() |
|
{ |
|
P_Disaster = GameObject.Find("P_AllParent").transform.Find("P_Disasters"); |
|
} |
|
public override void OnDestroy() |
|
{ |
|
base.OnDestroy(); |
|
vicHint = ""; |
|
} |
|
public override void RespondFun() |
|
{ |
|
|
|
if (GameSettings.othersSettings.isStartDrill == false) |
|
{ |
|
if (!victoryConditionSetJudge()) |
|
{ |
|
Victoryconditionpanel.GetComponent<Toggle>().isOn = true; |
|
return; |
|
} |
|
//判断是否设置到达时间 |
|
Arrivetime.GetArriveTime(); |
|
if (!Arrivetime.Isset) |
|
{ |
|
LoadPromptWin.Instance.LoadTextPromptWindow("有组织未设置到达时间", 1f); |
|
Arrivetime.GetComponent<Toggle>().isOn = true; |
|
return; |
|
} |
|
if (!PoliceCallPanel.gameObject.activeInHierarchy) |
|
{ |
|
PoliceCallPanel.gameObject.SetActive(true); |
|
} |
|
} |
|
else |
|
{ |
|
|
|
//ToDo:结束演练 |
|
GameSettings.othersSettings.isStartDrill = false; |
|
KeyValuePair<long, bool> pair = new KeyValuePair<long, bool>(CurrentUserInfo.room.Id, false); |
|
NetworkManager.Default.SendAsync("TIMER_ENABLE_SYNC", pair); //向服务端申请停止计时 |
|
bool isVictory = CheckVictory(); |
|
GetComponent<Button>().interactable = false; |
|
// 演练结束消息 |
|
// DRILL_OVER_SYNC |
|
NetworkManager.Default.SendAsync("DRILL_OVER_SYNC", isVictory); |
|
Debug.Log("结束"); |
|
} |
|
} |
|
public static Func<IntData, IntData> getDiedFiremanCount; |
|
public static Func<IntData, IntData> getUnrescuedCount; |
|
/// <summary> |
|
/// 演习结束时检查是否胜利 |
|
/// </summary> |
|
/// <returns></returns> |
|
private bool CheckVictory() |
|
{ |
|
bool victory = true; |
|
//获取燃烧面积 |
|
int burnedArea = (int)FireScaleValue.BurnedArea; |
|
int diedFireman = 0; |
|
int unRescued = 0; |
|
float burnedTime = 0; |
|
int failCount = 0; |
|
//获取牺牲消防员人数 |
|
if (getDiedFiremanCount != null) |
|
{ |
|
IntData diedFiremanData = new IntData(0); |
|
diedFiremanData = getDiedFiremanCount(diedFiremanData); |
|
diedFireman = diedFiremanData.value; |
|
} |
|
//获取未营救人员人数 |
|
if (getUnrescuedCount != null) |
|
{ |
|
IntData unRescuedData = new IntData(0); |
|
unRescuedData = getUnrescuedCount(unRescuedData); |
|
unRescued = unRescuedData.value; |
|
} |
|
//获取燃烧时间 |
|
burnedTime = BurnTimer.BurnTime; |
|
VictoryConditionSetting vicSetting; |
|
if (GameSettings.othersSettings.isSelectedDisaster) |
|
{ |
|
vicSetting = GameSettings.othersSettings.disaster.VictoryCondition; |
|
} |
|
else |
|
{ |
|
vicSetting = Victorysetting; |
|
} |
|
if (Victoryconditionpanel.FireAreaToggle.GetComponent<Toggle>().isOn && burnedArea > vicSetting.BurnedArea) |
|
{ |
|
victory = false; |
|
failCount++; |
|
vicHint += "燃烧面积超过指定值"; |
|
} |
|
if (Victoryconditionpanel.FireManSettingToggle.GetComponent<Toggle>().isOn && vicSetting.FireManDied > 0 && diedFireman >= vicSetting.FireManDied) |
|
{ |
|
victory = false; |
|
failCount++; |
|
vicHint += vicHint == "" ? "牺牲消防员人数超过指定值" : "\n牺牲消防员人数超过指定值"; |
|
} |
|
if (Victoryconditionpanel.TrappedPersonToggle.GetComponent<Toggle>().isOn && vicSetting.UnRescued > 0 && unRescued >= vicSetting.UnRescued) |
|
{ |
|
victory = false; |
|
failCount++; |
|
vicHint += vicHint == "" ? "未营救人员超过指定值" : "\n未营救人员超过指定值"; |
|
} |
|
if (Victoryconditionpanel.FireTimeToggle.GetComponent<Toggle>().isOn && burnedTime > vicSetting.BurnedTime) |
|
{ |
|
victory = false; |
|
failCount++; |
|
vicHint += vicHint == "" ? "燃烧时间超过指定值" : "\n燃烧时间超过指定值"; |
|
} |
|
if (victory == false /*&& failCount >=vicSetting.Count*/) |
|
{ |
|
vicHint += "\n演习失败"; |
|
vicHint.Trim(); |
|
//LoadPromptWin.Instance.LoadFailTextPromptWindow(vicHint, 3); |
|
LoadPromptWin.Instance.LoadTipWindowNoButton(vicHint,8); |
|
} |
|
else |
|
{ |
|
vicHint = "演习胜利"; |
|
// LoadPromptWin.Instance.LoadTextPromptWindow(vicHint, 3); |
|
LoadPromptWin.Instance.LoadTipWindowNoButton(vicHint, 5); |
|
} |
|
return victory; |
|
} |
|
|
|
private KeyValuePair<int, int> GetFireTotalArea() |
|
{ |
|
GameObject P_FireNormal = GameObject.Find("P_FireNormal"); |
|
GameObject P_FireLiquidLevel = GameObject.Find("P_FireLiquidLevel"); |
|
GameObject P_Leak1 = GameObject.Find("P_Leak1"); |
|
|
|
int fireMinAre = 0; |
|
int fireMaxArea = 0; |
|
|
|
foreach (Transform child in P_FireNormal.transform) |
|
{ |
|
int tempMinFireArea = (int)child.GetComponent<FireInitialSizeSet>().selectedFireScale; |
|
fireMinAre += tempMinFireArea; |
|
|
|
int tempMaxFireArea = (int)child.GetComponent<FireInitialSizeSet>().selectedFireScale |
|
+ child.GetComponent<FireSpreadCtrl>().spreadPoints.Count * 10; |
|
fireMaxArea += tempMaxFireArea; |
|
} |
|
|
|
foreach (Transform child in P_FireLiquidLevel.transform) |
|
{ |
|
int tempMinFireArea = Mathf.RoundToInt(child.GetComponent<BoxCollider>().size.x) |
|
* Mathf.RoundToInt(child.GetComponent<BoxCollider>().size.z); |
|
fireMinAre += tempMinFireArea; |
|
|
|
int tempMaxFireArea = tempMinFireArea; |
|
fireMaxArea += tempMaxFireArea; |
|
} |
|
|
|
foreach (Transform child in P_Leak1.transform) |
|
{ |
|
int tempMaxFireArea = Mathf.RoundToInt(child.GetComponent<BoxCollider>().size.x) |
|
* Mathf.RoundToInt(child.GetComponent<BoxCollider>().size.z); |
|
fireMaxArea += tempMaxFireArea; |
|
} |
|
|
|
return new KeyValuePair<int, int>(fireMinAre, fireMaxArea); |
|
} |
|
/// <summary> |
|
/// 胜利条件设置判断 |
|
/// </summary> |
|
private bool victoryConditionSetJudge() |
|
{ |
|
|
|
bool ok = true; |
|
//判断是否设置胜利条件 |
|
if (Victoryconditionpanel != null) |
|
{ |
|
|
|
if (Victoryconditionpanel.SetCount <= 0) |
|
{ |
|
LoadPromptWin.Instance.LoadTextPromptWindow("请先设置胜利条件", 1f); |
|
Victoryconditionpanel.GetComponent<Toggle>().isOn = true; |
|
ok = false; |
|
} |
|
else |
|
{ |
|
ok = true; |
|
Toggle[] all = Victoryconditionpanel.VictoryScrollView.GetComponentsInChildren<Toggle>(true); |
|
int select = 0; |
|
for (int i = 0; i < all.Length; i++) |
|
{ |
|
if (all[i].isOn) |
|
{ |
|
select++; |
|
} |
|
} |
|
if (select < Victoryconditionpanel.SetCount) |
|
{ |
|
ok = false; |
|
LoadPromptWin.Instance.LoadTextPromptWindow("胜利条件未设置完善", 1f); |
|
} |
|
if (Victoryconditionpanel.FireTimeToggle.GetComponent<Toggle>().isOn) |
|
{ |
|
if (Victoryconditionpanel.FireTime <= 0) |
|
{ |
|
ok = false; |
|
LoadPromptWin.Instance.LoadTextPromptWindow("未设置着火时间", 1f); |
|
} |
|
} |
|
if (Victoryconditionpanel.TrappedPersonToggle.GetComponent<Toggle>().isOn) |
|
{ |
|
int trappedandwound = P_Disaster.Find("P_Wounded").childCount + P_Disaster.Find("P_TrappedPerson").childCount; |
|
if (trappedandwound == 0) |
|
{ |
|
ok = false; |
|
LoadPromptWin.Instance.LoadTextPromptWindow("尚未设置伤员及被困人员灾情", 1f); |
|
} |
|
if (Victoryconditionpanel.Trapped <= 0 && trappedandwound > 0) |
|
{ |
|
ok = false; |
|
LoadPromptWin.Instance.LoadTextPromptWindow("未营救人员不能为0", 1f); |
|
} |
|
|
|
if (Victoryconditionpanel.Trapped > trappedandwound) |
|
{ |
|
ok = false; |
|
LoadPromptWin.Instance.LoadTextPromptWindow("未营救人数大于设置总人数", 1f); |
|
} |
|
} |
|
if (Victoryconditionpanel.FireManSettingToggle.GetComponent<Toggle>().isOn) |
|
{ |
|
if (Victoryconditionpanel.FireMan <= 0) |
|
{ |
|
ok = false; |
|
LoadPromptWin.Instance.LoadTextPromptWindow("未设置牺牲消防员人数", 1f); |
|
} |
|
} |
|
if (Victoryconditionpanel.FireAreaToggle.GetComponent<Toggle>().isOn) |
|
{ |
|
if (Victoryconditionpanel.FireArea > GetFireTotalArea().Value) |
|
{ |
|
ok = false; |
|
LoadPromptWin.Instance.LoadTextPromptWindow("火灾面积超过最大蔓延面积", 1f); |
|
} |
|
if (Victoryconditionpanel.FireArea < GetFireTotalArea().Key) |
|
{ |
|
ok = false; |
|
LoadPromptWin.Instance.LoadTextPromptWindow("火灾面积小于最小面积", 1f); |
|
} |
|
if (Victoryconditionpanel.FireArea <= 0) |
|
{ |
|
ok = false; |
|
LoadPromptWin.Instance.LoadTextPromptWindow("未设置过火面积", 1f); |
|
} |
|
} |
|
} |
|
} |
|
return ok; |
|
|
|
} |
|
}
|
|
|