Exemplo n.º 1
0
        public void Unpack(BinaryReader reader)
        {
            var numPolygons        = reader.ReadUInt32();
            var numPhysicsPolygons = reader.ReadUInt32();
            var numPortals         = reader.ReadUInt32();

            VertexArray.Unpack(reader);

            Polygons.Unpack(reader, numPolygons);

            for (uint i = 0; i < numPortals; i++)
            {
                Portals.Add(reader.ReadUInt16());
            }

            reader.AlignBoundary();

            CellBSP.Unpack(reader, BSPType.Cell);

            PhysicsPolygons.Unpack(reader, numPhysicsPolygons);

            PhysicsBSP.Unpack(reader, BSPType.Physics);

            uint hasDrawingBSP = reader.ReadUInt32();

            if (hasDrawingBSP != 0)
            {
                DrawingBSP = new BSPTree();
                DrawingBSP.Unpack(reader, BSPType.Drawing);
            }

            reader.AlignBoundary();
        }
Exemplo n.º 2
0
        public void Link(Side side, Location destination)
        {
            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }

            if (AwailableSides.HasFlag(side))
            {
                throw new InvalidOperationException($"Location {this} already has portal for {side}");
            }
            if (destination.AwailableSides.HasFlag(GetOpposite(side)))
            {
                throw new InvalidOperationException($"Location {destination} already has portal for {GetOpposite(side)}");
            }

            Portals.Add(side, new Portal()
            {
                Destination = destination
            });
            AwailableSides |= side;

            Side opposite = GetOpposite(side);

            destination.Portals.Add(opposite, new Portal()
            {
                Destination = this
            });
            destination.AwailableSides |= opposite;
        }
Exemplo n.º 3
0
 private void LoadPortals()
 {
     SpaceDef.Portals.OfType <DictionaryAtom>().ToList().ForEach(portal =>
     {
         var portalId = portal.GetInt("SpacePortalMapID");
         Portals.Add(new PortalDef(portalId, "Portal-" + portalId, portal));
     });
 }
Exemplo n.º 4
0
    public void AddPortal(Portal portal)
    {
        if (Portals.Contains(portal))
        {
            return;
        }

        Portals.Add(portal);
    }
Exemplo n.º 5
0
 public void LoadPortals()
 {
     foreach (PortalDTO portal in DAOFactory.PortalDAO.LoadByMap(Map.MapId))
     {
         Portal p = new Portal(portal)
         {
             SourceMapInstanceId = MapInstanceId
         };
         Portals.Add(p);
     }
 }
Exemplo n.º 6
0
 internal void CreatePortalTemp(Portal portal, int timeInSeconds = 0, bool isTemporary = false)
 {
     portal.SourceMapInstanceId = MapInstanceId;
     Portals.Add(portal);
     Broadcast(portal.GenerateGp());
     if (isTemporary)
     {
         Observable.Timer(TimeSpan.FromSeconds(timeInSeconds)).Subscribe(o =>
         {
             Portals.Remove(portal);
             MapClear();
         });
     }
 }
Exemplo n.º 7
0
 public void AddPortal(Portal PT)
 {
     if (PT.Name == "sp")
     {
         SpawnPoints.Add(PT.ID, PT);
     }
     else if (PT.Name == "tp")
     {
         // TownPortal: Mystic Door
     }
     else
     {
         if (Portals.ContainsKey(PT.Name))
         {
             Console.WriteLine("Duplicate portal, Name: {0} MapID: {1}", PT.Name, ID);
         }
         else
         {
             Portals.Add(PT.Name, PT);
         }
     }
 }
Exemplo n.º 8
0
 internal void CreatePortal(Portal portal)
 {
     portal.SourceMapInstanceId = MapInstanceId;
     Portals.Add(portal);
     Broadcast(portal.GenerateGp());
 }
