private void MoveHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (user.IsDead()) { return; } UserAiStateInfo info = user.GetAiStateInfo(); AiData_UserSelf_General data = GetAiData(user); Vector3 targetPos = info.TargetPos; ScriptRuntime.Vector3 srcPos = user.GetMovementStateInfo().GetPosition3D(); if (null != data && !IsReached(srcPos, targetPos)) { if (info.IsTargetPosChanged) { info.IsTargetPosChanged = false; data.FoundPath.Clear(); } PathToTarget(user, data.FoundPath, targetPos, deltaTime); } else { user.GetMovementStateInfo().StopMove(); NotifyUserMove(user); info.Time = 0; data.Time = 0; data.FoundPath.Clear(); ChangeToState(user, (int)AiStateId.Idle); } }
private AiData_UserSelf_General GetAiData(UserInfo user) { AiData_UserSelf_General data = user.GetAiStateInfo().AiDatas.GetData <AiData_UserSelf_General>(); if (null == data) { data = new AiData_UserSelf_General(); user.GetAiStateInfo().AiDatas.AddData(data); } return(data); }
private void StopFindPath(UserInfo playerself, UserAiStateInfo aiInfo) { if (null == playerself || null == aiInfo) { return; } AiData_UserSelf_General data = playerself.GetAiStateInfo().AiDatas.GetData <AiData_UserSelf_General>(); if (null == data) { data = new AiData_UserSelf_General(); playerself.GetAiStateInfo().AiDatas.AddData(data); } playerself.GetMovementStateInfo().IsMoving = false; aiInfo.Time = 0; data.Time = 0; data.FoundPath.Clear(); aiInfo.ChangeToState((int)AiStateId.Idle); }
internal static void Execute(object msg, User user) { Msg_CR_UserMoveToAttack attack_msg = msg as Msg_CR_UserMoveToAttack; if (attack_msg == null) { return; } UserInfo charactor = user.Info; if (charactor == null) { LogSys.Log(LOG_TYPE.ERROR, "charactor {0} not exist", user.RoleId); return; } /// if (charactor.GetAIEnable()) { MovementStateInfo msi = charactor.GetMovementStateInfo(); msi.PositionX = attack_msg.cur_pos_x; msi.PositionZ = attack_msg.cur_pos_z; UserAiStateInfo aiInfo = charactor.GetAiStateInfo(); AiData_UserSelf_General data = charactor.GetAiStateInfo().AiDatas.GetData <AiData_UserSelf_General>(); if (null == data) { data = new AiData_UserSelf_General(); charactor.GetAiStateInfo().AiDatas.AddData(data); } charactor.GetMovementStateInfo().IsMoving = false; data.FoundPath.Clear(); aiInfo.Time = 0; aiInfo.Target = attack_msg.target_id; aiInfo.IsAttacked = false; aiInfo.AttackRange = attack_msg.attack_range; aiInfo.ChangeToState((int)AiStateId.Combat); } }
private void CombatHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (user.IsDead()) { return; } UserAiStateInfo info = user.GetAiStateInfo(); info.Time += deltaTime; if (info.Time > 100) { AiData_UserSelf_General data = GetAiData(user); if (null != data) { data.Time += info.Time; info.Time = 0; /// CharacterInfo target = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(user, info.Target); Vector3 targetPos = Vector3.Zero; float dist = info.AttackRange; if (null != target) { targetPos = target.GetMovementStateInfo().GetPosition3D(); } else { targetPos = info.TargetPos; } Vector3 srcPos = user.GetMovementStateInfo().GetPosition3D(); float powDist = Geometry.DistanceSquare(srcPos, targetPos); if (!info.IsAttacked) { if (powDist < dist * dist) { data.Time = 0; info.AttackRange = 0; info.IsAttacked = true; float dir = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); user.GetMovementStateInfo().SetFaceDir(dir); user.GetMovementStateInfo().SetMoveDir(dir); if (null != target) { if (null != OnUserStartAttack) { OnUserStartAttack(user, targetPos.X, targetPos.Y, targetPos.Z); } } else { if (null != OnUserSkill) { OnUserSkill(user); } } /// user.GetMovementStateInfo().StopMove(); NotifyUserMove(user); info.Time = 0; data.FoundPath.Clear(); ChangeToState(user, (int)AiStateId.Idle); } else { if (null != OnSkillPursuit) { OnSkillPursuit(user); } user.GetMovementStateInfo().StopMove(); NotifyUserMove(user); info.Time = 0; info.IsAttacked = false; data.FoundPath.Clear(); ChangeToState(user, (int)AiStateId.Pursuit); } } } else { info.Time = 0; } } }
private void PursuitHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (user.IsDead()) { return; } UserAiStateInfo info = user.GetAiStateInfo(); AiData_UserSelf_General data = GetAiData(user); if (null != data) { if (info.Target > 0) { CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(user, info.Target); if (null != target) { float dist = info.AttackRange - 1.0f; Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D(); ScriptRuntime.Vector3 srcPos = user.GetMovementStateInfo().GetPosition3D(); float powDist = Geometry.DistanceSquare(srcPos, targetPos); if (powDist < dist * dist) { user.GetMovementStateInfo().IsMoving = false; info.Time = 0; data.Time = 0; ChangeToState(user, (int)AiStateId.Combat); NotifyUserMove(user); } else { info.Time += deltaTime; if (info.Time > 100) { info.Time = 0; CharacterInfo target2 = GetCanAttackUserTarget(user); if (null == target2) { AiLogicUtility.GetNearstTargetHelper(user, CharacterRelation.RELATION_ENEMY); } if (null == target2 || target == target2) { PathToTarget(user, data.FoundPath, targetPos, deltaTime); } else { info.Target = target2.GetId(); return; } } } } else { user.GetMovementStateInfo().StopMove(); NotifyUserMove(user); info.Time = 0; data.Time = 0; data.FoundPath.Clear(); ChangeToState(user, (int)AiStateId.Idle); } } else { float dist = info.AttackRange; Vector3 targetPos = info.TargetPos; ScriptRuntime.Vector3 srcPos = user.GetMovementStateInfo().GetPosition3D(); float powDist = Geometry.DistanceSquare(srcPos, targetPos); if (powDist < dist * dist) { user.GetMovementStateInfo().IsMoving = false; info.Time = 0; data.Time = 0; ChangeToState(user, (int)AiStateId.Combat); NotifyUserMove(user); } else { info.Time += deltaTime; if (info.Time > 100) { info.Time = 0; PathToTarget(user, data.FoundPath, targetPos, deltaTime); } } } } }