Ejemplo n.º 1
0
 public void Insert(MapleFoothold f)
 {
     if (m_depth == 0)
     {
         if (f.Point1.X > MaxDropX)
         {
             MaxDropX = f.Point1.X;
         }
         if (f.Point1.X < MinDropX)
         {
             MinDropX = f.Point1.X;
         }
         if (f.Point2.X > MaxDropX)
         {
             MaxDropX = f.Point2.X;
         }
         if (f.Point2.X < MinDropX)
         {
             MinDropX = f.Point2.X;
         }
     }
     if (m_depth == MaxDepth ||
         (f.Point1.X >= Point1.X && f.Point2.X <= Point2.X &&
          f.Point1.Y >= Point1.Y && f.Point2.Y <= Point2.Y))
     {
         m_footholds.Add(f);
     }
     else
     {
         if (m_nw == null)
         {
             m_nw = new MapleFootholdTree(Point1, m_center, m_depth + 1);
             m_ne = new MapleFootholdTree(new Point(m_center.X, Point1.Y), new Point(Point2.X, m_center.Y),
                                          m_depth + 1);
             m_sw = new MapleFootholdTree(new Point(Point1.X, m_center.Y), new Point(m_center.X, Point2.Y),
                                          m_depth + 1);
             m_se = new MapleFootholdTree(m_center, Point2, m_depth + 1);
         }
         if (f.Point2.X <= m_center.X && f.Point2.Y <= m_center.Y)
         {
             m_nw.Insert(f);
         }
         else if (f.Point1.X > m_center.X && f.Point2.Y <= m_center.Y)
         {
             m_ne.Insert(f);
         }
         else if (f.Point2.X <= m_center.X && f.Point1.Y > m_center.Y)
         {
             m_sw.Insert(f);
         }
         else
         {
             m_se.Insert(f);
         }
     }
 }
