Search in sources :

Example 11 with MaplePartyCharacter

use of net.server.world.MaplePartyCharacter in project HeavenMS by ronancpl.

the class MapleCharacter method levelUp.

public void levelUp(boolean takeexp) {
    Skill improvingMaxHP = null;
    Skill improvingMaxMP = null;
    int improvingMaxHPLevel = 0;
    int improvingMaxMPLevel = 0;
    if (isBeginnerJob() && getLevel() < 11) {
        remainingAp = 0;
        if (getLevel() < 6) {
            str += 5;
        } else {
            str += 4;
            dex += 1;
        }
    } else {
        remainingAp += 5;
        if (isCygnus() && level < 70) {
            remainingAp++;
        }
    }
    if (job == MapleJob.BEGINNER || job == MapleJob.NOBLESSE || job == MapleJob.LEGEND) {
        maxhp += Randomizer.rand(12, 16);
        maxmp += Randomizer.rand(10, 12);
    } else if (job.isA(MapleJob.WARRIOR) || job.isA(MapleJob.DAWNWARRIOR1)) {
        improvingMaxHP = isCygnus() ? SkillFactory.getSkill(DawnWarrior.MAX_HP_INCREASE) : SkillFactory.getSkill(Swordsman.IMPROVED_MAX_HP_INCREASE);
        if (job.isA(MapleJob.CRUSADER)) {
            improvingMaxMP = SkillFactory.getSkill(1210000);
        } else if (job.isA(MapleJob.DAWNWARRIOR2)) {
            improvingMaxMP = SkillFactory.getSkill(11110000);
        }
        improvingMaxHPLevel = getSkillLevel(improvingMaxHP);
        maxhp += Randomizer.rand(24, 28);
        maxmp += Randomizer.rand(4, 6);
    } else if (job.isA(MapleJob.MAGICIAN) || job.isA(MapleJob.BLAZEWIZARD1)) {
        improvingMaxMP = isCygnus() ? SkillFactory.getSkill(BlazeWizard.INCREASING_MAX_MP) : SkillFactory.getSkill(Magician.IMPROVED_MAX_MP_INCREASE);
        improvingMaxMPLevel = getSkillLevel(improvingMaxMP);
        maxhp += Randomizer.rand(10, 14);
        maxmp += Randomizer.rand(22, 24);
    } else if (job.isA(MapleJob.BOWMAN) || job.isA(MapleJob.THIEF) || (job.getId() > 1299 && job.getId() < 1500)) {
        maxhp += Randomizer.rand(20, 24);
        maxmp += Randomizer.rand(14, 16);
    } else if (job.isA(MapleJob.GM)) {
        maxhp = 30000;
        maxmp = 30000;
    } else if (job.isA(MapleJob.PIRATE) || job.isA(MapleJob.THUNDERBREAKER1)) {
        improvingMaxHP = isCygnus() ? SkillFactory.getSkill(ThunderBreaker.IMPROVE_MAX_HP) : SkillFactory.getSkill(5100000);
        improvingMaxHPLevel = getSkillLevel(improvingMaxHP);
        maxhp += Randomizer.rand(22, 28);
        maxmp += Randomizer.rand(18, 23);
    } else if (job.isA(MapleJob.ARAN1)) {
        maxhp += Randomizer.rand(44, 48);
        int aids = Randomizer.rand(4, 8);
        maxmp += aids + Math.floor(aids * 0.1);
    }
    if (improvingMaxHPLevel > 0 && (job.isA(MapleJob.WARRIOR) || job.isA(MapleJob.PIRATE) || job.isA(MapleJob.DAWNWARRIOR1))) {
        maxhp += improvingMaxHP.getEffect(improvingMaxHPLevel).getX();
    }
    if (improvingMaxMPLevel > 0 && (job.isA(MapleJob.MAGICIAN) || job.isA(MapleJob.CRUSADER) || job.isA(MapleJob.BLAZEWIZARD1))) {
        maxmp += improvingMaxMP.getEffect(improvingMaxMPLevel).getX();
    }
    if (ServerConstants.USE_RANDOMIZE_HPMP_GAIN) {
        if (job.isA(MapleJob.MAGICIAN) || job.isA(MapleJob.BLAZEWIZARD1)) {
            maxmp += localint_ / 20;
        } else {
            maxmp += localint_ / 10;
        }
    }
    if (takeexp) {
        exp.addAndGet(-ExpTable.getExpNeededForLevel(level));
        if (exp.get() < 0) {
            exp.set(0);
        }
    }
    level++;
    if (level >= getMaxClassLevel()) {
        exp.set(0);
        // To prevent levels past the maximum
        level = getMaxClassLevel();
    }
    maxhp = Math.min(30000, maxhp);
    maxmp = Math.min(30000, maxmp);
    if (level == 200) {
        exp.set(0);
    }
    recalcLocalStats();
    hp = localmaxhp;
    mp = localmaxmp;
    List<Pair<MapleStat, Integer>> statup = new ArrayList<>(10);
    statup.add(new Pair<>(MapleStat.AVAILABLEAP, remainingAp));
    statup.add(new Pair<>(MapleStat.HP, localmaxhp));
    statup.add(new Pair<>(MapleStat.MP, localmaxmp));
    statup.add(new Pair<>(MapleStat.EXP, exp.get()));
    statup.add(new Pair<>(MapleStat.LEVEL, level));
    statup.add(new Pair<>(MapleStat.MAXHP, maxhp));
    statup.add(new Pair<>(MapleStat.MAXMP, maxmp));
    statup.add(new Pair<>(MapleStat.STR, Math.min(str, Short.MAX_VALUE)));
    statup.add(new Pair<>(MapleStat.DEX, Math.min(dex, Short.MAX_VALUE)));
    if (job.getId() % 1000 > 0) {
        remainingSp[GameConstants.getSkillBook(job.getId())] += 3;
        statup.add(new Pair<>(MapleStat.AVAILABLESP, remainingSp[GameConstants.getSkillBook(job.getId())]));
    }
    client.announce(MaplePacketCreator.updatePlayerStats(statup, this));
    getMap().broadcastMessage(this, MaplePacketCreator.showForeignEffect(getId(), 0), false);
    recalcLocalStats();
    setMPC(new MaplePartyCharacter(this));
    silentPartyUpdate();
    if (level == 10 && party != null) {
        if (this.isPartyLeader())
            party.assignNewLeader(client);
        PartyOperationHandler.leaveParty(party, mpc, client);
        showHint("You have reached #blevel 10#k, therefore you must leave your #rstarter party#k.");
    }
    if (this.guildid > 0) {
        getGuild().broadcast(MaplePacketCreator.levelUpMessage(2, level, name), this.getId());
    }
    if (ServerConstants.USE_PERFECT_PITCH && level >= 30) {
        // milestones?
        if (MapleInventoryManipulator.checkSpace(client, 4310000, (short) 1, "")) {
            MapleInventoryManipulator.addById(client, 4310000, (short) 1);
        }
    }
    if (level == 200 && !isGM()) {
        final String names = (getMedalText() + name);
        client.getWorldServer().broadcastPacket(MaplePacketCreator.serverNotice(6, String.format(LEVEL_200, names, names)));
    }
    if (level % 20 == 0 && ServerConstants.USE_ADD_SLOTS_BY_LEVEL == true) {
        if (!isGM()) {
            for (byte i = 1; i < 5; i++) {
                gainSlots(i, 4, true);
            }
            this.yellowMessage("You reached level " + level + ". Congratulations! As a token of your success, your inventory has been expanded a little bit.");
        }
    }
    if (level % 20 == 0 && ServerConstants.USE_ADD_RATES_BY_LEVEL == true) {
        // For the drop & meso rate
        revertLastPlayerRates();
        setPlayerRates();
        this.yellowMessage("You managed to get level " + level + "! Getting experience and items seems a little easier now, huh?");
    }
    levelUpMessages();
    guildUpdate();
}
Also used : MobSkill(server.life.MobSkill) ArrayList(java.util.ArrayList) Point(java.awt.Point) Pair(tools.Pair) MaplePartyCharacter(net.server.world.MaplePartyCharacter)

