예제 #1
0
        public static CreateParticleHook ReadHookType(DatReader datReader)
        {
            CreateParticleHook hook = new CreateParticleHook();

            hook.EmitterInfoId = datReader.ReadUInt32();

            hook.PartIndex = datReader.ReadUInt32();

            hook.Offset = PositionExtensions.ReadPosition(datReader);

            hook.EmitterId = datReader.ReadUInt32();
            return(hook);
        }
예제 #2
0
        private static Result <ArrayOrObject <Location, Location>, ResponseError> DefinitionForTemplateExpression(INode node, string name)
        {
            var taggedTemplte     = node.Parent.Cast <ITaggedTemplateExpression>();
            var literal           = taggedTemplte.TemplateExpression.Cast <ILiteralExpression>();
            var interpolationKind = taggedTemplte.GetInterpolationKind();

            // This is p`` or f`` or `r`
            if (interpolationKind == InterpolationKind.FileInterpolation ||
                interpolationKind == InterpolationKind.PathInterpolation ||
                interpolationKind == InterpolationKind.RelativePathInterpolation)
            {
                string fullPath = string.Empty;

                // Exceptions can happen if the string literal contains any invalid path characters (such as * and ?)
                // as well if there is any string interoplation in them such as ${variable} as the $ is also an invalid path
                // character.
                try
                {
                    if (Path.IsPathRooted(literal.Text))
                    {
                        fullPath = literal.Text;
                    }
                    else
                    {
                        fullPath = Path.Combine(Path.GetDirectoryName(node.GetSourceFile().Path.AbsolutePath), literal.Text);
                    }
                }
                catch (ArgumentException)
                {
                    // An ArgumentException from IsPathRooted indicates that the path has invalid characters.
                    // Path.IsPathRooted and Path.Combine throw ArgumentException;
                }

                // This is path or file.
                // They can be absolute or relative to the current file.

                if (!string.IsNullOrEmpty(fullPath))
                {
                    return(Success(new[]
                    {
                        new Location()
                        {
                            Range = PositionExtensions.EmptyRange(),
                            Uri = UriExtensions.GetUriFromPath(fullPath).ToString(),
                        },
                    }));
                }
            }

            return(SilentError());
        }
예제 #3
0
    public override void OnBeforeMoveTile(Position movingTo)
    {
        // Inform the server i moved
        UnityClient.TcpClient.Send(new EntityMovePacket()
        {
            UID = UnityClient.Player.UID,
            To  = movingTo
        });

        var playerPos = UnityClient.Player.Position;

        var currentChunk = UnityClient.Map.GetChunkByTilePosition(playerPos.X, playerPos.Y);
        var newChunk     = UnityClient.Map.GetChunkByTilePosition(movingTo.X, movingTo.Y);

        if (currentChunk.x != newChunk.x || currentChunk.y != newChunk.y)
        {
            var currentChunkX = playerPos.X >> 4;
            var currentChunkY = playerPos.Y >> 4;

            var newChunkX = movingTo.X >> 4;
            var newChunkY = movingTo.Y >> 4;

            var currentChunkParents = PositionExtensions.GetSquared3x3Around(new Position(currentChunkX, currentChunkY)).ToList();
            var newChunkParents     = PositionExtensions.GetSquared3x3Around(new Position(newChunkX, newChunkY)).ToList();

            foreach (var cc in currentChunkParents.Except(newChunkParents))
            {
                var chunk = UnityClient.Map.GetChunkByChunkPosition(cc.X, cc.Y);
                if (chunk != null)
                {
                    chunk.GameObject.SetActive(false);
                }
            }

            foreach (var nc in newChunkParents.Except(currentChunkParents))
            {
                var chunk = UnityClient.Map.GetChunkByChunkPosition(nc.X, nc.Y);
                if (chunk != null)
                {
                    chunk.GameObject.SetActive(true);
                }
            }
        }
    }
