private bool RangeCheck(ActiveSkill skill, float distSqr) { // ignore range if (!onlyIfWithinRange) { return(true); } // 0 range means infinite range if (skill.GetRange() == 0 || distSqr <= Math.Pow(skill.GetRange(), 2)) { return(true); } return(false); }
public virtual IEnumerator CastSkill(Character target, ActiveSkill sk, float distSqrToTarget, bool noRangeCheck, bool moveTowardsIfRequired = true, float skillRangeAdd = 0, float randomSkilLRangeAdd = 0) { int range = sk.GetRange(); if (target != null) { if (!noRangeCheck && range != 0) { while (Mathf.Pow((range + Random.Range(-randomSkilLRangeAdd, randomSkilLRangeAdd)), 2) * (0.6f + skillRangeAdd) < distSqrToTarget) { distSqrToTarget = Utils.DistanceSqr(target.GetData().transform.position, Owner.GetData().transform.position); if (moveTowardsIfRequired) { MoveTo(target); yield return(null); } else // too far, cant move closer - break the action { currentAction = null; yield break; } } } if (GetTemplate().TargetRotationSpeed > 0) { // not rotated towards target if (!Owner.GetData().IsRotatedTowards(target.GetData().GetBody().transform.position, 3)) { Owner.GetData().Rotate(target.GetData().GetBody().transform.position, GetTemplate().TargetRotationSpeed); while (Owner.GetData().IsRotating()) { // wait till rotation is finished yield return(null); } } } } Owner.GetData().BreakMovement(true); if (target != null) { if (GetTemplate().TargetRotationSpeed < 0) { RotateToTarget(target); } else { UpdateDirection(target); } } Owner.CastSkill(sk); currentAction = null; }
public virtual IEnumerator CastSkill(Vector3 target, ActiveSkill sk, float distSqrToTarget, bool noRangeCheck, bool moveTowardsIfRequired, float skillRangeAdd = 0, float randomSkilLRangeAdd = 0) { int range = sk.GetRange(); if (!noRangeCheck && range != 0) { while (Mathf.Pow((range + Random.Range(-randomSkilLRangeAdd, randomSkilLRangeAdd)), 2) < distSqrToTarget) { //distSqrToTarget = Vector3.Distance(target, Owner.GetData().transform.position); distSqrToTarget = Utils.DistanceSqr(target, Owner.GetData().transform.position); if (moveTowardsIfRequired) { MoveTo(target); //TODO not working with pathnodes - replace with setmovementtarget yield return(null); } else // too far, cant move closer - break the action { currentAction = null; yield break; } } } if (GetTemplate().TargetRotationSpeed > 0) { // not rotated towards target if (!Owner.GetData().IsRotatedTowards(target, 3)) { Owner.GetData().Rotate(target, GetTemplate().TargetRotationSpeed); while (Owner.GetData().IsRotating()) { // wait till rotation is finished yield return(null); } } } Owner.GetData().BreakMovement(true); if (GetTemplate().TargetRotationSpeed < 0) { RotateToTarget(target); } else { UpdateDirection(target); } Owner.CastSkill(sk, null, true); currentAction = null; }
protected override void AttackTarget(Character target) { //SetMainTarget(target); bool isCasting = Owner.GetData().IsCasting; bool isMeleeAttacking = Owner.GetData().IsMeleeAttacking(); //float distSqr = Utils.DistanceObjectsSqr(Owner.GetData().GetBody(), target.GetData().GetBody()); float distSqr = Utils.DistanceSqr(Owner.GetData().GetBody().transform.position, target.GetData().GetBody().transform.position); int hpPercentage = (int)((GetStatus().Hp / (float)GetStatus().MaxHp) * 100); if (isCasting) { ActiveSkill castedSkill = null; foreach (ActiveSkill sk in Owner.Status.ActiveSkills) { if (sk.HasTrait(SkillTraits.BuffDamage) || sk.HasTrait(SkillTraits.BuffDefense)) { castedSkill = sk; break; } } if (castedSkill != null) { GameObject initTarget = castedSkill.InitTarget; if (initTarget != null) { float dist = Utils.DistanceSqr(Owner.GetData().GetBody().transform.position, initTarget.transform.position); if (dist > Math.Pow(castedSkill.GetRange(), 2)) { castedSkill.AbortCast(); } } } } // already doing something if (isCasting || Owner.Status.IsStunned()) { return; } if (Owner.GetData().Target == null || Owner.GetData().Target.Equals(target.GetData().GetBody())) { Owner.GetData().Target = target.GetData().GetBody(); } Collider2D[] colls = Physics2D.OverlapCircleAll(Owner.GetData().transform.position, AggressionRange * 3); List <Character> targets = new List <Character>(); foreach (Collider2D coll in colls) { if (coll.gameObject == null) { continue; } Character ch = Utils.GetCharacter(coll.gameObject); if (ch != null) { if (!Owner.CanAttack(ch) && !Owner.Equals(ch) && !ch.IsInteractable()) { targets.Add(ch); } } } Character supportTarget = SelectSupportTarget(targets); if (supportTarget != null) { // try spawn skills List <Skill> supportSkills = GetAllSkillsWithTraitOr(SkillTraits.BuffDefense, SkillTraits.BuffDamage); foreach (Skill s in supportSkills) { if (s.CanUse()) { Owner.GetData().Target = supportTarget.GetData().GetBody(); if (StartAction(CastSkill(supportTarget, (ActiveSkill)s, Utils.DistanceSqr(supportTarget.GetData().transform.position, Owner.GetData().GetBody().transform.position), false, true, 0, 0), 0.5f)) { return; } } } //TODO add buffdamage skills support } if (LaunchAttackModule(target, distSqr, hpPercentage)) { return; } }
public override bool Trigger(Character target, float distSqr) { if (minRangeToTeleport < 0 || distSqr >= (minRangeToTeleport * minRangeToTeleport)) { if (maxRangeToTeleport < 0 || distSqr <= (maxRangeToTeleport * maxRangeToTeleport)) { ActiveSkill teleport = (ActiveSkill)ai.GetSkillWithTrait(SkillTraits.Teleport); // if range too high, teleport if (teleport.CanUse() && !ai.Owner.GetData().forcedVelocity&& (!checkTeleportSkillRange || (distSqr >= ((Math.Pow(teleport.GetRange(), 2)) / 4f) && distSqr <= (Math.Pow(teleport.GetRange(), 2))))) { if (ai.StartAction(ai.CastSkill(target, teleport, distSqr, true, false, 0f, 0f), 0.5f)) { return(true); } } } } return(false); }