Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.IO;
- [CreateAssetMenu(fileName = "NewAttack", menuName = "Attacks/Basic - Empty", order = 1)]
- public class BasicAttack : AttackTypeBase {
- [SerializeField, Tooltip("The point of attack based on attacker's position")]
- private Vector2Int _AttackPoint;
- [SerializeField, Tooltip("The range of the attack starting from attack point")]
- private int _AttackRange;
- [SerializeField, Tooltip("Decrease damage over distance")]
- private bool _DecreaseDamage;
- [SerializeField, Tooltip("The base hp change for teammates")]
- private int _TeamHealthAdditive;
- [SerializeField, Tooltip("The base hp change for all other characters")]
- private int _EnemyHealthAdditive;
- [SerializeField, Tooltip("Does the attack affect the attacker himself")]
- private bool _AffectsSelf;
- [SerializeField, Tooltip("Knockback distance in attacking direction for teammates")]
- private int _TeamKnockBack;
- [SerializeField, Tooltip("Knockback distance in attacking direction for enemys")]
- private int _EnemyKnockBack;
- [SerializeField, Tooltip("Does the attacker move to the point of attack (Knockback has to be higher than 0)")]
- private bool _TravelToPiont;
- private Vector2Int _DirectionVector;
- public override bool Attack(CharacterStats owner) {
- if (owner.currentTile.occupant == null || owner.currentTile.occupant == owner) {
- Vector2Int pointOfEffect = new Vector2Int(owner.currentTile.position.x + (_AttackPoint.x * _DirectionVector.x), owner.currentTile.position.y + (_AttackPoint.y * _DirectionVector.y));
- if (pointOfEffect.x >= 0 && pointOfEffect.x <= owner.fieldManager.gridSize.x - 1 && pointOfEffect.y >= 0 && pointOfEffect.y <= owner.fieldManager.gridSize.y - 1) {
- List<TileNode> currentLevel = new List<TileNode>();
- List<CharacterStats> damaged = new List<CharacterStats>();
- currentLevel.Add(owner.fieldManager.grid[pointOfEffect.x, pointOfEffect.y]);
- if (_AffectsSelf == false) {
- damaged.Add(owner);
- }
- if (currentLevel[0].occupant != null && damaged.Contains(currentLevel[0].occupant) == false) {
- damaged.Add(currentLevel[0].occupant);
- if (currentLevel[0].occupant.playSide == owner.playSide) {
- currentLevel[0].occupant.health += _TeamHealthAdditive;
- if (currentLevel[0].occupant != owner && currentLevel[0].position.x >= _TeamKnockBack * -_DirectionVector.x && currentLevel[0].position.x <= (owner.fieldManager.gridSize.x - 1) - (_TeamKnockBack * _DirectionVector.x) && currentLevel[0].position.y >= _TeamKnockBack * -_DirectionVector.y && currentLevel[0].position.y <= (owner.fieldManager.gridSize.y - 1) - (_TeamKnockBack * _DirectionVector.y)) {
- if (owner.fieldManager.grid[currentLevel[0].position.x + (_TeamKnockBack * _DirectionVector.x), currentLevel[0].position.y + (_TeamKnockBack * _DirectionVector.y)].occupant == null) {
- currentLevel[0].occupant.transform.position = owner.fieldManager.grid[currentLevel[0].position.x + (_TeamKnockBack * _DirectionVector.x), currentLevel[0].position.y + (_TeamKnockBack * _DirectionVector.y)].transform.position;
- currentLevel[0].occupant.UpdateTilePosition();
- }
- }
- }
- else {
- currentLevel[0].occupant.health += _EnemyHealthAdditive;
- if (currentLevel[0].occupant != owner && currentLevel[0].position.x >= _EnemyKnockBack * -_DirectionVector.x && currentLevel[0].position.x <= (owner.fieldManager.gridSize.x - 1) - (_EnemyKnockBack * _DirectionVector.x) && currentLevel[0].position.y >= _EnemyKnockBack * -_DirectionVector.y && currentLevel[0].position.y <= (owner.fieldManager.gridSize.y - 1) - (_EnemyKnockBack * _DirectionVector.y)) {
- if (owner.fieldManager.grid[currentLevel[0].position.x + (_EnemyKnockBack * _DirectionVector.x), currentLevel[0].position.y + (_EnemyKnockBack * _DirectionVector.y)].occupant == null) {
- currentLevel[0].occupant.transform.position = owner.fieldManager.grid[currentLevel[0].position.x + (_EnemyKnockBack * _DirectionVector.x), currentLevel[0].position.y + (_EnemyKnockBack * _DirectionVector.y)].transform.position;
- currentLevel[0].occupant.UpdateTilePosition();
- }
- }
- }
- }
- for (int l = 0; l < _AttackRange; ++l) {
- List<TileNode> nextLevel = new List<TileNode>();
- foreach (TileNode curLink in currentLevel) {
- if (curLink.occupant != null && damaged.Contains(curLink.occupant) == false) {
- Vector2Int knockbackDirection = curLink.position - pointOfEffect;
- knockbackDirection.x = Mathf.Clamp(knockbackDirection.x, -1, 1);
- knockbackDirection.y = Mathf.Clamp(knockbackDirection.y, -1, 1);
- damaged.Add(curLink.occupant);
- if (curLink.occupant.playSide == owner.playSide) {
- curLink.occupant.health += _TeamHealthAdditive - (_TeamHealthAdditive / _AttackRange) * l;
- if (curLink.occupant != owner && curLink.position.x >= _TeamKnockBack * -knockbackDirection.x && curLink.position.x <= (owner.fieldManager.gridSize.x - 1) - (_TeamKnockBack * knockbackDirection.x) && curLink.position.y >= _TeamKnockBack * -knockbackDirection.y && curLink.position.y <= (owner.fieldManager.gridSize.y - 1) - (_TeamKnockBack * knockbackDirection.y)) {
- if (owner.fieldManager.grid[curLink.position.x + (_TeamKnockBack * knockbackDirection.x), curLink.position.y + (_TeamKnockBack * knockbackDirection.y)].occupant == null) {
- curLink.occupant.transform.position = owner.fieldManager.grid[curLink.position.x + (_TeamKnockBack * knockbackDirection.x), curLink.position.y + (_TeamKnockBack * knockbackDirection.y)].transform.position;
- curLink.occupant.UpdateTilePosition();
- }
- }
- }
- else {
- curLink.occupant.health += _EnemyHealthAdditive - (_EnemyHealthAdditive / _AttackRange) * l;
- if (curLink.occupant != owner && curLink.position.x >= _EnemyKnockBack * -knockbackDirection.x && curLink.position.x <= (owner.fieldManager.gridSize.x - 1) - (_EnemyKnockBack * knockbackDirection.x) && curLink.position.y >= _EnemyKnockBack * -knockbackDirection.y && curLink.position.y <= (owner.fieldManager.gridSize.y - 1) - (_EnemyKnockBack * knockbackDirection.y)) {
- if (owner.fieldManager.grid[curLink.position.x + (_EnemyKnockBack * knockbackDirection.x), curLink.position.y + (_EnemyKnockBack * knockbackDirection.y)].occupant == null) {
- curLink.occupant.transform.position = owner.fieldManager.grid[curLink.position.x + (_EnemyKnockBack * knockbackDirection.x), curLink.position.y + (_EnemyKnockBack * knockbackDirection.y)].transform.position;
- curLink.occupant.UpdateTilePosition();
- }
- }
- }
- }
- foreach (TileNode nextLink in curLink.links) {
- if (nextLink.occupant != null && damaged.Contains(nextLink.occupant) == false) {
- Vector2Int knockbackDirection = nextLink.position - pointOfEffect;
- knockbackDirection.x = Mathf.Clamp(knockbackDirection.x, -1, 1);
- knockbackDirection.y = Mathf.Clamp(knockbackDirection.y, -1, 1);
- damaged.Add(nextLink.occupant);
- if (nextLink.occupant.playSide == owner.playSide) {
- nextLink.occupant.health += _TeamHealthAdditive - (_TeamHealthAdditive / _AttackRange) * l; ;
- if (nextLink.occupant != owner && nextLink.position.x >= _TeamKnockBack * -knockbackDirection.x && nextLink.position.x <= (owner.fieldManager.gridSize.x - 1) - (_TeamKnockBack * knockbackDirection.x) && nextLink.position.y >= _TeamKnockBack * -knockbackDirection.y && nextLink.position.y <= (owner.fieldManager.gridSize.y - 1) - (_TeamKnockBack * knockbackDirection.y)) {
- if (owner.fieldManager.grid[nextLink.position.x + (_TeamKnockBack * knockbackDirection.x), nextLink.position.y + (_TeamKnockBack * knockbackDirection.y)].occupant == null) {
- nextLink.occupant.transform.position = owner.fieldManager.grid[nextLink.position.x + (_TeamKnockBack * knockbackDirection.x), nextLink.position.y + (_TeamKnockBack * knockbackDirection.y)].transform.position;
- nextLink.occupant.UpdateTilePosition();
- }
- }
- }
- else {
- nextLink.occupant.health += _EnemyHealthAdditive - (_EnemyHealthAdditive / _AttackRange) * l;
- if (nextLink.occupant != owner && nextLink.position.x >= _EnemyKnockBack * -knockbackDirection.x && nextLink.position.x <= (owner.fieldManager.gridSize.x - 1) - (_EnemyKnockBack * knockbackDirection.x) && nextLink.position.y >= _EnemyKnockBack * -knockbackDirection.y && nextLink.position.y <= (owner.fieldManager.gridSize.y - 1) - (_EnemyKnockBack * knockbackDirection.y)) {
- if (owner.fieldManager.grid[nextLink.position.x + (_EnemyKnockBack * knockbackDirection.x), nextLink.position.y + (_EnemyKnockBack * knockbackDirection.y)].occupant == null) {
- nextLink.occupant.transform.position = owner.fieldManager.grid[nextLink.position.x + (_EnemyKnockBack * knockbackDirection.x), nextLink.position.y + (_EnemyKnockBack * knockbackDirection.y)].transform.position;
- nextLink.occupant.UpdateTilePosition();
- }
- }
- }
- }
- nextLevel.Add(nextLink);
- }
- }
- currentLevel = nextLevel;
- }
- if (_TravelToPiont == true && owner.fieldManager.grid[pointOfEffect.x, pointOfEffect.y].occupant == null) {
- owner.transform.position = owner.fieldManager.grid[pointOfEffect.x, pointOfEffect.y].transform.position;
- owner.UpdateTilePosition();
- }
- }
- return true;
- }
- else {
- return false;
- }
- }
- public override void UpdateTileFeedback(CharacterStats owner) {
- switch (owner.moveDirection) {
- case CharacterStats.MoveDirection.Up:
- _DirectionVector = new Vector2Int(0, 1);
- break;
- case CharacterStats.MoveDirection.UpRight:
- _DirectionVector = new Vector2Int(1, 1);
- break;
- case CharacterStats.MoveDirection.Right:
- _DirectionVector = new Vector2Int(1, 0);
- break;
- case CharacterStats.MoveDirection.DownRight:
- _DirectionVector = new Vector2Int(1, -1);
- break;
- case CharacterStats.MoveDirection.Down:
- _DirectionVector = new Vector2Int(0, -1);
- break;
- case CharacterStats.MoveDirection.DownLeft:
- _DirectionVector = new Vector2Int(-1, -1);
- break;
- case CharacterStats.MoveDirection.Left:
- _DirectionVector = new Vector2Int(-1, 0);
- break;
- case CharacterStats.MoveDirection.UpLeft:
- _DirectionVector = new Vector2Int(-1, 1);
- break;
- }
- Vector2Int pointOfEffect = new Vector2Int(owner.currentTile.position.x + (_AttackPoint.x * _DirectionVector.x), owner.currentTile.position.y + (_AttackPoint.y * _DirectionVector.y));
- if (pointOfEffect.x >= 0 && pointOfEffect.x <= owner.fieldManager.gridSize.x - 1 && pointOfEffect.y >= 0 && pointOfEffect.y <= owner.fieldManager.gridSize.y - 1) {
- List<TileNode> currentLevel = new List<TileNode>();
- List<TileNode> covered = new List<TileNode>();
- currentLevel.Add(owner.fieldManager.grid[pointOfEffect.x, pointOfEffect.y]);
- if (_AffectsSelf == false) {
- covered.Add(owner.currentTile);
- }
- if (covered.Contains(currentLevel[0]) == false) {
- covered.Add(currentLevel[0]);
- currentLevel[0].tilePhase = TileNode.Phase.Closed;
- }
- for (int l = 0; l < _AttackRange; ++l) {
- List<TileNode> nextLevel = new List<TileNode>();
- foreach (TileNode curLink in currentLevel) {
- if (covered.Contains(curLink) == false) {
- covered.Add(curLink);
- curLink.tilePhase = TileNode.Phase.Closed;
- }
- foreach (TileNode nextLink in curLink.links) {
- if (covered.Contains(nextLink) == false) {
- covered.Add(nextLink);
- nextLink.tilePhase = TileNode.Phase.Closed;
- }
- nextLevel.Add(nextLink);
- }
- }
- currentLevel = nextLevel;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment