use of tools.Pair in project HeavenMS by ronancpl.
the class MapleCharacter method handleEnergyChargeGain.
public void handleEnergyChargeGain() {
// to get here energychargelevel has to be > 0
Skill energycharge = isCygnus() ? SkillFactory.getSkill(ThunderBreaker.ENERGY_CHARGE) : SkillFactory.getSkill(Marauder.ENERGY_CHARGE);
MapleStatEffect ceffect;
ceffect = energycharge.getEffect(getSkillLevel(energycharge));
TimerManager tMan = TimerManager.getInstance();
if (energybar < 10000) {
energybar += 102;
if (energybar > 10000) {
energybar = 10000;
}
List<Pair<MapleBuffStat, Integer>> stat = Collections.singletonList(new Pair<>(MapleBuffStat.ENERGY_CHARGE, energybar));
setBuffedValue(MapleBuffStat.ENERGY_CHARGE, energybar);
client.announce(MaplePacketCreator.giveBuff(energybar, 0, stat));
client.announce(MaplePacketCreator.showOwnBuffEffect(energycharge.getId(), 2));
getMap().broadcastMessage(this, MaplePacketCreator.showBuffeffect(id, energycharge.getId(), 2));
getMap().broadcastMessage(this, MaplePacketCreator.giveForeignBuff(energybar, stat));
}
if (energybar >= 10000 && energybar < 11000) {
energybar = 15000;
final MapleCharacter chr = this;
tMan.schedule(new Runnable() {
@Override
public void run() {
energybar = 0;
List<Pair<MapleBuffStat, Integer>> stat = Collections.singletonList(new Pair<>(MapleBuffStat.ENERGY_CHARGE, energybar));
setBuffedValue(MapleBuffStat.ENERGY_CHARGE, energybar);
client.announce(MaplePacketCreator.giveBuff(energybar, 0, stat));
getMap().broadcastMessage(chr, MaplePacketCreator.giveForeignBuff(energybar, stat));
}
}, ceffect.getDuration());
}
}
use of tools.Pair 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();
}
use of tools.Pair 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;
}
use of tools.Pair in project HeavenMS by ronancpl.
the class MapleCharacter method deregisterBuffStats.
private List<Pair<MapleBuffStat, MapleBuffStatValueHolder>> deregisterBuffStats(Map<MapleBuffStat, MapleBuffStatValueHolder> stats) {
chrLock.lock();
try {
List<Pair<MapleBuffStat, MapleBuffStatValueHolder>> effectsToCancel = new ArrayList<>(stats.size());
for (Entry<MapleBuffStat, MapleBuffStatValueHolder> stat : stats.entrySet()) {
int sourceid = stat.getValue().effect.getBuffSourceId();
if (!buffEffects.containsKey(sourceid)) {
buffExpires.remove(sourceid);
}
MapleBuffStat mbs = stat.getKey();
effectsToCancel.add(new Pair<>(mbs, stat.getValue()));
MapleBuffStatValueHolder mbsvh = effects.get(mbs);
if (mbsvh != null && mbsvh.effect.getBuffSourceId() == sourceid) {
mbsvh.bestApplied = true;
effects.remove(mbs);
if (mbs == MapleBuffStat.RECOVERY) {
if (recoveryTask != null) {
recoveryTask.cancel(false);
recoveryTask = null;
}
} else if (mbs == MapleBuffStat.SUMMON || mbs == MapleBuffStat.PUPPET) {
int summonId = mbsvh.effect.getSourceId();
MapleSummon summon = summons.get(summonId);
if (summon != null) {
getMap().broadcastMessage(MaplePacketCreator.removeSummon(summon, true), summon.getPosition());
getMap().removeMapObject(summon);
removeVisibleMapObject(summon);
summons.remove(summonId);
if (summon.getSkill() == DarkKnight.BEHOLDER) {
if (beholderHealingSchedule != null) {
beholderHealingSchedule.cancel(false);
beholderHealingSchedule = null;
}
if (beholderBuffSchedule != null) {
beholderBuffSchedule.cancel(false);
beholderBuffSchedule = null;
}
}
}
} else if (mbs == MapleBuffStat.DRAGONBLOOD) {
dragonBloodSchedule.cancel(false);
dragonBloodSchedule = null;
} else if (mbs == MapleBuffStat.HPREC || mbs == MapleBuffStat.MPREC) {
if (mbs == MapleBuffStat.HPREC) {
extraHpRec = 0;
} else {
extraMpRec = 0;
}
if (extraRecoveryTask != null) {
extraRecoveryTask.cancel(false);
extraRecoveryTask = null;
}
if (extraHpRec != 0 || extraMpRec != 0) {
startExtraTaskInternal(extraHpRec, extraMpRec, extraRecInterval);
}
}
}
}
return effectsToCancel;
} finally {
chrLock.unlock();
}
}
use of tools.Pair 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();
}
Aggregations