using AX.NetworkSystem; using System.Collections; using System.Collections.Generic; using UnityEngine; using AX.MessageSystem; using System; using UnityEngine.UI; using AX.InputSystem; /// /// 出水物体流量改变同步信息 /// public class FlowChangeData { public long SenderId; public long GameObjId; public float Flow; } public class FireManControl : MonoBehaviour { /// /// 当前使用的技能 /// public FireManSkills WorkType; public bool IsSprayWater; private Animator anim; private float Speed; private Transform shuiqiang; /// /// 消防员水枪 /// private Transform FiremanHose; //public GameObject FrothPrefabs; //public GameObject WaterFlowerPrefabs; //public GameObject WaterFogPrefabs; //public GameObject WaterStraightPrefabs; public SprayParticleType SelectParticleType; //粒子大小 public float ParticleSize = 0.2f; public float MaxSize = 0.4f; public float MinSize = 0.0f; public GameObject CurrentParticle; /// /// 水流量,如果设为私有的,同步只能改属性,然后属性改变又会同步,同步过来改这个值 /// public float flow; /// /// 剩余时间 /// public int RemainTime; /// /// 剩余水量 /// public float RemainWater; /// /// 出水纵向旋转 /// private float MinVrotate = -75; private float MaxVrotate = 15; private float NowVrotate = -20f; /// /// 出水横向旋转 /// // private float MinHrotate = -180; // private float MaxHrotate = 180; private float NowHrotate; private float timer = 1f; public SprayMode spraymode = SprayMode.WaterGun19; /// /// 水量用完 /// public bool waterrunoutof = false; private BaseGameObjInfo basegameinfo; private FireManWaterHoseManager waterhosemanage; private bool isFirstAirOrMoving = false; public Vector3 tagSearcehRoomStartPoint = Vector3.zero;//侦察消防员的起始点 /// /// 是否在移动或者急救伤员 /// public bool IsFirstAirOrMoving { get { return isFirstAirOrMoving; } set { isFirstAirOrMoving = value; if (value == true) { GetComponent().pathFindEnable = false; if (FireManSkillPanelController.Instance) { FireManSkillPanelController.Instance.SetSkillDisable(); } } else { GetComponent().pathFindEnable = true; if (FireManSkillPanelController.Instance) { FireManSkillPanelController.Instance.SetSkillEnable(); } } } } public FireManSkills workType { get { return WorkType; } set { WorkType = value; FiremanWorktypeChangeSyncData worksync = new FiremanWorktypeChangeSyncData(); worksync.SendUserID = CurrentUserInfo.mySelf.Id; worksync.worktype = value; worksync.gameObjID = GetComponent().gameObjID; worksync.UserID = GetComponent().UserID; NetworkManager.Default.SendAsync(/*CurrentUserInfo.mySelf.Id,*/ "FIREMAN_WORKTYPECHANGE_SYNC", worksync); } } public float Flow { get { return flow; } set { flow = value; //if (GetComponent().WaterLineConnent) //{ // GetComponent().WaterLineConnent.GetComponent().HasWaterCross = value > 0 ? true : false; //} //流量修改时重新分流 if (GetComponent()) { if (GetComponent().ConnentSource) { if (GetComponent().ConnentSource.GetComponent()) {//直接水源是车辆 float remain = CheckWaterRemain(GetComponent().WaterSourceLine); if (remain > 0 || remain == -100) {//水源有水 if (GetComponent().ConnentSource.GetComponent()) {//直接水源为水源车辆 // GetComponent().ConnentSource.GetComponent().Flow += ; GetComponent().ConnentSource.GetComponent().TotalFlowChange(basegameinfo.gameObjID, flow); } } else { Debug.Log("水源没水了"); } } else {//直接连接的消防设施 // GetComponent().ConnentSource.GetComponent().TotalFlow += (value - prveflow); GetComponent().ConnentSource.GetComponent().TotalFlowChange(basegameinfo.gameObjID, flow); } } } //流量同步 FlowChangeData arg = new FlowChangeData { SenderId = CurrentUserInfo.mySelf.Id, GameObjId = GetComponent().gameObjID, Flow = value, }; NetworkManager.Default.SendAsync("FLOW_CHANGE_SYNC", arg); } } void Start() { basegameinfo = GetComponent(); waterhosemanage = GetComponent(); anim = GetComponent(); shuiqiang = TransformHelper.FindChild(transform, "shuiqiang"); //shuiqiang.gameObject.SetActive(true); //GetComponent().SetBool("isInSitu", true); // NowVrotate = shuiqiang.transform.localRotation.eulerAngles.y; // NowVrotate = -20f; //NowHrotate = transform.eulerAngles.x; //NowHrotate = transform.localRotation.eulerAngles.y; FiremanHose = shuiqiang.Find("Hose"); //if (FrothPrefabs == null) //{ // FrothPrefabs = Resources.Load("Particle/Froth"); //} //if (WaterFlowerPrefabs == null) // WaterFlowerPrefabs = Resources.Load("Particle/WaterFlower"); //if (WaterFogPrefabs == null) // WaterFogPrefabs = Resources.Load("Particle/WaterFog"); //if (WaterStraightPrefabs == null) // WaterStraightPrefabs = Resources.Load("Particle/WaterStraight"); //MessageDispatcher.AddListener("SPRAY_WATER", Changeflow); //MessageDispatcher.AddListener("RUN_OUR_OF_WATER", CloseSpray); GetRealtimeConsume.getAllRealtimeConsume += addMyRealtimeConsume; //统计实时流量 MessageDispatcher.AddListener("ArrivedDestination", ArrivedDestination); } /// /// 消防员到达目的地 /// /// private void ArrivedDestination(IMessage obj) { var data = (long)obj.Data; if (data == GetComponent().gameObjID) { if (workType == FireManSkills.TagSearchRoom) {//这里会进两次:到达侦察点进入一次;回到侦察起始点一次 //回到侦察起始点后。注意:不能与下面的if块调换位置 if (tagSearcehRoomStartPoint == Vector3.zero) { //侦察技能状态结束 workType = FireManSkills.None; ChangeUINameCmdArgs arg = new ChangeUINameCmdArgs(); arg.gameObjID = GetComponent().gameObjID; arg.Value = GetComponent().FullName; MessageDispatcher.SendMessage("CHANGE_HEAD_NAME", arg); //提示侦察信息 string tagSearchRoomInfo = GetTagSearchRoomInfo(); LoadPromptWin.Instance.LoadFailTextPromptWindow(tagSearchRoomInfo, 6f); } //到达侦察点后,触发回到侦察起始点的寻路 if (tagSearcehRoomStartPoint != Vector3.zero) { GetComponent().AutoPathFinding(tagSearcehRoomStartPoint); tagSearcehRoomStartPoint = Vector3.zero; } } } } /// /// 获取侦察信息 /// /// private string GetTagSearchRoomInfo() { string result = ""; Transform Pdister = GameObject.Find("P_AllParent").transform.Find("P_Disasters"); string comburent = ""; string position = ""; FireSpreadCtrl[] fireNormal = Pdister.Find("P_FireNormal").GetComponentsInChildren(); for (int i = 0; i < fireNormal.Length; i++) { string thisfirecomburent = fireNormal[i].fireAttribute.comburent; string thisfireposition = fireNormal[i].fireAttribute.position; if (!comburent.Contains(thisfirecomburent)) { comburent += thisfirecomburent; comburent += " "; } if (!position.Contains(thisfireposition)) { position += thisfireposition; position += " "; } } if (position.Trim().Length > 0) { result += "* 火灾位置为:" + position + "\n"; } else { result += "* 火灾位置为:" + "不详" + "\n"; } if (comburent.Trim().Length > 0) { result += "* 燃烧物为:" + comburent + "\n"; } else { result += "* 燃烧物为:" + "不详" + "\n"; } int wonder = Pdister.transform.Find("P_Wounded").childCount; int Trapped = Pdister.transform.Find("P_TrappedPerson").childCount; string trap = wonder + Trapped > 0 ? "* 有被困人员" : "* 没有被困人员"; result += trap + "\n"; int dangerous = Pdister.transform.Find("P_DangerousCargo").childCount; result += dangerous > 0 ? "* 有危险品" : "* 没有危险品"; return result; } void Update() { if (workType == FireManSkills.SprayWater) { timer -= Time.deltaTime; if (timer <= 0) { KeyValuePair remain = GetWaterAndTimeRemain(waterhosemanage.WaterSourceLine); RemainTime = remain.Key; RemainWater = remain.Value; if (remain.Key != -100) { if (remain.Key <= 0 || remain.Value <= 0) {//没水了 stopSpray(); } } if (GetComponentInChildren() && GetComponentInChildren().particleType == SprayParticleType.Froth) {//出的是泡沫,直接水源的泡沫 float remainfoam = CheckFoamRemain(); if (remainfoam == -100 || remainfoam > 0) {//直接水源有泡沫 GetComponent().ConnentSource.GetComponent().UserFoam((Flow / 0.97f) * 0.03f); } else { stopSpray(); //LoadPromptWin.Instance.LoadTextPromptWindow("泡沫量不足", 1f); } } timer = 1; } } //if (workType == FireManSkills.SprayWater) //{ // if(waterrunoutof==false) // { // timer -= Time.deltaTime; // if (timer <= 0) // { // GameObject watersource = GetComponent().ConnentSource; // if (watersource!=null) // { // watersource.GetComponent().UserWater(Flow); // var watertimepair = watersource.GetComponent().GetRemainTimeAndWater(); // RemainTime = watertimepair.Key; // RemainWater = watertimepair.Value; // } // timer = 1f; // } // } //} //if (gameObject==FireManSkillPanelController.Instance.SelectFireMan) //{ // if (GetComponentInChildren()) // { // ParticleSize = GetComponentInChildren().GetScaleValue(); // } //} } /// /// 出水动画 /// /// public void SetLay(bool islay) { shuiqiang.gameObject.SetActive(islay); anim.SetBool("isInSitu", islay); } public void SetParticleType(SprayParticleType type) { switch (type) { case SprayParticleType.Froth: setShowParticle(type); SelectParticleType = SprayParticleType.Froth; CurrentParticle.GetComponentInChildren(true).SetScaleValue(0.95f); ParticleSize = 0.95f; break; case SprayParticleType.WaterFlower: setShowParticle(type); SelectParticleType = SprayParticleType.WaterFlower; CurrentParticle.GetComponentInChildren(true).SetScaleValue(2f); ParticleSize = 2f; break; case SprayParticleType.WaterFog: setShowParticle(type); SelectParticleType = SprayParticleType.WaterFog; CurrentParticle.GetComponentInChildren(true).SetScaleValue(1.7f); ParticleSize = 1.7f; break; case SprayParticleType.WaterStraight: setShowParticle(type); SelectParticleType = SprayParticleType.WaterStraight; CurrentParticle.GetComponentInChildren(true).SetScaleValue(0.2f); ParticleSize = 0.2f; break; } } private void setShowParticle(SprayParticleType type) { for (int i = 0; i < FiremanHose.childCount; i++) { if (type.ToString() == FiremanHose.GetChild(i).name) { FiremanHose.GetChild(i).gameObject.SetActive(true); CurrentParticle = FiremanHose.GetChild(i).gameObject; } else { FiremanHose.GetChild(i).gameObject.SetActive(false); } } } void OnEnable() { GetUsers.PicTransferableCheck += checkPicTrans; RescueTeamManager.getAllRescueTeams += addMyRescue; } void OnDisable() { GetUsers.PicTransferableCheck -= checkPicTrans; RescueTeamManager.getAllRescueTeams -= addMyRescue; //MessageDispatcher.RemoveListener("SPRAY_WATER", Changeflow); //MessageDispatcher.RemoveListener("RUN_OUR_OF_WATER", CloseSpray); } void OnDestroy() { GetUsers.PicTransferableCheck -= checkPicTrans; RescueTeamManager.getAllRescueTeams -= addMyRescue; // MessageDispatcher.RemoveListener("SPRAY_WATER", Changeflow); //MessageDispatcher.RemoveListener("RUN_OUR_OF_WATER", CloseSpray); GetRealtimeConsume.getAllRealtimeConsume -= addMyRealtimeConsume; MessageDispatcher.RemoveListener("ArrivedDestination", ArrivedDestination); } private FloatData addMyRealtimeConsume(FloatData data) { data.value += Flow; return data; } /// /// 连接的水源没有水了 /// /// private void CloseSpray(IMessage obj) { // Debug.Log("over22"); if (workType == FireManSkills.SprayWater) { long watersourceId = (long)obj.Data; long thiswaterid = -1; if (GetComponent().ConnentSource != null) { thiswaterid = GetComponent().ConnentSource.GetComponent().gameObjID; } // Debug.Log(thiswaterid); if (watersourceId == thiswaterid) { waterrunoutof = true; Flow = 0; workType = FireManSkills.None; if (FireManSkillPanelController.Instance) { if (FireManSkillPanelController.Instance.SelectFireMan == gameObject) { FireManSkillPanelController.Instance.SprayWater.GetComponent().isOn = false; } } for (int i = 0; i < FiremanHose.childCount; i++) { // Destroy(FiremanHose.GetChild(i).gameObject); if (FiremanHose.GetChild(i).gameObject.activeInHierarchy) { FiremanHose.GetChild(i).gameObject.SetActive(false); } } SpraySyncData spraysync = new SpraySyncData(); spraysync.SendUserID = CurrentUserInfo.mySelf.Id; spraysync.IsOn = false; // spraysync.spraytype = SprayParticleType.WaterStraight; spraysync.gameObjID = basegameinfo.gameObjID; //spraysync.UserID = GetComponent().UserID; //spraysync.gameObjType = .GetComponent().gameObjType; NetworkManager.Default.SendAsync(/*CurrentUserInfo.mySelf.Id,*/ "SPRAY_WATER_SYNC", spraysync); } } } public void DestoryPartical() { for (int i = 0; i < FiremanHose.childCount; i++) { //Destroy(FiremanHose.GetChild(i).gameObject); FiremanHose.GetChild(i).gameObject.SetActive(false); } } /// /// 连接的水源流量计算 /// /// private void Changeflow(IMessage obj) { var info = (flowchangeinfo)obj.Data; if (info.ChangObjId == basegameinfo.gameObjID) { GameObject watersource = GetComponent().ConnentSource; if (watersource != null) { watersource.GetComponent().SetTotalFlow(new KeyValuePair(gameObject, Flow), info.IsAdd); } } } List checkPicTrans(List list, bool checkLevel) { if (checkLevel) //需检查此消防员是否是自己下级 { long userID = GetComponent().UserID; UserData data = CurrentUserInfo.room.FindUserById(userID); if (checkIsMine(data) && workType == FireManSkills.PictureTransmission) //是自己的下级,并且开启了4G图传技能 { list.Add(GetComponent()); GetComponent().updateMap = true; return list; } else { GetComponent().updateMap = false; return list; } } else //不用检查是否为自己下属 { if (workType == FireManSkills.PictureTransmission) { list.Add(GetComponent()); GetComponent().updateMap = true; return list; } else { GetComponent().updateMap = false; return list; } } } bool checkIsMine(UserData userData) { long id = userData.Org.ParentId; int lv = userData.Org.Level; /* //演习模式下 if (GameSettings.othersSettings.mode == Mode.manoeuvre && id == CurrentUserInfo.mySelf.) { return true; } //练习模式下 else if (GameSettings.othersSettings.mode == Mode.Practice && id == CurrentUserInfo.organization.Id) { return true; } else if (id == 0) { return false; } else { UserData parentData = CurrentUserInfo.room.FindUserById(id); if (parentData != null) { return checkIsMine(parentData); } else { return false; } } */ if (lv > CurrentUserInfo.organization.Level) { return true; } else { return false; } } public void Up() { // NowVrotate = shuiqiang.transform.localRotation.eulerAngles.y; NowHrotate = transform.localRotation.eulerAngles.y; //NowVrotate = Mathf.Clamp((NowVrotate + 5), MinVrotate, MaxVrotate); if (NowVrotate < MaxVrotate) { NowVrotate += 5; } else { NowVrotate = MaxVrotate; } shuiqiang.transform.localRotation = Quaternion.Euler(18.4f, NowVrotate, 0); SprayRotateSyncData arg = new SprayRotateSyncData(); arg.SendUserID = CurrentUserInfo.mySelf.Id; arg.gameObjID = basegameinfo.gameObjID; arg.Vroatet = NowVrotate; arg.Hrotate = NowHrotate; NetworkManager.Default.SendAsync("FIREMAN_SPRAY_ROTATE_SYNC", arg); } public void Down() { //NowVrotate = shuiqiang.transform.localRotation.eulerAngles.y; NowHrotate = transform.localRotation.eulerAngles.y; if (NowVrotate > MinVrotate) { NowVrotate -= 5; } else { NowVrotate = MinVrotate; } shuiqiang.transform.localRotation = Quaternion.Euler(18.4f, NowVrotate, 0); SprayRotateSyncData arg = new SprayRotateSyncData(); arg.SendUserID = CurrentUserInfo.mySelf.Id; arg.gameObjID = basegameinfo.gameObjID; arg.Vroatet = NowVrotate; arg.Hrotate = NowHrotate; NetworkManager.Default.SendAsync("FIREMAN_SPRAY_ROTATE_SYNC", arg); } public void Left() { // NowVrotate = shuiqiang.transform.localRotation.eulerAngles.y; NowHrotate = transform.localRotation.eulerAngles.y - 5; //NowHrotate = Mathf.Clamp((NowHrotate - 5), MinHrotate, MaxHrotate); transform.localRotation = Quaternion.Euler(transform.localRotation.eulerAngles.x, NowHrotate, transform.localRotation.eulerAngles.z); SprayRotateSyncData arg = new SprayRotateSyncData(); arg.SendUserID = CurrentUserInfo.mySelf.Id; arg.gameObjID = basegameinfo.gameObjID; arg.Vroatet = NowVrotate; arg.Hrotate = NowHrotate; NetworkManager.Default.SendAsync("FIREMAN_SPRAY_ROTATE_SYNC", arg); } public void Right() { //NowVrotate = shuiqiang.transform.localRotation.eulerAngles.y; NowHrotate = transform.localRotation.eulerAngles.y + 5; //NowHrotate = Mathf.Clamp((NowHrotate + 5), MinHrotate, MaxHrotate); transform.localRotation = Quaternion.Euler(transform.localRotation.eulerAngles.x, NowHrotate, transform.localRotation.eulerAngles.z); SprayRotateSyncData arg = new SprayRotateSyncData(); arg.SendUserID = CurrentUserInfo.mySelf.Id; arg.gameObjID = basegameinfo.gameObjID; arg.Vroatet = NowVrotate; arg.Hrotate = NowHrotate; NetworkManager.Default.SendAsync("FIREMAN_SPRAY_ROTATE_SYNC", arg); } /// /// 添加正在执行营救的人员中队名称 /// /// /// private List addMyRescue(List data) { if (workType == FireManSkills.FristAid || workType == FireManSkills.Guidance || workType == FireManSkills.Move || workType == FireManSkills.Pacify || workType == FireManSkills.Save) { long userid = GetComponent().UserID; string teamName = CurrentUserInfo.room.FindUserById(userid).Org.DisplayName; if (!data.Contains(teamName)) { data.Add(teamName); } } return data; } /// /// 连接水源时造成的水源信息修改 /// /// 直接水源上的两条线路信息总和 /// 直接水源id /// 连接的哪条线路 public void ChangeWaterSourceLineInfo(long directionId, int linenum) { List> go = CloneBySerialize.Clone(GetDirectWaterSourceInfo(directionId)); go.Insert(0, new List { directionId }); if (linenum == 0) { GetComponent().WaterSourceLine = go; Debug.Log(name + "水源信息更改"); } } /// /// 获取直接水源上的所有水源信息 /// /// 直接水源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 {//消防设施没有进水口 } 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++) { WaterSource ws = EntitiesManager.Instance.GetEntityByID(watersouce[i][j]).GetComponent(); if (ws.TotalWater != -100) { allremain += (ws.TotalWater - ws.AllUserWater); } else { allremain = -100; break; } } } return allremain; } public KeyValuePair GetWaterAndTimeRemain(List> waterline) { KeyValuePair remain = new KeyValuePair(); // float allflow = 0; float remainwater = 0; List allwatersource = new List(); for (int i = 0; i < waterline.Count; i++) { for (int j = 0; j < waterline[i].Count; j++) { if (!allwatersource.Contains(waterline[i][j])) { allwatersource.Add(waterline[i][j]); } } } for (int i = 0; i < allwatersource.Count; 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 (waterhosemanage.ConnentSource) { float realewater = 0;//实际分到的水量=自己的流量/直接水源的总流量*直接水源总水量 float dirTotalFlow = waterhosemanage.ConnentSource.GetComponent().TotalFlow; realewater = (Flow / dirTotalFlow) * remainwater; if (Flow != 0) remaintime = Mathf.CeilToInt(realewater / Flow); else remaintime = 0; } } remain = new KeyValuePair(remaintime, remainwater); return remain; } void stopSpray() { Flow = 0; RemainTime = 0; RemainWater = 0; SetLay(false); DestoryPartical(); GetComponent().EndLay(); workType = FireManSkills.None; if (FireManSkillPanelController.Instance && FireManSkillPanelController.Instance.SelectFireMan == gameObject) { FireManSkillPanelController.Instance.SprayWater.GetComponent().isOn = false; } SpraySyncData spraysync = new SpraySyncData(); spraysync.SendUserID = CurrentUserInfo.mySelf.Id; spraysync.IsOn = false; spraysync.gameObjID = basegameinfo.gameObjID; NetworkManager.Default.SendAsync(/*CurrentUserInfo.mySelf.Id,*/ "SPRAY_WATER_SYNC", spraysync); } public float CheckFoamRemain() { float remain = 0; WaterSource ws = GetComponent().ConnentSource.GetComponent(); if (ws.foam) { if (ws.TotalFoam != -100) { remain = ws.TotalFoam - ws.AllUserFoam; } else { remain = -100; } } return remain; } }