using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using AX.MessageSystem;
using AX.NetworkSystem;
using System;
public class WaterSourceSyncdata
{
public long SenderId;
public long GameobjId;
public float AllUserWater;
public float TotalFlow;
public float AllUserFoam;
// public bool hasover;
}
public class FlowValueChangeData
{
public GameObject gameobj;
public float flow;
}
//[RequireComponent(typeof(WATER_SOURCE_INFO_SYNC))]
public class WaterSource : MonoBehaviour
{
//绑定在水源上,喷水时判定是否连接了水源
public bool water;//有水
public bool foam;//有泡沫
public float TotalWater;//水总量(单位:升)
public float AllUserWater;//使用总水量(单位:升)
public bool hasover = false;//是否已经没水了
public float TotalFoam;//泡沫总量(单位:升)
public float AllUserFoam;//使用泡沫量
///
/// 总流量
///
public float totalFlow;
public float TotalFlow
{
get
{
return totalFlow;
}
set
{
totalFlow = value;
//分流
fenliu(value);
//修改连接管线的流量是否有水流通过,用以判断管线能否被删除
WaterSourceSyncdata arg = new WaterSourceSyncdata()
{
SenderId = CurrentUserInfo.mySelf.Id,
GameobjId = GetComponent().gameObjID,
AllUserWater = AllUserWater,
TotalFlow = TotalFlow,
AllUserFoam = AllUserFoam,
//hasover = hasover
};
NetworkManager.Default.SendAsync("WATER_SOURCE_INFO_SYNC", arg);
}
}
//该水源出水口直接或间接连接的所有出水物体集合
private List outConnectObjIdList = new List();
public List OutConnectObjIdList
{
get
{
return outConnectObjIdList;
}
set
{
outConnectObjIdList = value;
//if (GetComponent())
//{//水源车
// if (GetComponent().WaterSourceLine1.Count > 0)
// {
// long dir1 = GetComponent().WaterSourceLine1[0][0];
// GameObject dirobj1 = EntitiesManager.Instance.GetEntityByID(dir1);
// dirobj1.GetComponent().OutConnectObjIdList = GetOutSprayId(baseinfo.gameObjID, connectOrDelect);
// }
// if (GetComponent().WaterSourceLine2.Count > 0)
// {
// long dir2 = GetComponent().WaterSourceLine2[0][0];
// GameObject dirobj2 = EntitiesManager.Instance.GetEntityByID(dir2);
// dirobj2.GetComponent().OutConnectObjIdList = GetOutSprayId(baseinfo.gameObjID, connectOrDelect);
// }
//}
}
}
///
/// 自己本身以及连接的水源线上有没有水
///
private bool hasWaterSelfAndLine = true;
public bool HasWaterSelfAndLine
{
get
{
return hasWaterSelfAndLine;
}
set
{
bool prve = hasWaterSelfAndLine;
hasWaterSelfAndLine = value;
if (prve != value)
{
if (prve == true)
{//在出水,之前有水,现在没了,分流
if (GetComponent())
{
if (GetComponent().DirectConnectObj1.Key!=null)
{
if (GetComponent().DirectConnectObj1.Key.GetComponent())
{//出水口1直接连接的是车
TruckBindWaterSource dircon1 = GetComponent().DirectConnectObj1.Key.GetComponent();
waterrunout(dircon1);
}
else
{//直接连接bu为车(消防设施),只有一条管线
}
}
if(GetComponent().DirectConnectObj2.Key!=null)
{
if (GetComponent().DirectConnectObj2.Key.GetComponent())
{//出水口2直接连接的是车
TruckBindWaterSource dircon2 = GetComponent().DirectConnectObj2.Key.GetComponent();
waterrunout(dircon2);
}
else
{//直接连接不是车,只有一条管线,不存在分流
}
}
}
}
else
{//本来没水了,又链接上了水源
if (GetComponent())
{
if (GetComponent().DirectConnectObj1.Key!=null&& GetComponent().DirectConnectObj1.Key.GetComponent())
{
if (GetComponent().DirectConnectObj1.Key.GetComponent())
{//出水口1直接连接的是车
TruckBindWaterSource dircon1 = GetComponent().DirectConnectObj1.Key.GetComponent();
waterConnectWhileNoWater(dircon1);
}
}
if (GetComponent().DirectConnectObj2.Key != null && GetComponent().DirectConnectObj2.Key.GetComponent())
{
if (GetComponent().DirectConnectObj2.Key.GetComponent())
{//出水口2直接连接的是车
TruckBindWaterSource dircon2 = GetComponent().DirectConnectObj2.Key.GetComponent();
waterConnectWhileNoWater(dircon2);
}
}
}
}
}
}
}
public Dictionary OutFlowInfoDic = new Dictionary();
///
/// 预计剩余时间
///
public int Remiantime;
//连接的所有出水的物体
//private List> ConnectSprayKeyValueList = new List>();
private Dictionary ConnectSprayDic = new Dictionary();
//连接的所有出水的物体
// private List ConnectSprayobj = new List();
public GameObject ConnectGameObj;
private BaseGameObjInfo baseinfo;
private bool connectOrDelect;//执行的是连接还是删除操作
private float timer = 1;
private TruckBindWaterSource tbws;
void Start()
{
baseinfo = GetComponent();
if (GetComponent())
{
tbws = GetComponent();
}
//if (GetComponent())
//{
// gameObject.AddComponent();
//}
if (GetComponent())
{
//if(foam)
//{
// TotalWater = 15000;//15000
// TotalFoam = 3000;//3000;
//}
//else
//TotalWater = 12000; //12000;
//水源车(水罐车,泡沫车)暂时用产品定的载水量,泡沫量
//GetComponent().MyCarMessage.WaterAmount = (int)(TotalWater / 1000) ;//转换为吨
//GetComponent().MyCarMessage.FoamAmount = (int)(TotalFoam / 1000);//转换为吨
TotalWater = (float)GetComponent().MyCarMessage.WaterAmount * 1000;
TotalFoam = (float)GetComponent().MyCarMessage.FoamAmount * 1000;
}
else
{
if (foam)
{
TotalFoam = -100;
}
TotalWater = -100;
}
MessageDispatcher.AddListener("WATERCAR_BIND_CURTAINHOSE", ConnectWaterCurtain);
MessageDispatcher.AddListener("WATERCAR_DESTORY_CURTAINHOSE", DelectWaterCurtain);
MessageDispatcher.AddListener("HOSE_CONNECT_OR_DELECT", ConnectOrDelectWaterHose);
// MessageDispatcher.AddListener("FLOW_CHANGE", TotalFlowChange);
//供水关系改为串联,并联等复杂关系后,再在这里统计实时供水总流量不对,转移到各个出水方。
GetRealtimeConsume.getAllRealtimeConsume += addMyRealtimeConsume; //统计实时流量
//GetAllUsed.getAllUsedAmount += addMyUsed;
WaterUsedValue.getAllUsedWater += addMyUsed; //用水量统计
}
void OnDestroy()
{
MessageDispatcher.RemoveListener("WATERCAR_BIND_CURTAINHOSE", ConnectWaterCurtain);
MessageDispatcher.RemoveListener("WATERCAR_DESTORY_CURTAINHOSE", DelectWaterCurtain);
MessageDispatcher.RemoveListener("HOSE_CONNECT_OR_DELECT", ConnectOrDelectWaterHose);
// MessageDispatcher.RemoveListener("FLOW_CHANGE", TotalFlowChange);
GetRealtimeConsume.getAllRealtimeConsume -= addMyRealtimeConsume;
//GetAllUsed.getAllUsedAmount -= addMyUsed;
WaterUsedValue.getAllUsedWater -= addMyUsed;
}
///
/// 删除水幕水带时的处理
///
///
private void DelectWaterCurtain(IMessage obj)
{
if (!GetComponent())
{
WaterCarBindCurtainHose data = (WaterCarBindCurtainHose)obj.Data;
if (GetComponent().gameObjID == data.WaterSourceObjId)
{
//if (data.isConnect)
{
ConnectGameObj = null;
}
}
}
}
///
/// 连接水幕水带时水源上的处理,仅处理消防设施,用以判断是否还能再连接
///
///
private void ConnectWaterCurtain(IMessage obj)
{
if (!GetComponent())
{
WaterCarBindCurtainHose data = (WaterCarBindCurtainHose)obj.Data;
if (GetComponent().gameObjID == data.WaterSourceObjId)
{
// if (data.isConnect)
{
ConnectGameObj = data.WaterCurtainHose;
}
}
}
}
///
/// 连接或删除管线水源上的处理,仅处理消防设施,用以判断是否还能再连接
///
///
private void ConnectOrDelectWaterHose(IMessage obj)
{
if (!GetComponent())
{
HoseConnectOrDelectData data = (HoseConnectOrDelectData)obj.Data;
if (data.StartId == GetComponent().gameObjID)
{//只处理作为起点的
connectOrDelect = data.Isconnect;
GameObject hose = EntitiesManager.Instance.GetEntityByID(data.HoseId);
if (data.Isconnect)
{
ConnectGameObj = hose.GetComponent().GetAnotherGameObj(GetComponent().gameObjID);
if (!GetComponent())
{//自己本身是消防设施(水源车辆在truckbindwatersource里处理过了)
GameObject end= EntitiesManager.Instance.GetEntityByID(data.EndId);
//以下处理连接终端车辆哪个进水口
if (end.GetComponent())
{
TruckBindWaterSource endtbw = end.GetComponent();
int inpoint = 1;
if (endtbw.WaterSourceLine1.Count <= 0)
{
inpoint = 1;
}
else
{
if (endtbw.WaterSourceLine2.Count <= 0)
{
inpoint = 2;
}
else
{
Debug.LogError(end.name+"没有更多进水口");
}
}
WaterHoseEndDo arg = new WaterHoseEndDo
{
ConnectHose = hose,
StartId = baseinfo.gameObjID,
ConnectInPoint = inpoint,
EndId = data.EndId,
};
MessageDispatcher.SendMessage("StartConnectDone", arg);
}
}
}
else
{
ConnectGameObj = null;
}
//修改所有连接的出水物体的集合
//OutConnectObjIdList = GetOutSprayId(data.EndId, data.Isconnect);
}
}
}
//通过出水UI修改出水流量引起总流量变化
private void TotalFlowChange(IMessage obj)
{
var data = (FlowValueChangeData)obj.Data;
if (ConnectSprayDic.ContainsKey(data.gameobj))
{
TotalFlow -= ConnectSprayDic[data.gameobj];
ConnectSprayDic[data.gameobj] = data.flow;
TotalFlow += ConnectSprayDic[data.gameobj];
}
//个客户端水源各自计算自己的消耗
//水源信息同步,当有连接在该水源的物体通过UI改变出水大小时
WaterSourceSyncdata arg = new WaterSourceSyncdata()
{
SenderId = CurrentUserInfo.mySelf.Id,
GameobjId = GetComponent().gameObjID,
AllUserWater = AllUserWater,
TotalFlow = TotalFlow,
AllUserFoam=AllUserFoam
// hasover = hasover
};
NetworkManager.Default.SendAsync("WATER_SOURCE_INFO_SYNC", arg);
}
// Update is called once per frame
void Update()
{
if (TotalFlow > 0)
{
if (tbws != null)
{//如果是水源车
if (tbws.GetComponent().UserID==CurrentUserInfo.mySelf.Id)
{
var connect1 = tbws.WaterSourceLine1;
var connect2 = tbws.WaterSourceLine2;
float remain1 = tbws.checkWaterRemain(connect1);
float remain2 = tbws.checkWaterRemain(connect2);
if ((remain1 > 0 || remain1 == -100) || (remain2 > 0 || remain2 == -100))
{//上级水源有水
}
else
{//上级水源没水消耗自己
if (hasover == false)
{
timer -= Time.deltaTime;
if (timer <= 0)
{
AllUserWater += TotalFlow;
//消耗计算
if (AllUserWater >= TotalWater)
{
AllUserWater = TotalWater;
hasover = true;
HasWaterSelfAndLine = false;
OutFlowInfoDic.Clear();
TotalFlow = 0;
}
WaterSourceSyncdata arg = new WaterSourceSyncdata()
{
SenderId = CurrentUserInfo.mySelf.Id,
GameobjId = GetComponent().gameObjID,
AllUserWater = AllUserWater,
TotalFlow = TotalFlow,
AllUserFoam = AllUserFoam
//hasover = hasover
};
NetworkManager.Default.SendAsync("WATER_SOURCE_INFO_SYNC", arg);
timer = 1;
}
}
}
// Debug.Log("tbws"+timer);
}
}
else
{//本身是消防设施
if (hasover == false)
{
if (ConnectGameObj!=null)
{
if ( ConnectGameObj.GetComponent().UserID == CurrentUserInfo.mySelf.Id)
{
timer -= Time.deltaTime;
if (timer <= 0)
{
AllUserWater += TotalFlow;
timer = 1;
}
WaterSourceSyncdata arg = new WaterSourceSyncdata()
{
SenderId = CurrentUserInfo.mySelf.Id,
GameobjId = GetComponent().gameObjID,
AllUserWater = AllUserWater,
TotalFlow = TotalFlow,
AllUserFoam = AllUserFoam
// hasover = hasover
};
NetworkManager.Default.SendAsync("WATER_SOURCE_INFO_SYNC", arg);
}
//Debug.Log("ws" + timer);
}
}
}
}
}
public void UserFoam(float use)
{
if (TotalFoam == -100)
{
AllUserFoam += use;
TotalFoam = -100;
}
else
{
if (TotalFoam > AllUserFoam)
{
AllUserFoam += use;
}
else
{
AllUserFoam = TotalFoam;
}
}
WaterSourceSyncdata arg = new WaterSourceSyncdata()
{
SenderId = CurrentUserInfo.mySelf.Id,
GameobjId = GetComponent().gameObjID,
AllUserWater = AllUserWater,
TotalFlow = TotalFlow,
AllUserFoam = AllUserFoam
// hasover = hasover
};
NetworkManager.Default.SendAsync("WATER_SOURCE_INFO_SYNC", arg);
}
///
/// 用水消耗
///
/// 每秒消耗量
public void UserWater(float use)
{
if (TotalWater == -100)
{
AllUserWater += use;
TotalWater = -100;
}
else
{
if (hasover == false)
{
if (TotalWater > AllUserWater)
{
//TotalWater -= use;
AllUserWater += use;
}
//水用完了
else
{
AllUserWater = TotalWater;
hasover = true;
MessageDispatcher.SendMessage("RUN_OUR_OF_WATER", GetComponent().gameObjID);
TotalFlow = 0;
WaterSourceSyncdata arg = new WaterSourceSyncdata()
{
SenderId = CurrentUserInfo.mySelf.Id,
GameobjId = GetComponent().gameObjID,
AllUserWater = AllUserWater,
TotalFlow = TotalFlow,
AllUserFoam=AllUserFoam
//hasover = hasover
};
NetworkManager.Default.SendAsync("WATER_SOURCE_INFO_SYNC", arg);
}
}
}
// 水源信息同步
//WaterSourceSyncdata arg = new WaterSourceSyncdata()
//{
// SenderId = CurrentUserInfo.mySelf.Id,
// GameobjId = GetComponent().gameObjID,
// AllUserWater = AllUserWater,
// TotalFlow = TotalFlow,
// hasover = hasover
//};
//NetworkManager.Default.SendAsync("WATER_SOURCE_INFO_SYNC", arg);
}
///
/// 设置当前水源的消耗总流量
///
public void SetTotalFlow(KeyValuePair flowinfo, bool IsAdd)
{
if (!ConnectSprayDic.ContainsKey(flowinfo.Key) && IsAdd)
{
ConnectSprayDic.Add(flowinfo.Key, flowinfo.Value);
// ConnectSprayobj.Add(flowinfo.Key);
}
if (ConnectSprayDic.ContainsKey(flowinfo.Key) && !IsAdd)
{
ConnectSprayDic.Remove(flowinfo.Key);
// ConnectSprayobj.Remove(flowinfo.Key);
}
if (TotalFlow < 0)
{
TotalFlow = 0;
return;
}
else
{
if (IsAdd)
{
TotalFlow += flowinfo.Value;
}
else
{
TotalFlow -= flowinfo.Value;
}
}
//个客户端水源各自计算自己的消耗
//水源信息同步,当有连接在该水源的物体开始/关闭出水导致流量改变
WaterSourceSyncdata arg = new WaterSourceSyncdata()
{
SenderId = CurrentUserInfo.mySelf.Id,
GameobjId = GetComponent().gameObjID,
AllUserWater = AllUserWater,
TotalFlow = TotalFlow,
AllUserFoam=AllUserFoam
// hasover = hasover
};
NetworkManager.Default.SendAsync("WATER_SOURCE_INFO_SYNC", arg);
}
//获取剩余时间及水量
public KeyValuePair GetRemainTimeAndWater()
{
var timewater = new KeyValuePair();
if (TotalWater == -100)
{
timewater = new KeyValuePair(-100, -100);
//time = -1;
}
else
{
float Remainwater = TotalWater - AllUserWater;
int time = Mathf.CeilToInt(Remainwater / TotalFlow);
timewater = new KeyValuePair(time, Remainwater);
}
return timewater;
}
private FloatData addMyRealtimeConsume(FloatData data)
{
if (!GetComponent())
{
data.value -= TotalFlow;
}
return data;
}
private FloatData addMyUsed(FloatData data)
{
if (GetComponent())
{
data.value += AllUserWater;
}
return data;
}
///
/// 获取某条出水口上所有连接的物体
///
///
///
///
public List GetOutSprayId(long endid, bool isconnect)
{
List go = CloneBySerialize.Clone(OutConnectObjIdList);
GameObject end = EntitiesManager.Instance.GetEntityByID(endid);
if (end.GetComponent())
{
if (end.GetComponent())
{
List endlist = CloneBySerialize.Clone(end.GetComponent().OutConnectObjIdList);
if (isconnect)
{
endlist.Add(endid);
for (int i = 0; i < endlist.Count; i++)
{
if (!go.Contains(endlist[i]))
{
go.Add(endlist[i]);
}
}
}
else
{ //删除的时候判断两根线是不是(直接或间接)?连着同一条线上的物体
if (GetComponent().DirectConnectObj1.Key == GetComponent().DirectConnectObj2.Key)
{
}
else
{
for (int i = 0; i < endlist.Count; i++)
{
if (go.Contains(endlist[i]))
{
go.Remove(endlist[i]);
}
}
go.Remove(endid);
}
}
}
}
else
{//非水源
if (isconnect)
{
go.Add(endid);
}
else
{
go.Remove(endid);
}
}
return go;
}
public void TotalFlowChange(long changeid, float flow)
{
if (!OutFlowInfoDic.ContainsKey(changeid))
{
OutFlowInfoDic.Add(changeid, flow);
TotalFlow += flow;
}
else
{
TotalFlow = TotalFlow - OutFlowInfoDic[changeid] + flow;
if (TotalFlow<0)
{
TotalFlow = 0;
}
//TotalFlow += (OutFlowInfoDic[changeid] - flow);
OutFlowInfoDic[changeid] = flow;
}
}
///
/// 修改总流量信息,一次连接一个出水网络
///
/// 直接连接的物体上的出水信息
public void TotalFlowChange(Dictionary connectwaternet)
{
}
//void SetTotalFlowZero()
//{
// for (int i = 0; i ())
{
TruckBindWaterSource tbws = GetComponent();
float remain1 = tbws.checkWaterRemain(tbws.WaterSourceLine1);
float remain2 = tbws.checkWaterRemain(tbws.WaterSourceLine2);
if (tbws.WaterSourceLine1.Count > 0 && tbws.WaterSourceLine2.Count > 0)
{//两条线都连接水源
GameObject dir1 = EntitiesManager.Instance.GetEntityByID(tbws.WaterSourceLine1[0][0]);
GameObject dir2 = EntitiesManager.Instance.GetEntityByID(tbws.WaterSourceLine2[0][0]);
if ((remain1 > 0 || remain1 == -100))
{//线1有水
if (remain2 > 0 || remain2 == -100)
{//线2有水,平分
dir1.GetComponent().TotalFlowChange(baseinfo.gameObjID, value / 2);
dir2.GetComponent().TotalFlowChange(baseinfo.gameObjID, value / 2);
}
else
{//线2没水,全加到线1上
dir1.GetComponent().TotalFlowChange(baseinfo.gameObjID, value);
dir2.GetComponent().TotalFlowChange(baseinfo.gameObjID, 0);
}
}
else
{//线1没水
if (remain2 > 0 || remain2 == -100)
{//线2有水
dir2.GetComponent().TotalFlowChange(baseinfo.gameObjID, value);
dir1.GetComponent().TotalFlowChange(baseinfo.gameObjID, 0);
}
else
{//线2没水
dir2.GetComponent().TotalFlowChange(baseinfo.gameObjID, 0);
dir1.GetComponent().TotalFlowChange(baseinfo.gameObjID, 0);
}
}
}
else if (tbws.WaterSourceLine1.Count > 0 && tbws.WaterSourceLine2.Count <= 0)
{//线1有水源,线2没有
GameObject dir1 = EntitiesManager.Instance.GetEntityByID(tbws.WaterSourceLine1[0][0]);
if (remain1 > 0 || remain1 == -100)
{//线1有水
dir1.GetComponent().TotalFlowChange(baseinfo.gameObjID, value);
}
else
{
dir1.GetComponent().TotalFlowChange(baseinfo.gameObjID, 0);
}
}
else if (tbws.WaterSourceLine1.Count <= 0 && tbws.WaterSourceLine2.Count > 0)
{//线1没水源,线2有
GameObject dir2 = EntitiesManager.Instance.GetEntityByID(tbws.WaterSourceLine2[0][0]);
if (remain2 > 0 || remain2 == -100)
{
dir2.GetComponent().TotalFlowChange(baseinfo.gameObjID, value);
}
else
{
dir2.GetComponent().TotalFlowChange(baseinfo.gameObjID, 0);
}
}
else if (tbws.WaterSourceLine1.Count <= 0 && tbws.WaterSourceLine2.Count <= 0)
{//两条线都没连接水源
}
}
}
void changeHasWaterCross(float value)
{
if (GetComponent())
{
List connectwaterhose = GetComponent().allConnectWaterHose;
int count = 0;
for (int i = 0; i < connectwaterhose.Count; i++)
{
if (connectwaterhose[i].GetComponent().EndHitGameObj == gameObject)
{
count++;
}
}
if (count > 0)
{
for (int i = 0; i < connectwaterhose.Count; i++)
{
if (connectwaterhose[i].GetComponent().EndHitGameObj == gameObject)
{
//if (value > 0)
//{
// connectwaterhose[i].GetComponent().HasWaterCross = true;
//}
//else
//{
// connectwaterhose[i].GetComponent().HasWaterCross = false;
//}
}
}
}
}
}
///
/// 水用完了流量处理
///
///
void waterrunout(TruckBindWaterSource dircon)
{
if (dircon.GetComponent())
{
WaterSource dirws = dircon.GetComponent();
if (dirws.TotalWater<=dirws.AllUserWater)
{
dirws.HasWaterSelfAndLine = false;
}
}
// TruckBindWaterSource dircon1 = GetComponent().DirectConnectObj1.Key.GetComponent();
if (dircon.WaterSourceLine1.Count > 0 && dircon.WaterSourceLine2.Count > 0)
{//两条线都连了水源
if (dircon.WaterSourceLine1[0][0] == baseinfo.gameObjID)
{//自己连接的是线路1
//注:如果线路2连接的也是自己,自己没有水,不会走有水的判断
float line2water = dircon.checkWaterRemain(dircon.WaterSourceLine2);
if (line2water > 0 || line2water == -100)
{//线路2有水
GetComponent().TotalFlowChange(dircon.GetComponent().gameObjID, 0);
//另一条线路上的直接连接水源分流
GameObject dir2 = EntitiesManager.Instance.GetEntityByID(dircon.WaterSourceLine2[0][0]);
if (dircon.GetComponent())
{//直接连接为水源车
dir2.GetComponent().TotalFlowChange(dircon.GetComponent().gameObjID, dircon.GetComponent().TotalFlow);
}
else
{//非水源车
dir2.GetComponent().TotalFlowChange(dircon.GetComponent().gameObjID, dircon.GetComponent().Flow);
}
}
else
{//线路2没水
}
}
else
{//自己连的线路2
float line1water = dircon.checkWaterRemain(dircon.WaterSourceLine1);
if (line1water > 0 || line1water == -100)
{//线路1有水
GetComponent().TotalFlowChange(dircon.GetComponent().gameObjID, 0);
//另一条线路上的直接连接水源分流
GameObject dir1 = EntitiesManager.Instance.GetEntityByID(dircon.WaterSourceLine1[0][0]);
if (dircon.GetComponent())
{//水源车
dir1.GetComponent().TotalFlowChange(dircon.GetComponent().gameObjID, dircon.GetComponent().TotalFlow);
}
else
{//非水源车
dir1.GetComponent().TotalFlowChange(dircon.GetComponent().gameObjID, dircon.GetComponent().Flow);
}
}
else
{//线路1没水
}
}
}
else
{//只练了一条线路
}
}
///
/// 车辆没水时连接水源,连接时分流处理
///
///
void waterConnectWhileNoWater(TruckBindWaterSource dircon)
{
if (dircon.GetComponent()&&dircon.GetComponent().HasWaterSelfAndLine==false)
{
dircon.GetComponent().HasWaterSelfAndLine = true;
}
if (dircon.WaterSourceLine1.Count > 0 && dircon.WaterSourceLine2.Count > 0)
{ //连接的车的两条进水口都连接了
if (baseinfo.gameObjID == dircon.WaterSourceLine1[0][0] && baseinfo.gameObjID != dircon.WaterSourceLine2[0][0])
{//自己连在1上
GameObject Direline2 = EntitiesManager.Instance.GetEntityByID(dircon.WaterSourceLine2[0][0]);
float antherline = dircon.checkWaterRemain(dircon.WaterSourceLine2);
if (antherline > 0 || antherline == -100)
{//另一条有水
if (dircon.GetComponent())
{
TotalFlowChange(dircon.GetComponent().gameObjID, dircon.GetComponent().TotalFlow / 2);
Direline2.GetComponent().TotalFlowChange(dircon.GetComponent().gameObjID, dircon.GetComponent().TotalFlow / 2);
}
else
{
TotalFlowChange(dircon.GetComponent().gameObjID, dircon.GetComponent().Flow / 2);
Direline2.GetComponent().TotalFlowChange(dircon.GetComponent().gameObjID, dircon.GetComponent().Flow / 2);
}
}
else
{//另一条没水
if (dircon.GetComponent())
{
TotalFlowChange(dircon.GetComponent().gameObjID, dircon.GetComponent().TotalFlow);
}
else
{
TotalFlowChange(dircon.GetComponent().gameObjID, dircon.GetComponent().Flow);
}
}
}
else if (baseinfo.gameObjID == dircon.WaterSourceLine2[0][0] && baseinfo.gameObjID != dircon.WaterSourceLine1[0][0])
{//自己连在2上
GameObject Direline1 = EntitiesManager.Instance.GetEntityByID(dircon.WaterSourceLine1[0][0]);
float antherline = dircon.checkWaterRemain(dircon.WaterSourceLine1);
if (antherline > 0 || antherline == -100)
{//另一条有水
if (dircon.GetComponent())
{//连接的是水源车
TotalFlowChange(dircon.GetComponent().gameObjID, dircon.GetComponent().TotalFlow / 2);
Direline1.GetComponent().TotalFlowChange(dircon.GetComponent().gameObjID, dircon.GetComponent().TotalFlow / 2);
}
else
{//连接的是非水源车
TotalFlowChange(dircon.GetComponent().gameObjID, dircon.GetComponent().Flow / 2);
Direline1.GetComponent().TotalFlowChange(dircon.GetComponent().gameObjID, dircon.GetComponent().Flow / 2);
}
}
else
{//另一条没水
if (dircon.GetComponent())
{
TotalFlowChange(dircon.GetComponent().gameObjID, dircon.GetComponent().TotalWater);
}
else
{
TotalFlowChange(dircon.GetComponent().gameObjID, dircon.GetComponent().Flow);
}
}
}
else if (baseinfo.gameObjID == dircon.WaterSourceLine2[0][0] && baseinfo.gameObjID == dircon.WaterSourceLine1[0][0])
{//两根都连接的本车辆
if (dircon.GetComponent())
{
TotalFlowChange(dircon.GetComponent().gameObjID, dircon.GetComponent().TotalWater);
}
else
{
TotalFlowChange(dircon.GetComponent().gameObjID, dircon.GetComponent().Flow);
}
}
}
else if (dircon.WaterSourceLine1.Count > 0 && dircon.WaterSourceLine2.Count <= 0||
dircon.WaterSourceLine1.Count <= 0 && dircon.WaterSourceLine2.Count > 0)
{//只连接了一进水口,
if (dircon.GetComponent())
{
TotalFlowChange(dircon.GetComponent().gameObjID, dircon.GetComponent().TotalFlow);
}
else
{
TotalFlowChange(dircon.GetComponent().gameObjID, dircon.GetComponent().Flow);
}
}
}
}