using AX.Network.Protocols; using AX.NetworkSystem; using AX.Serialization; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class TruckMessage : CloneGameObjInfo { public FireCarEngine MyCarMessage; public List MySkills; public TruckSkills nowSkill; public List DisableSkills; public bool IsFixedSupport; public TruckSkills NowSkill { set { nowSkill = value; TruckNowSkillSyncData data = new TruckNowSkillSyncData() { gameObjID = this.gameObjID, NowSkill = value, SendUserID = CurrentUserInfo.mySelf.Id, }; //发送同步脚本 NetworkManager.Default.SendAsync("TRUCK_NOWSKILL_SYNC", data); } get { return nowSkill; } } public override void Start() { base.Start(); Init(); InBattleTrucksCount.getInBattleTrucks += addMyInBattle; //计算参战车辆数 WaitingTrucksCount.getWaitingTrucks += addMyWaiting; //计算待命车辆数 GetSprayingCount.getSprayingTrucksCount += addMySpraying; //计算正在喷水车辆数 GetAllWater.getAllWaterAmount += addMyWater; //计算到场水量 GetAllFoam.getAllFoamAmount += addMyFoam; //计算到场泡沫量 ArrivedPowerTotal.getArrivedPower += addMyArrival; //OnwayForceTotal.getOnwayCars += removeMyTeam; //获取在途力量 NetworkMessageDispatcher.AddListener("TRUCK_NOWSKILL_SYNC", NowSkillUpdate); } public void NowSkillUpdate(BinaryMessage message) { var data = message.Body.Deserialize(); if (data.gameObjID == this.gameObjID) { nowSkill = data.NowSkill; } } public void Init() { MySkills = new List(); DisableSkills = new List(); if (TruckSkillPanelController.GetInstance!=null) { MySkills = TruckSkillPanelController.GetInstance.GetTruckSkills((CloneObjType)MyCarMessage.Type); } NowSkill = TruckSkills.待命; /*MySkills[MySkills.Count > 2 ? MySkills.Count - 2 : MySkills.Count - 1];*/ if ((CloneObjType)MyCarMessage.Type == CloneObjType.HighSprayingTruck || (CloneObjType)MyCarMessage.Type == CloneObjType.LadderTruck || (CloneObjType)MyCarMessage.Type == CloneObjType.ForcibleEntryTruck || (CloneObjType)MyCarMessage.Type == CloneObjType.AerialTowerTruck) { DisableSkills.Add(TruckSkills.收回举臂); //DisableSkills.Add(TruckSkills.自动举臂); } if ((CloneObjType)MyCarMessage.Type == CloneObjType.HighSprayingTruck || (CloneObjType)MyCarMessage.Type == CloneObjType.LadderTruck || (CloneObjType)MyCarMessage.Type == CloneObjType.AerialTowerTruck) { DisableSkills.Add(TruckSkills.喷水); //DisableSkills.Add(TruckSkills.喷水); } } public override void OnDestroy() { base.OnDestroy(); InBattleTrucksCount.getInBattleTrucks -= addMyInBattle; WaitingTrucksCount.getWaitingTrucks -= addMyWaiting; GetSprayingCount.getSprayingTrucksCount -= addMySpraying; GetAllWater.getAllWaterAmount -= addMyWater; GetAllFoam.getAllFoamAmount -= addMyFoam; ArrivedPowerTotal.getArrivedPower -= addMyArrival; //OnwayForceTotal.getOnwayCars -= removeMyTeam; NetworkMessageDispatcher.RemoveListener("TRUCK_NOWSKILL_SYNC", NowSkillUpdate); } private List addMyInBattle(List list) { if (NowSkill != TruckSkills.待命) { list.Add(this); } return list; } private List addMyWaiting(List list) { if(NowSkill == TruckSkills.待命) { list.Add(this); } return list; } private IntData addMySpraying(IntData data) { if(NowSkill==TruckSkills.喷水 || NowSkill==TruckSkills.喷泡沫) { data.value += 1; } return data; } private IntData addMyWater(IntData data) { if(MyCarMessage.WaterAmount != 0) { data.value += (int)MyCarMessage.WaterAmount; } return data; } private IntData addMyFoam(IntData data) { if(MyCarMessage.FoamAmount != 0) { data.value += (int)MyCarMessage.FoamAmount; } return data; } public string GetWaterSourceInfo() { TruckBindWaterSource truckBindWaterSource = GetComponent(); string waterSourceInfo = ""; //if (truckBindWaterSource.ConnentWaterSource != null && truckBindWaterSource.ConnentWaterSource.GetComponent()) //{ //水源为车 // GameObject mySource = GetComponent().ConnentWaterSource; // waterSourceInfo = mySource.GetComponent().FullName; // WaterSource waterSource = mySource.GetComponent(); // if (waterSource.water) // { // string remainTime = truckBindWaterSource.Flow > 0 ? Mathf.RoundToInt(truckBindWaterSource.RemainWater / truckBindWaterSource.Flow / 60).ToString() : "0"; // waterSourceInfo += ",水共【" + Math.Round(waterSource.TotalWater, 2) + "】L,每分钟消耗【" + Math.Round(truckBindWaterSource.Flow * 60, 2) + "】L,剩余量【" + Math.Round(truckBindWaterSource.RemainWater, 2) + "】L,预计可用【" + remainTime + "】分钟。"; // } //} //else if (truckBindWaterSource.ConnentWaterSource != null && truckBindWaterSource.ConnentWaterSource.GetComponent()) //{ //水源为消火栓 // waterSourceInfo = truckBindWaterSource.ConnentWaterSource.GetComponent().type.ToString(); //} if (!(truckBindWaterSource.WaterSourceLine1.Count > 0 && truckBindWaterSource.WaterSourceLine2.Count > 0)) {//该车辆没有供水线路或者只有一条供水线路 if (truckBindWaterSource.WaterSourceLine1.Count == 0 && truckBindWaterSource.WaterSourceLine2.Count == 0) {//没有供水线路,自己为水源车出水的情况 if (GetComponent()) { waterSourceInfo += "。没有供水线路,本身为水源车:" + "剩余水量" + Math.Round(GetComponent().TotalWater - GetComponent().AllUserWater, 2) + "L" + ", 预计可用" + Mathf.RoundToInt((GetComponent().TotalWater - GetComponent().AllUserWater) / GetComponent().TotalFlow / 60) + "分钟"; } } else { if (truckBindWaterSource.WaterSourceLine1.Count > 0 && truckBindWaterSource.WaterSourceLine2.Count == 0) { string str1 = WaterSourceLineInfo(truckBindWaterSource.WaterSourceLine1); waterSourceInfo += ":\n"; waterSourceInfo += "1干线:" + "直接水源是" + str1; } if (truckBindWaterSource.WaterSourceLine1.Count == 0 && truckBindWaterSource.WaterSourceLine2.Count > 0) { string str2 = WaterSourceLineInfo(truckBindWaterSource.WaterSourceLine2); waterSourceInfo += ":\n"; waterSourceInfo += "2干线:" + "直接水源是" + str2; } if (GetComponent()) { waterSourceInfo += "\n" + "本身:" + "剩余水量" + Math.Round(GetComponent().TotalWater - GetComponent().AllUserWater, 2) + "L" + ", 预计可用" + Mathf.RoundToInt((GetComponent().TotalWater - GetComponent().AllUserWater) / GetComponent().TotalFlow / 60) + "分钟"; } } } else {//该车辆有两条供水线路 string str1 = WaterSourceLineInfo(truckBindWaterSource.WaterSourceLine1); string str2 = WaterSourceLineInfo(truckBindWaterSource.WaterSourceLine2); waterSourceInfo += ":\n"; waterSourceInfo += "1干线:" + "直接水源是" + str1 ; waterSourceInfo += "\n" + "2干线:" + "直接水源是" + str2; if (GetComponent()) { waterSourceInfo += "\n" + "本身:" + "剩余水量" + Math.Round(GetComponent().TotalWater - GetComponent().AllUserWater, 2) + "L" + ", 预计可用" + Mathf.RoundToInt((GetComponent().TotalWater - GetComponent().AllUserWater) / GetComponent().TotalFlow /60) + "分钟"; } } return waterSourceInfo; } /// /// 获取当前供水线路剩余水量,可用时间字符串 /// /// 当前出水车的供水线路 /// 返回拼接字符串 private string WaterSourceLineInfo(List> dirWaterSource) { GameObject dirConnentWaterSource1 = EntitiesManager.Instance.GetEntityByID(dirWaterSource[0][0]); string str = ""; if (!dirConnentWaterSource1.GetComponent()) {//当前线路直接供水方为消火栓 str = dirConnentWaterSource1.GetComponent().type.ToString(); } else {//当前线路直接供水方为水源车 str = dirConnentWaterSource1.GetComponent().FullName; float isWaterRemain = GetComponent().checkWaterRemain(dirWaterSource); if (isWaterRemain > 0 || isWaterRemain == -100) {//当前线路可供水 if (isWaterRemain != -100) {//当前线路只存在供水车 KeyValuePair waterAndTimeRemain = dirConnentWaterSource1.GetComponent().GetWaterAndTimeRemain( dirConnentWaterSource1.GetComponent().WaterSourceLine1, dirConnentWaterSource1.GetComponent().WaterSourceLine2); str += ", 剩余水量" + Math.Round(waterAndTimeRemain.Value, 2) + "L" + ", 预计可用" + Mathf.RoundToInt(waterAndTimeRemain.Key / 60) + "分钟"; } else {//当前线路最终供水方为消火栓 str += "当前干线供水充足"; } } else {//当前线路不可供水 str += "当前干线没有水"; } } return str; } private PowerPair addMyArrival(PowerPair pair) { pair.trucks += 1; pair.firemen += (int)MyCarMessage.PassengerCapacity; pair.truckMsgs.Add(this); string myteam = GetObjsOrg(); if (myteam != null && !pair.teams.Contains(myteam)) { pair.teams.Add(myteam); } return pair; } private Dictionary>> removeMyTeam(Dictionary>> allCars) { string myteam = GetObjsOrg(); //我所在的中队已经到场,从在途力量中删除 if (allCars.ContainsKey(myteam)) { allCars.Remove(myteam); } return allCars; } // Update is called once per frame void Update() { } }