|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
//火灾是否可蔓延
|
|
|
|
//一个人可控50平方,其他200平方
|
|
|
|
public class SpreadFireController : MonoBehaviour
|
|
|
|
{
|
|
|
|
|
|
|
|
private float timer = 1f;
|
|
|
|
private Transform p_AllParent;
|
|
|
|
//private Transform p_car;
|
|
|
|
//private Transform p_watercannon;
|
|
|
|
private Transform p_FireNormal;
|
|
|
|
private bool flag = false;
|
|
|
|
/// <summary>
|
|
|
|
/// 普通火的火堆集合(主火Id)
|
|
|
|
/// </summary>
|
|
|
|
private static List<long> fireNormalStruckList = new List<long>();
|
|
|
|
/// <summary>
|
|
|
|
/// 火堆字典,每个火堆对应几个火,key为火堆(主火id),list为这堆火由哪几个火组成
|
|
|
|
/// </summary>
|
|
|
|
public static Dictionary<long, List<FireFightNormal>> fireStruckContainDic = new Dictionary<long, List<FireFightNormal>>();
|
|
|
|
// Use this for initialization
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
p_AllParent = GameObject.Find("P_AllParent").transform;
|
|
|
|
//p_car = p_AllParent.Find("P_Cars");
|
|
|
|
//p_watercannon = p_AllParent.Find("P_Tools/P_WaterCannon");
|
|
|
|
p_FireNormal = p_AllParent.Find("P_Disasters/P_FireNormal");
|
|
|
|
}
|
|
|
|
private void OnDestroy()
|
|
|
|
{
|
|
|
|
fireNormalStruckList.Clear();
|
|
|
|
fireStruckContainDic.Clear();
|
|
|
|
|
|
|
|
}
|
|
|
|
private void OnDisable()
|
|
|
|
{
|
|
|
|
fireNormalStruckList.Clear();
|
|
|
|
fireStruckContainDic.Clear();
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
if (GameSettings.othersSettings.isStartDrill)
|
|
|
|
{
|
|
|
|
if (flag == false)
|
|
|
|
{
|
|
|
|
GetFireStruckList();
|
|
|
|
GetfireStruckContainDic();
|
|
|
|
flag = true;
|
|
|
|
}
|
|
|
|
if (CurrentUserInfo.mySelf == null || CurrentUserInfo.room == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (CurrentUserInfo.mySelf.Id == CurrentUserInfo.room.Owner.UserInfo.Id)
|
|
|
|
{
|
|
|
|
if (p_FireNormal.childCount > 0)
|
|
|
|
{
|
|
|
|
if (GetNumOnAllNormalFire() > 0)
|
|
|
|
{
|
|
|
|
timer -= Time.deltaTime;
|
|
|
|
if (timer < 0)
|
|
|
|
{
|
|
|
|
removeDiedFireFromDic();
|
|
|
|
judgeControl();
|
|
|
|
timer = 1f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
timer -= Time.deltaTime;
|
|
|
|
if (timer < 0)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < fireNormalStruckList.Count; i++)
|
|
|
|
{
|
|
|
|
GameObject normal = EntitiesManager.Instance.GetEntityByID(fireNormalStruckList[i]);
|
|
|
|
if (normal.GetComponent<FireSpreadCtrl>().BeController)
|
|
|
|
{
|
|
|
|
normal.GetComponent<FireSpreadCtrl>().BeController = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
timer = 1f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//获取普通火及蔓延火上的水枪数,大于0表示有水枪打在火上
|
|
|
|
int GetNumOnAllNormalFire()
|
|
|
|
{
|
|
|
|
int num = 0;
|
|
|
|
for (int i = 0; i < p_FireNormal.childCount; i++)
|
|
|
|
{
|
|
|
|
num += p_FireNormal.GetChild(i).GetComponent<FireFightNormal>().Straightwater.Count;
|
|
|
|
}
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// 获取火堆集合,也就是克隆的普通火的数量
|
|
|
|
/// </summary>
|
|
|
|
void GetFireStruckList()
|
|
|
|
{
|
|
|
|
fireNormalStruckList.Clear();
|
|
|
|
for (int i = 0; i < p_FireNormal.childCount; i++)
|
|
|
|
{
|
|
|
|
BaseGameObjInfo baseinfo = p_FireNormal.GetChild(i).GetComponent<BaseGameObjInfo>();
|
|
|
|
if (baseinfo.gameObjType == CloneObjType.fireNormal)
|
|
|
|
{
|
|
|
|
if (!fireNormalStruckList.Contains(baseinfo.gameObjID))
|
|
|
|
{
|
|
|
|
fireNormalStruckList.Add(baseinfo.gameObjID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// 获取火堆的字典
|
|
|
|
/// </summary>
|
|
|
|
void GetfireStruckContainDic()
|
|
|
|
{
|
|
|
|
fireStruckContainDic.Clear();
|
|
|
|
for (int i = 0; i < fireNormalStruckList.Count; i++)
|
|
|
|
{
|
|
|
|
List<FireFightNormal> fireFightNormalList = new List<FireFightNormal>();
|
|
|
|
//把主火加进字典
|
|
|
|
fireFightNormalList.Add(EntitiesManager.Instance.GetEntityByID(fireNormalStruckList[i]).GetComponent<FireFightNormal>());
|
|
|
|
fireStruckContainDic.Add(fireNormalStruckList[i], fireFightNormalList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// 从字典中移除熄灭的火堆
|
|
|
|
/// </summary>
|
|
|
|
void removeDiedFireFromDic()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < fireNormalStruckList.Count; i++)
|
|
|
|
{
|
|
|
|
if (fireStruckContainDic[fireNormalStruckList[i]].Count < 1)
|
|
|
|
{
|
|
|
|
fireStruckContainDic.Remove(fireNormalStruckList[i]);
|
|
|
|
fireNormalStruckList.Remove(fireNormalStruckList[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// 判断火堆是否被控制(控火强度大于火堆面积)
|
|
|
|
/// </summary>
|
|
|
|
void judgeControl()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < fireNormalStruckList.Count; i++)
|
|
|
|
{
|
|
|
|
float fireArea = 0;//该火堆的面积
|
|
|
|
float waterControlArea = 0;//该火堆总控火面积
|
|
|
|
GameObject mainfire = EntitiesManager.Instance.GetEntityByID(fireNormalStruckList[i]);
|
|
|
|
|
|
|
|
List<FireFightNormal> nowstruck = fireStruckContainDic[fireNormalStruckList[i]];
|
|
|
|
|
|
|
|
for (int j = 0; j < nowstruck.Count; j++)
|
|
|
|
{
|
|
|
|
//该火堆中每个火的baseinfo
|
|
|
|
BaseGameObjInfo info = nowstruck[j].GetComponent<BaseGameObjInfo>();
|
|
|
|
if (info.gameObjType == CloneObjType.fireNormal)
|
|
|
|
{
|
|
|
|
fireArea += info.GetComponent<FireSpreadCtrl>().fireAttribute.initialSize;
|
|
|
|
}
|
|
|
|
if (info.gameObjType == CloneObjType.SpreadedFire)
|
|
|
|
{
|
|
|
|
fireArea += 10;
|
|
|
|
}
|
|
|
|
if (info.GetComponent<FireFightNormal>().Straightwater.Count > 0)
|
|
|
|
{
|
|
|
|
//作用在某个火的面积
|
|
|
|
for (int k = 0; k < info.GetComponent<FireFightNormal>().Straightwater.Count; k++)
|
|
|
|
{
|
|
|
|
WaterFightFire water = info.GetComponent<FireFightNormal>().Straightwater[k];
|
|
|
|
if (water.GetComponentInParent<BaseGameObjInfo>().gameObjType == CloneObjType.fireman ||
|
|
|
|
water.GetComponentInParent<BaseGameObjInfo>().gameObjType == CloneObjType.FirefightingRobot)
|
|
|
|
{
|
|
|
|
waterControlArea += 50;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
waterControlArea += 200;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//如果可以控制住
|
|
|
|
|
|
|
|
if (waterControlArea > fireArea)
|
|
|
|
{
|
|
|
|
|
|
|
|
mainfire.GetComponent<FireSpreadCtrl>().BeController = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mainfire.GetComponent<FireSpreadCtrl>().BeController = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|