예제 #4
0
        public static Animation ReadFromDat(uint fileId)
        {
            // Check the FileCache so we don't need to hit the FileSystem repeatedly
            if (DatManager.PortalDat.FileCache.ContainsKey(fileId))
            {
                return((Animation)DatManager.PortalDat.FileCache[fileId]);
            }
            else
            {
                DatReader datReader = DatManager.PortalDat.GetReaderForFile(fileId);
                Animation a         = new Animation();
                a.AnimationId = datReader.ReadUInt32();

                uint flags = datReader.ReadUInt32();

                a.NumParts  = datReader.ReadUInt32();
                a.NumFrames = datReader.ReadUInt32();

                bool hasPosFrames = ((flags & 1) > 0);
                if (hasPosFrames && a.NumFrames > 0)
                {
                    for (uint i = 0; i < a.NumFrames; i++)
                    {
                        // Origin
                        a.PosFrames.Add(PositionExtensions.ReadPosition(datReader));
                    }
                }

                for (uint i = 0; i < a.NumFrames; i++)
                {
                    AnimationFrame f = AnimationFrame.Read(a.NumParts, datReader);
                    a.Frames.Add(f);
                }

                // Store this object in the FileCache
                DatManager.PortalDat.FileCache[fileId] = a;

                return(a);
            }
        }
예제 #5
0
        // server recieving entitymove means its a player moving
        public void OnEntityMovePacket(EntityMovePacket packet)
        {
            var player           = Server.GetPlayerByConnectionId(packet.ClientId);
            var originalPosition = new Position(player.Position.X, player.Position.Y);
            var distanceMoved    = PositionExtensions.GetDistance(player.Position, packet.To);
            var timeToMove       = Formulas.GetTimeToMoveBetweenTwoTiles(player.MoveSpeed);

            var now = GameThread.TIME_MS_NOW;

            // Player tryng to hack ?
            var isPassable = Server.Map.IsPassable(packet.To.X, packet.To.Y);

            if (distanceMoved > 1 || now < player.CanMoveAgainTime || !isPassable)
            {
                // send player back to the position client-side
                player.Tcp.Send(new SyncPacket()
                {
                    Position = player.Position
                });
                return;
            }

            // subtract the player latency for possibility of lag for a smoother movement
            player.CanMoveAgainTime = now + timeToMove - player.Tcp.Latency;

            var entityMoveEvent = new EntityMoveEvent()
            {
                To     = packet.To,
                Entity = player
            };

            Server.Events.Call(entityMoveEvent);

            // updating in database
            PlayerService.UpdatePlayerPosition(player.UID, player.Position.X, player.Position.Y);


            // update chunks for that player
            ChunkProvider.CheckChunks(player);
        }
예제 #6
0
        public static List <OnlinePlayer> GetPlayersNear(this Entity player)
        {
            List <OnlinePlayer> near = new List <OnlinePlayer>();
            var chunk  = player.GetChunk();
            var radius = PositionExtensions.GetSquared3x3Around(new Position(chunk.x, chunk.y));

            foreach (var position in radius)
            {
                var chunkThere = Server.Map.GetChunkByChunkPosition(position.X, position.Y);
                if (chunkThere != null)
                {
                    foreach (var playerInChunk in chunkThere.EntitiesInChunk[EntityType.PLAYER])
                    {
                        if (playerInChunk.UID != player.UID)
                        {
                            near.Add((OnlinePlayer)playerInChunk);
                        }
                    }
                }
            }
            return(near);
        }
예제 #7
0
        public static void CheckChunks(this OnlinePlayer player)
        {
            var client = player.Tcp;

            if (client.OnlinePlayer != null && client.OnlinePlayer.AssetsReady)
            {
                var chunkX = client.OnlinePlayer.Position.X >> 4;
                var chunkY = client.OnlinePlayer.Position.Y >> 4;

                var shouldBeLoaded = PositionExtensions.GetSquared3x3Around(new Position(chunkX, chunkY));

                foreach (var position in shouldBeLoaded)
                {
                    var chunkKey = $"{position.X}_{position.Y}";
                    if (!client.ChunksLoaded.Contains(chunkKey))
                    {
                        if (Server.Map.Chunks.ContainsKey(chunkKey))
                        {
                            client.ChunksLoaded.Add(chunkKey);
                            var chunk = Server.Map.Chunks[chunkKey];
                            client.Send(new ChunkPacket()
                            {
                                X         = position.X,
                                Y         = position.Y,
                                ChunkData = chunk.TilePacketData
                            });

                            foreach (var entity in chunk.EntitiesInChunk[EntityType.MONSTER])
                            {
                                var monsterInstance = (Monster)entity;
                                client.Send(monsterInstance.ToPacket());
                            }
                        }
                    }
                }
            }
        }
