void AttemptMoveAttack(CreatureBase creature) { if (creature != null) { List <CreatureBase> searchTargetCreatures = creature.ActiveLaneNode.laneManager.SearchRange((int)creature.Range, creature.ActiveLaneNode, this); bool foundAttackTarget = false; foreach (CreatureBase _creature in searchTargetCreatures) { if (_creature.Owner != creature.Owner) //Found enemy creature in range { foundAttackTarget = true; AIResponse.Attack(creature); } } if (!foundAttackTarget) { int moveSpaces = creature.ActiveLaneNode.laneManager.GetOpenNodes(creature.ActiveLaneNode, _RightFacing); if (moveSpaces > AIResponse.Tokens) { moveSpaces = AIResponse.Tokens; } if (AIResponse.Move(creature, moveSpaces)) { LogStack.Log("Hal Move " + creature.GetInstanceID() + " - " + moveSpaces + " spaces - " + creature.LaneProgress, LogLevel.System); } } } }
public void MoveAtk(CreatureBase creat) { Debug.Log("Moving or attacking: " + creat.name + ", in lane: " + creat.LaneIndex.ToString()); if (creat != null) { bool TargetInRange = false; List <CreatureBase> Targets = creat.ActiveLaneNode.laneManager.SearchRange((int)creat.Range, creat.ActiveLaneNode, this); foreach (CreatureBase creature in Targets) { if (creature.Owner != creat.Owner) { TargetInRange = true; AIResponse.Attack(creat); } } if (!TargetInRange) { int spaces = creat.ActiveLaneNode.laneManager.GetOpenNodes(creat.ActiveLaneNode, creat.RightFacing); if (spaces > AIResponse.Tokens) { spaces = AIResponse.Tokens; } if (spaces > 10) { spaces = 10; } AIResponse.Move(creat, spaces); } } }
public void Auto_Nearest(LaneManager[] Board) { Tuple <CreatureBase, int> nearestAndRange = GetNearestCreatureToNearestEnemy(Board); if (nearestAndRange != null && _Creatures.Count > 0) { LogStack.Log("I have a nearby unit", Logging.LogLevel.Color); List <CreatureBase> inRange = nearestAndRange.Item1.ActiveLaneNode.laneManager.SearchRange((int)nearestAndRange.Item1.Range, nearestAndRange.Item1.ActiveLaneNode, nearestAndRange.Item1.Owner); if (inRange.GetEnemies(nearestAndRange.Item1.Owner).Count > 0) { // if (AIResponse.Attack (nearestAndRange.Item1)) { if (!AIResponse.Attack(nearestAndRange.Item1, nearestAndRange.Item1.CreatureType == Spawnable.Bunny ? 1 : (int)GetNearestEnemy(Board).Health)) { // LogStack.Log ("Attack Validation check failed", Logging.LogLevel.System); } else { LogStack.Log("Nearby Unit Attacking", Logging.LogLevel.Color); } } else { LogStack.Log("Try Move " + nearestAndRange.Item1.GetInstanceID(), Logging.LogLevel.System); if (!AIResponse.Move(nearestAndRange.Item1)) { LogStack.Log("Move validation check failed", Logging.LogLevel.Color); } else { LogStack.Log("Nearby Unit Moving", Logging.LogLevel.Stack); } } } else if (Opponent._Creatures.Count > 0) { CreatureBase nearestCreature = GetNearestEnemy(Board); int nearestLane = 1; Spawnable spawnCreature = Spawnable.Bunny; if (nearestCreature != null) { spawnCreature = nearestCreature.LaneProgress < 6 ? Spawnable.Unicorn : Spawnable.Bunny; nearestLane = nearestCreature.ActiveLaneNode.laneManager.LaneNumber; } if (!AIResponse.Spawn(spawnCreature, nearestLane)) { LogStack.Log("Spawn Validation check failed", Logging.LogLevel.Stack); } } else if (Opponent._Creatures.Count == 0) { LogStack.Log("Wait till opponent does something", Logging.LogLevel.Stack); } }
public override void OnTick(IBoardState[] data) { if (!AIResponse.Spawn(Random.Range(0, 2) == 0 ? Spawnable.Bunny : Spawnable.Unicorn, Random.Range(1, 4))) { if (_Creatures.Count > 0) { AIResponse.Attack(_Creatures[0]); } } //IResponse[] responses = AIResponse.QueryResponse(); AIResponse.FinalizeResponse(); }
public IEnumerator AttackConfirm() { LogStack.Log("AttackConfirm () " + this.name, LogLevel.Stack); bool foundCreature = false; while (!foundCreature) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; Debug.DrawLine(ray.origin, ray.direction * 500, Color.yellow, 1); if (Physics.Raycast(ray, out hit, 500, layerMask, QueryTriggerInteraction.Collide)) { CreatureBase creature = hit.transform.gameObject.GetComponent <CreatureBase> (); LogStack.Log("AttackConfirm () " + this.name + " | " + hit.transform.name, LogLevel.Stack); if (Input.GetMouseButtonDown(0) && creature?.Owner == this) { foundCreature = true; if (!AIResponse.Attack(creature)) { LogStack.Log("Could Not Attack Creature", LogLevel.Stack); OpenUI(); } else if (AIResponse.Tokens > 0) { LogStack.Log("Creature Attacked", LogLevel.Stack); _uiAnimator.SetBool("Actions", false); yield return(null); OpenUI(); } else { LogStack.Log("Creature Attacked", LogLevel.Stack); Finalise(); CloseUI(); } } else if (Input.GetMouseButtonDown(1)) { OpenUI(); foundCreature = true; } } yield return(null); } }
private void CheckIfClosestenemyIsInAttackingrange(CreatureBase allyWithMostProgress) { if (allyWithMostProgress == null) { return; } List <CreatureBase> searchTargetCreatures; searchTargetCreatures = allyWithMostProgress.ActiveLaneNode.laneManager.SearchRange( (int)allyWithMostProgress.Range, allyWithMostProgress.ActiveLaneNode, this); var hasTraget = false; foreach (CreatureBase creature in searchTargetCreatures) { if (creature.Owner != allyWithMostProgress.Owner) { //Found enemy creature in range hasTraget = true; AIResponse.Attack(allyWithMostProgress); } } if (hasTraget) { return; } int moveSpaces = allyWithMostProgress.ActiveLaneNode.laneManager.GetOpenNodes(allyWithMostProgress.ActiveLaneNode, _RightFacing); if (moveSpaces > AIResponse.Tokens) { moveSpaces = AIResponse.Tokens; } if (AIResponse.Move(allyWithMostProgress, moveSpaces)) { } else if (AIResponse.Move(_Creatures[_Creatures.Count - 1], 2)) { } }
private bool CheckIfAlliesAreInAttackingDistance() { foreach (var creature in _Creatures) { if (creature.ActiveLaneNode.laneManager.SearchRange(0, creature.ActiveLaneNode, this) != null && creature != null) { var list = creature.ActiveLaneNode.laneManager.SearchRange(0, creature.ActiveLaneNode, this); foreach (var VARIABLE in list) { if (VARIABLE.Owner != this) { AIResponse.Attack(VARIABLE); return(true); } } } } return(false); }
private void AttackWithTroops(List <CreatureBase> Troops) { foreach (CreatureBase troop in Troops) { List <CreatureBase> searchTargetCreatures = troop.ActiveLaneNode.laneManager.SearchRange((int)troop.Range, troop.ActiveLaneNode, this); foreach (CreatureBase _creature in searchTargetCreatures) { if (_creature.Owner != this && !AttackedThisTurn.Contains(_creature)) { AttackedThisTurn.Add(_creature); if (troop.CreatureType == Spawnable.Unicorn) // Unicorn Attacks { if (_creature.Health == 1) { AIResponse.Attack(troop); } else { int iCount = 0; int iSpareTokens = AIResponse.Tokens - (iAttackTokenThreshold + iSavingTokens); // NB NB NB CHANGED iAttackTokenThreshold from iOffensiveThreshold if (iSpareTokens < 0) { iSpareTokens = 0; } while (iCount < _creature.Health && iUnicornAttacks < 2 + iSpareTokens) { //LogStack.Log("%%%%%%%%%%%%%%%%%%% Unicorn attack #" + iCount, LogLevel.Debug); iCount++; iUnicornAttacks++; AIResponse.Attack(troop); } } } else { AIResponse.Attack(troop); // Bunny Attacks } } } } }
//--Random attack or move-- void AttemptMoveAttack() { Debug.Log("---Attempt Move/Attack---"); if (_Creatures.Count > 0) { CreatureBase toMove = _Creatures[Random.Range(0, _Creatures.Count)]; if (toMove != null) { List <CreatureBase> searchTargetCreatures = toMove.ActiveLaneNode.laneManager.SearchRange((int)toMove.Range, toMove.ActiveLaneNode, this); bool foundAttackTarget = false; foreach (CreatureBase _creature in searchTargetCreatures) { if (_creature.Owner != toMove.Owner) { //---Found enemy creature in rang--- foundAttackTarget = true; AIResponse.Attack(toMove); //---find pair that contains friendlyToMove--- foreach (var pair in attackingPairs) { if (pair.ContainsCreature(toMove)) { //---if first creature still exists--- if (pair.creatures[0] != null) { pair.AttackAsPair(AIResponse); } else { pair.AttackSingle(pair.creatures[1], AIResponse); } break; } } } } if (!foundAttackTarget) { int moveSpaces = toMove.ActiveLaneNode.laneManager.GetOpenNodes(toMove.ActiveLaneNode, _RightFacing); if (moveSpaces > AIResponse.Tokens) { moveSpaces = AIResponse.Tokens; } foreach (var pair in attackingPairs) { if (pair.ContainsCreature(toMove)) { //---if first creature still exists--- if (pair.creatures[0] != null) { pair.MovePair(AIResponse); } else { pair.MoveSingle(pair.creatures[1], AIResponse, moveSpaces); } break; } } } } } }