|
|
@@ -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);
|