📄 maplecharacter.java
字号:
updatePartyMemberHP();
}
}
}
});
getClient().getSession().write(warpPacket);
}
public void changeJob(MapleJob newJob) {
this.job = newJob;
this.remainingSp++;
updateSingleStat(MapleStat.AVAILABLESP, this.remainingSp);
updateSingleStat(MapleStat.JOB, newJob.getId());
getMap().broadcastMessage(this, MaplePacketCreator.showJobChange(getId()), false);
silentPartyUpdate();
}
public void gainAp(int ap) {
this.remainingAp += ap;
updateSingleStat(MapleStat.AVAILABLEAP, this.remainingAp);
}
public void changeSkillLevel(ISkill skill, int newLevel, int newMasterlevel) {
skills.put(skill, new SkillEntry(newLevel, newMasterlevel));
this.getClient().getSession().write(MaplePacketCreator.updateSkill(skill.getId(), newLevel, newMasterlevel));
}
public void setHp(int newhp) {
setHp(newhp, false);
}
private void setHp(int newhp, boolean silent) {
int oldHp = hp;
int thp = newhp;
if (thp < 0) {
thp = 0;
}
if (thp > localmaxhp) {
thp = localmaxhp;
}
this.hp = thp;
if (!silent) {
updatePartyMemberHP();
}
if (oldHp > hp && !isAlive()) {
playerDead();
}
}
private void playerDead() {
if (getEventInstance() != null) {
getEventInstance().playerKilled(this);
}
cancelAllBuffs();
getClient().getSession().write(MaplePacketCreator.enableActions());
}
public void updatePartyMemberHP() {
if (party != null) {
int channel = client.getChannel();
for (MaplePartyCharacter partychar : party.getMembers()) {
if (partychar.getMapid() == getMapId() && partychar.getChannel() == channel) {
MapleCharacter other = ChannelServer.getInstance(channel).getPlayerStorage().getCharacterByName(partychar.getName());
if (other != null) {
other.getClient().getSession().write(
MaplePacketCreator.updatePartyMemberHP(getId(), this.hp, localmaxhp));
}
}
}
}
}
public void receivePartyMemberHP() {
if (party != null) {
int channel = client.getChannel();
for (MaplePartyCharacter partychar : party.getMembers()) {
if (partychar.getMapid() == getMapId() && partychar.getChannel() == channel) {
MapleCharacter other = ChannelServer.getInstance(channel).getPlayerStorage().getCharacterByName(partychar.getName());
if (other != null) {
getClient().getSession().write(
MaplePacketCreator.updatePartyMemberHP(other.getId(), other.getHp(), other.getCurrentMaxHp()));
}
}
}
}
}
public void setMp(int newmp) {
int tmp = newmp;
if (tmp < 0) {
tmp = 0;
}
if (tmp > localmaxmp) {
tmp = localmaxmp;
}
this.mp = tmp;
}
/**
* Convenience function which adds the supplied parameter to the current hp then directly does a updateSingleStat.
*
* @see MapleCharacter#setHp(int)
* @param delta
*/
public void addHP(int delta) {
setHp(hp + delta);
updateSingleStat(MapleStat.HP, hp);
}
/**
* Convenience function which adds the supplied parameter to the current mp then directly does a updateSingleStat.
*
* @see MapleCharacter#setMp(int)
* @param delta
*/
public void addMP(int delta) {
setMp(mp + delta);
updateSingleStat(MapleStat.MP, mp);
}
/**
* Updates a single stat of this MapleCharacter for the client. This method only creates and sends an update packet,
* it does not update the stat stored in this MapleCharacter instance.
*
* @param stat
* @param newval
* @param itemReaction
*/
public void updateSingleStat(MapleStat stat, int newval, boolean itemReaction) {
Pair<MapleStat, Integer> statpair = new Pair<MapleStat, Integer>(stat, Integer.valueOf(newval));
MaplePacket updatePacket = MaplePacketCreator.updatePlayerStats(Collections.singletonList(statpair),
itemReaction);
client.getSession().write(updatePacket);
}
public void updateSingleStat(MapleStat stat, int newval) {
updateSingleStat(stat, newval, false);
}
public void updateStatsEmpty() {
client.getSession().write(MaplePacketCreator.updatePlayerStats(MaplePacketCreator.EMPTY_STATUPDATE, true));
}
public void gainExp(int gain, boolean show, boolean inChat, boolean white) {
if (getLevel() < 200) { // lv200 is max and has 0 exp required to level
int newexp = this.exp.addAndGet(gain);
updateSingleStat(MapleStat.EXP, newexp);
}
if (show) { // still show the expgain even if it's not there
client.getSession().write(MaplePacketCreator.getShowExpGain(gain, inChat, white));
}
while (level < 200 && exp.get() >= ExpTable.getExpNeededForLevel(level + 1)) {
levelUp();
}
}
public void silentPartyUpdate() {
if (party != null) {
try {
getClient().getChannelServer().getWorldInterface().updateParty(party.getId(),
PartyOperation.SILENT_UPDATE, new MaplePartyCharacter(MapleCharacter.this));
} catch (RemoteException e) {
getClient().getChannelServer().reconnectWorld();
}
}
}
public void gainExp(int gain, boolean show, boolean inChat) {
gainExp(gain, show, inChat, true);
}
public boolean isGM() {
return gm;
}
public MapleInventory getInventory(MapleInventoryType type) {
return inventory[type.ordinal()];
}
public MapleShop getShop() {
return shop;
}
public void setShop(MapleShop shop) {
this.shop = shop;
}
public int getMeso() {
return meso.get();
}
public int getSavedLocation(SavedLocationType type) {
return savedLocations[type.ordinal()];
}
public void saveLocation(SavedLocationType type) {
savedLocations[type.ordinal()] = getMapId();
}
public void clearSavedLocation(SavedLocationType type) {
savedLocations[type.ordinal()] = -1;
}
public void gainMeso(int gain, boolean show) {
gainMeso(gain, show, false, false);
}
public void gainMeso(int gain, boolean show, boolean itemReaction) {
gainMeso(gain, show, itemReaction, false);
}
public void gainMeso(int gain, boolean show, boolean itemReaction, boolean inChat) {
if (meso.get() + gain < 0) {
return;
}
int newVal = meso.addAndGet(gain);
updateSingleStat(MapleStat.MESO, newVal, itemReaction);
if (show)
client.getSession().write(MaplePacketCreator.getShowMesoGain(gain, inChat));
}
/**
* Adds this monster to the controlled list. The monster must exist on the Map.
*
* @param monster
*/
public void controlMonster(MapleMonster monster, boolean aggro) {
monster.setController(this);
controlled.add(monster);
client.getSession().write(MaplePacketCreator.controlMonster(monster, false, aggro));
}
public void stopControllingMonster(MapleMonster monster) {
controlled.remove(monster);
}
public Collection<MapleMonster> getControlledMonsters() {
return Collections.unmodifiableCollection(controlled);
}
public int getNumControlledMonsters() {
return controlled.size();
}
@Override
public String toString() {
return "Character: " + this.name;
}
public int getAccountID() {
return accountid;
}
public void mobKilled(int id) {
for (MapleQuestStatus q : quests.values()) {
if (q.getStatus() == MapleQuestStatus.Status.COMPLETED || q.getQuest().canComplete(this, null))
continue;
if (q.mobKilled(id) && !(q.getQuest() instanceof MapleCustomQuest)) {
client.getSession().write(MaplePacketCreator.updateQuestMobKills(q));
if (q.getQuest().canComplete(this, null)) {
client.getSession().write(MaplePacketCreator.getShowQuestCompletion(q.getQuest().getId()));
}
}
}
}
public final List<MapleQuestStatus> getStartedQuests() {
List<MapleQuestStatus> ret = new LinkedList<MapleQuestStatus>();
for (MapleQuestStatus q : quests.values()) {
if (q.getStatus().equals(MapleQuestStatus.Status.STARTED) && !(q.getQuest() instanceof MapleCustomQuest))
ret.add(q);
}
return Collections.unmodifiableList(ret);
}
public final List<MapleQuestStatus> getCompletedQuests() {
List<MapleQuestStatus> ret = new LinkedList<MapleQuestStatus>();
for (MapleQuestStatus q : quests.values()) {
if (q.getStatus().equals(MapleQuestStatus.Status.COMPLETED) && !(q.getQuest() instanceof MapleCustomQuest))
ret.add(q);
}
return Collections.unmodifiableList(ret);
}
public MaplePlayerShop getPlayerShop() {
return playerShop;
}
public void setPlayerShop(MaplePlayerShop playerShop) {
this.playerShop = playerShop;
}
public Map<ISkill, SkillEntry> getSkills() {
return Collections.unmodifiableMap(skills);
}
public int getSkillLevel(ISkill skill) {
SkillEntry ret = skills.get(skill);
if (ret == null) {
return 0;
}
return ret.skillevel;
}
public int getMasterLevel(ISkill skill) {
SkillEntry ret = skills.get(skill);
if (ret == null) {
return 0;
}
return ret.masterlevel;
}
// the equipped inventory only contains equip... I hope
public int getTotalDex() {
return localdex;
}
public int getTotalInt() {
return localint_;
}
public int getTotalStr() {
return localstr;
}
public int getTotalLuk() {
return localluk;
}
public int getTotalMagic() {
return magic;
}
public double getSpeedMod() {
return speedMod;
}
public double getJumpMod() {
return jumpMod;
}
public int getTotalWatk() {
return watk;
}
private static int rand(int lbound, int ubound) {
return (int) ((Math.random() * (ubound - lbound + 1)) + lbound);
}
public void levelUp() {
ISkill improvingMaxHP = SkillFactory.getSkill(1000001);
ISkill improvingMaxMP = SkillFactory.getSkill(2000001);
int improvingMaxHPLevel = getSkillLevel(improvingMaxHP);
int improvingMaxMPLevel = getSkillLevel(improvingMaxMP);
remainingAp += 5;
if (job == MapleJob.BEGINNER) {
// info from the odin what's working thread, thanks
maxhp += rand(14, 16);
maxmp += rand(10, 12);
} else if (job.isA(MapleJob.BOWMAN) || job.isA(MapleJob.THIEF) || job.isA(MapleJob.GM)) {
// info from bowman forum at sleepywood, thanks guys
maxhp += rand(20, 24);
maxmp += rand(14, 16);
} else if (job.isA(MapleJob.MAGICIAN)) {
// made up
maxhp += rand(10, 14);
maxmp += rand(20, 24);
} else if (job.isA(MapleJob.WARRIOR)) {
// made up
maxhp += rand(22, 26);
maxmp += rand(4, 7);
}
if (improvingMaxHPLevel > 0) {
maxhp += improvingMaxHP.getEffect(improvingMaxHPLevel).getX();
}
if (improvingMaxMPLevel > 0) {
maxmp += improvingMaxMP.getEffect(improvingMaxMPLevel).getX();
}
maxmp += getTotalInt() / 10;
exp.addAndGet(-ExpTable.getExpNeededForLevel(level + 1));
if (level == 200) {
exp.set(0);
}
maxhp = Math.min(30000, maxhp);
maxmp = Math.min(30000, maxmp);
level += 1;
List<Pair<MapleStat, Integer>> statup = new ArrayList<Pair<MapleStat, Integer>>(8);
statup.add(new Pair<MapleStat, Integer>(MapleStat.AVAILABLEAP, Integer.valueOf(remainingAp)));
statup.add(new Pair<MapleStat, Integer>(MapleStat.MAXHP, Integer.valueOf(maxhp)));
statup.add(new Pair<MapleStat, Integer>(MapleStat.MAXMP, Integer.valueOf(maxmp)));
statup.add(new Pair<MapleStat, Integer>(MapleStat.HP, Integer.valueOf(maxhp)));
statup.add(new Pair<MapleStat, Integer>(MapleStat.MP, Integer.valueOf(maxmp)));
statup.add(new Pair<MapleStat, Integer>(MapleStat.EXP, Integer.valueOf(exp.get())));
statup.add(new Pair<MapleStat, Integer>(MapleStat.LEVEL, Integer.valueOf(level)));
if (job != MapleJob.BEGINNER) {
remainingSp += 3;
statup.add(new Pair<MapleStat, Integer>(MapleStat.AVAILABLESP, Integer.valueOf(remainingSp)));
}
setHp(maxhp);
setMp(maxmp);
getClient().getSession().write(MaplePacketCreator.updatePlayerStats(statup));
getMap().broadcastMessage(this, MaplePacketCreator.showLevelup(getId()), false);
recalcLocalStats();
silentPartyUpdate();
}
public void changeKeybinding(int key, MapleKeyBinding keybinding) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -