Преглед на файлове

新增建筑表,建筑生成表,建筑扣血触发召唤一大波兵

LAPTOP-OM1V99U2\永远de小亡灵 преди 1 година
родител
ревизия
e8a29d69d0

+ 114 - 74
ActionTowerDefense/Assets/Scripts/EnemyCreater.cs

@@ -4,17 +4,19 @@ using UnityEngine;
 using cfg;
 using System.Threading.Tasks;
 using Base.Common;
-using System.IO;
+using System.Linq;
 
 public class EnemyCreater : MonoBehaviour
 {
     public static EnemyCreater instance;
     public List<SingleCreateEnemyConfig> cfgCreateEnemy;
-    public List<bool> created;
+    public List<SingleCreateBuildingConfig> cfgCreateBuilding;
+    public List<bool> createdEnemy;
+    public List<bool> createdBuilding;
     public Dictionary<int, List<Enemy>> enemyDic;
+    public Dictionary<int, GameObject> buildingDic;
 
     [Header("传送门")]
-    public List<GameObject> portals;               //能召唤怪物的传送门
     public float portalsCreateTime = 10;           //传送门提前出现时间
     public Transform portalUIParent;               //传送门出现提示UI的父物体
 
@@ -30,15 +32,22 @@ public class EnemyCreater : MonoBehaviour
             return;
         }
         enemyDic = new Dictionary<int, List<Enemy>>();
+        buildingDic = new Dictionary<int, GameObject>();
     }
 
     private void Start()
     {
         cfgCreateEnemy = GameManager.instance.allCfgData.CfgCreateEnemy.DataList;
-        created = new List<bool>();
+        cfgCreateBuilding = GameManager.instance.allCfgData.CfgCreateBuilding.DataList;
+        createdEnemy = new List<bool>();
+        createdBuilding = new List<bool>();
         for (int i = 0; i < cfgCreateEnemy.Count; i++)
         {
-            created.Add(false);
+            createdEnemy.Add(false);
+        }
+        for (int i = 0; i < cfgCreateBuilding.Count; i++)
+        {
+            createdBuilding.Add(false);
         }
     }
 
@@ -46,50 +55,68 @@ public class EnemyCreater : MonoBehaviour
     {
         for (int i = 0; i < cfgCreateEnemy.Count; i++)
         {
-            if(cfgCreateEnemy[i].EnemyID > 2000)
+            if(cfgCreateEnemy[i].BuildingID == 0)
             {
-                if (cfgCreateEnemy[i].Time - portalsCreateTime <= gameTime && !created[i])
+                if (cfgCreateEnemy[i].Time <= gameTime && !createdEnemy[i])
                 {
-                    created[i] = true;
-                    SingleEnemyConfig cfgEnemy =
-                        GameManager.instance.allCfgData.CfgEnemy.Get(cfgCreateEnemy[i].EnemyID);
-                    GameObject prefab;
-                    GameObject enemyObj;
-                    prefab = Resources.Load<GameObject>(cfgEnemy.EnemyPrefab);
-                    if (prefab == null)
-                    {
-                        Debug.LogError("未读取到prefab:" + cfgEnemy.EnemyPrefab);
-                        continue;
-                    }
-                    else
+                    createdEnemy[i] = true;
+                    StartCreateEnemy(i);
+                }
+            }
+            else
+            {
+                GameObject result = null;
+                buildingDic.TryGetValue(cfgCreateEnemy[i].BuildingID, out result);
+                if (result != null)
+                {
+                    EnemyTower enemyTower = result.GetComponent<EnemyTower>();
+                    if (enemyTower.hp * 100 <= enemyTower.totalHp * cfgCreateEnemy[i].BuildingHP && !createdEnemy[i])
                     {
-                        enemyObj = Instantiate(prefab);
-                        enemyObj.SetActive(true);
+                        createdEnemy[i] = true;
+                        StartCreateEnemy(i);
                     }
-                    PortalsCreater portalsCreater = enemyObj.GetComponentInChildren<PortalsCreater>();
-                    portals.Add(portalsCreater.transform.GetChild(0).gameObject);
-                    portalsCreater.id = cfgCreateEnemy[i].PortalsID;
-                    portalsCreater.enemyCreater = this;
-                    portalsCreater.portalUIParent = portalUIParent;
-                    portalsCreater.Init(
-                        (int)(cfgEnemy.HP * cfgCreateEnemy[i].HPRatio),
-                        cfgCreateEnemy[i].PortalsPosition,
-                        cfgCreateEnemy[i].Scale,
-                        cfgCreateEnemy[i].Time - gameTime);
                 }
             }
-            else
+        }
+        for (int i = 0; i < cfgCreateBuilding.Count; i++)
+        {
+            if (!createdBuilding[i]
+                &&(cfgCreateBuilding[i].Type == 0 && cfgCreateBuilding[i].Time - portalsCreateTime <= gameTime
+                ||cfgCreateBuilding[i].Type == 1 && cfgCreateBuilding[i].Time <= gameTime))
             {
-                if (cfgCreateEnemy[i].Time<= gameTime && !created[i])
+                createdBuilding[i] = true;
+                if(gameTime< portalsCreateTime)
                 {
-                    created[i] = true;
-                    StartCreateEnemy(i);
-
+                    StartCreateBuilding(i, cfgCreateBuilding[i].Time);
                 }
+                else
+                {
+                    StartCreateBuilding(i, portalsCreateTime);
+                }
+                
             }
         }
     }
 