예제 #8
0
        public static GfxObj ReadFromDat(uint fileId)
        {
            // Check the FileCache so we don't need to hit the FileSystem repeatedly
            if (DatManager.PortalDat.FileCache.ContainsKey(fileId))
            {
                return((GfxObj)DatManager.PortalDat.FileCache[fileId]);
            }
            else
            {
                DatReader datReader = DatManager.PortalDat.GetReaderForFile(fileId);
                GfxObj    obj       = new GfxObj();

                obj.Id    = datReader.ReadUInt32();
                obj.Flags = datReader.ReadUInt32();

                short num_surfaces = datReader.ReadPackedByte();
                for (short i = 0; i < num_surfaces; i++)
                {
                    obj.Surfaces.Add(datReader.ReadUInt32());
                }

                obj.VertexArray = CVertexArray.Read(datReader);

                // Has Physics
                if ((obj.Flags & 1) > 0)
                {
                    short num_physics_polygons = datReader.ReadPackedByte();
                    for (ushort i = 0; i < num_physics_polygons; i++)
                    {
                        ushort poly_id = datReader.ReadUInt16();
                        obj.PhysicsPolygons.Add(poly_id, Polygon.Read(datReader));
                    }

                    obj.PhysicsBSP = BSPTree.Read(datReader, BSPType.Physics);
                }

                obj.SortCenter = PositionExtensions.ReadPositionFrame(datReader);

                // Has Drawing
                if ((obj.Flags & 2) > 0)
                {
                    short num_polygons = datReader.ReadPackedByte();
                    for (ushort i = 0; i < num_polygons; i++)
                    {
                        ushort poly_id = datReader.ReadUInt16();
                        obj.Polygons.Add(poly_id, Polygon.Read(datReader));
                    }

                    obj.DrawingBSP = BSPTree.Read(datReader, BSPType.Drawing);
                }

                if ((obj.Flags & 8) > 0)
                {
                    obj.DIDDegrade = datReader.ReadUInt32();
                }

                // Store this object in the FileCache
                DatManager.PortalDat.FileCache[fileId] = obj;

                return(obj);
            }
        }
예제 #9
0
        public static ParticleEmitterInfo ReadFromDat(uint fileId)
        {
            // Check the FileCache so we don't need to hit the FileSystem repeatedly
            if (DatManager.PortalDat.FileCache.ContainsKey(fileId))
            {
                return((ParticleEmitterInfo)DatManager.PortalDat.FileCache[fileId]);
            }
            else
            {
                DatReader           datReader = DatManager.PortalDat.GetReaderForFile(fileId);
                ParticleEmitterInfo obj       = new ParticleEmitterInfo();

                obj.Id = datReader.ReadUInt32();

                uint unknown = datReader.ReadUInt32();

                obj.EmitterType  = (EmitterType)datReader.ReadInt32();
                obj.ParticleType = (ParticleType)datReader.ReadInt32();

                obj.GfxObjId   = datReader.ReadUInt32();
                obj.HwGfxObjId = datReader.ReadUInt32();

                obj.Birthrate = datReader.ReadDouble();

                obj.MaxParticles     = datReader.ReadInt32();
                obj.InitialParticles = datReader.ReadInt32();
                obj.TotalParticles   = datReader.ReadInt32();

                obj.TotalSeconds = datReader.ReadDouble();
                obj.LifespanRand = datReader.ReadDouble();
                obj.Lifespan     = datReader.ReadDouble();

                obj.SortingSphere = datReader.ReadUInt32();

                obj.OffsetDir = PositionExtensions.ReadPositionFrame(datReader);
                obj.MinOffset = datReader.ReadSingle();
                obj.MaxOffset = datReader.ReadSingle();

                obj.A = PositionExtensions.ReadPositionFrame(datReader);
                obj.B = PositionExtensions.ReadPositionFrame(datReader);
                obj.C = PositionExtensions.ReadPositionFrame(datReader);

                obj.MinA = datReader.ReadSingle();
                obj.MaxA = datReader.ReadSingle();
                obj.MinB = datReader.ReadSingle();
                obj.MaxB = datReader.ReadSingle();
                obj.MinC = datReader.ReadSingle();
                obj.MaxC = datReader.ReadSingle();

                obj.ScaleRand  = datReader.ReadSingle();
                obj.StartScale = datReader.ReadSingle();
                obj.FinalScale = datReader.ReadSingle();
                obj.TransRand  = datReader.ReadSingle();
                obj.StartTrans = datReader.ReadSingle();
                obj.FinalTrans = datReader.ReadSingle();

                // Store this object in the FileCache
                DatManager.PortalDat.FileCache[fileId] = obj;

                return(obj);
            }
        }