Example 12 with MaplePartyCharacter

use of net.server.world.MaplePartyCharacter in project HeavenMS by ronancpl.

the class MapleCharacter method cancelEffectInternal.

private List<Pair<MapleBuffStat, MapleBuffStatValueHolder>> cancelEffectInternal(MapleStatEffect effect, boolean overwrite, long startTime, Set<MapleBuffStat> removedStats) {
    Map<MapleBuffStat, MapleBuffStatValueHolder> buffstats = null;
    MapleBuffStat ombs;
    if (!overwrite) {
        // is removing the source effect, meaning every effect from this srcid is being purged
        buffstats = extractCurrentBuffStats(effect);
    } else if ((ombs = getSingletonStatupFromEffect(effect)) != null) {
        // removing all effects of a buff having non-shareable buff stat.
        MapleBuffStatValueHolder mbsvh = effects.get(ombs);
        if (mbsvh != null) {
            buffstats = extractCurrentBuffStats(mbsvh.effect);
        }
    }
    if (buffstats == null) {
        // all else, is dropping ALL current statups that uses same stats as the given effect
        buffstats = extractLeastRelevantStatEffectsIfFull(effect);
    }
    if (effect.isMagicDoor()) {
        MapleDoor destroyDoor;
        chrLock.lock();
        try {
            destroyDoor = doors.remove(this.getId());
        } finally {
            chrLock.unlock();
        }
        if (destroyDoor != null) {
            destroyDoor.getTarget().removeMapObject(destroyDoor.getAreaDoor());
            destroyDoor.getTown().removeMapObject(destroyDoor.getTownDoor());
            for (MapleCharacter chr : destroyDoor.getTarget().getCharacters()) {
                destroyDoor.getAreaDoor().sendDestroyData(chr.getClient());
            }
            for (MapleCharacter chr : destroyDoor.getTown().getCharacters()) {
                destroyDoor.getTownDoor().sendDestroyData(chr.getClient());
            }
            prtLock.lock();
            try {
                if (party != null) {
                    for (MaplePartyCharacter partyMembers : party.getMembers()) {
                        partyMembers.getPlayer().removeDoor(this.getId());
                        partyMembers.removeDoor(this.getId());
                    }
                    silentPartyUpdateInternal();
                }
            } finally {
                prtLock.unlock();
            }
        }
    } else if (effect.isMapChair()) {
        stopChairTask();
    }
    List<Pair<MapleBuffStat, MapleBuffStatValueHolder>> toCancel = deregisterBuffStats(buffstats);
    if (effect.getSourceId() == Spearman.HYPER_BODY || effect.getSourceId() == GM.HYPER_BODY || effect.getSourceId() == SuperGM.HYPER_BODY) {
        List<Pair<MapleStat, Integer>> statup = new ArrayList<>(4);
        statup.add(new Pair<>(MapleStat.HP, Math.min(hp, maxhp)));
        statup.add(new Pair<>(MapleStat.MP, Math.min(mp, maxmp)));
        statup.add(new Pair<>(MapleStat.MAXHP, maxhp));
        statup.add(new Pair<>(MapleStat.MAXMP, maxmp));
        client.announce(MaplePacketCreator.updatePlayerStats(statup, this));
    }
    if (effect.isMonsterRiding()) {
        if (effect.getSourceId() != Corsair.BATTLE_SHIP) {
            this.getClient().getWorldServer().unregisterMountHunger(this);
            this.getMount().setActive(false);
        }
    }
    if (!overwrite) {
        List<MapleBuffStat> cancelStats = new LinkedList<>();
        chrLock.lock();
        try {
            for (Entry<MapleBuffStat, MapleBuffStatValueHolder> mbsl : buffstats.entrySet()) {
                cancelStats.add(mbsl.getKey());
            }
        } finally {
            chrLock.unlock();
        }
        for (MapleBuffStat mbs : cancelStats) removedStats.add(mbs);
        cancelPlayerBuffs(cancelStats);
    }
    return toCancel;
}
Also used : ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) MapleDoor(server.maps.MapleDoor) MaplePartyCharacter(net.server.world.MaplePartyCharacter) Pair(tools.Pair)

