internal void Tick() { long time = TimeUtility.GetServerMilliseconds(); long delta = (time - m_LastTickTime) * 1000; m_LastTickTime = time; int ct = m_SkillLogicInfos.Count; for (int ix = ct - 1; ix >= 0; --ix) { SkillLogicInfo info = m_SkillLogicInfos[ix]; CharacterInfo obj = CurScene.SceneContext.GetCharacterInfoById(info.SenderId); if (null != obj) { info.SkillInst.Tick(obj, delta); //DashFire.LogSystem.Debug("Skill {0} tick {1}.", info.SkillId, time); } if (null == obj || info.SkillInst.IsFinished) { //DashFire.LogSystem.Warn("Skill {0} finished (time finish).", info.SkillId); if (info.SkillInst.IsControlMove) { if (null != obj) { obj.GetMovementStateInfo().IsSkillMoving = false; } info.SkillInst.IsControlMove = false; } if (null != obj) { SkillInfo skillInfo = obj.GetSkillStateInfo().GetSkillInfoById(info.SkillId); if (null != skillInfo) { skillInfo.IsSkillActivated = false; } } RecycleSkillInstance(info.Info); m_SkillLogicInfos.RemoveAt(ix); } } }
protected override void OnTick() { try { long curTime = TimeUtility.GetServerMilliseconds(); if (m_LastLogTime + 60000 < curTime) { m_LastLogTime = curTime; DebugPoolCount((string msg) => { LogSys.Log(LOG_TYPE.INFO, "SceneLoadThread.ActionQueue {0}", msg); }); } } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "Exception {0}\n{1}", ex.Message, ex.StackTrace); } }
private void Follow(long deltaTime) { long now = TimeUtility.GetServerMilliseconds(); if (now >= m_NextTriggerTime) { m_NextTriggerTime = now + TriggerInterval; OnTrigger(); } if (Geometry.IsSamePoint(m_CurPos, m_CurFollowObj.GetPosition())) { return; } Vector3 new_pos = Move(m_CurPos, m_CurFollowObj.GetPosition(), FollowSpeed, deltaTime); if (Geometry.DistanceSquare(new_pos, m_BeginFollowPos) <= m_MaxFollowRange * m_MaxFollowRange) { m_CurPos = new_pos; } }
public void Tick(CharacterInfo character, int impactId) { ImpactInfo impactInfo = character.GetSkillStateInfo().GetImpactInfoById(impactId); if (null != impactInfo) { if (impactInfo.m_IsActivated) { float damageDelayTime = float.Parse(impactInfo.ConfigData.ExtraParams[0]); if (TimeUtility.GetServerMilliseconds() > impactInfo.m_StartTime + damageDelayTime * 1000 && !impactInfo.m_HasEffectApplyed) { int damage = int.Parse(impactInfo.ConfigData.ExtraParams[1]); if (!character.IsHaveStateFlag(CharacterState_Type.CST_Invincible)) { ApplyDamage(impactInfo.m_ImpactSenderId, character, damage); } impactInfo.m_HasEffectApplyed = true; if (impactInfo.ConfigData.ExtraParams.Count >= 3) { int rage = int.Parse(impactInfo.ConfigData.ExtraParams[2]); if (character.IsUser) { character.SetRage(Operate_Type.OT_Relative, rage); } else { CharacterInfo user = character.SceneContext.GetCharacterInfoById(impactInfo.m_ImpactSenderId); if (user != null && user.IsUser) { user.SetRage(Operate_Type.OT_Relative, rage); } } } } if (TimeUtility.GetServerMilliseconds() > impactInfo.m_StartTime + impactInfo.m_ImpactDuration) { impactInfo.m_IsActivated = false; } } } }
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.Add(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); }
public override void Adjust() { CharacterInfo info = WorldSystem.Instance.GetCharacterById(m_ObjId); if (null != info) { if (!info.GetMovementStateInfo().IsMoving) { m_IsTerminated = true; } else { float curTime = TimeUtility.GetServerMilliseconds(); float delta = curTime - m_LastTime; m_LastTime = curTime; m_CurTotalTime += delta; if (m_CurTotalTime > m_TotalTime) { delta -= m_CurTotalTime - m_TotalTime; } float dx = (float)(m_Dx * delta / m_TotalTime); float dy = (float)(m_Dy * delta / m_TotalTime); float dz = (float)(m_Dz * delta / m_TotalTime); Vector2 pos = info.GetMovementStateInfo().GetPosition2D() + new Vector2(dx, dz); info.GetMovementStateInfo().SetPosition2D(pos); if (m_CurTotalTime >= m_TotalTime) { m_IsTerminated = true; } } } else { m_IsTerminated = true; } }
private void UpdateStatus(DashFireSpatial.ISpatialSystem spatial_system) { List <ISpaceObject> in_objs = spatial_system.GetObjectInCircle(m_CurPos, SearchRadius); switch (m_Status) { case SearchLightStatus.kPatrol: case SearchLightStatus.kReturn: ISpaceObject target = GetFirstUser(in_objs); if (target != null) { BeginFollow(target); } break; case SearchLightStatus.kFollow: if (!IsContainObj(in_objs, m_CurFollowObj)) { ISpaceObject new_target = GetFirstUser(in_objs); if (new_target != null) { BeginFollow(new_target); } else { BeginExFollow(); } } break; case SearchLightStatus.kExFollow: if (TimeUtility.GetServerMilliseconds() > m_ExFollowTime + ExFollowTimeMs) { BeginReturn(); } break; } }
public void Tick(CharacterInfo character, int impactId) { ImpactInfo impactInfo = character.GetSkillStateInfo().GetImpactInfoById(impactId); if (null == impactInfo) { return; } if (!impactInfo.m_IsActivated) { return; } if (!impactInfo.m_HasEffectApplyed) { character.SetStateFlag(Operate_Type.OT_AddBit, CharacterState_Type.CST_Invincible); impactInfo.m_HasEffectApplyed = true; } if (TimeUtility.GetServerMilliseconds() > impactInfo.m_StartTime + impactInfo.m_ImpactDuration) { character.SetStateFlag(Operate_Type.OT_RemoveBit, CharacterState_Type.CST_Invincible); impactInfo.m_IsActivated = false; } }
public override void Adjust() { CharacterInfo info = m_SceneContext.GetCharacterInfoById(m_ObjId); if (null != info) { float curTime = TimeUtility.GetLocalMilliseconds(); float delta = curTime - m_LastTime; m_LastTime = curTime; m_CurTotalTime += delta; float faceDir = info.GetMovementStateInfo().GetFaceDir(); if (m_CurTotalTime >= m_TotalTime || Math.Abs(faceDir - m_FaceDir) <= 0.1f) { info.GetMovementStateInfo().SetFaceDir(m_FaceDir); m_IsTerminated = true; } else { float offset = c_PI - (m_FaceDir + c_2PI - faceDir) % c_2PI; if (offset * m_DeltaDir <= 0) { info.GetMovementStateInfo().SetFaceDir(m_FaceDir); m_IsTerminated = true; } else { float newFaceDir = (faceDir + c_2PI + delta * m_DeltaDir / m_TotalTime) % c_2PI; info.GetMovementStateInfo().SetFaceDir(newFaceDir); //LogSystem.Debug("FaceController {0}, obj:{1}, faceDir:{2}->{3}, delta:{4} totalTime:{5} deltaDir:{6} targetDir:{7}", m_Id, m_ObjId, faceDir, newFaceDir, delta, m_TotalTime, m_DeltaDir, m_FaceDir); } } } else { m_IsTerminated = true; } }
private void CreateNpc() { if (!m_IsTriggered) { return; } if (m_NextNpcIndex >= NpcList.Count) { m_IsTriggered = false; return; } long now = TimeUtility.GetServerMilliseconds(); if (now >= m_NextNpcCreateTime) { int npc_unit_id = NpcList[m_NextNpcIndex]; m_NextNpcIndex++; m_NextNpcCreateTime = now + CreateNpcInterval; if (OnCreateNpc != null) { OnCreateNpc(LogicInfo, this, npc_unit_id); } } }
protected virtual void UpdateIdle() { if (!GetOwner().IsDead() && m_CharacterAnimationInfo.IsIdle()) { if (m_IdleState == IdleState.kNotIdle) { //PlayAnimation(Animation_Type.AT_Hold); string name = GetAnimationNameByType(Animation_Type.AT_Hold); if (!string.IsNullOrEmpty(name)) { GfxSystem.CrossFadeAnimation(m_Actor, name, 0.5f); } m_BeginIdleTime = TimeUtility.GetServerMilliseconds(); m_IdleState = IdleState.kReady; m_IdleInterval = new Random().Next(1, 3) * 1000; } else if (m_IdleState == IdleState.kReady) { if (TimeUtility.GetServerMilliseconds() - m_BeginIdleTime > m_IdleInterval) { string name = GetAnimationNameByType(Animation_Type.AT_Stand); if (!string.IsNullOrEmpty(name)) { GfxSystem.CrossFadeAnimation(m_Actor, name, 0.5f); } //PlayAnimation(Animation_Type.AT_Stand); m_BeginIdleTime = TimeUtility.GetServerMilliseconds(); } } } else { m_IdleState = IdleState.kNotIdle; } }
protected override void OnTick() { //这里是在逻辑线程执行的tick,渲染线程的在GameControler.cs:TickGame里。 try { TimeUtility.SampleClientTick(); long curTime = TimeUtility.GetLocalMilliseconds(); if (m_LastLogTime + 10000 < curTime) { m_LastLogTime = curTime; GfxSystem.GfxLog("LogicThread.Tick actionNum {0}", this.CurActionNum); } NetworkSystem.Instance.Tick(); LobbyNetworkSystem.Instance.Tick(); PlayerControl.Instance.Tick(); WorldSystem.Instance.Tick(); GameControler.LogicLoggerInstance.Tick(); } catch (Exception ex) { GfxSystem.GfxLog("GameLogicThread.Tick throw Exception:{0}\n{1}", ex.Message, ex.StackTrace); } }
private void OnNpcSkill(NpcInfo 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.GetServerMilliseconds(); if (!curSkillInfo.IsInCd(curTime / 1000.0f)) { curSkillInfo.StartTime = curTime / 1000.0f; curSkillInfo.BeginCD(); scene.SkillSystem.StartSkill(npc.GetId(), skillId); Msg_RC_NpcSkill skillBuilder = new Msg_RC_NpcSkill(); skillBuilder.npc_id = npc.GetId(); skillBuilder.skill_id = skillId; ArkCrossEngineMessage.Position posBuilder1 = new ArkCrossEngineMessage.Position(); posBuilder1.x = npc.GetMovementStateInfo().GetPosition3D().X; posBuilder1.z = npc.GetMovementStateInfo().GetPosition3D().Z; skillBuilder.stand_pos = posBuilder1; skillBuilder.face_direction = (float)npc.GetMovementStateInfo().GetFaceDir(); LogSystem.Debug("Send Msg_RC_NpcSkill, EntityId={0}, SkillId={1}", npc.GetId(), skillId); scene.NotifyAreaUser(npc, skillBuilder); } } } } }
private void PathToTarget(UserInfo user, AiPathData data, Vector3 pathTargetPos, long deltaTime) { UserAiStateInfo info = user.GetAiStateInfo(); if (null != data) { data.UpdateTime += deltaTime; ScriptRuntime.Vector3 srcPos = user.GetMovementStateInfo().GetPosition3D(); float dir = user.GetMovementStateInfo().GetMoveDir(); bool findObstacle = false; bool havePathPoint = data.HavePathPoint; if (havePathPoint)//沿路点列表移动的逻辑 { Vector3 targetPos = data.CurPathPoint; if (!data.IsReached(srcPos))//向指定路点移动(避让移动过程) { user.GetMovementStateInfo().TargetPosition = targetPos; float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); if (!Geometry.IsSameDouble(angle, user.GetMovementStateInfo().GetMoveDir())) { user.GetMovementStateInfo().SetFaceDir(angle); user.GetMovementStateInfo().SetMoveDir(angle); user.GetMovementStateInfo().IsMoving = true; NotifyUserMove(user); } } else//改变路点或结束沿路点移动 { data.UseNextPathPoint(); if (data.HavePathPoint) { targetPos = data.CurPathPoint; user.GetMovementStateInfo().TargetPosition = targetPos; float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); user.GetMovementStateInfo().SetFaceDir(angle); user.GetMovementStateInfo().SetMoveDir(angle); user.GetMovementStateInfo().IsMoving = true; NotifyUserMove(user); } else { data.Clear(); } } } if (!havePathPoint || findObstacle)//获得路点过程(寻路) { data.Clear(); Vector3 targetPos = pathTargetPos; if (Geometry.DistanceSquare(srcPos, targetPos) > 400) { targetPos = user.SpatialSystem.CalcNearstReachablePoint(srcPos, targetPos, 20); } bool canGo = true; /* * if (!user.SpatialSystem.GetCellMapView(user.AvoidanceRadius).CanPass(targetPos)) { * if (!AiLogicUtility.GetWalkablePosition(user.SpatialSystem.GetCellMapView(user.AvoidanceRadius), targetPos, srcPos, ref targetPos)) * canGo = false; * }*/ if (canGo) { List <Vector3> posList = null; if (user.SpatialSystem.CanPass(user.SpaceObject, targetPos)) { posList = new List <Vector3>(); posList.Add(srcPos); posList.Add(targetPos); } else { long stTime = TimeUtility.GetElapsedTimeUs(); posList = user.SpatialSystem.FindPath(srcPos, targetPos, user.AvoidanceRadius); long endTime = TimeUtility.GetElapsedTimeUs(); long calcTime = endTime - stTime; if (calcTime > 1000) { //LogSystem.Warn("pvp FindPath consume {0} us,user:{1} from:{2} to:{3} radius:{4} pos:{5}", calcTime, user.GetId(), srcPos.ToString(), targetPos.ToString(), user.AvoidanceRadius, user.GetMovementStateInfo().GetPosition3D().ToString()); } } if (posList.Count >= 2) { data.SetPathPoints(posList[0], posList, 1); targetPos = data.CurPathPoint; user.GetMovementStateInfo().TargetPosition = targetPos; float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); user.GetMovementStateInfo().SetFaceDir(angle); user.GetMovementStateInfo().SetMoveDir(angle); user.GetMovementStateInfo().IsMoving = true; NotifyUserMove(user); } else { user.GetMovementStateInfo().IsMoving = false; NotifyUserMove(user); } } else { user.GetMovementStateInfo().IsMoving = false; NotifyUserMove(user); } } } }
private void TickNpcs() { List <NpcInfo> deletes = new List <NpcInfo>(); for (LinkedListNode <NpcInfo> linkNode = m_NpcMgr.Npcs.FirstValue; null != linkNode; linkNode = linkNode.Next) { NpcInfo info = linkNode.Value; if (info.LevelChanged || info.GetShootStateInfo().WeaponChanged || info.GetSkillStateInfo().BuffChanged || info.GetEquipmentStateInfo().EquipmentChanged) { NpcAttrCalculator.Calc(info); info.LevelChanged = false; info.GetShootStateInfo().WeaponChanged = false; info.GetSkillStateInfo().BuffChanged = false; info.GetEquipmentStateInfo().EquipmentChanged = false; } // 约定npc的高度低于140时,直接判定npc死亡。 if (140.0f > info.GetMovementStateInfo().GetPosition3D().Y) { info.SetHp(Operate_Type.OT_Absolute, 0); } if (info.NeedDelete) { deletes.Add(info); } else if (info.Hp <= 0) { if (!info.LogicDead) { GfxSystem.PublishGfxEvent("ge_on_npc_dead", "story", info.GetUnitId()); info.LogicDead = true; } if (info.DeadTime <= 0) { } else if (TimeUtility.GetServerMilliseconds() - info.DeadTime > info.ReleaseTime) { deletes.Add(info); } } if (info.IsBorning && IsNpcBornOver(info)) { info.IsBorning = false; info.SetAIEnable(true); info.SetStateFlag(Operate_Type.OT_RemoveBit, CharacterState_Type.CST_Invincible); } } if (deletes.Count > 0) { foreach (NpcInfo ni in deletes) { CharacterView view = EntityManager.Instance.GetCharacterViewById(ni.GetId()); if (null != view) { GfxSystem.SendMessage(view.Actor, "OnDead", null); } EntityManager.Instance.DestroyNpcView(ni.GetId()); WorldSystem.Instance.DestroyCharacterById(ni.GetId()); return; } } }
private void BeginExFollow() { m_Status = SearchLightStatus.kExFollow; m_ExFollowTime = TimeUtility.GetServerMilliseconds(); }
private void TickRunning() { TimeSnapshot.DoCheckPoint(); m_ServerDelayActionProcessor.HandleActions(100); m_SceneProfiler.DelayActionProcessorTime = TimeSnapshot.DoCheckPoint(); m_ControlSystemOperation.Tick(); m_MovementSystem.Tick(); m_SceneProfiler.MovementSystemTime = TimeSnapshot.DoCheckPoint(); m_SpatialSystem.Tick(); m_SceneProfiler.SpatialSystemTime = TimeSnapshot.DoCheckPoint(); m_AiSystem.Tick(); m_SceneProfiler.AiSystemTime = TimeSnapshot.DoCheckPoint(); m_SceneLogicSystem.Tick(); m_SceneProfiler.SceneLogicSystemTime = TimeSnapshot.DoCheckPoint(); m_StorySystem.Tick(); m_GmStorySystem.Tick(); m_SceneProfiler.StorySystemTime = TimeSnapshot.DoCheckPoint(); //技能逻辑Tick TickSkill(); m_SceneProfiler.TickSkillTime = TimeSnapshot.DoCheckPoint(); //obj特殊状态处理(如死亡,重生等) TickUsers(); m_SceneProfiler.TickUsersTime = TimeSnapshot.DoCheckPoint(); TickNpcs(); m_SceneProfiler.TickNpcsTime = TimeSnapshot.DoCheckPoint(); TickLevelup(); m_SceneProfiler.TickLevelupTime = TimeSnapshot.DoCheckPoint(); //属性回复 if (0 == m_LastTickTimeForTickPerSecond) { m_LastTickTimeForTickPerSecond = TimeUtility.GetServerMilliseconds(); TickRecover(); TickBlindage(); } else { long curTime = TimeUtility.GetServerMilliseconds(); if (curTime > m_LastTickTimeForTickPerSecond + c_IntervalPerSecond) { m_LastTickTimeForTickPerSecond = curTime; TickRecover(); TickBlindage(); } } m_SceneProfiler.TickAttrRecoverTime = TimeSnapshot.DoCheckPoint(); //空间信息调试 TickDebugSpaceInfo(); m_SceneProfiler.TickDebugSpaceInfoTime = TimeSnapshot.DoCheckPoint(); }
private void TickNpcs() { List <NpcInfo> deletes = new List <NpcInfo>(); List <NpcInfo> deletes2 = new List <NpcInfo>(); Msg_RC_NpcDead npcDeadBuilder = new Msg_RC_NpcDead(); for (LinkedListNode <NpcInfo> linkNode = NpcManager.Npcs.FirstValue; null != linkNode; linkNode = linkNode.Next) { NpcInfo info = linkNode.Value; if (info.LevelChanged || info.GetSkillStateInfo().BuffChanged || info.GetEquipmentStateInfo().EquipmentChanged || info.GetLegacyStateInfo().LegacyChanged) { NpcAttrCalculator.Calc(info); info.LevelChanged = false; info.GetSkillStateInfo().BuffChanged = false; info.GetEquipmentStateInfo().EquipmentChanged = false; info.GetLegacyStateInfo().LegacyChanged = false; } // 伙伴自动掉血 if ((int)NpcTypeEnum.Partner == info.NpcType) { UserInfo owner = UserManager.GetUserInfo(info.OwnerId); if (null != owner) { PartnerInfo pi = owner.GetPartnerInfo(); if (null != pi && TimeUtility.GetServerMilliseconds() - pi.LastTickTime > pi.TickInterval) { info.SetHp(Operate_Type.OT_Relative, (int)pi.GetHpCostPerTick(info.GetActualProperty().HpMax)); pi.LastTickTime = TimeUtility.GetServerMilliseconds(); } } } if (info.NeedDelete) { deletes2.Add(info); } else if (info.IsDead()) { if (info.DeadTime <= 0) { info.DeadTime = TimeUtility.GetServerMilliseconds(); //击杀收益计算 CalcKillIncome(info); //解除控制 ReleaseControl(info); //发送npc死亡消息 npcDeadBuilder.npc_id = info.GetId(); NotifyAllUser(npcDeadBuilder); if (info.IsCombatNpc()) { m_StorySystem.SendMessage("objkilled", info.GetId(), GetBattleNpcCount()); m_StorySystem.SendMessage(string.Format("npckilled:{0}", info.GetUnitId()), info.GetId(), GetBattleNpcCount()); if (info.GetUnitId() > 0) { if (m_IsAttemptScene) { if ((int)NpcTypeEnum.BigBoss == info.NpcType) { TryFireAllNpcKilled(); } } else { TryFireAllNpcKilled(); } } } } else if (TimeUtility.GetServerMilliseconds() - info.DeadTime > info.ReleaseTime && info.GfxDead) { deletes.Add(info); } } if (info.IsBorning && IsNpcBornOver(info)) { info.IsBorning = false; info.SetAIEnable(true); info.SetStateFlag(Operate_Type.OT_RemoveBit, CharacterState_Type.CST_Invincible); } CheckNpcOwnerId(info); } if (deletes.Count > 0) { Msg_RC_DestroyNpc destroyNpcBuilder = new Msg_RC_DestroyNpc(); foreach (NpcInfo ni in deletes) { //发送npc消失消息 destroyNpcBuilder.npc_id = ni.GetId(); destroyNpcBuilder.need_play_effect = true; NotifyAllUser(destroyNpcBuilder); //删除npc NpcManager.RemoveNpc(ni.GetId()); LogSystem.Debug("Npc {0} name {1} is deleted.", ni.GetId(), ni.GetName()); } } if (deletes2.Count > 0) { Msg_RC_DestroyNpc destroyNpcBuilder = new Msg_RC_DestroyNpc(); foreach (NpcInfo ni in deletes2) { //发送npc消失消息 destroyNpcBuilder.npc_id = ni.GetId(); destroyNpcBuilder.need_play_effect = false; NotifyAllUser(destroyNpcBuilder); //删除npc NpcManager.RemoveNpc(ni.GetId()); LogSystem.Debug("Npc {0} name {1} is deleted.", ni.GetId(), ni.GetName()); } } NpcManager.ExecuteDelayAdd(); }
internal void SummonPartner(Msg_CR_SummonPartner msg) { UserInfo userInfo = UserManager.GetUserInfo(msg.obj_id); if (null != userInfo) { // summonpartner PartnerInfo partnerInfo = userInfo.GetPartnerInfo(); if (null != partnerInfo && (TimeUtility.GetServerMilliseconds() - userInfo.LastSummonPartnerTime > partnerInfo.CoolDown || userInfo.LastSummonPartnerTime == 0)) { Data_Unit data = new Data_Unit(); data.m_Id = -1; data.m_LinkId = partnerInfo.LinkId; data.m_CampId = userInfo.GetCampId(); data.m_Pos = userInfo.GetMovementStateInfo().GetPosition3D(); data.m_RotAngle = 0; data.m_AiLogic = partnerInfo.GetAiLogic(); data.m_AiParam[0] = ""; data.m_AiParam[1] = ""; data.m_AiParam[2] = partnerInfo.GetAiParam().ToString(); data.m_IsEnable = true; NpcInfo npc = NpcManager.AddNpc(data); if (null != npc) { AppendAttributeConfig aac = AppendAttributeConfigProvider.Instance.GetDataById(partnerInfo.GetAppendAttrConfigId()); float inheritAttackAttrPercent = partnerInfo.GetInheritAttackAttrPercent(); float inheritDefenceAttrPercent = partnerInfo.GetInheritDefenceAttrPercent(); if (null != aac) { // attack npc.GetBaseProperty().SetAttackBase(Operate_Type.OT_Absolute, (int)(userInfo.GetActualProperty().AttackBase *inheritAttackAttrPercent)); npc.GetBaseProperty().SetFireDamage(Operate_Type.OT_Absolute, userInfo.GetActualProperty().FireDamage *inheritAttackAttrPercent); npc.GetBaseProperty().SetIceDamage(Operate_Type.OT_Absolute, userInfo.GetActualProperty().IceDamage *inheritAttackAttrPercent); npc.GetBaseProperty().SetPoisonDamage(Operate_Type.OT_Absolute, userInfo.GetActualProperty().PoisonDamage *inheritAttackAttrPercent); // defence npc.GetBaseProperty().SetHpMax(Operate_Type.OT_Absolute, (int)(userInfo.GetActualProperty().HpMax *inheritDefenceAttrPercent)); npc.GetBaseProperty().SetEnergyMax(Operate_Type.OT_Absolute, (int)(userInfo.GetActualProperty().EnergyMax *inheritDefenceAttrPercent)); npc.GetBaseProperty().SetADefenceBase(Operate_Type.OT_Absolute, (int)(userInfo.GetActualProperty().ADefenceBase *inheritDefenceAttrPercent)); npc.GetBaseProperty().SetMDefenceBase(Operate_Type.OT_Absolute, (int)(userInfo.GetActualProperty().MDefenceBase *inheritDefenceAttrPercent)); npc.GetBaseProperty().SetFireERD(Operate_Type.OT_Absolute, userInfo.GetActualProperty().FireERD *inheritDefenceAttrPercent); npc.GetBaseProperty().SetIceERD(Operate_Type.OT_Absolute, userInfo.GetActualProperty().IceERD *inheritDefenceAttrPercent); npc.GetBaseProperty().SetPoisonERD(Operate_Type.OT_Absolute, userInfo.GetActualProperty().PoisonERD *inheritDefenceAttrPercent); // reset hp & energy npc.SetHp(Operate_Type.OT_Absolute, npc.GetBaseProperty().HpMax); npc.SetEnergy(Operate_Type.OT_Absolute, npc.GetBaseProperty().EnergyMax); } npc.SetAIEnable(true); npc.GetSkillStateInfo().RemoveAllSkill(); npc.BornTime = TimeUtility.GetServerMilliseconds(); List <int> skillList = partnerInfo.GetSkillList(); if (null != skillList) { for (int i = 0; i < skillList.Count; ++i) { SkillInfo skillInfo = new SkillInfo(skillList[i]); npc.GetSkillStateInfo().AddSkill(skillInfo); } } userInfo.LastSummonPartnerTime = TimeUtility.GetServerMilliseconds(); npc.OwnerId = userInfo.GetId(); userInfo.PartnerId = npc.GetId(); if (partnerInfo.BornSkill > 0) { SkillInfo skillInfo = new SkillInfo(partnerInfo.BornSkill); npc.GetSkillStateInfo().AddSkill(skillInfo); } ArkCrossEngineMessage.Msg_RC_CreateNpc builder = DataSyncUtility.BuildCreateNpcMessage(npc); NotifyAllUser(builder); } } } }
public SceneLogicInfo(int id) { m_Id = id; m_IsLogicFinished = false; m_CreateTime = TimeUtility.GetServerMilliseconds(); }
internal void Start() { game_start_ms_ = TimeUtility.GetServerMilliseconds(); }
public static void PathToTargetWithoutObstacle(NpcInfo npc, AiPathData data, Vector3 pathTargetPos, long deltaTime, bool faceIsMoveFir, AbstractNpcStateLogic logic) { NpcAiStateInfo info = npc.GetAiStateInfo(); Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); if (null != data) { data.Clear(); data.UpdateTime += deltaTime; Vector3 targetPos = pathTargetPos; List <Vector3> posList = null; bool canPass = npc.SpatialSystem.CanPass(npc.SpaceObject, targetPos); if (canPass) { posList = new List <Vector3>(); posList.Add(srcPos); posList.Add(targetPos); } else { long stTime = TimeUtility.GetElapsedTimeUs(); posList = npc.SpatialSystem.FindPath(srcPos, targetPos, npc.AvoidanceRadius); long endTime = TimeUtility.GetElapsedTimeUs(); long calcTime = endTime - stTime; if (calcTime > 10000) { LogSystem.Warn("*** pve FindPath consume {0} us,npc:{1} from:{2} to:{3} radius:{4} pos:{5}", calcTime, npc.GetId(), srcPos.ToString(), targetPos.ToString(), npc.AvoidanceRadius, npc.GetMovementStateInfo().GetPosition3D().ToString()); } } if (posList.Count >= 2) { data.SetPathPoints(posList[0], posList, 1); } else { npc.GetMovementStateInfo().IsMoving = false; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } bool havePathPoint = data.HavePathPoint; if (havePathPoint)//沿路点列表移动的逻辑 { targetPos = data.CurPathPoint; if (!data.IsReached(srcPos))//向指定路点移动(避让移动过程) { float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); Vector3 prefVelocity = (float)npc.GetActualProperty().MoveSpeed *new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle)); Vector3 v = new Vector3(targetPos.X - srcPos.X, 0, targetPos.Z - srcPos.Z); v.Normalize(); Vector3 velocity = npc.SpaceObject.GetVelocity(); float speedSquare = (float)npc.GetActualProperty().MoveSpeed *(float)npc.GetActualProperty().MoveSpeed; long stTime = TimeUtility.GetElapsedTimeUs(); Vector3 newVelocity = npc.SpatialSystem.ComputeVelocity(npc.SpaceObject, v, (float)deltaTime / 1000, (float)npc.GetActualProperty().MoveSpeed, (float)npc.GetRadius(), data.IsUsingAvoidanceVelocity); long endTime = TimeUtility.GetElapsedTimeUs(); long calcTime = endTime - stTime; if (calcTime > 10000) { LogSystem.Warn("*** pve ComputeVelocity consume {0} us,npc:{1} velocity:{2} newVelocity:{3} deltaTime:{4} speed:{5} pos:{6}", calcTime, npc.GetId(), velocity.ToString(), newVelocity.ToString(), deltaTime, npc.GetActualProperty().MoveSpeed, npc.GetMovementStateInfo().GetPosition3D().ToString()); } if (data.UpdateTime > 500) { data.UpdateTime = 0; float newAngle = Geometry.GetYAngle(new Vector2(0, 0), new Vector2(newVelocity.X, newVelocity.Z)); npc.GetMovementStateInfo().SetMoveDir(newAngle); if (faceIsMoveFir) { logic.NotifyNpcFace(npc, newAngle); } newVelocity.Normalize(); npc.GetMovementStateInfo().TargetPosition = srcPos + newVelocity * Geometry.Distance(srcPos, targetPos); npc.GetMovementStateInfo().IsMoving = true; logic.NotifyNpcMove(npc); } else { data.UpdateTime += deltaTime; } } else//改变路点或结束沿路点移动 { data.UseNextPathPoint(); if (data.HavePathPoint) { targetPos = data.CurPathPoint; npc.GetMovementStateInfo().TargetPosition = targetPos; float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); npc.GetMovementStateInfo().SetMoveDir(angle); if (faceIsMoveFir) { logic.NotifyNpcFace(npc, angle); } npc.GetMovementStateInfo().IsMoving = true; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } else { npc.GetMovementStateInfo().IsMoving = false; data.Clear(); } } } } }
internal bool AddNewUser(User newUser) { foreach (User us in room_users_) { if (us != null && us.Guid == newUser.Guid) { //当前玩家已在游戏房间内 LogSys.Log(LOG_TYPE.DEBUG, "Add user success: User already in the room! RoomID:{0}, Guid:{1}, OldUser[{2}]({3}) NewUser[{4}]({5}) ", cur_room_id_, us.Guid, us.LocalID, us.GetKey(), newUser.LocalID, newUser.GetKey()); LogSys.Log(LOG_TYPE.INFO, "FreeUser {0} for {1} {2}, [Room.AddNewUser]", newUser.LocalID, newUser.Guid, newUser.GetKey()); user_pool_.FreeUser(newUser.LocalID); return(true); } } can_close_time_ = 0; newUser.EnterRoomTime = TimeUtility.GetServerMilliseconds(); newUser.OwnRoom = this; newUser.RegisterObservers(room_observers_); newUser.Info = m_UserMgr.AddUser(newUser.HeroId); newUser.Info.SetUnitId(GlobalVariables.GetUnitIdByCampId(newUser.CampId)); newUser.Info.SetCampId(newUser.CampId); newUser.Info.SetLevel(newUser.Level); if ((int)UserControlState.Ai == newUser.UserControlState) { newUser.Info.GetAiStateInfo().AiLogic = (int)AiStateLogicId.PvpUser_General; newUser.IsEntered = true; } if (m_ActiveScene >= 0 && m_Scenes.Count > m_ActiveScene) { Scene scene = m_Scenes[m_ActiveScene]; scene.EnterScene(newUser.Info); if ((int)UserControlState.Ai == newUser.UserControlState) { Data_Unit unit = scene.MapData.ExtractData(DataMap_Type.DT_Unit, newUser.Info.GetUnitId()) as Data_Unit; if (null != unit) { newUser.Info.GetMovementStateInfo().SetPosition(unit.m_Pos); newUser.Info.GetMovementStateInfo().SetFaceDir(unit.m_RotAngle); } } } foreach (User otheruser in room_users_) { if (otheruser != null) { otheruser.AddSameRoomUser(newUser); newUser.AddSameRoomUser(otheruser); } } room_users_.Add(newUser); LogSys.Log(LOG_TYPE.DEBUG, "Add user success ! RoomID:{0} , UserGuid:{1}({2})", cur_room_id_, newUser.Guid, newUser.GetKey()); if (null != newUser.Skill && 4 == newUser.Skill.Count) { newUser.Info.GetSkillStateInfo().RemoveAllSkill(); newUser.Info.ResetSkill(); for (int index = 0; index < newUser.Skill.Count; index++) { if (newUser.Skill[index].SkillId > 0) { SkillInfo info = new SkillInfo(newUser.Skill[index].SkillId); info.SkillLevel = newUser.Skill[index].SkillLevel; info.Postions.SetCurSkillSlotPos(newUser.PresetIndex, (SlotPosition)(index + 1)); SkillCategory cur_skill_pos = SkillCategory.kNone; if ((index + 1) == (int)SlotPosition.SP_A) { cur_skill_pos = SkillCategory.kSkillA; } else if ((index + 1) == (int)SlotPosition.SP_B) { cur_skill_pos = SkillCategory.kSkillB; } else if ((index + 1) == (int)SlotPosition.SP_C) { cur_skill_pos = SkillCategory.kSkillC; } else if ((index + 1) == (int)SlotPosition.SP_D) { cur_skill_pos = SkillCategory.kSkillD; } info.ConfigData.Category = cur_skill_pos; newUser.Info.GetSkillStateInfo().AddSkill(info); newUser.Info.ResetSkill(); /// AddSubSkill(newUser, info.SkillId, cur_skill_pos, info.SkillLevel); } } Data_PlayerConfig playerData = PlayerConfigProvider.Instance.GetPlayerConfigById(newUser.HeroId); if (null != playerData && null != playerData.m_FixedSkillList && playerData.m_FixedSkillList.Count > 0) { foreach (int skill_id in playerData.m_FixedSkillList) { if (null == newUser.Info.GetSkillStateInfo().GetSkillInfoById(skill_id)) { SkillInfo info = new SkillInfo(skill_id, 1); newUser.Info.GetSkillStateInfo().AddSkill(info); newUser.Info.ResetSkill(); } } } } if (null != newUser.Equip && newUser.Equip.Count > 0) { newUser.Info.GetEquipmentStateInfo().Reset(); for (int index = 0; index < newUser.Equip.Count; index++) { if (newUser.Equip[index].ItemId > 0) { ItemDataInfo info = new ItemDataInfo(newUser.Equip[index].ItemRandomProperty); info.ItemId = newUser.Equip[index].ItemId; info.Level = newUser.Equip[index].ItemLevel; info.RandomProperty = newUser.Equip[index].ItemRandomProperty; info.ItemConfig = ItemConfigProvider.Instance.GetDataById(info.ItemId); newUser.Info.GetEquipmentStateInfo().SetEquipmentData(index, info); } } } if (null != newUser.Legacy && newUser.Legacy.Count > 0) { newUser.Info.GetLegacyStateInfo().Reset(); for (int index = 0; index < newUser.Legacy.Count; index++) { if (null != newUser.Legacy[index] && newUser.Legacy[index].ItemId > 0 && newUser.Legacy[index].IsUnlock) { ItemDataInfo info = new ItemDataInfo(newUser.Legacy[index].ItemRandomProperty); info.ItemId = newUser.Legacy[index].ItemId; info.Level = newUser.Legacy[index].ItemLevel; info.RandomProperty = newUser.Legacy[index].ItemRandomProperty; info.IsUnlock = newUser.Legacy[index].IsUnlock; info.ItemConfig = ItemConfigProvider.Instance.GetDataById(info.ItemId); newUser.Info.GetLegacyStateInfo().SetLegacyData(index, info); } } newUser.Info.GetLegacyStateInfo().UpdateLegacyComplexAttr(); } if (null != newUser.Partner) { newUser.Info.SetPartnerInfo(newUser.Partner); } return(true); }
internal void Tick() { try { if (this.CurrentState != RoomState.Active && this.CurrentState != RoomState.Finish) { return; } long curTime = TimeUtility.GetServerMilliseconds(); if (m_LastLogTime + 60000 < curTime) { m_LastLogTime = curTime; LogSys.Log(LOG_TYPE.INFO, "Room.Tick {0}", RoomID); } if (this.CurrentState == RoomState.Active) { Scene scene = GetActiveScene(); if (null != scene) { scene.Tick(); scene.SightTick(); } disconnected_users_.Clear(); request_delete_users_.Clear(); foreach (User user in room_users_) { if (user != null) { user.Tick(); if (user.IsTimeout()) { if (user.UserControlState == (int)UserControlState.User) { disconnected_users_.Add(user); } else if (user.UserControlState == (int)UserControlState.Remove) { request_delete_users_.Add(user); } } } } foreach (User user in disconnected_users_) { DropUser(user); } foreach (User user in request_delete_users_) { RemoveUser(user); } //todo:观察者掉线处理 for (int i = 0; i < room_observers_.Length; ++i) { Observer observer = room_observers_[i]; if (!observer.IsIdle) { observer.Tick(); } } int userCount = GetActiveRoomUserCount(); if (userCount <= 0) { if (GetMinimizeElapsedDroppedTime() > c_finish_time_for_no_users_) { //若房间内玩家数目为0,结束战斗,关闭房间 EndBattle((int)CampIdEnum.Unkown); } } //每个Tick结束,将空间属性同步给Peer,用于Peer转发消息 foreach (User user in room_users_) { if (null != user && null != user.Info && null != user.Info.GetMovementStateInfo()) { RoomServer.RoomPeer peer = user.GetPeer(); if (null != peer) { MovementStateInfo info = user.Info.GetMovementStateInfo(); peer.Position = info.GetPosition3D(); peer.FaceDir = info.GetFaceDir(); } } } } else if (m_FinishTime + c_DeactiveWaitTime < curTime) { Deactive(); } } catch (Exception ex) { LogSys.Log(LOG_TYPE.ERROR, "Exception {0}\n{1}", ex.Message, ex.StackTrace); } }
internal static void Execute(object msg, User user) { Msg_CRC_SendImpactToEntity impact_msg = msg as Msg_CRC_SendImpactToEntity; if (null != impact_msg) { Scene scene = user.OwnRoom.GetActiveScene(); if (null != scene) { CharacterInfo character = scene.SceneContext.GetCharacterInfoById(impact_msg.sender_id); if (null != character && (character.OwnerId == user.RoleId || impact_msg.sender_id == user.RoleId)) { //校验 Vector3 senderPos = new Vector3(impact_msg.sender_pos.x, impact_msg.sender_pos.y, impact_msg.sender_pos.z); SkillInfo skillInfo = character.GetSkillStateInfo().GetSkillInfoById(impact_msg.skill_id); if (null != skillInfo && null != skillInfo.m_EnableImpactsToMyself && null != skillInfo.m_EnableImpactsToOther) { //LogSys.Log(LOG_TYPE.DEBUG, "----update hit count to " + impact_msg.hit_count); UpdateCharacterHitCount(character, impact_msg.hit_count); bool isSend = false; if (impact_msg.sender_id == impact_msg.target_id) { if (skillInfo.m_LeftEnableImpactsToMyself.Contains(impact_msg.impact_id)) {//给自己发impact skillInfo.m_LeftEnableImpactsToOther.Remove(impact_msg.impact_id); ImpactSystem.Instance.SendImpactToCharacter(character, impact_msg.impact_id, impact_msg.target_id, impact_msg.skill_id, impact_msg.duration, senderPos, impact_msg.sender_dir); isSend = true; //LogSys.Log(LOG_TYPE.WARN, "SendImpactToEntityHandler, send impact {0} to charactor {1}, leftImpacts:{2} skill:{3}", impact_msg.impact_id, impact_msg.target_id, string.Join<int>(",", skillInfo.m_LeftEnableImpactsToMyself), impact_msg.skill_id); } else { LogSys.Log(LOG_TYPE.ERROR, "SendImpactToEntityHandler, can't send impact {0} to charactor {1}, leftImpacts:{2} skill:{3}", impact_msg.impact_id, impact_msg.target_id, string.Join <int>(",", skillInfo.m_LeftEnableImpactsToMyself), impact_msg.skill_id); } } else {//给别人发impact List <int> leftImpacts; if (!skillInfo.m_LeftEnableImpactsToOther.TryGetValue(impact_msg.target_id, out leftImpacts)) { leftImpacts = new List <int>(); leftImpacts.AddRange(skillInfo.m_EnableImpactsToOther); if (TimeUtility.GetServerMilliseconds() <= character.GetSkillStateInfo().SimulateEndTime) { leftImpacts.AddRange(skillInfo.m_EnableImpactsToOther); } skillInfo.m_LeftEnableImpactsToOther.Add(impact_msg.target_id, leftImpacts); } if (null != leftImpacts && leftImpacts.Contains(impact_msg.impact_id)) { leftImpacts.Remove(impact_msg.impact_id); ImpactSystem.Instance.SendImpactToCharacter(character, impact_msg.impact_id, impact_msg.target_id, impact_msg.skill_id, impact_msg.duration, senderPos, impact_msg.sender_dir); isSend = true; //LogSys.Log(LOG_TYPE.WARN, "SendImpactToEntityHandler, send impact {0} to charactor {1}, leftImpacts:{2} skill:{3}", impact_msg.impact_id, impact_msg.target_id, string.Join<int>(",", leftImpacts), impact_msg.skill_id); } else { LogSys.Log(LOG_TYPE.ERROR, "SendImpactToEntityHandler, can't send impact {0} to charactor {1}, leftImpacts:{2} skill:{3}", impact_msg.impact_id, impact_msg.target_id, string.Join <int>(",", leftImpacts), impact_msg.skill_id); } } if (!isSend) { //todo:记录违规次数 } } else { LogSys.Log(LOG_TYPE.WARN, "SendImpactToEntityHandler, can't add impact!!"); } } else { if (null == character) { LogSys.Log(LOG_TYPE.ERROR, "SendImpactToEntityHandler, charactor {0} not exist", impact_msg.target_id); } else { LogSys.Log(LOG_TYPE.ERROR, "SendImpactToEntityHandler, charactor {0} or owner {1} not user {2}", character.GetId(), character.OwnerId, user.RoleId); } } } } }
private void PathToTargetWithoutObstacle(NpcInfo npc, AiPathData data, Vector3 pathTargetPos, long deltaTime) { NpcAiStateInfo info = npc.GetAiStateInfo(); if (null != data) { data.UpdateTime += deltaTime; ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); float dir = npc.GetMovementStateInfo().GetMoveDir(); bool findObstacle = false; bool havePathPoint = data.HavePathPoint; if (havePathPoint)//沿路点列表移动的逻辑 { Vector3 targetPos = data.CurPathPoint; if (!data.IsReached(srcPos))//向指定路点移动(避让移动过程) { float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); Vector3 prefVelocity = (float)npc.GetActualProperty().MoveSpeed *new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle)); Vector3 v = new Vector3(targetPos.X - srcPos.X, 0, targetPos.Z - srcPos.Z); v.Normalize(); Vector3 velocity = npc.SpaceObject.GetVelocity(); float speedSquare = (float)npc.GetActualProperty().MoveSpeed *(float)npc.GetActualProperty().MoveSpeed; long stTime = TimeUtility.GetElapsedTimeUs(); Vector3 newVelocity = npc.SpatialSystem.ComputeVelocity(npc.SpaceObject, v, (float)deltaTime / 1000, (float)npc.GetActualProperty().MoveSpeed, (float)npc.GetRadius(), data.IsUsingAvoidanceVelocity); long endTime = TimeUtility.GetElapsedTimeUs(); long calcTime = endTime - stTime; if (calcTime > 10000) { LogSystem.Warn("*** pvp ComputeVelocity consume {0} us,npc:{1} velocity:{2} newVelocity:{3} deltaTime:{4} speed:{5} pos:{6}", calcTime, npc.GetId(), velocity.ToString(), newVelocity.ToString(), deltaTime, npc.GetActualProperty().MoveSpeed, npc.GetMovementStateInfo().GetPosition3D().ToString()); for (LinkedListNode <UserInfo> node = npc.UserManager.Users.FirstValue; null != node; node = node.Next) { UserInfo userInfo = node.Value; if (null != userInfo) { LogSystem.Warn("===>User:{0} Pos:{1}", userInfo.GetId(), userInfo.GetMovementStateInfo().GetPosition3D().ToString()); } } for (LinkedListNode <NpcInfo> node = npc.NpcManager.Npcs.FirstValue; null != node; node = node.Next) { NpcInfo npcInfo = node.Value; if (null != npcInfo) { LogSystem.Warn("===>Npc:{0} Pos:{1}", npcInfo.GetId(), npcInfo.GetMovementStateInfo().GetPosition3D().ToString()); } } } if (findObstacle)//当前移动方向遇到阻挡,停止移动,触发寻路 { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } else if (!npc.GetMovementStateInfo().IsMoving&& velocity.LengthSquared() > speedSquare * 0.25f)//正常移动过程,继续移动 { velocity.Normalize(); npc.GetMovementStateInfo().TargetPosition = srcPos + velocity * Geometry.Distance(srcPos, targetPos); npc.GetMovementStateInfo().IsMoving = true; NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } } else//改变路点或结束沿路点移动 { data.UseNextPathPoint(); if (data.HavePathPoint) { targetPos = data.CurPathPoint; npc.GetMovementStateInfo().TargetPosition = targetPos; float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); npc.GetMovementStateInfo().SetFaceDir(angle); npc.GetMovementStateInfo().SetMoveDir(angle); npc.GetMovementStateInfo().IsMoving = true; NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } else { data.Clear(); } } } if (!havePathPoint || findObstacle)//获得路点过程(寻路) { data.Clear(); Vector3 targetPos = pathTargetPos; bool canGo = true; if (canGo) { List <Vector3> posList = null; bool canPass = npc.SpatialSystem.CanPass(npc.SpaceObject, targetPos); if (canPass) { posList = new List <Vector3>(); posList.Add(srcPos); posList.Add(targetPos); } else { long stTime = TimeUtility.GetElapsedTimeUs(); posList = npc.SpatialSystem.FindPath(srcPos, targetPos, npc.AvoidanceRadius); long endTime = TimeUtility.GetElapsedTimeUs(); long calcTime = endTime - stTime; if (calcTime > 10000) { LogSystem.Warn("*** pvp FindPath consume {0} us,npc:{1} from:{2} to:{3} radius:{4} pos:{5}", calcTime, npc.GetId(), srcPos.ToString(), targetPos.ToString(), npc.AvoidanceRadius, npc.GetMovementStateInfo().GetPosition3D().ToString()); } } if (posList.Count >= 2) { data.SetPathPoints(posList[0], posList, 1); targetPos = data.CurPathPoint; npc.GetMovementStateInfo().TargetPosition = targetPos; float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); npc.GetMovementStateInfo().SetFaceDir(angle); npc.GetMovementStateInfo().SetMoveDir(angle); npc.GetMovementStateInfo().IsMoving = true; NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } else { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } } else { npc.GetMovementStateInfo().IsMoving = false; NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } } } }
public void Tick() { long now = TimeUtility.GetServerMilliseconds(); m_LastTickIntervalMs = now - m_LastTickTime; m_LastTickTime = now; if (WorldSystem.Instance.IsObserver && !WorldSystem.Instance.IsFollowObserver) { bool keyPressed = false; float x = 0.5f, y = 0.5f; if (GfxSystem.IsKeyPressed(Keyboard.Code.A)) { x = 0.1f; keyPressed = true; } else if (GfxSystem.IsKeyPressed(Keyboard.Code.D)) { x = 0.9f; keyPressed = true; } if (GfxSystem.IsKeyPressed(Keyboard.Code.W)) { y = 0.1f; keyPressed = true; } else if (GfxSystem.IsKeyPressed(Keyboard.Code.S)) { y = 0.9f; keyPressed = true; } if (keyPressed) { WorldSystem.Instance.UpdateObserverCamera(x, y); } return; } // if move input is disable // MotionStatus is MoveStop, and MotionChanged is reflect the change accordingly // pm_.Update(EnableMoveInput); UserInfo playerself = WorldSystem.Instance.GetPlayerSelf(); if (null == playerself) { return; } Vector3 pos = playerself.GetMovementStateInfo().GetPosition3D(); Vector3 mouse_pos = new Vector3(GfxSystem.GetMouseX(), GfxSystem.GetMouseY(), GfxSystem.GetMouseZ());//GfxSystem.Instance.MainScene.GetMousePos(pos.Y); if (pm_.MotionStatus == PlayerMovement.Motion.Moving) { if (pm_.MotionChanged) { WorldSystem.Instance.InputMoveDir = pm_.MoveDir; playerself.GetMovementStateInfo().SetWantMoveDir(pm_.MoveDir); if (WorldSystem.Instance.IsPveScene()) { playerself.GetMovementStateInfo().SetMoveDir(pm_.MoveDir); playerself.GetMovementStateInfo().IsMoving = true; playerself.GetMovementStateInfo().TargetPosition = Vector3.Zero; } else { NetworkSystem.Instance.SyncPlayerMoveStart((float)pm_.MoveDir); } if (EnableRotateInput) { MovementStateInfo msi = playerself.GetMovementStateInfo(); msi.SetFaceDir(pm_.MoveDir); NetworkSystem.Instance.SyncFaceDirection((float)pm_.MoveDir); } } } else { if (pm_.MotionChanged) { WorldSystem.Instance.LastMoveDirAdjust = 0; if (WorldSystem.Instance.IsPveScene()) { playerself.GetMovementStateInfo().IsMoving = false; } else { NetworkSystem.Instance.SyncPlayerMoveStop(); } } } old_mouse_pos_ = mouse_pos_; mouse_pos_.X = GfxSystem.GetMouseX(); mouse_pos_.Y = GfxSystem.GetMouseY(); UserAiStateInfo aiInfo = playerself.GetAiStateInfo(); if (null != aiInfo && (int)AiStateId.Idle == aiInfo.CurState) { m_lastSelectObjId = -1; } }
private void TickUsers() { for (LinkedListNode <UserInfo> linkNode = UserManager.Users.FirstValue; null != linkNode; linkNode = linkNode.Next) { UserInfo info = linkNode.Value; if (info.GetEquipmentStateInfo().EquipmentChanged) { RefreshItemSkills(info); } if (info.LevelChanged || info.GetSkillStateInfo().BuffChanged || info.GetEquipmentStateInfo().EquipmentChanged || info.GetLegacyStateInfo().LegacyChanged) { UserAttrCalculator.Calc(info); info.LevelChanged = false; info.GetSkillStateInfo().BuffChanged = false; info.GetEquipmentStateInfo().EquipmentChanged = false; info.GetLegacyStateInfo().LegacyChanged = false; } if (info.Hp <= 0) { if (info.DeadTime <= 0) { //计算击杀收益 CalcKillIncome(info); info.GetCombatStatisticInfo().AddDeadCount(1); //死亡计数+1 //解除控制 ReleaseControl(info); //发送玩家死亡消息 Msg_RC_Dead build = new Msg_RC_Dead(); build.role_id = info.GetId(); NotifyAllUser(build); PlayerLevelupExpConfig cfg = PlayerConfigProvider.Instance.GetPlayerLevelupExpConfigById(info.GetLevel()); info.SetStateFlag(Operate_Type.OT_AddBit, CharacterState_Type.CST_BODY); m_StorySystem.SendMessage("userkilled", info.GetId(), GetLivingUserCount()); TryFireAllUserKilled(); NoticeAttempRoomClosing(); info.DeadTime = TimeUtility.GetServerMilliseconds(); if (null != cfg && m_IsPvpScene) { info.ReviveTime = TimeUtility.GetServerMilliseconds() + cfg.m_RebornTime * 1000; } else { info.ReviveTime = TimeUtility.GetServerMilliseconds() + info.ReleaseTime + 2000; } NpcInfo npc = NpcManager.GetNpcInfo(info.PartnerId); if (null != npc && npc.NpcType == (int)NpcTypeEnum.Partner) { npc.NeedDelete = true; } } else { /* * long delta = TimeUtility.GetServerMilliseconds() - info.DeadTime; * if (delta > info.ReleaseTime) { * info.DeadTime = info.ReviveTime; * Msg_RC_Disappear build = new Msg_RC_Disappear(); * build.role_id = info.GetId(); * NotifyAllUser(build); * } */ } } } }
internal void EndBattle(int winnerCampID) { if (this.CurrentState == RoomState.Finish || this.CurrentState == RoomState.Deactive) { return; } foreach (User user in room_users_) { if (user != null) { Msg_RL_UserQuit.Builder unqBuilder = Msg_RL_UserQuit.CreateBuilder(); unqBuilder.SetRoomID(cur_room_id_); unqBuilder.SetUserGuid(user.Guid); unqBuilder.SetIsBattleEnd(true); connector_.SendMsgToLobby(unqBuilder.Build()); } } //向Lobby发送战斗结束消息:RoomID,胜方阵营,开始时间,结束时间。。。 Msg_RL_BattleEnd.Builder beBuilder = Msg_RL_BattleEnd.CreateBuilder(); beBuilder.SetRoomID(RoomID); Msg_RL_BattleEnd.Types.WinnerCampEnum winCamp = Msg_RL_BattleEnd.Types.WinnerCampEnum.None; if (winnerCampID == (int)CampIdEnum.Blue) { winCamp = Msg_RL_BattleEnd.Types.WinnerCampEnum.Blue; } else { winCamp = Msg_RL_BattleEnd.Types.WinnerCampEnum.Red; } beBuilder.SetWinnerCamp(winCamp); //战斗数据 foreach (User user in room_users_) { if (user != null) { var battleRecord = user.Info.GetCombatStatisticInfo(); Msg_RL_UserBattleInfo.Builder ubrBuilder = Msg_RL_UserBattleInfo.CreateBuilder(); ubrBuilder.SetUserGuid(user.Guid); Msg_RL_UserBattleInfo.Types.BattleResultEnum result = Msg_RL_UserBattleInfo.Types.BattleResultEnum.Unfinish; if (winnerCampID != (int)CampIdEnum.Unkown) { if (user.CampId == winnerCampID) { result = Msg_RL_UserBattleInfo.Types.BattleResultEnum.Win; } else { result = Msg_RL_UserBattleInfo.Types.BattleResultEnum.Lost; } } ubrBuilder.SetBattleResult(result); ubrBuilder.SetMoney(user.Info.Money); CombatStatisticInfo combatInfo = user.Info.GetCombatStatisticInfo(); ubrBuilder.SetHitCount(combatInfo.HitCount); ubrBuilder.SetMaxMultiHitCount(combatInfo.MaxMultiHitCount); ubrBuilder.SetTotalDamageToMyself(combatInfo.TotalDamageToMyself); ubrBuilder.SetTotalDamageFromMyself(combatInfo.TotalDamageFromMyself); beBuilder.AddUserBattleInfos(ubrBuilder.Build()); } } connector_.SendMsgToLobby(beBuilder.Build()); this.CurrentState = RoomState.Finish; m_FinishTime = TimeUtility.GetServerMilliseconds(); LogSys.Log(LOG_TYPE.DEBUG, "Room {0}({1}) EndBattle.", RoomID, LocalID); }
public static void PathToTarget(NpcInfo npc, AiPathData data, Vector3 pathTargetPos, long deltaTime, bool faceIsMoveFir, AbstractNpcStateLogic logic) { NpcAiStateInfo info = npc.GetAiStateInfo(); if (null != data) { data.UpdateTime += deltaTime; ScriptRuntime.Vector3 srcPos = npc.GetMovementStateInfo().GetPosition3D(); float dir = npc.GetMovementStateInfo().GetMoveDir(); bool findObstacle = false; bool havePathPoint = data.HavePathPoint; if (havePathPoint)//沿路点列表移动的逻辑 { Vector3 targetPos = data.CurPathPoint; if (!data.IsReached(srcPos))//向指定路点移动(避让移动过程) { float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); Vector3 prefVelocity = (float)npc.GetActualProperty().MoveSpeed *new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle)); Vector3 v = new Vector3(targetPos.X - srcPos.X, 0, targetPos.Z - srcPos.Z); v.Normalize(); Vector3 velocity = npc.SpaceObject.GetVelocity(); float speedSquare = (float)npc.GetActualProperty().MoveSpeed *(float)npc.GetActualProperty().MoveSpeed; long stTime = TimeUtility.GetElapsedTimeUs(); Vector3 newVelocity = npc.SpatialSystem.ComputeVelocity(npc.SpaceObject, v, (float)deltaTime / 1000, (float)npc.GetActualProperty().MoveSpeed, (float)npc.GetRadius(), data.IsUsingAvoidanceVelocity); findObstacle = !AiLogicUtility.IsWalkable(npc.SpatialSystem.GetCellMapView(npc.AvoidanceRadius), srcPos, newVelocity); long endTime = TimeUtility.GetElapsedTimeUs(); long calcTime = endTime - stTime; if (calcTime > 10000) { LogSystem.Warn("*** pve ComputeVelocity consume {0} us,npc:{1} velocity:{2} newVelocity:{3} deltaTime:{4} speed:{5} pos:{6}", calcTime, npc.GetId(), velocity.ToString(), newVelocity.ToString(), deltaTime, npc.GetActualProperty().MoveSpeed, npc.GetMovementStateInfo().GetPosition3D().ToString()); } if (Geometry.DistanceSquare(newVelocity, new Vector3()) <= speedSquare * 0.25f)//避让计算的移动速度变小(说明没有更好的保持原速的选择,停止) { npc.GetMovementStateInfo().IsMoving = false; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } else if (findObstacle)//当前移动方向遇到阻挡,停止移动,触发寻路 { npc.GetMovementStateInfo().IsMoving = false; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } else if (data.UpdateTime > 1000)//避让速度改变每秒一次(表现上更像人类一些) { data.UpdateTime = 0; float newAngle = Geometry.GetYAngle(new Vector2(0, 0), new Vector2(newVelocity.X, newVelocity.Z)); npc.GetMovementStateInfo().SetMoveDir(newAngle); if (faceIsMoveFir) { npc.GetMovementStateInfo().SetFaceDir(newAngle); } newVelocity.Normalize(); npc.GetMovementStateInfo().TargetPosition = srcPos + newVelocity * Geometry.Distance(srcPos, targetPos); npc.GetMovementStateInfo().IsMoving = true; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = true; } else if (Geometry.DistanceSquare(velocity, newVelocity) > 9.0f) //没有到速度改变周期,但避让方向需要大幅调整 { if (Geometry.Dot(newVelocity, prefVelocity) > 0) //如果是调整为与目标方向一致,则进行调整 { float newAngle = Geometry.GetYAngle(new Vector2(0, 0), new Vector2(newVelocity.X, newVelocity.Z)); npc.GetMovementStateInfo().SetMoveDir(newAngle); if (faceIsMoveFir) { npc.GetMovementStateInfo().SetFaceDir(newAngle); } newVelocity.Normalize(); npc.GetMovementStateInfo().TargetPosition = srcPos + newVelocity * Geometry.Distance(srcPos, targetPos); npc.GetMovementStateInfo().IsMoving = true; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = true; } else//如果调整为远离目标方向,则停止 { npc.GetMovementStateInfo().IsMoving = false; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } } else if (!npc.GetMovementStateInfo().IsMoving&& velocity.LengthSquared() > speedSquare * 0.25f)//正常移动过程,继续移动 { velocity.Normalize(); npc.GetMovementStateInfo().TargetPosition = srcPos + velocity * Geometry.Distance(srcPos, targetPos); npc.GetMovementStateInfo().IsMoving = true; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } } else//改变路点或结束沿路点移动 { data.UseNextPathPoint(); if (data.HavePathPoint) { targetPos = data.CurPathPoint; npc.GetMovementStateInfo().TargetPosition = targetPos; float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); npc.GetMovementStateInfo().SetMoveDir(angle); if (faceIsMoveFir) { npc.GetMovementStateInfo().SetFaceDir(angle); } npc.GetMovementStateInfo().IsMoving = true; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } else { data.Clear(); } } } if (!havePathPoint || findObstacle)//获得路点过程(寻路) { data.Clear(); Vector3 targetPos = pathTargetPos; bool canGo = true; if (!npc.SpatialSystem.GetCellMapView(npc.AvoidanceRadius).CanPass(targetPos)) { if (!AiLogicUtility.GetWalkablePosition(npc.SpatialSystem.GetCellMapView(npc.AvoidanceRadius), targetPos, srcPos, ref targetPos)) { canGo = false; } } if (canGo) { List <Vector3> posList = null; bool canPass = npc.SpatialSystem.CanPass(npc.SpaceObject, targetPos); if (canPass) { posList = new List <Vector3>(); posList.Add(srcPos); posList.Add(targetPos); } else { long stTime = TimeUtility.GetElapsedTimeUs(); posList = npc.SpatialSystem.FindPath(srcPos, targetPos, npc.AvoidanceRadius); long endTime = TimeUtility.GetElapsedTimeUs(); long calcTime = endTime - stTime; if (calcTime > 10000) { LogSystem.Warn("*** pve FindPath consume {0} us,npc:{1} from:{2} to:{3} radius:{4} pos:{5}", calcTime, npc.GetId(), srcPos.ToString(), targetPos.ToString(), npc.AvoidanceRadius, npc.GetMovementStateInfo().GetPosition3D().ToString()); } } if (posList.Count >= 2) { data.SetPathPoints(posList[0], posList, 1); targetPos = data.CurPathPoint; npc.GetMovementStateInfo().TargetPosition = targetPos; float angle = Geometry.GetYAngle(new Vector2(srcPos.X, srcPos.Z), new Vector2(targetPos.X, targetPos.Z)); npc.GetMovementStateInfo().SetMoveDir(angle); if (faceIsMoveFir) { npc.GetMovementStateInfo().SetFaceDir(angle); } npc.GetMovementStateInfo().IsMoving = true; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } else { npc.GetMovementStateInfo().IsMoving = false; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } } else { npc.GetMovementStateInfo().IsMoving = false; logic.NotifyNpcMove(npc); data.IsUsingAvoidanceVelocity = false; } } } }