Exemplo n.º 9
0
        public MapReference(WzImage img)
        {
            var name = img.Name.Remove(9);

            if (!int.TryParse(name, out var id))
            {
                return;
            }

            MapleId = id;

            var info = img["info"];

            foreach (var node in info.WzProperties)
            {
                switch (node.Name)
                {
                case "mapMark":
                case "cloud":
                case "snow":
                case "rain":
                case "fs":
                case "bgm":
                case "version":
                case "mapDesc":
                case "mapName":
                case "help":
                case "streetName":
                case "moveLimit":
                case "hideMinimap":
                    break;

                case "town":
                    IsTown = node.GetInt() > 0;
                    break;

                case "mobRate":
                    SpawnRate = node.GetDouble();
                    break;

                case "returnMap":
                    ReturnMapId = node.GetInt();
                    break;

                case "forcedReturn":
                    ForcedReturnMapId = node.GetInt();
                    break;

                case "fieldLimit":
                    FieldLimit = (FieldLimitFlags)node.GetInt();
                    break;

                case "bUnableToChangeChannel":
                    IsUnableToChangeChannel = node.GetInt() > 0;
                    break;

                case "bUnableToShop":
                    IsUnableToShop = node.GetInt() > 0;
                    break;

                case "everlast":
                    IsEverlastDrops = node.GetInt() > 0;
                    break;

                case "personalShop":
                    IsPersonalShop = node.GetInt() > 0;
                    break;

                case "recovery":
                    RecoveryHp = (byte)node.GetInt();
                    break;

                case "decHP":
                    DecreaseHp = (byte)node.GetInt();
                    break;

                case "scrollDisable":
                    IsScrollDisable = node.GetInt() > 0;
                    break;

                case "timeLimit":
                    TimeLimit = node.GetInt();
                    break;

                case "VRTop":
                    VrTop = node.GetInt();
                    break;

                case "VRLeft":
                    VrLeft = node.GetInt();
                    break;

                case "VRBottom":
                    VrBottom = node.GetInt();
                    break;

                case "VRRight":
                    VrRight = node.GetInt();
                    break;

                case "fieldType":
                    FieldType = (MapFieldType)node.GetInt();
                    break;

                default:
                    _log.Warning(
                        $"Unknown map node Skill={MapleId} Name={node.Name} Value={node.WzValue}");
                    break;
                }
            }

            HasClock = img["clock"] != null;
            HasShip  = img["shipObj"] != null;
            img["portal"]?.WzProperties?.ForEach(x => Portals.Add(new PortalReference(x)));
            img["seat"]?.WzProperties?.ForEach(x => Seats.Add(new SeatReference(x)));
            img["foothold"]?.WzProperties.SelectMany(x => x.WzProperties).SelectMany(x => x.WzProperties).ToList()
            .ForEach(x => Footholds.Add(new FootholdReference(x)));
            img["seat"]?.WzProperties?.ForEach(x => Seats.Add(new SeatReference(x)));
            img["life"]?.WzProperties?.ForEach(life =>
            {
                var type = life["type"].GetString();

                switch (type)
                {
                case "n":
                    Npcs.Add(new MapNpcReference(life));
                    break;

                case "m":
                    SpawnPoints.Add(new SpawnPointReference(life, LifeObjectType.Mob));
                    break;
                }
            });
        }
Exemplo n.º 10
0
        public void LoadMap(string mapname)
        {
            this.Loading = true;
            map          = Squared.Tiled.Map.Load(String.Format("Content\\{0}", mapname), content);
            MapWidth     = map.Width * map.TileWidth;
            MapHeight    = map.Height * map.TileHeight;
            MapWidth     = (MapWidth > screenw) ? MapWidth : screenw;
            MapHeight    = (MapHeight > screenh) ? MapWidth : screenh;
            renderTarget = new RenderTarget2D(
                device,
                MapWidth,
                MapHeight,
                //1024,
                //1024,
                false,
                device.PresentationParameters.BackBufferFormat,
                DepthFormat.Depth24);


            Random random = new Random();

            foreach (var grp in map.ObjectGroups)
            {
                //ObjectGroup grp = kvpair.Value;
                foreach (var tiledobj in grp.Objects)
                {
                    if (tiledobj.Name.Equals("Start"))
                    {
                        Console.WriteLine("object: {0}, x {1} y {2} width {3} height {4}", tiledobj.Name, tiledobj.X, tiledobj.Y, tiledobj.Width, tiledobj.Height);
                        Player.Location = new Vector2(tiledobj.X + tiledobj.Width / 2, tiledobj.Y + tiledobj.Width / 2);
                    }
                    else if (tiledobj.Name.Equals("SpawnPortal"))
                    {
                        Portals.Add(new SpawnPortal()
                        {
                            CreatureTypes = new Creature.Types[] { Creature.Types.SMALL, Creature.Types.MEDIUM },
                            Location      = new Vector2(tiledobj.X + tiledobj.Width / 2, tiledobj.Y + tiledobj.Height / 2),
                            Size          = random.Next(1, 6),
                            isOpen        = false
                        });
                    }
                    else if (tiledobj.Name.Equals("BossSpawn"))
                    {
                        var bosstype = tiledobj.Properties["BossType"];
                        switch (bosstype)
                        {
                        case "FirstBoss":
                            Creatures.Add(new Creature()
                            {
                                Attack   = 10,
                                Health   = 500,
                                Range    = 128,
                                Location = new Vector2(tiledobj.X + tiledobj.Width / 2, tiledobj.Y + tiledobj.Height / 2),
                                ID       = Creatures.Count,
                                Type     = Creature.Types.BOSS,
                                Speed    = 4,
                                AIScript = Creature.ChargePlayerIfInRange
                            });
                            break;

                        default:
                            throw new NotImplementedException();
                        }
                    }
                    else if (tiledobj.Name.Equals("Location"))
                    {
                        if (tiledobj.Properties.ContainsKey("LocationType"))
                        {
                            Locations.Add(new Location()
                            {
                                X      = tiledobj.X + tiledobj.Width / 2,
                                Y      = tiledobj.Y + tiledobj.Height / 2,
                                Type   = tiledobj.Properties["LocationType"],
                                Width  = tiledobj.Width,
                                Height = tiledobj.Height,
                            });
                        }
                    }
                }
                MapChanged = true;
            }

            //this.Viewport = new Vector2(-(map.Width*map.TileWidth / 2f), - (map.Height*map.TileHeight / 2f));
            this.Viewport = new Vector2(0, 0);
            //X = this.MapWidth / 2;
            //Y = this.MapHeight / 2;
            X            = this.Viewport.X / 2;
            Y            = this.Viewport.Y / 2;
            this.Loading = false;
        }
