private async void InteractWithTileOccupant(Vector2 _moveToPosition) { if (grid.TileGrid[(int)_moveToPosition.x, (int)_moveToPosition.y].Occupant is Enemy) { Enemy occupant = grid.TileGrid[(int)_moveToPosition.x, (int)_moveToPosition.y].Occupant as Enemy; attack.AttackTarget(player, occupant, console, grid.Random); await ToSignal(attackTimer, "timeout"); } else if (grid.TileGrid[(int)_moveToPosition.x, (int)_moveToPosition.y].Occupant is Door) { Door occupant = grid.TileGrid[(int)_moveToPosition.x, (int)_moveToPosition.y].Occupant as Door; occupant.OpenDoor(player); } else if (grid.TileGrid[(int)_moveToPosition.x, (int)_moveToPosition.y].Occupant is Chest) { Chest occupant = grid.TileGrid[(int)_moveToPosition.x, (int)_moveToPosition.y].Occupant as Chest; occupant.OpenChest(player); } else if (grid.TileGrid[(int)_moveToPosition.x, (int)_moveToPosition.y].Occupant is Loot) { Loot occupant = grid.TileGrid[(int)_moveToPosition.x, (int)_moveToPosition.y].Occupant as Loot; player.Inventory.AddItem(occupant.ItemContained); occupant.QueueFree(); } else if (grid.TileGrid[(int)_moveToPosition.x, (int)_moveToPosition.y].Occupant is Stairs) { Stairs occupant = grid.TileGrid[(int)_moveToPosition.x, (int)_moveToPosition.y].Occupant as Stairs; // Get the player going to the next level } // TODO add interaction with doors, chests, items, etc here }
public virtual void Update() { if (!enemyStats.getIsDead() && lastPlayerSeenPosition != getLastPlayerSeenResetPosition() && !enemyAttack.getAttackingTarget()) { if (getLastCharacterSeen() != null) { if (!isLastCharacterSeenDead()) { enemyAttack.AttackTarget(getLastCharacterSeen()); } else { resetLastPlayerSeenPosition(); } } } if (getLastCharacterSeen() != null) { if (Vector3.Distance(transform.position, getLastCharacterSeen().transform.position) > enemyStats.attackRange) { enemyAttack.setAttackingTarget(false); resetLastPlayerSeenPosition(); } } }
public void AttackTarget(GameObject enemy) { if (!playerStats.getIsDead()) { playerAttack.AttackTarget(enemy); } }
private void TriggerStay(Collider2D mycol, Collider2D other) { if (target == null) { targets.Add(other.gameObject); } else { if (target == other.gameObject) { if (mycol.name == "AttackMelee") { if (attackMelee != null) { lastAttack = attackMelee as Attack; attackMelee.AttackTarget(other.transform); } } else if (mycol.name == "AttackRange") { if (attackRange != null) { if ((attackMelee == null) || ((attackMelee != null) && (lastAttack != attackMelee))) { lastAttack = attackRange as Attack; attackRange.AttackTarget(other.transform); } } } } } }
protected override void Update() { base.Update(); if (checkForLocationReached) { if (nodeParent == node) { node = null; checkForLocationReached = false; canMove = false; //If move was initiated as part of attacking if (state == State.Attack) { Attack.AttackTarget(currentAttack, target); currentAttack = null; target = null; RaiseEndTurnEvent(); } else { ResetScores(); //Do another action OnEnemyTurn(new List <BattleEntity>() { target }); } } } }
public override void ActivateAbility() { base.ActivateAbility(); target = refManager.targetManager.GetClosestTarget(refManager.transform.position, refManager.enemyTag.ToString()); if (target == null) { return; } if (Utility.CheckDistance(refManager.transform.position, target.position) < refManager.stats.attackRange) { Attack attack = new Attack(); attack.Initialize(damage, refManager.enemyTag.ToString(), refManager.friendlyTag.ToString(), afterEffects); attack.SetTarget(target); for (int j = 0; j < GetActiveModules().Count; j++) { attack.SetModule(GetActiveModules()[j]); } attack.AttackTarget(); } RemoveModules(); TriggerCooldown(); }
public virtual void Update() { if (enemyAnimator != null) { enemyAnimator.SetFloat(hashAnimator.velocity, agent.velocity.magnitude); } if (!enemyStats.getIsDead() && lastPlayerSeenPosition == getLastPlayerSeenResetPosition() && !enemyAttack.getAttackingTarget()) { Patrol(); } if (!enemyStats.getIsDead() && lastPlayerSeenPosition != getLastPlayerSeenResetPosition() && !enemyAttack.getAttackingTarget()) { //Stalk(); if (getLastCharacterSeen() != null) { if (!isLastCharacterSeenDead()) { enemyAttack.AttackTarget(getLastCharacterSeen()); } else { resetLastPlayerSeenPosition(); } } } }
void Update() { _viewField.LookForTarget(_selfTransform); _rotation.RotateToTarget(_selfTransform, _viewField); _attack.AttackTarget(_selfTransform, _viewField, StartCoroutine); Death(); }
private void bdrAttack_MouseDown(object sender, MouseButtonEventArgs e) { if (GameData.arrSelectedEnemiesObjects.Count == 0 || GameData.arrSelectedUserObjects.Count == 0) { //提示未选中 return; } Attack.AttackTarget(GameData.arrSelectedUserObjects, GameData.arrSelectedEnemiesObjects, TeamSign.Teams.User); }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (attackComponent) { if (unitAI) { GameObject target = unitAI.ReadFromBlackboard("HIGHESTTHREAT") as GameObject; if (target) { attackComponent.AttackTarget(target); } else { target = unitAI.ReadFromBlackboard("NEAREST") as GameObject; if (target) { attackComponent.AttackTarget(target); } } } } }
// create the enemy selection menu and associate each entry with the proper target in such a way that, when clicked on, // the correct enemy is then attacked. public void SelectAttack() { Destroy(enemyUnitsMenu); enemyUnitsMenu = Instantiate(enemyUnitsMenuPrefab, gameObject.transform.parent.transform, false); GameObject[] enemies = GameObject.FindGameObjectsWithTag("EnemyUnit"); Attack contestantAttack = contestant.gameObject.GetComponent <Attack>(); foreach (GameObject enemy in enemies) { GameObject newEnemyButton = Instantiate(targetEnemyButton, enemyUnitsMenu.transform, false); newEnemyButton.GetComponent <Image>().sprite = enemy.GetComponent <UnitStats>().Portrait; newEnemyButton.GetComponent <Button>().onClick.AddListener( delegate { StartCoroutine(contestantAttack.AttackTarget(this, enemy)); } ); } }
private void Update() { //TODO dont constantly raycast GameObject raycastObject = MouseRaycast(playerMovementRange); //TODO change this if (CurrentTurn == Turn.Player) { if (raycastObject != null) { if (!friendlies[0].IsMoving && !Attacking) { List <Node> path = Pathfinding.FindPath(friendlies[0].nodeParent, GetTargetNode(raycastObject.GetComponent <Tile>()), reverse: true); if (canDisplayPathTiles) { Pathfinding.SelectNodes(playerMovementRange, movementRangeColour); Pathfinding.SelectNodes(path, pathColour); } } else if (Attacking) { if (Input.GetMouseButtonDown(0)) { BattleEntity entity = raycastObject.GetComponent <BattleEntity>(); //print("Attacking: " + entity.name); Attack.AttackTarget(lastSelectedAttack, entity); //End turn once attacked canMove = true; OnPlayerInfoChangedEvent(canMove: canMove.ToString()); OnEndTurn(); } } //Else if repairing do similar stuff as the above if else if (true) { } } } //TODO do not do this else if (CurrentTurn == Turn.Enemy && !eventCalled) { eventCalled = true; OnEnemyTurnEvent(friendlies); } }
private void FollowTarget() { if (!target.isDead && !animator.GetBool("Attack1")) { if (!VectorMath.IsWithinDistance(meleeRange, transform.position, target.transform.position)) { animator.SetBool("isWalking", true); move.MoveToTarget(GetCurrentSpeed(), target.transform.position); } else { animator.SetBool("isWalking", false); animator.SetTrigger("Attack1"); move.StopMoving(); StopRunning(); this.transform.LookAt(target.transform.position); attack.AttackTarget(target, damage); } } }
public async void RunAI() { if (currentEnemyState == EnemyState.Wandering) { bool isInViewDistance = IsPlayerInViewDistance(); bool isInLineOfSight = false; if (isInViewDistance) // Run line of sight algorithim if player is nearby, if not don't waste the energy { isInLineOfSight = IsPlayerInLineOfSight(); } if (!isInViewDistance || !isInLineOfSight) { Wander(); } else if (isInLineOfSight) { PlayerPlayerSpottedAnimation(); currentEnemyState = EnemyState.Pursuit; } } else if (currentEnemyState == EnemyState.Pursuit) { if (IsPlayerNearby()) { attack.AttackTarget(this, player, console, grid.Random); await ToSignal(attackTimer, "timeout"); } else { ChasePlayer(); } } ChangeGridPosition(); }
/// <summary> /// Logic to be executed on enemy turn /// </summary> /// <param name="targets">List of possible targets</param> private void OnEnemyTurn(List <BattleEntity> targets) { target = GetTarget(targets); currentAttack = DetermineAttackScore(target); consumable = DetermineConsumableScore(); node = DetermineMoveScore(target, canAttack: currentAttack != null, canConsume: consumable != null); //print("A-score: " + attackingScore + " C-score: "+ consumableScore + " M-Score: "+moveScore); //If enemy cant do anything just end turn if (currentAttack == null && (consumable == null || consumableScore <= 0) && !canMove) { RaiseEndTurnEvent(); } state = GetState(); switch (state) { case State.Attack: print("Attacking..."); if (currentAttack != null && moveForAttack) //TODO remove the first condition { Node nodeToMoveTo = null; List <Node> movementRangeNodes = Pathfinding.GetRange(battleController.Nodes, nodeParent, (data.Speed)); int minDistance = int.MaxValue; for (int i = 0; i < movementRangeNodes.Count; i++) { if (nodeParent != movementRangeNodes[i] && target.nodeParent != movementRangeNodes[i]) { List <Node> attackRangeNodes = Pathfinding.GetRange(battleController.Nodes, movementRangeNodes[i], currentAttack.Range); int currentDistance = Pathfinding.GetDistance(target.nodeParent, movementRangeNodes[i]); if (currentDistance < minDistance) { minDistance = currentDistance; nodeToMoveTo = movementRangeNodes[i]; } } } List <Node> path = Pathfinding.FindPath(nodeParent, nodeToMoveTo, reverse: true); for (int i = 0; i < path.Count; i++) { int distance = Pathfinding.GetDistance(path[i], target.nodeParent); if (distance <= currentAttack.Range) { path = Pathfinding.FindPath(nodeParent, path[i], reverse: true); break; } } SetPathNodes(path); node = path[path.Count - 1]; checkForLocationReached = true; } else if (currentAttack != null) { Attack.AttackTarget(currentAttack, target); RaiseEndTurnEvent(); } break; case State.Consumable: print("consuming"); consumable.Consume(this); data.Consumables.Remove(consumable); print("Consuming " + consumable.Name); consumable = null; //TODO allow selecting other targets(party members) RaiseEndTurnEvent(); break; case State.Move: print("Moving..."); List <Node> _path = Pathfinding.FindPath(nodeParent, node, reverse: true); if (_path != null) { SetPathNodes(_path); node = _path[_path.Count - 1]; } checkForLocationReached = true; break; } }