+    public void StartCreateBuilding(int id,float createTime)
+    {
+        SingleCreateBuildingConfig singleCreateBuilding = cfgCreateBuilding[id];
+        if (!instance)
+        {
+            return;
+        }
+        switch (singleCreateBuilding.Type)
+        {
+            case 0:
+                List<float> pos = singleCreateBuilding.Position.Concat(singleCreateBuilding.Position1).ToList();
+                CreatePortal(singleCreateBuilding.BuildingID, pos, singleCreateBuilding.Scale, singleCreateBuilding.HPRatio, createTime);
+                break;
+            case 1:
+                CreateEnemyTower(singleCreateBuilding.BuildingID, singleCreateBuilding.HPRatio, singleCreateBuilding.AttackRatio);
+                break;
+        }
+    }
+
     public async void StartCreateEnemy(int id)
     {
         SingleCreateEnemyConfig singleCreateEnemy = cfgCreateEnemy[id];
@@ -99,51 +126,64 @@ public class EnemyCreater : MonoBehaviour
             {
                 return;
             }
-            Vector3 pos;
-            if (singleCreateEnemy.PortalsID == 0)
+            Vector3 pos = Vector3.zero;
+            switch (singleCreateEnemy.Type)
             {
-                pos = new Vector3(
-                    singleCreateEnemy.Position[0],
-                    singleCreateEnemy.Position[1]
-                        + Random.Range(-singleCreateEnemy.YRandomRange / 2, singleCreateEnemy.YRandomRange / 2),
-                    singleCreateEnemy.Position[2]
-                        + Random.Range(-singleCreateEnemy.ZRandomRange / 2, singleCreateEnemy.ZRandomRange / 2));
-            }
-            else
-            {
-                GameObject portal = portals[singleCreateEnemy.PortalsID];
-                if (!portal.transform.GetChild(0).GetChild(0).gameObject.activeSelf)
-                {
-                    continue;
-                }
-                pos = portal.transform.position;
-                if(portal.transform.localScale.x > 0)
-                {
-                    pos.x -= 1;
-                }
-                else
-                {
-                    pos.x += 1;
-                }
-                pos.y += Random.Range(0, singleCreateEnemy.YRandomRange);
-                pos.z += Random.Range(-singleCreateEnemy.ZRandomRange / 2, singleCreateEnemy.ZRandomRange / 2);
-                PortalsCreater portalsCreater = portal.GetComponentInParent<PortalsCreater>();
-                portalsCreater.enemyNumber -= 1;
-                portalsCreater.enemyNumberText.text = portalsCreater.enemyNumber.ToString();
-                if(portalsCreater.enemyNumber == 0)
-                {
-                    portalsCreater.enemyNumberText.transform.parent.gameObject.SetActive(false);
-                    if (portalsCreater.onlyEnemy)
-                    {
-                        portalsCreater.coreCharacter.CoreBreak();
-                    }
-                }
+                case 0:
+                    pos = new Vector3(
+                            singleCreateEnemy.Position[0],
+                            singleCreateEnemy.Position[1]
+                                + Random.Range(-singleCreateEnemy.YRandomRange / 2, singleCreateEnemy.YRandomRange / 2),
+                            singleCreateEnemy.Position[2]
+                                + Random.Range(-singleCreateEnemy.ZRandomRange / 2, singleCreateEnemy.ZRandomRange / 2));
+                    break;
+                case 1:
+                    pos = buildingDic[singleCreateEnemy.BuildingID].transform.position;
+                    pos.y += Random.Range(0, singleCreateEnemy.YRandomRange);
+                    pos.z += Random.Range(0, singleCreateEnemy.ZRandomRange);
+                    break;
             }
             CreateEnemy(singleCreateEnemy.EnemyID, pos, singleCreateEnemy.HPRatio, singleCreateEnemy.AttackRatio);
             await Task.Delay((int)(singleCreateEnemy.TimeInterval * 1000));
         }
     }
 