Exemplo n.º 11
0
 public void AddPortal(Portal portal)
 {
     Portals.Add(portal);
 }
Exemplo n.º 12
0
        public void Load(string onvfile)
        {
            Name = Path.GetFileNameWithoutExtension(onvfile).ToLowerInvariant();

            var       lines            = File.ReadAllLines(onvfile);
            bool      inverts          = false;
            bool      ininds           = false;
            bool      inedges          = false;
            bool      inpolys          = false;
            bool      insectors        = false;
            bool      insectordata     = false;
            bool      insectorpolyinds = false;
            bool      insectorbounds   = false;
            bool      inportals        = false;
            int       depth            = 0;
            int       cdepth           = 0;
            OnvSector csector          = SectorTree;

            var spacedelim = new[] { ' ' };
            var cult       = CultureInfo.InvariantCulture;

            foreach (var line in lines)
            {
                string tline = line.Trim();
                if (string.IsNullOrEmpty(tline))
                {
                    continue;                              //blank line
                }
                //if (tline.StartsWith("#")) continue; //commented out

                string[] parts = tline.Split(spacedelim, StringSplitOptions.RemoveEmptyEntries);

                if (tline.StartsWith("{"))
                {
                    depth++; continue;
                }
                if (tline.StartsWith("}"))
                {
                    depth--;
                }                                       //need to handle the closing cases

                if (inverts)
                {
                    if (depth <= 0)
                    {
                        inverts = false;
                    }
                    else if (parts.Length == 3)
                    {
                        NavMeshVertex v = new NavMeshVertex();
                        v.X = ushort.Parse(parts[0].Trim(), cult);
                        v.Y = ushort.Parse(parts[1].Trim(), cult);
                        v.Z = ushort.Parse(parts[2].Trim(), cult);
                        Vertices.Add(v);
                    }
                }
                else if (ininds)
                {
                    if (depth <= 0)
                    {
                        ininds = false;
                    }
                    else
                    {
                        for (int i = 0; i < parts.Length; i++)
                        {
                            int ind = int.Parse(parts[i]);
                            Indices.Add(ind);
                        }
                    }
                }
                else if (inedges)
                {
                    if (depth <= 0)
                    {
                        inedges = false;
                    }
                    else
                    {
                        OnvEdge edge = new OnvEdge(parts);
                        Edges.Add(edge);
                    }
                }
                else if (inpolys)
                {
                    if (depth <= 0)
                    {
                        inpolys = false;
                    }
                    else
                    {
                        OnvPoly poly = new OnvPoly(parts);
                        Polys.Add(poly);
                    }
                }
                else if (insectors)
                {
                    if (depth <= 0)
                    {
                        insectors        = false;
                        insectordata     = false;
                        insectorpolyinds = false;
                        insectorbounds   = false;
                    }
                    else if (insectordata)
                    {
                        if (depth <= cdepth)
                        {
                            insectordata     = false;
                            insectorpolyinds = false;
                            insectorbounds   = false;
                        }
                        else if (insectorpolyinds)
                        {
                            if (depth <= (cdepth + 1))
                            {
                                insectorpolyinds = false;
                            }
                            else
                            {
                                for (int i = 0; i < parts.Length; i++)
                                {
                                    int ind = int.Parse(parts[i]);
                                    csector.SectorData.PolyIndices.Add(ind);
                                }
                            }
                        }
                        else if (insectorbounds)
                        {
                            if (depth <= (cdepth + 1))
                            {
                                insectorbounds = false;
                            }
                            else
                            {
                                OnvBounds bounds = new OnvBounds(parts);
                                csector.SectorData.Bounds.Add(bounds);
                            }
                        }
                        else
                        {
                            string idstr = parts[0].Trim();
                            if (idstr == "PolyIndices")
                            {
                                csector.SectorData.PolyIndicesCount = int.Parse(parts[1].Trim(), cult);
                                insectorpolyinds = csector.SectorData.PolyIndicesCount > 0;
                                if (insectorpolyinds)
                                {
                                    csector.SectorData.PolyIndices = new List <int>();
                                }
                            }
                            else if (idstr == "Bounds")
                            {
                                csector.SectorData.BoundsCount = int.Parse(parts[1].Trim(), cult);
                                insectorbounds = csector.SectorData.BoundsCount > 0;
                                if (insectorbounds)
                                {
                                    csector.SectorData.Bounds = new List <OnvBounds>();
                                }
                            }
                        }
                    }
                    else
                    {
                        if (depth < cdepth)
                        {
                            csector = csector.Parent;
                        }
                        cdepth = depth;
                        string idstr = parts[0].Trim();
                        if (idstr == "AABBMin")
                        {
                            csector.AABBMin = Util.GetVector3(parts, 1);
                        }
                        else if (idstr == "AABBMax")
                        {
                            csector.AABBMax = Util.GetVector3(parts, 1);
                        }
                        else if ((parts.Length < 2) || (parts[1].Trim() != "null"))
                        {
                            if (idstr == "SectorData")
                            {
                                csector.SectorData = new OnvSectorData();
                                insectordata       = true;
                            }
                            else if (idstr == "SubTree0")
                            {
                                csector.SubTree0        = new OnvSector();
                                csector.SubTree0.Parent = csector;
                                csector = csector.SubTree0;
                            }
                            else if (idstr == "SubTree1")
                            {
                                csector.SubTree1        = new OnvSector();
                                csector.SubTree1.Parent = csector;
                                csector = csector.SubTree1;
                            }
                            else if (idstr == "SubTree2")
                            {
                                csector.SubTree2        = new OnvSector();
                                csector.SubTree2.Parent = csector;
                                csector = csector.SubTree2;
                            }
                            else if (idstr == "SubTree3")
                            {
                                csector.SubTree3        = new OnvSector();
                                csector.SubTree3.Parent = csector;
                                csector = csector.SubTree3;
                            }
                        }
                    }
                }
                else if (inportals)
                {
                    if (depth <= 0)
                    {
                        inportals = false;
                    }
                    else
                    {
                        OnvPortal portal = new OnvPortal(parts);
                        Portals.Add(portal);
                    }
                }
                else
                {
                    //at root level, look for identifier
                    depth = 0; //reset just in case
                    string idstr = parts[0].Trim();
                    if (idstr == "Version")
                    {
                        VersionMaj = int.Parse(parts[1].Trim(), cult);
                        VersionMin = int.Parse(parts[2].Trim(), cult);
                    }
                    else if (idstr == "Sizes")
                    {
                        Sizes = Util.GetVector3(parts, 1);
                    }
                    else if (idstr == "Flags")
                    {
                        Flags = int.Parse(parts[1].Trim(), cult);
                    }
                    else if (idstr == "Vertices")
                    {
                        VerticesCount = int.Parse(parts[1].Trim(), cult);
                        inverts       = VerticesCount > 0;
                    }
                    else if (idstr == "Indices")
                    {
                        IndicesCount = int.Parse(parts[1].Trim(), cult);
                        ininds       = IndicesCount > 0;
                    }
                    else if (idstr == "Edges")
                    {
                        EdgesCount = int.Parse(parts[1].Trim(), cult);
                        inedges    = EdgesCount > 0;
                    }
                    else if (idstr == "Polys")
                    {
                        PolysCount = int.Parse(parts[1].Trim(), cult);
                        inpolys    = PolysCount > 0;
                    }
                    else if (idstr == "SectorTree")
                    {
                        insectors = true;
                    }
                    else if (idstr == "Portals")
                    {
                        PortalsCount = int.Parse(parts[1].Trim(), cult);
                        inportals    = PortalsCount > 0;
                    }
                    else if (idstr == "SectorID")
                    {
                        SectorID = int.Parse(parts[1].Trim(), cult);
                    }
                }
            }
        }