Merge branch 'pr/427'

This commit is contained in:
ronancpl
2019-03-12 21:20:40 -03:00
63 changed files with 4824 additions and 2482 deletions

View File

@@ -237,7 +237,9 @@ public class AbstractPlayerInteraction {
private static List<Integer> convertToIntegerArray(List<Double> list) {
List<Integer> intList = new LinkedList<>();
for(Double d: list) intList.add(d.intValue());
for(Double d: list) {
intList.add(d.intValue());
}
return intList;
}
@@ -346,7 +348,9 @@ public class AbstractPlayerInteraction {
}
public void openNpc(int npcid, String script) {
if(c.getCM() != null) return;
if (c.getCM() != null) {
return;
}
c.removeClickedNPC();
NPCScriptManager.getInstance().dispose(c);
@@ -423,17 +427,23 @@ public class AbstractPlayerInteraction {
MapleQuestStatus status = c.getPlayer().getQuest(MapleQuest.getInstance(qid));
String progress = status.getProgress(status.getAnyProgressKey());
if(progress.isEmpty()) return 0;
if (progress.isEmpty()) {
return 0;
}
return Integer.parseInt(progress);
}
public int getQuestProgress(int qid, int pid) {
if(getPlayer().getQuest(MapleQuest.getInstance(qid)).getProgress(pid).isEmpty()) return 0;
if (getPlayer().getQuest(MapleQuest.getInstance(qid)).getProgress(pid).isEmpty()) {
return 0;
}
return Integer.parseInt(getPlayer().getQuest(MapleQuest.getInstance(qid)).getProgress(pid));
}
public String getStringQuestProgress(int qid, int pid) {
if(getPlayer().getQuest(MapleQuest.getInstance(qid)).getProgress(pid).isEmpty()) return "";
if (getPlayer().getQuest(MapleQuest.getInstance(qid)).getProgress(pid).isEmpty()) {
return "";
}
return getPlayer().getQuest(MapleQuest.getInstance(qid)).getProgress(pid);
}
@@ -548,7 +558,9 @@ public class AbstractPlayerInteraction {
if(item != null) {
Equip it = (Equip)item;
if(ItemConstants.isAccessory(item.getItemId()) && it.getUpgradeSlots() <= 0) it.setUpgradeSlots(3);
if (ItemConstants.isAccessory(item.getItemId()) && it.getUpgradeSlots() <= 0) {
it.setUpgradeSlots(3);
}
if(ServerConstants.USE_ENHANCED_CRAFTING == true && c.getPlayer().getCS() == true) {
Equip eqp = (Equip)item;
@@ -562,8 +574,9 @@ public class AbstractPlayerInteraction {
item = new Item(id, (short) 0, quantity, petId);
}
if(expires >= 0)
item.setExpiration(System.currentTimeMillis() + expires);
if (expires >= 0) {
item.setExpiration(System.currentTimeMillis() + expires);
}
if (!MapleInventoryManipulator.checkSpace(c, id, quantity, "")) {
c.getPlayer().dropMessage(1, "Your inventory is full. Please remove an item from your " + ItemConstants.getInventoryType(id).name() + " inventory.");
@@ -641,8 +654,6 @@ public class AbstractPlayerInteraction {
showIntro(intro);
}
public void showIntro(String path) {
c.announce(MaplePacketCreator.showIntro(path));
}
@@ -680,8 +691,9 @@ public class AbstractPlayerInteraction {
}
public boolean isPartyLeader() {
if(getParty() == null)
if (getParty() == null) {
return false;
}
return getParty().getLeaderId() == getPlayer().getId();
}
@@ -735,7 +747,6 @@ public class AbstractPlayerInteraction {
givePartyExp(PQ, true);
}
public void givePartyExp(String PQ, boolean instance) {
//1 player = +0% bonus (100)
//2 players = +0% bonus (100)
@@ -1093,4 +1104,4 @@ public class AbstractPlayerInteraction {
public long getCurrentTime() {
return System.currentTimeMillis();
}
}
}

View File

@@ -1,24 +1,24 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 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 version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
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 version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
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.
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/>.
*/
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 scripting.event;
import java.util.LinkedHashMap;
@@ -38,8 +38,9 @@ import scripting.AbstractScriptManager;
* @author Matze
*/
public class EventScriptManager extends AbstractScriptManager {
private class EventEntry {
public EventEntry(Invocable iv, EventManager em) {
this.iv = iv;
this.em = em;
@@ -78,10 +79,12 @@ public class EventScriptManager extends AbstractScriptManager {
}
}
}
private void reloadScripts() {
if (events.isEmpty()) return;
if (events.isEmpty()) {
return;
}
Channel cserv = events.values().iterator().next().em.getChannelServer();
for (Entry<String, EventEntry> entry : events.entrySet()) {
String script = entry.getKey();
@@ -89,11 +92,11 @@ public class EventScriptManager extends AbstractScriptManager {
events.put(script, new EventEntry(iv, new EventManager(cserv, iv, script)));
}
}
public void reload() {
cancel();
cancel();
reloadScripts();
init();
init();
}
public void cancel() {
@@ -101,4 +104,4 @@ public class EventScriptManager extends AbstractScriptManager {
entry.em.cancel();
}
}
}
}

View File

@@ -1,22 +1,22 @@
/*
This file is part of the HeavenMS MapleStory Server
Copyleft (L) 2016 - 2018 RonanLana
This file is part of the HeavenMS MapleStory Server
Copyleft (L) 2016 - 2018 RonanLana
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 version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
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 version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
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.
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/>.
*/
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 scripting.event.worker;
import constants.ServerConstants;
@@ -39,63 +39,64 @@ import server.ThreadManager;
* @author Ronan
*/
public class EventScriptScheduler {
private boolean disposed = false;
private int idleProcs = 0;
private Map<Runnable, Long> registeredEntries = new HashMap<>();
private ScheduledFuture<?> schedulerTask = null;
private MonitoredReentrantLock schedulerLock;
private Runnable monitorTask = new Runnable() {
@Override
public void run() {
runBaseSchedule();
}
};
@Override
public void run() {
runBaseSchedule();
}
};
public EventScriptScheduler() {
schedulerLock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.EM_SCHDL, true);
}
private void runBaseSchedule() {
List<Runnable> toRemove;
Map<Runnable, Long> registeredEntriesCopy;
schedulerLock.lock();
try {
if(registeredEntries.isEmpty()) {
if (registeredEntries.isEmpty()) {
idleProcs++;
if(idleProcs >= ServerConstants.MOB_STATUS_MONITOR_LIFE) {
if(schedulerTask != null) {
if (idleProcs >= ServerConstants.MOB_STATUS_MONITOR_LIFE) {
if (schedulerTask != null) {
schedulerTask.cancel(false);
schedulerTask = null;
}
}
return;
}
idleProcs = 0;
registeredEntriesCopy = new HashMap<>(registeredEntries);
} finally {
schedulerLock.unlock();
}
long timeNow = Server.getInstance().getCurrentTime();
toRemove = new LinkedList<>();
for(Entry<Runnable, Long> rmd : registeredEntriesCopy.entrySet()) {
if(rmd.getValue() < timeNow) {
for (Entry<Runnable, Long> rmd : registeredEntriesCopy.entrySet()) {
if (rmd.getValue() < timeNow) {
Runnable r = rmd.getKey();
r.run(); // runs the scheduled action
toRemove.add(r);
}
}
if(!toRemove.isEmpty()) {
if (!toRemove.isEmpty()) {
schedulerLock.lock();
try {
for(Runnable r : toRemove) {
for (Runnable r : toRemove) {
registeredEntries.remove(r);
}
} finally {
@@ -103,17 +104,19 @@ public class EventScriptScheduler {
}
}
}
public void registerEntry(final Runnable scheduledAction, final long duration) {
ThreadManager.getInstance().newTask(new Runnable() {
@Override
public void run() {
schedulerLock.lock();
try {
idleProcs = 0;
if(schedulerTask == null) {
if(disposed) return;
if (schedulerTask == null) {
if (disposed) {
return;
}
schedulerTask = TimerManager.getInstance().register(monitorTask, ServerConstants.MOB_STATUS_MONITOR_PROC, ServerConstants.MOB_STATUS_MONITOR_PROC);
}
@@ -125,9 +128,9 @@ public class EventScriptScheduler {
}
});
}
public void cancelEntry(final Runnable scheduledAction) {
ThreadManager.getInstance().newTask(new Runnable() {
@Override
public void run() {
@@ -140,15 +143,15 @@ public class EventScriptScheduler {
}
});
}
public void dispose() {
ThreadManager.getInstance().newTask(new Runnable() {
@Override
public void run() {
schedulerLock.lock();
try {
if(schedulerTask != null) {
if (schedulerTask != null) {
schedulerTask.cancel(false);
schedulerTask = null;
}
@@ -163,7 +166,7 @@ public class EventScriptScheduler {
}
});
}
private void disposeLocks() {
LockCollector.getInstance().registerDisposeAction(new Runnable() {
@Override
@@ -172,7 +175,7 @@ public class EventScriptScheduler {
}
});
}
private void emptyLocks() {
schedulerLock = schedulerLock.dispose();
}

View File

@@ -0,0 +1,35 @@
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 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 version 3 as published by
the Free Software Foundation. You may not use, modify or distribute
this program under any other version of the GNU Affero General Public
License.
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 scripting.item;
import client.MapleClient;
import scripting.AbstractPlayerInteraction;
/**
*
* @author kevintjuh93
*/
public class ItemScriptMethods extends AbstractPlayerInteraction {
public ItemScriptMethods(MapleClient c) {
super(c);
}
}

View File

@@ -58,28 +58,47 @@ import client.inventory.Item;
import client.inventory.ItemFactory;
import client.inventory.MaplePet;
import constants.ItemConstants;
import java.awt.Point;
import java.util.Arrays;
import constants.LinguaConstants;
import net.server.channel.Channel;
import scripting.event.EventInstanceManager;
import server.MapleSkillbookInformationProvider;
import server.MapleSkillbookInformationProvider.SkillBookEntry;
import server.TimerManager;
import server.maps.MapleMapObject;
import server.maps.MapleMapObjectType;
import server.partyquest.MonsterCarnival;
import tools.FilePrinter;
import tools.packets.Wedding;
import java.awt.Point;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
/**
*
* @author Matze
*/
public class NPCConversationManager extends AbstractPlayerInteraction {
private int npc;
private int npcOid;
private String scriptName;
private String getText;
private boolean itemScript;
private List<MaplePartyCharacter> otherParty;
public NPCConversationManager(MapleClient c, int npc, String scriptName) {
this(c, npc, -1, scriptName, false);
}
public NPCConversationManager(MapleClient c, int npc, List<MaplePartyCharacter> otherParty, boolean test) {
super(c);
this.c = c;
this.npc = npc;
this.otherParty = otherParty;
}
public NPCConversationManager(MapleClient c, int npc, int oid, String scriptName, boolean itemScript) {
super(c);
this.npc = npc;
@@ -549,7 +568,9 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
}
public int getCosmeticItem(int itemid) {
if (itemExists(itemid)) return itemid;
if (itemExists(itemid)) {
return itemid;
}
int baseid;
if (itemid < 30000) {
@@ -594,4 +615,370 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
return sbe != SkillBookEntry.UNAVAILABLE ? " Obtainable through #rquestline#k." : "";
}
}
// By Drago/Dragohe4rt CPQ + WED
public int calcAvgLvl(int map) {
int num = 0;
int avg = 0;
for (MapleMapObject mmo
: c.getChannelServer().getMapFactory().getMap(map).getAllPlayer()) {
avg += ((MapleCharacter) mmo).getLevel();
num++;
}
avg /= num;
return avg;
}
public void sendCPQMapLists() {
String msg = LinguaConstants.Linguas(getPlayer()).CPQInicioEscolha;
for (int i = 0; i < 6; i++) {
if (fieldTaken(i)) {
if (fieldLobbied(i)) {
msg += "#b#L" + i + "#Map " + (i + 1) + " (nível: "
+ calcAvgLvl(980000100 + i * 100) + " / "
+ getPlayerCount(980000100 + i * 100) + "x"
+ getPlayerCount(980000100 + i * 100) + ") #l\\r\\n";
} else {
continue;
}
} else {
if (i == 0 || i == 1 || i == 2 || i == 3) {
msg += "#b#L" + i + "#Map " + (i + 1) + " (2x2) #l\\r\\n";
} else {
msg += "#b#L" + i + "#Map " + (i + 1) + " (3x3) #l\\r\\n";
}
}
}
sendSimple(msg);
}
public boolean fieldTaken(int field) {
if (!c.getChannelServer().getMapFactory().getMap(980000100 + field * 100).getAllPlayer().isEmpty()) {
return true;
}
if (!c.getChannelServer().getMapFactory().getMap(980000101 + field * 100).getAllPlayer().isEmpty()) {
return true;
}
if (!c.getChannelServer().getMapFactory().getMap(980000102 + field * 100).getAllPlayer().isEmpty()) {
return true;
}
return false;
}
public boolean fieldLobbied(int field) {
if (!c.getChannelServer().getMapFactory().getMap(980000100 + field * 100).getAllPlayer().isEmpty()) {
return true;
}
return false;
}
public void cpqLobby(int field) {
try {
final MapleMap map, mapsaida;
Channel cs = c.getChannelServer();
map = cs.getMapFactory().getMap(980000100 + 100 * field);
mapsaida = cs.getMapFactory().getMap(980000000);
for (MaplePartyCharacter mpc : c.getPlayer().getParty().getMembers()) {
final MapleCharacter mc;
mc = cs.getPlayerStorage().getCharacterByName(mpc.getName());
if (mc != null) {
mc.changeMap(map, map.getPortal(0));
mc.getClient().getSession().write(MaplePacketCreator.serverNotice(6, LinguaConstants.Linguas(mc).CPQEntradaLobby));
TimerManager tMan = TimerManager.getInstance();
tMan.schedule(new Runnable() {
@Override
public void run() {
mapClock(3 * 60);
}
}, 1500);
}
mc.timer = TimerManager.getInstance().schedule(new Runnable() {
@Override
public void run() {
mc.changeMap(mapsaida, mapsaida.getPortal(0));
}
}, 3 * 60 * 1000);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
public MapleCharacter getChrById(int id) {
Channel cs = c.getChannelServer();
return cs.getPlayerStorage().getCharacterById(id);
}
public void cancelarSaida() {
Channel cs = c.getChannelServer();
for (MaplePartyCharacter mpc : c.getPlayer().getParty().getMembers()) {
MapleCharacter mc = cs.getPlayerStorage().getCharacterByName(mpc.getName());
if (mc.timer != null) {
mc.timer.cancel(true);
mc.timer = null;
}
}
}
public void startCPQ(final MapleCharacter challenger, final int field) {
try {
cancelarSaida();
if (challenger != null) {
if (challenger.getParty() == null) {
throw new RuntimeException("Nao existe oponente!");
}
for (MaplePartyCharacter mpc : challenger.getParty().getMembers()) {
MapleCharacter mc = c.getChannelServer().getPlayerStorage().getCharacterByName(mpc.getName());
if (mc != null) {
mc.changeMap(getPlayer().getMap(), getPlayer().getMap().getPortal(0));
TimerManager tMan = TimerManager.getInstance();
tMan.schedule(new Runnable() {
@Override
public void run() {
mapClock(10);
}
}, 1500);
}
}
for (MaplePartyCharacter mpc : getPlayer().getParty().getMembers()) {
MapleCharacter mc = c.getChannelServer().getPlayerStorage().getCharacterByName(mpc.getName());
if (mc != null) {
TimerManager tMan = TimerManager.getInstance();
tMan.schedule(new Runnable() {
@Override
public void run() {
mapClock(10);
}
}, 1500);
}
}
}
final int mapid = c.getPlayer().getMapId() + 1;
TimerManager tMan = TimerManager.getInstance();
tMan.schedule(new Runnable() {
@Override
public void run() {
Channel cs = c.getChannelServer();
for (MaplePartyCharacter mpc : getPlayer().getParty().getMembers()) {
MapleCharacter mc = cs.getPlayerStorage().getCharacterByName(mpc.getName());
mc.setMonsterCarnival(null);
}
for (MaplePartyCharacter mpc : challenger.getParty().getMembers()) {
MapleCharacter mc = cs.getPlayerStorage().getCharacterByName(mpc.getName());
mc.setMonsterCarnival(null);
}
new MonsterCarnival(getPlayer().getParty(), challenger.getParty(), mapid, true);
}
}, 11000);
} catch (Exception e) {
e.printStackTrace();
}
}
public void startCPQ2(final MapleCharacter challenger, final int field) {
try {
cancelarSaida();
if (challenger != null) {
if (challenger.getParty() == null) {
throw new RuntimeException("Não existe oponente!");
}
for (MaplePartyCharacter mpc : challenger.getParty().getMembers()) {
MapleCharacter mc = c.getChannelServer().getPlayerStorage().getCharacterByName(mpc.getName());
if (mc != null) {
mc.changeMap(getPlayer().getMap(), getPlayer().getMap().getPortal(0));
mapClock(10);
}
}
}
final int mapid = c.getPlayer().getMapId() + 100;
TimerManager tMan = TimerManager.getInstance();
tMan.schedule(new Runnable() {
@Override
public void run() {
Channel cs = c.getChannelServer();
for (MaplePartyCharacter mpc : getPlayer().getParty().getMembers()) {
MapleCharacter mc = cs.getPlayerStorage().getCharacterByName(mpc.getName());
mc.setMonsterCarnival(null);
}
for (MaplePartyCharacter mpc : challenger.getParty().getMembers()) {
MapleCharacter mc = cs.getPlayerStorage().getCharacterByName(mpc.getName());
mc.setMonsterCarnival(null);
}
new MonsterCarnival(getPlayer().getParty(), challenger.getParty(), mapid, false);
}
}, 10000);
} catch (Exception e) {
e.printStackTrace();
}
}
public void sendCPQMapLists2() {
String msg = LinguaConstants.Linguas(getPlayer()).CPQInicioEscolha;
for (int i = 0; i < 3; i++) {
if (fieldTaken2(i)) {
if (fieldLobbied2(i)) {
msg += "#b#L" + i + "#Map " + (i + 1) + " (Nível: "
+ calcAvgLvl(980031000 + i * 1000) + "#l\\r\\n";
} else {
continue;
}
} else {
if (i == 0 || i == 1) {
msg += "#b#L" + i + "#Map " + (i + 1) + " (2x2) #l\\r\\n";
} else {
msg += "#b#L" + i + "#Map " + (i + 1) + " (3x3) #l\\r\\n";
}
}
}
sendSimple(msg);
}
public boolean fieldTaken2(int field) {
if (!c.getChannelServer().getMapFactory().getMap(980031000 + field * 1000).getAllPlayer().isEmpty()) {
return true;
}
if (!c.getChannelServer().getMapFactory().getMap(980031000 + field * 1000).getAllPlayer().isEmpty()) {
return true;
}
if (!c.getChannelServer().getMapFactory().getMap(980031000 + field * 1000).getAllPlayer().isEmpty()) {
return true;
}
return false;
}
public boolean fieldLobbied2(int field) {
if (!c.getChannelServer().getMapFactory().getMap(980031000 + field * 1000).getAllPlayer().isEmpty()) {
return true;
}
return false;
}
public void cpqLobby2(int field) {
try {
final MapleMap map, mapsaida;
Channel cs = c.getChannelServer();
mapsaida = cs.getMapFactory().getMap(980030000);
map = cs.getMapFactory().getMap(980031000 + 1000 * field);
for (MaplePartyCharacter mpc : c.getPlayer().getParty().getMembers()) {
final MapleCharacter mc;
mc = cs.getPlayerStorage().getCharacterByName(mpc.getName());
if (mc != null) {
mc.changeMap(map, map.getPortal(0));
mc.getClient().getSession().write(MaplePacketCreator.serverNotice(6, LinguaConstants.Linguas(mc).CPQEntradaLobby));
TimerManager tMan = TimerManager.getInstance();
tMan.schedule(new Runnable() {
@Override
public void run() {
mapClock(3 * 60);
}
}, 1500);
}
mc.timer = TimerManager.getInstance().schedule(new Runnable() {
@Override
public void run() {
mc.changeMap(mapsaida, mapsaida.getPortal(0));
}
}, 3 * 60 * 1000);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void challengeParty2(int field) {
MapleCharacter leader = null;
MapleMap map = c.getChannelServer().getMapFactory().getMap(980031000 + 1000 * field);
for (MapleMapObject mmo : map.getAllPlayer()) {
MapleCharacter mc = (MapleCharacter) mmo;
if (mc.getParty() == null) {
sendOk(LinguaConstants.Linguas(mc).CPQEscolha);
return;
}
if (mc.getParty().getLeader().getId() == mc.getId()) {
leader = mc;
break;
}
}
if (leader != null) {
if (!leader.isChallenged()) {
List<MaplePartyCharacter> members = new LinkedList<>();
for (MaplePartyCharacter fucker : c.getPlayer().getParty().getMembers()) {
members.add(fucker);
}
NPCScriptManager.getInstance().start("cpqchallenge2", leader.getClient(), npc, members);
} else {
sendOk(LinguaConstants.Linguas(leader).CPQInicioEscolhaEmEscolha);
}
} else {
sendOk(LinguaConstants.Linguas(leader).CPQLiderNaoEncontrado);
}
}
public void mapClock(int time) {
//getPlayer().getMap().broadcastMessage(MaplePacketCreator.serverNotice(type, message));
getPlayer().getMap().broadcastMessage(MaplePacketCreator.getClock(time));
}
public void challengeParty(int field) {
MapleCharacter leader = null;
MapleMap map = c.getChannelServer().getMapFactory().getMap(980000100 + 100 * field);
if (map.getAllPlayer().size() != getPlayer().getParty().getMembers().size()) {
sendOk("erro");
return;
}
for (MapleMapObject mmo : map.getAllPlayer()) {
MapleCharacter mc = (MapleCharacter) mmo;
if (mc.getParty() == null) {
sendOk(LinguaConstants.Linguas(mc).CPQEscolha);
return;
}
if (mc.getParty().getLeader().getId() == mc.getId()) {
leader = mc;
break;
}
}
if (leader != null) {
if (!leader.isChallenged()) {
List<MaplePartyCharacter> members = new LinkedList<>();
for (MaplePartyCharacter fucker : c.getPlayer().getParty().getMembers()) {
members.add(fucker);
}
NPCScriptManager.getInstance().start("cpqchallenge", leader.getClient(), npc, members);
} else {
sendOk(LinguaConstants.Linguas(leader).CPQInicioEscolhaEmEscolha);
}
} else {
sendOk(LinguaConstants.Linguas(leader).CPQLiderNaoEncontrado);
}
}
public MapleCharacter getCharByName(String namee) {
try {
return getClient().getChannelServer().getPlayerStorage().getCharacterByName(namee);
} catch (Exception e) {
return null;
}
}
public void enviarLista() {
EventInstanceManager eim = getEventInstance();
if(eim != null) {
String name = eim.getProperty("brideId");
MapleCharacter chr = getChrById(Integer.parseInt(name));
//MapleCharacter chr = getChrById(3);
if (chr != null) {
if (chr.getId() == getPlayer().getId()) {
getPlayer().announce(Wedding.OnWeddingGiftResult((byte) 0xA, chr.getItens(), chr.getItem()));
} else {
getPlayer().announce(Wedding.OnWeddingGiftResult((byte) 0x09, chr.getItens(), chr.getItem()));
}
}
}
}
public void criarLista() {
getClient().getSession().write(Wedding.sendWishList());
}
}

View File

@@ -26,10 +26,12 @@ import client.MapleClient;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.script.Invocable;
import javax.script.ScriptException;
import net.server.world.MaplePartyCharacter;
import scripting.AbstractScriptManager;
import server.MapleItemInformationProvider.ScriptedItem;
@@ -43,43 +45,86 @@ import tools.MaplePacketCreator;
public class NPCScriptManager extends AbstractScriptManager {
private static NPCScriptManager instance = new NPCScriptManager();
public static NPCScriptManager getInstance() {
return instance;
}
private Map<MapleClient, NPCConversationManager> cms = new HashMap<>();
private Map<MapleClient, Invocable> scripts = new HashMap<>();
public boolean isNpcScriptAvailable(MapleClient c, String fileName) {
Invocable iv = null;
if (fileName != null) {
iv = getInvocable("npc/" + fileName + ".js", c);
}
return iv != null;
}
public boolean start(MapleClient c, int npc, MapleCharacter chr) {
return start(c, npc, -1, chr);
}
public boolean start(MapleClient c, int npc, int oid, MapleCharacter chr) {
return start(c, npc, oid, null, chr);
}
public boolean start(MapleClient c, int npc, String fileName, MapleCharacter chr) {
return start(c, npc, -1, fileName, chr);
}
public boolean start(MapleClient c, int npc, int oid, String fileName, MapleCharacter chr) {
return start(c, npc, oid, fileName, chr, false, "cm");
}
public boolean start(MapleClient c, ScriptedItem scriptItem, MapleCharacter chr) {
return start(c, scriptItem.getNpc(), -1, scriptItem.getScript(), chr, true, "im");
}
public void start(String filename, MapleClient c, int npc, List<MaplePartyCharacter> chrs) {
try {
NPCConversationManager cm = new NPCConversationManager(c, npc, chrs, true);
cm.dispose();
if (cms.containsKey(c)) {
return;
}
cms.put(c, cm);
Invocable iv = null;
iv = getInvocable("npc/" + filename + ".js", c);
NPCScriptManager npcsm = NPCScriptManager.getInstance();
if (iv == null || NPCScriptManager.getInstance() == null) {
c.getPlayer().dropMessage(1, npc + "");
cm.dispose();
return;
}
if (iv == null || npcsm == null) {
c.getPlayer().dropMessage(1, npc + "");
cm.dispose();
return;
}
engine.put("cm", cm);
scripts.put(c, iv);
try {
iv.invokeFunction("start", chrs);
} catch (final NoSuchMethodException nsme) {
try {
iv.invokeFunction("start", chrs);
} catch (final NoSuchMethodException nsma) {
nsma.printStackTrace();
}
}
} catch (final UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.NPC + npc + ".txt", ute);
dispose(c);
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.NPC + npc + ".txt", e);
dispose(c);
}
}
private boolean start(MapleClient c, int npc, int oid, String fileName, MapleCharacter chr, boolean itemScript, String engineName) {
try {
NPCConversationManager cm = new NPCConversationManager(c, npc, oid, fileName, itemScript);
@@ -121,17 +166,17 @@ public class NPCScriptManager extends AbstractScriptManager {
} else {
c.announce(MaplePacketCreator.enableActions());
}
return true;
} catch (final UndeclaredThrowableException | ScriptException ute) {
FilePrinter.printError(FilePrinter.NPC + npc + ".txt", ute);
dispose(c);
return false;
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.NPC + npc + ".txt", e);
dispose(c);
return false;
}
}
@@ -157,9 +202,9 @@ public class NPCScriptManager extends AbstractScriptManager {
c.getPlayer().setNpcCooldown(System.currentTimeMillis());
cms.remove(c);
scripts.remove(c);
String scriptFolder = (cm.isItemScript() ? "item" : "npc");
if(cm.getScriptName() != null) {
if (cm.getScriptName() != null) {
resetContext(scriptFolder + "/" + cm.getScriptName() + ".js", c);
} else {
resetContext(scriptFolder + "/" + cm.getNpc() + ".js", c);

View File

@@ -47,6 +47,8 @@ import server.maps.MapMonitor;
import server.maps.MapleMap;
import server.maps.MapleReactor;
import server.maps.ReactorDropEntry;
import server.partyquest.MapleCarnivalFactory;
import server.partyquest.MapleCarnivalFactory.MCSkill;
import tools.MaplePacketCreator;
/**
@@ -311,4 +313,20 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
}
}, timestamp);
}
public void dispelAllMonsters(int num, int team) { //dispels all mobs, cpq
final MCSkill skil = MapleCarnivalFactory.getInstance().getGuardian(num);
if (skil != null) {
for (MapleMonster mons : getMap().getMonsters()) {
if(mons.getTeam() == team) {
mons.dispelSkill(skil.getSkill());
}
}
}
if (team == 0) {
getPlayer().getMap().getRedTeamBuffs().remove(skil);
} else {
getPlayer().getMap().getBlueTeamBuffs().remove(skil);
}
}
}