private void OnAiSkill(EntityInfo npc, int skillId) { Scene scene = npc.SceneContext.CustomData as Scene; if (null != scene) { SkillInfo skillInfo = npc.GetSkillStateInfo().GetCurSkillInfo(); if (null == skillInfo || !skillInfo.IsSkillActivated) { SkillInfo curSkillInfo = npc.GetSkillStateInfo().GetSkillInfoById(skillId); if (null != curSkillInfo) { long curTime = TimeUtility.GetLocalMilliseconds(); if (!curSkillInfo.IsInCd(curTime)) { if (scene.SkillSystem.StartSkill(npc.GetId(), curSkillInfo.ConfigData, 0)) { Msg_RC_NpcSkill skillBuilder = DataSyncUtility.BuildNpcSkillMessage(npc, skillId); LogSystem.Info("Send Msg_RC_NpcSkill, EntityId={0}, SkillId={1}", npc.GetId(), skillId); scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcSkill, skillBuilder); } } } } } }
private void OnAiAddImpact(EntityInfo npc, int impactId) { Scene scene = npc.SceneContext.CustomData as Scene; if (null != scene) { ImpactInfo impactInfo = new ImpactInfo(impactId); impactInfo.StartTime = TimeUtility.GetLocalMilliseconds(); impactInfo.ImpactSenderId = npc.GetId(); impactInfo.SkillId = 0; if (null != impactInfo.ConfigData) { npc.GetSkillStateInfo().AddImpact(impactInfo); int seq = impactInfo.Seq; if (scene.SkillSystem.StartSkill(npc.GetId(), impactInfo.ConfigData, seq)) { Msg_RC_AddImpact addImpactBuilder = new Msg_RC_AddImpact(); addImpactBuilder.sender_id = npc.GetId(); addImpactBuilder.target_id = npc.GetId(); addImpactBuilder.impact_id = impactId; addImpactBuilder.skill_id = -1; addImpactBuilder.duration = impactInfo.DurationTime; scene.NotifyAllUser(RoomMessageDefine.Msg_RC_AddImpact, addImpactBuilder); } } } }
public static void SyncUserPropertyToCaredUsers(EntityInfo user) { Scene scene = user.SceneContext.CustomData as Scene; if (null != scene) { Msg_RC_SyncProperty bd = BuildSyncPropertyMessage(user); scene.NotifyAllUser(RoomMessageDefine.Msg_RC_SyncProperty, bd); } }
private void MoveNpc(EntityInfo obj, long deltaTime) { if (obj.IsHaveStateFlag(CharacterState_Type.CST_Sleep) || obj.IsHaveStateFlag(CharacterState_Type.CST_FixedPosition)) { return; } MovementStateInfo msi = obj.GetMovementStateInfo(); //npc执行移动时忽略阻挡与避让,这些行为由ai模块在规划其路径时执行。 if (!obj.IsDead() && obj.CanMove && msi.IsMoving && !msi.IsSkillMoving) { ScriptRuntime.Vector3 pos = msi.GetPosition3D(); float speed = (float)obj.GetActualProperty().MoveSpeed; float distance = (speed * (float)(int)deltaTime) / 1000.0f; ScriptRuntime.Vector3 dir = msi.TargetDir; //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; ScriptRuntime.Vector2 newPos = new ScriptRuntime.Vector2(x, y); msi.SetPosition2D(newPos); msi.IsMoving = false; User user = obj.CustomData as User; if (null != user) { Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(obj); if (null != npcMoveBuilder) { Scene scene = user.OwnRoom.ActiveScene; if (null != scene) { scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcMove, npcMoveBuilder); } } } } else { ScriptRuntime.Vector3 tpos = pos + dir * distance; msi.SetPosition(tpos); } } }
private void OnAiRemoveImpact(EntityInfo npc, int impactId) { Scene scene = npc.SceneContext.CustomData as Scene; if (null != scene) { ImpactInfo impactInfo = npc.GetSkillStateInfo().FindImpactInfoById(impactId); if (null != impactInfo) { Msg_RC_RemoveImpact removeImpactBuilder = new Msg_RC_RemoveImpact(); removeImpactBuilder.obj_id = npc.GetId(); removeImpactBuilder.impact_id = impactId; scene.NotifyAllUser(RoomMessageDefine.Msg_RC_RemoveImpact, removeImpactBuilder); scene.SkillSystem.StopSkill(npc.GetId(), impactId, impactInfo.Seq, false); } } }
private void OnAiStopSkill(EntityInfo npc) { Scene scene = npc.SceneContext.CustomData as Scene; if (null != scene) { SkillInfo skillInfo = npc.GetSkillStateInfo().GetCurSkillInfo(); if (null == skillInfo || skillInfo.IsSkillActivated) { scene.SkillSystem.StopAllSkill(npc.GetId(), true); } Msg_RC_NpcStopSkill skillBuilder = DataSyncUtility.BuildNpcStopSkillMessage(npc); LogSystem.Info("Send Msg_RC_NpcStopSkill, EntityId={0}", npc.GetId()); scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcStopSkill, skillBuilder); } }
private void OnAiStopPursue(EntityInfo npc) { Scene scene = npc.SceneContext.CustomData as Scene; if (null != scene) { npc.GetMovementStateInfo().IsMoving = false; if (npc.GetMovementStateInfo().IsMoveStatusChanged) { npc.GetMovementStateInfo().IsMoveStatusChanged = false; Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(npc); if (null != npcMoveBuilder) { scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcMove, npcMoveBuilder); } } } }
internal static void Execute(object msg, User user) { Msg_CR_UserMoveToPos move_msg = msg as Msg_CR_UserMoveToPos; if (move_msg == null) { return; } EntityInfo charactor = user.Info; if (charactor == null) { LogSys.Log(LOG_TYPE.DEBUG, "charactor {0}({1},{2},{3}) not exist", user.RoleId, user.GetKey(), user.Guid, user.Name); return; } /// if (charactor.GetAIEnable()) { float tx, tz; ProtoHelper.DecodePosition2D(move_msg.target_pos, out tx, out tz); ScriptRuntime.Vector3 pos = new ScriptRuntime.Vector3(tx, 0, tz); MovementStateInfo msi = charactor.GetMovementStateInfo(); msi.IsMoving = true; msi.TargetPosition = pos; float dir = Geometry.GetYRadian(msi.GetPosition3D(), pos); msi.SetFaceDir(dir); msi.SetMoveDir(dir); Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(charactor); if (null != npcMoveBuilder) { Scene scene = user.OwnRoom.ActiveScene; if (null != scene) { scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcMove, npcMoveBuilder); } } } }
public static void Execute(object msg, User user) { Msg_CR_StopSkill stopMsg = msg as Msg_CR_StopSkill; if (null == stopMsg) { return; } EntityInfo userInfo = user.Info; if (null == userInfo) { return; } Scene scene = user.OwnRoomUserManager.ActiveScene; if (null != scene) { Msg_RC_NpcStopSkill retMsg = DataSyncUtility.BuildNpcStopSkillMessage(userInfo); scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcStopSkill, retMsg); } }
public static void Execute(object msg, User user) { Msg_CR_Skill use_skill = msg as Msg_CR_Skill; if (null == use_skill) { return; } EntityInfo userObj = user.Info; if (null == userObj) { LogSys.Log(LOG_TYPE.DEBUG, "UseSkillHandler, charactor {0}({1},{2},{3}) not exist", user.RoleId, user.GetKey(), user.Guid, user.Name); return; } Scene scene = user.OwnRoomUserManager.ActiveScene; if (null != scene) { EntityInfo obj = scene.GetEntityById(use_skill.role_id); if (null != obj) { AiStateInfo aiInfo = obj.GetAiStateInfo(); if (use_skill.target_id > 0) { aiInfo.Target = use_skill.target_id; } else if (use_skill.target_dir > 0) { float dir = use_skill.target_dir; obj.GetMovementStateInfo().SetFaceDir(dir); aiInfo.Target = 0; } Msg_RC_NpcSkill retMsg = DataSyncUtility.BuildNpcSkillMessage(obj, use_skill.skill_id); scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcSkill, retMsg); } } }
private void OnAiFace(EntityInfo npc) { if (npc.GetMovementStateInfo().IsFaceDirChanged) { npc.GetMovementStateInfo().IsFaceDirChanged = false; if (null != npc) { float dir = npc.GetMovementStateInfo().GetFaceDir(); npc.GetMovementStateInfo().SetFaceDir(dir); } if (!npc.GetMovementStateInfo().IsMoving) { Scene scene = npc.SceneContext.CustomData as Scene; if (null != scene) { Msg_RC_NpcFace npcFaceBuilder = DataSyncUtility.BuildNpcFaceMessage(npc); if (null != npcFaceBuilder) { scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcFace, npcFaceBuilder); } } } } }
private void OnAiPursue(EntityInfo npc, ScriptRuntime.Vector3 target) { Scene scene = npc.SceneContext.CustomData as Scene; if (null != scene) { npc.GetMovementStateInfo().TargetPosition = target; float dir = Geometry.GetYRadian(npc.GetMovementStateInfo().GetPosition3D(), target); npc.GetMovementStateInfo().SetFaceDir(dir); npc.GetMovementStateInfo().SetMoveDir(dir); npc.GetMovementStateInfo().IsMoving = true; if (npc.GetMovementStateInfo().IsMoveStatusChanged) { npc.GetMovementStateInfo().IsMoveStatusChanged = false; Msg_RC_NpcMove npcMoveBuilder = DataSyncUtility.BuildNpcMoveMessage(npc); if (null != npcMoveBuilder) { scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcMove, npcMoveBuilder); } } } }
internal static void Execute(object msg, User user) { Msg_CR_StopSkill stopMsg = msg as Msg_CR_StopSkill; if (null == stopMsg) { return; } EntityInfo userInfo = user.Info; if (null == userInfo) { return; } Scene scene = user.OwnRoom.ActiveScene; if (null != scene) { scene.SkillSystem.StopAllSkill(userInfo.GetId(), true); Msg_RC_NpcStopSkill retMsg = DataSyncUtility.BuildNpcStopSkillMessage(userInfo); scene.NotifyAllUser(RoomMessageDefine.Msg_RC_NpcStopSkill, retMsg); } }