public void Update() { foreach (var it in owner.skills) { it.Update(AILogic.GetHpPercentage(owner)); } }
public void Awake() { // See if this player is an AI aiLogic = GetComponent <AILogic>(); if (aiLogic != null) { isAI = true; } else // Just in case somehow the initial false set doesn't work { isAI = false; } // On awake, set mana to 0 so that when a turn is activated it can increase the mana CurrentMana = 0; MaxMana = 0; Health = 40; // Set alignment to 0 CurrentAlignment = 0; // Assign players with ID (using find objects as there will only be two player scripts attached) players = GameObject.FindObjectsOfType <Player>(); // Give the players an ID (1 + 2) PlayerID = IDCreator.GetUniqueID(); // set starting health }
public void OnSpawn(Enemy enemy) { Enemies = SceneManager.GetCurrentScene().GetEntities <Enemy>(); Player player = SceneManager.GetCurrentScene().GetEntity <Player>("Player"); AILogicCMD = new AILogic(enemy); ProjectileSpawner = new ProjectileSpawner(ProjectileSprite, this); }
public override IEnumerator StartMyActivationCoroutine() { Ability strike = mySpellBook.GetAbilityByName("Strike"); Ability move = mySpellBook.GetAbilityByName("Move"); Ability layBroodlingEgg = mySpellBook.GetAbilityByName("Lay Broodling Egg"); ActionStart: SetTargetDefender(GetClosestDefender()); if (IsAbleToTakeActions() == false) { EndMyActivation(); } // Lay Broodling Egg else if (HasEnoughAP(currentAP, layBroodlingEgg.abilityAPCost) && IsAbilityOffCooldown(layBroodlingEgg.abilityCurrentCooldownTime)) { StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Lay Broodling Egg", false)); yield return(new WaitForSeconds(0.5f)); Action layEgg = AbilityLogic.Instance.PerformLayBroodlingEgg(this); yield return(new WaitUntil(() => layEgg.actionResolved == true)); yield return(new WaitForSeconds(1f)); goto ActionStart; } // Strike else if (IsTargetInRange(myCurrentTarget, currentMeleeRange) && HasEnoughAP(currentAP, strike.abilityAPCost)) { StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Strike", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformStrike(this, myCurrentTarget); // brief delay between actions yield return(new WaitForSeconds(1f)); goto ActionStart; } // Move else if (IsTargetInRange(myCurrentTarget, currentMeleeRange) == false && IsAbleToMove() && HasEnoughAP(currentAP, move.abilityAPCost)) { StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Move", false)); yield return(new WaitForSeconds(0.5f)); TileScript destination = AILogic.GetBestValidMoveLocationBetweenMeAndTarget(this, myCurrentTarget, currentMeleeRange, currentMobility); Action action = AbilityLogic.Instance.PerformMove(this, destination); yield return(new WaitUntil(() => action.ActionResolved() == true)); // small delay here in order to seperate the two actions a bit. yield return(new WaitForSeconds(1f)); goto ActionStart; } EndMyActivation(); }
void StateMachine() { distanceToPlayer = Vector3.Distance(transform.position, target.position); // Debug.Log(distanceToPlayer); switch (States) { case AILogic.PATROL: AIMove(transform.position, targetPos, translateSpeed / 1.5f,true); SpriteReposition(); break; case AILogic.WAIT: gameTimer += Time.deltaTime; if(gameTimer>waitTime) { gameTimer = 0f; States = AILogic.PATROL; } break; case AILogic.MOVETOPLAYER: gameTimer += Time.deltaTime; AIMove(transform.position,target.position,translateSpeed); SpriteReposition(); //logic for repositioning the sprite //Let's the sprite blink back and forth booSprite.color = new Color(1, 0, 0, (Mathf.PingPong(Time.time / 2, 1 - 0))); if (gameTimer > 3f) { ResetAI(); gameTimer = 0; } break; case AILogic.RUNFROMPLAYER: AIMove(target.position, transform.position,translateSpeed*5); booSprite.color = new Color(1, 1, 1,(Mathf.Lerp(1, 0, _t / 1))); if (fadeAway) { _t += Time.deltaTime; if (_t / 1 > 1) { _t = 0; ResetAI(); gameObject.SetActive(false); fadeAway = false; } } break; } if (distanceToPlayer < aggroRange && States!=AILogic.RUNFROMPLAYER) { States = AILogic.MOVETOPLAYER; //ResetAI(); } }
//------------------------------------------------------------------------------------------------------------------------ void Awake() { // Setting up the references. photonView = GetComponent <PhotonView> (); anim = transform.root.gameObject.GetComponent <Animator> (); AICtrl = transform.root.GetComponent <AIControl> (); atcpro = GetComponent <AttackedProperties> (); ailo = GetComponent <AILogic> (); //Set to default weapon: BareHand weaponInHeld = "BareHand"; }
public void MoveAI_Test() { AILogic ai = new AILogic(); float speed = 6.5f; Assert.That(ai.MoveAI(-0.7f, speed), Is.EqualTo(-speed)); float speed2 = 3.45f; Assert.That(ai.MoveAI(0.6f, speed2), Is.EqualTo(speed2)); Assert.That(ai.MoveAI(0.3f, 7.5f), Is.EqualTo(0)); }
public void gainFlag() { flag = GameObject.FindGameObjectWithTag("Flag"); flag.GetComponent <Animator> ().SetBool("Wavin", true); Collider2D[] cols = flag.GetComponents <Collider2D> (); //deactivate rigidbody component Rigidbody2D rb = flag.GetComponent <Rigidbody2D> (); rb.gravityScale = 0; rb.freezeRotation = false; rb.isKinematic = true; flag.transform.parent = flagPos.transform; foreach (Collider2D coll in cols) { coll.enabled = false; } PhotonView flagPhotonView = flag.GetComponent <PhotonView> (); if (gameObject.GetPhotonView().isMine) { flagPhotonView.RequestOwnership(); } flag.transform.localPosition = Vector3.zero; flag.transform.localRotation = Quaternion.Euler(Vector3.zero); if (PhotonNetwork.offlineMode) { GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); foreach (GameObject ply in players) { AILogic ailog = ply.GetComponent <AILogic> (); if (ailog) { if (ply == this.gameObject) { ailog.StateChange(3); } else { ailog.StateChange(2); } } } } isHandlingFlag = true; arrow.GetComponent <FixedRotation> ().isHandling = true; }
void DrawForClass() { AILogic fow = (AILogic)target; Handles.color = Color.blue; Handles.DrawWireArc(fow.transform.position, Vector3.up, Vector3.forward, 360, fow.viewRadius); Vector3 viewAngleA = fow.DirFromAngle(-fow.viewAngle / 2, false); Vector3 viewAngleB = fow.DirFromAngle(fow.viewAngle / 2, false); Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleA * fow.viewRadius); Handles.DrawLine(fow.transform.position, fow.transform.position + viewAngleB * fow.viewRadius); Handles.color = Color.black; foreach (Transform visibleTarget in fow.possibleWaypoints) { Handles.DrawLine(fow.transform.position, visibleTarget.position); } }
public Enemy(Game game, Vector3 position, Entity entityToChase) : base(game) { addComponent(new Spatial(game, this, position)); getComponent<Spatial>().focus = Vector3.Forward + position; addComponent(new Drawable3D(game, this, Game.Content.Load<Model>(@"models\Plane3"))); addComponent(new Collidable(game, this, CollisionType.enemy, onHit, 50, 250,getComponent<Drawable3D>().modelBoundingBox)); addComponent(new Spatial2D(game, this, Vector2.Zero, new Vector2(1.0f, 1.0f))); addComponent(new Drawable2D(game, this, Game.Content.Load<Texture2D>(@"Textures\TrackingTriangle"),Color.Lime)); weapon = new Missiles(game, this); path = new PathingWander(Game, this, entityToChase, speed); addComponent(weapon); logic = joust; int type = ((Game1)Game).rnd.Next(0, 2); //int type = 0; switch (type) { case 0: logic = joust; break; case 1: logic = stayInFrontAndEvade; break; case 2: logic = wanderInFront; break; case 3: logic = kamiKaze; break; case 4: logic = chaseDown; break; default: break; } addComponent(path); targetToChase = entityToChase; enemyManager.add(this); }
private IEnumerator <CoroutinePhase> TimeAttack() { m_attackCycle++; yield return(Suspend.Do(skills[0].Cooltime())); if (null != CurrentTarget) { if (!skills[0].IsCooltime()) { if (AILogic.TargetDistance(this.transform, CurrentTarget) <= skills[0].SkillRange) { if (skills[0] != null) { //Debug.Log("공격"); WeaponPosition.transform.forward = (CurrentTarget.position - WeaponPosition.transform.position).normalized; AssetManager.Projectile.Retrieve(skills[0].SkillName, this.WeaponPosition, this.gameObject); skills[0].Reset(this); } } } } if (null != m_customPath) { if (m_attackCycle > m_customPath.m_nodes[m_customIndex].AttackCycle) { Move(); } else { Attack(); } } else { Attack(); } }
void OnTriggerEnter2D(Collider2D col) { // If the colliding gameobject is an Enemy... //&& col.gameObject != transform.parent.gameObject if (col.gameObject.tag == "Player" && col.gameObject != transform.parent.gameObject) //If the player is currently attackingg.... { if (AIAttack.isAttacking) { //send the col object flying // Create a vector that's from the enemy to the player with an upwards boost. col.gameObject.GetComponent <AttackedProperties> ().wasAttacked(photonView.viewID); PhotonNetwork.Instantiate("rocketExplosion", transform.position, Quaternion.identity, 0); AILogic ailo = col.gameObject.GetComponent <AILogic> (); if (ailo) { ailo.Attacked(this.gameObject); } AIAttack.isAttacking = false; //Vector3 hurtVector = col.gameObject.transform.position - GetComponentInParent<Transform>().position + Vector3.up * 5f; // Add a force to the player in the direction of the vector and multiply by the hurtForce. //col.gameObject.GetComponent<Rigidbody2D>().AddForce(hurtVector * hurtForce*10); } else { AIAttack.attack(); } } else if (col.gameObject.tag == "Pickable") //Destroy the pickable { if (AIAttack.isAttacking) { col.gameObject.GetComponent <PickableObject> ().DestroySelf(); AIAttack.isAttacking = false; } } }
void Start() { // if (isMine) { // PlayerPrefs.SetInt ("OwnerID", photonView.viewID); // print (gameObject.name + " is mine"); // } GetComponent <FlagHandling> ().isAI = true; atcpro = GetComponent <AttackedProperties> (); ailog = GetComponent <AILogic> (); atcpro.isAI = true; // InvokeRepeating ("AIRandomMove", 0f, 2f); seeker = GetComponent <Seeker>(); rb = GetComponent <Rigidbody2D>(); StartCoroutine("CheckError"); if (target == null) { //Debug.LogError ("No Player found? PANIC!"); return; } }
private void computerTurn() { AILogic ai = new AILogic(); Random rand = new Random(); int colToBeInserted = 0; int numOfCols = m_Game.GetNumOfCols(); //// Column choosed. colToBeInserted = ai.AIManager(this.m_Game); while (!ValidateColumn(colToBeInserted)) { /// Column choosed. /// We left the rand here, as a "Fail-Safe" procedure . please pay attion for this point. colToBeInserted = rand.Next(0, numOfCols); } //// only if a legal column....(have to a legal one at this point..^^^^) InsertChip(new Chip(ePlayerNum.Computer), colToBeInserted); Screen.Clear(); PrintBoard(); if (CheckForAWin(colToBeInserted, ePlayerNum.Computer, true)) { this.m_Game.IncreasePointsByOne(ePlayerNum.Computer); this.m_Game.LastRoundWinner = ePlayerNum.Computer; this.PrintGameStatus(); exitMenu(ePlayerNum.Player1); this.clearBoard(); } else { ////Tie - because if the other player has won - it should dealt in his turn. } }
public static DataTable Generar(List <Curso> cursos) { DataTable Listado = new DataTable(); Listado.Columns.Add("ID", typeof(int)); Listado.Columns.Add("AnioCalendario", typeof(int)); Listado.Columns.Add("Cupo", typeof(string)); Listado.Columns.Add("Curso", typeof(string)); Listado.Columns.Add("Materia", typeof(string)); Listado.Columns.Add("Comision", typeof(string)); Listado.Columns.Add("Plan", typeof(string)); List <Especialidad> especialidades = EspLogic.GetAll(); List <Plan> planes = PlanLogic.GetAll(); List <Materia> materias = MatLogic.GetAll(); List <Comision> comisiones = ComLogic.GetAll(); foreach (Curso cur in cursos) { DataRow Linea = Listado.NewRow(); Linea["ID"] = cur.ID; Linea["AnioCalendario"] = cur.AnioCalendario; Linea["Cupo"] = AILogic.GetCantCupo(cur.ID) + "/" + cur.Cupo; Comision com = comisiones.FirstOrDefault(x => x.ID == cur.IDComision); Linea["Comision"] = com.Descripcion; Materia materia = materias.FirstOrDefault(x => x.ID == cur.IDMateria); Linea["Materia"] = materia.Descripcion; Plan plan = planes.FirstOrDefault(x => x.ID == materia.IDPlan); Especialidad esp = especialidades.FirstOrDefault(x => x.ID == plan.IDEspecialidad); Linea["Plan"] = esp.Descripcion + " - " + plan.Descripcion; Linea["Curso"] = com.Descripcion + " - " + materia.Descripcion; Listado.Rows.Add(Linea); } return(Listado); }
public Game MakeMove(User user, GameAction action) { Game actualGame = _gameRepository.GetActualByUser(user.Id); actualGame.ProceedMapToLastState(); actualGame.PlayerMoves.Add(action.Normalize(actualGame)); actualGame.ProceedMapStep(actualGame.PlayerMoves.Last(), PlayerType.Player); actualGame.OpponentMoves.Add(AILogic.GenerateAction(actualGame.Map).Normalize(actualGame)); actualGame.ProceedMapStep(actualGame.OpponentMoves.Last(), PlayerType.AI); actualGame.UpdateResources(); if (actualGame.IsFinished || !actualGame.Map.Fields.Any(x => x.Owner == FieldOwner.AI) || !actualGame.Map.Fields.Any(x => x.Owner == FieldOwner.Player)) { actualGame.IsFinished = true; actualGame.Score = actualGame.ComputeScore(); _statRepository.Create(new Stats() { FinalGold = (int)actualGame.Map.Money, FinalGummies = (int)actualGame.Map.Fields.Where(x => x.Owner == FieldOwner.Player).Sum(x => x.GummiesNumber), GameId = actualGame.Id, MapId = actualGame.MapId, OverallScore = actualGame.Score, UserId = actualGame.UserId }); } else { ActionsLogic.GetPossibleActions(actualGame.Map); } _gameRepository.Update(actualGame); return(actualGame); }
private void computerTurn() { AILogic ai = new AILogic(); Random rand = new Random(); int colToBeInserted = 0; int numOfCols = m_GameManager.GetNumOfCols(); //// Column choosed. colToBeInserted = ai.AIManager(this.m_GameManager); // $G$ NTT-002 (-10) You shouldn't use while for game routin. WinForm project is events oriented. while (!ValidateColumn(colToBeInserted)) { /// Column choosed. /// We left the rand here, as a "Fail-Safe" procedure . please pay attion for this point. // $G$ DSN-002 (-20) No UI seperation! This class merge the Logic board with the Visual board (UserControl) of the game... colToBeInserted = rand.Next(0, numOfCols); } insertSelection(colToBeInserted, ePlayerNum.Computer); updateButtonsAvailability(); }
private void Button_Click(object sender, EventArgs e) { var btn = (Button)sender; var cord = (int[])btn.Tag; var res = logic.SetPlayer(btn, cord); ShowMessage(res); if (!logic.PlayerOneWalk && res == ResType.Nothing) { cord = AILogic.CordAI(logic, XOType.O, logic.Field); foreach (var cntrl in gameBoard.Controls) { if (cntrl is Button btnAI) { var btnCord = (int[])btnAI.Tag; if (btnCord[0] == cord[0] && btnCord[1] == cord[1]) { ShowMessage(logic.SetPlayer(btnAI, cord)); } } } } }
// Use this for initialization void Start() { hp = 30; // Hp of VIPs logic = transform.GetComponent <AILogic>(); CT = GameObject.Find("controller").GetComponent <Create_Teams> (); // the accessor for the list we need to remove VIPs from when they are destroyed }
public override void Update(GameTime gameTime) { if (targetToChase != null) { logic(gameTime); switchWeapons(); } lifeTime += gameTime.ElapsedGameTime.Milliseconds / 1000.0f; if (lifeTime > 30.0f) { path = null; logic = joust; lifeTime = float.MinValue; } Vector3 screenPos = getScreenPosition(); getComponent<Spatial2D>().position = new Vector2(screenPos.X, screenPos.Y); float zscale = 1.0f - (float)Math.Pow(screenPos.Z, 300); getComponent<Spatial2D>().scale = new Vector2(zscale); base.Update(gameTime); }
public override IEnumerator StartMyActivationCoroutine() { Ability strike = mySpellBook.GetAbilityByName("Strike"); Ability move = mySpellBook.GetAbilityByName("Move"); Ability dash = mySpellBook.GetAbilityByName("Dash"); Ability twinStrike = mySpellBook.GetAbilityByName("Twin Strike"); /* AI LOGIC * If enemy is in melee range and twin strike ready, twin strike * if enemy is in melee range and strike ready, strike * If enemy is not in melee range, and dash ready, dash towards them * if enemy is not in melee range and move ready, move towards them. */ ActionStart: if (IsAbleToTakeActions() == false) { EndMyActivation(); } // Twin Strike else if (IsTargetInRange(GetDefenderWithLowestCurrentHP(), currentMeleeRange) && HasEnoughAP(currentAP, twinStrike.abilityAPCost) && IsAbilityOffCooldown(twinStrike.abilityCurrentCooldownTime)) { SetTargetDefender(GetDefenderWithLowestCurrentHP()); StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Twin Strike", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformTwinStrike(this, myCurrentTarget); yield return(new WaitForSeconds(1f)); goto ActionStart; } // Strike else if (IsTargetInRange(GetDefenderWithLowestCurrentHP(), currentMeleeRange) && HasEnoughAP(currentAP, strike.abilityAPCost) && IsAbilityOffCooldown(strike.abilityCurrentCooldownTime)) { SetTargetDefender(GetDefenderWithLowestCurrentHP()); StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Strike", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformStrike(this, myCurrentTarget); yield return(new WaitForSeconds(1f)); goto ActionStart; } // Dash else if (IsTargetInRange(GetDefenderWithLowestCurrentHP(), currentMeleeRange) == false && IsAbleToMove() && HasEnoughAP(currentAP, dash.abilityAPCost) && IsAbilityOffCooldown(dash.abilityCurrentCooldownTime) ) { SetTargetDefender(GetDefenderWithLowestCurrentHP()); StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Dash", false)); yield return(new WaitForSeconds(0.5f)); TileScript destination = AILogic.GetBestValidMoveLocationBetweenMeAndTarget(this, myCurrentTarget, currentMeleeRange, dash.abilityPrimaryValue); AbilityLogic.Instance.PerformDash(this, destination); // small delay here in order to seperate the two actions a bit. yield return(new WaitForSeconds(1f)); goto ActionStart; } // Move else if (IsTargetInRange(GetDefenderWithLowestCurrentHP(), currentMeleeRange) == false && IsAbleToMove() && HasEnoughAP(currentAP, move.abilityAPCost) && IsAbilityOffCooldown(move.abilityCurrentCooldownTime) ) { SetTargetDefender(GetDefenderWithLowestCurrentHP()); StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Move", false)); yield return(new WaitForSeconds(0.5f)); TileScript destination = AILogic.GetBestValidMoveLocationBetweenMeAndTarget(this, myCurrentTarget, currentMeleeRange, currentMobility); AbilityLogic.Instance.PerformMove(this, destination); // small delay here in order to seperate the two actions a bit. yield return(new WaitForSeconds(1f)); goto ActionStart; } EndMyActivation(); }
private float healthConfidence;//, VIPSafety; // Use this for initialization void Start() { logic = transform.GetComponent <AILogic>(); interaction = transform.GetComponent <Interaction>(); controller = GameObject.Find("controller").GetComponent <Create_Teams>(); }
public override IEnumerator StartMyActivationCoroutine() { Ability strike = mySpellBook.GetAbilityByName("Strike"); Ability move = mySpellBook.GetAbilityByName("Move"); Ability charge = mySpellBook.GetAbilityByName("Charge"); Ability whirlwind = mySpellBook.GetAbilityByName("Whirlwind"); ActionStart: SetTargetDefender(GetClosestDefender()); // below line used later to prevent charging this is already in melee with List <TileScript> tilesInMyMeleeRange = LevelManager.Instance.GetTilesWithinRange(currentMeleeRange, TileCurrentlyOn); if (IsAbleToTakeActions() == false) { EndMyActivation(); } // Charge else if (IsAbilityOffCooldown(charge.abilityCurrentCooldownTime) && IsTargetInRange(myCurrentTarget, charge.abilityRange) && HasEnoughAP(currentAP, charge.abilityAPCost) && tilesInMyMeleeRange.Contains(myCurrentTarget.TileCurrentlyOn) == false && IsAbleToMove() ) { TileScript destination = AILogic.GetBestValidMoveLocationBetweenMeAndTarget(this, myCurrentTarget, currentMeleeRange, charge.abilityRange); StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Charge", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformCharge(this, myCurrentTarget, destination); // brief delay between actions yield return(new WaitForSeconds(1f)); goto ActionStart; } // Whirlwind else if (IsTargetInRange(myCurrentTarget, currentMeleeRange) && HasEnoughAP(currentAP, whirlwind.abilityAPCost) && IsAbilityOffCooldown(whirlwind.abilityCurrentCooldownTime)) { StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Whirlwind", false)); yield return(new WaitForSeconds(1f)); AbilityLogic.Instance.PerformWhirlwind(this); // brief delay between actions yield return(new WaitForSeconds(1f)); goto ActionStart; } // Strike else if (IsTargetInRange(myCurrentTarget, currentMeleeRange) && HasEnoughAP(currentAP, strike.abilityAPCost)) { StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Strike", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformStrike(this, myCurrentTarget); // brief delay between actions yield return(new WaitForSeconds(1f)); goto ActionStart; } // Move else if (IsTargetInRange(myCurrentTarget, currentMeleeRange) == false && IsAbleToMove() && HasEnoughAP(currentAP, move.abilityAPCost)) { StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Move", false)); yield return(new WaitForSeconds(0.5f)); TileScript destination = AILogic.GetBestValidMoveLocationBetweenMeAndTarget(this, myCurrentTarget, currentMeleeRange, currentMobility); AbilityLogic.Instance.PerformMove(this, destination); // small delay here in order to seperate the two actions a bit. yield return(new WaitForSeconds(1f)); goto ActionStart; } EndMyActivation(); }
void Start() { myParent = transform.parent.GetComponent <AILogic>(); transform.GetComponent <Collider>().enabled = true; }
public void DespawnAll() { States = AILogic.RUNFROMPLAYER; fadeAway = true; }
public void releasingFlag(int attackerID, float hurtForce) { //make Flag normal again if (flag && isHandlingFlag) { flag.GetComponent <Animator> ().SetBool("Wavin", false); if (attackerID != -5) { GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); foreach (GameObject player in players) { if (player.GetComponent <PhotonView> ().viewID == attackerID) { attacker = player; } } } else { attacker = gameObject; } Rigidbody2D rb = flag.GetComponent <Rigidbody2D> (); rb.gravityScale = 1; rb.freezeRotation = true; rb.isKinematic = false; Collider2D[] cols = flag.GetComponents <Collider2D> (); foreach (Collider2D coll in cols) { coll.enabled = true; } //apply force to flag; if (photonView.isMine) { photonView.RPC("NullParent", PhotonTargets.Others); flag.transform.parent = null; } if (flag.GetComponent <PhotonView> ().isMine) { Vector3 hurtVector = (transform.position - attacker.transform.position) / 2 + Vector3.up * 7f; flag.GetComponent <Rigidbody2D> ().AddForce(hurtVector * hurtForce * 10); } //flag.GetComponent<PhotonView> ().RPC ("Taked", PhotonTargets.AllViaServer, false,0); //if (photonView.isMine) { // arrow.SetActive (false); //} if (PhotonNetwork.offlineMode) { GameObject[] players = GameObject.FindGameObjectsWithTag("Player"); foreach (GameObject ply in players) { AILogic ailog = ply.GetComponent <AILogic> (); if (ailog) { ailog.StateChange(1); } } } isHandlingFlag = false; arrow.GetComponent <FixedRotation> ().isHandling = false; PhotonNetwork.room.SetCustomProperties(expectedValue); } }
void OnTriggerEnter2D(Collider2D _col) { if(_col.gameObject.CompareTag("Player")) { //Send message to player when it hits the player FindNewTargetPosition(); _col.gameObject.SendMessage("TakeDamage", 10f,SendMessageOptions.DontRequireReceiver); States = AILogic.RUNFROMPLAYER; fadeAway = true; } }
void ResetAI() { FindNewTargetPosition(); States = AILogic.PATROL; transform.position = spawnPoint; transform.rotation = Quaternion.identity; booSprite.color = new Color(1, 1, 1, 1); gameTimer = 0; }
void AIMove(Vector3 A,Vector3 B,float _speed,bool isPatrol=false) { Vector3 direction = (B - A).normalized; //Gets the direction that the AI should be going to to chase player direction.z = 0; //resets the position of the player's Z so he doesn't look far away //Vector3 vectorToTarget = targetTransform.position - transform.position; float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; //gets angle of the direction you should face Quaternion q = Quaternion.AngleAxis(angle, Vector3.forward); //makes a quaternion for that angle, using the correct axis if (isPatrol) { float distance = Vector3.Distance(B, A); if (distance < minDistance) { FindNewTargetPosition(); States = AILogic.WAIT; } } transform.rotation = Quaternion.Slerp(transform.rotation, q, Time.deltaTime * rotateSpeed); //rotate to face character transform.position = new Vector3(transform.position.x, transform.position.y, 0); // Set the Z to 0 transform.localPosition += transform.right * Time.deltaTime * _speed; //moves the AI }
public override IEnumerator StartMyActivationCoroutine() { Ability fireBall = mySpellBook.GetAbilityByName("Fire Ball"); Ability move = mySpellBook.GetAbilityByName("Move"); Ability frostBolt = mySpellBook.GetAbilityByName("Frost Bolt"); ActionStart: if (IsAbleToTakeActions() == false) { EndMyActivation(); } // Frost Bolt else if (IsTargetInRange(GetClosestDefender(), frostBolt.abilityRange) && HasEnoughAP(currentAP, frostBolt.abilityAPCost) && IsAbilityOffCooldown(frostBolt.abilityCurrentCooldownTime) ) { SetTargetDefender(GetClosestDefender()); // VFX notification StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Frost Bolt", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformFrostBolt(this, myCurrentTarget); yield return(new WaitForSeconds(1f)); goto ActionStart; } // Fireball the most vulnerable target else if (IsTargetInRange(GetMostVulnerableDefender(), fireBall.abilityRange) && GetMostVulnerableDefender().isKnockedDown&& HasEnoughAP(currentAP, fireBall.abilityAPCost) && IsAbilityOffCooldown(fireBall.abilityCurrentCooldownTime)) { SetTargetDefender(GetMostVulnerableDefender()); StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Fire Ball", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformFireBall(this, myCurrentTarget); yield return(new WaitForSeconds(1f)); goto ActionStart; } // Fireball the target with lowest current HP else if (IsTargetInRange(GetDefenderWithLowestCurrentHP(), fireBall.abilityRange) && HasEnoughAP(currentAP, fireBall.abilityAPCost) && IsAbilityOffCooldown(fireBall.abilityCurrentCooldownTime)) { SetTargetDefender(GetDefenderWithLowestCurrentHP()); StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Fire Ball", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformFireBall(this, myCurrentTarget); yield return(new WaitForSeconds(1f)); goto ActionStart; } // Fireball the closest target if the most vulnerable and the weakest cant be targetted else if (IsTargetInRange(GetClosestDefender(), fireBall.abilityRange) && HasEnoughAP(currentAP, fireBall.abilityAPCost) && IsAbilityOffCooldown(fireBall.abilityCurrentCooldownTime)) { SetTargetDefender(GetClosestDefender()); StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Fire Ball", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformFireBall(this, myCurrentTarget); yield return(new WaitForSeconds(1f)); goto ActionStart; } // Move else if ( IsTargetInRange(GetClosestDefender(), fireBall.abilityRange) == false && IsAbleToMove() && HasEnoughAP(currentAP, move.abilityAPCost) ) { SetTargetDefender(GetClosestDefender()); StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Move", false)); yield return(new WaitForSeconds(0.5f)); TileScript destination = AILogic.GetBestValidMoveLocationBetweenMeAndTarget(this, myCurrentTarget, fireBall.abilityRange, currentMobility); AbilityLogic.Instance.PerformMove(this, destination); // small delay here in order to seperate the two actions a bit. yield return(new WaitForSeconds(1f)); goto ActionStart; } EndMyActivation(); }
public override IEnumerator StartMyActivationCoroutine() { Ability strike = mySpellBook.GetAbilityByName("Strike"); Ability move = mySpellBook.GetAbilityByName("Move"); Ability doom = mySpellBook.GetAbilityByName("Doom"); Ability whirlwind = mySpellBook.GetAbilityByName("Whirlwind"); Ability crushingBlow = mySpellBook.GetAbilityByName("Crushing Blow"); ActionStart: if (IsAbleToTakeActions() == false) { EndMyActivation(); } // Doom else if (IsAbilityOffCooldown(doom.abilityCurrentCooldownTime) && HasEnoughAP(currentAP, doom.abilityAPCost) ) { StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Doom", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformDoom(this); // brief delay between actions yield return(new WaitForSeconds(1f)); goto ActionStart; } // Crushing Blow else if (IsTargetInRange(GetClosestDefender(), currentMeleeRange) && HasEnoughAP(currentAP, crushingBlow.abilityAPCost) && IsAbilityOffCooldown(crushingBlow.abilityCurrentCooldownTime)) { StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Crushing Blow", false)); yield return(new WaitForSeconds(0.6f)); AbilityLogic.Instance.PerformCrushingBlow(this, GetClosestDefender()); // brief delay between actions yield return(new WaitForSeconds(1f)); goto ActionStart; } // try to move to a position that we can hit two or more enemies with a whirlwind from else if ( IsAdjacentToTwoOrMoreDefenders() == false && GetClosestValidTileThatHasTwoAdjacentDefenders() != null && LevelManager.Instance.GetTilesWithinRange(currentMobility, TileCurrentlyOn).Contains(GetClosestValidTileThatHasTwoAdjacentDefenders()) && HasEnoughAP(currentAP, move.abilityAPCost) && IsAbilityOffCooldown(whirlwind.abilityCurrentCooldownTime) ) { StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Move", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformMove(this, GetClosestValidTileThatHasTwoAdjacentDefenders()); // small delay here in order to seperate the two actions a bit. yield return(new WaitForSeconds(1f)); goto ActionStart; } // Whirlwind else if (IsTargetInRange(GetClosestDefender(), currentMeleeRange) && HasEnoughAP(currentAP, whirlwind.abilityAPCost) && IsAbilityOffCooldown(whirlwind.abilityCurrentCooldownTime)) { StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Whirlwind", false)); yield return(new WaitForSeconds(1f)); AbilityLogic.Instance.PerformWhirlwind(this); // brief delay between actions yield return(new WaitForSeconds(1f)); goto ActionStart; } // Strike else if (IsTargetInRange(GetClosestDefender(), currentMeleeRange) && HasEnoughAP(currentAP, strike.abilityAPCost)) { StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Strike", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformStrike(this, GetClosestDefender()); // brief delay between actions yield return(new WaitForSeconds(1f)); goto ActionStart; } // Move else if (IsTargetInRange(GetClosestDefender(), currentMeleeRange) == false && IsAbleToMove() && HasEnoughAP(currentAP, move.abilityAPCost)) { SetTargetDefender(GetClosestDefender()); StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Move", false)); yield return(new WaitForSeconds(0.5f)); TileScript destination = AILogic.GetBestValidMoveLocationBetweenMeAndTarget(this, myCurrentTarget, currentMeleeRange, currentMobility); AbilityLogic.Instance.PerformMove(this, destination); // small delay here in order to seperate the two actions a bit. yield return(new WaitForSeconds(1f)); goto ActionStart; } EndMyActivation(); }
public override IEnumerator StartMyActivationCoroutine() { Ability strike = mySpellBook.GetAbilityByName("Strike"); Ability move = mySpellBook.GetAbilityByName("Move"); Ability guard = mySpellBook.GetAbilityByName("Guard"); Ability inspire = mySpellBook.GetAbilityByName("Inspire"); /* AI LOGIC * If inspire is ready and best inspire target is in range and inspire ready, inspire * prioritise archer>assassin>barbarian>warrior>self) * if best inspire target is not in range, inspire something random within range * if an ally is not at max hp and in range of barrier and barrier is ready, barrier them * if in melee range of closest target and strike ready, strike * if move ready and not on grass and a grass tile is within movement range, move to grass * if not in melee range of closest target and both move and strike ready, move towards them * (stops Ai from moving onto grass, then off the grass towards an enemy without being able to attack) */ ActionStart: if (IsAbleToTakeActions() == false) { EndMyActivation(); } // Inspire best target if they are in range else if (IsTargetInRange(GetBestInspireTarget(), inspire.abilityRange) && IsAbilityOffCooldown(inspire.abilityCurrentCooldownTime) && HasEnoughAP(currentAP, inspire.abilityAPCost)) { StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Inspire", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformInspire(this, GetBestInspireTarget()); yield return(new WaitForSeconds(1f)); goto ActionStart; } // Inspire something else if the best target is not in range else if (GetBestInspireTargetInRange(inspire.abilityRange) != null && IsAbilityOffCooldown(inspire.abilityCurrentCooldownTime) && HasEnoughAP(currentAP, inspire.abilityAPCost)) { StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Inspire", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformInspire(this, GetBestInspireTargetInRange(inspire.abilityRange)); yield return(new WaitForSeconds(1f)); goto ActionStart; } // Guard an ally if they are injured and in range else if (GetBestBarrierTargetInRange(guard.abilityRange) != null && IsAbilityOffCooldown(guard.abilityCurrentCooldownTime) && HasEnoughAP(currentAP, guard.abilityAPCost)) { StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Guard", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformGuard(this, GetBestBarrierTargetInRange(guard.abilityRange)); yield return(new WaitForSeconds(1f)); goto ActionStart; } // Strike else if (IsTargetInRange(GetClosestDefender(), currentMeleeRange) && HasEnoughAP(currentAP, strike.abilityAPCost) && IsAbilityOffCooldown(strike.abilityCurrentCooldownTime)) { SetTargetDefender(GetClosestDefender()); StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Strike", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformStrike(this, myCurrentTarget); yield return(new WaitForSeconds(1f)); goto ActionStart; } // Move else if (IsTargetInRange(GetDefenderWithLowestCurrentHP(), currentMeleeRange) == false && IsAbleToMove() && HasEnoughAP(currentAP, move.abilityAPCost) && IsAbilityOffCooldown(move.abilityCurrentCooldownTime) ) { SetTargetDefender(GetDefenderWithLowestCurrentHP()); StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Move", false)); yield return(new WaitForSeconds(0.5f)); TileScript destination = AILogic.GetBestValidMoveLocationBetweenMeAndTarget(this, myCurrentTarget, currentMeleeRange, currentMobility); AbilityLogic.Instance.PerformMove(this, destination); // small delay here in order to seperate the two actions a bit. yield return(new WaitForSeconds(1f)); goto ActionStart; } EndMyActivation(); }
public override IEnumerator StartMyActivationCoroutine() { Ability move = mySpellBook.GetAbilityByName("Move"); Ability siphonLife = mySpellBook.GetAbilityByName("Siphon Life"); Ability twinStrike = mySpellBook.GetAbilityByName("Twin Strike"); Ability teleport = mySpellBook.GetAbilityByName("Teleport"); Ability fireBall = mySpellBook.GetAbilityByName("Fire Ball"); ChooseRandomTargetingLogic(); ActionStart: if (myCurrentTarget.currentHealth <= 0 || myCurrentTarget == null) { ChooseRandomTargetingLogic(); } if (IsAbleToTakeActions() == false) { EndMyActivation(); } // Siphon Life else if (IsAbilityOffCooldown(siphonLife.abilityCurrentCooldownTime) && IsTargetInRange(myCurrentTarget, siphonLife.abilityRange) && HasEnoughAP(currentAP, siphonLife.abilityAPCost) ) { //SetTargetDefender(GetClosestDefender()); StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Siphon Life", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformSiphonLife(this, myCurrentTarget); // brief delay between actions yield return(new WaitForSeconds(1f)); goto ActionStart; } // If unable to siphon life the ideal target, siphon the closest valid target else if (IsAbilityOffCooldown(siphonLife.abilityCurrentCooldownTime) && IsTargetInRange(GetClosestDefender(), siphonLife.abilityRange) && HasEnoughAP(currentAP, siphonLife.abilityAPCost) ) { SetTargetDefender(GetClosestDefender()); StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Siphon Life", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformSiphonLife(this, myCurrentTarget); // brief delay between actions yield return(new WaitForSeconds(1f)); goto ActionStart; } // Twin Strike else if (IsTargetInRange(myCurrentTarget, currentMeleeRange) && HasEnoughAP(currentAP, twinStrike.abilityAPCost) && IsAbilityOffCooldown(twinStrike.abilityCurrentCooldownTime)) { //SetTargetDefender(GetDefenderWithLowestCurrentHP()); StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Twin Strike", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformTwinStrike(this, myCurrentTarget); yield return(new WaitForSeconds(1f)); goto ActionStart; } // Fireball else if (IsTargetInRange(myCurrentTarget, fireBall.abilityRange) && HasEnoughAP(currentAP, fireBall.abilityAPCost) && IsAbilityOffCooldown(fireBall.abilityCurrentCooldownTime)) { //SetTargetDefender(GetMostVulnerableDefender()); StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Fire Ball", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformFireBall(this, myCurrentTarget); yield return(new WaitForSeconds(1f)); goto ActionStart; } // Move else if (IsTargetInRange(myCurrentTarget, fireBall.abilityRange) == false && IsAbleToMove() && HasEnoughAP(currentAP, move.abilityAPCost) && IsAbilityOffCooldown(move.abilityCurrentCooldownTime) ) { StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Move", false)); yield return(new WaitForSeconds(0.5f)); TileScript destination = AILogic.GetBestValidMoveLocationBetweenMeAndTarget(this, myCurrentTarget, fireBall.abilityRange, currentMobility); AbilityLogic.Instance.PerformMove(this, destination); // small delay here in order to seperate the two actions a bit. yield return(new WaitForSeconds(1f)); goto ActionStart; } else if (AILogic.IsEngagedInMelee(this) && IsAbilityOffCooldown(teleport.abilityCurrentCooldownTime) && HasEnoughAP(currentAP, teleport.abilityAPCost) ) { StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Teleport", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformTeleport(this, GetBestTeleportLocation(myCurrentTarget.TileCurrentlyOn)); yield return(new WaitForSeconds(1f)); goto ActionStart; } EndMyActivation(); }
public void Start() { aILogic = GetComponent <AILogic>(); }
public override IEnumerator StartMyActivationCoroutine() { Ability strike = mySpellBook.GetAbilityByName("Strike"); Ability move = mySpellBook.GetAbilityByName("Move"); Ability invigorate = mySpellBook.GetAbilityByName("Invigorate"); Ability healingLight = mySpellBook.GetAbilityByName("Healing Light"); /* AI LOGIC * if invigorate ready, invigorate * Find the closest wounded ally * if heal ready and wounded ally in range, heal. * If closest wounded ally is not in range and move ready, move towards them. * Check if all allies are at full hp * GetClosestAlly(dont include self) * If all allies are at full health, and move ready, move towards ally * will try to move adjacent to an ally to give the protector bonus. * If no allies are in range to move next to, it will try to move into a grass tile. * If no grass tile is within range, it will stand still. * Only attacks enemies with strike if all allies are dead, and will target the closest enemy. */ ActionStart: if (IsAbleToTakeActions() == false) { EndMyActivation(); } // Invigorate else if (IsTargetInRange(GetBestInvigorateTarget(invigorate.abilityRange), invigorate.abilityRange) && IsAbilityOffCooldown(invigorate.abilityCurrentCooldownTime) && HasEnoughAP(currentAP, invigorate.abilityAPCost)) { StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Invigorate", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformInvigorate(this, GetBestInvigorateTarget(invigorate.abilityRange)); yield return(new WaitForSeconds(1f)); goto ActionStart; } // Healing Light else if (IsTargetInRange(GetBestHealingLightTarget(), healingLight.abilityRange) && GetBestHealingLightTarget().currentHealth < GetBestHealingLightTarget().currentMaxHealth&& IsAbilityOffCooldown(healingLight.abilityCurrentCooldownTime) && HasEnoughAP(currentAP, healingLight.abilityAPCost)) { StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Healing Light", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformHealingLight(this, GetBestHealingLightTarget()); yield return(new WaitForSeconds(1f)); goto ActionStart; } // Move towards an ally to give Encouraging presence bonus else if (GetClosestFriendlyTarget() != this && IsTargetInRange(GetClosestFriendlyTarget(), currentMobility) == false && IsAbleToMove() && HasEnoughAP(currentAP, move.abilityAPCost) && IsAbilityOffCooldown(move.abilityCurrentCooldownTime) ) { StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Move", false)); yield return(new WaitForSeconds(0.5f)); TileScript destination = AILogic.GetBestValidMoveLocationBetweenMeAndTarget(this, GetClosestFriendlyTarget(), 1, currentMobility); AbilityLogic.Instance.PerformMove(this, destination); // small delay here in order to seperate the two actions a bit. yield return(new WaitForSeconds(1f)); goto ActionStart; } // Strike else if (IsTargetInRange(GetClosestDefender(), currentMeleeRange) && HasEnoughAP(currentAP, strike.abilityAPCost) && IsAbilityOffCooldown(strike.abilityCurrentCooldownTime)) { SetTargetDefender(GetClosestDefender()); StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Strike", false)); yield return(new WaitForSeconds(0.5f)); AbilityLogic.Instance.PerformStrike(this, myCurrentTarget); yield return(new WaitForSeconds(1f)); goto ActionStart; } EndMyActivation(); }