public MeleeAttackBehaviour(GameEntity entity, Transform transform) : base(entity, transform) { movement = entity.movement; combat = entity.combat; sensing = entity.sensing; unitAI = entity.unitAI; nextUpdateDestinationTime = Random.Range(0, updateDestinationInterval); }
void Start() { if (playerEntity != null) { health = playerEntity.GetComponent <EC_Health>(); movement = playerEntity.GetComponent <EC_Movement>(); combat = playerEntity.GetComponent <EC_Combat>(); unitAnimation = playerEntity.GetComponent <EC_UnitAnimation>(); unitAI = playerEntity.GetComponent <EC_UnitAI>(); } }
//2. weapon lands on the target- what now? void MA_DetermineAttackOutcome() { //TODO make a bounds check here - draw the bounds with on Gizmo Draw, the bounds are saved in the CA_Attack object List <GameEntity> surroundingEnemies = new List <GameEntity>(); int layerMask1 = 1 << 12; int layerMask2 = 1 << 13; int layerMask = layerMask1 | layerMask2;; //sphere for now, later box Collider[] nearestUnits = Physics.OverlapSphere(myTransform.TransformPoint(currentAttack.hitSpherePosition), currentAttack.hitSphereRadius, layerMask); drawDamageBoxGizmo = true; gizmoPosition = myTransform.TransformPoint(currentAttack.hitSpherePosition); gizmoRadius = currentAttack.hitSphereRadius; currentTarget = null; if (nearestUnits.Length > 0) { if (nearestUnits[0] != myCollider) { currentTarget = nearestUnits[0].GetComponent <GameEntity>(); } else if (nearestUnits.Length > 1) { if (nearestUnits[1] != null) { currentTarget = nearestUnits[1].GetComponent <GameEntity>(); } } } if (currentTarget != null) { //TODO if the block is sucessful is dependant on skills levels //for now only one enemy currentTargetsCombat = currentTarget.combat; currentTargetsUnitAI = currentTarget.unitAI; currentTargetsHealth = currentTarget.health; if (currentTargetsCombat != null) { //TODO is the vector angle check the most performant one? if (currentTargetsCombat.currentCombatState == CombatState.Blocking && Vector3.Angle(currentTarget.transform.forward, -myTransform.forward) < currentTargetsCombat.currentBlock.blockCoveringAngle) { MA_AttackFlinch(); currentTargetsUnitAI.OnEnemyWasBlockedByMe(); } else { MA_FinishAttack(); } } else //if the target does not have any combat, just deal the damage { currentTargetsHealth.TakeDamage(currentAttack.meleeDamage); } } else { GoBackToIdle(); } }