public bool SpawnUnit(TCController.STORE tospawn, bool amAI, AIBehaviour.outpostBuilding aiBuilding, AIDroneController.DroneMode droneMode) { if (tospawn == STORE.BASE) { if (!Modifylock && (GM.GetResouceCount((int)objID.ownerPlayerID) >= baseCost) && (GM.GetUnitCount((int)objID.ownerPlayerID) < GM.GetUnitCountMax((int)objID.ownerPlayerID))) { GM.UpdateResourceCount((int)objID.ownerPlayerID, -baseCost); GameObject spawnedObj = Instantiate(unitTemplate, (transform.position + (new Vector3(Random.Range(-1.0f, 1.0f), 0.0f, Random.Range(-1.0f, 1.0f)) * 5.0f)), Quaternion.identity); spawnedObj.GetComponent <ObjectID>().ownerPlayerID = objID.ownerPlayerID; if (!amAI) { playerunit.Add(spawnedObj); } else { spawnedObj.GetComponent <AIDroneController>().droneMode = droneMode; } return(true); } } else if (tospawn == STORE.MINECW) { if (GM.GetResouceCount((int)objID.ownerPlayerID) >= mineCost) { if (!amAI) { GM.UpdateResourceCount((int)objID.ownerPlayerID, -mineCost); playerCtrl.lastSelectedBuildingToBuild = carWashMiner; } else { GM.UpdateResourceCount((int)objID.ownerPlayerID, -mineCost); GameObject refer = Instantiate(carWashMiner, aiBuilding.lastSeenPosition, Quaternion.identity); //Assign ownership refer.GetComponent <ObjectID>().ownerPlayerID = objID.ownerPlayerID; } return(true); } } else if (tospawn == STORE.ATTACKCW) { if (GM.GetResouceCount((int)objID.ownerPlayerID) >= attackCost) { if (!amAI) { GM.UpdateResourceCount((int)objID.ownerPlayerID, -attackCost); playerCtrl.lastSelectedBuildingToBuild = carWashFighter; } else { GM.UpdateResourceCount((int)objID.ownerPlayerID, -attackCost); GameObject refer = Instantiate(carWashFighter, aiBuilding.lastSeenPosition, Quaternion.identity); //Assign ownership refer.GetComponent <ObjectID>().ownerPlayerID = objID.ownerPlayerID; } return(true); } } else if (tospawn == STORE.BOOSTCW) { if (GM.GetResouceCount((int)objID.ownerPlayerID) >= boostCost) { if (!amAI) { GM.UpdateResourceCount((int)objID.ownerPlayerID, -boostCost); playerCtrl.lastSelectedBuildingToBuild = carWashBoost; } else { GM.UpdateResourceCount((int)objID.ownerPlayerID, -boostCost); GameObject refer = Instantiate(carWashBoost, aiBuilding.lastSeenPosition, Quaternion.identity); //Assign ownership refer.GetComponent <ObjectID>().ownerPlayerID = objID.ownerPlayerID; } return(true); } } else if (tospawn == STORE.HOUSE) { if (GM.GetResouceCount((int)objID.ownerPlayerID) >= housecost) { if (!amAI) { Debug.Log("spawn house"); GM.UpdateResourceCount((int)objID.ownerPlayerID, -housecost); GM.setUnitCountMax((int)objID.ownerPlayerID, GM.GetUnitCountMax((int)objID.ownerPlayerID) + 10); playerCtrl.lastSelectedBuildingToBuild = houseTemplate; } else { GM.UpdateResourceCount((int)objID.ownerPlayerID, -housecost); GameObject refer = Instantiate(houseTemplate, aiBuilding.lastSeenPosition, Quaternion.identity); //Assign ownership refer.GetComponent <ObjectID>().ownerPlayerID = objID.ownerPlayerID; } return(true); } } else if (tospawn == STORE.ESCAPE) { if (GM.GetResouceCount((int)objID.ownerPlayerID) >= escapeCost) { GM.UpdateResourceCount((int)objID.ownerPlayerID, -escapeCost); if (objID.ownerPlayerID == ObjectID.PlayerID.PLAYER) { gamewinUI.SetActive(true); Debug.Log("escape"); } this.gameObject.GetComponent <Rigidbody>().AddForce(-(GameObject.Find("Blackhole").gameObject.transform.position - transform.position).normalized * 10.0f, ForceMode.Impulse); return(true); } } else if (tospawn == STORE.TURRET) { if (!amAI) { GM.UpdateResourceCount((int)objID.ownerPlayerID, -turretCost); playerCtrl.lastSelectedBuildingToBuild = turretTemplate; } else { GM.UpdateResourceCount((int)objID.ownerPlayerID, -turretCost); GameObject refer = Instantiate(turretTemplate, aiBuilding.lastSeenPosition, Quaternion.identity); //Assign ownership refer.GetComponent <ObjectID>().ownerPlayerID = objID.ownerPlayerID; } return(true); } return(false); }
public bool SpawnUnit(TCController.STORE tospawn, bool amAI, AIDroneController.DroneMode dronemode) { return(SpawnUnit(tospawn, amAI, null, dronemode)); }