Пример #1
0
        public static MobAttackInfo GetMobAttackInfo(MapleMonster mob, int attack)
        {
            MobAttackInfo ret;
            var           key = Tuple.Create(mob.Id, attack);

            if (MobAttacks.TryGetValue(key, out ret))
            {
                return(ret);
            }
            lock (MobAttacks)
            {
                if (!MobAttacks.TryGetValue(key, out ret))
                {
                    var mobData = DataSource.GetData((mob.Id + ".img").PadLeft(11, '0'));
                    if (mobData != null)
                    {
                        var linkedmob = MapleDataTool.GetString("link", mobData, "");

                        if (linkedmob != "")
                        {
                            mobData = DataSource.GetData((linkedmob + ".img").PadLeft(11, '0'));
                        }

                        var attackData = mobData.GetChildByPath($"attack{attack + 1}/info");
                        if (attackData != null)
                        {
                            var deadlyAttack = attackData.GetChildByPath("deadlyAttack");
                            var mpBurn       = MapleDataTool.GetInt("mpBurn", attackData, 0);
                            var disease      = MapleDataTool.GetInt("disease", attackData, 0);
                            var level        = MapleDataTool.GetInt("level", attackData, 0);
                            var mpCon        = MapleDataTool.GetInt("conMP", attackData, 0);
                            ret = new MobAttackInfo(mob.Id, attack)
                            {
                                IsDeadlyAttack = deadlyAttack != null,
                                MpBurn         = mpBurn,
                                DiseaseSkill   = (byte)disease,
                                DiseaseLevel   = (byte)level,
                                MpCon          = mpCon
                            };
                        }
                    }
                    if (MobAttacks.ContainsKey(key))
                    {
                        MobAttacks[key] = ret;
                    }
                    else
                    {
                        MobAttacks.Add(key, ret);
                    }
                }
                return(ret);
            }
        }
Пример #2
0
        public static ISkill GetSkill(int id)
        {
            ISkill ret;

            if (Skills.TryGetValue(id, out ret))
            {
                return(ret);
            }
            lock (Skills)
            {
                // see if someone else that's also synchronized has loaded the skill by now
                if (!Skills.TryGetValue(id, out ret))
                {
                    var job       = id / 10000;
                    var skillroot = Datasource.GetData(job.ToString().PadLeft(3, '0') + ".img");
                    var skillData = skillroot.GetChildByPath("skill/" + id.ToString().PadLeft(7, '0'));
                    if (skillData != null)
                    {
                        ret = Skill.LoadFromData(id, skillData);
                    }
                    Skills.Add(id, ret);
                }
                return(ret);
            }
        }
Пример #3
0
        public static PetCommand GetPetCommand(int petId, int skillId)
        {
            PetCommand ret;
            var        key = Tuple.Create(petId, skillId);

            if (PetCommands.TryGetValue(key, out ret))
            {
                return(ret);
            }
            lock (PetCommands)
            {
                // see if someone else that's also synchronized has loaded the skill by now
                PetCommands.TryGetValue(key, out ret);
                if (ret == null)
                {
                    IMapleData skillData = DataRoot.GetData("Pet/" + petId + ".img");
                    int        prob      = 0;
                    int        inc       = 0;
                    if (skillData != null)
                    {
                        prob = MapleDataTool.GetInt("interact/" + skillId + "/prob", skillData, 0);
                        inc  = MapleDataTool.GetInt("interact/" + skillId + "/inc", skillData, 0);
                    }
                    ret = new PetCommand(petId, skillId, prob, inc);

                    if (PetCommands.ContainsKey(key))
                    {
                        PetCommands[key] = ret;
                    }
                    else
                    {
                        PetCommands.Add(key, ret);
                    }
                }
                return(ret);
            }
        }
Пример #4
0
        public static List <CashItem> GetPackageItems(int itemId)
        {
            if (CashPackages.ContainsKey(itemId))
            {
                return(CashPackages[itemId]);
            }
            List <CashItem>    packageItems = new List <CashItem>();
            IMapleDataProvider dataProvider = MapleDataProviderFactory.GetDataProvider("Etc.wz");
            IMapleData         a            = dataProvider.GetData("CashPackage.img");

            foreach (var b in a.Children)
            {
                if (itemId == int.Parse(b.Name))
                {
                    foreach (var c in b.Children)
                    {
                        foreach (var d in c.Children)
                        {
                            int sn = MapleDataTool.GetInt("" + int.Parse(d.Name), c);
                            packageItems.Add(GetItem(sn));
                        }
                    }
                    break;
                }
            }

            if (CashPackages.ContainsKey(itemId))
            {
                CashPackages[itemId] = packageItems;
            }
            else
            {
                CashPackages.Add(itemId, packageItems);
            }

            return(packageItems);
        }
