| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- using cfg;
- using SimpleJSON;
- using Sirenix.OdinInspector;
- using System.Collections.Generic;
- using System.IO;
- using TMPro;
- using UnityEngine;
- using UnityEngine.UI;
- public enum SoldierType
- {
- [LabelText("飞剑")] sword = 0,
- [LabelText("胖子")] shield = 1,
- [LabelText("林冲")] spear = 2,
- [LabelText("阴灵")] Spirits = 3,
- }
- public enum GameType
- {
- Gaming,
- GameEnd,
- Shop,
- }
- public class GameManager : MonoBehaviour
- {
- public static GameManager instance;
- [FoldoutGroup("组件", order: -1)] public UIHP p1uiHP;
- [FoldoutGroup("组件")] public UIHP p1uiMP;
- [FoldoutGroup("组件")] public Transform p1uiRush;
- [FoldoutGroup("组件")] public GameObject[] demonicNum;
- [FoldoutGroup("组件")] public TextMeshProUGUI text;
- [FoldoutGroup("组件")] public GameObject chapterBG; //当前关卡的原始背景(用于和boss背景做替换)
- [FoldoutGroup("组件")] public GameObject shopButton;
- [FoldoutGroup("组件")] public ShopUI shopUI;
- [FoldoutGroup("组件")] public TextMeshProUGUI moneyText;
- [FoldoutGroup("金币结算", order: -1)][LabelText("限制时间")] public int rewardTime;
- [FoldoutGroup("金币结算")][LabelText("金币奖励")] public int totalMoney;
- [FoldoutGroup("金币结算")][LabelText("额外金币奖励")] public int extraMoney;
- [FoldoutGroup("金币结算")][LabelText("惩罚时间间隔")] public int deductMoneyTime;
- [FoldoutGroup("金币结算")][LabelText("每次惩罚扣除金币数量")] public int deductMoney;
- [Header("金币掉落")]
- [FoldoutGroup("金币结算")][LabelText("怪物掉落金币数量")] public int enemyGoldDrop;
- [FoldoutGroup("金币结算")][LabelText("金币掉落特效")] public GameObject dropGoldFX;
- [FoldoutGroup("金币结算")][LabelText("金币掉落字体")] public GameObject dropGoldText;
- [Header("商店刷新")]
- [ValidateInput("CheckTagWeight","标签池子概率总和不是100%")]
- [FoldoutGroup("Rogue")] [LabelText("标签池子比重(%)")] [Tooltip("最高标签池;标签池;公共池")] public List<float> tagWeight;
- public bool CheckTagWeight(List<float> weights)
- {
- float num = 0;
- for(int i = 0; i < 3; i++)
- {
- num += weights[i];
- }
- if(num == 100)
- {
- return true;
- }
- else
- {
- return false;
- }
-
- }
- [FoldoutGroup("Rogue")] [LabelText("第几关开始出现(%)")] public List<int> unlockLevel;
- [FoldoutGroup("Rogue")] [LabelText("基础几率(%)")] public List<float> baseChance;
- [FoldoutGroup("Rogue")] [LabelText("每关增加的几率(%)")] public List<float> chanceIncreasePerLevel;
- [FoldoutGroup("Rogue")] [LabelText("最大几率(%)")] public List<float> maximumChance ;
- [FoldoutGroup("Rogue")] public List<List<List<SingleTreasureConfig>>> treasuresList;
- [FoldoutGroup("Rogue")] [DisplayOnly] public List<float> trueRefreshChance;
- [FoldoutGroup("Rogue")] [HideInInspector] public List<float> refreshChance;
- [Header("数值加成")]
- [FoldoutGroup("Rogue")] [LabelText("伤害")] public int damage;
- [FoldoutGroup("Rogue")] [LabelText("暴击率")] public int criticalChance;
- [FoldoutGroup("Rogue")] [LabelText("回血")] public int regeneration;
- [FoldoutGroup("Rogue")] [LabelText("吸血")] public int lifesteal;
- [FoldoutGroup("Rogue")] [LabelText("护甲")] public int armor;
- [FoldoutGroup("Rogue")] [LabelText("闪避")] public int dodge;
- [FoldoutGroup("Rogue")] [LabelText("血量上限")] public int totalHp;
- [FoldoutGroup("Rogue")] [LabelText("金币获得增加")] public int increasedGoldGain;
- [FoldoutGroup("Rogue")] [LabelText("经验获得增加")] public int increasedEXPGain;
- [FoldoutGroup("Rogue")] [LabelText("冲刺次数")] public int dashCharges;
- [FoldoutGroup("Rogue")] [LabelText("蓝量")] public int totalMp;
- [FoldoutGroup("Rogue")] [LabelText("回蓝速度")] public int mpRegen;
- public LeveType leveType;
- [LabelText("下一关倍率增幅")] public List<float> ratioIncrease = new List<float> { 0.4f, 1.6f, -0.8f };
- public int nowLevel;
- public int money;
- public List<Treasure> myTreasures;
- public List<int> myTreasuresTag;
- public int maxTreasuresTag;
- public float gameTime;
- public float totalGameTime;
- public Tables allCfgData;
- static public SoldierType[] curSoldiers; //本局游戏选择的三个士兵
- public List<CreateEnemyConfig> createEnemyConfigs;
- [DisplayOnly] public GameType gameType;
- [DisplayOnly] public float levelRatio = 1;
-
- private JSONNode Loader(string fileName)
- {
- return JSON.Parse(File.ReadAllText("GenerateDatas/json/" + fileName + ".json"));
- }
- public void GetAllExcel()
- {
- allCfgData = new Tables(Loader);
- }
- public void ReloadCfgCreateEnemyData()
- {
- createEnemyConfigs = new List<CreateEnemyConfig>(); ;
- for (int i = 0; i < 9; i++)
- {
- JSONNode keyValuePairs = JSON.Parse(File.ReadAllText($"GenerateDatas/json/CfgCreateEnemy{i}.json"));
- CreateEnemyConfig createEnemyConfig = new CreateEnemyConfig(keyValuePairs);
- createEnemyConfigs.Add(createEnemyConfig);
- }
- }
- private void Awake()
- {
- //选定本局游戏有哪些士兵,后面兵多了这里要改
- curSoldiers = new SoldierType[3];
- curSoldiers[0] = SoldierType.sword;
- curSoldiers[1] = SoldierType.shield;
- curSoldiers[2] = SoldierType.spear;
- if (!instance)
- {
- instance = this;
- GetAllExcel();
- ReloadCfgCreateEnemyData();
- }
- else
- {
- DestroyImmediate(gameObject);
- return;
- }
- leveType = LeveType.Introduction;
- myTreasures = new List<Treasure>();
- treasuresList = new List<List<List<SingleTreasureConfig>>>();
- refreshChance = new List<float>();
- for (int i = 0; i < 4; i++)
- {
- treasuresList.Add(new List<List<SingleTreasureConfig>>());
- refreshChance.Add(baseChance[i]);
- for(int j = 0; j < 9; j++)
- {
- treasuresList[i].Add(new List<SingleTreasureConfig>());
- }
- }
- trueRefreshChance = new List<float>();
- for (int i = 0; i < 3; i++)
- {
- trueRefreshChance.Add(refreshChance[i] - refreshChance[i + 1]);
- }
- trueRefreshChance.Add(refreshChance[3]);
- List<SingleTreasureConfig> cfgTreasureList = allCfgData.CfgTreasure.DataList;
- for(int i = 0;i< cfgTreasureList.Count; i++)
- {
- SingleTreasureConfig singleTreasureConfig = cfgTreasureList[i];
- treasuresList[singleTreasureConfig.Quality][0].Add(singleTreasureConfig);
- for(int j = 0; j < singleTreasureConfig.Tag.Count;j++)
- {
- treasuresList[singleTreasureConfig.Quality][singleTreasureConfig.Tag[j]].Add(singleTreasureConfig);
- }
- }
- maxTreasuresTag = -1;
- nowLevel = 1;
- }
- private void Start()
- {
- gameTime = 0;
- gameType = GameType.Gaming;
- }
- private void FixedUpdate()
- {
- if (gameType == GameType.Gaming)
- {
- gameTime += Time.deltaTime;
- totalGameTime += Time.deltaTime;
- EnemyCreater.instance.OnGameTimeChange(gameTime);
- int timeText = (int)gameTime;
- //text.text = $"{timeText / 60:D2}:{timeText % 60:D2}({timeText}s)";
- text.text = $"{timeText}";
- }
- }
- //游戏结束
- public void GameEnd()
- {
- gameType = GameType.GameEnd;
- int dropGold = 0;
- foreach (List<Enemy> objs in EnemyCreater.instance.enemyDic.Values)
- {
- for (int i = 0; i < objs.Count; i++)
- {
- if (objs[i].gameObject.activeSelf)
- {
- objs[i].killer = null;
- objs[i].ChangeState(CharacterState.Die);
- dropGold += enemyGoldDrop;
- }
- }
- }
- if (leveType == LeveType.Boss)
- {
- return;
- }
- AddMoney(dropGold);
- shopButton.SetActive(true);
- }
-
- public void AddMoney(int enemyDrop)
- {
- int addMoney;
- if(gameTime < rewardTime)
- {
- addMoney = totalMoney + extraMoney;
- }
- else
- {
- int extraTime = (int)gameTime - rewardTime;
- addMoney = Mathf.Clamp(totalMoney - (extraTime / deductMoneyTime) * deductMoney, 0, totalMoney);
- }
- addMoney += enemyDrop;
- money += Mathf.RoundToInt(addMoney * (1 + increasedGoldGain / 100f));
- moneyText.text = $"{money}";
- }
- //下一关
- public void NextLevel()
- {
- shopButton.SetActive(false);
- if(nowLevel - 1 < ratioIncrease.Count)
- {
- levelRatio += ratioIncrease[nowLevel - 1];
- }
- switch (leveType)
- {
- case LeveType.Introduction:
- EnemyCreater.instance.GetLevelOrientation(0);
- leveType = LeveType.Development;
- break;
- case LeveType.Development:
- EnemyCreater.instance.GetLevelOrientation(1);
- leveType = LeveType.Transition;
- break;
- case LeveType.Transition:
- leveType = LeveType.Conclusion;
- break;
- case LeveType.Conclusion:
- leveType = LeveType.Boss;
- break;
- }
- PlayersInput.instance[0].PlayerRevive();
- foreach(List<GameObject> objs in PoolManager.instance.activeObjs.Values)
- {
- List<GameObject> newObjs = new List<GameObject>(objs);
- for(int i = 0; i < newObjs.Count; i++)
- {
- newObjs[i].gameObject.SetActive(false);
- }
- }
- EnemyCreater.instance.Init();
- LevelSelect.instance.ChangeText();
- gameTime = 0;
- gameType = GameType.Gaming;
- nowLevel += 1;
- ChangeRogueChance();
- }
- public void ShowShop()
- {
- gameType = GameType.Shop;
- shopUI.Init();
- }
- public void GetTreasure(Treasure treasure)
- {
- PlayerController player = PlayersInput.instance[0];
- for (int i = 0; i < treasure.type.Count; i++)
- {
- float data = treasure.data[i];
- switch (treasure.type[i])
- {
- case "伤害":
- damage += (int)data;
- break;
- case "暴击率":
- criticalChance += (int)data;
- break;
- case "回血":
- regeneration += (int)data;
- break;
- case "吸血":
- lifesteal += (int)data;
- break;
- case "护甲":
- armor += (int)data;
- break;
- case "闪避":
- dodge += (int)data;
- break;
- case "血量上限":
- totalHp += (int)data;
- break;
- case "金币获得增加":
- increasedGoldGain += (int)data;
- break;
- case "经验获得增加":
- increasedEXPGain += (int)data;
- break;
- case "冲刺次数":
- dashCharges += (int)data;
- player.rushChargeTotalNums += (int)data;
- player.rushChargeNums = player.rushChargeTotalNums;
- for (int j = 0; i < player.rushChargeTotalNums; j++)
- {
- if (player.uiRush.childCount <= i)
- {
- Transform rushUIchid = Instantiate(player.uiRush.GetChild(0), player.uiRush);
- rushUIchid.localPosition = player.uiRush.GetChild(0).transform.localPosition + Vector3.right * 50 * i;
- }
- UIController.ChangeImageFill(player.uiRush.GetChild(i).GetComponent<Image>(), 1);
- }
- break;
- case "蓝量":
- totalMp += (int)data;
- player.totalMp += (int)data;
- player.mp = player.totalMp;
- player.uiMp.Show(player.mp, player.totalMp);
- break;
- case "回蓝速度":
- mpRegen += (int)data;
- player.mpReplySpeed += (int)data;
- break;
- default:
- Debug.LogError($"宝物配置出错,不存在词条【{treasure.type[i]}】");
- break;
- }
- }
- }
- public void ChangeRogueChance()
- {
- for(int i = 0; i < 4; i++)
- {
- if(nowLevel >= unlockLevel[i])
- {
- refreshChance[i] += chanceIncreasePerLevel[i];
- if(refreshChance[i] > maximumChance[i])
- {
- refreshChance[i] = maximumChance[i];
- }
- }
- }
- for (int i = 0; i < 3; i++)
- {
- trueRefreshChance.Add(refreshChance[i] - refreshChance[i + 1]);
- }
- trueRefreshChance.Add(refreshChance[3]);
- }
- }
|