void updateSection() { if (!PhotonNetwork.isMasterClient) { print("not master"); return; } if (TotalEnemiesPool > 0) { //if there's any enemy left, spawn if (AIStatusHandler.Get_PVs(true).Count < _enemiesAtOnce) { int aiToSpawn = Mathf.Clamp(_enemiesAtOnce - AIStatusHandler.Get_PVs(true).Count, 0, Mathf.Min(TotalEnemiesPool, 4)); _NPCSpawners.Shuffle(); foreach (var s in _NPCSpawners) { //Spawn if ready if (s.IsAvailable && aiToSpawn > 0) { // print ("current alive AIs : " + AIStatusHandler.Get_PVs (true).Count + ", spawning : " + aiToSpawn); s.Spawn(aiToSpawn); //deduct once spawned TotalEnemiesPool -= aiToSpawn; return; } } } } else { // print ("pool empty"); EndEvent(); } }
virtual protected void Start() { _pv = PhotonView.Get(this); _ais = GetComponent <AIScanner> (); _aimh = GetComponent <AIMovementHandler> (); _aish = GetComponent <AIStatusHandler> (); _ch = GetComponent <CombatHandler> (); }
protected override void checkCondition() { if (_spawner.TotalEnemiesPool < 1 && AIStatusHandler.Get_PVs(true).Count <= _AIAliveCount) { //condition met // print ("enemy count < 1"); triggerNext(); } else { // print (_spawner.TotalEnemiesPool + ", " + AIStatusHandler.Get_PVs (true).Count); } }
/// <summary> /// Called after switching to a new MasterClient when the current one leaves. /// </summary> /// <remarks>This is not called when this client enters a room. /// The former MasterClient is still in the player list when this method get called.</remarks> /// <param name="newMasterClient">New master client.</param> public override void OnMasterClientSwitched(PhotonPlayer newMasterClient) { base.OnMasterClientSwitched(newMasterClient); // print ("Master switched, otherplayercount : " + PhotonNetwork.otherPlayers.Length); //transfer ownerhsip of this AI to the new master foreach (var pv in AIStatusHandler.Get_PVs()) { pv.TransferOwnership(newMasterClient); print("Ownership transferred"); } // } }
/// <summary> /// Updates the dynamic AI numbers.(needs testing, note : add it after character death?, needs to be network synced?) /// </summary> public static void UpdateDynamicAINumbers() { _dynamicAINumbers.Clear(); foreach (PhotonView p in AIStatusHandler.Get_ALL_PVs(true)) { if (p.GetComponent <UnitComponent> () == null) { Debug.LogWarning("WARNING : AIStatusHandler without UnitComponent"); continue; } else { _dynamicAINumbers.Add((DynamicAINumber)p.GetComponent <UnitComponent> ().attributes.value); } } }
/// /// <summary> /// Gets the list of enemies searched from photonview list /// </summary> /// <returns>The enemies.</returns> /// <param name="ofTeam">Of team.</param> /// <param name="checkAlive">If set to <c>true</c> check alive.</param> public static List <CombatHandler> GET_ENEMIES(TEAM ofTeam, bool checkAlive = false) { List <CombatHandler> enemies = new List <CombatHandler> (); foreach (var p in AIStatusHandler.Get_ALL_PVs(checkAlive)) { CombatHandler ch = p.GetComponent <CombatHandler> (); if (ch != null) { //check if enemy if (ofTeam != ch.GetTeam()) { enemies.Add(ch); } } else { Debug.LogWarning("WARNING : this photonview must have combathandler as its component"); } } return(enemies); }