Example 13 with MaplePartyCharacter

use of net.server.world.MaplePartyCharacter in project HeavenMS by ronancpl.

the class MapleCharacter method loadCharFromDB.

public static MapleCharacter loadCharFromDB(int charid, MapleClient client, boolean channelserver) throws SQLException {
    try {
        MapleCharacter ret = new MapleCharacter();
        ret.client = client;
        ret.id = charid;
        Connection con = DatabaseConnection.getConnection();
        PreparedStatement ps = con.prepareStatement("SELECT * FROM characters WHERE id = ?");
        ps.setInt(1, charid);
        ResultSet rs = ps.executeQuery();
        if (!rs.next()) {
            rs.close();
            ps.close();
            throw new RuntimeException("Loading char failed (not found)");
        }
        ret.name = rs.getString("name");
        ret.level = rs.getInt("level");
        ret.fame = rs.getInt("fame");
        ret.quest_fame = rs.getInt("fquest");
        ret.str = rs.getInt("str");
        ret.dex = rs.getInt("dex");
        ret.int_ = rs.getInt("int");
        ret.luk = rs.getInt("luk");
        ret.exp.set(rs.getInt("exp"));
        ret.gachaexp.set(rs.getInt("gachaexp"));
        ret.hp = rs.getInt("hp");
        ret.maxhp = rs.getInt("maxhp");
        ret.mp = rs.getInt("mp");
        ret.maxmp = rs.getInt("maxmp");
        ret.hpMpApUsed = rs.getInt("hpMpUsed");
        ret.hasMerchant = rs.getInt("HasMerchant") == 1;
        String[] skillPoints = rs.getString("sp").split(",");
        for (int i = 0; i < ret.remainingSp.length; i++) {
            ret.remainingSp[i] = Integer.parseInt(skillPoints[i]);
        }
        ret.remainingAp = rs.getInt("ap");
        ret.meso.set(rs.getInt("meso"));
        ret.merchantmeso = rs.getInt("MerchantMesos");
        ret.gmLevel = rs.getInt("gm");
        ret.skinColor = MapleSkinColor.getById(rs.getInt("skincolor"));
        ret.gender = rs.getInt("gender");
        ret.job = MapleJob.getById(rs.getInt("job"));
        ret.finishedDojoTutorial = rs.getInt("finishedDojoTutorial") == 1;
        ret.vanquisherKills = rs.getInt("vanquisherKills");
        ret.omokwins = rs.getInt("omokwins");
        ret.omoklosses = rs.getInt("omoklosses");
        ret.omokties = rs.getInt("omokties");
        ret.matchcardwins = rs.getInt("matchcardwins");
        ret.matchcardlosses = rs.getInt("matchcardlosses");
        ret.matchcardties = rs.getInt("matchcardties");
        ret.hair = rs.getInt("hair");
        ret.face = rs.getInt("face");
        ret.accountid = rs.getInt("accountid");
        ret.mapid = rs.getInt("map");
        ret.jailExpiration = rs.getLong("jailexpire");
        ret.initialSpawnPoint = rs.getInt("spawnpoint");
        ret.world = rs.getByte("world");
        ret.rank = rs.getInt("rank");
        ret.rankMove = rs.getInt("rankMove");
        ret.jobRank = rs.getInt("jobRank");
        ret.jobRankMove = rs.getInt("jobRankMove");
        int mountexp = rs.getInt("mountexp");
        int mountlevel = rs.getInt("mountlevel");
        int mounttiredness = rs.getInt("mounttiredness");
        ret.guildid = rs.getInt("guildid");
        ret.guildRank = rs.getInt("guildrank");
        ret.allianceRank = rs.getInt("allianceRank");
        ret.familyId = rs.getInt("familyId");
        ret.bookCover = rs.getInt("monsterbookcover");
        ret.monsterbook = new MonsterBook();
        ret.monsterbook.loadCards(charid);
        ret.vanquisherStage = rs.getInt("vanquisherStage");
        ret.dojoPoints = rs.getInt("dojoPoints");
        ret.dojoStage = rs.getInt("lastDojoStage");
        ret.dataString = rs.getString("dataString");
        ret.mgc = new MapleGuildCharacter(ret);
        int buddyCapacity = rs.getInt("buddyCapacity");
        ret.buddylist = new BuddyList(buddyCapacity);
        ret.getInventory(MapleInventoryType.EQUIP).setSlotLimit(rs.getByte("equipslots"));
        ret.getInventory(MapleInventoryType.USE).setSlotLimit(rs.getByte("useslots"));
        ret.getInventory(MapleInventoryType.SETUP).setSlotLimit(rs.getByte("setupslots"));
        ret.getInventory(MapleInventoryType.ETC).setSlotLimit(rs.getByte("etcslots"));
        for (Pair<Item, MapleInventoryType> item : ItemFactory.INVENTORY.loadItems(ret.id, !channelserver)) {
            ret.getInventory(item.getRight()).addFromDB(item.getLeft());
            Item itemz = item.getLeft();
            if (itemz.getPetId() > -1) {
                MaplePet pet = itemz.getPet();
                if (pet != null && pet.isSummoned()) {
                    ret.addPet(pet);
                }
                continue;
            }
            if (item.getRight().equals(MapleInventoryType.EQUIP) || item.getRight().equals(MapleInventoryType.EQUIPPED)) {
                Equip equip = (Equip) item.getLeft();
                if (equip.getRingId() > -1) {
                    MapleRing ring = MapleRing.loadFromDb(equip.getRingId());
                    if (item.getRight().equals(MapleInventoryType.EQUIPPED)) {
                        ring.equip();
                    }
                    if (ring.getItemId() > 1112012) {
                        ret.addFriendshipRing(ring);
                    } else {
                        ret.addCrushRing(ring);
                    }
                }
            }
        }
        NewYearCardRecord.loadPlayerNewYearCards(ret);
        PreparedStatement ps2, ps3;
        ResultSet rs2, rs3;
        ps3 = con.prepareStatement("SELECT petid FROM inventoryitems WHERE characterid = ? AND petid > -1");
        ps3.setInt(1, charid);
        rs3 = ps3.executeQuery();
        while (rs3.next()) {
            int petId = rs3.getInt("petid");
            ps2 = con.prepareStatement("SELECT itemid FROM petignores WHERE petid = ?");
            ps2.setInt(1, petId);
            ret.resetExcluded(petId);
            rs2 = ps2.executeQuery();
            while (rs2.next()) {
                ret.addExcluded(petId, rs2.getInt("itemid"));
            }
            ps2.close();
            rs2.close();
        }
        ps3.close();
        rs3.close();
        ret.commitExcludedItems();
        if (channelserver) {
            MapleMapFactory mapFactory = client.getChannelServer().getMapFactory();
            ret.map = mapFactory.getMap(ret.mapid);
            if (ret.map == null) {
                ret.map = mapFactory.getMap(100000000);
            }
            MaplePortal portal = ret.map.getPortal(ret.initialSpawnPoint);
            if (portal == null) {
                portal = ret.map.getPortal(0);
                ret.initialSpawnPoint = 0;
            }
            ret.setPosition(portal.getPosition());
            int partyid = rs.getInt("party");
            MapleParty party = Server.getInstance().getWorld(ret.world).getParty(partyid);
            if (party != null) {
                ret.mpc = party.getMemberById(ret.id);
                if (ret.mpc != null) {
                    ret.mpc = new MaplePartyCharacter(ret);
                    ret.party = party;
                }
            }
            int messengerid = rs.getInt("messengerid");
            int position = rs.getInt("messengerposition");
            if (messengerid > 0 && position < 4 && position > -1) {
                MapleMessenger messenger = Server.getInstance().getWorld(ret.world).getMessenger(messengerid);
                if (messenger != null) {
                    ret.messenger = messenger;
                    ret.messengerposition = position;
                }
            }
            ret.loggedIn = true;
        }
        rs.close();
        ps.close();
        ps = con.prepareStatement("SELECT mapid,vip FROM trocklocations WHERE characterid = ? LIMIT 15");
        ps.setInt(1, charid);
        rs = ps.executeQuery();
        byte v = 0;
        byte r = 0;
        while (rs.next()) {
            if (rs.getInt("vip") == 1) {
                ret.viptrockmaps.add(rs.getInt("mapid"));
                v++;
            } else {
                ret.trockmaps.add(rs.getInt("mapid"));
                r++;
            }
        }
        while (v < 10) {
            ret.viptrockmaps.add(999999999);
            v++;
        }
        while (r < 5) {
            ret.trockmaps.add(999999999);
            r++;
        }
        rs.close();
        ps.close();
        ps = con.prepareStatement("SELECT name FROM accounts WHERE id = ?", Statement.RETURN_GENERATED_KEYS);
        ps.setInt(1, ret.accountid);
        rs = ps.executeQuery();
        if (rs.next()) {
            ret.getClient().setAccountName(rs.getString("name"));
        }
        rs.close();
        ps.close();
        ps = con.prepareStatement("SELECT `area`,`info` FROM area_info WHERE charid = ?");
        ps.setInt(1, ret.id);
        rs = ps.executeQuery();
        while (rs.next()) {
            ret.area_info.put(rs.getShort("area"), rs.getString("info"));
        }
        rs.close();
        ps.close();
        ps = con.prepareStatement("SELECT `name`,`info` FROM eventstats WHERE characterid = ?");
        ps.setInt(1, ret.id);
        rs = ps.executeQuery();
        while (rs.next()) {
            String name = rs.getString("name");
            if (rs.getString("name").equals("rescueGaga")) {
                ret.events.put(name, new RescueGaga(rs.getInt("info")));
            }
        // ret.events = new MapleEvents(new RescueGaga(rs.getInt("rescuegaga")), new ArtifactHunt(rs.getInt("artifacthunt")));
        }
        rs.close();
        ps.close();
        ret.cashshop = new CashShop(ret.accountid, ret.id, ret.getJobType());
        ret.autoban = new AutobanManager(ret);
        // for now
        ret.marriageRing = null;
        ps = con.prepareStatement("SELECT name, level FROM characters WHERE accountid = ? AND id != ? ORDER BY level DESC limit 1");
        ps.setInt(1, ret.accountid);
        ps.setInt(2, charid);
        rs = ps.executeQuery();
        if (rs.next()) {
            ret.linkedName = rs.getString("name");
            ret.linkedLevel = rs.getInt("level");
        }
        rs.close();
        ps.close();
        if (channelserver) {
            ps = con.prepareStatement("SELECT * FROM queststatus WHERE characterid = ?");
            ps.setInt(1, charid);
            rs = ps.executeQuery();
            PreparedStatement psf;
            try (PreparedStatement pse = con.prepareStatement("SELECT * FROM questprogress WHERE queststatusid = ?")) {
                psf = con.prepareStatement("SELECT mapid FROM medalmaps WHERE queststatusid = ?");
                while (rs.next()) {
                    MapleQuest q = MapleQuest.getInstance(rs.getShort("quest"));
                    MapleQuestStatus status = new MapleQuestStatus(q, MapleQuestStatus.Status.getById(rs.getInt("status")));
                    long cTime = rs.getLong("time");
                    if (cTime > -1) {
                        status.setCompletionTime(cTime * 1000);
                    }
                    long eTime = rs.getLong("expires");
                    if (eTime > 0) {
                        status.setExpirationTime(eTime);
                    }
                    status.setForfeited(rs.getInt("forfeited"));
                    ret.quests.put(q.getId(), status);
                    pse.setInt(1, rs.getInt("queststatusid"));
                    try (ResultSet rsProgress = pse.executeQuery()) {
                        while (rsProgress.next()) {
                            status.setProgress(rsProgress.getInt("progressid"), rsProgress.getString("progress"));
                        }
                    }
                    psf.setInt(1, rs.getInt("queststatusid"));
                    try (ResultSet medalmaps = psf.executeQuery()) {
                        while (medalmaps.next()) {
                            status.addMedalMap(medalmaps.getInt("mapid"));
                        }
                    }
                }
                rs.close();
                ps.close();
            }
            psf.close();
            ps = con.prepareStatement("SELECT skillid,skilllevel,masterlevel,expiration FROM skills WHERE characterid = ?");
            ps.setInt(1, charid);
            rs = ps.executeQuery();
            while (rs.next()) {
                ret.skills.put(SkillFactory.getSkill(rs.getInt("skillid")), new SkillEntry(rs.getByte("skilllevel"), rs.getInt("masterlevel"), rs.getLong("expiration")));
            }
            rs.close();
            ps.close();
            ps = con.prepareStatement("SELECT SkillID,StartTime,length FROM cooldowns WHERE charid = ?");
            ps.setInt(1, ret.getId());
            rs = ps.executeQuery();
            while (rs.next()) {
                final int skillid = rs.getInt("SkillID");
                final long length = rs.getLong("length"), startTime = rs.getLong("StartTime");
                if (skillid != 5221999 && (length + startTime < System.currentTimeMillis())) {
                    continue;
                }
                ret.giveCoolDowns(skillid, startTime, length);
            }
            rs.close();
            ps.close();
            ps = con.prepareStatement("DELETE FROM cooldowns WHERE charid = ?");
            ps.setInt(1, ret.getId());
            ps.executeUpdate();
            ps.close();
            ps = con.prepareStatement("SELECT * FROM skillmacros WHERE characterid = ?");
            ps.setInt(1, charid);
            rs = ps.executeQuery();
            while (rs.next()) {
                int position = rs.getInt("position");
                SkillMacro macro = new SkillMacro(rs.getInt("skill1"), rs.getInt("skill2"), rs.getInt("skill3"), rs.getString("name"), rs.getInt("shout"), position);
                ret.skillMacros[position] = macro;
            }
            rs.close();
            ps.close();
            ps = con.prepareStatement("SELECT `key`,`type`,`action` FROM keymap WHERE characterid = ?");
            ps.setInt(1, charid);
            rs = ps.executeQuery();
            while (rs.next()) {
                int key = rs.getInt("key");
                int type = rs.getInt("type");
                int action = rs.getInt("action");
                ret.keymap.put(Integer.valueOf(key), new MapleKeyBinding(type, action));
            }
            rs.close();
            ps.close();
            ps = con.prepareStatement("SELECT `locationtype`,`map`,`portal` FROM savedlocations WHERE characterid = ?");
            ps.setInt(1, charid);
            rs = ps.executeQuery();
            while (rs.next()) {
                ret.savedLocations[SavedLocationType.valueOf(rs.getString("locationtype")).ordinal()] = new SavedLocation(rs.getInt("map"), rs.getInt("portal"));
            }
            rs.close();
            ps.close();
            ps = con.prepareStatement("SELECT `characterid_to`,`when` FROM famelog WHERE characterid = ? AND DATEDIFF(NOW(),`when`) < 30");
            ps.setInt(1, charid);
            rs = ps.executeQuery();
            ret.lastfametime = 0;
            ret.lastmonthfameids = new ArrayList<>(31);
            while (rs.next()) {
                ret.lastfametime = Math.max(ret.lastfametime, rs.getTimestamp("when").getTime());
                ret.lastmonthfameids.add(Integer.valueOf(rs.getInt("characterid_to")));
            }
            rs.close();
            ps.close();
            ret.buddylist.loadFromDb(charid);
            ret.storage = MapleStorage.loadOrCreateFromDB(ret.accountid, ret.world);
            ret.recalcLocalStats();
            // ret.resetBattleshipHp();
            ret.silentEnforceMaxHpMp();
        }
        int mountid = ret.getJobType() * 10000000 + 1004;
        if (ret.getInventory(MapleInventoryType.EQUIPPED).getItem((short) -18) != null) {
            ret.maplemount = new MapleMount(ret, ret.getInventory(MapleInventoryType.EQUIPPED).getItem((short) -18).getItemId(), mountid);
        } else {
            ret.maplemount = new MapleMount(ret, 0, mountid);
        }
        ret.maplemount.setExp(mountexp);
        ret.maplemount.setLevel(mountlevel);
        ret.maplemount.setTiredness(mounttiredness);
        ret.maplemount.setActive(false);
        con.close();
        return ret;
    } catch (SQLException | RuntimeException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : MapleQuest(server.quest.MapleQuest) AutobanManager(client.autoban.AutobanManager) SQLException(java.sql.SQLException) MapleGuildCharacter(net.server.guild.MapleGuildCharacter) RescueGaga(server.events.RescueGaga) MapleMapFactory(server.maps.MapleMapFactory) MapleMapItem(server.maps.MapleMapItem) Item(client.inventory.Item) MaplePlayerShopItem(server.maps.MaplePlayerShopItem) Equip(client.inventory.Equip) MapleInventoryType(client.inventory.MapleInventoryType) ResultSet(java.sql.ResultSet) MaplePet(client.inventory.MaplePet) CashShop(server.CashShop) DatabaseConnection(tools.DatabaseConnection) Connection(java.sql.Connection) SavedLocation(server.maps.SavedLocation) MapleParty(net.server.world.MapleParty) PreparedStatement(java.sql.PreparedStatement) Point(java.awt.Point) MaplePortal(server.MaplePortal) MaplePartyCharacter(net.server.world.MaplePartyCharacter) MapleMessenger(net.server.world.MapleMessenger)

Example 14 with MaplePartyCharacter

use of net.server.world.MaplePartyCharacter in project HeavenMS by ronancpl.

the class PlayerLoggedinHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    final int cid = slea.readInt();
    final Server server = Server.getInstance();
    MapleCharacter player = c.getWorldServer().getPlayerStorage().getCharacterById(cid);
    boolean newcomer = false;
    if (player == null) {
        try {
            player = MapleCharacter.loadCharFromDB(cid, c, true);
            newcomer = true;
        } catch (SQLException e) {
            e.printStackTrace();
        }
    } else {
        player.newClient(c);
    }
    if (player == null) {
        // If you are still getting null here then please just uninstall the game >.>, we dont need you fucking with the logs
        c.disconnect(true, false);
        return;
    }
    c.setPlayer(player);
    c.setAccID(player.getAccountID());
    int state = c.getLoginState();
    boolean allowLogin = true;
    Channel cserv = c.getChannelServer();
    if (state == MapleClient.LOGIN_SERVER_TRANSITION || state == MapleClient.LOGIN_NOTLOGGEDIN) {
        for (String charName : c.loadCharacterNames(c.getWorld())) {
            for (Channel ch : c.getWorldServer().getChannels()) {
                if (ch.isConnected(charName)) {
                    allowLogin = false;
                }
            }
            break;
        }
    }
    if (state != MapleClient.LOGIN_SERVER_TRANSITION || !allowLogin) {
        c.setPlayer(null);
        c.announce(MaplePacketCreator.getAfterLoginError(7));
        return;
    }
    c.updateLoginState(MapleClient.LOGIN_LOGGEDIN);
    cserv.addPlayer(player);
    List<PlayerBuffValueHolder> buffs = server.getPlayerBuffStorage().getBuffsFromStorage(cid);
    if (buffs != null) {
        List<Pair<Long, PlayerBuffValueHolder>> timedBuffs = getLocalStartTimes(buffs);
        player.silentGiveBuffs(timedBuffs);
    }
    c.announce(MaplePacketCreator.getCharInfo(player));
    if (!player.isHidden()) {
        player.toggleHide(true);
    }
    player.sendKeymap();
    player.sendMacros();
    if (player.getKeymap().get(91) != null)
        player.announce(MaplePacketCreator.sendAutoHpPot(player.getKeymap().get(91).getAction()));
    if (player.getKeymap().get(92) != null)
        player.announce(MaplePacketCreator.sendAutoMpPot(player.getKeymap().get(92).getAction()));
    player.getMap().addPlayer(player);
    World world = server.getWorld(c.getWorld());
    world.getPlayerStorage().addPlayer(player);
    player.setAwayFromWorld(false);
    int[] buddyIds = player.getBuddylist().getBuddyIds();
    world.loggedOn(player.getName(), player.getId(), c.getChannel(), buddyIds);
    for (CharacterIdChannelPair onlineBuddy : server.getWorld(c.getWorld()).multiBuddyFind(player.getId(), buddyIds)) {
        BuddylistEntry ble = player.getBuddylist().get(onlineBuddy.getCharacterId());
        ble.setChannel(onlineBuddy.getChannel());
        player.getBuddylist().put(ble);
    }
    c.announce(MaplePacketCreator.updateBuddylist(player.getBuddylist().getBuddies()));
    c.announce(MaplePacketCreator.loadFamily(player));
    if (player.getFamilyId() > 0) {
        MapleFamily f = world.getFamily(player.getFamilyId());
        if (f == null) {
            f = new MapleFamily(player.getId());
            world.addFamily(player.getFamilyId(), f);
        }
        player.setFamily(f);
        c.announce(MaplePacketCreator.getFamilyInfo(f.getMember(player.getId())));
    }
    if (player.getGuildId() > 0) {
        MapleGuild playerGuild = server.getGuild(player.getGuildId(), player.getWorld(), player);
        if (playerGuild == null) {
            player.deleteGuild(player.getGuildId());
            player.getMGC().setGuildId(0);
        } else {
            playerGuild.getMGC(player.getId()).setCharacter(player);
            player.setMGC(playerGuild.getMGC(player.getId()));
            server.setGuildMemberOnline(player, true, c.getChannel());
            c.announce(MaplePacketCreator.showGuildInfo(player));
            int allianceId = player.getGuild().getAllianceId();
            if (allianceId > 0) {
                MapleAlliance newAlliance = server.getAlliance(allianceId);
                if (newAlliance == null) {
                    newAlliance = MapleAlliance.loadAlliance(allianceId);
                    if (newAlliance != null) {
                        server.addAlliance(allianceId, newAlliance);
                    } else {
                        player.getGuild().setAllianceId(0);
                    }
                }
                if (newAlliance != null) {
                    c.announce(MaplePacketCreator.updateAllianceInfo(newAlliance, c));
                    c.announce(MaplePacketCreator.allianceNotice(newAlliance.getId(), newAlliance.getNotice()));
                    if (newcomer) {
                        server.allianceMessage(allianceId, MaplePacketCreator.allianceMemberOnline(player, true), player.getId(), -1);
                    }
                }
            }
        }
    }
    player.showNote();
    if (player.getParty() != null) {
        MaplePartyCharacter pchar = player.getMPC();
        // Use this in case of enabling party HPbar HUD when logging in, however "you created a party" will appear on chat.
        // c.announce(MaplePacketCreator.partyCreated(pchar));
        pchar.setChannel(c.getChannel());
        pchar.setMapId(player.getMapId());
        pchar.setOnline(true);
        world.updateParty(player.getParty().getId(), PartyOperation.LOG_ONOFF, pchar);
        player.updatePartyMemberHP();
    }
    if (player.getInventory(MapleInventoryType.EQUIPPED).findById(1122017) != null) {
        player.equipPendantOfSpirit();
    }
    c.announce(MaplePacketCreator.updateBuddylist(player.getBuddylist().getBuddies()));
    CharacterNameAndId pendingBuddyRequest = c.getPlayer().getBuddylist().pollPendingRequest();
    if (pendingBuddyRequest != null) {
        c.announce(MaplePacketCreator.requestBuddylistAdd(pendingBuddyRequest.getId(), c.getPlayer().getId(), pendingBuddyRequest.getName()));
    }
    if (newcomer) {
        for (MaplePet pet : player.getPets()) {
            if (pet != null)
                world.registerPetHunger(player, player.getPetIndex(pet));
        }
        player.reloadQuestExpirations();
    }
    c.announce(MaplePacketCreator.updateGender(player));
    player.checkMessenger();
    c.announce(MaplePacketCreator.enableReport());
    player.changeSkillLevel(SkillFactory.getSkill(10000000 * player.getJobType() + 12), (byte) (player.getLinkedLevel() / 10), 20, -1);
    player.checkBerserk(player.isHidden());
    player.buffExpireTask();
    player.diseaseExpireTask();
    player.skillCooldownTask();
    player.expirationTask();
    player.questExpirationTask();
    if (GameConstants.hasSPTable(player.getJob()) && player.getJob().getId() != 2001) {
        player.createDragon();
    }
    player.commitExcludedItems();
    if (newcomer) {
        /*
            if (!c.hasVotedAlready()){
            	player.announce(MaplePacketCreator.earnTitleMessage("You can vote now! Vote and earn a vote point!"));
            }
                    */
        if (player.isGM()) {
            Server.getInstance().broadcastGMMessage(c.getWorld(), MaplePacketCreator.earnTitleMessage((player.gmLevel() < 6 ? "GM " : "Admin ") + player.getName() + " has logged in"));
        }
    }
    showDueyNotification(c, player);
    if (player.getMap().getHPDec() > 0)
        player.resetHpDecreaseTask();
    player.resetPlayerRates();
    if (ServerConstants.USE_ADD_RATES_BY_LEVEL == true)
        player.setPlayerRates();
    player.setWorldRates();
    player.updateCouponRates();
    player.receivePartyMemberHP();
}
Also used : MapleCharacter(client.MapleCharacter) PlayerBuffValueHolder(net.server.PlayerBuffValueHolder) CharacterIdChannelPair(net.server.channel.CharacterIdChannelPair) Server(net.server.Server) SQLException(java.sql.SQLException) MapleFamily(client.MapleFamily) Channel(net.server.channel.Channel) World(net.server.world.World) BuddylistEntry(client.BuddylistEntry) MapleGuild(net.server.guild.MapleGuild) MapleAlliance(net.server.guild.MapleAlliance) MaplePet(client.inventory.MaplePet) CharacterIdChannelPair(net.server.channel.CharacterIdChannelPair) Pair(tools.Pair) MaplePartyCharacter(net.server.world.MaplePartyCharacter) CharacterNameAndId(client.CharacterNameAndId)

Example 15 with MaplePartyCharacter

use of net.server.world.MaplePartyCharacter in project HeavenMS by ronancpl.

the class PartySearchStartHandler method handlePacket.

@Override
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    if (!ServerConstants.USE_PARTY_SEARCH) {
        return;
    }
    int min = slea.readInt();
    int max = slea.readInt();
    // members
    slea.readInt();
    int jobs = slea.readInt();
    MapleParty party = c.getPlayer().getParty();
    if (party == null)
        return;
    MapleCharacter chr = c.getPlayer();
    MapleMap map = chr.getMap();
    World world = c.getWorldServer();
    Collection<MapleMapObject> mapobjs = map.getPlayers();
    for (MapleMapObject mapobj : mapobjs) {
        if (party.getMembers().size() > 5) {
            break;
        }
        if (mapobj instanceof MapleCharacter) {
            MapleCharacter tchar = (MapleCharacter) mapobj;
            int charlvl = tchar.getLevel();
            if (charlvl >= min && charlvl <= max && isValidJob(tchar.getJob(), jobs)) {
                if (tchar.getParty() == null) {
                    MaplePartyCharacter partyplayer = new MaplePartyCharacter(tchar);
                    tchar.getMap().addPartyMember(tchar);
                    world.updateParty(party.getId(), PartyOperation.JOIN, partyplayer);
                    tchar.receivePartyMemberHP();
                    tchar.updatePartyMemberHP();
                }
            }
        }
    }
}
Also used : MapleMap(server.maps.MapleMap) MapleCharacter(client.MapleCharacter) MapleParty(net.server.world.MapleParty) MapleMapObject(server.maps.MapleMapObject) World(net.server.world.World) MaplePartyCharacter(net.server.world.MaplePartyCharacter)

Aggregations

MaplePartyCharacter (net.server.world.MaplePartyCharacter)16 MapleCharacter (client.MapleCharacter)6 Point (java.awt.Point)6 MapleParty (net.server.world.MapleParty)6 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 World (net.server.world.World)4 MapleMap (server.maps.MapleMap)4 Pair (tools.Pair)4 SQLException (java.sql.SQLException)3 MapleDoor (server.maps.MapleDoor)3 Item (client.inventory.Item)2 MaplePet (client.inventory.MaplePet)2 Server (net.server.Server)2 MapleGuild (net.server.guild.MapleGuild)2 MapleGuildCharacter (net.server.guild.MapleGuildCharacter)2 MapleMapFactory (server.maps.MapleMapFactory)2 MapleMapItem (server.maps.MapleMapItem)2 BuddylistEntry (client.BuddylistEntry)1 CharacterNameAndId (client.CharacterNameAndId)1