Ejemplo n.º 2
0
        public MapleMap GetMap(int mapid)
        {
            var      omapid = mapid;
            MapleMap map;

            if (!Maps.TryGetValue(omapid, out map))
            {
                lock (this)
                {
                    // check if someone else who was also synchronized has loaded the map already
                    if (Maps.ContainsKey(omapid))
                    {
                        return(Maps[omapid]);
                    }
                    var mapName = GetMapName(mapid);
                    var mapData = m_mSource.GetData(mapName);
                    var link    = MapleDataTool.GetString(mapData.GetChildByPath("info/link"), "");
                    if (!link.Equals(""))
                    {
                        mapName = GetMapName(int.Parse(link));
                        mapData = m_mSource.GetData(mapName);
                    }
                    float monsterRate = 0;
                    var   mobRate     = mapData.GetChildByPath("info/mobRate");
                    if (mobRate != null)
                    {
                        monsterRate = (float)mobRate.Data;
                    }
                    map = new MapleMap(mapid, ChannelId, MapleDataTool.GetInt("info/returnMap", mapData), monsterRate)
                    {
                        OnFirstUserEnter = MapleDataTool.GetString(mapData.GetChildByPath("info/onFirstUserEnter"),
                                                                   mapid.ToString()),
                        OnUserEnter = MapleDataTool.GetString(mapData.GetChildByPath("info/onUserEnter"),
                                                              mapid.ToString()),
                        TimeMobId      = MapleDataTool.GetInt(mapData.GetChildByPath("info/timeMob/id"), -1),
                        TimeMobMessage = MapleDataTool.GetString(mapData.GetChildByPath("info/timeMob/message"), "")
                    };

                    var portalFactory = new PortalFactory();
                    foreach (var portal in mapData.GetChildByPath("portal"))
                    {
                        var portalresult =
                            portalFactory.MakePortal((PortalType)MapleDataTool.GetInt(portal.GetChildByPath("pt")),
                                                     portal);
                        map.Portals.Add(portalresult.PortalId, portalresult);
                    }
                    var allFootholds = new List <MapleFoothold>();

                    var lBound = new Point();
                    var uBound = new Point();
                    foreach (var footRoot in mapData.GetChildByPath("foothold"))
                    {
                        foreach (var footCat in footRoot)
                        {
                            foreach (var footHold in footCat)
                            {
                                var x1 = MapleDataTool.GetInt(footHold.GetChildByPath("x1"));
                                var y1 = MapleDataTool.GetInt(footHold.GetChildByPath("y1"));
                                var x2 = MapleDataTool.GetInt(footHold.GetChildByPath("x2"));
                                var y2 = MapleDataTool.GetInt(footHold.GetChildByPath("y2"));
                                var fh = new MapleFoothold(new Point(x1, y1), new Point(x2, y2),
                                                           int.Parse(footHold.Name));
                                fh.PrevFootholdId = MapleDataTool.GetInt(footHold.GetChildByPath("prev"));
                                fh.NextFootholdId = MapleDataTool.GetInt(footHold.GetChildByPath("next"));

                                if (fh.Point1.X < lBound.X)
                                {
                                    lBound.X = fh.Point1.X;
                                }
                                if (fh.Point2.X > uBound.X)
                                {
                                    uBound.X = fh.Point2.X;
                                }
                                if (fh.Point1.Y < lBound.Y)
                                {
                                    lBound.Y = fh.Point1.Y;
                                }
                                if (fh.Point2.Y > uBound.Y)
                                {
                                    uBound.Y = fh.Point2.Y;
                                }
                                allFootholds.Add(fh);
                            }
                        }
                    }

                    var fTree = new MapleFootholdTree(lBound, uBound);
                    foreach (var fh in allFootholds)
                    {
                        fTree.Insert(fh);
                    }
                    map.Footholds = fTree;

                    // load areas (EG PQ platforms)
                    if (mapData.GetChildByPath("area") != null)
                    {
                        foreach (var area in mapData.GetChildByPath("area"))
                        {
                            var x1      = MapleDataTool.GetInt(area.GetChildByPath("x1"));
                            var y1      = MapleDataTool.GetInt(area.GetChildByPath("y1"));
                            var x2      = MapleDataTool.GetInt(area.GetChildByPath("x2"));
                            var y2      = MapleDataTool.GetInt(area.GetChildByPath("y2"));
                            var mapArea = new Rectangle(x1, y1, x2 - x1, y2 - y1);
                            map.Areas.Add(mapArea);
                        }
                    }

                    // load life data (npc, monsters)
                    foreach (var life in mapData.GetChildByPath("life"))
                    {
                        var id           = MapleDataTool.GetString(life.GetChildByPath("id"));
                        var type         = MapleDataTool.GetString(life.GetChildByPath("type"));
                        var myLife       = LoadLife(life, id, type);
                        var mapleMonster = myLife as MapleMonster;
                        if (mapleMonster != null)
                        {
                            var monster = mapleMonster;
                            var mobTime = MapleDataTool.GetInt("mobTime", life, 0);
                            if (mobTime == -1)
                            {
                                //does not respawn, force spawn once
                                map.SpawnMonster(monster);
                            }
                            else
                            {
                                map.AddMonsterSpawn(monster, mobTime);
                            }
                        }
                        else
                        {
                            map.AddMapObject(myLife);
                        }
                    }

                    //load reactor data
                    if (mapData.GetChildByPath("reactor") != null)
                    {
                        foreach (var reactor in mapData.GetChildByPath("reactor"))
                        {
                            var id = MapleDataTool.GetString(reactor.GetChildByPath("id"));
                            if (id != null)
                            {
                                var newReactor = LoadReactor(reactor, id);
                                map.SpawnReactor(newReactor);
                            }
                        }
                    }

                    //try
                    //{
                    map.MapName = MapleDataTool.GetString("mapName", m_mNameData.GetChildByPath(GetMapStringName(omapid)),
                                                          "");
                    map.StreetName = MapleDataTool.GetString("streetName",
                                                             m_mNameData.GetChildByPath(GetMapStringName(omapid)), "");
                    //}
                    //catch
                    //{
                    //map.MapName = "";
                    //map.StreetName = "";
                    //}

                    map.Clock             = mapData.GetChildByPath("clock") != null;
                    map.Everlast          = mapData.GetChildByPath("everlast") != null;
                    map.Town              = mapData.GetChildByPath("town") != null;
                    map.AllowShops        = MapleDataTool.GetInt(mapData.GetChildByPath("info/personalShop"), 0) == 1;
                    map.DecHp             = MapleDataTool.ConvertToInt("decHP", mapData, 0);
                    map.ProtectItem       = MapleDataTool.ConvertToInt("protectItem", mapData, 0);
                    map.ForcedReturnMapId = MapleDataTool.GetInt(mapData.GetChildByPath("info/forcedReturn"), 999999999);
                    map.OnFirstUserEnter  = MapleDataTool.GetString(mapData.GetChildByPath("info/onFirstUserEnter"), "");
                    map.OnUserEnter       = MapleDataTool.GetString(mapData.GetChildByPath("info/onUserEnter"), "");

                    map.HasBoat = mapData.GetChildByPath("shipObj") != null;


                    map.FieldLimit = MapleDataTool.GetInt(mapData.GetChildByPath("info/fieldLimit"), 0);
                    map.TimeLimit  = MapleDataTool.ConvertToInt("timeLimit", mapData.GetChildByPath("info"), -1);
                    map.FieldType  = MapleDataTool.ConvertToInt("info/fieldType", mapData, 0);
                    Maps.Add(omapid, map);

                    //try
                    //{
                    //    PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM spawns WHERE mid = ?");
                    //    ps.setInt(1, omapid);
                    //    ResultSet rs = ps.executeQuery();
                    //    while (rs.next())
                    //    {
                    //        int id = rs.getInt("idd");
                    //        int f = rs.getInt("f");
                    //        bool hide = false;
                    //        string type = rs.getString("type");
                    //        int fh = rs.getInt("fh");
                    //        int cy = rs.getInt("cy");
                    //        int rx0 = rs.getInt("rx0");
                    //        int rx1 = rs.getInt("rx1");
                    //        int x = rs.getInt("x");
                    //        int y = rs.getInt("y");
                    //        int mobTime = rs.getInt("mobtime");
                    //        AbstractLoadedMapleLife myLife = loadLife(id, f, hide, fh, cy, rx0, rx1, x, y, type);
                    //        if (type.equals("n"))
                    //        {
                    //            map.addMapObject(myLife);
                    //        }
                    //        else if (type.equals("m"))
                    //        {
                    //            MapleMonster monster = (MapleMonster)myLife;
                    //            map.addMonsterSpawn(monster, mobTime);
                    //        }
                    //    }
                    //}
                    //catch (SQLException e)
                    //{
                    //    log.info(e.toString());
                    //}
                }
            }
            return(map);
        }