public static void Handle(Player player, MsgWalk packet)
        {
            var    uniqueId  = packet.UniqueId;
            var    location  = new Vector2(packet.X, packet.Y);
            var    tickCount = packet.TickCount;
            Entity entity    = null;

            if (uniqueId == player.UniqueId)
            {
                return;
            }

            if (Collections.Entities.TryGetValue(uniqueId, out entity))
            {
                ThreadedConsole.WriteLine("[Net][MsgWalk] Walk Packet for existing Player #" + entity.UniqueId);
                entity.MoveTo(location);
            }
            else
            {
                entity = Entity.Spawn(uniqueId, location);
                ThreadedConsole.WriteLine("[Net][MsgWalk] Walk Packet for New Player #" + entity.UniqueId);
                SceneManager.CurrentScene.Entities.Add(entity);
            }
        }
Example #2
0
 public static void Handle(MsgWalk packet)
 {
     if (World.UidExists(packet.UniqueId))
     {
         ref readonly var entity = ref World.GetEntityByUniqueId(packet.UniqueId);
        public static void HandleWalk(Client pClient, MsgWalk pMsg)
        {
            if (pClient.Character != null &&
                pClient.Character.Identity == pMsg.Identity)
            {
                byte   direction;
                ushort x;
                ushort y;

                // Get the data from the packet:
                switch (pMsg.Action)
                {
                case MovementType.WALK:
                case MovementType.RUN:
                    direction = (byte)(pMsg.Direction % 8);
                    x         = (ushort)(pClient.Character.MapX + WALK_X_COORDS[direction]);
                    y         = (ushort)(pClient.Character.MapY + WALK_Y_COORDS[direction]);
                    break;

                case MovementType.RIDE:
                    direction = (byte)(pMsg.Direction % 24);
                    x         = (ushort)(pClient.Character.MapX + DELTA_WALK_X_COORDS[direction]);
                    y         = (ushort)(pClient.Character.MapY + DELTA_WALK_Y_COORDS[direction]);
                    break;

                default:
                    pClient.Character.Kickback(pClient.Character.MapX, pClient.Character.MapY);
                    return;
                }

                Tile tile = pClient.Character.Map[x, y];
                if (tile.Access > TileType.NPC && !pClient.Character.IsFreeze &&
                    !(pClient.Character.QueryStatus(Core.Common.Enums.FlagInt.CTF_FLAG) != null &&
                      pClient.Character.Map.QueryRegion(RegionType.REGION_PK_PROTECTED, x, y)))
                {
                    // The packet is valid. Assign character data:
                    pClient.Character.MapX      = x;
                    pClient.Character.MapY      = y;
                    pClient.Character.Direction = (FacingDirection)direction;
                    pClient.Character.Action    = EntityAction.STAND;
                    pClient.Character.Elevation = tile.Elevation;
                    pClient.Tile = tile;

                    // Send the movement back to the message server and client:
                    pClient.Send(pMsg);
                    pClient.Screen.SendMovement(pMsg);

                    if (pClient.Character.QueryStatus(Core.Common.Enums.FlagInt.RIDING) != null)
                    {
                        if (pClient.Character.Vigor > 1)
                        {
                            pClient.Character.Vigor -= 2;
                        }
                    }

                    pClient.Character.ProcessOnMove();
                    return;
                }
                pClient.Character.Kickback(pClient.Character.MapX, pClient.Character.MapY);
            }
            else
            {
                Console.WriteLine("RoleID:{0} tried MsgWalk::{1}", pMsg.Identity, pMsg.Action);
            }
        }