Пример #5
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);
        }
Пример #6
0
 public MapleMapFactory(IMapleDataProvider source, IMapleDataProvider stringSource)
 {
     m_mSource   = source;
     m_mNameData = stringSource.GetData("Map.img");
 }
Пример #7
0
        public static MapleReactorStats GetReactor(int rid)
        {
            MapleReactorStats stats;

            if (!ReactorStats.TryGetValue(rid, out stats))
            {
                var infoId      = rid;
                var reactorData = Data.GetData((infoId + ".img").PadLeft(11, '0'));
                var link        = reactorData.GetChildByPath("info/link");
                if (link != null)
                {
                    infoId = MapleDataTool.ConvertToInt("info/link", reactorData);
                    stats  = ReactorStats[infoId];
                }
                var activateOnTouch = reactorData.GetChildByPath("info/activateByTouch");
                var loadArea        = false;
                if (activateOnTouch != null)
                {
                    loadArea = MapleDataTool.GetInt("info/activateByTouch", reactorData, 0) != 0;
                }
                if (stats == null)
                {
                    reactorData = Data.GetData((infoId + ".img").PadLeft(11, '0'));
                    var reactorInfoData = reactorData.GetChildByPath("0/event/0");
                    stats = new MapleReactorStats();
                    if (reactorInfoData != null)
                    {
                        var areaSet = false;
                        var i       = 0;
                        while (reactorInfoData != null)
                        {
                            Tuple <int, int> reactItem = null;
                            var type = MapleDataTool.ConvertToInt("type", reactorInfoData);
                            if (type == 100)
                            {
                                //reactor waits for item
                                reactItem = Tuple.Create(MapleDataTool.ConvertToInt("0", reactorInfoData),
                                                         MapleDataTool.ConvertToInt("1", reactorInfoData));
                                if (!areaSet || loadArea)
                                {
                                    //only set area of effect for item-triggered reactors once
                                    stats.Tl = MapleDataTool.GetPoint("lt", reactorInfoData);
                                    stats.Br = MapleDataTool.GetPoint("rb", reactorInfoData);
                                    areaSet  = true;
                                }
                            }
                            var nextState = (byte)MapleDataTool.ConvertToInt("state", reactorInfoData);
                            stats.AddState((byte)i, type, reactItem, nextState);
                            i++;
                            reactorInfoData = reactorData.GetChildByPath(i + "/event/0");
                        }
                    }
                    else
                    {
                        //sit there and look pretty; likely a reactor such as Zakum/Papulatus doors that shows if player can enter
                        stats.AddState(0, 999, null, 0);
                    }

                    if (ReactorStats.ContainsKey(infoId))
                    {
                        ReactorStats[infoId] = stats;
                    }
                    else
                    {
                        ReactorStats.Add(infoId, stats);
                    }

                    if (rid != infoId)
                    {
                        if (ReactorStats.ContainsKey(rid))
                        {
                            ReactorStats[rid] = stats;
                        }
                        else
                        {
                            ReactorStats.Add(rid, stats);
                        }
                    }
                }
                else
                {
                    // stats exist at infoId but not rid; add to map
                    if (ReactorStats.ContainsKey(rid))
                    {
                        ReactorStats[rid] = stats;
                    }
                    else
                    {
                        ReactorStats.Add(rid, stats);
                    }
                }
            }
            return(stats);
        }
