/// <summary>Handle the command.</summary> /// <param name="monitor">Writes messages to the console and log file.</param> /// <param name="command">The command name.</param> /// <param name="args">The command arguments.</param> public override void Handle(IMonitor monitor, string command, ArgumentParser args) { // parse arguments if (!args.TryGet(0, "target", out string target)) { return; } WorldActor entity = SGame.Instance.xEntityMaster.FindEntityByTag(target) as WorldActor; if (entity == null) { monitor.Log($"Target {target} not found", LogLevel.Info); return; } BaseStats stats = entity.xBaseStats; if (!args.TryGet(1, "stat", out string stat)) { return; } // handle switch (target) { case "hp": { if (!args.TryGetInt(2, "value", out int value, required: false)) { monitor.Log($"Current hp is {stats.iHP}", LogLevel.Info); }
public void RunService(int serverPort) { if (m_actorManager != null) { return; } m_actorManager = new ActorManager(); m_watchDogActor = new WatchDogActor(this); //Id为1的Actor, 不与Agent绑定,也没有U3DId标识 m_actorManager.AddActor(m_watchDogActor, true); m_worldActor = new WorldActor(this); m_watchDogActor.WorldActor = m_worldActor; //Id为2的Actor, 不与Agent绑定,也没有U3DId标识 m_actorManager.AddActor(m_worldActor, true); m_serverActor = new ServerActor(this); m_watchDogActor.ServerActor = m_serverActor; m_serverActor.WatchDogActor = m_watchDogActor; //Id为3的Actor, 不与Agent绑定,也没有U3DId标识 m_actorManager.AddActor(m_serverActor, true); //启动服务器 m_serverActor.Run(serverPort); }
private void DestroyPlayerActorCallback(uint agentId) { Agent agent = ServerActor.GetAgent(agentId); if (agent == null) { return; } PlayerActor playerActor = (PlayerActor)agent.Actor; if (playerActor != null) { if (playerActor.PlayerActorType == PlayerActorType.U3DPlayerActorType) { //移除 WorldActor.RemovePlayerActor4U3DDict(playerActor); //如果PlayerActor是U3DPlayerActor类型, 需要通知UI更新 SendNotification(EventID_Cmd.U3DClientOffLine, playerActor.U3DId, null); } else if (playerActor.PlayerActorType == PlayerActorType.StationPlayerActorType) { WorldActor.RemoveStationPlayerActor4StationDict(playerActor); SendNotification(EventID_Cmd.StationClientOffLine, null, null); } playerActor.Stop(); ActorManager.Instance.RemoveActor(playerActor.Id); agent.Actor = null; } ServerActor.RemoveAgent(agent); }
public BaseHandle GetHandleInstantiateObj(UInt16 firstId, UInt16 secondId, Agent agent, WorldActor worldActor, PlayerActor playerActor) { string handleClassName = ""; if (m_packetHandleMap.ContainsKey(firstId)) { if (m_packetHandleMap[firstId].ContainsKey(secondId)) { handleClassName = m_packetHandleMap[firstId][secondId]; } } if (string.IsNullOrEmpty(handleClassName)) { return(null); } //带参数的反射类实例 Assembly assembly = Type.GetType(handleClassName).Assembly; Object[] parameters = new Object[3]; parameters[0] = agent; parameters[1] = worldActor; parameters[2] = playerActor; BaseHandle handle = (BaseHandle)Assembly.Load(assembly.FullName).CreateInstance(handleClassName, false, BindingFlags.Default, null, parameters, null, null); return(handle); }
public PlayerActor(uint agentId, MonoBehaviour mono) : base(mono) { AgentId = agentId; ServerActor server = ActorManager.Instance.GetActor <ServerActor>(); m_agent = server.GetAgent(m_agentId); m_agent.Actor = this; m_worldActor = ActorManager.Instance.GetActor <WorldActor>(); }
public override void OnTaunted(WorldActor xTauntSource) { base.OnTaunted(xTauntSource); bTotallyMad = true; xPlayerLockedOnto = xTauntSource; if (fFurthestAllowedDistance < 200f) { fFurthestAllowedDistance = 200f; } }
public void EndGame() { if (!IsGameOver) { IsGameOver = true; foreach (var t in WorldActor.TraitsImplementing <IGameOver>()) { t.GameOver(this); } GameOver(); } }
public void EndGame() { if (!IsGameOver) { IsGameOver = true; foreach (var t in WorldActor.TraitsImplementing <IGameOver>()) { t.GameOver(this); } gameInfo.FinalGameTick = WorldTick; GameOver(); } }
public void EndGame() { if (!IsGameOver) { IsGameOver = true; foreach (var t in WorldActor.TraitsImplementing <IGameOver>()) { t.GameOver(this); } GameOver(); Console.WriteLine("Game Over!"); Game.Exit(); } }
public void StopDogActorAndWorldActor() { if (m_actorManager != null) { if (m_watchDogActor != null) { m_watchDogActor.Stop(); m_actorManager.RemoveActor(m_watchDogActor.Id); m_watchDogActor = null; } if (m_worldActor != null) { m_worldActor.Stop(); m_actorManager.RemoveActor(m_worldActor.Id); m_worldActor = null; } m_actorManager = null; } }
private static bool GetEntityAttribute(WorldActor entity, string attr, out string value) { switch (attr) { case "hp": value = entity.xBaseStats.iHP.ToString(); return(true); case "ep": value = entity.xBaseStats.iEP.ToString(); return(true); case "level": value = entity.xBaseStats.iLevel.ToString(); return(true); default: value = ""; return(false); } }
public BaseHandle(Agent agent, WorldActor worldActor, PlayerActor playerActor) { m_agent = agent; m_worldActor = worldActor; m_playerActor = playerActor; }
public U3DClientLoginHandle(Agent agent, WorldActor worldActor, PlayerActor playerActor) : base(agent, worldActor, playerActor) { Name = "U3DClientLoginHandle"; }
public override void OnUpdate() { if (!bInited) { bInited = true; } if (v2RandMoveDir != Vector2.Zero && iNextHardUpdate > 0 && xOwner.xRenderComponent.GetCurrentAnimation().bIsMoveCancellable) { Move(v2RandMoveDir); } iCounter++; iNextHardUpdate--; if (xCatchMode != null) { if (xCatchMode.enPhase == CatchMode.Phase.WaitingForBaitedEnemy) { float fDistance2 = 50000f; WorldActor xClosestPlayer2 = xCatchMode.xView.xEntity; Vector2 v2TargetPosition = ((!(xClosestPlayer2.xTransform.v2Pos.X >= xOwner.xTransform.v2Pos.X)) ? (xClosestPlayer2.xTransform.v2Pos + new Vector2(30f, 0f)) : (xClosestPlayer2.xTransform.v2Pos - new Vector2(30f, 0f))); fDistance2 = Vector2.Distance(v2TargetPosition, xOwner.xTransform.v2Pos); if (xClosestPlayer2 != null && iNextHardUpdate <= 0) { if (fDistance2 < 5f) { xCatchMode.EnterMiniGame(); xOwner.xRenderComponent.SwitchAnimation(0, Animation.CancelOptions.UseAnimationDefault); v2RandMoveDir = Vector2.Zero; } else { iNextHardUpdate = 40; v2RandMoveDir = v2TargetPosition - xOwner.xTransform.v2Pos; v2RandMoveDir = v2RandMoveDir.SafeNormalized(); if (fDistance2 < 18f) { v2RandMoveDir *= fDistance2 / 18f; } xOwner.xRenderComponent.SwitchAnimation(1, Animation.CancelOptions.IgnoreIfPlaying); } } } xOwner.xTransform.v2ServerPos = xOwner.xTransform.v2Pos; return; } if ((!(v2RandMoveDir != Vector2.Zero) || iNextHardUpdate <= 0 || !xOwner.xRenderComponent.GetCurrentAnimation().bIsMoveCancellable) && xOwner.xRenderComponent.GetCurrentAnimation().bIsMoveCancellable) { if (xPlayerLockedOnto != null && bTotallyMad) { float fDistance3 = Vector2.Distance(xPlayerLockedOnto.GetBelievedPosition(), xOwner.xTransform.v2Pos); Vector2 v2Dir = xPlayerLockedOnto.GetBelievedPosition() - xOwner.xTransform.v2Pos; v2Dir = v2Dir.SafeNormalized(); xOwner.xRenderComponent.SwitchAnimation(1, Animation.CancelOptions.UseAnimationDefault); if (fDistance3 > fAttackDistance * 2.2f) { TryMove(v2Dir); xOwner.xRenderComponent.SwitchAnimation(1, Animation.CancelOptions.UseAnimationDefault); } else if (fDistance3 > fAttackDistance * 1.25f) { Vector2 v2LineDir = Utility.FindClosestStraightLine(xOwner.xTransform.v2Pos, xPlayerLockedOnto.GetBelievedPosition()); if (v2LineDir != Vector2.Zero) { v2LineDir = Utility.Normalize(v2LineDir); } v2Dir += v2LineDir; v2Dir = v2Dir.SafeNormalized(); TryMove(v2Dir); xOwner.xRenderComponent.SwitchAnimation(1, Animation.CancelOptions.UseAnimationDefault); } else { v2Dir = Utility.FindClosestStraightLine(xOwner.xTransform.v2Pos, xPlayerLockedOnto.GetBelievedPosition()); v2Dir = v2Dir.SafeNormalized(); if (v2Dir != Vector2.Zero) { if (v2Dir.X != 0f) { float fDist3 = MathHelper.Distance(xOwner.xTransform.v2Pos.X, xPlayerLockedOnto.GetBelievedPosition().X); if (fDist3 < xOwner.xBaseStats.fMovementSpeed * 6f * 4f) { v2Dir *= fDist3 / (xOwner.xBaseStats.fMovementSpeed * 6f * 4f); } } else { float fDist2 = MathHelper.Distance(xOwner.xTransform.v2Pos.Y, xPlayerLockedOnto.GetBelievedPosition().Y); if (fDist2 < xOwner.xBaseStats.fMovementSpeed * 6f * 4f) { v2Dir *= fDist2 / (xOwner.xBaseStats.fMovementSpeed * 6f * 4f); } } } TryMove(v2Dir); } if (fDistance3 <= fAttackDistance * 1.3f) { if (MathHelper.Distance(xOwner.xTransform.v2Pos.X, xPlayerLockedOnto.GetBelievedPosition().X) < 8f) { if (xOwner.xTransform.v2Pos.Y < xPlayerLockedOnto.GetBelievedPosition().Y) { Utils.GetTheGame()._Enemy_EnterAttackAnimation(xOwner, 6); bTotallyMad = false; v2RandMoveDir = Vector2.Zero; iNextHardUpdate = 1; } else { Utils.GetTheGame()._Enemy_EnterAttackAnimation(xOwner, 4); bTotallyMad = false; v2RandMoveDir = Vector2.Zero; iNextHardUpdate = 1; } } else if (MathHelper.Distance(xOwner.xTransform.v2Pos.Y, xPlayerLockedOnto.GetBelievedPosition().Y) < 8f) { if (xOwner.xTransform.v2Pos.X < xPlayerLockedOnto.GetBelievedPosition().X) { Utils.GetTheGame()._Enemy_EnterAttackAnimation(xOwner, 5); bTotallyMad = false; v2RandMoveDir = Vector2.Zero; iNextHardUpdate = 1; } else { Utils.GetTheGame()._Enemy_EnterAttackAnimation(xOwner, 7); bTotallyMad = false; v2RandMoveDir = Vector2.Zero; iNextHardUpdate = 1; } } } if (fDistance3 > fFurthestAllowedDistance) { xPlayerLockedOnto = null; } } else { xOwner.xRenderComponent.SwitchAnimation(0, Animation.CancelOptions.UseAnimationDefault); } if (iNextHardUpdate <= 0) { while (lv2PathFindingPositions.Count > 0) { if (Vector2.Distance(lv2PathFindingPositions[0], xOwner.xTransform.v2Pos) < 15f) { lv2PathFindingPositions.RemoveAt(0); continue; } iNextHardUpdate = 40; v2RandMoveDir = lv2PathFindingPositions[0] - xOwner.xTransform.v2Pos; v2RandMoveDir = v2RandMoveDir.SafeNormalized(); xOwner.xRenderComponent.SwitchAnimation(1, Animation.CancelOptions.IgnoreIfPlaying); return; } iNextHardUpdate = 10; Game1 Lord = Utils.GetTheGame(); float fClosest = 50000f; Item xClosestItem = null; WorldActor xClosestPlayer = null; List <WorldActor> lx = Lord._Enemy_GetTargetList(this); foreach (WorldActor xActor in lx) { float fDist = Vector2.Distance(xActor.xTransform.v2Pos, xOwner.xTransform.v2Pos); if (fDist < fFurthestAllowedDistance && fDist < fClosest) { xClosestPlayer = xActor; fClosest = fDist; } } if (xTauntSource != null && Vector2.Distance(xTauntSource.xTransform.v2Pos, xOwner.xTransform.v2Pos) < fFurthestAllowedDistance) { xClosestPlayer = xTauntSource; } Random knark = Utils.GetTheGame().randomInLogic; if (xPlayerLockedOnto == null && xClosestPlayer != null) { bTotallyMad = true; } else if (xClosestPlayer != null && knark.Next(4) == 0) { bTotallyMad = true; } if (xClosestPlayer != null) { xPlayerLockedOnto = xClosestPlayer; xItemLockedOnto = null; float fDistance = Vector2.Distance(xPlayerLockedOnto.GetBelievedPosition(), xOwner.xTransform.v2Pos); if (!bTotallyMad) { if (fDistance <= 30f) { bTotallyMad = true; } else if (knark.Next(3) == 0) { iNextHardUpdate = 56; Vector2 v2RealDir = xPlayerLockedOnto.GetBelievedPosition() - xOwner.xTransform.v2Pos; v2RealDir = v2RealDir.SafeNormalized(); v2RandMoveDir = new Vector2(((float)knark.NextDouble() / 2f + 0.5f) * v2RealDir.X, ((float)knark.NextDouble() / 2f + 0.5f) * v2RealDir.Y); v2RandMoveDir = v2RandMoveDir.SafeNormalized(); xOwner.xRenderComponent.SwitchAnimation(1, Animation.CancelOptions.IgnoreIfPlaying); } else { xOwner.xRenderComponent.SwitchAnimation(0, Animation.CancelOptions.IgnoreIfPlaying); v2RandMoveDir = Vector2.Zero; } } } else if (xClosestItem != null) { xItemLockedOnto = xClosestItem; xPlayerLockedOnto = null; } else { Rectangle levelRec = Utils.GetTheGame().xLevelMaster.xCurrentLevel.recCurrentBounds; if (!levelRec.Contains((int)xOwner.xTransform.v2Pos.X, (int)xOwner.xTransform.v2Pos.Y)) { iNextHardUpdate = 70 + knark.Next(40); v2RandMoveDir = new Vector2(levelRec.Center.X, levelRec.Center.Y) - xOwner.xTransform.v2Pos; v2RandMoveDir = v2RandMoveDir.SafeNormalized(); } else if (knark.Next(20) == 1) { iNextHardUpdate = 120; if (xClosestPlayer != null) { iNextHardUpdate = 40; } v2RandMoveDir = new Vector2(-1f + (float)knark.NextDouble() * 2f, -1f + (float)knark.NextDouble() * 2f); v2RandMoveDir = v2RandMoveDir.SafeNormalized(); } else { iNextHardUpdate = 10; v2RandMoveDir = Vector2.Zero; } } } } xOwner.xTransform.v2ServerPos = xOwner.xTransform.v2Pos; }
public ClientReConnectHandle(Agent agent, WorldActor worldActor, PlayerActor playerActor) : base(agent, worldActor, playerActor) { Name = "ClientReConnectHandle"; }