public override void Reason(Entity entity) { Entity enemy = SkillProcesser.GetTargetInDistance(entity, entity.blackboard.chaseDist); if (enemy != null) { Debug.Log("切换到 ChaseState"); entity.blackboard.target = enemy; entity.AI.SetTransition(Transition.SawEnemy); } }
//由时间控制的击中事件,一般是近战类攻击击中目标 public void SkillHit(uint skillID, List <Entity> targets = null) { if (targets == null) { Log.Info("技能id = " + skillID + " 没有目标"); return; } CSVSkill skillInfo = CSVManager.GetSkillCfg(skillID); //技能类型(1.普攻 2.物理 3.法术 4.保护 5.治疗 6.辅助 7.召唤 8.被动) if (skillInfo.type <= 3) { for (int i = 0; i < targets.Count; i++) { Entity target = targets[i]; if (target.IsDead || target.invincible) { continue; } //受击动作 if (!string.IsNullOrEmpty(skillInfo.beattackAction)) { target.Anim.SyncAction(skillInfo.beattackAction); } //受击特效 if (!string.IsNullOrEmpty(skillInfo.beattackEffect)) { EffectEntity effect = EffectManager.Instance.GetEffect(skillInfo.beattackEffect); effect.Init(eDestroyType.Time, skillInfo.beattackActionDuration); effect.Pos = target.Pos; effect.Forward = target.Forward; } SkillProcesser.CalcBlood(m_entity, target, skillInfo); } } else if (skillInfo.type <= 6) { //添加增益buff for (int i = 0; i < targets.Count; i++) { } } }
public List <Entity> GetSkillTargets() { m_targets.Clear(); if (IsNormalAttackSkill) //普攻 { if (m_caster.SelectTarget != null && !m_caster.SelectTarget.IsDead) { m_targets.Add(m_caster.SelectTarget); m_caster.Forward = (m_caster.SelectTarget.Pos - m_caster.Pos).normalized; } else { m_caster.SelectTarget = SkillProcesser.GetTargetInSkillDistance(m_caster, m_skillInfo); if (m_caster.SelectTarget != null) { m_targets.Add(m_caster.SelectTarget); m_caster.Forward = (m_caster.SelectTarget.Pos - m_caster.Pos).normalized; } } } else //技能 { if (m_skillInfo.attackType == 1) //单个目标 { if (m_caster.SelectTarget != null && !m_caster.SelectTarget.IsDead) { m_targets.Add(m_caster.SelectTarget); m_caster.Forward = (m_caster.SelectTarget.Pos - m_caster.Pos).normalized; } else { m_caster.SelectTarget = SkillProcesser.GetTargetInSkillDistance(m_caster, m_skillInfo); m_targets.Add(m_caster.SelectTarget); m_caster.Forward = (m_caster.SelectTarget.Pos - m_caster.Pos).normalized; } } else if (m_skillInfo.attackType == 2) //自己 { m_targets.Add(m_caster); } else if (m_skillInfo.attackType == 3) //线性 { var e = EntityManager.Instance.m_dicObject.GetEnumerator(); while (e.MoveNext()) { Entity ent = e.Current.Value; if (m_caster.IsEnemy(ent) == false) { continue; } //自己在纸上画一下就知道啦 /* * v3 v1 \ | \ | \| */ Vector3 v1 = m_caster.Forward; Vector3 v2 = ent.Pos - m_caster.Pos; Vector3 v3 = v2.normalized; float cos_value = Vector3.Dot(v1, v3); float dv = Mathf.Abs(cos_value * cos_value * v2.sqrMagnitude); //forward方向的距离的平方 float sin_value = Mathf.Sin(Mathf.Acos(cos_value)); float dh = Mathf.Abs(sin_value * sin_value * v2.sqrMagnitude); //left、right方向的距离的平方 if (dh <= 1f && dv <= m_skillInfo.attackDistance * m_skillInfo.attackDistance) { m_targets.Add(ent); } } } else if (m_skillInfo.attackType == 4) //扇形,目前都是判断 60度,后续有需求可配表 { var e = EntityManager.Instance.m_dicObject.GetEnumerator(); while (e.MoveNext()) { Entity ent = e.Current.Value; if (m_caster.IsEnemy(ent) == false) { continue; } Vector3 v1 = m_caster.Forward; Vector3 v2 = ent.Pos - m_caster.Pos; if (v2.sqrMagnitude <= m_skillInfo.attackDistance * m_skillInfo.attackDistance) { float cos_value = Vector3.Dot(v1.normalized, v2.normalized); if (cos_value >= Mathf.Cos(Mathf.PI / 3)) // 60度 { m_targets.Add(ent); } } } } else if (m_skillInfo.attackType == 5) //圆形 { //圆形范围技能,一般还要判断作用对象是敌人还是自己人 var e = EntityManager.Instance.m_dicObject.GetEnumerator(); while (e.MoveNext()) { Entity ent = e.Current.Value; if (IsAttackSkill) //如果是攻击性技能,作用对象是敌人 { if (m_caster.IsEnemy(ent) == false) { continue; } } else if (IsAssistSkill) //如果是辅助性技能 { //作用对象是自己人 if (m_caster.IsEnemy(ent) == true) { continue; } } if ((ent.Pos - m_caster.Pos).sqrMagnitude <= m_skillInfo.attackDistance * m_skillInfo.attackDistance) { m_targets.Add(ent); } } } } return(m_targets); }