void ReachDestination() { Debug.Log("ReachDestination"); GameControl.OnCreepReachDestination(this); SpawnManager.OnCreepReachDestination(this); TDTK.OnCreepDestination(this); if (path.loop) { if (!path.IsLinearPath()) { //if(onDestinationE!=null) onDestinationE(this); subWaypointID = 0; waypointID = path.GetLoopPoint(); subPath = path.GetWPSectionPath(waypointID); } else { waypointID = path.GetLoopPoint(); } return; } destroyed = true; //if(onDestinationE!=null) onDestinationE(this); //float delay=0; //if(aniInstance!=null){ delay=aniInstance.PlayDestination(); } StartCoroutine(_ReachDestination(PlayAnimDestination())); }
public bool _SpendRsc(List <float> list) { //Debug.Log("SpendRsc "+list[0]+" "+rscList[0]); if (!VerifyRscList(list.Count)) { return(false); } //~ if(mul!=1) list=ApplyMultiplier(list, mul); if (!_HasSufficientRsc(list)) { return(false); } //Debug.Log(" - SpendRsc "+list[0]+" "+rscList[0]); for (int i = 0; i < list.Count; i++) { rscList[i] -= (int)Mathf.Round(list[i]); } TDTK.OnRscChanged(rscList); return(true); }
private void SpawnNextWave() //actual function to spawn next wave { if (!GameControl.HasGameStarted()) { GameControl.StartGame(); } if (spawning) { return; } readyToSpawn = false; SetTimeToNextWave(-1); currentWaveIdx += 1; if (!IsEndlessMode()) { StartCoroutine(SpawnWave(waveList[currentWaveIdx])); } else { waveList.Add(generator.Generate(currentWaveIdx + 2)); int waveIdx = GetListIndexFromWaveIndex(currentWaveIdx); StartCoroutine(SpawnWave(waveList[waveIdx])); } TDTK.OnNewWave(currentWaveIdx + 1); AudioManager.OnNewWave(); }
// Use this for initialization void Awake() { instance = this; List <UnitTower> dbList = TowerDB.GetList(); for (int i = 0; i < dbList.Count; i++) { if (!unavailablePrefabIDList.Contains(dbList[i].prefabID) && !dbList[i].hideInInspector) { buildableList.Add(dbList[i]); } } for (int i = 0; i < buildableList.Count; i++) { GameObject obj = (GameObject)Instantiate(buildableList[i].gameObject); sampleList.Add(obj.GetComponent <UnitTower>()); sampleList[sampleList.Count - 1].isPreview = true; sampleList[sampleList.Count - 1].gameObject.layer = TDTK.GetLayerTerrain(); sampleList[sampleList.Count - 1].transform.parent = transform; obj.SetActive(false); } //Debug.Log("remove this"); //for(int i=0; i<buildableList.Count; i++) buildableList[i].prefabID=i; }
public static void EndGame() { if (instance.gameState == _GameState.Over) { return; } instance.playerWon = instance.life > 0; instance.gameState = _GameState.Over; if (instance.playerWon) { RscManager.GainRsc(instance.rscGainOnWin); PerkManager.GainRsc(instance.perkRscGainOnWin); RscManager.CachedRsc(); //for rsc to be carry forth to next level PerkManager.CachedProgress(); //for perk progress to be carry forth to next level AudioManager.OnPlayerWon(); } else { AudioManager.OnPlayerLost(); } Debug.Log("Game Over " + instance.playerWon + " " + instance.gameState); TDTK.OnGameOver(instance.playerWon); }
public void _ActivateAbility(int idx, Vector3 pos = default(Vector3)) { Debug.Log("_ActivateAbility " + idx + " " + pendingTgtAbilityIdx); if (idx < 0 && Time.time - tgtSelectCooldown < 0.2) { return; } if (idx < 0) { if (pendingTgtAbilityIdx >= 0) { idx = pendingTgtAbilityIdx; } else { return; } } Debug.Log("_ActivateAbility"); abilityList[idx].Activate(pos); ClearSelect(); TDTK.OnActivateAbility(abilityList[idx]); }
public void _Show(UnitTower tower) { if (weaponList.Count == 0) { TDTK.OnGameMessage("No available weapon"); return; } if (useTowerWeapon && tower.FPSWeaponID < 0) { TDTK.OnGameMessage("Tower doesn't have a weapon"); return; } SetAnchorTower(tower); thisT.position = tower.thisT.position + new Vector3(0, 5, 0); thisT.rotation = Camera.main.transform.rotation; //Screen.lockCursor=false; Cursor.visible = false; isInFPSMode = true; //if(onFPSModeE!=null) onFPSModeE(isInFPSMode); TDTK.OnFPSMode(isInFPSMode); thisObj.SetActive(isInFPSMode); StartCoroutine(_LerpToView(thisT.position)); }
public static void AddAbility(int prefabID, int replacePrefabID = -1) //called from perk to add new ability { if (instance == null) { return; } int replaceIdx = -1; if (replacePrefabID >= 0) { for (int i = 0; i < instance.abilityList.Count; i++) { if (instance.abilityList[i].prefabID == replacePrefabID) { replaceIdx = i; break; } } } Ability newAbility = AbilityDB.GetPrefab(prefabID).Clone(); if (replaceIdx < 0) { instance.abilityList.Add(newAbility); newAbility.Init(instance.abilityList.Count - 1, instance.transform); } else { instance.abilityList[replaceIdx] = newAbility; newAbility.Init(replaceIdx, instance.transform); } TDTK.OnNewAbility(newAbility); }
public static void PreBuildTower(UnitTower tower) { BuildPlatform platform = null; LayerMask mask = 1 << TDTK.GetLayerPlatform(); Collider[] cols = Physics.OverlapSphere(tower.GetPos(), GetGridSize(), mask); if (cols.Length > 0) { platform = cols[0].gameObject.GetComponent <BuildPlatform>(); } if (platform != null) { NodeTD node = platform.GetNearestNode(tower.GetPos()); if (Vector3.Distance(node.pos, tower.GetPos()) < GetGridSize()) { AddTower(tower, platform, node.ID); tower.transform.position = node.pos; return; } } //~ GameObject obj=new GameObject("platform"); //~ SphereCollider collider=obj.AddComponent<SphereCollider>(); //~ collider.radius=GetGridSize()*.5f; //~ obj.transform.parent=tower.transform; //~ obj.transform.localPosition=Vector3.zero; //~ obj.layer=TDTK.GetLayerPlatform(); //~ platform=obj.AddComponent<BuildPlatform>(); //~ platform.SingleNodePlatform(); AddTower(tower, CreatePlatformForTower(tower, GetGridSize()), 0); }
public void RegenerateRsc() { if (!regenerateRsc) { return; } bool requireUpate = false; for (int i = 0; i < rscList.Count; i++) { if (rscItemList[i].regenRate == 0) { continue; } regenCachedList[i] += GetRegenRate(i) * Time.fixedDeltaTime; if (regenCachedList[i] > 1) { float gain = Mathf.Floor(regenCachedList[i]); rscList[i] += (int)gain; regenCachedList[i] -= gain; requireUpate = true; } } if (requireUpate) { TDTK.OnRscChanged(rscList); } }
public void InitTower() { List <UnitTower> towerListDB = TDTK.GetTowerDBList(); //TowerDB.Load(); availableTowerIDList = new List <int>(); towerList = new List <UnitTower>(); for (int i = 0; i < towerListDB.Count; i++) { if (towerListDB[i] == null) { continue; } if (towerListDB[i].disableInBuildManager) { continue; } if (unavailableTowerIDList.Contains(towerListDB[i].prefabID)) { continue; } //if(availableTowerIDList.Contains(towerListDB[i].prefabID)) towerList.Add(towerListDB[i]); availableTowerIDList.Add(towerListDB[i].prefabID); } List <UnitTower> newList = PerkManager.GetUnlockedTowerList(); for (int i = 0; i < newList.Count; i++) { towerList.Add(newList[i]); } }
public static void PreBuildTower(UnitTower tower) { PlatformTD platform = null; LayerMask mask = 1 << TDTK.GetLayerPlatform(); Collider[] cols = Physics.OverlapSphere(tower.thisT.position, GetGridSize(), mask); if (cols.Length > 0) { platform = cols[0].gameObject.GetComponent <PlatformTD>(); } if (platform != null) { Vector3 buildPos = GetTilePos(platform, tower.thisT.position); tower.thisT.position = buildPos; tower.thisT.rotation = platform.thisT.rotation; platform.BuildTower(buildPos, tower); } else { Debug.Log("no platform found for pre-placed tower"); } tower.InitTower(instance.towerCount += 1); }
public void Build(bool isUpgrade = false) { if (!isUpgrade) { constructState = _ConstructState.Build; AudioManager.OnBuildStart(); AudioManager.PlaySound(soundBuilding); } else { constructState = _ConstructState.Upgrade; AudioManager.OnUpgradeStart(); AudioManager.PlaySound(soundUpgrading); } float buildDuration = GetBuildDuration(level + (isUpgrade ? 1 : 0)); constructDuration = buildDuration; constructRemained = buildDuration; effectBuilding.Spawn(GetPos(), Quaternion.identity); AnimPlayConstruct(); TDTK.OnTowerConstructing(this); }
IEnumerator MineRoutine() { LayerMask maskTarget = 1 << TDTK.GetLayerCreep(); while (true) { if (!destroyed && !IsInConstruction()) { Collider[] cols = Physics.OverlapSphere(thisT.position, GetRange(), maskTarget); if (cols.Length > 0) { List <Unit> targetList = TDTK.GetUnitInRange(thisT.position, GetAOERadius(), maskTarget); for (int i = 0; i < targetList.Count; i++) { AttackInstance attInstance = new AttackInstance(this, targetList[i]); attInstance.Process(); targetList[i].ApplyEffect(attInstance); } SpawnEffectObject(); Destroyed(); } } yield return(new WaitForSeconds(0.1f)); } }
public static void StartReload(FPSWeapon weap) { if (instance.currentWeapon == weap) { //if(onFPSReloadE!=null) onFPSReloadE(true); TDTK.OnFPSReload(true); } }
public static void SpendRsc(int value) { instance.rsc -= value; if (value != 0) { TDTK.OnPerkRscChanged(instance.rsc); } }
void Awake(){ if(instance!=null){ Destroy(gameObject); return; } instance=this; }
public static void ReloadComplete(FPSWeapon weap) { if (instance.currentWeapon == weap) { //if(onFPSReloadE!=null) onFPSReloadE(false); TDTK.OnFPSReload(false); } }
public static void MultiplyRscCap(float mul) { int gain = (int)Mathf.Round(instance.rscCap * mul) - instance.rscCap; instance.rsc += gain; instance.rscCap += gain; TDTK.OnAbilityRscChanged(instance.rsc); }
public static void GainRsc(int value) { if (instance == null) { return; } instance.rsc += value; TDTK.OnAbilityRscChanged(instance.rsc); }
public static void ModifyRscCap(int value) { instance.rscCap += value; if (value > 0) { instance.rsc += value; } instance.rsc = Mathf.Min(instance.rsc, instance.rscCap); TDTK.OnAbilityRscChanged(instance.rsc); }
void Awake() { if (instance != null) { Destroy(gameObject); return; } instance = this; }
public void _GainLife(int value) { playerLife += value; if (capLife) { playerLife = Mathf.Min(playerLife, GetPlayerLifeCap()); } //if(onLifeE!=null) onLifeE(value); TDTK.OnLife(value); }
public void Init() { instance = this; thisT = transform; if (startWithFullEnergy) { energy = fullEnergy; } List <Ability> dbList = TDTK.GetAbilityDBList(); //AbilityDB.Load(); availableIDList = new List <int>(); abilityList = new List <Ability>(); for (int i = 0; i < dbList.Count; i++) { if (dbList[i].disableInAbilityManager) { continue; } if (!unavailableIDList.Contains(dbList[i].ID)) { abilityList.Add(dbList[i].Clone()); availableIDList.Add(dbList[i].ID); } } List <Ability> newList = PerkManager.GetUnlockedAbilityList(); for (int i = 0; i < newList.Count; i++) { abilityList.Add(newList[i].Clone()); } for (int i = 0; i < abilityList.Count; i++) { abilityList[i].Init(); } if (defaultIndicator != null) { defaultIndicator = (Transform)Instantiate(defaultIndicator); defaultIndicator.parent = thisT; defaultIndicator.gameObject.SetActive(false); } maskAOE = 1 << TDTK.GetLayerPlatform(); int terrainLayer = TDTK.GetLayerTerrain(); if (terrainLayer >= 0) { maskAOE |= 1 << terrainLayer; } }
//called when unit take damage void DamageHP(float dmg) { HP -= dmg; new TextOverlay(GetTextOverlayPos(), dmg.ToString("f0"), new Color(1f, 1f, 1f, 1f)); TDTK.OnUnitDamaged(this); PlayAnimHit(); currentHPStagger = HPStaggerDuration; currentShieldStagger = shieldStaggerDuration; }
public void _OnCreepReachDestination(UnitCreep unit) { playerLife = Mathf.Max(0, playerLife - unit.lifeCost); TDTK.OnLife(-unit.lifeCost); if (playerLife <= 0) { GameOver(); } }
public IEnumerator CooldownRoutine() { currentCD = GetCooldown(); while (currentCD > 0) { currentCD -= Time.deltaTime; yield return(null); } TDTK.OnAbilityReady(this); }
public void Init() { wpSectionList = new List <WPSection>(); for (int i = 0; i < wpList.Count; i++) { Transform wpT = wpList[i]; //check if this is a platform, BuildManager would have add the component and have them layered if (wpT != null) { WPSection section = new WPSection(wpT); if (wpT.gameObject.layer == TDTK.GetLayerPlatform()) { section.isPlatform = true; section.platform = wpT.gameObject.GetComponent <PlatformTD>(); section.pathIDOnPlatform = section.platform.AddSubPath(this, i, wpList[i - 1], wpList[i + 1]); if (isLinearPath) { isLinearPath = false; } } else { WPSubPath wpSubPath = wpT.gameObject.GetComponent <WPSubPath>(); if (wpSubPath != null) { section.SetPosList(new List <Vector3>(wpSubPath.posList)); } else { section.SetPosList(new List <Vector3> { wpT.position }); } } wpSectionList.Add(section); } else { wpList.RemoveAt(i); i -= 1; } } if (loop) { loopPoint = Mathf.Min(wpList.Count - 1, loopPoint); //looping must be 1 waypoint before the destination } }
//Add Cash public void AddCash() { //自動增加資源的程式,取當前的值然後+上一個值在更新 int money; money = m_RscManager.rscList [0]; m_RscManager.rscList = new List <int> { money + 1, 1 }; //更新目前前導核心(包含UI) TDTK.OnRscChanged(m_RscManager.rscList); }
public static void GainRsc(int value) { if (instance == null) { return; } instance.rsc += value; if (value != 0) { TDTK.OnPerkRscChanged(instance.rsc); } }
public override void Destroyed(float delay = 0) { if (destroyed) { return; } destroyed = true; TDTK.OnUnitTowerDestroyed(this); RemoveFromGame(); }
public virtual void OnEnemyThrough(TDTK.UnitCreep u) { }