using System; using System.Collections; using System.Collections.Generic; using System.Linq; using TMPro; using Unity.Jobs.LowLevel.Unsafe; using UnityEngine; public class Barracks_Buildings : Buildings { [Header("特有内容")] public int Soldiers_Num = 0; public Dictionary AllBattleBlobs = new(); public override void Start() { base.Start(); BattleManager.Instance.onBlobRetire += OnBattleBlobRetired; GameProcedureManager.Instance.OnDay += ComeBack; GameProcedureManager.Instance.OnNight += SendOut; //远程团子 SpecailBuff_Buildings.BuildingTechItem BlobBTI = new SpecailBuff_Buildings.BuildingTechItem( null, () => { if(AllBattleBlobs.Keys.Contains(typeof(BattleBlobArcher)))AllBattleBlobs[typeof(BattleBlobArcher)] += 1; else AllBattleBlobs.Add(typeof(BattleBlobArcher),1); //判定是否黑夜,是的话直接放去战场 if (!GameProcedureManager.Instance.isDay) { BattleManager.Instance.SpawnBattleBlob(typeof(BattleBlobArcher), TuanZiList[TuanZiList.Count - 1]); } }, "光标团子", 0, 0, 1, true,0 ); BlobBTI.SetEndless(); InformationPanel.AddTechItem(BlobBTI); } public override void AddFunctionToTreeController() { Action Action1 = BuildingsActive; TreeControl.Instance.AddEvent("兵营", Action1); Action Action2 = () => AddCeremony("战之初级仪式", 3); TreeControl.Instance.AddEvent("战之初级仪式", Action2); Action Action3 = () => AddCeremony("战之中级仪式", 6); TreeControl.Instance.AddEvent("战之中级仪式", Action3); Action Action4 = () => AddCeremony("战之高级仪式", 9); TreeControl.Instance.AddEvent("战之高级仪式", Action4); } public override void AddResources_Click() { //这里不会有任何反应,天黑的时候所有团子被自动送出,天亮团子自动回来 return; if (TuanZi_Num>0) { //TuanZi_Num --; Soldiers_Num++; foreach (BlobController tuanzi in TuanZiList) { if (tuanzi.gameObject.activeSelf) { tuanzi.BelongingBuilding = this; var battleBlob = BattleManager.Instance.SpawnBattleBlob(tuanzi); break; } } // } //Debug.Log("Click_Tree"); } /// /// 团子在战败后退休成为休闲团子 /// /// 战败的团子 public void OnBattleBlobRetired(BattleBlob battleBlob) { Soldiers_Num --; TuanZi_Num --; if (battleBlob.originalBlob) { battleBlob.originalBlob.gameObject.SetActive(true); battleBlob.originalBlob.BelongingBuilding = null; } AllBattleBlobs[battleBlob.Job]--; TuanZiList.Remove(battleBlob.originalBlob); //TODO: 增加视觉效果 Destroy(battleBlob.gameObject); } /// /// 到夜晚出去作战 /// public void SendOut() { var index = 0; foreach (var currentJobBlob in AllBattleBlobs) { var jobCount = currentJobBlob.Value; var jobType = currentJobBlob.Key; for (int i = 0; i < jobCount; i++) { var battleBlob = BattleManager.Instance.SpawnBattleBlob(jobType, TuanZiList[index]); index++; } } // TuanZiList.ForEach(tuanzi => // { // if (tuanzi.gameObject.activeSelf) // { // // var battleBlob = BattleManager.Instance.SpawnBattleBlob(tuanzi); // } // }); } /// /// 白天在兵营等着 /// public void ComeBack() { FindObjectsByType(FindObjectsInactive.Include, FindObjectsSortMode.InstanceID). ToList(). ForEach( battleBlob => { battleBlob.originalBlob?.gameObject.SetActive(true); //TODO: 增加视觉效果 Destroy(battleBlob.gameObject); }); } }