MayHeCome/Assets/ChengHui/Script/SpecialBuff/SpecailBuff_Buildings.cs
2024-12-18 17:55:34 +08:00

189 lines
6.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using System;
using UnityEngine.UI;
using System.Reflection;
public class SpecailBuff_Buildings : MonoBehaviour
{
public GameObject specialBuffButton_Prefab;
public List<string> buffName_CN = new List<string>();
public List<string> buffName_EN = new List<string>();
public UI_InformationPanel infoPanel;
//已弃用
private GameObject information_Panel;
public Dictionary<string,string> EN_CN = new Dictionary<string, string>();
public Dictionary<string, bool> buff_ifActive = new Dictionary<string, bool>();
public Dictionary<string, int> buff_Level = new Dictionary<string, int>();
// Start is called before the first frame update
public List<BuildingTechItem> buildTechItems = new List<BuildingTechItem>();
[System.Serializable]
public struct Resource
{
public int Wood;
public int Faith;
public int TuanZi;
public Resource(int w, int f, int t)
{
Wood = w;
Faith = f;
TuanZi = t;
}
}
public enum BuffState
{
Close,UpGrade,Open
}
public class BuildingTechItem
{
public BuildingTechItem NextItem;
public Action TechNameEN;
public string TechNameCN;
public int faithCost;
public int woodCost;
public int blobCost;
public bool firstTech;
private bool endless;
public int currentNum;
public BuildingTechItem(BuildingTechItem nextItem, Action techNameEN, string techNameCN, int faithCost, int woodCost, int blobCost,bool firstTech,int currentNum = 0)
{
this.NextItem = nextItem;
this.TechNameEN = techNameEN;
this.TechNameCN = techNameCN;
this.faithCost = faithCost;
this.woodCost = woodCost;
this.blobCost = blobCost;
this.firstTech = firstTech;
this.currentNum = currentNum;
}
//-----------------------------------------------------
//注意如果团子消耗方式与建筑物高度相关请把团子消耗写在Buff里
//-----------------------------------------------------
public void CostResource()
{
Singleton<GameProcedureManager>.Instance.FaithCount -= faithCost;
Singleton<GameProcedureManager>.Instance.WoodCount -= woodCost;
//TODO: 有待维护消耗团子数
//BlobManager.Instance.AvailableBlobs.RemoveRange(0,blobCost);
}
public void SetEndless()
{
endless = true;
}
public void InvokeNextTech(UI_InformationPanel infoPanel,int siblingIndex)
{
if (NextItem != null) infoPanel.AddTechItem(NextItem, siblingIndex);
if (endless)
{
//目前Endless 团子专属
currentNum++;
infoPanel.AddTechItem(this,siblingIndex);
}else if (currentNum>=0)
{
currentNum++;
}
}
}
public BuildingTechItem CreateTechItem(BuildingTechItem nextItem, Action techNameEN, string techNameCN, int faithCost, int woodCost, int blobCost,bool firstTech,int currentNum = -1)
{
BuildingTechItem newItem = new BuildingTechItem(nextItem, techNameEN, techNameCN, faithCost, woodCost, blobCost,firstTech,currentNum);
if (firstTech)
{
//無消耗,则为直接解锁项目,直接解锁
if (faithCost == 0 && woodCost == 0 && blobCost == 0)
{
techNameEN.Invoke();
}
//需要消耗资源解锁则在UI面板中添加【建筑解锁项】
else
{
infoPanel.AddTechItem(newItem);
}
}
return newItem;
}
void Start()
{
for (int i = 0; i < buffName_CN.Count; i++)
{
EN_CN.Add(buffName_EN[i], buffName_CN[i]);
}
AddFunctionToTreeContoller();
}
public virtual void AddFunctionToTreeContoller()
{
}
//1.在UI添加buff按钮2.不需要升级
public void AddBuff_Type_1(string BuffName, bool canBeClosed)
{
if (canBeClosed)
{
buff_ifActive.Add(BuffName, true);
}
GameObject Button = Instantiate(specialBuffButton_Prefab, information_Panel.transform.Find("Panel"));
//设置按钮的脚本内容
Button.GetComponent<SpecialBuff_Button>().InitalSet(this,BuffName,canBeClosed);
//激活buff
Button.GetComponent<SpecialBuff_Button>().SpecialBuffActive();
}
//2.在UI添加按钮需要升级
public void AddBuff_Type_2(string BuffName,bool canBeClosed,int maxLevel,List<Resource> resourceNeeded)
{
if (canBeClosed)
{
buff_ifActive.Add(BuffName, false);//满级以后才会被真正视为激活状态,然后可以被关闭
}
GameObject Button = Instantiate(specialBuffButton_Prefab, information_Panel.transform.Find("Panel"));
//设置按钮的脚本内容
Button.GetComponent<SpecialBuff_Button>().InitalSet(this, BuffName, canBeClosed,maxLevel,resourceNeeded);
//修改按钮文本
Button.GetComponent<SpecialBuff_Button>().SetText();
}
public void Step2_Type_1(string BuffName)//激活Buff
{
Invoke(BuffName, 0);
}
public void Step2_Type_2(string BuffName,int Level)//激活Buff
{
CallMethodByName(BuffName,Level);
}
public void CallMethodByName(string methodName, int Level)
{
// 获取当前实例的Type对象
Type type = this.GetType();
// 获取MethodInfo对象
MethodInfo methodInfo = type.GetMethod(methodName, new Type[] { typeof(int) });
// 检查MethodInfo是否找到
if (methodInfo != null)
{
// 调用方法
methodInfo.Invoke(this, new object[] { Level });
}
else
{
Debug.LogError("Method not found: " + methodName);
}
}
}