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.
300 lines
12 KiB
300 lines
12 KiB
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<TruckSkills> MySkills; |
|
public TruckSkills nowSkill; |
|
public List<TruckSkills> 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<TruckNowSkillSyncData>(); |
|
|
|
if (data.gameObjID == this.gameObjID) |
|
{ |
|
nowSkill = data.NowSkill; |
|
} |
|
} |
|
public void Init() |
|
{ |
|
MySkills = new List<TruckSkills>(); |
|
DisableSkills = new List<TruckSkills>(); |
|
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<TruckMessage> addMyInBattle(List<TruckMessage> list) |
|
{ |
|
if (NowSkill != TruckSkills.待命) |
|
{ |
|
list.Add(this); |
|
} |
|
return list; |
|
} |
|
private List<TruckMessage> addMyWaiting(List<TruckMessage> 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<TruckBindWaterSource>(); |
|
string waterSourceInfo = ""; |
|
//if (truckBindWaterSource.ConnentWaterSource != null && truckBindWaterSource.ConnentWaterSource.GetComponent<TruckMessage>()) |
|
//{ //水源为车 |
|
// GameObject mySource = GetComponent<TruckBindWaterSource>().ConnentWaterSource; |
|
// waterSourceInfo = mySource.GetComponent<TruckMessage>().FullName; |
|
// WaterSource waterSource = mySource.GetComponent<WaterSource>(); |
|
// 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<XFSS>()) |
|
//{ //水源为消火栓 |
|
// waterSourceInfo = truckBindWaterSource.ConnentWaterSource.GetComponent<XFSS>().type.ToString(); |
|
//} |
|
|
|
if (!(truckBindWaterSource.WaterSourceLine1.Count > 0 && truckBindWaterSource.WaterSourceLine2.Count > 0)) |
|
{//该车辆没有供水线路或者只有一条供水线路 |
|
|
|
if (truckBindWaterSource.WaterSourceLine1.Count == 0 && truckBindWaterSource.WaterSourceLine2.Count == 0) |
|
{//没有供水线路,自己为水源车出水的情况 |
|
if (GetComponent<WaterSource>()) |
|
{ |
|
waterSourceInfo += "。没有供水线路,本身为水源车:" + |
|
"剩余水量" + Math.Round(GetComponent<WaterSource>().TotalWater - GetComponent<WaterSource>().AllUserWater, 2) + "L" + |
|
", 预计可用" + |
|
Mathf.RoundToInt((GetComponent<WaterSource>().TotalWater - GetComponent<WaterSource>().AllUserWater) / |
|
GetComponent<WaterSource>().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<WaterSource>()) |
|
{ |
|
waterSourceInfo += "\n" + "本身:" + |
|
"剩余水量" + Math.Round(GetComponent<WaterSource>().TotalWater - GetComponent<WaterSource>().AllUserWater, 2) + "L" + |
|
", 预计可用" + |
|
Mathf.RoundToInt((GetComponent<WaterSource>().TotalWater - GetComponent<WaterSource>().AllUserWater) / |
|
GetComponent<WaterSource>().TotalFlow / 60) + "分钟"; |
|
} |
|
} |
|
} |
|
else |
|
{//该车辆有两条供水线路 |
|
|
|
string str1 = WaterSourceLineInfo(truckBindWaterSource.WaterSourceLine1); |
|
|
|
string str2 = WaterSourceLineInfo(truckBindWaterSource.WaterSourceLine2); |
|
|
|
waterSourceInfo += ":\n"; |
|
|
|
waterSourceInfo += "1干线:" + "直接水源是" + str1 ; |
|
|
|
waterSourceInfo += "\n" + "2干线:" + "直接水源是" + str2; |
|
|
|
if (GetComponent<WaterSource>()) |
|
{ |
|
waterSourceInfo += "\n" + "本身:" + |
|
"剩余水量" + Math.Round(GetComponent<WaterSource>().TotalWater - GetComponent<WaterSource>().AllUserWater, 2) + "L" + |
|
", 预计可用" + |
|
Mathf.RoundToInt((GetComponent<WaterSource>().TotalWater - GetComponent<WaterSource>().AllUserWater) / |
|
GetComponent<WaterSource>().TotalFlow /60) + "分钟"; |
|
} |
|
} |
|
|
|
return waterSourceInfo; |
|
} |
|
|
|
/// <summary> |
|
/// 获取当前供水线路剩余水量,可用时间字符串 |
|
/// </summary> |
|
/// <param name="dirWaterSource"> 当前出水车的供水线路 </param> |
|
/// <returns> 返回拼接字符串 </returns> |
|
private string WaterSourceLineInfo(List<List<long>> dirWaterSource) |
|
{ |
|
GameObject dirConnentWaterSource1 = EntitiesManager.Instance.GetEntityByID(dirWaterSource[0][0]); |
|
string str = ""; |
|
if (!dirConnentWaterSource1.GetComponent<TruckMessage>()) |
|
{//当前线路直接供水方为消火栓 |
|
str = dirConnentWaterSource1.GetComponent<XFSS>().type.ToString(); |
|
} |
|
else |
|
{//当前线路直接供水方为水源车 |
|
str = dirConnentWaterSource1.GetComponent<TruckMessage>().FullName; |
|
float isWaterRemain = GetComponent<TruckBindWaterSource>().checkWaterRemain(dirWaterSource); |
|
if (isWaterRemain > 0 |
|
|| isWaterRemain == -100) |
|
{//当前线路可供水 |
|
if (isWaterRemain != -100) |
|
{//当前线路只存在供水车 |
|
KeyValuePair<int, float> waterAndTimeRemain = dirConnentWaterSource1.GetComponent<TruckBindWaterSource>().GetWaterAndTimeRemain( |
|
dirConnentWaterSource1.GetComponent<TruckBindWaterSource>().WaterSourceLine1, |
|
dirConnentWaterSource1.GetComponent<TruckBindWaterSource>().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<string, List<KeyValuePair<FireCarEngine, int>>> removeMyTeam(Dictionary<string, List<KeyValuePair<FireCarEngine, int>>> allCars) |
|
{ |
|
string myteam = GetObjsOrg(); |
|
//我所在的中队已经到场,从在途力量中删除 |
|
if (allCars.ContainsKey(myteam)) |
|
{ |
|
allCars.Remove(myteam); |
|
} |
|
return allCars; |
|
} |
|
// Update is called once per frame |
|
void Update() |
|
{ |
|
|
|
} |
|
}
|
|
|