+    public void CreateEnemyTower(int buildingID, float hpRatio, float attackRatio)
+    {
+        SingleBuildingConfig cfgBuilding = GameManager.instance.allCfgData.CfgBuilding.Get(buildingID);
+        GameObject towerObj = Util.Instantiate(cfgBuilding.BuildingPrefab);
+        EnemyTower enemyTower = towerObj.GetComponent<EnemyTower>();
+        buildingDic.Add(buildingID, towerObj);
+        enemyTower.totalHp = (int)(cfgBuilding.HP * hpRatio);
+        enemyTower.Init();
+        AttackInfo attackInfo = enemyTower.attack1Infos[0];
+        attackInfo.damage = (int)(cfgBuilding.Attack * attackRatio);
+        enemyTower.attack1Infos[0] = attackInfo;
+    }
+
+    public void CreatePortal(int buildingID, List<float> pos, List<float> scale, float hpRatio, float createTime)
+    {
+        SingleBuildingConfig cfgBuilding = GameManager.instance.allCfgData.CfgBuilding.Get(buildingID);
+        GameObject portalObj = Util.Instantiate(cfgBuilding.BuildingPrefab);
+        PortalsCreater portalsCreater = portalObj.GetComponent<PortalsCreater>();
+        portalsCreater.id = buildingID;
+        buildingDic.Add(buildingID, portalObj);
+        portalsCreater.totalHp = (int)(cfgBuilding.HP * hpRatio);
+        portalsCreater.enemyCreater = this;
+        portalsCreater.portalUIParent = portalUIParent;
+        portalsCreater.Init(pos,scale,createTime);
+        portalsCreater.enemyNumber -= 1;
+        portalsCreater.enemyNumberText.text = portalsCreater.enemyNumber.ToString();
+        if (portalsCreater.enemyNumber == 0)
+        {
+            portalsCreater.enemyNumberText.transform.parent.gameObject.SetActive(false);
+            if (portalsCreater.onlyEnemy)
+            {
+                portalsCreater.coreCharacter.CoreBreak();
+            }
+        }
+    }
+
     public void CreateEnemy(int enemyId, Vector3 pos, float hpRatio, float attackRatio)
     {
         SingleEnemyConfig cfgEnemy = GameManager.instance.allCfgData.CfgEnemy.Get(enemyId);

+ 0 - 1
ActionTowerDefense/Assets/Scripts/EnemyTower.cs

@@ -8,7 +8,6 @@ public class EnemyTower : Character
     private void Awake()
     {
         TowerMap.enemyTowers.Add(gameObject);
-        Init();
     }
 
     public bool GetAttack()

+ 17 - 1
ActionTowerDefense/Assets/Scripts/PlayerController.cs

@@ -614,6 +614,20 @@ public class PlayerController : MoveCharacter
             {
                 if (spirits.currentSpirit != Spirits.SpiritType.None)
                 {
+                    for (int i = 0; i < 3; i++)
+                    {
+                        if(spirits.ownSpirits[i] == spirits.currentSpirit) {
+                            if(spirits.ultimateTimes[i] == 1)
+                            {
+                                spirits.hasSpirits -= 1;
+                            }
+                            else
+                            {
+                                spirits.ultimateTimes[i] -= 1;
+                            }
+                            break;
+                        }
+                    }
                     switch (playerId)
                     {
                         case 0:
@@ -625,7 +639,9 @@ public class PlayerController : MoveCharacter
                         default:
                             break;
                     }
-                    Transfiguration((int)spirits.currentSpirit + 3);
+                    //Transfiguration((int)spirits.currentSpirit + 3);
+                    Summon((int)spirits.currentSpirit + 3);
+                   
                 }
             }
             else

+ 7 - 5
ActionTowerDefense/Assets/Scripts/Portal/PortalsCreater.cs

@@ -5,6 +5,7 @@ using TMPro;
 
 public class PortalsCreater : MonoBehaviour
 {
+    public int totalHp;
     public PortalsController[] portalsControllers = new PortalsController[2];
     public CoreCharacter coreCharacter;
     [HideInInspector]
@@ -28,6 +29,7 @@ public class PortalsCreater : MonoBehaviour
 
     private void Start()
     {
+        coreCharacter.totalHp = totalHp;
         for(int i = 0; i < countDowns.Length; i++)
         {
             countDowns[i].gameObject.SetActive(true);
@@ -69,7 +71,7 @@ public class PortalsCreater : MonoBehaviour
             }
         }
     }
-    public void Init(int totalHP, List<float> position, List<float> scale, float createTime)
+    public void Init(List<float> position, List<float> scale, float createTime)
     {
         transform.position = Vector3.zero;
         for(int i = 0; i < portal.Length; i++)
@@ -101,12 +103,12 @@ public class PortalsCreater : MonoBehaviour
         }
 
         
-        coreCharacter.totalHp = totalHP;
-        coreCharacter.hp = totalHP;
-        coreCharacter.uiHp.Show(totalHP, totalHP);
+        coreCharacter.totalHp = totalHp;
+        coreCharacter.hp = totalHp;
+        coreCharacter.uiHp.Show(totalHp, totalHp);
         for (int i = 0; i < enemyCreater.cfgCreateEnemy.Count; i++)
         {
-            if (enemyCreater.cfgCreateEnemy[i].PortalsID == id)
+            if (enemyCreater.cfgCreateEnemy[i].BuildingID == id)
             {
                 enemyNumber += enemyCreater.cfgCreateEnemy[i].Count;
             }

BIN
ActionTowerDefense/Luban/Config/Datas/__tables__.xlsx


BIN
ActionTowerDefense/Luban/Config/Datas/出怪表.xlsx


BIN
ActionTowerDefense/Luban/Config/Datas/建筑生成表.xlsx


BIN
ActionTowerDefense/Luban/Config/Datas/建筑表.xlsx


BIN
ActionTowerDefense/Luban/Config/Datas/怪物表.xlsx