/*
OrpheusMS: MapleStory Private Server based on OdinMS
Copyright (C) 2012 Aaron Weiss <aaron@deviant-core.net>
Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.server.handlers.channel;
import client.MapleCharacter;
import client.MapleClient;
import client.MapleJob;
import client.MapleStat;
import net.AbstractMaplePacketHandler;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public final class DistributeAPHandler extends AbstractMaplePacketHandler {
private static final int max = Short.MAX_VALUE;
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
slea.readInt();
int num = slea.readInt();
if (c.getPlayer().getRemainingAp() > 0) {
if (addStat(c, num)) {
c.getPlayer().setRemainingAp(c.getPlayer().getRemainingAp() - 1);
c.getPlayer().updateSingleStat(MapleStat.AVAILABLEAP, c.getPlayer().getRemainingAp());
}
}
c.announce(MaplePacketCreator.enableActions());
}
static boolean addStat(MapleClient c, int id) {
switch (id) {
case 64: // Str
if (c.getPlayer().getStr() >= max) {
return false;
}
c.getPlayer().addStat(1, 1);
break;
case 128: // Dex
if (c.getPlayer().getDex() >= max) {
return false;
}
c.getPlayer().addStat(2, 1);
break;
case 256: // Int
if (c.getPlayer().getInt() >= max) {
return false;
}
c.getPlayer().addStat(3, 1);
break;
case 512: // Luk
if (c.getPlayer().getLuk() >= max) {
return false;
}
c.getPlayer().addStat(4, 1);
break;
case 2048: // HP
addHP(c.getPlayer(), addHP(c));
break;
case 8192: // MP
addMP(c.getPlayer(), addMP(c));
break;
default:
c.announce(MaplePacketCreator.updatePlayerStats(MaplePacketCreator.EMPTY_STATUPDATE, true));
return false;
}
return true;
}
static int addHP(MapleClient c) {
MapleCharacter player = c.getPlayer();
MapleJob job = player.getJob();
int MaxHP = player.getMaxHp();
if (player.getHpMpApUsed() > 9999 || MaxHP >= 30000) {
return MaxHP;
}
if (job.isA(MapleJob.WARRIOR) || job.isA(MapleJob.DAWNWARRIOR1) || job.isA(MapleJob.ARAN1)) {
MaxHP += 20;
} else if (job.isA(MapleJob.MAGICIAN) || job.isA(MapleJob.BLAZEWIZARD1)) {
MaxHP += 6;
} else if (job.isA(MapleJob.BOWMAN) || job.isA(MapleJob.WINDARCHER1) || job.isA(MapleJob.THIEF) || job.isA(MapleJob.NIGHTWALKER1)) {
MaxHP += 16;
} else if (job.isA(MapleJob.PIRATE) || job.isA(MapleJob.THUNDERBREAKER1)) {
MaxHP += 18;
} else {
MaxHP += 8;
}
return MaxHP;
}
static int addMP(MapleClient c) {
MapleCharacter player = c.getPlayer();
int MaxMP = player.getMaxMp();
MapleJob job = player.getJob();
if (player.getHpMpApUsed() > 9999 || player.getMaxMp() >= 30000) {
return MaxMP;
}
if (job.isA(MapleJob.WARRIOR) || job.isA(MapleJob.DAWNWARRIOR1) || job.isA(MapleJob.ARAN1)) {
MaxMP += 2;
} else if (job.isA(MapleJob.MAGICIAN) || job.isA(MapleJob.BLAZEWIZARD1)) {
MaxMP += 18;
} else if (job.isA(MapleJob.BOWMAN) || job.isA(MapleJob.WINDARCHER1) || job.isA(MapleJob.THIEF) || job.isA(MapleJob.NIGHTWALKER1)) {
MaxMP += 10;
} else if (job.isA(MapleJob.PIRATE) || job.isA(MapleJob.THUNDERBREAKER1)) {
MaxMP += 14;
} else {
MaxMP += 6;
}
return MaxMP;
}
static void addHP(MapleCharacter player, int MaxHP) {
MaxHP = Math.min(30000, MaxHP);
player.setHpMpApUsed(player.getHpMpApUsed() + 1);
player.setMaxHp(MaxHP);
player.updateSingleStat(MapleStat.MAXHP, MaxHP);
}
static void addMP(MapleCharacter player, int MaxMP) {
MaxMP = Math.min(30000, MaxMP);
player.setHpMpApUsed(player.getHpMpApUsed() + 1);
player.setMaxMp(MaxMP);
player.updateSingleStat(MapleStat.MAXMP, MaxMP);
}
}