public void CardAttack(int cardDmg, bool weaponAtk, DealDamageDel DamageFunction, RangeDefined range, CardActionExecutor cae, int currentAction) { if (range.IsTileValid == null) //this gets done in TilesInAttack anyway, but whatever { range.IsTileValid = GridHelper.CanAttackThrough; } List <Vector3Int> tiles; if (range.basicRange) { tiles = TilesInBasic(range.allowedDirections); } else { tiles = TilesInAttack(range); } foreach (var tile in tiles) { GridHelper.groundTilemap.SetColor(tile, atkRangeColor); } List <RaycastHit2D> hits = GridHelper.RaycastTiles(tiles); List <IAttackable> targets = new List <IAttackable>(); foreach (var hit in hits) { IAttackable target = hit.collider.gameObject.transform.parent.GetComponent <IAttackable>(); if (target != null) { target.SetAttackableOutline(true); targets.Add(target); } } StartCoroutine(CardAttackRoutine( tiles, (range.basicRange && playerInfo.basicIsPiercing && playerInfo.basicIsStraight) || (!range.basicRange && range.straight && range.piercing), cae, currentAction, cardDmg, weaponAtk, DamageFunction, targets)); }
private IEnumerator CardAttackRoutine(List <Vector3Int> tiles, bool piercing, CardActionExecutor cae, int currentAction, int cardDmg, bool weaponAtk, DealDamageDel DamageFunction, List <IAttackable> targets) { while (true) { if (Input.GetMouseButtonDown(0)) { if (!GridHelper.TileInList(MouseCoords(), tiles)) { CardAttackCancel(); break; } List <RaycastHit2D> hits = GridHelper.RaycastTile(MouseCoords()); if (hits.Count == 0) { CardAttackCancel(); break; } bool landedHit = false; foreach (var hit in hits) { IAttackable target = hit.transform.parent.GetComponent <IAttackable>(); if (target == null) { continue; } landedHit = true; //actually hit something if (piercing) { int targetDir = -1; int basicDist = BasicRange(); List <Vector3Int>[] tilesInDir = new List <Vector3Int> [6]; for (int i = 0; i < 6; ++i) { tilesInDir[i] = GridHelper.TilesInDirection(Coords(), i, basicDist, true, GridHelper.CanAttackThrough); if (GridHelper.TileInList(target.Coords(), tilesInDir[i])) { targetDir = i; break; } } List <RaycastHit2D> hits1 = GridHelper.RaycastTilesNoEmptyHits(tilesInDir[targetDir]); foreach (var dirHit in hits1) { IAttackable piercedTarget = dirHit.transform.parent.GetComponent <IAttackable>(); if (piercedTarget != null) { DamageFunction(cardDmg, piercedTarget, weaponAtk); target.SetAttackableOutline(false); } } } else { DamageFunction(cardDmg, target, weaponAtk); } break; } if (!landedHit) { CardAttackCancel(); break; } CardAttackHide(); cae.cardPlayState[currentAction] = 1; break; } else if (Input.GetMouseButtonDown(1)) { foreach (var tile in tiles) { GridHelper.groundTilemap.SetColor(tile, Color.white); } cae.cardPlayState[currentAction] = 2; break; } yield return(null); } void CardAttackHide() { foreach (var tile in tiles) { GridHelper.groundTilemap.SetColor(tile, Color.white); } foreach (var target in targets) { target.SetAttackableOutline(false); } } void CardAttackCancel() { CardAttackHide(); cae.cardPlayState[currentAction] = 2; } }