public void Tick() { if (0 == m_LastTickTime) { m_LastTickTime = TimeUtility.GetServerMilliseconds(); LogSystem.Debug("MovementSystem LastTickTime:{0}", m_LastTickTime); } else { long delta = TimeUtility.GetServerMilliseconds() - m_LastTickTime; m_LastTickTime = TimeUtility.GetServerMilliseconds(); if (delta > 1000) { delta = 1000; } if (null != m_NpcMgr) { for (LinkedListNode <NpcInfo> node = m_NpcMgr.Npcs.FirstValue; null != node; node = node.Next) { NpcInfo npc = node.Value; if (null != npc) { MoveNpc(npc, delta); /* * npc.TransformShape(); * if (null != npc.SceneContext.SightManager) { * npc.SceneContext.SightManager.UpdateObject(npc); * } */ } } } if (null != m_UserMgr) { for (LinkedListNode <UserInfo> node = m_UserMgr.Users.FirstValue; null != node; node = node.Next) { UserInfo user = node.Value; if (null != user) { MoveUser(user, delta); /* * user.TransformShape(); * if (null != user.SceneContext.SightManager) { * user.SceneContext.SightManager.UpdateObject(user); * } */ } } } } }
private void IdleHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (!CanAiControl(npc)) { npc.GetMovementStateInfo().IsMoving = false; return; } NpcAiStateInfo info = npc.GetAiStateInfo(); info.Time += deltaTime; if (info.Time > 100) { info.Time = 0; if (GetAiData(npc).HasPatrolData) { npc.GetMovementStateInfo().IsMoving = false; ChangeToState(npc, (int)AiStateId.PatrolCommand); } else { CharacterInfo target = null; if (info.IsExternalTarget) { target = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(npc, info.Target); if (null == target) { target = AiLogicUtility.GetNearstTargetHelper(npc, CharacterRelation.RELATION_ENEMY); if (null != target) { info.Target = target.GetId(); } } } else { target = AiLogicUtility.GetNearstTargetHelper(npc, CharacterRelation.RELATION_ENEMY); if (null != target) { info.Target = target.GetId(); } } if (null != target) { NotifyNpcTargetChange(npc); npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); info.Time = 0; ChangeToState(npc, (int)AiStateId.Pursuit); } } } }
public override void OnEvent(NpcInfo npc, int eventId, CharacterInfo target, long deltaTime) { AiData_Npc_ActionDrive data = GetAiData(npc); if (null != data) { NormalForceStopHandler(npc); switch (eventId) { case (int)AiEventEnum.CONTROL_TIME_OVERFLOW: if (data.MaxControlEventActions.Count > 0) { data.ActionStack.Clear(); } int plusActionCount = data.MaxControlEventPlusActions.Count; if (plusActionCount > 0) { data.ActionStack.Push(data.MaxControlEventPlusActions[CrossEngineHelper.Random.Next(plusActionCount)]); } for (int i = data.MaxControlEventActions.Count - 1; i >= 0; --i) { if (data.MaxControlEventActions[i].IsSatifyCD(TimeUtility.GetServerMilliseconds()) && data.MaxControlEventActions[i].IsLuckyEnough()) { data.ActionStack.Push(data.MaxControlEventActions[i]); } } break; case (int)AiEventEnum.GET_UP: if (data.GetUpEventActions.Count > 0) { data.ActionStack.Clear(); } for (int i = data.GetUpEventActions.Count - 1; i >= 0; --i) { if (data.GetUpEventActions[i].IsSatifyCD(TimeUtility.GetServerMilliseconds()) && data.GetUpEventActions[i].IsLuckyEnough()) { data.ActionStack.Push(data.GetUpEventActions[i]); } } break; } if (data.ActionStack.Count > 0) { data.ActiveAction = data.ActionStack.Pop(); } ExecAiAction(npc, target, deltaTime); } }
private void ChangeCameraToPartner(ArenaStateInfo state) { NpcInfo not_dead_partner = FindNotdeadPartner(state.CreatedPartners); if (not_dead_partner != null) { NpcView view = EntityManager.Instance.GetNpcViewById(not_dead_partner.GetId()); if (view != null) { GfxSystem.SendMessage("GfxGameRoot", "CameraFollow", view.Actor); state.CurCameraTargetPartner = not_dead_partner.GetId(); } } }
private void OnDropoutPlayEffect(UserInfo user, NpcInfo npc, string effect, string path, int dropType, int dropNum) { CharacterView view = EntityManager.Instance.GetCharacterViewById(user.GetId()); if (null != view) { if (!String.IsNullOrEmpty(effect)) { GfxSystem.CreateAndAttachGameObject(effect, view.Actor, path, 1.0f); } GfxSystem.PlaySound(view.Actor, "Sound/Scene/UI_UP_PickupMoney", user.GetMovementStateInfo().GetFaceDir()); } Network.NetworkSystem.Instance.SyncPickUpNpc(npc); }
public bool TryCastSkill(NpcInfo npc, int skillId, CharacterInfo target, bool needFaceToTarget = true) { if (AiLogicUtility.CanCastSkill(npc, skillId, target)) { float angle = Geometry.GetYAngle(npc.GetMovementStateInfo().GetPosition2D(), target.GetMovementStateInfo().GetPosition2D()); NotifyNpcFace(npc, angle); if (!needFaceToTarget || Math.Abs(npc.GetMovementStateInfo().GetFaceDir() - angle) < 0.1) { NotifyNpcSkill(npc, skillId); return(true); } } return(false); }
private bool GetEscapeTargetPos(NpcInfo npc, CharacterInfo target, float dis, float anglePlus, ref Vector3 escapePos) { Vector3 targetPos = Vector3.Zero; Vector3 sourcePos = npc.GetMovementStateInfo().GetPosition3D(); float angle = Geometry.GetYAngle(target.GetMovementStateInfo().GetPosition2D(), npc.GetMovementStateInfo().GetPosition2D()); angle += CrossEngineHelper.DegreeToRadian(anglePlus); targetPos.X = sourcePos.X + dis * (float)Math.Sin(angle); targetPos.Y = sourcePos.Y; targetPos.Z = sourcePos.Z + dis * (float)Math.Cos(angle); bool isFind = AiLogicUtility.GetWalkablePosition(npc.SpatialSystem.GetCellMapView(npc.AvoidanceRadius), targetPos, sourcePos, ref escapePos); return(isFind); }
internal void CreateNpcView(int objId) { if (!m_NpcViews.ContainsKey(objId)) { NpcInfo obj = WorldSystem.Instance.NpcManager.GetNpcInfo(objId); if (null != obj) { NpcView view = new NpcView(); view.Create(obj); m_NpcViews.Add(objId, view); } WorldSystem.Instance.SyncGfxNpcInfo(objId); } }
private void NormalActionStartHandler(NpcInfo npc, CharacterInfo target) { NpcAiStateInfo info = npc.GetAiStateInfo(); AiData_Npc_ActionDrive data = GetAiData(npc); if (null != data && null != target) { AiActionInfo aiActionInfo = data.ActiveAction; if (null != aiActionInfo) { //aiActionInfo.LastStartTime = TimeUtility.GetServerMilliseconds(); aiActionInfo.StartTime = TimeUtility.GetServerMilliseconds(); } } }
public NpcInfo GetNpcInfoByUnitId(int id) { NpcInfo npc = null; for (LinkedListNode <NpcInfo> linkNode = m_Npcs.FirstValue; null != linkNode; linkNode = linkNode.Next) { NpcInfo info = linkNode.Value; if (info.GetUnitId() == id) { npc = info; break; } } return(npc); }
public bool HasCombatNpcAlive() { bool result = false; for (LinkedListNode <NpcInfo> linkNode = m_Npcs.FirstValue; null != linkNode; linkNode = linkNode.Next) { NpcInfo npc = linkNode.Value; if (null != npc && npc.IsCombatNpc() && !npc.IsDead()) { result = true; break; } } return(result); }
private void PathFindingCommandHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { // Path has found. if (!npc.UnityPathFinding) { return; } if (npc.PathFindingFinished) { // npc.PathFindingFinished = false; NpcAiStateInfo info = npc.GetAiStateInfo(); ChangeToState(npc, info.PreviousState); } }
private bool IsAiActionSatifyWithOutProbability(NpcInfo npc, CharacterInfo target, AiActionInfo aiActionInfo) { Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D(); Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); float dist = Geometry.Distance(srcPos, targetPos); if (aiActionInfo.IsSatifyCD(TimeUtility.GetServerMilliseconds()) && aiActionInfo.IsSatifyDis(dist) && aiActionInfo.IsSatisfySelfHp(npc.Hp, npc.GetActualProperty().HpMax) && aiActionInfo.IsSatisfyTargetHp(target.Hp, target.GetActualProperty().HpMax) && aiActionInfo.IsSatifyUser(npc)) { return(true); } return(false); }
protected virtual void OnStateLogicInit(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { NpcAiStateInfo info = npc.GetAiStateInfo(); info.Time = 0; npc.GetMovementStateInfo().IsMoving = false; info.HomePos = npc.GetMovementStateInfo().GetPosition3D(); info.Target = 0; if (!string.IsNullOrEmpty(info.AiParam[0])) { if (int.Parse(info.AiParam[0]) == 1) { AiLogicUtility.InitPatrolData(npc, this); } } }
private NpcInfo NewNpcInfo(int id) { NpcInfo npc = null; if (m_UnusedNpcs.Count > 0) { npc = m_UnusedNpcs.Dequeue(); npc.Reset(); npc.InitId(id); } else { npc = new NpcInfo(id); } return(npc); }
public override void Execute(SceneLogicInfo info, long deltaTime) { if (null == info || info.IsLogicFinished || info.IsLogicPaused) { return; } info.Time += deltaTime; if (info.Time > 100) { NpcInAreaLogicInfo data = info.LogicDatas.GetData <NpcInAreaLogicInfo>(); if (null == data) { data = new NpcInAreaLogicInfo(); info.LogicDatas.AddData <NpcInAreaLogicInfo>(data); SceneLogicConfig sc = info.SceneLogicConfig; if (null != sc) { if (null != sc) { List <float> pts = Converter.ConvertNumericList <float>(sc.m_Params[0]); data.m_Area = new Vector3[pts.Count / 2]; for (int ix = 0; ix < pts.Count - 1; ix += 2) { data.m_Area[ix / 2].X = pts[ix]; data.m_Area[ix / 2].Z = pts[ix + 1]; } } } } info.Time = 0; if (null != data) { info.SpatialSystem.VisitObjectOutPolygon(data.m_Area, (float distSqr, ArkCrossEngineSpatial.ISpaceObject obj) => { if (obj.GetObjType() == ArkCrossEngineSpatial.SpatialObjType.kNPC) { NpcInfo npc = obj.RealObject as NpcInfo; if (null != npc && !npc.IsDead()) { npc.SetHp(Operate_Type.OT_Absolute, 0); SceneLogicSendStoryMessage(info, "npcleavearea", npc.GetId()); } } }); } } }
private void ExecuteCommandQueue(NpcInfo npc, long deltaTime) { NpcAiStateInfo npcAi = npc.GetAiStateInfo(); while (npcAi.CommandQueue.Count > 0) { IAiCommand cmd = npcAi.CommandQueue.Peek(); if (cmd.Execute(deltaTime)) { npcAi.CommandQueue.Dequeue(); } else { break; } } }
public void VisitWatchingObjUsers(CharacterInfo obj, MyAction <UserInfo> visitor) { int objId = obj.GetId(); NpcInfo npc = obj.CastNpcInfo(); if (null != npc && npc.NpcType == (int)NpcTypeEnum.PvpTower) { for (LinkedListNode <UserInfo> node = obj.UserManager.Users.FirstValue; null != node; node = node.Next) { UserInfo user = node.Value; if (null != user) { visitor(user); } } } else { if (obj.CurBlueCanSeeMe) { int campId = (int)CampIdEnum.Blue; List <UserInfo> list = null; if (camp_users_.TryGetValue(campId, out list)) { int ct = list.Count; for (int i = 0; i < ct; ++i) { visitor(list[i]); } } } if (obj.CurRedCanSeeMe) { int campId = (int)CampIdEnum.Red; List <UserInfo> list; if (camp_users_.TryGetValue(campId, out list)) { int ct = list.Count; for (int i = 0; i < ct; ++i) { visitor(list[i]); } } } } }
public void NotifyNpcFace(NpcInfo npc, float faceDirection = 0.0f) { if (GlobalVariables.Instance.IsClient) { if (null != OnNpcFaceClient) { OnNpcFaceClient(npc, faceDirection); } } else { npc.GetMovementStateInfo().SetFaceDir(faceDirection); } if (null != OnNpcFace) { OnNpcFace(npc); } }
public void UpdateTarget(NpcInfo npc) { if (npc.GetAIEnable()) { NpcAiStateInfo npcAi = npc.GetAiStateInfo(); long curTime = TimeUtility.GetServerMilliseconds(); if (npcAi.Target > 0) { if (curTime > npcAi.LastChangeTargetTime + m_ChangeTargetCD && curTime > npc.GetCombatStatisticInfo().LastHitTime + m_MaxChaseTime) { npcAi.Target = 0; NotifyNpcTargetChange(npc); npcAi.LastChangeTargetTime = curTime; LogSystem.Debug("Npc {0} changed target", npc.GetId()); } } } }
private void NormalForceStopHandler(NpcInfo npc) { NpcAiStateInfo info = npc.GetAiStateInfo(); AiData_Npc_ActionDrive data = GetAiData(npc); if (null != data) { npc.GetMovementStateInfo().IsMoving = false; npc.IsTaunt = false; NotifyNpcRun(npc); AiActionInfo aiActionInfo = data.ActiveAction; if (null != aiActionInfo) { data.ActiveAction = null; aiActionInfo.LastStartTime = TimeUtility.GetServerMilliseconds(); } } }
private void NpcSkill(NpcInfo npc, int skillId) { if (null != npc) { if (npc.SkillController != null) { SkillInfo skillInfo = npc.GetSkillStateInfo().GetSkillInfoById(skillId); if (null != skillInfo) { long curTime = TimeUtility.GetServerMilliseconds(); if (!skillInfo.IsInCd(curTime / 1000.0f)) { npc.SkillController.ForceStartSkill(skillId); skillInfo.BeginCD(); } } } } }
internal void Create(NpcInfo npc) { Init(); if (null != npc) { m_Npc = npc; ObjectInfo.UnitId = m_Npc.GetUnitId(); ObjectInfo.CampId = m_Npc.GetCampId(); ObjectInfo.LinkId = m_Npc.GetLinkId(); MovementStateInfo msi = m_Npc.GetMovementStateInfo(); Vector3 pos = msi.GetPosition3D(); float dir = msi.GetFaceDir(); CreateActor(m_Npc.GetId(), m_Npc.GetModel(), pos, dir, m_Npc.Scale); npc.ActorId = Actor; ObjectInfo.IsNpc = true; CreateBornEffect(Actor, npc.GetBornEffect(), npc.ParticleScale, npc.GetBornEffectTime()); InitAnimationSets(); } }
public void RemoveNpc(int id) { NpcInfo npc = GetNpcInfo(id); if (null != npc) { if (null != m_SceneContext && null != m_SceneContext.SpatialSystem) { m_SceneContext.SpatialSystem.RemoveObj(npc.SpaceObject); } if (null != m_SceneContext && null != m_SceneContext.SightManager) { m_SceneContext.SightManager.RemoveObject(npc); } m_Npcs.Remove(id); npc.SceneContext = m_SceneContext; RecycleNpcInfo(npc); } }
public NpcInfo GetNearest(Vector3 pos, ref float minPowDist) { NpcInfo result = null; float powDist = 0.0f; for (LinkedListNode <NpcInfo> linkNode = m_Npcs.FirstValue; null != linkNode; linkNode = linkNode.Next) { NpcInfo npc = linkNode.Value; if (null != npc && npc.IsCombatNpc()) { powDist = Geometry.DistanceSquare(pos, npc.GetMovementStateInfo().GetPosition3D()); if (minPowDist > powDist) { result = npc; minPowDist = powDist; } } } return(result); }
private void RecycleNpcInfo(NpcInfo npcInfo) { if (null != npcInfo) { int id = npcInfo.GetId(); if (id >= c_StartId && id < c_StartId + c_MaxIdNum) { m_UnusedIds.Push(id); } if (id >= c_StartId_Client && id < c_StartId_Client + c_MaxIdNum) { m_UnusedClientIds.Push(id); } if (m_UnusedNpcs.Count < m_NpcPoolSize) { npcInfo.Reset(); m_UnusedNpcs.Enqueue(npcInfo); } } }
private void MoveNpc(NpcInfo obj, long deltaTime) { if (obj.IsHaveStateFlag(CharacterState_Type.CST_Sleep) || obj.IsHaveStateFlag(CharacterState_Type.CST_FixedPosition) || null != obj.ControllerObject) { return; } MovementStateInfo msi = obj.GetMovementStateInfo(); //npc执行移动时忽略阻挡与避让,这些行为由ai模块在规划其路径时执行。 if (!obj.IsDead() && obj.CanMove && msi.IsMoving && !msi.IsSkillMoving) { Vector3 pos = msi.GetPosition3D(); float cos_angle = (float)msi.MoveDirCosAngle; float sin_angle = (float)msi.MoveDirSinAngle; float speed = (float)obj.GetActualProperty().MoveSpeed *(float)obj.VelocityCoefficient; float distance = (speed * (float)(int)deltaTime) / 1000.0f; //LogSystem.Debug("MovementSystem npc:{0} speed:{1} deltaTime:{2} distance:{3}", obj.GetId(), speed, deltaTime, distance); float x = 0, y = 0; if (msi.CalcDistancSquareToTarget() < distance * distance) { x = msi.TargetPosition.X; y = msi.TargetPosition.Z; AdjustPosition(obj.SpatialSystem, ref x, ref y); Vector2 newPos = new Vector2(x, y); msi.SetPosition2D(newPos); } else { float len = pos.Length(); y = pos.Z + distance * cos_angle; x = pos.X + distance * sin_angle; AdjustPosition(obj.SpatialSystem, ref x, ref y); Vector2 newPos = new Vector2(x, y); msi.SetPosition2D(newPos); } } }
private void PursuitHandler(NpcInfo npc, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (!CanAiControl(npc)) { npc.GetMovementStateInfo().IsMoving = false; return; } NpcAiStateInfo info = npc.GetAiStateInfo(); AiData_Demo_Melee data = GetAiData(npc); if (null != data) { CharacterInfo target = AiLogicUtility.GetLivingCharacterInfoHelper(npc, info.Target); if (null != target) { float dist = (float)npc.GetActualProperty().AttackRange; float distGoHome = (float)npc.GohomeRange; Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D(); Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); float powDist = Geometry.DistanceSquare(srcPos, targetPos); float powDistToHome = Geometry.DistanceSquare(srcPos, info.HomePos); if (powDist < dist * dist) { npc.GetMovementStateInfo().IsMoving = false; info.Time = 0; data.Time = 0; ChangeToState(npc, (int)AiStateId.Combat); NotifyNpcMove(npc); } else { info.Time += deltaTime; if (info.Time > m_IntervalTime) { info.Time = 0; AiLogicUtility.PathToTargetWithoutObstacle(npc, data.FoundPath, targetPos, m_IntervalTime, true, this); } } } } }
private void HandleSelfImpactAction(NpcInfo npc, CharacterInfo target, long deltaTime) { if (npc.GetSkillStateInfo().IsSkillActivated()) { return; } NpcAiStateInfo info = npc.GetAiStateInfo(); AiData_Npc_ActionDrive data = GetAiData(npc); if (null != data && null != target) { Vector3 targetPos = target.GetMovementStateInfo().GetPosition3D(); AiActionInfo aiActionInfo = data.ActiveAction; if (null != aiActionInfo && !String.IsNullOrEmpty(aiActionInfo.Config.ActionParam)) { NotifyNpcAddImpact(npc, int.Parse(aiActionInfo.Config.ActionParam)); } data.ActiveAction = null; aiActionInfo.LastStartTime = TimeUtility.GetServerMilliseconds(); } }
public NpcInfo AddNpc(int id, Data_Unit unit) { NpcInfo npc = NewNpcInfo(id); npc.SceneContext = m_SceneContext; npc.LoadData(unit); npc.IsBorning = true; npc.SetAIEnable(false); npc.SetStateFlag(Operate_Type.OT_AddBit, CharacterState_Type.CST_Invincible); npc.BornTime = TimeUtility.GetServerMilliseconds(); m_Npcs.AddLast(npc.GetId(), npc); if (null != m_SceneContext && null != m_SceneContext.SpatialSystem) { m_SceneContext.SpatialSystem.AddObj(npc.SpaceObject); } if (null != m_SceneContext && null != m_SceneContext.SightManager) { m_SceneContext.SightManager.AddObject(npc); } return(npc); }