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

271 lines
8.5 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class WoodSculpture_Buildings : Buildings
{
[Header("特有内容")]
public int Craftsman_Num;
//public List<Transform> TuanZi_Craftsman_Point = new List<Transform>();
public Transform AppearPoint;
public int Current_WoodSculpture;
public int Max_WoodSculpture;
public int CurrentSculptureValue = 100;
public int CurrentSculptureCost
{
get
{
return currentScCost;
}
set
{
currentScCost = value;
Max_Progress = currentScCost / 10;
}
}
private int currentScCost = 100;
public int Max_Progress = 100;
public List<GameObject> WoodSculpture_List = new List<GameObject>();
public int progress;
public bool isProducing = true;
[Header("木像及其摆放位置")]
public GameObject WoodSculpture_Prefab_Simple;
public GameObject WoodSculpture_Prefab_Super;
public GameObject WoodSculpture_Prefab_Special;
public List<Transform> WoodSculpture_Point;
public List<bool> AvailableScuplturePoints = new List<bool>();
public Transform Special_WoodSculpture_Point;
public WoodElasticHit weh;
public GameObject wehObject;
[Header("Buff专用")]
public bool is_Buff3_Active = false;
public int WoodSculpture_to_FaithBuff = 1;
//public GameObject WoodSculpture_Forever;
public override void AddFunctionToTreeController()
{
Action Action1 = BuildingsActive;
TreeControl.Instance.AddEvent("木像台", Action1);
Action Action2 = () => {
AddCeremony("春之初级仪式", 2);
BuildingUpgrade();
};
TreeControl.Instance.AddEvent("春之初级仪式", Action2);
Action Action3 = () => {
AddCeremony("春之中级仪式", 5);
//BuildingUpgrade();
};
TreeControl.Instance.AddEvent("春之中级仪式", Action3);
Action Action4 = () => AddCeremony("春之高级仪式", 8);
TreeControl.Instance.AddEvent("春之高级仪式", Action4);
}
public override void Start()
{
base.Start();
SpecailBuff_Buildings.BuildingTechItem BlobBTI = new SpecailBuff_Buildings.BuildingTechItem(
null,AddTuanZi_Craftsman, "工匠团子", 0, 0, 1, true,0
);
BlobBTI.SetEndless();
InformationPanel.AddTechItem(BlobBTI);
for (int i = 0; i < WoodSculpture_Point.Count; i++)
{
AvailableScuplturePoints.Add(true);
}
}
public override void AddResources_Auto()
{
/*if (GameProcedureManager.Instance.WoodCount>=5 && Current_WoodSculpture < Max_WoodSculpture && isProducing)
{
int addNum = (int)(GlobalBuffSystem.Instance.GlobalMultiplier * LocalBuff_Auto * TuanZi_efficiency * TuanZi_Num * (efficiency_Level_Auto[1] * SpecalBuffMuti_efficiency_Auto + SpecalBuffAdd_efficiency_Auto));
progress += addNum;
if (addNum>0)
{
GameProcedureManager.Instance.WoodCount -= 5;
}
}*/
}
public override void SpecalUpdate()
{
if (progress >= Max_Progress && Current_WoodSculpture<WoodSculpture_Point.Count)
{
Debug.Log("木像台——木像已完成");
Current_WoodSculpture++;
GameObject new_WoodSculpture;
if (!is_Buff3_Active)
{
int avaint = GetAvailablePosi();
Transform avaPosi = WoodSculpture_Point[avaint];
new_WoodSculpture = Instantiate(WoodSculpture_Prefab_Simple, avaPosi);
new_WoodSculpture.GetComponent<WoodSculpture>().avaIndex = avaint;
}
else
{
float x = 0 + 0.1f * Craftsman_Num;
float r = UnityEngine.Random.Range(0f, 1f);
if (r <= x)
{
int avaint = GetAvailablePosi();
Transform avaPosi = WoodSculpture_Point[avaint];
new_WoodSculpture = Instantiate(WoodSculpture_Prefab_Super, avaPosi);
new_WoodSculpture.GetComponent<WoodSculpture>().avaIndex = avaint;
}
else
{
int avaint = GetAvailablePosi();
Transform avaPosi = WoodSculpture_Point[avaint];
new_WoodSculpture = Instantiate(WoodSculpture_Prefab_Simple, avaPosi);
new_WoodSculpture.GetComponent<WoodSculpture>().avaIndex = avaint;
}
}
WoodSculpture_List.Add(new_WoodSculpture);
new_WoodSculpture.GetComponent<WoodSculpture>().woodSculpture_Buildings = this;
new_WoodSculpture.GetComponent<WoodSculpture>().Value = CurrentSculptureValue;
ClearSculp();
}
}
public void ClearSculp()
{
//weh.TargetGameObject.SetActive(false);
isProducing = false;
progress = 0;
}
public void ReStartBuilding()
{
isProducing = true;
weh.ResetBranch();
//weh.TargetGameObject.SetActive(true);
progress = 0;
//weh.ResetBranch();
while (controllers.Count > 0)
{
/*if (cc.animator.GetCurrentAnimatorStateInfo(0).IsName("木锤移动")&&!cc.isFalling)
{
cc.animator.SetTrigger("Landed");
}*/
controllers[0].animator.SetTrigger("Landed");
controllers.RemoveAt(0);
}
}
public void AddSpecialWoodSculpture()
{
GameObject Special = Instantiate(WoodSculpture_Prefab_Special, Special_WoodSculpture_Point);
Special.transform.localPosition = new Vector3(0,0,0);
WoodSculpture_List.Add(Special);
Special.GetComponent<WoodSculpture>().woodSculpture_Buildings = this;
}
public void StopandStart()
{
isProducing = !isProducing;
}
public bool BuildingSwitch = true;
public void BuildingToggle()
{
BuildingSwitch = !BuildingSwitch;
}
public void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
Debug.Log(progress);
progress += 2;
weh.OnHit((float)(progress)/Max_Progress);
}
if (BuildingSwitch && !isProducing && Current_WoodSculpture<WoodSculpture_Point.Count)
{
if (CurrentSculptureCost <= GameProcedureManager.Instance.WoodCount)
{
GameProcedureManager.Instance.WoodCount -= CurrentSculptureCost;
ReStartBuilding();
}
}
}
public void AddTuanZi_Craftsman()
{
BlobController tuanzi = BlobManager.Instance.AvailableBlobs[0];
tuanzi.moveCancellation.Cancel();
tuanzi.transform.position = TuanZiPoint[TuanZi_Num%TuanZiPoint.Count].position;
// GameObjectPool.Instance.CreateDebugSphere(tuanzi.transform.position);
//Debug.Log("Generate at "+TuanZiPoint[TuanZi_Num].position.ToString());
TuanZiList.Add(BlobManager.Instance.AvailableBlobs[0]);
tuanzi.BelongingBuilding = this;
TuanZi_Num++;
Craftsman_Num++;
tuanzi.GetComponent<Animator>().Play("木锤移动");
tuanzi.GetComponent<Animator>().SetTrigger("Landed");
tuanzi.GetComponent<SpriteRenderer>().flipX = false;
//tuanzi.GetComponent<Animator>().Play("Kowtow_JiSi 1");
}
public void Punch(int num)
{
if(isProducing) progress += num;
weh.OnHit((float)(progress)/Max_Progress);
}
public int GetAvailablePosi()
{
//Debug.Log(AvailableScuplturePoints);
for (int i = 0; i < AvailableScuplturePoints.Count; i++)
{
if (AvailableScuplturePoints[i])
{
AvailableScuplturePoints[i] = false;
return i;
}
}
return -1;
}
public void RemoveScuplture(WoodSculpture sculpTrans)
{
AvailableScuplturePoints[sculpTrans.avaIndex] = true;
Current_WoodSculpture -= 1;
WoodSculpture_List.Remove(gameObject);
}
public List<BlobAnimationController> controllers = new List<BlobAnimationController>();
public void AddController(BlobAnimationController controller)
{
controllers.Add(controller);
}
public void RemoveController(BlobAnimationController controller)
{
controllers.Remove(controller);
}
}