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 void InteractObject(int key_code, int what) { UserInfo myself = WorldSystem.Instance.GetPlayerSelf(); if (myself != null && myself.IsDead()) { GfxSystem.PublishGfxEvent("ge_move_camera_to_next_friend", "script", -1, -1); } WorldSystem.Instance.InteractObject(); }
private void TickLevelup() { for (LinkedListNode <UserInfo> linkNode = UserManager.Users.FirstValue; null != linkNode; linkNode = linkNode.Next) { UserInfo info = linkNode.Value; if (!info.IsDead()) { if (info.GetCombatStatisticInfo().DataChanged) { Msg_RC_SyncCombatStatisticInfo combatBuilder = DataSyncUtility.BuildSyncCombatStatisticInfo(info); NotifyAllUser(combatBuilder); info.GetCombatStatisticInfo().DataChanged = false; } } } }
private void MoveHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (user.IsDead()) { user.GetMovementStateInfo().IsMoving = false; ChangeToState(user, (int)AiStateId.Wait); return; } UserAiStateInfo info = user.GetAiStateInfo(); info.Time += deltaTime; if (info.Time > 10) { info.Time = 0; Vector3 srcPos = user.GetMovementStateInfo().GetPosition3D(); Vector3 targetPos = user.GetMovementStateInfo().TargetPosition; if (!IsReached(srcPos, targetPos)) { float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); user.GetMovementStateInfo().SetMoveDir(angle); user.GetMovementStateInfo().IsMoving = true; } } }
private void IdleHandler(UserInfo user, AiCommandDispatcher aiCmdDispatcher, long deltaTime) { if (user.IsDead()) { return; } UserAiStateInfo info = user.GetAiStateInfo(); info.Time += deltaTime; if (info.Time > 100) { info.Time = 0; CharacterInfo target = null; if (info.IsAttacked && m_AttackRangeLast > 0) { if (info.Target > 0 /* || info.TargetPos != Vector3.Zero*/) { target = AiLogicUtility.GetSeeingLivingCharacterInfoHelper(user, info.Target); if (null == target) { info.Target = 0; target = AiLogicUtility.GetNearstTargetHelper(user, CharacterRelation.RELATION_ENEMY); } } if (null != target) { info.Time = 0; info.Target = target.GetId(); info.IsAttacked = false; info.AttackRange = m_AttackRangeLast; m_AttackRangeLast = 0; ChangeToState(user, (int)AiStateId.Combat); } } } }
public void Update(bool move_enable) { UserInfo playerself = WorldSystem.Instance.GetPlayerSelf(); if (playerself == null || playerself.IsDead()) { return; } KeyHit kh = KeyHit.None; if (move_enable) { if (DashFireSpatial.SpatialObjType.kNPC == playerself.GetRealControlledObject().SpaceObject.GetObjType()) { NpcInfo npcInfo = playerself.GetRealControlledObject().CastNpcInfo(); if (null != npcInfo) { if (!npcInfo.CanMove) { return; } } } if (GfxSystem.IsKeyPressed(GetKeyCode(KeyIndex.W))) { kh |= KeyHit.Up; } if (GfxSystem.IsKeyPressed(GetKeyCode(KeyIndex.A))) { kh |= KeyHit.Left; } if (GfxSystem.IsKeyPressed(GetKeyCode(KeyIndex.S))) { kh |= KeyHit.Down; } if (GfxSystem.IsKeyPressed(GetKeyCode(KeyIndex.D))) { kh |= KeyHit.Right; } } Motion m = kh == KeyHit.None ? Motion.Stop : Motion.Moving; MotionChanged = MotionStatus != m || last_key_hit_ != kh; if (MotionChanged) { //LogSystem.Debug("MotionChanged:{0}!={1} || {2}!={3}", MotionStatus, m, last_key_hit_, kh); } last_key_hit_ = kh; MotionStatus = m; MoveDir = CalcMoveDir(kh); if (MoveDir < 0) { MotionStatus = Motion.Stop; } if (MotionChanged) { //GfxSystem.GfxLog(string.Format("InputMoveDir:{0} Pos:{1}", MoveDir, playerself.GetMovementStateInfo().GetPosition3D().ToString())); } }
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); } } } } }
private void TickRecover() { float hp_coefficient = 1.0f; float mp_coefficient = 1.0f; Data_SceneConfig scene_data = SceneConfigProvider.Instance.GetSceneConfigById(m_SceneResId); if (null != scene_data) { hp_coefficient = scene_data.m_RecoverHpCoefficient; mp_coefficient = scene_data.m_RecoverMpCoefficient; } for (LinkedListNode <UserInfo> linkNode = UserManager.Users.FirstValue; null != linkNode; linkNode = linkNode.Next) { UserInfo info = linkNode.Value; if (!info.IsDead()) { float hpRecover = info.GetActualProperty().HpRecover *hp_coefficient; float epRecover = info.GetActualProperty().EnergyRecover *mp_coefficient; if (hpRecover > 0.0001) { if (info.Hp + (int)hpRecover >= info.GetActualProperty().HpMax) { info.SetHp(Operate_Type.OT_Absolute, (int)info.GetActualProperty().HpMax); } else { info.SetHp(Operate_Type.OT_Relative, (int)hpRecover); } } if (epRecover > 0.0001) { if (info.Energy + (int)epRecover >= info.GetActualProperty().EnergyMax) { info.SetEnergy(Operate_Type.OT_Absolute, (int)info.GetActualProperty().EnergyMax); } else { info.SetEnergy(Operate_Type.OT_Relative, (int)epRecover); } } if (hpRecover > 0.0001 || epRecover > 0.0001) { Msg_RC_SyncProperty builder = DataSyncUtility.BuildSyncPropertyMessage(info); NotifyAreaUser(info, builder, false); } } } for (LinkedListNode <NpcInfo> linkNode = NpcManager.Npcs.FirstValue; null != linkNode; linkNode = linkNode.Next) { NpcInfo info = linkNode.Value; if (!info.IsDead()) { float hpRecover = info.GetActualProperty().HpRecover; float npRecover = info.GetActualProperty().EnergyRecover; if (hpRecover > 0.0001) { if (info.Hp + (int)hpRecover >= info.GetActualProperty().HpMax) { info.SetHp(Operate_Type.OT_Absolute, (int)info.GetActualProperty().HpMax); } else { info.SetHp(Operate_Type.OT_Relative, (int)hpRecover); } } if (npRecover > 0.0001) { if (info.Energy + (int)npRecover >= info.GetActualProperty().EnergyMax) { info.SetEnergy(Operate_Type.OT_Absolute, (int)info.GetActualProperty().EnergyMax); } else { info.SetEnergy(Operate_Type.OT_Relative, (int)npRecover); } } if (hpRecover > 0.0001 || npRecover > 0.0001) { Msg_RC_SyncProperty builder = DataSyncUtility.BuildSyncPropertyMessage(info); NotifyAreaUser(info, builder, false); } } } }