using System.Collections; using System.Collections.Generic; using UnityEngine; using AX.MessageSystem; using System; using AX.InputSystem; using UnityEngine.UI; using AX.NetworkSystem; public class WaterHoseEndDo { public GameObject ConnectHose;//连接的管线 public long StartId;//连接管线的起点Id public long EndId;//连接管线的终点物体Id public int ConnectInPoint;//连接的进水口 } public class TruckBindWaterSource : MonoBehaviour { public List allConnectWaterCurtainHose = new List();//水源车上连接的所有水幕水带 public List allConnectWaterHose = new List(); //注:本车辆的两个进水口直接连接水源即为两条进水路线的第0个索引值 private List> waterSourceLine1 = new List>();//当前水源车辆进水口线路1 private List> waterSourceLine2 = new List>();//当前水源车辆进水口线路1 public List> WaterSourceLine1 { get { return waterSourceLine1; } set { waterSourceLine1 = value; //水源信息修改后其出水端连接的对象水源信息也要修改(出水口水源跟着修改) checkOutAndChangeWaterInfo(); //if (connectWaterHose1 != null) //{ // connectWaterHose1.GetComponent().WaterSourceConnect = value; //} //for (int i = 0; i < WaterSourceLine1.Count; i++) //{ // for (int j = 0; j < WaterSourceLine1[i].Count; j++) // { // Debug.Log(name + "水源" + EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[i][j]).name); // } //} } } public List> WaterSourceLine2 { get { return waterSourceLine2; } set { waterSourceLine2 = value; checkOutAndChangeWaterInfo(); //if (connectWaterHose2 != null) //{ // connectWaterHose2.GetComponent().WaterSourceConnect = value; //} //for (int i = 0; i < WaterSourceLine1.Count; i++) //{ // for (int j = 0; j < WaterSourceLine1[i].Count; j++) // { // Debug.Log(name + "水源" + EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[i][j]).name); // } //} } } public KeyValuePair DirectConnectObj1;//key当前水源车出水口1连接的物体,value为连接的出水车辆的哪个进水口,1为进水口1,2为进水口2,0则只有一个进水口 public KeyValuePair DirectConnectObj2;//key当前水源车出水口2连接的物体,value为连接的出水车辆的哪个进水口,1为进水口1,2为进水口2,0则只有一个进水口 private GameObject outtWaterHose1;//出水口1连接的管线 private GameObject outWaterHose2;//出水口2连接的管线 private GameObject inWaterHose1;//进水口1连接的管线 private GameObject inWaterHose2;//进水口2连接的管线 public bool ConnectWater; public bool ConnectFoam; public Transform Hose; // public GameObject WaterStraightPrefabs; // public GameObject FrothPrefabs; public GameObject ConnentWaterSource;//连接的直接水源,用来判断能不能供泡沫 public float ParticleSize = 0.7f;//出水粒子大小 public bool waterrunoutof = false;//水是否用完 public SprayMode spraymode;//计算消耗的类型 public float flow; /// /// 剩余时间 /// public int RemainTime; /// /// 剩余水量 /// public float RemainWater; private BaseGameObjInfo gameobjinfo; private float timer = 1f; public float Flow { get { return flow; } set { // float prve = flow; flow = value; //if (inWaterHose1) //{ // inWaterHose1.GetComponent().HasWaterCross = value > 0 ? true : false; //} //if (inWaterHose2) //{ // inWaterHose2.GetComponent().HasWaterCross = value > 0 ? true : false; //} if (GetComponent()) {//如果自己是水源,加到自己上 GetComponent().TotalFlowChange(gameobjinfo.gameObjID, flow); } else {//自己不是水源,加到直接水源上 #region //流量改变重新分流 // 要根据水源的出水物体集合找到对应的物体然后改变 // 检查供水线路是不是还有水 float remainwater1 = checkWaterRemain(WaterSourceLine1); float remainwater2 = checkWaterRemain(WaterSourceLine2); if (WaterSourceLine1.Count > 0 && WaterSourceLine2.Count > 0) {//有两个水源给本车供水 GameObject dir1 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[0][0]); GameObject dir2 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine2[0][0]); WaterSource ws1 = dir1.GetComponent(); WaterSource ws2 = dir2.GetComponent(); if (GetComponentInChildren() && GetComponentInChildren().particleType == SprayParticleType.Froth) {//出的是泡沫,判断消耗哪边的水,泡沫不平均分配,updata里消耗的时候在传参计算 //float foamFlow = (Flow / 0.97f) * 0.03f;//泡沫流量 if (ws1.foam && (ws1.TotalFoam == -100 || (ws1.TotalFoam - ws1.AllUserFoam) > 0) && ws1.HasWaterSelfAndLine) {//直接水源1是泡沫车并且有泡沫,且有水 if (ws2.foam && (ws2.TotalFoam == -100 || (ws2.TotalFoam - ws2.AllUserFoam) > 0 && ws2.HasWaterSelfAndLine)) {//直接水源2是泡沫车并且有泡沫,且有水 //水平分 ws1.TotalFlowChange(gameobjinfo.gameObjID, flow / 2); ws2.TotalFlowChange(gameobjinfo.gameObjID, flow / 2); } else {//直接水源2不是泡沫车或者没泡沫了,全摊到水源1上 ws1.TotalFlowChange(gameobjinfo.gameObjID, flow); ws2.TotalFlowChange(gameobjinfo.gameObjID, 0); } } else { if (ws2.foam && (ws2.TotalFoam == -100 || (ws2.TotalFoam - ws2.AllUserFoam) > 0 && ws2.HasWaterSelfAndLine)) { ws2.TotalFlowChange(gameobjinfo.gameObjID, flow); } else { Debug.Log(name + "连接的水源没有泡沫"); } } } else {//出的是水 if (ws1 && (remainwater1 > 0 || remainwater1 == -100)) {//如果进水口1直接连接的是车,并且进水口1有水 if (remainwater2 > 0 || remainwater2 == -100) {//供水线路2也有水,两者平摊 ws1.TotalFlowChange(gameobjinfo.gameObjID, flow / 2); ws2.TotalFlowChange(gameobjinfo.gameObjID, flow / 2); } } else if (ws1 && !(remainwater1 > 0 || remainwater1 == -100)) {//进水口1直接水源是水源车但是没有水了 ws1.TotalFlowChange(gameobjinfo.gameObjID, 0); if (remainwater2 > 0 || remainwater2 == -100) {//供水线路2有水,全摊到2上 ws2.TotalFlowChange(gameobjinfo.gameObjID, flow); } else {//线路2也没水了 ws2.TotalFlowChange(gameobjinfo.gameObjID, 0); } } else if (!dir1.GetComponent()) {//线路1直接水源时消防设施 if (remainwater2 > 0 || remainwater2 == -100) {//水源2有水,两条线路平摊 ws1.TotalFlowChange(gameobjinfo.gameObjID, flow / 2); ws2.TotalFlowChange(gameobjinfo.gameObjID, flow / 2); } } } } if (WaterSourceLine1.Count > 0 && WaterSourceLine2.Count <= 0) {//只有一个水源给本车供水,且连在线路1上 GameObject dir1 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[0][0]); if (remainwater1 > 0 || remainwater1 == -100) { dir1.GetComponent().TotalFlowChange(gameobjinfo.gameObjID, flow); } else { Debug.Log(name + " 没水了"); } } if (WaterSourceLine1.Count <= 0 && WaterSourceLine2.Count > 0) {//只有一个水源给本车供水,且连在线路2上 // Debug.Log("没用出水口1,直接用的2?");可能先连上又把1删掉了。。。 GameObject dir2 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine2[0][0]); if (remainwater2 > 0 || remainwater2 == -100) { dir2.GetComponent().TotalFlowChange(gameobjinfo.gameObjID, flow); } else { Debug.Log(name + " 没水了"); } } if (WaterSourceLine1.Count <= 0 && WaterSourceLine2.Count <= 0) {//没有水源给本车供水 } #endregion } //流量改变流量同步 FlowChangeData arg = new FlowChangeData { SenderId = CurrentUserInfo.mySelf.Id, GameObjId = GetComponent().gameObjID, Flow = value, }; NetworkManager.Default.SendAsync("FLOW_CHANGE_SYNC", arg); } } void Start() { gameobjinfo = GetComponent(); if (gameobjinfo.gameObjType == CloneObjType.HighSprayingTruck) { spraymode = SprayMode.PS30; } else { spraymode = SprayMode.PS20; } Hose = TransformHelper.FindChild(transform, "Hose"); if (GetComponent()) { ConnectWater = GetComponent().water; ConnectFoam = GetComponent().foam; ConnentWaterSource = gameObject; } //if (WaterStraightPrefabs == null) //{ // WaterStraightPrefabs = Resources.Load("Particle/WaterStraight"); //} //if (FrothPrefabs == null) //{ // FrothPrefabs = Resources.Load("Particle/Froth"); //} MessageDispatcher.AddListener("SPRAY_WATER", Changeflow); MessageDispatcher.AddListener("RUN_OUR_OF_WATER", CloseSpray); GetRealtimeConsume.getAllRealtimeConsume += addMyRealtimeConsume; //统计实时流量 } void Update() { if (GetComponent().NowSkill == TruckSkills.喷水 || GetComponent().NowSkill == TruckSkills.喷泡沫) { if (Flow > 0) { timer -= Time.deltaTime; if (timer <= 0) { KeyValuePair remain = GetWaterAndTimeRemain(WaterSourceLine1, WaterSourceLine2); RemainTime = remain.Key; RemainWater = remain.Value; if (RemainWater != -100) { if (RemainTime <= 0 || RemainWater <= 0) {//没水了 stopspraywaterorform(); } } #region 泡沫消耗 if (GetComponent().NowSkill == TruckSkills.喷泡沫) { if (GetComponent() && GetComponent().foam) {//泡沫车 WaterSource ws = GetComponent(); if (ws.TotalFoam > ws.AllUserFoam) { GetComponent().UserFoam((Flow / 0.97f) * 0.03f); } else { // LoadPromptWin.Instance.LoadTextPromptWindow("泡沫量不足",1f); stopspraywaterorform(); } } else {//非水源车 float remianfoam = CheckFoamRemain(); if (remianfoam == -100 || remianfoam > 0) {//有泡沫 if (WaterSourceLine1.Count > 0) { GameObject dir1 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[0][0]); WaterSource ws1 = dir1.GetComponent(); if (ws1.foam) { if (ws1.TotalFoam == -100 || ws1.TotalFoam - ws1.AllUserFoam > 0) {//水源1有泡沫 if (WaterSourceLine2.Count > 0) {//线路2有链接 GameObject dir2 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine2[0][0]); WaterSource ws2 = dir2.GetComponent(); if (ws2.foam && (ws2.TotalFoam == -100 || ws2.TotalFoam - ws2.AllUserFoam > 0)) {//水源2有泡沫,两水源平分 ws1.UserFoam((Flow / 0.97f) * 0.03f / 2); ws2.UserFoam((Flow / 0.97f) * 0.03f / 2); } else { ws1.UserFoam((Flow / 0.97f) * 0.03f); } } else { ws1.UserFoam((Flow / 0.97f) * 0.03f); } } else {//线路1没泡沫 if (WaterSourceLine2.Count > 0) {//线路2有链接 GameObject dir2 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine2[0][0]); WaterSource ws2 = dir2.GetComponent(); if (ws2.foam && (ws2.TotalFoam == -100 || ws2.TotalFoam - ws2.AllUserFoam > 0)) {//水源2有泡沫 ws2.UserFoam((Flow / 0.97f) * 0.03f); } else { Debug.Log("没泡沫"); } } else { Debug.Log("没泡沫"); } } } } else { if (WaterSourceLine2.Count > 0) { GameObject dir2 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine2[0][0]); WaterSource ws2 = dir2.GetComponent(); if (ws2.foam && (ws2.TotalFoam == -100 || ws2.TotalFoam - ws2.AllUserFoam > 0)) {//水源2有泡沫 ws2.UserFoam((Flow / 0.97f) * 0.03f); } else { Debug.Log("没泡沫"); } } } } else {//没泡沫 //LoadPromptWin.Instance.LoadTextPromptWindow("泡沫量不足", 1f); stopspraywaterorform(); } } } #endregion timer = 1f; } } } } public void OnEnable() { //Todo 监听连接水源(有消耗)的水量 // MessageDispatcher.AddListener("WATERHOSECONNECT", AddWaterHose); // MessageDispatcher.AddListener("DelectWaterHose", DestoryWaterHose); MessageDispatcher.AddListener("HOSE_CONNECT_OR_DELECT", ConnectOrDelectControl); MessageDispatcher.AddListener("WATERCAR_BIND_CURTAINHOSE", AddWaterCurtainHose); MessageDispatcher.AddListener("WATERCAR_DESTORY_CURTAINHOSE", DestoryWaterCurtainHose); MessageDispatcher.AddListener("StartConnectDone", EndConnectDo); } public void OnDestroy() { //MessageDispatcher.RemoveListener("WATERHOSECONNECT", AddWaterHose); // MessageDispatcher.RemoveListener("DelectWaterHose", DestoryWaterHose); MessageDispatcher.RemoveListener("SPRAY_WATER", Changeflow); MessageDispatcher.RemoveListener("RUN_OUR_OF_WATER", CloseSpray); MessageDispatcher.RemoveListener("HOSE_CONNECT_OR_DELECT", ConnectOrDelectControl); MessageDispatcher.RemoveListener("WATERCAR_BIND_CURTAINHOSE", AddWaterCurtainHose); MessageDispatcher.RemoveListener("WATERCAR_DESTORY_CURTAINHOSE", DestoryWaterCurtainHose); MessageDispatcher.RemoveListener("StartConnectDone", EndConnectDo); //销毁所有所连接的管线 for (int i = 0; i < allConnectWaterHose.Count; i++) { if (allConnectWaterHose[i] != null) { EntitiesManager.Instance.DeleteObj(allConnectWaterHose[i]); } } GetRealtimeConsume.getAllRealtimeConsume -= addMyRealtimeConsume; } private FloatData addMyRealtimeConsume(FloatData data) { data.value += Flow; return data; } public void OnDisable() { //MessageDispatcher.RemoveListener("WATERHOSECONNECT", AddWaterHose); //MessageDispatcher.RemoveListener("DelectWaterHose", DestoryWaterHose); MessageDispatcher.RemoveListener("SPRAY_WATER", Changeflow); MessageDispatcher.RemoveListener("RUN_OUR_OF_WATER", CloseSpray); MessageDispatcher.RemoveListener("HOSE_CONNECT_OR_DELECT", ConnectOrDelectControl); MessageDispatcher.RemoveListener("WATERCAR_BIND_CURTAINHOSE", AddWaterCurtainHose); MessageDispatcher.RemoveListener("WATERCAR_DESTORY_CURTAINHOSE", DestoryWaterCurtainHose); MessageDispatcher.RemoveListener("StartConnectDone", EndConnectDo); } /// /// 连接管线处理完起点之后再处理终点,防止连接终点比起点先接受连接管线信息导致DirectConnectObj没有赋值信息,然后不能正确对其设置水源信息,仅处理连接 /// /// private void EndConnectDo(IMessage obj) { WaterHoseEndDo data = (WaterHoseEndDo)obj.Data; if (gameobjinfo.gameObjID == data.EndId) { GameObject ws = EntitiesManager.Instance.GetEntityByID(data.StartId); //GameObject hose = EntitiesManager.Instance.GetEntityByID(data.HoseId); // GameObject anther = hose.GetComponent().GetAnotherGameObj(gameobjinfo.gameObjID); if (data.ConnectInPoint == 1) {//进水口1未使用,连接进水口1 // if (anther.GetComponent()) // {//如果连接起点为水源车,因为起点必定是水源就没加watersource的判断 ChangeWaterSourceLineInfo(data.StartId, 1); inWaterHose1 = data.ConnectHose; if (GetComponent()) {//如果自己是水源车 if (GetComponent().HasWaterSelfAndLine == false) {//自己以及线上没水了 float remain = checkWaterRemain(WaterSourceLine1); if (remain > 0 || remain == -100) {//新水源有水 GetComponent().HasWaterSelfAndLine = true; } } } //如果起点为消防设施,分流处理,(起点为水源车辆已经在水源车辆连接起点处理) if (!ws.GetComponent()) {//连接水源为非车辆 if (GetComponent()) {//如果自身是水源车 if (GetComponent().TotalFlow > 0) {//本身所在网络在出水 注:自己在出水网络但是自己作为最终供水端已经没有水可用即TotalFlow为0,会在HasWaterSelfAndLine中处理 if (WaterSourceLine2.Count > 0) {//线路2有链接 GameObject ws2 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine2[0][0]); float remain2 = checkWaterRemain(WaterSourceLine2); if (remain2 == -100 || remain2 > 0) {//线路2 有水 ws.GetComponent().TotalFlowChange(gameobjinfo.gameObjID, GetComponent().TotalFlow / 2); ws2.GetComponent().TotalFlowChange(gameobjinfo.gameObjID, GetComponent().TotalFlow / 2); } else { ws.GetComponent().TotalFlowChange(gameobjinfo.gameObjID, GetComponent().TotalFlow); } } } } else {//自身为非水源车 if (Flow > 0) {//本身在出水 if (WaterSourceLine2.Count > 0) {//线路2有链接,自身为非水源又在出水,线路2肯定有连接且有水。。。 GameObject ws2 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine2[0][0]); float remain2 = checkWaterRemain(WaterSourceLine2); if (remain2 == -100 || remain2 > 0) {//线路2 有水 ws.GetComponent().TotalFlowChange(gameobjinfo.gameObjID, GetComponent().TotalFlow / 2); ws2.GetComponent().TotalFlowChange(gameobjinfo.gameObjID, GetComponent().TotalFlow / 2); } else { ws.GetComponent().TotalFlowChange(gameobjinfo.gameObjID, GetComponent().TotalFlow); } } } } } } else if (data.ConnectInPoint == 2) { if (WaterSourceLine2.Count <= 0) {//进水口2未使用,连接进水口2 //if (anther.GetComponent()) //{//如果连接起点为水源车,因为起点必定是水源就没加watersource的判断 inWaterHose2 = data.ConnectHose; ChangeWaterSourceLineInfo(data.StartId, 2); if (GetComponent()) {//如果自己是水源车 if (GetComponent().HasWaterSelfAndLine == false) {//自己以及线上没水了 float remain = checkWaterRemain(WaterSourceLine2); if (remain > 0 || remain == -100) {//新水源有水 GetComponent().HasWaterSelfAndLine = true; } } } //} if (!ws.GetComponent()) {//连接水源为非车辆 if (GetComponent()) {//如果自身是水源车 if (GetComponent().TotalFlow > 0) {//本身所在网络在出水 注:自己在出水网络但是自己作为最终供水端已经没有水可用即TotalFlow为0,会在HasWaterSelfAndLine中处理 if (WaterSourceLine1.Count > 0) {//线路1有链接 GameObject ws1 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[0][0]); float remain1 = checkWaterRemain(WaterSourceLine1); if (remain1 == -100 || remain1 > 0) {//线路2 有水 ws.GetComponent().TotalFlowChange(gameobjinfo.gameObjID, GetComponent().TotalFlow / 2); ws1.GetComponent().TotalFlowChange(gameobjinfo.gameObjID, GetComponent().TotalFlow / 2); } else { ws.GetComponent().TotalFlowChange(gameobjinfo.gameObjID, GetComponent().TotalFlow); } } } } else {//自身为非水源车 if (Flow > 0) {//本身在出水 if (WaterSourceLine1.Count > 0) {//线路2有链接,自身为非水源又在出水,线路1肯定有连接且有水。。。 GameObject ws1 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[0][0]); float remain1 = checkWaterRemain(WaterSourceLine1); if (remain1 == -100 || remain1 > 0) {//线路2 有水 ws.GetComponent().TotalFlowChange(gameobjinfo.gameObjID, GetComponent().TotalFlow / 2); ws1.GetComponent().TotalFlowChange(gameobjinfo.gameObjID, GetComponent().TotalFlow / 2); } else { ws.GetComponent().TotalFlowChange(gameobjinfo.gameObjID, GetComponent().TotalFlow); } } } } } } else { Debug.Log(name + "没有更多进水口,检查连接逻辑"); } } if (!GetComponent()) {//非水源车辆直接水源赋值及UI显示 // ConnentWaterSource = anther; ConnectWater = true; if (!ConnectFoam) { ConnectFoam = EntitiesManager.Instance.GetEntityByID(data.StartId).GetComponent().foam; } RefreshUI(ConnectWater, ConnectFoam); } } } //同步的管线连接到该车辆或者连接在该车辆的管线同步删除时,移动控制 private void ConnectOrDelectControl(IMessage obj) { HoseConnectOrDelectData data = (HoseConnectOrDelectData)obj.Data; if (data.StartId == gameobjinfo.gameObjID || data.EndId == gameobjinfo.gameObjID) { GameObject hose = EntitiesManager.Instance.GetEntityByID(data.HoseId); //移动处理 if (data.Isconnect) { GetComponent().pathFindEnable = false; if (!allConnectWaterHose.Contains(hose)) { allConnectWaterHose.Add(hose); } } else { if (allConnectWaterHose.Contains(hose)) { allConnectWaterHose.Remove(hose); } if (allConnectWaterHose.Count <= 0 && allConnectWaterCurtainHose.Count <= 0) { if (GetComponent().DisableSkills.Contains(TruckSkills.固定支架)) { GetComponent().pathFindEnable = false; } else { GetComponent().pathFindEnable = true; } } } //水源信息处理 GameObject anther = hose.GetComponent().GetAnotherGameObj(gameobjinfo.gameObjID); //管线连接 if (data.Isconnect) { if (gameobjinfo.gameObjID == data.StartId) {//为连接起点,起点必定是水源 //if (DirectConnectObj1.Key != null && DirectConnectObj2.Key != null && (hose != outtWaterHose1 || hose != outWaterHose2)) //{ // Debug.Log(name + " 两个出水口都被占用,检查连接逻辑,没限制住"); //} if (DirectConnectObj1.Key == null) {//出水口1空闲 outtWaterHose1 = hose; DirectConnectObj1 = Directionconnect(anther, data.EndId, data.StartId, DirectConnectObj1, hose); Debug.Log(name + "连接进水口1,连接的" + anther.name); #region //if (anther.GetComponent()) //{//另一端为可出水车辆 // if (anther.GetComponent().WaterSourceLine1.Count <= 0) // {//另一端进水口1没有被占用,连接进水口1 // DirectConnectObj1 = new KeyValuePair(anther, 1); // //连接了一个出水的网络 // if (anther.GetComponent()) // {//有watersource必为水源车,因为消防设施不能为连接终点 // if (anther.GetComponent().TotalFlow > 0) // {//连接的网络正在出水,修改流量信息 // if (anther.GetComponent().WaterSourceLine2.Count > 0) // {//另一条进水口有水源,另一端连接的肯定为进水口2 // float remain = anther.GetComponent().checkWaterRemain( // anther.GetComponent().WaterSourceLine2); // if (remain > 0 || remain == -100) // {//另一端水源有水 // GetComponent().TotalFlowChange(data.EndId, anther.GetComponent().TotalFlow / 2); // GameObject antherdir2 = EntitiesManager.Instance.GetEntityByID(anther.GetComponent().WaterSourceLine2[0][0]); // antherdir2.GetComponent().TotalFlowChange(data.EndId, anther.GetComponent().TotalFlow / 2); // } // else // {//另一端水源没水了但是在出水可能是消耗自己的水 // //另一端在连接了水源之后就不再消耗自己的水了,可以看watersource的updata逻辑 // GetComponent().TotalFlowChange(data.EndId, anther.GetComponent().TotalFlow); // } // } // } // } // } // else if (anther.GetComponent().WaterSourceLine2.Count <= 0) // { // //另一端进水口2没有被占用,连接进水口2 // DirectConnectObj1 = new KeyValuePair(anther, 2); // //连接了一个出水的网络 // if (anther.GetComponent()) // {//有watersource必为水源车,因为消防设施不能为连接终点 // if (anther.GetComponent().TotalFlow > 0) // {//连接的网络正在出水,修改流量信息 // if (anther.GetComponent().WaterSourceLine1.Count > 0) // {//另一条进水口有水源,另一端连接的肯定为进水口1 // float remain = anther.GetComponent().checkWaterRemain( // anther.GetComponent().WaterSourceLine1); // if (remain > 0 || remain == -100) // {//另一端水源有水 // GetComponent().TotalFlowChange(data.EndId, anther.GetComponent().TotalFlow / 2); // GameObject antherdir1 = EntitiesManager.Instance.GetEntityByID(anther.GetComponent().WaterSourceLine1[0][0]); // antherdir1.GetComponent().TotalFlowChange(data.EndId, anther.GetComponent().TotalFlow / 2); // } // else // {//另一端水源没水了但是在出水可能是消耗自己的水 // //另一端在连接了水源之后就不再消耗自己的水了,可以看watersource的updata逻辑 // GetComponent().TotalFlowChange(data.EndId, anther.GetComponent().TotalFlow); // } // } // } // } // } // else // { // Debug.Log(anther.name + " 没有更多进水口,检查连接逻辑"); // } //} //else //{//另一端为非车辆,则只有一个进水口,并且如果另一端不是车辆则一定没有在出水,因为只有一个进水口 // DirectConnectObj1 = new KeyValuePair(anther, 0); //} #endregion } else {//出水口1被占用 if (hose == outtWaterHose1) {//还是同一条水带的连接 DirectConnectObj1 = Directionconnect(anther, data.EndId, data.StartId, DirectConnectObj1, hose); Debug.Log(name + "连接进水口1,连接的" + anther.name); } else { if (DirectConnectObj2.Key == null) {//出水口2空闲 outWaterHose2 = hose; DirectConnectObj2 = Directionconnect(anther, data.EndId, data.StartId, DirectConnectObj2, hose); Debug.Log(name + "连接进水口2,连接的" + anther.name); } else { if (hose == outWaterHose2) { DirectConnectObj2 = Directionconnect(anther, data.EndId, data.StartId, DirectConnectObj2, hose); Debug.Log(name + "连接进水口2,连接的" + anther.name); //WaterHoseEndDo arg = new WaterHoseEndDo //{ // ConnectHose = hose, // StartId = gameobjinfo.gameObjID, // ConnectInPoint = 2, // EndId = data.EndId, //}; //MessageDispatcher.SendMessage("StartConnectDone", arg); } else { Debug.Log(name + "没有更多进水口"); } } } } } #region //else //{//该车辆为连接终点 // if (WaterSourceLine1.Count <= 0) // {//进水口1未使用,连接进水口1 // // if (anther.GetComponent()) // // {//如果连接起点为水源车,因为起点必定是水源就没加watersource的判断 // ChangeWaterSourceLineInfo(anther.GetComponent().gameObjID, 1); // inWaterHose1 = hose; // if (GetComponent()) // {//如果自己是水源车 // if (GetComponent().HasWaterSelfAndLine == false) // {//自己以及线上没水了 // float remain = checkWaterRemain(WaterSourceLine1); // if (remain > 0 || remain == -100) // {//新水源有水 // GetComponent().HasWaterSelfAndLine = true; // } // } // } // // } // // else // // {//连接起点为设施 // // } // } // else // { // if (WaterSourceLine2.Count <= 0) // {//进水口2未使用,连接进水口2 // //if (anther.GetComponent()) // //{//如果连接起点为水源车,因为起点必定是水源就没加watersource的判断 // inWaterHose2 = hose; // ChangeWaterSourceLineInfo(anther.GetComponent().gameObjID, 2); // if (GetComponent()) // {//如果自己是水源车 // if (GetComponent().HasWaterSelfAndLine == false) // {//自己以及线上没水了 // float remain = checkWaterRemain(WaterSourceLine2); // if (remain > 0 || remain == -100) // {//新水源有水 // GetComponent().HasWaterSelfAndLine = true; // } // } // } // //} // } // else // { // Debug.Log(name + "没有更多进水口,检查连接逻辑"); // } // } // if (!GetComponent()) // {//非水源车辆直接水源赋值及UI显示 // // ConnentWaterSource = anther; // ConnectWater = true; // if (!ConnectFoam) // { // ConnectFoam = anther.GetComponent().foam; // } // RefreshUI(ConnectWater, ConnectFoam); // } //} #endregion #region 原来代码 // if (!GetComponent()) // { // if (anther.GetComponent()) // {//如果另一端是水源 // //Todo:连接多个水源 // //假设已经连接了水源,又连接了水源,水源及消耗按老的 // if (ConnentWaterSource != null) // {//Todo:多水源处理 // //LoadPromptWin.Instance.LoadTextPromptWindow("暂未处理多水源信息",1f); // Debug.Log("暂未处理多水源信息"); // return; // } // else // { // ConnectWater = anther.GetComponent().water; // ConnectFoam = anther.GetComponent().foam; // ConnentWaterSource = anther; // //如果练了一个没水的水源 // if (anther.GetComponent().hasover) // { // waterrunoutof = true; // } // //如果别人连接时 本客户端刚好选中当前车辆 // if (TruckSkillPanelController.GetInstance) // {//UI控制 // if (TruckSkillPanelController.GetInstance.NowBindTruck == GetComponent()) // { // TruckSkillPanelController.GetInstance.SprayFoam.GetComponent().interactable = ConnectFoam; // TruckSkillPanelController.GetInstance.SprayWater.GetComponent().interactable = ConnectWater; // } // } // } // } // else // { // if (anther.GetComponent()) // { // //Todo: // //如果连接的是消防员,还要同步消防员的水源信息(因为这条管线本身就是别的客户端连的,所以要把水源信息返回去) // //LoadPromptWin.Instance.LoadTextPromptWindow("暂未处理消防员连接非本客户端非水源车的处理", 1f); // Debug.Log("暂未处理消防员连接非本客户端非水源车的处理"); // } // } // } // else // { // ConnectWater = GetComponent().water; // ConnectFoam = GetComponent().foam; // ConnentWaterSource = gameObject; // } //} ////管线删除 //else //{ // //TODO: // //因为现在消耗是按旧水源处理,所以如果删除的是非旧水源的管线,暂不处理 // if (anther.GetComponent()) // {//另一端是水源 // if (GetComponent()) // { // return; // } // if (ConnentWaterSource != null) // { // if (anther.GetComponent().gameObjID != ConnentWaterSource.GetComponent().gameObjID) // { // // // LoadPromptWin.Instance.LoadTextPromptWindow("暂未处理多水源的管线删除处理", 1f); // Debug.Log("暂未处理多水源的管线删除处理"); // } // } // else // { // Resert(); // } // } // else // {//另一端不是水源 // if (anther.GetComponent()) // { // anther.GetComponent().Resert(); // } // } //} #endregion } //删除管线 else { if (gameobjinfo.gameObjID == data.StartId) {//如果本车为该删除管线的起点,只把出水口信息清空,接水口水源信息由接水口接收的地方处理 if (hose == outtWaterHose1) {//删除的是出水口1的管线 DirectConnectObj1 = new KeyValuePair(); outtWaterHose1 = null; } else if (hose == outWaterHose2) { DirectConnectObj2 = new KeyValuePair(); outWaterHose2 = null; } //if (DirectConnectObj1.Key != null && DirectConnectObj1.Key.GetComponent().gameObjID == data.EndId) //{//出水口1不为空且出水口1就是管线终点所连接物体 // DirectConnectObj1 = new KeyValuePair(); // outtWaterHose1 = null; //} //if (DirectConnectObj2.Key != null && DirectConnectObj2.Key.GetComponent().gameObjID == data.EndId) //{//出水口2不为空且出水口2就是管线终点所连接物体 // DirectConnectObj2 = new KeyValuePair(); // outWaterHose2 = null; //} } else {//如果为终点 if (inWaterHose1 == hose) {//进水口1有链接并且直接水源为删除管线的起点 WaterSourceLine1 = new List>(); inWaterHose1 = null; //WaterSourceLine1.Clear(); } else if (inWaterHose2 == hose) {//进水口2有链接并且直接水源为删除管线的起点 WaterSourceLine2 = new List>(); inWaterHose2 = null; // WaterSourceLine2.Clear(); } } if (!GetComponent()) {//非水源车辆直接水源赋值及UI显示 // ConnentWaterSource = anther; CheckWaterHose(); //RefreshUI(ConnectWater, ConnectFoam); } } } } private void Changeflow(IMessage obj) { var info = (flowchangeinfo)obj.Data; if (info.ChangObjId == gameobjinfo.gameObjID) { if (GetComponent()) { GetComponent().SetTotalFlow(new KeyValuePair(gameObject, Flow), info.IsAdd); } else { if (ConnentWaterSource != null) { ConnentWaterSource.GetComponent().SetTotalFlow(new KeyValuePair(gameObject, Flow), info.IsAdd); } } } } private void CloseSpray(IMessage obj) { if (GetComponent().NowSkill == TruckSkills.喷水 || GetComponent().NowSkill == TruckSkills.喷泡沫) { long watersourceId = (long)obj.Data; long thiswaterid = -1; if (GetComponent()) { thiswaterid = GetComponent().gameObjID; } else { if (ConnentWaterSource != null) { thiswaterid = ConnentWaterSource.GetComponent().GetComponent().gameObjID; } } if (watersourceId == thiswaterid) { waterrunoutof = true; GetComponent().NowSkill = TruckSkills.待命; Flow = 0; if (TruckSkillPanelController.GetInstance) { if (TruckSkillPanelController.GetInstance.NowBindTruck == GetComponent()) { TruckSkillPanelController.GetInstance.SprayFoam.GetComponent().isOn = false; TruckSkillPanelController.GetInstance.SprayWater.GetComponent().isOn = false; } } for (int i = 0; i < Hose.childCount; i++) { //Destroy(Hose.GetChild(i).gameObject); Hose.GetChild(i).gameObject.SetActive(false); } SpraySyncData spraysync = new SpraySyncData(); spraysync.SendUserID = CurrentUserInfo.mySelf.Id; spraysync.IsOn = false; spraysync.gameObjID = gameobjinfo.gameObjID; NetworkManager.Default.SendAsync(/*CurrentUserInfo.mySelf.Id,*/ "SPRAY_WATER_SYNC", spraysync); } } } /// /// Todo:连接多个水源问题,牵扯水量消耗 /// 有管线连接到车上,现在连接多个水源按老的 /// /// private void AddWaterHose(IMessage obj) { var data = ((HoseConnectOrDelectData)obj.Data); var waterhose = EntitiesManager.Instance.GetEntityByID(data.HoseId);// data.SelectHoseWater; GameObject anthersider = waterhose.GetComponent().GetAnotherGameObj(gameObject); //如果该物体是管线的起点 if (GetComponent().gameObjID == data.StartId) { if (!allConnectWaterHose.Contains(waterhose)) { allConnectWaterHose.Add(waterhose); } //禁用寻路 if (allConnectWaterHose.Count > 0) { GetComponent().pathFindEnable = false; } //水源车出水口使用状况,用以判断能否再其他连接管线 if (GetComponent()) { if (DirectConnectObj1.Key == null) {//如果进水口1空闲 if (anthersider.GetComponent()) {//另一端为车辆 if (anthersider.GetComponent().WaterSourceLine1.Count <= 0) {//另一端进水口1没有被占用,连接进水口1 DirectConnectObj1 = new KeyValuePair(anthersider, 1); } else if (anthersider.GetComponent().WaterSourceLine2.Count <= 0) { //另一端进水口2没有被占用,连接进水口1 DirectConnectObj1 = new KeyValuePair(anthersider, 2); } else { Debug.Log(anthersider.name + "没有更多进水口,检查连接逻辑"); } } else {//另一端为非车辆 } } else {//进水口1被占用 if (DirectConnectObj2.Key == null) {//进水口二未被占用 //DirectConnectObj2 = anthersider; } } } if (!GetComponent()) { var endObj = EntitiesManager.Instance.GetEntityByID(data.EndId); if (ConnentWaterSource != null) { //ToDo连接多个水源问题 return; } if (endObj.GetComponent()) { if (endObj.GetComponent().water) { ConnectWater = true; } if (endObj.GetComponent().foam) { ConnectFoam = true; } ConnentWaterSource = endObj; RefreshUI(ConnectWater, ConnectFoam); } } //如果该车是非水源车辆并连接了消防员,重设消防员的水源信息 //if (!GetComponent()) //{ // for (int i = 0; i < allConnectWaterHose.Count; i++) // { // GameObject otherside = allConnectWaterHose[i].GetComponent().GetAnotherGameObj(gameObject); // RefushFiremanWaterInfo(otherside); // } //} //TruckWaterMessageSyncData arg = new TruckWaterMessageSyncData(); //arg.SendUserID = CurrentUserInfo.mySelf.Id; //arg.gameObjID = GetComponent().gameObjID; //arg.ConnectWaterHose = waterhose.GetComponent().gameObjID; //arg.IsConncet = true; //NetworkManager.Default.SendAsync("TRUCK_WATER_MESSAGE_SYNC", arg); } //如果该物体是管线的终点 if (GetComponent().gameObjID == data.EndId) { if (!allConnectWaterHose.Contains(waterhose)) { allConnectWaterHose.Add(waterhose); } //禁用寻路 if (allConnectWaterHose.Count > 0) { GetComponent().pathFindEnable = false; } //ToDo: //绑定水源信息 // // if (!GetComponent()) { var startObj = EntitiesManager.Instance.GetEntityByID(data.StartId); if (startObj.GetComponent()) { if (ConnentWaterSource != null) { //ToDo连接多个水源问题 return; } if (startObj.GetComponent().water) { ConnectWater = true; } if (startObj.GetComponent().foam) { ConnectFoam = true; } ConnentWaterSource = startObj; RefreshUI(ConnectWater, ConnectWater); } } //如果该车是非水源车辆并连接了消防员,重设消防员的水源信息 //if (!GetComponent()) //{ // for (int i = 0; i < allConnectWaterHose.Count; i++) // { // GameObject otherside = allConnectWaterHose[i].GetComponent().GetAnotherGameObj(gameObject); // RefushFiremanWaterInfo(otherside); // } //} //TruckWaterMessageSyncData arg = new TruckWaterMessageSyncData(); //arg.SendUserID = CurrentUserInfo.mySelf.Id; //arg.gameObjID = GetComponent().gameObjID; //arg.ConnectWaterHose = waterhose.GetComponent().gameObjID; //arg.IsConncet = true; //NetworkManager.Default.SendAsync("TRUCK_WATER_MESSAGE_SYNC", arg); } } /// /// 绑定连接到水源车上的水幕水带 /// /// private void AddWaterCurtainHose(IMessage obj) { if (GetComponent()) {//因此脚本水源车及出水车上都绑定了,所以需判断是否是水源车。水源车才需要绑定 var info = (WaterCarBindCurtainHose)obj.Data; if (info.WaterSourceObjId == GetComponent().gameObjID) {//判断水幕水带连接的车的是否是此脚本所挂载的对象本身 if (DirectConnectObj1.Key == null) { DirectConnectObj1 = new KeyValuePair(info.WaterCurtainHose, 0); } else { if (DirectConnectObj1.Key == info.WaterCurtainHose) { } if (DirectConnectObj2.Key == null) { DirectConnectObj2 = new KeyValuePair(info.WaterCurtainHose, 0); } else { if (DirectConnectObj2.Key == info.WaterCurtainHose) { } else { Debug.Log("没有更多出水口,检查连接逻辑"); } } } if (info.isConnect && !allConnectWaterCurtainHose.Contains(info.WaterCurtainHose)) { allConnectWaterCurtainHose.Add(info.WaterCurtainHose); } //禁用寻路 if (allConnectWaterCurtainHose.Count > 0) { GetComponent().pathFindEnable = false; } } } } /// /// 删除连接的管线 /// /// private void DestoryWaterHose(IMessage obj) { var data = ((WaterHoseDelectCmdArgs)obj.Data); //把管线从本车的管线列表中移除 var waterhose = data.SelectHoseWater; if (gameobjinfo.gameObjID == data.StartObjId || gameobjinfo.gameObjID == data.EndObjId) { GameObject antherside = waterhose.GetComponent().GetAnotherGameObj(gameObject); if (gameobjinfo.gameObjID == data.StartObjId && GetComponent()) {//水源车并且为连接起点,清除其出水口 //if (DirectConnectObj1==antherside) //{ // DirectConnectObj1 = null; //} //if (DirectConnectObj2==antherside) //{ // DirectConnectObj2 = null; //} } allConnectWaterHose.Remove(waterhose); //启用寻路 if (allConnectWaterHose.Count < 1) { GetComponent().pathFindEnable = true; } if (GetComponent()) { return; } CheckWaterHose(); if (allConnectWaterHose.Count <= 0) { //水源信息同步 TruckWaterMessageSyncData arg = new TruckWaterMessageSyncData(); arg.SendUserID = CurrentUserInfo.mySelf.Id; arg.gameObjID = GetComponent().gameObjID; arg.ConnectWaterHose = waterhose.GetComponent().gameObjID; arg.IsConncet = false; NetworkManager.Default.SendAsync("TRUCK_WATER_MESSAGE_SYNC", arg); } //因为出水时不能删除管线所以下边没用了 //如果是非水源车,而且在出水,同步出水 if (!GetComponent()) { if ((!ConnectWater && GetComponent().NowSkill == TruckSkills.喷水) || (!ConnectFoam && GetComponent().NowSkill == TruckSkills.喷泡沫)) { for (int i = 0; i < Hose.childCount; i++) { Destroy(Hose.GetChild(i).gameObject); } SpraySyncData spraysync = new SpraySyncData(); spraysync.SendUserID = CurrentUserInfo.mySelf.Id; spraysync.IsOn = false; spraysync.gameObjID = gameobjinfo.gameObjID; NetworkManager.Default.SendAsync("SPRAY_WATER_SYNC", spraysync); } } } ////如果这个车连接了消防员,修改消防员水原信息 //if (!GetComponent()) //{ // if (allConnectWaterHose.Count > 0) // { // for (int i = 0; i < allConnectWaterHose.Count; i++) // { // GameObject otherside = allConnectWaterHose[i].GetComponent().GetAnotherGameObj(gameObject); // RefushFiremanWaterInfo(otherside); // } // } //} } /// /// 删除连接在本车上的水幕水带 /// /// private void DestoryWaterCurtainHose(IMessage obj) { if (GetComponent()) {//因此脚本水源车及出水车上都绑定了,所以需判断是否是水源车。水源车才需要绑定 var info = (WaterCarBindCurtainHose)obj.Data; if (info.WaterSourceObjId == GetComponent().gameObjID) {//判断水幕水带连接的车的是否是此脚本所挂载的对象本身 if (DirectConnectObj1.Key == info.WaterCurtainHose) { DirectConnectObj1 = new KeyValuePair(); } else { if (DirectConnectObj2.Key == info.WaterCurtainHose) { DirectConnectObj2 = new KeyValuePair(); } else { Debug.Log("两个出水口都没有连接该水幕水带"); } } if (!info.isConnect && allConnectWaterCurtainHose.Contains(info.WaterCurtainHose)) { allConnectWaterCurtainHose.Remove(info.WaterCurtainHose); } //禁用寻路 if (allConnectWaterCurtainHose.Count <= 0) { if (allConnectWaterHose.Count <= 0) { if (!GetComponent().IsFixedSupport) { GetComponent().pathFindEnable = true; } } } } } } /// /// 刷新消防车出水UI /// private void RefreshUI(bool water, bool foam) { if (SelectedObjs.selectedObj == gameObject) { if (TruckSkillPanelController.GetInstance) {//如果当前选中为该车辆且UI面板显示 // TruckSkillPanelController.GetInstance.SprayWater.gameObject.SetActive(water); TruckSkillPanelController.GetInstance.SprayWater.GetComponent().interactable = water;//.gameObject.SetActive(value); // TruckSkillPanelController.GetInstance.SprayFoam.gameObject.SetActive(foam); TruckSkillPanelController.GetInstance.SprayFoam.GetComponent().interactable = foam; } } } /// /// 删除管线后检查是否依旧连接水源 /// private void CheckWaterHose() { bool haswater = false; bool hasfoam = false; for (int i = 0; i < allConnectWaterHose.Count; i++) { var antherObj = allConnectWaterHose[i].GetComponent().GetAnotherGameObj(gameObject); //如果另一端有水源 if (antherObj.GetComponent()) { if (antherObj.GetComponent().water) { haswater = true; } if (antherObj.GetComponent().foam) { hasfoam = true; } } } ConnectFoam = hasfoam; ConnectWater = haswater; RefreshUI(ConnectWater, ConnectFoam); } //非水源消防车连接水源后更新该车连接的消防员的水源信息 private void RefushFiremanWaterInfo(GameObject otherside) { if (otherside.GetComponent()) { otherside.GetComponent().ResetWaterSourceConnectInfo(ConnectWater, ConnectFoam); otherside.GetComponent().ConnentSource = ConnentWaterSource; if (otherside == SkillTollPanel.Instance.SelectObj) { //该消防员UI出水按钮可选显示 if (FireManSkillPanelController.Instance) { if (ConnectWater || ConnectFoam) { if (!FireManSkillPanelController.Instance.SprayWater.GetComponent().interactable) { FireManSkillPanelController.Instance.SprayWater.GetComponent().interactable = true; } } if (!ConnectWater && !ConnectFoam) { if (FireManSkillPanelController.Instance.SprayWater.GetComponent().interactable) { FireManSkillPanelController.Instance.SprayWater.GetComponent().interactable = false; } } } } } } /// /// 喷水 /// public void SparyWater() { Hose.gameObject.SetActive(true); for (int i = 0; i < Hose.childCount; i++) { //Destroy(Hose.GetChild(i).gameObject); if (Hose.GetChild(i).gameObject.name == "WaterStraight") { if (!Hose.GetChild(i).gameObject.activeInHierarchy) { Hose.GetChild(i).gameObject.SetActive(true); } } else { Hose.GetChild(i).gameObject.SetActive(false); } } //GameObject water = Instantiate(WaterStraightPrefabs, Hose.transform); Hose.GetComponentInChildren().SetScaleValue(0.7f); ParticleSize = 0.7f; JudeHightCarSpray(); } /// /// 高喷车出水内置判断 /// private void JudeHightCarSpray() { if (GetComponent().gameObjType == CloneObjType.HighSprayingTruck) { bool isconnecttwo = true; if (waterSourceLine1.Count < 1 || waterSourceLine2.Count < 1) {//如果有一条线路没链接,内置判断为错 isconnecttwo = false; } else { long con1 = waterSourceLine1[0][0];//路线1 直接水源id long con2 = waterSourceLine2[0][0];//路线2 直接水源id if (con1 == con2) {//两个直接水源一样,则连在一个水源车上,内置判断为错 isconnecttwo = false; } } if (!isconnecttwo) { //发送错误报告同步信息 ReportErroeSyncData arg = new ReportErroeSyncData(); // (GetComponent()) { arg.Time = TIME_SYNC.time; } arg.SendUserID = CurrentUserInfo.mySelf.Id; arg.errorset = CurrentUserInfo.role.ToString(); arg.describe = "高喷车出水只连接一个水源"; NetworkManager.Default.SendAsync("REPORT_ERROR_SYNC", arg); } } } /// /// 喷泡沫 /// public void SparyFoam() { Hose.gameObject.SetActive(true); for (int i = 0; i < Hose.childCount; i++) { if (Hose.GetChild(i).gameObject.name == "Froth") { if (!Hose.GetChild(i).gameObject.activeInHierarchy) { Hose.GetChild(i).gameObject.SetActive(true); } } else { Hose.GetChild(i).gameObject.SetActive(false); } } // GameObject froth = Instantiate(FrothPrefabs, Hose.transform); Hose.GetComponentInChildren().SetScaleValue(1f); ParticleSize = 1f; } public void StopSpray() { Hose.gameObject.SetActive(false); for (int i = 0; i < Hose.childCount; i++) { Hose.GetChild(i).gameObject.SetActive(false); } } /// /// 重置水源信息跟出水状态 /// public void Resert() { if (GetComponent()) { ConnectWater = GetComponent().water; ConnectFoam = GetComponent().foam; ConnentWaterSource = gameObject; } else { ConnectWater = false; ConnectFoam = false; ConnentWaterSource = null; } StopSpray(); SpraySyncData spraysync = new SpraySyncData(); spraysync.SendUserID = CurrentUserInfo.mySelf.Id; spraysync.IsOn = false; spraysync.gameObjID = gameobjinfo.gameObjID; NetworkManager.Default.SendAsync("SPRAY_WATER_SYNC", spraysync); } /// /// 连接水源。删除管线时造成的水源信息修改 /// /// 直接水源上的两条线路信息总和 /// 直接水源id /// 连接的哪条线路 public void ChangeWaterSourceLineInfo(long directionId, int linenum) { List> go = CloneBySerialize.Clone(GetDirectWaterSourceInfo(directionId)); go.Insert(0, new List { directionId }); if (linenum == 1) { WaterSourceLine1 = go; } else if (linenum == 2) { WaterSourceLine2 = go; } } /// /// 获取直接水源上的所有水源信息 /// /// 直接水源ID /// public List> GetDirectWaterSourceInfo(long directtionId) { List> go = new List>(); GameObject dirobj = EntitiesManager.Instance.GetEntityByID(directtionId); if (dirobj.GetComponent()) { TruckBindWaterSource dirTBC = dirobj.GetComponent(); List> line1 = CloneBySerialize.Clone(dirTBC.WaterSourceLine1); List> line2 = CloneBySerialize.Clone(dirTBC.WaterSourceLine2); line1.Reverse(); line2.Reverse(); int count = line1.Count >= line2.Count ? line1.Count : line2.Count; //List> go = new List>(count); for (int i = 0; i < count; i++) { List depth = new List(); if (i < line1.Count) { for (int j = 0; j < line1[i].Count; j++) { depth.Add(line1[i][j]); } } if (i < line2.Count) { for (int j = 0; j < line2[i].Count; j++) { depth.Add(line2[i][j]); } } go.Add(depth); } go.Reverse(); } else {//消防设施没有进水口,所以直接返回go } return go; } /// /// 检查出水口连接并更改出水口连接物体的水源信息 /// void checkOutAndChangeWaterInfo() { if (DirectConnectObj1.Key != null) { checkandchange(DirectConnectObj1); } if (DirectConnectObj2.Key != null) { checkandchange(DirectConnectObj2); } } void checkandchange(KeyValuePair target) { if (target.Key.GetComponent()) { // TruckBindWaterSource tbws = target.Key.GetComponent(); //if (tbws.WaterSourceLine1[0][0] == gameobjinfo.gameObjID) // {//如果线路1连接的本车辆 target.Key.GetComponent().ChangeWaterSourceLineInfo(gameobjinfo.gameObjID, target.Value); // } // else if (tbws.WaterSourceLine2[0][0] == gameobjinfo.gameObjID) // { //如果线路2连接的本车辆 //target.Key.GetComponent().ChangeWaterSourceLineInfo(gameobjinfo.gameObjID, 2); //} } else { CloneObjType type = target.Key.GetComponent().gameObjType; if (type == CloneObjType.fireman) { target.Key.GetComponent().ChangeWaterSourceLineInfo(gameobjinfo.gameObjID, 0); } else if (type == CloneObjType.FirefightingRobot) { target.Key.GetComponent().ChangeWaterSourceLineInfo(gameobjinfo.gameObjID, 0); } else if (type == CloneObjType.SnowCannon) { target.Key.GetComponent().ChangeWaterSourceLineInfo(gameobjinfo.gameObjID, 0); } else if (type == CloneObjType.WaterCannon) { target.Key.GetComponent().ChangeWaterSourceLineInfo(gameobjinfo.gameObjID, 0); } } } /// /// 获取车辆上的所有水源车辆,有重复添加(若任意线路上任意连接点进水口1跟2连接的同一水源,则重复) /// 不能根据末尾计算消耗,因为当某水源节点两个进水口连接同一水源但是水源线长度不同,则会出现末尾可能出现在前边 /// /// public List> GetAllWaterSource() { List> go = new List>(); List> line1 = CloneBySerialize.Clone(WaterSourceLine1); List> line2 = CloneBySerialize.Clone(WaterSourceLine2); line1.Reverse(); line2.Reverse(); int count = line1.Count >= line2.Count ? line1.Count : line2.Count; //List> go = new List>(count); for (int i = 0; i < count; i++) { List depth = new List(); if (i < line1.Count) { for (int j = 0; j < line1[i].Count; j++) { depth.Add(line1[i][j]); } } if (i < line2.Count) { for (int j = 0; j < line2[i].Count; j++) { depth.Add(line2[i][j]); } } go.Add(depth); } go.Reverse(); return go; } /// /// 检查某条线路上是否有水 /// /// /// public float checkWaterRemain(List> watersouce) { float allremain = 0; for (int i = 0; i < watersouce.Count; i++) { for (int j = 0; j < watersouce[i].Count; j++) { if (EntitiesManager.Instance.GetEntityByID(watersouce[i][j]) && EntitiesManager.Instance.GetEntityByID(watersouce[i][j]).GetComponent()) { WaterSource ws = EntitiesManager.Instance.GetEntityByID(watersouce[i][j]).GetComponent(); if (ws.TotalWater != -100) { allremain += (ws.TotalWater - ws.AllUserWater); } else { allremain = -100; break; } } } } return allremain; } KeyValuePair Directionconnect(GameObject anther, long EndId, long StartId, KeyValuePair target, GameObject hose) { target = new KeyValuePair(); if (anther.GetComponent()) {//另一端为可出水车辆 if (anther.GetComponent().WaterSourceLine1.Count <= 0) {//另一端进水口1没有被占用,连接进水口1 target = new KeyValuePair(anther, 1); WaterHoseEndDo arg = new WaterHoseEndDo { ConnectHose = hose, StartId = gameobjinfo.gameObjID, ConnectInPoint = 1, EndId = EndId, }; MessageDispatcher.SendMessage("StartConnectDone", arg); Debug.Log(name + "出水口占用" + anther.name + "的进水口1"); //连接了一个出水的网络 if (anther.GetComponent()) {//有watersource必为水源车,因为消防设施不能为连接终点 //注:考虑喷泡沫的情况,如果另一端为水源车,如果出泡沫,则泡沫值消耗其自身泡沫量,连接供水网络跟泡沫无关 //注:这里存在因为自身及自身供水端没有水的情况而导致水流量为0(即直接连接物体没有水、不出水,但是其下属连接可能存在出水情况,也是连接的出水网络) //此时watersource脚本的HasWaterSelfAndLine为false,修改这个值.HasWaterSelfAndLine为false修改后会逐级修改下一级的HasWaterSelfAndLine为false值, //当遇到出水的车辆时(若为其他,单干线),会根据出水车辆的流量进行分流,分流后又会主逐级上找,修改TotalFlow if (GetComponent().HasWaterSelfAndLine) {//自己本身有水 if (anther.GetComponent().HasWaterSelfAndLine == false) { anther.GetComponent().HasWaterSelfAndLine = true; } } if (anther.GetComponent().TotalFlow > 0) {//连接的网络正在出水,修改流量信息 ,泡沫消耗自己的,不考虑泡沫的分配 if (!GetComponent().HasWaterSelfAndLine) {//自身没水 } else {//自身有水,分流 if (anther.GetComponent().WaterSourceLine2.Count > 0) {//另一条进水口有水源,另一端连接的肯定为进水口2 float remain = anther.GetComponent().checkWaterRemain( anther.GetComponent().WaterSourceLine2); if (remain > 0 || remain == -100) {//另一端水源有水 if (gameobjinfo.gameObjID == anther.GetComponent().WaterSourceLine2[0][0]) {//另一端连接的是自己,不更改流量信息 } else { GetComponent().TotalFlowChange(EndId, anther.GetComponent().TotalFlow / 2); GameObject antherdir2 = EntitiesManager.Instance.GetEntityByID(anther.GetComponent().WaterSourceLine2[0][0]); antherdir2.GetComponent().TotalFlowChange(EndId, anther.GetComponent().TotalFlow / 2); } } else {//另一端水源没水了但是在出水可能是消耗自己的水 //另一端在连接了水源之后就不再消耗自己的水了,可以看watersource的updata逻辑 GetComponent().TotalFlowChange(EndId, anther.GetComponent().TotalFlow); } } else if (anther.GetComponent().WaterSourceLine2.Count <= 0) {//另一点没水源 GetComponent().TotalFlowChange(EndId, anther.GetComponent().TotalFlow); } } } } else {//连接的是单一物体或非水源车辆 if (!GetComponent().HasWaterSelfAndLine) {//自身没水 } else {//自己有水 if (anther.GetComponent()) {//连接的是可出水车辆 if (anther.GetComponent().Flow > 0) {//出水车辆在出水,分流 //出的是泡沫,分流注意 if (anther.GetComponent().WaterSourceLine2.Count > 0) {//另一条进水口有水源,另一端连接的肯定为进水口2 float remain = anther.GetComponent().checkWaterRemain( anther.GetComponent().WaterSourceLine2); if (remain > 0 || remain == -100) {//另一端水源有水 if (gameobjinfo.gameObjID == anther.GetComponent().WaterSourceLine2[0][0]) {//另一端连接的是自己 } else { GameObject antherdir2 = EntitiesManager.Instance.GetEntityByID(anther.GetComponent().WaterSourceLine2[0][0]); if (anther.GetComponentInChildren().particleType == SprayParticleType.Froth) {//如果出的是泡沫 WaterSource waters = GetComponent(); if (waters.foam && (waters.AllUserFoam == -100 || (waters.TotalFoam - waters.AllUserFoam) > 0)) {//本车有泡沫 GetComponent().TotalFlowChange(EndId, anther.GetComponent().Flow / 2); antherdir2.GetComponent().TotalFlowChange(EndId, anther.GetComponent().Flow / 2); } else {//本身没泡沫啥也不干 } } else {//出的不是泡沫 GetComponent().TotalFlowChange(EndId, anther.GetComponent().Flow / 2); antherdir2.GetComponent().TotalFlowChange(EndId, anther.GetComponent().Flow / 2); } } } else {//另一端没水了也就不用考虑是不是泡沫的问题 //另一端水源没水了但是在出水可能是消耗自己的水 //另一端在连接了水源之后就不再消耗自己的水了,可以看watersource的updata逻辑 Debug.Log(anther + " 水源没有水还在继续出水"); GetComponent().TotalFlowChange(EndId, anther.GetComponent().Flow); } } else if (anther.GetComponent().WaterSourceLine2.Count <= 0) {//另一条没连水源,也就是之前没水源,也就没有在出水 Debug.Log(anther + "没有连接水源还在出水,流量未分配"); // GetComponent().TotalFlowChange(EndId, anther.GetComponent().Flow); } } } else {//消防员、水泡、机器人、雪炮,肯定没有在出水,不处理 //因为上边判断了含有truckbindwater脚本,所以这里不会走 } } } } else {//另一端进水口1被占用 if (anther.GetComponent().WaterSourceLine1[0][0] == StartId) {//占用另一端进水口的是自己 Debug.Log(name + "出水口//已经//占用" + anther.name + "的进水口1"); //target = new KeyValuePair(anther, 1); } else { if (anther.GetComponent().WaterSourceLine2.Count <= 0) { //另一端进水口2没有被占用,连接进水口2 target = new KeyValuePair(anther, 2); WaterHoseEndDo arg = new WaterHoseEndDo { ConnectHose = hose, StartId = gameobjinfo.gameObjID, ConnectInPoint = 2, EndId = EndId, }; MessageDispatcher.SendMessage("StartConnectDone", arg); Debug.Log(name + "出水口占用" + anther.name + "的进水口2"); //连接了一个出水的网络 if (anther.GetComponent()) {//有watersource必为水源车,因为消防设施不能为连接终点 if (GetComponent().HasWaterSelfAndLine) {//自己本身有水 if (anther.GetComponent().HasWaterSelfAndLine == false) { anther.GetComponent().HasWaterSelfAndLine = true; } } if (anther.GetComponent().TotalFlow > 0) {//连接的网络正在出水,修改流量信息 float line1remain = checkWaterRemain(WaterSourceLine1); float line2remain = checkWaterRemain(WaterSourceLine2); //if (!((line1remain > 0 || line1remain == -100) || (line2remain > 0 || line2remain == -100) || // (GetComponent().AllUserWater < GetComponent().TotalWater))) if (!GetComponent().HasWaterSelfAndLine) {//自身没水不修改流量信息 } else { if (anther.GetComponent().WaterSourceLine1.Count > 0) {//另一条进水口有水源,另一端连接的肯定为进水口1 float remain = anther.GetComponent().checkWaterRemain( anther.GetComponent().WaterSourceLine1); if (remain > 0 || remain == -100) {//另一端水源有水 if (gameobjinfo.gameObjID == anther.GetComponent().WaterSourceLine1[0][0]) {//另一端就是自己 } else { GetComponent().TotalFlowChange(EndId, anther.GetComponent().TotalFlow / 2); GameObject antherdir1 = EntitiesManager.Instance.GetEntityByID(anther.GetComponent().WaterSourceLine1[0][0]); antherdir1.GetComponent().TotalFlowChange(EndId, anther.GetComponent().TotalFlow / 2); } } else {//另一端水源没水了但是在出水可能是消耗自己的水 //另一端在连接了水源之后就不再消耗自己的水了,可以看watersource的updata逻辑 GetComponent().TotalFlowChange(EndId, anther.GetComponent().TotalFlow); } } else if (anther.GetComponent().WaterSourceLine1.Count <= 0) {//另一端空着,没连水源 GetComponent().TotalFlowChange(EndId, anther.GetComponent().TotalFlow); } } } } else {//连接的是单一物体或可出水车辆 if (!GetComponent().HasWaterSelfAndLine) {//自身没水不修改流量信息 } else { if (anther.GetComponent()) {//连接的是可出水车辆 if (anther.GetComponent().Flow > 0) {//出水车辆在出水,分流 if (anther.GetComponent().WaterSourceLine1.Count > 0) {//另一条进水口有水源,另一端连接的肯定为进水口2 float remain = anther.GetComponent().checkWaterRemain( anther.GetComponent().WaterSourceLine1); if (remain > 0 || remain == -100) {//另一端水源有水 if (gameobjinfo.gameObjID == anther.GetComponent().WaterSourceLine1[0][0]) {//另一端连接的自己 GameObject antherdir1 = EntitiesManager.Instance.GetEntityByID(anther.GetComponent().WaterSourceLine1[0][0]); if (anther.GetComponentInChildren().particleType == SprayParticleType.Froth) {//出水端出的泡沫 WaterSource waters = GetComponent(); if (waters.foam && (waters.AllUserFoam == -100 || (waters.TotalFoam - waters.AllUserFoam) > 0)) {//本车有泡沫 GetComponent().TotalFlowChange(EndId, anther.GetComponent().Flow / 2); antherdir1.GetComponent().TotalFlowChange(EndId, anther.GetComponent().Flow / 2); } else {//本身没泡沫啥也不干 } } else { GetComponent().TotalFlowChange(EndId, anther.GetComponent().Flow / 2); antherdir1.GetComponent().TotalFlowChange(EndId, anther.GetComponent().Flow / 2); } } } else {//另一端水源没水了但是在出水可能是消耗自己的水 //另一端在连接了水源之后就不再消耗自己的水了,可以看watersource的updata逻辑 GetComponent().TotalFlowChange(EndId, anther.GetComponent().TotalFlow); } } else if (anther.GetComponent().WaterSourceLine1.Count <= 0) {//另一条线没水 Debug.Log(anther + "没有连接水源还在出水,流量未分配"); } } } else {//消防员、水泡、机器人、雪炮,肯定没有在出水,不处理 //这里不会走 } } } } else { if (anther.GetComponent().WaterSourceLine2[0][0] == StartId) { //target = new KeyValuePair(anther, 2); Debug.Log(name + "出水口//已经//占用" + anther.name + "的进水口2"); } else { Debug.Log(anther.name + " 没有更多进水口,检查连接逻辑"); // target = new KeyValuePair(anther, 0); } } } } } else { target = new KeyValuePair(anther, 0); } return target; } #region //void Direction2conncet(GameObject anther, long EndId, long StartId) //{ // if (anther.GetComponent()) // {//另一端为可出水车辆 // if (anther.GetComponent().WaterSourceLine1.Count <= 0) // {//另一端进水口1没有被占用,连接进水口1 // DirectConnectObj2 = new KeyValuePair(anther, 1); // //连接了一个出水的网络 // if (anther.GetComponent()) // {//有watersource必为水源车,因为消防设施不能为连接终点 // if (anther.GetComponent().TotalFlow > 0) // {//连接的网络正在出水,修改流量信息 // if (anther.GetComponent().WaterSourceLine2.Count > 0) // {//另一条进水口有水源,另一端连接的肯定为进水口2 // float remain = anther.GetComponent().checkWaterRemain( // anther.GetComponent().WaterSourceLine2); // if (remain > 0 || remain == -100) // {//另一端水源有水 // GetComponent().TotalFlowChange(EndId, anther.GetComponent().TotalFlow / 2); // GameObject antherdir2 = EntitiesManager.Instance.GetEntityByID(anther.GetComponent().WaterSourceLine2[0][0]); // antherdir2.GetComponent().TotalFlowChange(EndId, anther.GetComponent().TotalFlow / 2); // } // else // {//另一端水源没水了但是在出水可能是消耗自己的水 // //另一端在连接了水源之后就不再消耗自己的水了,可以看watersource的updata逻辑 // GetComponent().TotalFlowChange(EndId, anther.GetComponent().TotalFlow); // } // } // } // } // } // else // {//另一端进水口1被占用 // if (anther.GetComponent().WaterSourceLine1[0][0] == StartId) // {//占用另一端进水口的是自己 // Debug.Log(name + "出水口2占用" + anther.name + "的进水口1"); // } // else // { // if (anther.GetComponent().WaterSourceLine2.Count <= 0) // { // //另一端进水口2没有被占用,连接进水口2 // DirectConnectObj2 = new KeyValuePair(anther, 2); // //连接了一个出水的网络 // if (anther.GetComponent()) // {//有watersource必为水源车,因为消防设施不能为连接终点 // if (anther.GetComponent().TotalFlow > 0) // {//连接的网络正在出水,修改流量信息 // if (anther.GetComponent().WaterSourceLine1.Count > 0) // {//另一条进水口有水源,另一端连接的肯定为进水口1 // float remain = anther.GetComponent().checkWaterRemain( // anther.GetComponent().WaterSourceLine1); // if (remain > 0 || remain == -100) // {//另一端水源有水 // GetComponent().TotalFlowChange(EndId, anther.GetComponent().TotalFlow / 2); // GameObject antherdir1 = EntitiesManager.Instance.GetEntityByID(anther.GetComponent().WaterSourceLine1[0][0]); // antherdir1.GetComponent().TotalFlowChange(EndId, anther.GetComponent().TotalFlow / 2); // } // else // {//另一端水源没水了但是在出水可能是消耗自己的水 // //另一端在连接了水源之后就不再消耗自己的水了,可以看watersource的updata逻辑 // GetComponent().TotalFlowChange(EndId, anther.GetComponent().TotalFlow); // } // } // } // } // } // else // { // if (anther.GetComponent().WaterSourceLine2[0][0] == StartId) // { // Debug.Log(name + "出水口2占用" + anther.name + "的进水口2"); // } // else // Debug.Log(anther.name + " 没有更多进水口,检查连接逻辑"); // } // } // } // } // else // {//另一端为非车辆,则只有一个进水口 // DirectConnectObj2 = new KeyValuePair(anther, 0); // } //} #endregion /// /// 获取车辆可持续出水时间跟剩余水量 /// /// /// public KeyValuePair GetWaterAndTimeRemain(List> waterline1, List> waterline2) { KeyValuePair timewater = new KeyValuePair(); // float allflow = 0f;//整个网络的中出水流量 float remainwater = 0f; List allwatersource = new List(); for (int i = 0; i < waterline1.Count; i++) { for (int j = 0; j < waterline1[i].Count; j++) { if (!allwatersource.Contains(waterline1[i][j])) { allwatersource.Add(waterline1[i][j]); } } } for (int i = 0; i < waterline2.Count; i++) { for (int j = 0; j < waterline2[i].Count; j++) { if (!allwatersource.Contains(waterline2[i][j])) { allwatersource.Add(waterline2[i][j]); } } } if (GetComponent()) { allwatersource.Add(GetComponent().gameObjID); } for (int i = 0; i < allwatersource.Count; i++) { if (EntitiesManager.Instance.GetEntityByID(allwatersource[i])) { WaterSource ws = EntitiesManager.Instance.GetEntityByID(allwatersource[i]).GetComponent(); if (ws.TotalWater != -100) { remainwater += (ws.TotalWater - ws.AllUserWater); //if (ws.GetComponent()) //{ // allflow += ws.GetComponent().Flow; //} } else { remainwater = -100; break; } } } int remaintime = 0; //allflow += Flow; if (remainwater == -100) { remaintime = -100; } else { //if (allflow != 0) // remaintime = Mathf.CeilToInt(remainwater / allflow); WaterSource dirws1; if (WaterSourceLine1.Count > 0) { if (EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[0][0]) && EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[0][0]).GetComponent()) { dirws1 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[0][0]).GetComponent(); } else { dirws1 = null; } } else { dirws1 = null; } WaterSource dirws2; if (WaterSourceLine2.Count > 0) { dirws2 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine2[0][0]).GetComponent(); } else { dirws2 = null; } float dirflow = 0; //注 :一开始dirws1与dirws2不为空但是dirflow仍然为0,出现情况可能为流量还未分配,水源上的TotalFlow仍然为0 if (dirws1 != null) { dirflow += dirws1.TotalFlow; } if (dirws2 != null) dirflow += dirws2.TotalFlow; float realwatersource = 0;//实际分到的水源 if (GetComponent()) {//本身是水源车 if (dirflow <= 0) {//没有连接水源或者连接的水源没有水 if (GetComponent().TotalFlow != 0) { realwatersource =/* (Flow / GetComponent().TotalFlow) **/ remainwater; remaintime = Mathf.CeilToInt(realwatersource / GetComponent().TotalFlow); } else { remaintime = 0; } } else { //连接水源的总水量 float thiscarwater = (GetComponent().TotalWater - GetComponent().AllUserWater); float watersourcewater = remainwater - thiscarwater; //注:本身的水源不参与到供水方的流量比来计算分到的真实水源 realwatersource = (GetComponent().TotalFlow / dirflow) * watersourcewater + thiscarwater; remaintime = Mathf.CeilToInt(realwatersource / GetComponent().TotalFlow); } } else { if (dirflow != 0) { realwatersource = (Flow / dirflow) * remainwater; remaintime = Mathf.CeilToInt(realwatersource / Flow); } else { remaintime = 0; } } } timewater = new KeyValuePair(remaintime, remainwater); return timewater; } void stopspraywaterorform() { Debug.Log(name + "end"); StopSpray(); RemainTime = 0; RemainWater = 0; GetComponent().NowSkill = TruckSkills.待命; Flow = 0; if (TruckSkillPanelController.GetInstance && TruckSkillPanelController.GetInstance.NowBindTruck == GetComponent()) { if (TruckSkillPanelController.GetInstance.SprayWater.GetComponent().isOn) { TruckSkillPanelController.GetInstance.SprayWater.GetComponent().isOn = false; } if (TruckSkillPanelController.GetInstance.SprayFoam.GetComponent().isOn) { TruckSkillPanelController.GetInstance.SprayFoam.GetComponent().isOn = false; } } SpraySyncData spraysync = new SpraySyncData(); spraysync.SendUserID = CurrentUserInfo.mySelf.Id; spraysync.IsOn = false; spraysync.gameObjID = gameobjinfo.gameObjID; NetworkManager.Default.SendAsync("SPRAY_WATER_SYNC", spraysync); } public float CheckFoamRemain() { float remain = 0; if (GetComponent()) { WaterSource ws = GetComponent(); remain = ws.TotalFoam - ws.AllUserFoam; } else { if (WaterSourceLine1.Count > 0) { GameObject wsl1 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine1[0][0]); if (!wsl1.GetComponent()) { remain = -100; } else { WaterSource ws = wsl1.GetComponent(); remain += (ws.TotalFoam - ws.AllUserFoam); } if (WaterSourceLine2.Count > 0) { GameObject wsl2 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine2[0][0]); if (!wsl2.GetComponent()) { remain = -100; } else { WaterSource ws = wsl2.GetComponent(); remain += (ws.TotalFoam - ws.AllUserFoam); } } } else { if (WaterSourceLine2.Count > 0) { GameObject wsl2 = EntitiesManager.Instance.GetEntityByID(WaterSourceLine2[0][0]); if (!wsl2.GetComponent()) { remain = -100; } else { WaterSource ws = wsl2.GetComponent(); remain += (ws.TotalFoam - ws.AllUserFoam); } } } } return remain; } }