use of server.quest.MapleQuest in project HeavenMS by ronancpl.
the class MapleClient method disconnect.
public final synchronized void disconnect(boolean shutdown, boolean cashshop) {
// once per MapleClient instance
if (disconnecting) {
return;
}
disconnecting = true;
if (player != null && player.isLoggedin() && player.getClient() != null) {
MapleMap map = player.getMap();
final MapleParty party = player.getParty();
final int idz = player.getId();
final int messengerid = player.getMessenger() == null ? 0 : player.getMessenger().getId();
// final int fid = player.getFamilyId();
final BuddyList bl = player.getBuddylist();
final MaplePartyCharacter chrp = new MaplePartyCharacter(player);
final MapleMessengerCharacter chrm = new MapleMessengerCharacter(player, 0);
final MapleGuildCharacter chrg = player.getMGC();
final MapleGuild guild = player.getGuild();
player.cancelMagicDoor();
if (channel == -1 || shutdown) {
if (chrg != null)
chrg.setCharacter(null);
removePlayer();
player.saveCooldowns();
player.saveToDB(true);
player = null;
return;
}
removePlayer();
final World worlda = getWorldServer();
try {
if (!cashshop) {
if (!this.serverTransition) {
// meaning not changing channels
if (messengerid > 0) {
worlda.leaveMessenger(messengerid, chrm);
}
/*
if (fid > 0) {
final MapleFamily family = worlda.getFamily(fid);
family.
}
*/
for (MapleQuestStatus status : player.getStartedQuests()) {
// This is for those quests that you have to stay logged in for a certain amount of time
MapleQuest quest = status.getQuest();
if (quest.getTimeLimit() > 0) {
MapleQuestStatus newStatus = new MapleQuestStatus(quest, MapleQuestStatus.Status.NOT_STARTED);
newStatus.setForfeited(player.getQuest(quest).getForfeited() + 1);
player.updateQuest(newStatus);
}
}
if (guild != null) {
final Server server = Server.getInstance();
server.setGuildMemberOnline(player, false, player.getClient().getChannel());
player.getClient().announce(MaplePacketCreator.showGuildInfo(player));
}
if (party != null) {
chrp.setOnline(false);
worlda.updateParty(party.getId(), PartyOperation.LOG_ONOFF, chrp);
if (map != null && party.getLeader().getId() == idz) {
MaplePartyCharacter lchr = null;
for (MaplePartyCharacter pchr : party.getMembers()) {
if (pchr != null && map.getCharacterById(pchr.getId()) != null && (lchr == null || lchr.getLevel() <= pchr.getLevel())) {
lchr = pchr;
}
}
if (lchr != null) {
worlda.updateParty(party.getId(), PartyOperation.CHANGE_LEADER, lchr);
}
}
}
if (bl != null) {
worlda.loggedOff(player.getName(), player.getId(), channel, player.getBuddylist().getBuddyIds());
}
}
} else {
if (!this.serverTransition) {
// if dc inside of cash shop.
if (party != null) {
chrp.setOnline(false);
worlda.updateParty(party.getId(), PartyOperation.LOG_ONOFF, chrp);
if (map != null && party.getLeader().getId() == idz) {
MaplePartyCharacter lchr = null;
for (MaplePartyCharacter pchr : party.getMembers()) {
if (pchr != null && map.getCharacterById(pchr.getId()) != null && (lchr == null || lchr.getLevel() <= pchr.getLevel())) {
lchr = pchr;
}
}
if (lchr != null) {
worlda.updateParty(party.getId(), PartyOperation.CHANGE_LEADER, lchr);
}
}
}
if (bl != null) {
worlda.loggedOff(player.getName(), player.getId(), channel, player.getBuddylist().getBuddyIds());
}
}
}
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.ACCOUNT_STUCK, e);
} finally {
getChannelServer().removePlayer(player);
if (!this.serverTransition) {
worlda.removePlayer(player);
player.saveCooldowns();
player.saveToDB(true);
if (player != null) {
// no idea, occur :(
player.empty(false);
}
player.logOff();
} else {
player.saveCooldowns();
player.saveToDB();
}
player = null;
}
}
if (!serverTransition && isLoggedIn()) {
updateLoginState(MapleClient.LOGIN_NOTLOGGEDIN);
// prevents double dcing during login
session.removeAttribute(MapleClient.CLIENT_KEY);
session.close(false);
}
engines.clear();
}
use of server.quest.MapleQuest in project HeavenMS by ronancpl.
the class MapleCharacter method runQuestExpireTask.
private void runQuestExpireTask() {
petLock.lock();
try {
long timeNow = System.currentTimeMillis();
List<MapleQuest> expireList = new LinkedList<>();
for (Entry<MapleQuest, Long> qe : questExpirations.entrySet()) {
if (qe.getValue() <= timeNow)
expireList.add(qe.getKey());
}
if (!expireList.isEmpty()) {
for (MapleQuest quest : expireList) {
expireQuest(quest);
questExpirations.remove(quest);
}
if (questExpirations.isEmpty()) {
questExpireTask.cancel(false);
questExpireTask = null;
}
}
} finally {
petLock.unlock();
}
}
use of server.quest.MapleQuest in project HeavenMS by ronancpl.
the class MapScriptMethods method touchTheSky.
public void touchTheSky() {
// 29004
MapleQuest quest = MapleQuest.getInstance(29004);
if (!isQuestStarted(29004)) {
if (!quest.forceStart(getPlayer(), 9000066)) {
return;
}
}
MapleQuestStatus q = getPlayer().getQuest(quest);
if (!q.addMedalMap(getPlayer().getMapId())) {
return;
}
String status = Integer.toString(q.getMedalProgress());
getPlayer().announce(MaplePacketCreator.updateQuest(q, true));
getPlayer().announce(MaplePacketCreator.earnTitleMessage(status + "/5 Completed"));
getPlayer().announce(MaplePacketCreator.earnTitleMessage("The One Who's Touched the Sky title in progress."));
if (Integer.toString(q.getMedalProgress()).equals(quest.getInfoEx())) {
showInfoText("The One Who's Touched the Sky" + rewardstring);
getPlayer().announce(MaplePacketCreator.getShowQuestCompletion(quest.getId()));
} else {
showInfoText("The One Who's Touched the Sky title in progress. " + status + "/5 Completed");
}
}
use of server.quest.MapleQuest in project HeavenMS by ronancpl.
the class QuestScriptManager method end.
public void end(MapleClient c, short questid, int npc) {
MapleQuest quest = MapleQuest.getInstance(questid);
if (!c.getPlayer().getQuest(quest).getStatus().equals(MapleQuestStatus.Status.STARTED) || !c.getPlayer().getMap().containsNPC(npc)) {
dispose(c);
return;
}
try {
QuestActionManager qm = new QuestActionManager(c, questid, npc, false);
if (qms.containsKey(c)) {
return;
}
if (c.canClickNPC()) {
qms.put(c, qm);
Invocable iv = getInvocable("quest/" + questid + ".js", c);
if (iv == null) {
qm.dispose();
return;
}
engine.put("qm", qm);
scripts.put(c, iv);
c.setClickedNPC();
iv.invokeFunction("end", (byte) 1, (byte) 0, 0);
}
} catch (final UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.QUEST + questid + ".txt", ute);
dispose(c);
} catch (final Throwable t) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", t);
dispose(c);
}
}
use of server.quest.MapleQuest in project HeavenMS by ronancpl.
the class QuestScriptManager method start.
public void start(MapleClient c, short questid, int npc) {
MapleQuest quest = MapleQuest.getInstance(questid);
if (!c.getPlayer().getQuest(quest).getStatus().equals(MapleQuestStatus.Status.NOT_STARTED)) {
dispose(c);
return;
}
try {
QuestActionManager qm = new QuestActionManager(c, questid, npc, true);
if (qms.containsKey(c)) {
return;
}
if (c.canClickNPC()) {
qms.put(c, qm);
Invocable iv = getInvocable("quest/" + questid + ".js", c);
if (iv == null) {
FilePrinter.printError(FilePrinter.QUEST_UNCODED, "Quest " + questid + " is uncoded.\r\n");
}
if (iv == null || QuestScriptManager.getInstance() == null) {
qm.dispose();
return;
}
engine.put("qm", qm);
scripts.put(c, iv);
c.setClickedNPC();
iv.invokeFunction("start", (byte) 1, (byte) 0, 0);
}
} catch (final UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.QUEST + questid + ".txt", ute);
dispose(c);
} catch (final Throwable t) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", t);
dispose(c);
}
}
Aggregations