Search in sources :

Example 86 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class EventManager method attemptStartGuildInstance.

public boolean attemptStartGuildInstance() {
    MapleCharacter chr = null;
    while (chr == null) {
        List<Integer> guildInstance = getNextGuildQueue();
        if (guildInstance == null) {
            return false;
        }
        chr = cserv.getPlayerStorage().getCharacterById(guildInstance.get(1));
    }
    return startInstance(chr);
}
Also used : MapleCharacter(client.MapleCharacter)

Example 87 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class MapleMonster method switchController.

public void switchController(MapleCharacter newController, boolean immediateAggro) {
    MapleCharacter controllers = getController();
    if (controllers == newController) {
        return;
    }
    if (controllers != null) {
        controllers.stopControllingMonster(this);
        controllers.getClient().announce(MaplePacketCreator.stopControllingMonster(getObjectId()));
    }
    newController.controlMonster(this, immediateAggro);
    setController(newController);
    if (immediateAggro) {
        setControllerHasAggro(true);
    }
    setControllerKnowsAboutAggro(false);
}
Also used : MapleCharacter(client.MapleCharacter)

Example 88 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class MapleMonster method distributeExperience.

public void distributeExperience(int killerId) {
    if (isAlive()) {
        return;
    }
    int minThresholdLevel = calcThresholdLevel(this.getMap().getEventInstance() != null);
    int exp = getExp();
    long totalHealth = maxHpPlusHeal.get();
    Map<Integer, Integer> expDist = new HashMap<>();
    Map<Integer, Integer> partyExp = new HashMap<>();
    // 80% of pool is split amongst all the damagers
    float exp8perHp = (0.8f * exp) / totalHealth;
    // 20% of pool goes to the killer or his/her party
    float exp2 = (0.2f * exp);
    for (Entry<Integer, AtomicInteger> damage : takenDamage.entrySet()) {
        expDist.put(damage.getKey(), (int) (Math.min((exp8perHp * damage.getValue().get()), Integer.MAX_VALUE)));
    }
    Collection<MapleCharacter> chrs = map.getCharacters();
    Set<MapleCharacter> underleveled = new LinkedHashSet<>();
    for (MapleCharacter mc : chrs) {
        if (expDist.containsKey(mc.getId())) {
            boolean isKiller = (mc.getId() == killerId);
            int xp = expDist.get(mc.getId());
            if (isKiller) {
                xp = (int) Math.min(exp2 + xp, Integer.MAX_VALUE);
            }
            MapleParty p = mc.getParty();
            if (p != null) {
                int pID = p.getId();
                long pXP = (long) xp + (partyExp.containsKey(pID) ? partyExp.get(pID) : 0);
                partyExp.put(pID, (int) Math.min(pXP, Integer.MAX_VALUE));
            } else {
                if (mc.getLevel() >= minThresholdLevel) {
                    // NO EXP WILL BE GIVEN for those who are underleveled!
                    giveExpToCharacter(mc, xp, isKiller, 1);
                } else {
                    underleveled.add(mc);
                }
            }
        }
    }
    for (Entry<Integer, Integer> party : partyExp.entrySet()) {
        distributeExperienceToParty(party.getKey(), party.getValue(), killerId, underleveled, minThresholdLevel);
    }
    for (MapleCharacter mc : underleveled) {
        mc.showUnderleveledInfo(this);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MapleCharacter(client.MapleCharacter) HashMap(java.util.HashMap) MapleParty(net.server.world.MapleParty) Point(java.awt.Point) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 89 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class MapleMonster method killBy.

public MapleCharacter killBy(final MapleCharacter killer) {
    distributeExperience(killer != null ? killer.getId() : 0);
    MapleCharacter controller = getController();
    if (controller != null) {
        // this can/should only happen when a hidden gm attacks the monster
        controller.getClient().announce(MaplePacketCreator.stopControllingMonster(this.getObjectId()));
        controller.stopControllingMonster(this);
    }
    // this doesn't work (?)
    final List<Integer> toSpawn = this.getRevives();
    if (toSpawn != null) {
        final MapleMap reviveMap = killer.getMap();
        if (toSpawn.contains(9300216) && reviveMap.getId() > 925000000 && reviveMap.getId() < 926000000) {
            reviveMap.broadcastMessage(MaplePacketCreator.playSound("Dojang/clear"));
            reviveMap.broadcastMessage(MaplePacketCreator.showEffect("dojang/end/clear"));
        }
        Pair<Integer, String> timeMob = reviveMap.getTimeMob();
        if (timeMob != null) {
            if (toSpawn.contains(timeMob.getLeft())) {
                reviveMap.broadcastMessage(MaplePacketCreator.serverNotice(6, timeMob.getRight()));
            }
            if (timeMob.getLeft() == 9300338 && (reviveMap.getId() >= 922240100 && reviveMap.getId() <= 922240119)) {
                if (!reviveMap.containsNPC(9001108)) {
                    MapleNPC npc = MapleLifeFactory.getNPC(9001108);
                    npc.setPosition(new Point(172, 9));
                    npc.setCy(9);
                    npc.setRx0(172 + 50);
                    npc.setRx1(172 - 50);
                    npc.setFh(27);
                    reviveMap.addMapObject(npc);
                    reviveMap.broadcastMessage(MaplePacketCreator.spawnNPC(npc));
                } else {
                    reviveMap.toggleHiddenNPC(9001108);
                }
            }
        }
        if (toSpawn.size() > 0) {
            TimerManager.getInstance().schedule(new Runnable() {

                @Override
                public void run() {
                    for (Integer mid : toSpawn) {
                        final MapleMonster mob = MapleLifeFactory.getMonster(mid);
                        mob.setPosition(getPosition());
                        mob.setFh(getFh());
                        mob.setParentMobOid(getObjectId());
                        if (dropsDisabled()) {
                            mob.disableDrops();
                        }
                        reviveMap.spawnMonster(mob);
                        if (mob.getId() >= 8810010 && mob.getId() <= 8810017 && reviveMap.isHorntailDefeated()) {
                            boolean htKilled = false;
                            MapleMonster ht = reviveMap.getMonsterById(8810018);
                            if (ht != null) {
                                ht.lockMonster();
                                try {
                                    htKilled = ht.isAlive();
                                    ht.setHpZero();
                                } finally {
                                    ht.unlockMonster();
                                }
                                if (htKilled) {
                                    reviveMap.killMonster(ht, killer, true);
                                    ht.broadcastMobHpBar(killer);
                                }
                            }
                            for (int i = 8810017; i >= 8810010; i--) reviveMap.killMonster(reviveMap.getMonsterById(i), killer, true);
                        }
                    }
                }
            }, getAnimationTime("die1"));
        }
    } else {
        // is this even necessary?
        System.out.println("[CRITICAL LOSS] toSpawn is null for " + this.getName());
    }
    MapleCharacter looter = map.getCharacterById(getHighestDamagerId());
    return looter != null ? looter : killer;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapleMap(server.maps.MapleMap) MapleCharacter(client.MapleCharacter) Point(java.awt.Point)

Example 90 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class MapleMonster method distributeExperienceToParty.

private void distributeExperienceToParty(int pid, int exp, int killer, Set<MapleCharacter> underleveled, int minThresholdLevel) {
    List<MapleCharacter> members = new LinkedList<>();
    MapleCharacter pchar = getMap().getAnyCharacterFromParty(pid);
    if (pchar != null) {
        for (MapleCharacter chr : pchar.getPartyMembersOnSameMap()) {
            members.add(chr);
        }
    } else {
        MapleCharacter chr = getMap().getCharacterById(killer);
        if (chr == null)
            return;
        members.add(chr);
    }
    int partyLevel = 0;
    int leechCount = 0;
    for (MapleCharacter mc : members) {
        if (mc.getLevel() >= minThresholdLevel) {
            // NO EXP WILL BE GIVEN for those who are underleveled!
            partyLevel += mc.getLevel();
            leechCount++;
        } else {
            underleveled.add(mc);
        }
    }
    final int mostDamageCid = getHighestDamagerId();
    for (MapleCharacter mc : members) {
        int id = mc.getId();
        int level = mc.getLevel();
        if (level >= minThresholdLevel) {
            boolean isKiller = killer == id;
            boolean mostDamage = mostDamageCid == id;
            int xp = (int) ((0.80f * exp * level) / partyLevel);
            if (mostDamage) {
                xp += (0.20f * exp);
            }
            giveExpToCharacter(mc, xp, isKiller, leechCount);
        }
    }
}
Also used : MapleCharacter(client.MapleCharacter) LinkedList(java.util.LinkedList) Point(java.awt.Point)

Aggregations

MapleCharacter (client.MapleCharacter)163 Point (java.awt.Point)32 SQLException (java.sql.SQLException)22 Item (client.inventory.Item)21 Connection (java.sql.Connection)15 PreparedStatement (java.sql.PreparedStatement)15 MapleMonster (server.life.MapleMonster)15 MapleMapObject (server.maps.MapleMapObject)15 DatabaseConnection (tools.DatabaseConnection)15 MapleMap (server.maps.MapleMap)14 ArrayList (java.util.ArrayList)13 Skill (client.Skill)12 SpawnPoint (server.life.SpawnPoint)12 LinkedList (java.util.LinkedList)11 MapleInventory (client.inventory.MapleInventory)10 World (net.server.world.World)10 MapleStatEffect (server.MapleStatEffect)10 MapleInventoryType (client.inventory.MapleInventoryType)9 ResultSet (java.sql.ResultSet)9 MapleItemInformationProvider (server.MapleItemInformationProvider)9