using System.Collections; using System.Collections.Generic; using UnityEngine; namespace TBTK{ public class Attack{ public Ability ability; public Unit srcUnit; public Unit tgtUnit; //private const float overwatchHitPenalty=0.2f; //private const float overwatchHitPenalty=0.2f; public int cover=0; //private const float coverHitPenalty=0.2f; public float hitChance; public float critChance; public bool hit; public bool crit; public float damageHPMin; public float damageHPMax; public float damageAPMin; public float damageAPMax; public float damageHP; public float damageAP; public Attack(Unit sUnit, Unit tUnit, Node srcNode=null, bool isCounter=false, bool isOverwatch=false){ srcUnit=sUnit; tgtUnit=tUnit; if(srcNode==null) srcNode=srcUnit.node; int range=GridManager.GetDistance(srcNode, tgtUnit.node); float srcUnitHit=0; float srcUnitAttack=0; float dmgMultiplier=1; if(srcUnit.hasMeleeAttack && range<=srcUnit.GetAttackRangeMelee()){ srcUnitHit=srcUnit.GetHitM(); srcUnitAttack=srcUnit.GetAttackM(); hitChance=srcUnitHit/(srcUnitHit+tgtUnit.GetDodge()); if(isCounter) hitChance-=srcUnit.GetCHitPenalty(); if(isOverwatch) hitChance-=srcUnit.GetOHitPenalty(); hit=Rand.value()0){ //check side stepping //Debug.DrawLine(srcNode.GetPos(), tgtNode.GetPos(), Color.green, 1); //cant rely on default calculation at diagonal, angle at 45 does not always give the correct adjacent node if((Mathf.Round(GridManager.GetAngle(tgtNode, srcNode, false))-45)%90==0){ float distTH=GridManager.EnableDiagonalNeighbour() ? 1 : 2 ; if(GridManager.GetDistance(srcNode, tgtNode)<=distTH){ Vector3 centerP=(tgtNode.GetPos()+srcNode.GetPos())*0.5f; cover=CheckCoverSideStepping(srcNode, centerP, tgtNode, cover); return cover; } } cover=CheckCoverSideStepping(srcNode, srcNode.GetPos(), tgtNode, cover); } return cover; } public static int CheckCoverSideStepping(Node srcNode, Vector3 origin, Node tgtNode, int cover){ Vector3 dir=(tgtNode.GetPos()-srcNode.GetPos()).normalized; Vector3 dirP=new Vector3(dir.z, 0, -dir.x); float nodeS=GridManager.GetNodeSize(); //Utility.DebugDrawCrossT(origin+dirP*nodeS); Node neighbour=srcNode.GetNeighbourFromPos(origin+dirP*nodeS); if(neighbour!=null && !neighbour.IsBlocked(srcNode)){ //Debug.DrawLine(neighbour.GetPos(), tgtNode.GetPos(), Color.green, 1); int coverAlt1=tgtNode.GetCover(GridManager.GetAngle(tgtNode, neighbour, false)); if(coverAlt10){ //Utility.DebugDrawCrossT(origin-dirP*nodeS); neighbour=srcNode.GetNeighbourFromPos(origin-dirP*nodeS); if(neighbour!=null && !neighbour.IsBlocked(srcNode)){ //Debug.DrawLine(neighbour.GetPos(), tgtNode.GetPos(), Color.green, 1); int coverAlt2=tgtNode.GetCover(GridManager.GetAngle(tgtNode, neighbour, false)); if(coverAlt2