private void SelectDamageObj(EntityBase attacker, SkillDataCfg skillCfg, int skillIdx) { SkillActionCfg actionCfg = resSvc.GetSkillActionCfg(skillCfg.skillActionList[skillIdx]); int damageVal = skillCfg.skillDamageList[skillIdx]; if (attacker._entityType == Constants.EntityType.Monster) { EntityPlayer entityPlayer = attacker._battleMgr.GetEntityPlayer; if (entityPlayer == null) { return; } if (InRange(attacker.GetEntityPosition(), entityPlayer.GetEntityPosition(), actionCfg.radius) && InAngle(attacker.GetEntityTransform(), entityPlayer.GetEntityPosition(), actionCfg.angle)) { CalcDamage(attacker, entityPlayer, skillCfg, damageVal); } } else if (attacker._entityType == Constants.EntityType.Player) { //获取场景中所有的怪物 List <EntityMonster> listMonster = attacker._battleMgr.GetAllEntityMonsters(); for (int i = 0; i < listMonster.Count; i++) { EntityMonster monster = listMonster[i]; //在攻击范围内 if (InRange(attacker.GetEntityPosition(), monster.GetEntityPosition(), actionCfg.radius) && InAngle(attacker.GetEntityTransform(), monster.GetEntityPosition(), actionCfg.angle)) { CalcDamage(attacker, monster, skillCfg, damageVal); } } } }
public override Vector2 CalcTargetDirection() { EntityPlayer player = _battleMgr.GetEntityPlayer; if (player == null || player._currentPlayerAniState == PlayerAniState.Die) { bRunAI = false; return(Vector2.zero); } Vector3 targetDir = player.GetEntityPosition(); Vector3 vecSelf = GetEntityPosition(); return(new Vector2(targetDir.x - vecSelf.x, targetDir.z - vecSelf.z).normalized); }
private bool InAttackRange() { EntityPlayer player = _battleMgr.GetEntityPlayer; if (player == null || player._currentPlayerAniState == PlayerAniState.Die) { bRunAI = false; return(false); } Vector3 targetDir = player.GetEntityPosition(); Vector3 vecSelf = GetEntityPosition(); //排除y方向 targetDir.y = 0; vecSelf.y = 0; float distance = Vector3.Distance(targetDir, vecSelf); return(distance <= monsterData.cfg.atkDistance); }