Simplify NPC script start
This commit is contained in:
@@ -36,9 +36,9 @@ public class ClickGuideHandler extends AbstractPacketHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void handlePacket(InPacket p, Client c) {
|
public void handlePacket(InPacket p, Client c) {
|
||||||
if (c.getPlayer().getJob().equals(Job.NOBLESSE)) {
|
if (c.getPlayer().getJob().equals(Job.NOBLESSE)) {
|
||||||
NPCScriptManager.getInstance().start(c, NpcId.MIMO, null);
|
NPCScriptManager.getInstance().start(c, NpcId.MIMO);
|
||||||
} else {
|
} else {
|
||||||
NPCScriptManager.getInstance().start(c, NpcId.LILIN, null);
|
NPCScriptManager.getInstance().start(c, NpcId.LILIN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,11 +73,11 @@ public final class NPCTalkHandler extends AbstractPacketHandler {
|
|||||||
|
|
||||||
// Custom handling to reduce the amount of scripts needed.
|
// Custom handling to reduce the amount of scripts needed.
|
||||||
if (npc.getId() >= NpcId.GACHAPON_MIN && npc.getId() <= NpcId.GACHAPON_MAX) {
|
if (npc.getId() >= NpcId.GACHAPON_MIN && npc.getId() <= NpcId.GACHAPON_MAX) {
|
||||||
NPCScriptManager.getInstance().start(c, npc.getId(), "gachapon", null);
|
NPCScriptManager.getInstance().start(c, npc.getId(), "gachapon");
|
||||||
} else if (npc.getName().endsWith("Maple TV")) {
|
} else if (npc.getName().endsWith("Maple TV")) {
|
||||||
NPCScriptManager.getInstance().start(c, npc.getId(), "mapleTV", null);
|
NPCScriptManager.getInstance().start(c, npc.getId(), "mapleTV");
|
||||||
} else if (YamlConfig.config.server.USE_REBIRTH_SYSTEM && npc.getId() == YamlConfig.config.server.REBIRTH_NPC_ID) {
|
} else if (YamlConfig.config.server.USE_REBIRTH_SYSTEM && npc.getId() == YamlConfig.config.server.REBIRTH_NPC_ID) {
|
||||||
NPCScriptManager.getInstance().start(c, npc.getId(), "rebirth", null);
|
NPCScriptManager.getInstance().start(c, npc.getId(), "rebirth");
|
||||||
} else {
|
} else {
|
||||||
boolean hasNpcScript = NPCScriptManager.getInstance().start(c, npc.getId(), oid, null);
|
boolean hasNpcScript = NPCScriptManager.getInstance().start(c, npc.getId(), oid, null);
|
||||||
if (!hasNpcScript) {
|
if (!hasNpcScript) {
|
||||||
@@ -97,9 +97,9 @@ public final class NPCTalkHandler extends AbstractPacketHandler {
|
|||||||
NPCScriptManager nsm = NPCScriptManager.getInstance();
|
NPCScriptManager nsm = NPCScriptManager.getInstance();
|
||||||
|
|
||||||
if (pnpc.getScriptId() < NpcId.CUSTOM_DEV && !nsm.isNpcScriptAvailable(c, "" + pnpc.getScriptId())) {
|
if (pnpc.getScriptId() < NpcId.CUSTOM_DEV && !nsm.isNpcScriptAvailable(c, "" + pnpc.getScriptId())) {
|
||||||
nsm.start(c, pnpc.getScriptId(), "rank_user", null);
|
nsm.start(c, pnpc.getScriptId(), "rank_user");
|
||||||
} else {
|
} else {
|
||||||
nsm.start(c, pnpc.getScriptId(), null);
|
nsm.start(c, pnpc.getScriptId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,6 @@ public final class RemoteGachaponHandler extends AbstractPacketHandler {
|
|||||||
} else {
|
} else {
|
||||||
npcId = gacha == 8 ? NpcId.GACHAPON_NLC : NpcId.GACHAPON_NAUTILUS;
|
npcId = gacha == 8 ? NpcId.GACHAPON_NLC : NpcId.GACHAPON_NAUTILUS;
|
||||||
}
|
}
|
||||||
NPCScriptManager.getInstance().start(c, npcId, "gachaponRemote", null);
|
NPCScriptManager.getInstance().start(c, npcId, "gachaponRemote");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,9 +77,9 @@ public class MatchCheckerCPQChallenge implements MatchCheckerListenerRecipe {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (message.contentEquals("cpq1")) {
|
if (message.contentEquals("cpq1")) {
|
||||||
NPCScriptManager.getInstance().start("cpqchallenge", ldr.getClient(), npcid, chrMembers);
|
NPCScriptManager.getInstance().startCpqScript("cpqchallenge", ldr.getClient(), npcid, chrMembers);
|
||||||
} else {
|
} else {
|
||||||
NPCScriptManager.getInstance().start("cpqchallenge2", ldr.getClient(), npcid, chrMembers);
|
NPCScriptManager.getInstance().startCpqScript("cpqchallenge2", ldr.getClient(), npcid, chrMembers);
|
||||||
}
|
}
|
||||||
|
|
||||||
cm.sendOk(LanguageConstants.getMessage(chr, LanguageConstants.CPQChallengeRoomSent));
|
cm.sendOk(LanguageConstants.getMessage(chr, LanguageConstants.CPQChallengeRoomSent));
|
||||||
|
|||||||
@@ -352,7 +352,7 @@ public class AbstractPlayerInteraction {
|
|||||||
|
|
||||||
c.removeClickedNPC();
|
c.removeClickedNPC();
|
||||||
NPCScriptManager.getInstance().dispose(c);
|
NPCScriptManager.getInstance().dispose(c);
|
||||||
NPCScriptManager.getInstance().start(c, npcid, script, null);
|
NPCScriptManager.getInstance().start(c, npcid, script);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getQuestStatus(int id) {
|
public int getQuestStatus(int id) {
|
||||||
|
|||||||
@@ -34,6 +34,6 @@ public class ItemScriptManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void runItemScript(Client c, ScriptedItem scriptItem) {
|
public void runItemScript(Client c, ScriptedItem scriptItem) {
|
||||||
NPCScriptManager.getInstance().start(c, scriptItem, null);
|
NPCScriptManager.getInstance().startItemScript(c, scriptItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,27 +60,27 @@ public class NPCScriptManager extends AbstractScriptManager {
|
|||||||
return engine != null;
|
return engine != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean start(Client c, int npc, Character chr) {
|
public void start(Client c, int npc) {
|
||||||
return start(c, npc, -1, chr);
|
start(c, npc, -1, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean start(Client c, int npc, int oid, Character chr) {
|
public boolean start(Client c, int npc, int oid, Character chr) {
|
||||||
return start(c, npc, oid, null, chr);
|
return startNpcScript(c, npc, oid, null, chr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean start(Client c, int npc, String fileName, Character chr) {
|
public boolean start(Client c, int npc, String fileName) {
|
||||||
return start(c, npc, -1, fileName, chr);
|
return startNpcScript(c, npc, -1, fileName, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean start(Client c, int npc, int oid, String fileName, Character chr) {
|
public boolean startNpcScript(Client c, int npc, int oid, String fileName, Character chr) {
|
||||||
return start(c, npc, oid, fileName, chr, false, "cm");
|
return startWithBindings(c, npc, oid, fileName, chr, false, "cm");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean start(Client c, ScriptedItem scriptItem, Character chr) {
|
public boolean startItemScript(Client c, ScriptedItem scriptItem) {
|
||||||
return start(c, scriptItem.getNpc(), -1, scriptItem.getScript(), chr, true, "im");
|
return startWithBindings(c, scriptItem.getNpc(), -1, scriptItem.getScript(), null, true, "im");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start(String filename, Client c, int npc, List<PartyCharacter> chrs) {
|
public void startCpqScript(String filename, Client c, int npc, List<PartyCharacter> chrs) {
|
||||||
try {
|
try {
|
||||||
final NPCConversationManager cm = new NPCConversationManager(c, npc);
|
final NPCConversationManager cm = new NPCConversationManager(c, npc);
|
||||||
cm.dispose();
|
cm.dispose();
|
||||||
@@ -111,7 +111,7 @@ public class NPCScriptManager extends AbstractScriptManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean start(Client c, int npc, int oid, String fileName, Character chr, boolean itemScript, String engineName) {
|
private boolean startWithBindings(Client c, int npc, int oid, String fileName, Character chr, boolean itemScript, String engineName) {
|
||||||
try {
|
try {
|
||||||
final NPCConversationManager cm = new NPCConversationManager(c, npc, oid, fileName, itemScript);
|
final NPCConversationManager cm = new NPCConversationManager(c, npc, oid, fileName, itemScript);
|
||||||
if (cms.containsKey(c)) {
|
if (cms.containsKey(c)) {
|
||||||
@@ -165,16 +165,18 @@ public class NPCScriptManager extends AbstractScriptManager {
|
|||||||
|
|
||||||
public void action(Client c, byte mode, byte type, int selection) {
|
public void action(Client c, byte mode, byte type, int selection) {
|
||||||
Invocable iv = scripts.get(c);
|
Invocable iv = scripts.get(c);
|
||||||
if (iv != null) {
|
if (iv == null) {
|
||||||
try {
|
return;
|
||||||
c.setClickedNPC();
|
}
|
||||||
iv.invokeFunction("action", mode, type, selection);
|
|
||||||
} catch (ScriptException | NoSuchMethodException t) {
|
try {
|
||||||
if (getCM(c) != null) {
|
c.setClickedNPC();
|
||||||
log.error("Error performing NPC script action for npc: {}", getCM(c).getNpc(), t);
|
iv.invokeFunction("action", mode, type, selection);
|
||||||
}
|
} catch (ScriptException | NoSuchMethodException t) {
|
||||||
dispose(c);
|
if (getCM(c) != null) {
|
||||||
|
log.error("Error performing NPC script action for npc: {}", getCM(c).getNpc(), t);
|
||||||
}
|
}
|
||||||
|
dispose(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user