private AiData_PveNpc_Monster_CloseCombat GetAiData(NpcInfo npc) { AiData_PveNpc_Monster_CloseCombat data = npc.GetAiStateInfo().AiDatas.GetData <AiData_PveNpc_Monster_CloseCombat>(); if (null == data) { NpcAiStateInfo info = npc.GetAiStateInfo(); data = new AiData_PveNpc_Monster_CloseCombat(); data.FastMoveImpact = int.Parse(info.AiParam[0]); data.PreAttackImpact = int.Parse(info.AiParam[1]); data.PreAttackDistance = int.Parse(info.AiParam[2]); data.StandShootDistance = int.Parse(info.AiParam[3]); npc.GetAiStateInfo().AiDatas.AddData(data); } return(data); }
private void GoHomeHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (npc.IsDead()) { return; } AiData_PveNpc_Monster_CloseCombat data = GetAiData(npc); if (null != data) { if (null != npc.GetSkillStateInfo().GetImpactInfoById(data.FastMoveImpact)) { ServerNpcStopImpact(npc, data.FastMoveImpact); } if (null != npc.GetSkillStateInfo().GetImpactInfoById(data.PreAttackImpact)) { ServerNpcStopImpact(npc, data.PreAttackImpact); } } ChangeToState(npc, (int)AiStateId.Idle); }
private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (npc.IsDead() || npc.GetSkillStateInfo().IsSkillActivated()) { return; } NpcAiStateInfo info = npc.GetAiStateInfo(); bool goHome = false; AiData_PveNpc_Monster_CloseCombat data = GetAiData(npc); if (null != data) { CharacterInfo target = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(npc, info.Target); if (null != target) { float dist = (float)npc.GetActualProperty().AttackRange; float distGoHome = (float)npc.GohomeRange; Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D(); ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); float powDist = Geometry.DistanceSquare(srcPos, targetPos); float powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos); if (powDist < dist * dist)//进入移动攻击状态 { if (null != npc.GetSkillStateInfo().GetImpactInfoById(data.PreAttackImpact)) { ServerNpcStopImpact(npc, data.PreAttackImpact); } info.Time = 0; data.FoundPath.Clear(); data.Time = (long)(1000.0f / npc.GetActualProperty().Rps); ChangeToState(npc, (int)AiStateId.Combat); } else if (powDist < data.PreAttackDistance * data.PreAttackDistance) //预热状态 { if (null == npc.GetSkillStateInfo().GetImpactInfoById(data.FastMoveImpact)) { ServerNpcImpact(npc, data.FastMoveImpact, npc); } if (null == npc.GetSkillStateInfo().GetImpactInfoById(data.PreAttackImpact)) { ServerNpcImpact(npc, data.PreAttackImpact, npc); } info.Time += deltaTime; if (info.Time > 100) { info.Time = 0; if (AiLogicUtility.GetWalkablePosition(target, npc, ref targetPos)) { AiLogicUtility.PathToTarget(npc, data.FoundPath, targetPos, 100, true, this); } else { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); } } } else if (powDistToHome < distGoHome * distGoHome)//追击 { if (data.TestFlag != 3) { data.TestFlag = 3; } if (null != npc.GetSkillStateInfo().GetImpactInfoById(data.FastMoveImpact)) { ServerNpcStopImpact(npc, data.FastMoveImpact); } if (null != npc.GetSkillStateInfo().GetImpactInfoById(data.PreAttackImpact)) { ServerNpcStopImpact(npc, data.PreAttackImpact); } info.Time += deltaTime; if (info.Time > 100) { info.Time = 0; if (AiLogicUtility.GetWalkablePosition(target, npc, ref targetPos)) { AiLogicUtility.PathToTarget(npc, data.FoundPath, targetPos, 100, true, this); } else { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); } } } else { goHome = true; } } else { goHome = true; } if (goHome) { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); info.Time = 0; ChangeToState(npc, (int)AiStateId.GoHome); } } }