| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498 |
- using cfg;
- using SimpleJSON;
- using Sirenix.OdinInspector;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using TMPro;
- using UnityEngine;
- using UnityEngine.UI;
- public enum AttributeTag
- {
- [LabelText("飞行")] Flying = 1,
- [LabelText("风")] Wind = 2,
- [LabelText("水")] Water = 3,
- [LabelText("岩")] Earth = 4,
- [LabelText("地面")] Ground = 5,
- [LabelText("雷")] Lightning = 6,
- [LabelText("火")] Fire = 7,
- [LabelText("木")] Nature = 8,
- }
- public enum SoldierType
- {
- Conduct,
- [LabelText("飞剑")] sword = 0,
- [LabelText("胖子")] shield = 1,
- [LabelText("林冲")] spear = 2,
- [LabelText("阴灵")] Spirits = 3,
- }
- public enum GameType
- {
- Gaming,
- GameEnd,
- Shop,
- }
- public enum TargetType
- {
- None = 0,
- Demonic = 1,
- Tower = 2,
- Player = 3,
- Enemy = 4,
- EnemyTower = 5,
- Boss = 6,
- Portal = 7,
- }
- 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("组件")] public PlayerController player;
- [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;
- [FoldoutGroup("标签")]
- [FoldoutGroup("标签")] [LabelText("单属性解锁阈值")] public int singleAttributeUnlockThreshold = 5;
- [FoldoutGroup("标签")] [LabelText("双属性解锁阈值")] public int dualAttributeUnlockThreshold = 10;
- [FoldoutGroup("标签/火")] [LabelText("是否启用")] public bool isFireEnable = false;
- [FoldoutGroup("标签/火")] [LabelText("触发概率")] [PropertyRange(0, 100)] public int fireProbability = 100;
- [FoldoutGroup("标签/火")] [LabelText("灼烧伤害时间间隔")] public float fireInterval = 0.5f;
- [FoldoutGroup("标签/火")] [LabelText("每层基础灼烧伤害")] public int fireDamage = 1;
- [FoldoutGroup("标签/火")] [LabelText("灼烧效果持续时间")] public float fireBuffTime;
- [FoldoutGroup("标签/火")] [LabelText("标签作用比值")] public float fireLabelEffectRatio;
- [FoldoutGroup("标签/冰")] [LabelText("是否启用")] public bool isIceEnable = false;
- [FoldoutGroup("标签/冰")] [LabelText("触发概率")] [PropertyRange(0, 100)] public int iceProbability = 100;
- [FoldoutGroup("标签/冰")] [LabelText("冰冻时间")] public float frozenTime = 3;
- [FoldoutGroup("标签/冰")] [LabelText("标签作用比值")] public float iceLabelEffectRatio;
- [FoldoutGroup("标签/火冰")] [LabelText("是否启用")] public bool isFireIceEnable = false;
- [FoldoutGroup("标签/火冰")] [LabelText("触发概率")] [PropertyRange(0, 100)] public int fireIceProbability = 100;
- [FoldoutGroup("标签/火冰")] [LabelText("爆炸伤害")] public int explosionDamage = 8;
- [FoldoutGroup("标签/火冰")] [LabelText("标签作用比值")] public float fireIceLabelEffectRatio;
- [FoldoutGroup("标签/雷")] [LabelText("是否启用")] public bool isThunderEnable = false;
- [FoldoutGroup("标签/雷")] [LabelText("触发概率")] [PropertyRange(0, 100)] public int thunderProbability = 100;
- [FoldoutGroup("标签/雷")] [LabelText("感电移速比值")] [PropertyRange(0, 1)] public float moveSpeedScale = 0.6f;
- [FoldoutGroup("标签/雷")] [LabelText("感电攻速比值")] [PropertyRange(0, 1)] public float attackSpeedScale = 0.6f;
- [FoldoutGroup("标签/雷")] [LabelText("易伤比值")] [PropertyRange(0, 2)] public float vulnerableRate = 0.5f;
- [FoldoutGroup("标签/雷")] [LabelText("伤害")] public int thunderDamage =3;
- [FoldoutGroup("标签/雷")] [LabelText("感电效果时间")] public float electrifyTime;
- [FoldoutGroup("标签/雷")] [LabelText("标签作用比值")] public float thunderLabelEffectRatio;
- [FoldoutGroup("标签/风")] [LabelText("是否启用")] public bool isWindEnable = false;
- [FoldoutGroup("标签/风")] [LabelText("触发概率")] [PropertyRange(0, 100)] public int windProbability = 100;
- [FoldoutGroup("标签/风")] [LabelText("对地面敌人的击飞力度")] public float forceToGround = 80f;
- [FoldoutGroup("标签/风")] [LabelText("落地伤害比率")] public float landingDamageRate = 1f;
- [FoldoutGroup("标签/风")] [LabelText("对飞行敌人的水平力度")] public float forceToFly = 80f;
- [FoldoutGroup("标签/风")] [LabelText("标签作用比值")] public float windLabelEffectRatio;
- [FoldoutGroup("标签/风雷")] [LabelText("是否启用")] public bool isWindThunderEnable = false;
- [FoldoutGroup("标签/风雷")] [LabelText("触发概率")] [PropertyRange(0, 100)] public int windThunderProbability = 100;
- [FoldoutGroup("标签/风雷")] [LabelText("落雷伤害")] [PropertyRange(0, 100)] public int thunderboltDamage = 8;
- [FoldoutGroup("标签/风雷")] [LabelText("标签作用比值")] public float windThunderLabelEffectRatio;
- [FoldoutGroup("标签/木")] [LabelText("是否启用")] public bool isWoodEnable = false;
- [FoldoutGroup("标签/木")] [LabelText("触发概率")] [PropertyRange(0, 100)] public int woodProbability = 100;
- [FoldoutGroup("标签/木")] [LabelText("标签作用比值")] public float woodLabelEffectRatio;
- [FoldoutGroup("标签/岩")] [LabelText("是否启用")] public bool isRockEnable = false;
- [FoldoutGroup("标签/岩")] [LabelText("触发概率")] [PropertyRange(0, 100)] public int rockProbability = 100;
- [FoldoutGroup("标签/岩")] [LabelText("石像预制体")] public GameObject stoneStatuePrefab;
- [FoldoutGroup("标签/岩")] [LabelText("标签作用比值")] public float rockLabelEffectRatio;
- [FoldoutGroup("标签/木岩")] [LabelText("是否启用")] public bool isWoodRockEnable = false;
- [FoldoutGroup("标签/木岩")] [LabelText("触发概率")] [PropertyRange(0, 100)] public int woodRockProbability = 100;
- [FoldoutGroup("标签/木岩")] [LabelText("标签作用比值")] public float woodRockLabelEffectRatio;
- [FoldoutGroup("标签/天")] [LabelText("是否启用")] public bool isSkyEnable = false;
- [FoldoutGroup("标签/天")] [LabelText("每个兵提供的攻击buff比率")] public float attackRate = 0.01f;
- [FoldoutGroup("标签/天")] [LabelText("标签作用比值")] public float skyLabelEffectRatio;
- [FoldoutGroup("标签/地")] [LabelText("是否启用")] public bool isGroundEnable = false;
- [FoldoutGroup("标签/地")] [LabelText("每个兵提供的血量buff比率")] public float hpRate = 0.01f;
- [FoldoutGroup("标签/地")] [LabelText("标签作用比值")] public float groundLabelEffectRatio;
- [FoldoutGroup("标签/天地")] [LabelText("是否启用")] public bool isSkyGroundIceEnable = false;
- [FoldoutGroup("标签/天地")] [LabelText("触发概率")] [PropertyRange(0, 100)] public int skyGroundProbability = 100;
- [FoldoutGroup("标签/天地")] [LabelText("标签作用比值")] public float skyGroundLabelEffectRatio;
- [Header("商店刷新")]
- [ValidateInput("CheckTagWeight","标签池子概率总和不是100%")]
- [FoldoutGroup("Rogue")] [LabelText("标签池子比重(%)")] [Tooltip("最高标签池;标签池;公共池")] public List<float> tagWeight;
- public static readonly Dictionary<string, TargetType> TagToTargetTypeMap = new Dictionary<string, TargetType>(StringComparer.Ordinal);
- 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;
- [FoldoutGroup("Rogue")] [LabelText("行军式加成倍率")] public float damageRate;
- [Header("数值加成")]
- [FoldoutGroup("Rogue")] [LabelText("伤害倍率")] public float damageScale;
- [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;
- [FoldoutGroup("Rogue")] [LabelText("击落伤害")] public int downDamage;
- [FoldoutGroup("Rogue")] [LabelText("击飞伤害")] public int blowUpDamage;
- 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;
- foreach (TargetType type in Enum.GetValues(typeof(TargetType)))
- {
- string tagName = type.ToString();
- if (!string.IsNullOrEmpty(tagName))
- {
- TagToTargetTypeMap[tagName] = type;
- }
- }
- }
- 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);
- }
- }
- for(int i = 0; i < 3; i++)
- {
- player.demonicDic[i] = new List<Demonic>();
- demonicNum[i].GetComponentInChildren<TextMeshProUGUI>().text = "0";
- }
- EnemyCreater.instance.Init();
- LevelSelect.instance.ChangeText();
- gameTime = 0;
- gameType = GameType.Gaming;
- nowLevel += 1;
- ChangeRogueChance();
- }
- public void ShowShop()
- {
- gameType = GameType.Shop;
- shopUI.Init();
- GameUI.instance.gameObject.SetActive(false);
- }
- public void GetTreasure(Treasure treasure)
- {
- for (int i = 0; i < treasure.type.Count; i++)
- {
- float data = treasure.data[i];
- switch (treasure.type[i])
- {
- case "伤害加成":
- damageScale += (int)data;
- break;
- case "伤害":
- damage += (int)data;
- break;
- case "暴击率":
- criticalChance += (int)data;
- break;
- case "回血":
- regeneration += (int)data;
- //player.regeneration += (int)data;
- break;
- case "吸血":
- lifesteal += (int)data;
- break;
- case "护甲":
- armor += (int)data;
- player.attributeStatus.resistances.armor += (int)data;
- break;
- case "闪避":
- dodge += (int)data;
- player.attributeStatus.resistances.dodge += (int)data;
- break;
- case "血量上限":
- totalHp += (int)data;
- player.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; j < player.rushChargeTotalNums; j++)
- {
- if (player.uiRush.childCount <= j)
- {
- Transform rushUIchid = Instantiate(player.uiRush.GetChild(0), player.uiRush);
- rushUIchid.localPosition = player.uiRush.GetChild(0).transform.localPosition + Vector3.right * 50 * j;
- }
- UIController.ChangeImageFill(player.uiRush.GetChild(j).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;
- case "击落伤害":
- downDamage += (int)data;
- break;
- case "击飞伤害":
- blowUpDamage += (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]);
- }
- }
|