private void Start() { Transform enemyTransformHead = this.gameObject.transform.GetChild(0); GameObject player = GameObject.FindGameObjectWithTag("Player"); Transform playerTransform = player.transform; NavMeshAgent navAgent = GetComponentInChildren<NavMeshAgent>(); EnemyStats enemyStats = this.gameObject.GetComponent<EnemyStats>(); PlayerStats playerStatsScript = player.GetComponent<PlayerStats>(); if (enemySelection == EnemySelection.OffensiveTank) { // Offensive Tank behavior enemyAI = new OffensiveTank(enemyTransformHead, playerTransform, navAgent, enemyStats, playerStatsScript); } else if (enemySelection == EnemySelection.DefensiveTank) { // Defensive Tank behavior enemyAI = new DefensiveTank(enemyTransformHead, playerTransform, navAgent, enemyStats, playerStatsScript); } else { // Default AI, Offensive Tank enemyAI = new OffensiveTank(enemyTransformHead, playerTransform, navAgent, enemyStats, playerStatsScript); } enemyAI.melee = melee; enemyAI.attackRange = attackRange; enemyAI.chaseRange = chaseRange; enemyAI.damping = damping; enemyAI.fearFactor = fearFactor; enemyAI.lookRange = lookRange; enemyAI.lowHealth = lowHealth; enemyAI.thresholdRangeToFlee = thresholdRangeToFlee; }
public void AI_MjesovitaSimulacijaIspravnoDajeTaktike() { AITemplate ai = AIFactory.DajAI(); ai.Initialize(10, 10, new int[] { 2, 3, 3, 4 }); Polje p = ai.Gadjaj(); Assert.IsInstanceOfType(ai.Taktika, typeof(TaktikaNapipavanjeRazmak)); ai.ObradiPogodak(rezultatGadjanja.promasaj); p = ai.Gadjaj(); Assert.IsInstanceOfType(ai.Taktika, typeof(TaktikaNapipavanjeRazmak)); ai.ObradiPogodak(rezultatGadjanja.pogodak); p = ai.Gadjaj(); Assert.IsInstanceOfType(ai.Taktika, typeof(TaktikaTrazenjeSmjeraRazmak)); ai.ObradiPogodak(rezultatGadjanja.promasaj); p = ai.Gadjaj(); Assert.IsInstanceOfType(ai.Taktika, typeof(TaktikaTrazenjeSmjeraRazmak)); ai.ObradiPogodak(rezultatGadjanja.pogodak); p = ai.Gadjaj(); Assert.IsInstanceOfType(ai.Taktika, typeof(TaktikaUnistavanjeRazmak)); ai.ObradiPogodak(rezultatGadjanja.promasaj); p = ai.Gadjaj(); Assert.IsInstanceOfType(ai.Taktika, typeof(TaktikaTrazenjeSmjeraRazmak)); ai.ObradiPogodak(rezultatGadjanja.pogodak); p = ai.Gadjaj(); Assert.IsInstanceOfType(ai.Taktika, typeof(TaktikaUnistavanjeRazmak)); ai.ObradiPogodak(rezultatGadjanja.potopljen); p = ai.Gadjaj(); Assert.IsInstanceOfType(ai.Taktika, typeof(TaktikaNapipavanjeRazmak)); }
public override void Hit(AITemplate enemy, bool fromPrebuilt, GameObject bullet, int hitCount, bool exploded = false) { if (!exploded) { Explosion explosionInst = Instantiate(explosion, bullet.transform.position, Quaternion.identity); explosionInst.turret = this; Destroy(bullet); } else { if (enemy.hp > 0) { enemy.hp -= turretValues.dmg; //Decrease Enemy Health Upon Hit enemy.ResetTimer(); if (enemy.hp <= 0) { int addedMana = (int)(enemy.manaDrop * manaReturnPerc); manaSys.ManaAdd(addedMana, transform.position, 10); AudioSource source = enemy.GetComponent <AudioSource>(); ManaSystem.inst.audioLibrary.PlayAudio(ManaSystem.inst.audioLibrary.skeletonDeath, audioSource); enemies.Remove(enemy); if (closestEnemy == enemy) { closestEnemy = null; } Destroy(enemy.gameObject); } } } }
protected virtual void Update() { //Check for closest Enemy if it is not assigned if (closestEnemy == null) { closestEnemy = EnemyToLookAt(); } if (closestEnemy != null) { LookAtEnemy(); if (turretGO.transform.rotation != Quaternion.Euler(designatedAngle)) { if (ManaSystem.gameStateS == GameStates.started || ManaSystem.gameStateS == GameStates.afterWin) { turretGO.transform.rotation = Quaternion.RotateTowards(turretGO.transform.rotation, Quaternion.Euler(designatedAngle), 5f); } } } coolDown = Mathf.Max(coolDown -= Time.deltaTime, 0); if (coolDown <= 0) { float angleDiff = Mathf.Abs(designatedAngle.z - turretGO.transform.eulerAngles.y) % 360; //Compare with y since z rotation checks the euler of y if (angleDiff <= 20) { Shoot(arcTravel); //If the angle difference is minimal, then allow to shoot } } //if (Input.GetMouseButtonDown(0)) ManaSystem.inst.audioLibrary.PlayAudio (ManaSystem.inst.audioLibrary.build, audioSource); //kevins enjoyment }
void OnTriggerExit(Collider other) { if (other.tag == "AI") { enemies.Remove(other.GetComponent <AITemplate>()); closestEnemy = EnemyToLookAt(); } }
public void AIRazmak_GadjajDajePoljeUnutarMreze() { AITemplate ai = AIFactory.DajAI(); ai.Initialize(10, 10, new int[] { 4 }); ai.Gadjaj(); Assert.IsTrue(ai.Mreza.polja.Contains(ai.zap.gadjanoPolje)); }
public void AI_ObradiPogodakIspravnoRadiZaPromasaj() { AITemplate ai = AIFactory.DajAI(); ai.Initialize(10, 10, new int[] { 1, 2, 3, 3, 4 }); ai.Gadjaj(); ai.ObradiPogodak(rezultatGadjanja.promasaj); Assert.IsTrue(ai.zap.trenutnaMeta.Count == 0); Assert.IsFalse(ai.Mreza.polja.Contains(ai.zap.gadjanoPolje)); }
public void AI_IzvaziMjerenjeBrzine() { // zanima nas samo brzina izvrsavanja testa AIFactory.Pravila = PravilaIgre.DodirivanjeZabranjeno; int[] duljine = new int[] { 4, 3, 2, 1 }; AITemplate ai = AIFactory.DajAI(); ai.Initialize(10, 10, duljine); ai.Izvazi(); }
public void AI_NakonPotapanjaTaktikaJeNapipavanje() { AITemplate ai = AIFactory.DajAI(); ai.Initialize(10, 10, new int[] { 2, 3, 3, 4 }); Polje p = ai.Gadjaj(); ai.ObradiPogodak(rezultatGadjanja.potopljen); p = ai.Gadjaj(); Assert.IsInstanceOfType(ai.Taktika, typeof(TaktikaNapipavanjeRazmak)); }
public void AI_InitializeIspravnoPostavljaParametre() { AITemplate ai = AIFactory.DajAI(); ai.Initialize(5, 5, new int[] { 2, 3, 3, 4 }); Assert.IsTrue(((List <Polje>)ai.Mreza.DajSlobodnaPolja()).Count == 25); Assert.IsTrue(ai.Flota.Count == 4); Assert.IsTrue(ai.Flota.Contains(2)); Assert.IsTrue(ai.Flota.FindAll(x => x == 3).Count == 2); Assert.IsTrue(ai.Flota.Contains(4)); }
public void AI_NakonPrvogPogotkaTaktikaJeTrazenjeSmjera() { AITemplate ai = AIFactory.DajAI(); ai.Initialize(10, 10, new int[] { 2, 3, 3, 4 }); Polje p = ai.Gadjaj(); ai.ObradiPogodak(rezultatGadjanja.pogodak); p = ai.Gadjaj(); Assert.IsInstanceOfType(ai.Taktika, typeof(TaktikaTrazenjeSmjeraRazmak)); }
public void AIFactoryIspravnoDajeAIZaPravila() { AITemplate ai = AIFactory.DajAI(); Assert.IsInstanceOfType(ai, typeof(AIRazmak)); AIFactory.Pravila = PravilaIgre.DodirivanjeDozvoljeno; AITemplate a1 = AIFactory.DajAI(); Assert.IsInstanceOfType(a1, typeof(AIDodirivanje)); AIFactory.Pravila = PravilaIgre.DodirivanjeZabranjeno; AITemplate a2 = AIFactory.DajAI(); Assert.IsInstanceOfType(a2, typeof(AIRazmak)); }
void Act() { if (Character.Available) { Timer.RunTimerOnce(AI_ACTION_DELAY, () => { if (!AITemplate.ConsiderCastingAbility(Character)) { Character.UnlistenToAvailable(Act); onCompleteAction.Invoke(); } }); } }
public void AIRazmak_GadjajNakonPogotkaDajePoljeDoGadjanogPolja() { AITemplate ai = AIFactory.DajAI(); ai.Initialize(10, 10, new int[] { 4 }); ai.Gadjaj(); Polje prvoPolje = ai.zap.gadjanoPolje; ai.ObradiPogodak(rezultatGadjanja.pogodak); ai.Gadjaj(); Polje drugoPolje = ai.zap.gadjanoPolje; Assert.IsTrue((prvoPolje.Redak == drugoPolje.Redak && Math.Abs(prvoPolje.Stupac - drugoPolje.Stupac) == 1) || (prvoPolje.Stupac == drugoPolje.Stupac && Math.Abs(prvoPolje.Redak - drugoPolje.Redak) == 1)); }
public void AI_IzvaziIspravnoRacunaTezinuZaStupac() { AITemplate ai = AIFactory.DajAI(); ai.Initialize(5, 1, new int[] { 4 }); ai.Izvazi(); foreach (Polje p in ai.Mreza.polja) { if (p.Redak > 0 && p.Redak < 4) { Assert.IsTrue(p.Tezina == 2); } else { Assert.IsTrue(p.Tezina == 1); } } }
public void StartAction() { if (!Character.Available) { onCompleteAction.Invoke(); return; } // Listen for when the character is available again Character.ListenToAvailable(Act); // Prompts the character to do something. After which they will become unavailable // while doing it, and then become available again if (!AITemplate.ConsiderRepositioning(Character)) { Act(); } }
public void AIRazmak_GadjajNakonDvaPogotkaNastavljaSustavnoGadjatiUIstomSmjeru() { AITemplate ai = AIFactory.DajAI(); ai.Initialize(10, 10, new int[] { 4 }); ai.Gadjaj(); Polje prvoPolje = ai.zap.gadjanoPolje; ai.ObradiPogodak(rezultatGadjanja.pogodak); ai.Gadjaj(); Polje drugoPolje = ai.zap.gadjanoPolje; ai.ObradiPogodak(rezultatGadjanja.pogodak); ai.Gadjaj(); Polje trecePolje = ai.zap.gadjanoPolje; Assert.IsTrue((prvoPolje.Redak == trecePolje.Redak && Math.Abs(prvoPolje.Stupac - trecePolje.Stupac) == 2) || (prvoPolje.Stupac == trecePolje.Stupac && Math.Abs(prvoPolje.Redak - trecePolje.Redak) == 2)); }
private void OnTriggerEnter(Collider other) { if (other.tag == "AI") { AITemplate enemy = other.GetComponentInParent <AITemplate> (); if (enemies.Contains(null)) { enemies.RemoveAll(AI => AI == null); } foreach (AttackType attackType in turretValues.attackType) { if (attackType == enemy.enemyType) { enemies.Add(enemy); closestEnemy = EnemyToLookAt(); break; //Get out of loop once enemy is added } } } }
public void AIRazmak_GadjajNakonPogotkaIPromasajaJosUvijekDajePoljeDoGadjanogPolja() { AITemplate ai = AIFactory.DajAI(); ai.Initialize(10, 10, new int[] { 4 }); ai.Gadjaj(); Polje prvoPolje = ai.zap.gadjanoPolje; ai.ObradiPogodak(rezultatGadjanja.pogodak); ai.Gadjaj(); Polje drugoPolje = ai.zap.gadjanoPolje; ai.ObradiPogodak(rezultatGadjanja.promasaj); ai.Gadjaj(); Polje trecePolje = ai.zap.gadjanoPolje; Assert.IsTrue((prvoPolje.Redak == trecePolje.Redak && Math.Abs(prvoPolje.Stupac - trecePolje.Stupac) == 1) || (prvoPolje.Stupac == trecePolje.Stupac && Math.Abs(prvoPolje.Redak - trecePolje.Redak) == 1)); Assert.AreNotEqual(prvoPolje, drugoPolje); }
public void AIRazmak_EliminirajBrodIspravnoEliminiraPoljaZaBrodUUglu() { AITemplate ai = AIFactory.DajAI(); ai.Initialize(10, 10, new int[] { 4 }); Brod b = new Brod(new List <Polje>() { new Polje(0, 0), new Polje(0, 1), new Polje(0, 2), new Polje(0, 3) }); List <Polje> prosireniBrod = new List <Polje>(); ai.EliminirajBrod(b.Polja); prosireniBrod = b.Polja; prosireniBrod.Add(new Polje(1, 0)); prosireniBrod.Add(new Polje(1, 1)); prosireniBrod.Add(new Polje(1, 2)); prosireniBrod.Add(new Polje(1, 3)); prosireniBrod.Add(new Polje(0, 4)); Assert.IsFalse(prosireniBrod.Intersect(ai.Mreza.DajSlobodnaPolja()).Any()); }
private void btnFight_Click(object sender, EventArgs e) { // na pocetku ukloni stare flote ako postoje if (mojaFlotaGUI != null) { this.Controls.Remove(mojaFlotaGUI); } if (protivnikFlotaGUI != null) { this.Controls.Remove(protivnikFlotaGUI); } BrodograditeljTemplate brodograditelj = BrodograditeljFactory.DajBrodograditelja(); int[] duljine = SastaviListuBrodova(); int redaka = (int)numRedaka.Value; int stupaca = (int)numStupaca.Value; flota = brodograditelj.SloziFlotu(redaka, stupaca, duljine); mojaFlotaGUI = new FlotaGUI(redaka, stupaca); mojaFlotaGUI.sirina = 250; mojaFlotaGUI.Location = new Point(20, 170); mojaFlotaGUI.ZadajFlotu(flota); this.Controls.Add(mojaFlotaGUI); protivnikFlotaGUI = new FlotaNeprijatelj(redaka, stupaca); protivnikFlotaGUI.sirina = 250; protivnikFlotaGUI.Location = new Point(370, 170); this.Controls.Add(protivnikFlotaGUI); ai = AIFactory.DajAI(); ai.Initialize(redaka, stupaca, duljine); // iniciraj protivnika protivnik = new OOMPotapanje.Protivnik(redaka, stupaca, duljine); // zapocni igru ProgressChangedEventArgs x; bgWorker.RunWorkerAsync(); }
/// <summary> /// Checks which is its closests enemy /// Only checks when /// 1. A new enemy enters its range /// 2. An enemy exits its range /// 3. When the Enemy Count is > 0 and Closest Enemy is null /// </summary> protected AITemplate EnemyToLookAt() { AITemplate enemyToLookAt = null; //Remove any "Enemy" from list if the Enemy Reference is not present enemies = enemies.Where(AI => AI != null).ToList(); //if (enemies.Contains(null)) enemies.RemoveAll(AI => AI == null); if (enemies.Count > 0) { float shortestDist = Mathf.Infinity; int index = 0; //print ("=========================================================================="); for (int i = 0; i < enemies.Count; i++) { //For attacking enemies closest to Townhall float enemyDistance = enemies[i].CheckDistance(); //print ("Index " + i + ": " + enemyDistance); if (enemyDistance < shortestDist) { shortestDist = enemyDistance; index = i; enemyToLookAt = enemies[index]; //print ("i updated"); } //For attacking enemies closest to Turret /*if ((transform.position - enemies[i].transform.position).magnitude < distance) * { * distance = (transform.position - enemies[i].transform.position).magnitude; * //index = i; * }*/ } //Vector3 direction = enemies[index].enemyType == AttackType.air ? -(transform.position - enemies[index].transform.GetChild(0).position).normalized : -(transform.position - enemies[index].transform.position).normalized; } return(enemyToLookAt); }
public void AIRazmak_EliminirajBrodIspravnoEliminiraPolja() { AITemplate ai = AIFactory.DajAI(); ai.Initialize(10, 10, new int[] { 4 }); Brod b = new Brod(new List <Polje>() { new Polje(4, 4), new Polje(4, 5), new Polje(4, 6), new Polje(4, 7) }); List <Polje> prosireniBrod = new List <Polje>(); ai.EliminirajBrod(b.Polja); foreach (Polje p in b.Polja) { prosireniBrod.Add(p); prosireniBrod.Add(new Polje(p.Redak, p.Stupac + 1)); prosireniBrod.Add(new Polje(p.Redak, p.Stupac - 1)); prosireniBrod.Add(new Polje(p.Redak + 1, p.Stupac)); prosireniBrod.Add(new Polje(p.Redak - 1, p.Stupac)); } Assert.IsFalse(prosireniBrod.Intersect(ai.Mreza.DajSlobodnaPolja()).Any()); }
public virtual void onDialog(L2Player player, int ask, int reply) { player.FolkNpc = this; AIProcessor.TalkedReply(player, ask, reply); return; if (ask > 0 && ask < 1000) { QuestManager.getInstance().onQuestTalk(player, this, ask, reply); return; } AITemplate t = AIManager.getInstance().checkDialogResult(Template.NpcId); if (t != null) { t.onDialog(player, ask, reply, this); return; } switch (ask) { case -1: switch (reply) { case 8: player.sendPacket(new ExBuySellList_Buy(player.getAdena())); player.sendPacket(new ExBuySellList_Sell(player)); break; default: NpcData.getInstance().buylist(player, this, (short)reply); break; } break; case -3: grandmaster_total.onReply(player, reply, this); break; case -19: //нобл запрос switch (reply) { case 0: case 1: player.ShowHtm(player.Noblesse == 1 ? "fornobless.htm" : "fornonobless.htm", this); break; } break; case -20: //нобл запрос switch (reply) { case 2: NpcData.getInstance().RequestTeleportList(this, player, 2); break; } break; case -21: //нобл запрос switch (reply) { case 2: NpcData.getInstance().RequestTeleportList(this, player, 3); break; } break; case -22: //нобл запрос switch (reply) { case 2: NpcData.getInstance().RequestTeleportList(this, player, 1); break; } break; case -303: MultiSell.getInstance().showList(player, this, reply); break; case -305: switch (reply) { case 1: // NpcData.getInstance().multisell(player, this, reply); //TEST break; } break; case -1000: { switch (reply) { case 1: //See the lord and get the tax rate information break; } } break; } }
protected virtual void Shoot(bool arcTravel) { //Remove any "Enemy" from list if the Enemy Reference is not present enemies = enemies.Where(AI => AI != null).ToList(); if (closestEnemy == null) { closestEnemy = EnemyToLookAt(); } if (enemies.Count > 0) { Vector3 direction = closestEnemy.enemyType == AttackType.air ? -(transform.position - closestEnemy.transform.GetChild(0).position).normalized : new Vector3(transform.position.x - closestEnemy.transform.position.x, 0, transform.position.z - closestEnemy.transform.position.z).normalized * -1; Vector3 direction2D = new Vector3(direction.x, 0, direction.z); Bullet currentBullet = Instantiate(BulletSelect(level), turretGO.transform); currentBullet.transform.localPosition = turretValues.firingPos; currentBullet.transform.parent = null; //print(currentBullet.name); currentBullet.turret = this; //For Audio if (turretType == typeof(Cannon)) { ManaSystem.inst.audioLibrary.PlayAudio(ManaSystem.inst.audioLibrary.cannon, audioSource); Particles effects = Instantiate(shootingEffects, turretGO.transform); effects.transform.localPosition = turretValues.firingPos; effects.transform.eulerAngles = Vector3.zero; effects.transform.parent = null; //print (turretValues.firingPos); } else if (turretType == typeof(Catapult)) { ManaSystem.inst.audioLibrary.PlayAudio(ManaSystem.inst.audioLibrary.catapult, audioSource); } else if (turretType == typeof(Crossbow)) { ManaSystem.inst.audioLibrary.PlayAudio(ManaSystem.inst.audioLibrary.crossbow, audioSource); } else if (turretType == typeof(Rockets)) { ManaSystem.inst.audioLibrary.PlayAudio(ManaSystem.inst.audioLibrary.rocket, audioSource); } else { print("Error in Getting Correct Audio Source"); } if (arcTravel) { currentBullet.speed = turretValues.bulletSpeed; currentBullet.amplitude = amplitude; currentBullet.target = closestEnemy.transform.position; currentBullet.frequency1 = currentBullet.transform.position.x - currentBullet.target.x > 0 ? currentBullet.transform.position.x - currentBullet.target.x : -(currentBullet.transform.position.x - currentBullet.target.x); currentBullet.catapult = true; currentBullet.currentY = turretValues.firingPos.y; currentBullet = null; } else { currentBullet.catapult = false; currentBullet.velocity = direction * turretValues.bulletSpeed; } coolDown = 1 / turretValues.fireRate; //print ("Shortest: " + shortestDist); } else { return; } }