Пример #8
0
        public static MapleMonster GetMonster(int mid)
        {
            MapleMonsterStats stats;

            if (!MMonsterStats.TryGetValue(mid, out stats))
            {
                var monsterData = MData.GetData((mid + ".img").PadLeft(11, '0'));
                if (monsterData == null)
                {
                    return(null);
                }
                var monsterInfoData = monsterData.GetChildByPath("info");

                stats = new MapleMonsterStats
                {
                    Hp          = MapleDataTool.ConvertToInt("maxHP", monsterInfoData),
                    Mp          = MapleDataTool.ConvertToInt("maxMP", monsterInfoData, 0),
                    Exp         = MapleDataTool.ConvertToInt("exp", monsterInfoData, 0),
                    Level       = MapleDataTool.ConvertToInt("level", monsterInfoData),
                    RemoveAfter = MapleDataTool.ConvertToInt("removeAfter", monsterInfoData, 0),
                    IsBoss      = MapleDataTool.ConvertToInt("boss", monsterInfoData, 0) > 0,
                    IsFfaLoot   = MapleDataTool.ConvertToInt("publicReward", monsterInfoData, 0) > 0,
                    IsUndead    = MapleDataTool.ConvertToInt("undead", monsterInfoData, 0) > 0,
                    Name        = MapleDataTool.GetString(mid + "/name", MMobStringData, "MISSINGNO"),
                    BuffToGive  = MapleDataTool.ConvertToInt("buff", monsterInfoData, -1),
                    IsExplosive = MapleDataTool.ConvertToInt("explosiveReward", monsterInfoData, 0) > 0
                };

                var firstAttackData = monsterInfoData.GetChildByPath("firstAttack");
                var firstAttack     = 0;
                if (firstAttackData != null)
                {
                    if (firstAttackData.GetType() == MapleDataType.Float)
                    {
                        firstAttack = (int)Math.Round(MapleDataTool.GetFloat(firstAttackData));
                    }
                    else
                    {
                        firstAttack = MapleDataTool.GetInt(firstAttackData);
                    }
                }

                stats.IsFirstAttack = firstAttack > 0;
                stats.DropPeriod    = MapleDataTool.ConvertToInt("dropItemPeriod", monsterInfoData, 0);

                if (stats.IsBoss || mid == 8810018 || mid == 8810026)
                {
                    var hpTagColor   = monsterInfoData.GetChildByPath("hpTagColor");
                    var hpTagBgColor = monsterInfoData.GetChildByPath("hpTagBgcolor");

                    if (hpTagBgColor == null || hpTagColor == null)
                    {
                        Console.WriteLine($"Monster {stats.Name} ({mid}) flagged as boss without boss HP bars.");
                        stats.TagColor   = 0;
                        stats.TagBgColor = 0;
                    }
                    else
                    {
                        stats.TagColor   = (byte)MapleDataTool.ConvertToInt("hpTagColor", monsterInfoData);
                        stats.TagBgColor = (byte)MapleDataTool.ConvertToInt("hpTagBgcolor", monsterInfoData);
                    }
                }

                foreach (var idata in monsterData)
                {
                    if (!idata.Name.Equals("info"))
                    {
                        var delay = 0;
                        idata.Children.ForEach(pic => delay += MapleDataTool.ConvertToInt("delay", pic, 0));
                        stats.SetAnimationTime(idata.Name, delay);
                    }
                }

                var reviveInfo = monsterInfoData.GetChildByPath("revive");
                if (reviveInfo != null)
                {
                    var revives = new List <int>();
                    foreach (var data in reviveInfo)
                    {
                        revives.Add(MapleDataTool.GetInt(data));
                    }
                    stats.Revives = revives;
                }

                DecodeElementalString(stats, MapleDataTool.GetString("elemAttr", monsterInfoData, ""));

                var monsterSkillData = monsterInfoData.GetChildByPath("skill");
                if (monsterSkillData != null)
                {
                    var i      = 0;
                    var skills = new List <Tuple <byte, byte> >();
                    while (monsterSkillData.GetChildByPath(i.ToString()) != null)
                    {
                        skills.Add(new Tuple <byte, byte>(
                                       (byte)MapleDataTool.GetInt(i + "/skill", monsterSkillData, 0),
                                       (byte)MapleDataTool.GetInt(i + "/level", monsterSkillData, 0)));
                        i++;
                    }
                    stats.SetSkills(skills);
                }
                var banishData = monsterInfoData.GetChildByPath("ban");
                if (banishData != null)
                {
                    stats.Banish = new BanishInfo(MapleDataTool.GetString("banMsg", banishData),
                                                  MapleDataTool.GetInt("banMap/0/field", banishData, -1),
                                                  MapleDataTool.GetString("banMap/0/portal", banishData, "sp"));
                }
                MMonsterStats.Add(mid, stats);
            }
            return(new MapleMonster(mid, stats));
        }