Source for my MapleSolaxiaV2 (v83 MapleStory).
This commit is contained in:
ronancpl
2015-11-02 23:17:21 -02:00
parent 324982e94f
commit 972517e7b2
1675 changed files with 261831 additions and 0 deletions

View File

@@ -0,0 +1,748 @@
/*
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;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import tools.DatabaseConnection;
import java.awt.Point;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import net.server.Server;
import net.server.channel.Channel;
import net.server.guild.MapleGuild;
import net.server.world.MapleParty;
import net.server.world.MaplePartyCharacter;
import scripting.event.EventManager;
import scripting.npc.NPCScriptManager;
import server.MapleInventoryManipulator;
import server.MapleItemInformationProvider;
import server.expeditions.MapleExpedition;
import server.expeditions.MapleExpeditionType;
import server.life.MapleLifeFactory;
import server.life.MapleMonster;
import server.life.MobSkill;
import server.life.MobSkillFactory;
import server.maps.MapleMap;
import server.maps.MapleMapObject;
import server.maps.MapleMapObjectType;
import server.partyquest.PartyQuest;
import server.partyquest.Pyramid;
import server.quest.MapleQuest;
import tools.MaplePacketCreator;
import client.MapleCharacter;
import client.MapleClient;
import client.MapleQuestStatus;
import client.SkillFactory;
import client.inventory.Equip;
import client.inventory.Item;
import client.inventory.MapleInventory;
import client.inventory.MapleInventoryType;
import client.inventory.MaplePet;
import client.inventory.ModifyInventory;
import client.inventory.PetDataFactory;
import constants.ItemConstants;
import constants.ServerConstants;
public class AbstractPlayerInteraction {
public MapleClient c;
public AbstractPlayerInteraction(MapleClient c) {
this.c = c;
}
public MapleClient getClient() {
return c;
}
public MapleCharacter getPlayer() {
return c.getPlayer();
}
public void warp(int map) {
getPlayer().changeMap(getWarpMap(map), getWarpMap(map).getPortal(0));
}
public void warp(int map, int portal) {
getPlayer().changeMap(getWarpMap(map), getWarpMap(map).getPortal(portal));
}
public void warp(int map, String portal) {
getPlayer().changeMap(getWarpMap(map), getWarpMap(map).getPortal(portal));
}
public void warpMap(int map) {
getPlayer().getMap().warpEveryone(map);
}
public void warpParty(int id) {
for (MapleCharacter mc : getPartyMembers()) {
if (id == 925020100) {
mc.setDojoParty(true);
}
mc.changeMap(getWarpMap(id));
}
}
public List<MapleCharacter> getPartyMembers() {
if (getPlayer().getParty() == null) {
return null;
}
List<MapleCharacter> chars = new LinkedList<>();
for (Channel channel : Server.getInstance().getChannelsFromWorld(getPlayer().getWorld())) {
for (MapleCharacter chr : channel.getPartyMembers(getPlayer().getParty())) {
if (chr != null) {
chars.add(chr);
}
}
}
return chars;
}
protected MapleMap getWarpMap(int map) {
MapleMap target;
if (getPlayer().getEventInstance() == null) {
target = c.getChannelServer().getMapFactory().getMap(map);
} else {
target = getPlayer().getEventInstance().getMapInstance(map);
}
return target;
}
public MapleMap getMap(int map) {
return getWarpMap(map);
}
public EventManager getEventManager(String event) {
return getClient().getChannelServer().getEventSM().getEventManager(event);
}
public MapleInventory getInventory(MapleInventoryType type) {
return getPlayer().getInventory(type);
}
public boolean hasItem(int itemid){
return haveItem(itemid, 1);
}
public boolean hasItem(int itemid, int quantity){
return haveItem(itemid, quantity);
}
public boolean haveItem(int itemid) {
return haveItem(itemid, 1);
}
public boolean haveItem(int itemid, int quantity) {
return getPlayer().getItemQuantity(itemid, false) >= quantity;
}
public boolean canHold(int itemid) {
return canHold(itemid, 1);
}
public boolean canHold(int itemid, int quantity) {
if(haveItem(itemid)) {
if(getPlayer().getItemQuantity(itemid, false) + quantity <= MapleItemInformationProvider.getInstance().getSlotMax(c, itemid))
return true;
}
return getPlayer().getInventory(MapleItemInformationProvider.getInstance().getInventoryType(itemid)).getNextFreeSlot() > -1;
}
//---- \/ \/ \/ \/ \/ \/ \/ NOT TESTED \/ \/ \/ \/ \/ \/ \/ \/ \/ ----
public final MapleQuestStatus getQuestRecord(final int id) {
return c.getPlayer().getQuestNAdd(MapleQuest.getInstance(id));
}
public final MapleQuestStatus getQuestNoRecord(final int id) {
return c.getPlayer().getQuestNoAdd(MapleQuest.getInstance(id));
}
//---- /\ /\ /\ /\ /\ /\ /\ NOT TESTED /\ /\ /\ /\ /\ /\ /\ /\ /\ ----
public void openNpc(int npcid) {
openNpc(npcid, null);
}
public void openNpc(int npcid, String script) {
c.removeClickedNPC();
NPCScriptManager.getInstance().dispose(c);
NPCScriptManager.getInstance().start(c, npcid, script, null);
}
public void updateQuest(int questid, String data) {
MapleQuestStatus status = c.getPlayer().getQuest(MapleQuest.getInstance(questid));
status.setStatus(MapleQuestStatus.Status.STARTED);
status.setProgress(0, data);//override old if exists
c.getPlayer().updateQuest(status);
}
public MapleQuestStatus.Status getQuestStatus(int id) {
return c.getPlayer().getQuest(MapleQuest.getInstance(id)).getStatus();
}
public boolean isQuestCompleted(int quest) {
try {
return getQuestStatus(quest) == MapleQuestStatus.Status.COMPLETED;
} catch (NullPointerException e) {
e.printStackTrace();
return false;
}
}
public boolean isQuestActive(int quest) {
return isQuestStarted(quest);
}
public boolean isQuestStarted(int quest) {
try {
return getQuestStatus(quest) == MapleQuestStatus.Status.STARTED;
} catch (NullPointerException e) {
e.printStackTrace();
return false;
}
}
public int getQuestProgress(int qid) {
return Integer.parseInt(getPlayer().getQuest(MapleQuest.getInstance(qid)).getProgress().get(0));
}
public Item evolvePet(byte slot, int afterId) {
MaplePet evolved = null;
MaplePet target = null;
Item tmp;
long period = 90; //refreshes expiration date: 90 days
period *= 24;
period *= 60;
period *= 60;
period *= 1000;
target = getPlayer().getPet(slot);
if(target == null) {
getPlayer().message("Pet could not be evolved...");
return(null);
}
tmp = gainItem(afterId, (short)1, false, true, period, target);
getPlayer().unequipPet(target, true, false);
/*
evolved = MaplePet.loadFromDb(tmp.getItemId(), tmp.getPosition(), tmp.getPetId());
evolved = tmp.getPet();
if(evolved == null) {
getPlayer().message("Pet structure non-existent for " + tmp.getItemId() + "...");
return(null);
}
else if(tmp.getPetId() == -1) {
getPlayer().message("Pet id -1");
return(null);
}
getPlayer().addPet(evolved);
getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.showPet(c.getPlayer(), evolved, false, false), true);
c.announce(MaplePacketCreator.petStatUpdate(c.getPlayer()));
c.announce(MaplePacketCreator.enableActions());
getPlayer().startFullnessSchedule(PetDataFactory.getHunger(evolved.getItemId()), evolved, getPlayer().getPetIndex(evolved));
*/
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.CASH, target.getPosition(), (short) 1, false);
return evolved;
}
public void gainItem(int id, short quantity) {
gainItem(id, quantity, false, true);
}
public void gainItem(int id, short quantity, boolean show) {//this will fk randomStats equip :P
gainItem(id, quantity, false, show);
}
public void gainItem(int id, boolean show) {
gainItem(id, (short) 1, false, show);
}
public void gainItem(int id) {
gainItem(id, (short) 1, false, true);
}
public Item gainItem(int id, short quantity, boolean randomStats, boolean showMessage) {
return gainItem(id, quantity, randomStats, showMessage, -1);
}
public Item gainItem(int id, short quantity, boolean randomStats, boolean showMessage, long expires) {
return gainItem(id, quantity, randomStats, showMessage, expires, null);
}
public Item gainItem(int id, short quantity, boolean randomStats, boolean showMessage, long expires, MaplePet from) {
Item item = null;
MaplePet evolved = null;
int petId = -1;
if (id >= 5000000 && id <= 5000100) {
petId = MaplePet.createPet(id);
if(from != null) {
evolved = MaplePet.loadFromDb(id, (short) 0, petId);
Point pos = getPlayer().getPosition();
pos.y -= 12;
evolved.setPos(pos);
evolved.setFh(getPlayer().getMap().getFootholds().findBelow(evolved.getPos()).getId());
evolved.setStance(0);
evolved.setSummoned(true);
evolved.setName(from.getName());
evolved.setCloseness(from.getCloseness());
evolved.setFullness(from.getFullness());
evolved.setLevel(from.getLevel());
evolved.saveToDb();
}
//MapleInventoryManipulator.addById(c, id, (short) 1, null, petId, expires == -1 ? -1 : System.currentTimeMillis() + expires);
}
if (quantity >= 0) {
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
if (ii.getInventoryType(id).equals(MapleInventoryType.EQUIP)) {
item = ii.getEquipById(id);
if(ServerConstants.USE_ENHANCED_CRAFTING == true && c.getPlayer().getCS() == true)
item = MapleItemInformationProvider.getInstance().scrollEquipWithId(item, 2049100, true, c.getPlayer().isGM());
} else {
item = new Item(id, (short) 0, quantity, petId);
}
if(expires >= 0)
item.setExpiration(System.currentTimeMillis() + expires);
item.setPetId(petId);
if (!MapleInventoryManipulator.checkSpace(c, id, quantity, "")) {
c.getPlayer().dropMessage(1, "Your inventory is full. Please remove an item from your " + ii.getInventoryType(id).name() + " inventory.");
return null;
}
if (ii.getInventoryType(id).equals(MapleInventoryType.EQUIP) && !ItemConstants.isRechargable(item.getItemId())) {
if (randomStats) {
item = ii.randomizeStats((Equip) item);
MapleInventoryManipulator.addFromDrop(c, ii.randomizeStats((Equip) item), false, petId);
} else {
MapleInventoryManipulator.addFromDrop(c, (Equip) item, false, petId);
}
} else {
MapleInventoryManipulator.addFromDrop(c, item, false, petId);
}
} else {
MapleInventoryManipulator.removeById(c, MapleItemInformationProvider.getInstance().getInventoryType(id), id, -quantity, true, false);
}
if (showMessage) {
c.announce(MaplePacketCreator.getShowItemGain(id, quantity, true));
}
return item;
}
public void gainFame(int delta) {
c.getPlayer().addFame(delta);
c.announce(MaplePacketCreator.getShowFameGain(delta));
}
public void changeMusic(String songName) {
getPlayer().getMap().broadcastMessage(MaplePacketCreator.musicChange(songName));
}
public void playerMessage(int type, String message) {
c.announce(MaplePacketCreator.serverNotice(type, message));
}
public void message(String message) {
getPlayer().message(message);
}
public void mapMessage(int type, String message) {
getPlayer().getMap().broadcastMessage(MaplePacketCreator.serverNotice(type, message));
}
public void mapEffect(String path) {
c.announce(MaplePacketCreator.mapEffect(path));
}
public void mapSound(String path) {
c.announce(MaplePacketCreator.mapSound(path));
}
public void displayAranIntro() {
String intro = "";
switch (c.getPlayer().getMapId()) {
case 914090010:
intro = "Effect/Direction1.img/aranTutorial/Scene0";
break;
case 914090011:
intro = "Effect/Direction1.img/aranTutorial/Scene1" + (c.getPlayer().getGender() == 0 ? "0" : "1");
break;
case 914090012:
intro = "Effect/Direction1.img/aranTutorial/Scene2" + (c.getPlayer().getGender() == 0 ? "0" : "1");
break;
case 914090013:
intro = "Effect/Direction1.img/aranTutorial/Scene3";
break;
case 914090100:
intro = "Effect/Direction1.img/aranTutorial/HandedPoleArm" + (c.getPlayer().getGender() == 0 ? "0" : "1");
break;
case 914090200:
intro = "Effect/Direction1.img/aranTutorial/Maha";
break;
}
showIntro(intro);
}
public void showIntro(String path) {
c.announce(MaplePacketCreator.showIntro(path));
}
public void showInfo(String path) {
c.announce(MaplePacketCreator.showInfo(path));
c.announce(MaplePacketCreator.enableActions());
}
public void guildMessage(int type, String message) {
if (getGuild() != null) {
getGuild().guildMessage(MaplePacketCreator.serverNotice(type, message));
}
}
public MapleGuild getGuild() {
try {
return Server.getInstance().getGuild(getPlayer().getGuildId(), getPlayer().getWorld(), null);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public MapleParty getParty() {
return getPlayer().getParty();
}
public boolean isLeader() {
if(getParty() == null)
return false;
return getParty().getLeader().equals(getPlayer().getMPC());
}
public void givePartyItems(int id, short quantity, List<MapleCharacter> party) {
for (MapleCharacter chr : party) {
MapleClient cl = chr.getClient();
if (quantity >= 0) {
MapleInventoryManipulator.addById(cl, id, quantity);
} else {
MapleInventoryManipulator.removeById(cl, MapleItemInformationProvider.getInstance().getInventoryType(id), id, -quantity, true, false);
}
cl.announce(MaplePacketCreator.getShowItemGain(id, quantity, true));
}
}
public void removeHPQItems() {
int[] items = {4001095, 4001096, 4001097, 4001098, 4001099, 4001100, 4001101};
for (int i = 0; i < items.length; i ++) {
removePartyItems(items[i]);
}
}
public void removePartyItems(int id) {
if (getParty() == null) {
removeAll(id);
return;
}
for (MaplePartyCharacter chr : getParty().getMembers()) {
if (chr != null && chr.isOnline() && chr.getPlayer().getClient() != null){
removeAll(id, chr.getPlayer().getClient());
}
}
}
public void givePartyExp(int amount, List<MapleCharacter> party) {
for (MapleCharacter chr : party) {
chr.gainExp((amount * chr.getExpRate()), true, true);
}
}
public void givePartyExp(String PQ) {
givePartyExp(PQ, true);
}
public void givePartyExp(String PQ, boolean instance) {
//1 player = 0% bonus (100)
//2 players = 0% bonus (100)
//3 players = +0% bonus (100)
//4 players = +10% bonus (110)
//5 players = +20% bonus (120)
//6 players = +30% bonus (130)
MapleParty party = getPlayer().getParty();
int size = party.getMembers().size();
if(instance) {
for(MaplePartyCharacter member: party.getMembers()) {
if(member == null || !member.isOnline() || member.getPlayer().getEventInstance() == null){
size--;
}
}
}
int bonus = size < 4 ? 100 : 70 + (size * 10);
for (MaplePartyCharacter member : party.getMembers()) {
if(member == null || !member.isOnline()){
continue;
}
MapleCharacter player = member.getPlayer();
if(instance && player.getEventInstance() == null){
continue; // They aren't in the instance, don't give EXP.
}
int base = PartyQuest.getExp(PQ, player.getLevel());
int exp = base * player.getExpRate();
exp = exp * bonus / 100;
player.gainExp(exp, true, true);
if(ServerConstants.PQ_BONUS_EXP_MOD > 0 && System.currentTimeMillis() <= ServerConstants.EVENT_END_TIMESTAMP) {
player.gainExp((int) (exp * ServerConstants.PQ_BONUS_EXP_MOD), true, true);
}
}
}
public void removeFromParty(int id, List<MapleCharacter> party) {
for (MapleCharacter chr : party) {
MapleInventoryType type = MapleItemInformationProvider.getInstance().getInventoryType(id);
MapleInventory iv = chr.getInventory(type);
int possesed = iv.countById(id);
if (possesed > 0) {
MapleInventoryManipulator.removeById(c, MapleItemInformationProvider.getInstance().getInventoryType(id), id, possesed, true, false);
chr.announce(MaplePacketCreator.getShowItemGain(id, (short) -possesed, true));
}
}
}
public void removeAll(int id) {
removeAll(id, c);
}
public void removeAll(int id, MapleClient cl) {
MapleInventoryType invType = MapleItemInformationProvider.getInstance().getInventoryType(id);
int possessed = cl.getPlayer().getInventory(invType).countById(id);
if (possessed > 0) {
MapleInventoryManipulator.removeById(cl, MapleItemInformationProvider.getInstance().getInventoryType(id), id, possessed, true, false);
cl.announce(MaplePacketCreator.getShowItemGain(id, (short) -possessed, true));
}
if(invType == MapleInventoryType.EQUIP) {
if(cl.getPlayer().getInventory(MapleInventoryType.EQUIPPED).countById(id) > 0) {
MapleInventoryManipulator.removeById(cl, MapleInventoryType.EQUIPPED, id, 1, true, false);
cl.announce(MaplePacketCreator.getShowItemGain(id, (short) -1, true));
}
}
}
public int getMapId() {
return c.getPlayer().getMap().getId();
}
public int getPlayerCount(int mapid) {
return c.getChannelServer().getMapFactory().getMap(mapid).getCharacters().size();
}
public void showInstruction(String msg, int width, int height) {
c.announce(MaplePacketCreator.sendHint(msg, width, height));
c.announce(MaplePacketCreator.enableActions());
}
public void disableMinimap() {
c.announce(MaplePacketCreator.disableMinimap());
}
public void resetMap(int mapid) {
getMap(mapid).resetReactors();
getMap(mapid).killAllMonsters();
for (MapleMapObject i : getMap(mapid).getMapObjectsInRange(c.getPlayer().getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.ITEM))) {
getMap(mapid).removeMapObject(i);
getMap(mapid).broadcastMessage(MaplePacketCreator.removeItemFromMap(i.getObjectId(), 0, c.getPlayer().getId()));
}
}
public void sendClock(MapleClient d, int time) {
d.announce(MaplePacketCreator.getClock((int) (time - System.currentTimeMillis()) / 1000));
}
public void useItem(int id) {
MapleItemInformationProvider.getInstance().getItemEffect(id).applyTo(c.getPlayer());
c.announce(MaplePacketCreator.getItemMessage(id));//Useful shet :3
}
public void cancelItem(final int id) {
getPlayer().cancelEffect(MapleItemInformationProvider.getInstance().getItemEffect(id), false, -1);
}
public void teachSkill(int skillid, byte level, byte masterLevel, long expiration) {
getPlayer().changeSkillLevel(SkillFactory.getSkill(skillid), level, masterLevel, expiration);
}
public void removeEquipFromSlot(short slot) {
Item tempItem = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem(slot);
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.EQUIPPED, slot, tempItem.getQuantity(), false, false);
}
public void gainAndEquip(int itemid, short slot) {
final Item old = c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).getItem(slot);
if (old != null) {
MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.EQUIPPED, slot, old.getQuantity(), false, false);
}
final Item newItem = MapleItemInformationProvider.getInstance().getEquipById(itemid);
newItem.setPosition(slot);
c.getPlayer().getInventory(MapleInventoryType.EQUIPPED).addFromDB(newItem);
c.announce(MaplePacketCreator.modifyInventory(false, Collections.singletonList(new ModifyInventory(0, newItem))));
}
public void spawnMonster(int id, int x, int y) {
MapleMonster monster = MapleLifeFactory.getMonster(id);
monster.setPosition(new Point(x, y));
getPlayer().getMap().spawnMonster(monster);
}
public MapleMonster getMonsterLifeFactory(int mid) {
return MapleLifeFactory.getMonster(mid);
}
public void spawnGuide() {
c.announce(MaplePacketCreator.spawnGuide(true));
}
public void removeGuide() {
c.announce(MaplePacketCreator.spawnGuide(false));
}
public void displayGuide(int num) {
c.announce(MaplePacketCreator.showInfo("UI/tutorial.img/" + num));
}
public void goDojoUp() {
c.announce(MaplePacketCreator.dojoWarpUp());
}
public void enableActions() {
c.announce(MaplePacketCreator.enableActions());
}
public void showEffect(String effect){
c.announce(MaplePacketCreator.showEffect(effect));
}
public void dojoEnergy() {
c.announce(MaplePacketCreator.getEnergy("energy", getPlayer().getDojoEnergy()));
}
public void talkGuide(String message) {
c.announce(MaplePacketCreator.talkGuide(message));
}
public void guideHint(int hint) {
c.announce(MaplePacketCreator.guideHint(hint));
}
public void updateAreaInfo(Short area, String info) {
c.getPlayer().updateAreaInfo(area, info);
c.announce(MaplePacketCreator.enableActions());//idk, nexon does the same :P
}
public boolean containsAreaInfo(short area, String info) {
return c.getPlayer().containsAreaInfo(area, info);
}
public MobSkill getMobSkill(int skill, int level) {
return MobSkillFactory.getMobSkill(skill, level);
}
public void earnTitle(String msg) {
c.announce(MaplePacketCreator.earnTitleMessage(msg));
}
public void showInfoText(String msg) {
c.announce(MaplePacketCreator.showInfoText(msg));
}
public void openUI(byte ui) {
c.announce(MaplePacketCreator.openUI(ui));
}
public void lockUI() {
c.announce(MaplePacketCreator.disableUI(true));
c.announce(MaplePacketCreator.lockUI(true));
}
public void unlockUI() {
c.announce(MaplePacketCreator.disableUI(false));
c.announce(MaplePacketCreator.lockUI(false));
}
public void playSound(String sound) {
getPlayer().getMap().broadcastMessage(MaplePacketCreator.environmentChange(sound, 4));
}
public void environmentChange(String env, int mode) {
getPlayer().getMap().broadcastMessage(MaplePacketCreator.environmentChange(env, mode));
}
public Pyramid getPyramid() {
return (Pyramid) getPlayer().getPartyQuest();
}
public void createExpedition(MapleExpeditionType type) {
MapleExpedition exped = new MapleExpedition(getPlayer(), type);
getPlayer().getClient().getChannelServer().getExpeditions().add(exped);
}
public void endExpedition(MapleExpedition exped) {
exped.dispose(true);
getPlayer().getClient().getChannelServer().getExpeditions().remove(exped);
}
public MapleExpedition getExpedition(MapleExpeditionType type) {
for (MapleExpedition exped : getPlayer().getClient().getChannelServer().getExpeditions()) {
if (exped.getType().equals(type)) {
return exped;
}
}
return null;
}
}

View File

@@ -0,0 +1,83 @@
/*
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;
import client.MapleClient;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import constants.ServerConstants;
import tools.FilePrinter;
/**
*
* @author Matze
*/
public abstract class AbstractScriptManager {
protected ScriptEngine engine;
private ScriptEngineManager sem;
protected AbstractScriptManager() {
sem = new ScriptEngineManager();
}
protected Invocable getInvocable(String path, MapleClient c) {
path = "scripts/" + path;
engine = null;
if (c != null) {
engine = c.getScriptEngine(path);
}
if (engine == null) {
File scriptFile = new File(path);
if (!scriptFile.exists()) {
return null;
}
engine = sem.getEngineByName("javascript");
if (c != null) {
c.setScriptEngine(path, engine);
}
try (FileReader fr = new FileReader(scriptFile)) {
if (ServerConstants.JAVA_8){
engine.eval("load('nashorn:mozilla_compat.js');");
}
engine.eval(fr);
} catch (final ScriptException | IOException t) {
FilePrinter.printError(FilePrinter.INVOCABLE + path.substring(12, path.length()), t, path);
return null;
}
}
return (Invocable) engine;
}
protected void resetContext(String path, MapleClient c) {
c.removeScriptEngine("scripts/" + path);
}
}

View File

@@ -0,0 +1,325 @@
/*
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.event;
import java.io.File;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.script.ScriptException;
import net.server.world.MapleParty;
import net.server.world.MaplePartyCharacter;
import provider.MapleDataProviderFactory;
import server.TimerManager;
import server.expeditions.MapleExpedition;
import server.life.MapleMonster;
import server.maps.MapleMap;
import server.maps.MapleMapFactory;
import tools.DatabaseConnection;
import client.MapleCharacter;
/**
*
* @author Matze
*/
public class EventInstanceManager {
private List<MapleCharacter> chars = new ArrayList<>();
private List<MapleMonster> mobs = new LinkedList<>();
private Map<MapleCharacter, Integer> killCount = new HashMap<>();
private EventManager em;
private MapleMapFactory mapFactory;
private String name;
private Properties props = new Properties();
private long timeStarted = 0;
private long eventTime = 0;
private MapleExpedition expedition = null;
public EventInstanceManager(EventManager em, String name) {
this.em = em;
this.name = name;
mapFactory = new MapleMapFactory(MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/Map.wz")), MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/String.wz")), (byte) 0, (byte) 1);//Fk this
mapFactory.setChannel(em.getChannelServer().getId());
}
public EventManager getEm() {
return em;
}
public void registerPlayer(MapleCharacter chr) {
if (chr == null || !chr.isLoggedin()){
return;
}
try {
chars.add(chr);
chr.setEventInstance(this);
em.getIv().invokeFunction("playerEntry", this, chr);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
public void startEventTimer(long time) {
timeStarted = System.currentTimeMillis();
eventTime = time;
}
public boolean isTimerStarted() {
return eventTime > 0 && timeStarted > 0;
}
public long getTimeLeft() {
return eventTime - (System.currentTimeMillis() - timeStarted);
}
public void registerParty(MapleParty party, MapleMap map) {
for (MaplePartyCharacter pc : party.getMembers()) {
MapleCharacter c = map.getCharacterById(pc.getId());
registerPlayer(c);
}
}
public void registerExpedition(MapleExpedition exped) {
expedition = exped;
registerPlayer(exped.getLeader());
}
public void unregisterPlayer(MapleCharacter chr) {
chars.remove(chr);
chr.setEventInstance(null);
}
public int getPlayerCount() {
return chars.size();
}
public List<MapleCharacter> getPlayers() {
return new ArrayList<>(chars);
}
public void registerMonster(MapleMonster mob) {
if (!mob.getStats().isFriendly()) { //We cannot register moon bunny
mobs.add(mob);
mob.setEventInstance(this);
}
}
public void movePlayer(MapleCharacter chr) {
try {
em.getIv().invokeFunction("moveMap", this, chr);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
public void monsterKilled(MapleMonster mob) {
mobs.remove(mob);
if (mobs.isEmpty()) {
try {
em.getIv().invokeFunction("allMonstersDead", this);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
}
public void playerKilled(MapleCharacter chr) {
try {
em.getIv().invokeFunction("playerDead", this, chr);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
public boolean revivePlayer(MapleCharacter chr) {
try {
Object b = em.getIv().invokeFunction("playerRevive", this, chr);
if (b instanceof Boolean) {
return (Boolean) b;
}
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
return true;
}
public void playerDisconnected(MapleCharacter chr) {
try {
em.getIv().invokeFunction("playerDisconnected", this, chr);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
/**
*
* @param chr
* @param mob
*/
public void monsterKilled(MapleCharacter chr, MapleMonster mob) {
try {
Integer kc = killCount.get(chr);
int inc = ((Double) em.getIv().invokeFunction("monsterValue", this, mob.getId())).intValue();
if (kc == null) {
kc = inc;
} else {
kc += inc;
}
killCount.put(chr, kc);
if (expedition != null){
expedition.monsterKilled(chr, mob);
}
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
public int getKillCount(MapleCharacter chr) {
Integer kc = killCount.get(chr);
if (kc == null) {
return 0;
} else {
return kc;
}
}
public void dispose() {
try {
em.getIv().invokeFunction("dispose", this);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
chars.clear();
mobs.clear();
killCount.clear();
mapFactory = null;
if (expedition != null) {
em.getChannelServer().getExpeditions().remove(expedition);
}
em.disposeInstance(name);
em = null;
}
public MapleMapFactory getMapFactory() {
return mapFactory;
}
public void schedule(final String methodName, long delay) {
TimerManager.getInstance().schedule(new Runnable() {
@Override
public void run() {
try {
em.getIv().invokeFunction(methodName, EventInstanceManager.this);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
}, delay);
}
public String getName() {
return name;
}
public void saveWinner(MapleCharacter chr) {
try {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO eventstats (event, instance, characterid, channel) VALUES (?, ?, ?, ?)")) {
ps.setString(1, em.getName());
ps.setString(2, getName());
ps.setInt(3, chr.getId());
ps.setInt(4, chr.getClient().getChannel());
ps.executeUpdate();
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
public MapleMap getMapInstance(int mapId) {
MapleMap map = mapFactory.getMap(mapId);
if (!mapFactory.isMapLoaded(mapId)) {
if (em.getProperty("shuffleReactors") != null && em.getProperty("shuffleReactors").equals("true")) {
map.shuffleReactors();
}
}
return map;
}
public void setProperty(String key, String value) {
props.setProperty(key, value);
}
public Object setProperty(String key, String value, boolean prev) {
return props.setProperty(key, value);
}
public String getProperty(String key) {
return props.getProperty(key);
}
public Properties getProperties(){
return props;
}
public void leftParty(MapleCharacter chr) {
try {
em.getIv().invokeFunction("leftParty", this, chr);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
public void disbandParty() {
try {
em.getIv().invokeFunction("disbandParty", this);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
public void finishPQ() {
try {
em.getIv().invokeFunction("clearPQ", this);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
public void removePlayer(MapleCharacter chr) {
try {
em.getIv().invokeFunction("playerExit", this, chr);
} catch (ScriptException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
public boolean isLeader(MapleCharacter chr) {
return (chr.getParty().getLeader().getId() == chr.getId());
}
}

View File

@@ -0,0 +1,201 @@
/*
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.event;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.script.Invocable;
import javax.script.ScriptException;
import net.server.channel.Channel;
import net.server.world.MapleParty;
import server.TimerManager;
import server.expeditions.MapleExpedition;
import server.maps.MapleMap;
import client.MapleCharacter;
/**
*
* @author Matze
*/
public class EventManager {
private Invocable iv;
private Channel cserv;
private Map<String, EventInstanceManager> instances = new HashMap<String, EventInstanceManager>();
private Properties props = new Properties();
private String name;
private ScheduledFuture<?> schedule = null;
public EventManager(Channel cserv, Invocable iv, String name) {
this.iv = iv;
this.cserv = cserv;
this.name = name;
}
public void cancel() {
try {
iv.invokeFunction("cancelSchedule", (Object) null);
} catch (ScriptException ex) {
ex.printStackTrace();
} catch (NoSuchMethodException ex) {
ex.printStackTrace();
}
}
public void schedule(String methodName, long delay) {
schedule(methodName, null, delay);
}
public void schedule(final String methodName, final EventInstanceManager eim, long delay) {
schedule = TimerManager.getInstance().schedule(new Runnable() {
public void run() {
try {
iv.invokeFunction(methodName, eim);
} catch (ScriptException ex) {
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
} catch (NoSuchMethodException ex) {
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
}
}
}, delay);
}
public void cancelSchedule() {
schedule.cancel(true);
}
public ScheduledFuture<?> scheduleAtTimestamp(final String methodName, long timestamp) {
return TimerManager.getInstance().scheduleAtTimestamp(new Runnable() {
public void run() {
try {
iv.invokeFunction(methodName, (Object) null);
} catch (ScriptException ex) {
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
} catch (NoSuchMethodException ex) {
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
}
}
}, timestamp);
}
public Channel getChannelServer() {
return cserv;
}
public EventInstanceManager getInstance(String name) {
return instances.get(name);
}
public Collection<EventInstanceManager> getInstances() {
return Collections.unmodifiableCollection(instances.values());
}
public EventInstanceManager newInstance(String name) {
EventInstanceManager ret = new EventInstanceManager(this, name);
instances.put(name, ret);
return ret;
}
public void disposeInstance(String name) {
instances.remove(name);
}
public Invocable getIv() {
return iv;
}
public void setProperty(String key, String value) {
props.setProperty(key, value);
}
public String getProperty(String key) {
return props.getProperty(key);
}
public void setProperty(String key, int value) {
props.setProperty(key, value + "");
}
public int getIntProperty(String key) {
return Integer.parseInt(props.getProperty(key));
}
public String getName() {
return name;
}
//Expedition method: starts an expedition
public void startInstance(MapleExpedition exped) {
try {
EventInstanceManager eim = (EventInstanceManager) (iv.invokeFunction("setup", (Object) null));
eim.registerExpedition(exped);
exped.start();
} catch (ScriptException ex) {
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
} catch (NoSuchMethodException ex) {
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
}
}
//Regular method: player
public void startInstance(MapleCharacter chr) {
try {
EventInstanceManager eim = (EventInstanceManager) (iv.invokeFunction("setup", (Object) null));
eim.registerPlayer(chr);
} catch (ScriptException ex) {
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
} catch (NoSuchMethodException ex) {
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
}
}
//PQ method: starts a PQ
public void startInstance(MapleParty party, MapleMap map) {
try {
EventInstanceManager eim = (EventInstanceManager) (iv.invokeFunction("setup", (Object) null));
eim.registerParty(party, map);
} catch (ScriptException ex) {
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
} catch (NoSuchMethodException ex) {
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
}
}
//non-PQ method for starting instance
public void startInstance(EventInstanceManager eim, String leader) {
try {
iv.invokeFunction("setup", eim);
eim.setProperty("leader", leader);
} catch (ScriptException ex) {
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
} catch (NoSuchMethodException ex) {
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

View File

@@ -0,0 +1,90 @@
/*
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.event;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import net.server.channel.Channel;
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;
}
public Invocable iv;
public EventManager em;
}
private Map<String, EventEntry> events = new LinkedHashMap<>();
public EventScriptManager(Channel cserv, String[] scripts) {
super();
for (String script : scripts) {
if (!script.equals("")) {
Invocable iv = getInvocable("event/" + script + ".js", null);
events.put(script, new EventEntry(iv, new EventManager(cserv, iv, script)));
}
}
}
public EventManager getEventManager(String event) {
EventEntry entry = events.get(event);
if (entry == null) {
return null;
}
return entry.em;
}
public void init() {
for (EventEntry entry : events.values()) {
try {
((ScriptEngine) entry.iv).put("em", entry.em);
entry.iv.invokeFunction("init", (Object) null);
} catch (Exception ex) {
Logger.getLogger(EventScriptManager.class.getName()).log(Level.SEVERE, null, ex);
System.out.println("Error on script: " + entry.em.getName());
}
}
}
public void reload(){
cancel();
init();
}
public void cancel() {
for (EventEntry entry : events.values()) {
entry.em.cancel();
}
}
}

View File

@@ -0,0 +1,98 @@
/*
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 java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.HashMap;
import java.util.Map;
import javax.script.Compilable;
import javax.script.CompiledScript;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import tools.FilePrinter;
import tools.MaplePacketCreator;
public class ItemScriptManager {
private static ItemScriptManager instance = new ItemScriptManager();
private Map<String, Invocable> scripts = new HashMap<>();
private ScriptEngineFactory sef;
private ItemScriptManager() {
ScriptEngineManager sem = new ScriptEngineManager();
sef = sem.getEngineByName("javascript").getFactory();
}
public static ItemScriptManager getInstance() {
return instance;
}
public boolean scriptExists(String scriptName) {
File scriptFile = new File("scripts/item/" + scriptName + ".js");
return scriptFile.exists();
}
public void getItemScript(MapleClient c, String scriptName) {
if (scripts.containsKey(scriptName)) {
try {
scripts.get(scriptName).invokeFunction("start", new ItemScriptMethods(c));
} catch (ScriptException | NoSuchMethodException ex) {
FilePrinter.printError(FilePrinter.ITEM + scriptName + ".txt", ex);
}
return;
}
File scriptFile = new File("scripts/item/" + scriptName + ".js");
if (!scriptFile.exists()) {
c.announce(MaplePacketCreator.enableActions());
return;
}
FileReader fr = null;
ScriptEngine portal = sef.getScriptEngine();
try {
fr = new FileReader(scriptFile);
CompiledScript compiled = ((Compilable) portal).compile(fr);
compiled.eval();
final Invocable script = ((Invocable) portal);
scripts.put(scriptName, script);
script.invokeFunction("start", new ItemScriptMethods(c));
} catch (final UndeclaredThrowableException | ScriptException ute) {
FilePrinter.printError(FilePrinter.ITEM + scriptName + ".txt", ute);
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.ITEM + scriptName + ".txt", e);
} finally {
if (fr != null) {
try {
fr.close();
} catch (IOException e) {
}
}
}
}
}

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

@@ -0,0 +1,100 @@
/*
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.map;
import client.MapleClient;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.HashMap;
import java.util.Map;
import javax.script.Compilable;
import javax.script.CompiledScript;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import tools.FilePrinter;
public class MapScriptManager {
private static MapScriptManager instance = new MapScriptManager();
private Map<String, Invocable> scripts = new HashMap<>();
private ScriptEngineFactory sef;
private MapScriptManager() {
ScriptEngineManager sem = new ScriptEngineManager();
sef = sem.getEngineByName("javascript").getFactory();
}
public static MapScriptManager getInstance() {
return instance;
}
public void reloadScripts() {
scripts.clear();
}
public boolean scriptExists(String scriptName, boolean firstUser) {
File scriptFile = new File("scripts/map/" + (firstUser ? "onFirstUserEnter/" : "onUserEnter/") + scriptName + ".js");
return scriptFile.exists();
}
public void getMapScript(MapleClient c, String scriptName, boolean firstUser) {
if (scripts.containsKey(scriptName)) {
try {
scripts.get(scriptName).invokeFunction("start", new MapScriptMethods(c));
} catch (final ScriptException | NoSuchMethodException e) {
}
return;
}
String type = firstUser ? "onFirstUserEnter/" : "onUserEnter/";
File scriptFile = new File("scripts/map/" + type + scriptName + ".js");
if (!scriptExists(scriptName, firstUser)) {
return;
}
FileReader fr = null;
ScriptEngine portal = sef.getScriptEngine();
try {
fr = new FileReader(scriptFile);
CompiledScript compiled = ((Compilable) portal).compile(fr);
compiled.eval();
final Invocable script = ((Invocable) portal);
scripts.put(scriptName, script);
script.invokeFunction("start", new MapScriptMethods(c));
} catch (final UndeclaredThrowableException | ScriptException ute) {
FilePrinter.printError(FilePrinter.MAP_SCRIPT + type + scriptName + ".txt", ute);
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.MAP_SCRIPT + type + scriptName + ".txt", e);
} finally {
if (fr != null) {
try {
fr.close();
} catch (IOException e) {
}
}
}
}
}

View File

@@ -0,0 +1,140 @@
/*
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.map;
import client.MapleClient;
import client.MapleQuestStatus;
import scripting.AbstractPlayerInteraction;
import server.quest.MapleQuest;
import tools.MaplePacketCreator;
public class MapScriptMethods extends AbstractPlayerInteraction {
private String rewardstring = " title has been rewarded. Please see NPC Dalair to receive your Medal.";
public MapScriptMethods(MapleClient c) {
super(c);
}
public void displayAranIntro() {
switch (c.getPlayer().getMapId()) {
case 914090010:
lockUI();
c.announce(MaplePacketCreator.showIntro("Effect/Direction1.img/aranTutorial/Scene0"));
break;
case 914090011:
c.announce(MaplePacketCreator.showIntro("Effect/Direction1.img/aranTutorial/Scene1" + c.getPlayer().getGender()));
break;
case 914090012:
c.announce(MaplePacketCreator.showIntro("Effect/Direction1.img/aranTutorial/Scene2" + c.getPlayer().getGender()));
break;
case 914090013:
c.announce(MaplePacketCreator.showIntro("Effect/Direction1.img/aranTutorial/Scene3"));
break;
case 914090100:
lockUI();
c.announce(MaplePacketCreator.showIntro("Effect/Direction1.img/aranTutorial/HandedPoleArm" + c.getPlayer().getGender()));
break;
}
}
public void startExplorerExperience() {
if (c.getPlayer().getMapId() == 1020100) //Swordman
{
c.announce(MaplePacketCreator.showIntro("Effect/Direction3.img/swordman/Scene" + c.getPlayer().getGender()));
} else if (c.getPlayer().getMapId() == 1020200) //Magician
{
c.announce(MaplePacketCreator.showIntro("Effect/Direction3.img/magician/Scene" + c.getPlayer().getGender()));
} else if (c.getPlayer().getMapId() == 1020300) //Archer
{
c.announce(MaplePacketCreator.showIntro("Effect/Direction3.img/archer/Scene" + c.getPlayer().getGender()));
} else if (c.getPlayer().getMapId() == 1020400) //Rogue
{
c.announce(MaplePacketCreator.showIntro("Effect/Direction3.img/rogue/Scene" + c.getPlayer().getGender()));
} else if (c.getPlayer().getMapId() == 1020500) //Pirate
{
c.announce(MaplePacketCreator.showIntro("Effect/Direction3.img/pirate/Scene" + c.getPlayer().getGender()));
}
}
public void goAdventure() {
lockUI();
c.announce(MaplePacketCreator.showIntro("Effect/Direction3.img/goAdventure/Scene" + c.getPlayer().getGender()));
}
public void goLith() {
lockUI();
c.announce(MaplePacketCreator.showIntro("Effect/Direction3.img/goLith/Scene" + c.getPlayer().getGender()));
}
public void explorerQuest(short questid, String questName) {
MapleQuest quest = MapleQuest.getInstance(questid);
if (!isQuestStarted(questid)) {
if (!quest.forceStart(getPlayer(), 9000066)) {
return;
}
}
MapleQuestStatus q = getPlayer().getQuest(quest);
if (!q.addMedalMap(getPlayer().getMapId())) {
return;
}
String status = Integer.toString(q.getMedalProgress());
String infoex = quest.getInfoEx();
getPlayer().announce(MaplePacketCreator.updateQuest(q, true));
StringBuilder smp = new StringBuilder();
StringBuilder etm = new StringBuilder();
if (status.equals(infoex)) {
etm.append("Earned the ").append(questName).append(" title!");
smp.append("You have earned the <").append(questName).append(">").append(rewardstring);
getPlayer().announce(MaplePacketCreator.getShowQuestCompletion(quest.getId()));
} else {
getPlayer().announce(MaplePacketCreator.earnTitleMessage(status + "/" + infoex + " regions explored."));
etm.append("Trying for the ").append(questName).append(" title.");
smp.append("You made progress on the ").append(questName).append(" title. ").append(status).append("/").append(infoex);
}
getPlayer().announce(MaplePacketCreator.earnTitleMessage(etm.toString()));
showInfoText(smp.toString());
}
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");
}
}
}

View File

@@ -0,0 +1,520 @@
/*
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.npc;
import java.io.File;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import net.server.Server;
import net.server.guild.MapleAlliance;
import net.server.guild.MapleGuild;
import net.server.world.MapleParty;
import net.server.world.MaplePartyCharacter;
import provider.MapleData;
import provider.MapleDataProviderFactory;
import scripting.AbstractPlayerInteraction;
import server.MapleItemInformationProvider;
import server.MapleStatEffect;
import server.events.gm.MapleEvent;
import server.gachapon.MapleGachapon;
import server.gachapon.MapleGachapon.MapleGachaponItem;
import server.maps.MapleMap;
import server.maps.MapleMapFactory;
import server.partyquest.Pyramid;
import server.partyquest.Pyramid.PyramidMode;
import server.quest.MapleQuest;
import tools.LogHelper;
import tools.DatabaseConnection;
import tools.FilePrinter;
import tools.MaplePacketCreator;
import client.MapleCharacter;
import client.MapleClient;
import client.MapleJob;
import client.MapleSkinColor;
import client.MapleStat;
import client.Skill;
import client.SkillFactory;
import client.inventory.Item;
import client.inventory.ItemFactory;
import client.inventory.MapleInventoryType;
import client.inventory.MaplePet;
import constants.ExpTable;
import constants.ServerConstants;
/**
*
* @author Matze
*/
public class NPCConversationManager extends AbstractPlayerInteraction {
private int npc;
private String scriptName;
private String getText;
public NPCConversationManager(MapleClient c, int npc, String scriptName) {
super(c);
this.npc = npc;
this.scriptName = scriptName;
}
public int getNpc() {
return npc;
}
public String getScriptName() {
return scriptName;
}
public void dispose() {
NPCScriptManager.getInstance().dispose(this);
}
public void sendNext(String text) {
getClient().announce(MaplePacketCreator.getNPCTalk(npc, (byte) 0, text, "00 01", (byte) 0));
}
public void sendPrev(String text) {
getClient().announce(MaplePacketCreator.getNPCTalk(npc, (byte) 0, text, "01 00", (byte) 0));
}
public void sendNextPrev(String text) {
getClient().announce(MaplePacketCreator.getNPCTalk(npc, (byte) 0, text, "01 01", (byte) 0));
}
public void sendOk(String text) {
getClient().announce(MaplePacketCreator.getNPCTalk(npc, (byte) 0, text, "00 00", (byte) 0));
}
public void sendYesNo(String text) {
getClient().announce(MaplePacketCreator.getNPCTalk(npc, (byte) 1, text, "", (byte) 0));
}
public void sendAcceptDecline(String text) {
getClient().announce(MaplePacketCreator.getNPCTalk(npc, (byte) 0x0C, text, "", (byte) 0));
}
public void sendSimple(String text) {
getClient().announce(MaplePacketCreator.getNPCTalk(npc, (byte) 4, text, "", (byte) 0));
}
public void sendNext(String text, byte speaker) {
getClient().announce(MaplePacketCreator.getNPCTalk(npc, (byte) 0, text, "00 01", speaker));
}
public void sendPrev(String text, byte speaker) {
getClient().announce(MaplePacketCreator.getNPCTalk(npc, (byte) 0, text, "01 00", speaker));
}
public void sendNextPrev(String text, byte speaker) {
getClient().announce(MaplePacketCreator.getNPCTalk(npc, (byte) 0, text, "01 01", speaker));
}
public void sendOk(String text, byte speaker) {
getClient().announce(MaplePacketCreator.getNPCTalk(npc, (byte) 0, text, "00 00", speaker));
}
public void sendYesNo(String text, byte speaker) {
getClient().announce(MaplePacketCreator.getNPCTalk(npc, (byte) 1, text, "", speaker));
}
public void sendAcceptDecline(String text, byte speaker) {
getClient().announce(MaplePacketCreator.getNPCTalk(npc, (byte) 0x0C, text, "", speaker));
}
public void sendSimple(String text, byte speaker) {
getClient().announce(MaplePacketCreator.getNPCTalk(npc, (byte) 4, text, "", speaker));
}
public void sendStyle(String text, int styles[]) {
getClient().announce(MaplePacketCreator.getNPCTalkStyle(npc, text, styles));
}
public void sendGetNumber(String text, int def, int min, int max) {
getClient().announce(MaplePacketCreator.getNPCTalkNum(npc, text, def, min, max));
}
public void sendGetText(String text) {
getClient().announce(MaplePacketCreator.getNPCTalkText(npc, text, ""));
}
/*
* 0 = ariant colliseum
* 1 = Dojo
* 2 = Carnival 1
* 3 = Carnival 2
* 4 = Ghost Ship PQ?
* 5 = Pyramid PQ
* 6 = Kerning Subway
*/
public void sendDimensionalMirror(String text) {
getClient().announce(MaplePacketCreator.getDimensionalMirror(text));
}
public void setGetText(String text) {
this.getText = text;
}
public String getText() {
return this.getText;
}
public int getJobId() {
return getPlayer().getJob().getId();
}
public MapleJob getJob(){
return getPlayer().getJob();
}
public void startQuest(short id) {
try {
MapleQuest.getInstance(id).forceStart(getPlayer(), npc);
} catch (NullPointerException ex) {
}
}
public void completeQuest(short id) {
try {
MapleQuest.getInstance(id).forceComplete(getPlayer(), npc);
} catch (NullPointerException ex) {
}
}
public void startQuest(int id) {
try {
MapleQuest.getInstance(id).forceStart(getPlayer(), npc);
} catch (NullPointerException ex) {
}
}
public void completeQuest(int id) {
try {
MapleQuest.getInstance(id).forceComplete(getPlayer(), npc);
} catch (NullPointerException ex) {
}
}
public int getMeso() {
return getPlayer().getMeso();
}
public void gainMeso(int gain) {
if (gain > 0 && ServerConstants.USE_AUTOBAN == true) {
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " gained " + gain + " mesos from NPC " + npc + "\r\n");
}
getPlayer().gainMeso(gain, true, false, true);
}
public void gainExp(int gain) {
getPlayer().gainExp(gain, true, true);
}
public int getLevel() {
return getPlayer().getLevel();
}
public void showEffect(String effect) {
getPlayer().getMap().broadcastMessage(MaplePacketCreator.environmentChange(effect, 3));
}
public void setHair(int hair) {
getPlayer().setHair(hair);
getPlayer().updateSingleStat(MapleStat.HAIR, hair);
getPlayer().equipChanged();
}
public void setFace(int face) {
getPlayer().setFace(face);
getPlayer().updateSingleStat(MapleStat.FACE, face);
getPlayer().equipChanged();
}
public void setSkin(int color) {
getPlayer().setSkinColor(MapleSkinColor.getById(color));
getPlayer().updateSingleStat(MapleStat.SKIN, color);
getPlayer().equipChanged();
}
public int itemQuantity(int itemid) {
return getPlayer().getInventory(MapleItemInformationProvider.getInstance().getInventoryType(itemid)).countById(itemid);
}
public void displayGuildRanks() {
MapleGuild.displayGuildRanks(getClient(), npc);
}
@Override
public MapleParty getParty() {
return getPlayer().getParty();
}
@Override
public void resetMap(int mapid) {
getClient().getChannelServer().getMapFactory().getMap(mapid).resetReactors();
}
public void gainCloseness(int closeness) {
for (MaplePet pet : getPlayer().getPets()) {
if (pet.getCloseness() > 30000) {
pet.setCloseness(30000);
return;
}
pet.gainCloseness(closeness);
while (pet.getCloseness() > ExpTable.getClosenessNeededForLevel(pet.getLevel())) {
pet.setLevel((byte) (pet.getLevel() + 1));
byte index = getPlayer().getPetIndex(pet);
getClient().announce(MaplePacketCreator.showOwnPetLevelUp(index));
getPlayer().getMap().broadcastMessage(getPlayer(), MaplePacketCreator.showPetLevelUp(getPlayer(), index));
}
Item petz = getPlayer().getInventory(MapleInventoryType.CASH).getItem(pet.getPosition());
getPlayer().forceUpdateItem(petz);
}
}
public String getName() {
return getPlayer().getName();
}
public int getGender() {
return getPlayer().getGender();
}
public void changeJobById(int a) {
getPlayer().changeJob(MapleJob.getById(a));
}
public void changeJob(MapleJob job){
getPlayer().changeJob(job);
}
public MapleJob getJobName(int id) {
return MapleJob.getById(id);
}
public MapleStatEffect getItemEffect(int itemId) {
return MapleItemInformationProvider.getInstance().getItemEffect(itemId);
}
public void resetStats() {
getPlayer().resetStats();
}
public void maxMastery() {
for (MapleData skill_ : MapleDataProviderFactory.getDataProvider(new File(System.getProperty("wzpath") + "/" + "String.wz")).getData("Skill.img").getChildren()) {
try {
Skill skill = SkillFactory.getSkill(Integer.parseInt(skill_.getName()));
getPlayer().changeSkillLevel(skill, (byte) 0, skill.getMaxLevel(), -1);
} catch (NumberFormatException nfe) {
break;
} catch (NullPointerException npe) {
continue;
}
}
}
public void doGachapon() {
int[] maps = {100000000, 101000000, 102000000, 103000000, 105040300, 800000000, 809000101, 809000201, 600000000, 120000000};
MapleGachaponItem item = MapleGachapon.getInstance().process(npc);
Item itemGained = gainItem(item.getId(), (short) (item.getId() / 10000 == 200 ? 100 : 1), true, true); // For normal potions, make it give 100.
sendNext("You have obtained a #b#t" + item.getId() + "##k.");
String map = c.getChannelServer().getMapFactory().getMap(maps[(getNpc() != 9100117 && getNpc() != 9100109) ? (getNpc() - 9100100) : getNpc() == 9100109 ? 8 : 9]).getMapName();
LogHelper.logGacha(getPlayer(), item.getId(), map);
if (item.getTier() > 0){ //Uncommon and Rare
Server.getInstance().broadcastMessage(MaplePacketCreator.gachaponMessage(itemGained, map, getPlayer()));
}
}
public void disbandAlliance(MapleClient c, int allianceId) {
PreparedStatement ps = null;
try {
ps = DatabaseConnection.getConnection().prepareStatement("DELETE FROM `alliance` WHERE id = ?");
ps.setInt(1, allianceId);
ps.executeUpdate();
ps.close();
Server.getInstance().allianceMessage(c.getPlayer().getGuild().getAllianceId(), MaplePacketCreator.disbandAlliance(allianceId), -1, -1);
Server.getInstance().disbandAlliance(allianceId);
} catch (SQLException sqle) {
sqle.printStackTrace();
} finally {
try {
if (ps != null && !ps.isClosed()) {
ps.close();
}
} catch (SQLException ex) {
}
}
}
public boolean canBeUsedAllianceName(String name) {
if (name.contains(" ") || name.length() > 12) {
return false;
}
try {
ResultSet rs;
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT name FROM alliance WHERE name = ?")) {
ps.setString(1, name);
rs = ps.executeQuery();
if (rs.next()) {
ps.close();
rs.close();
return false;
}
}
rs.close();
return true;
} catch (SQLException e) {
e.printStackTrace();
return false;
}
}
public static MapleAlliance createAlliance(MapleCharacter chr1, MapleCharacter chr2, String name) {
int id;
int guild1 = chr1.getGuildId();
int guild2 = chr2.getGuildId();
try {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO `alliance` (`name`, `guild1`, `guild2`) VALUES (?, ?, ?)", PreparedStatement.RETURN_GENERATED_KEYS)) {
ps.setString(1, name);
ps.setInt(2, guild1);
ps.setInt(3, guild2);
ps.executeUpdate();
try (ResultSet rs = ps.getGeneratedKeys()) {
rs.next();
id = rs.getInt(1);
}
}
} catch (SQLException e) {
e.printStackTrace();
return null;
}
MapleAlliance alliance = new MapleAlliance(name, id, guild1, guild2);
try {
Server.getInstance().setGuildAllianceId(guild1, id);
Server.getInstance().setGuildAllianceId(guild2, id);
chr1.setAllianceRank(1);
chr1.saveGuildStatus();
chr2.setAllianceRank(2);
chr2.saveGuildStatus();
Server.getInstance().addAlliance(id, alliance);
Server.getInstance().allianceMessage(id, MaplePacketCreator.makeNewAlliance(alliance, chr1.getClient()), -1, -1);
} catch (Exception e) {
return null;
}
return alliance;
}
public boolean hasMerchant() {
return getPlayer().hasMerchant();
}
public boolean hasMerchantItems() {
try {
if (!ItemFactory.MERCHANT.loadItems(getPlayer().getId(), false).isEmpty()) {
return true;
}
} catch (SQLException e) {
return false;
}
if (getPlayer().getMerchantMeso() == 0) {
return false;
} else {
return true;
}
}
public void showFredrick() {
c.announce(MaplePacketCreator.getFredrick(getPlayer()));
}
public int partyMembersInMap() {
int inMap = 0;
for (MapleCharacter char2 : getPlayer().getMap().getCharacters()) {
if (char2.getParty() == getPlayer().getParty()) {
inMap++;
}
}
return inMap;
}
public MapleEvent getEvent() {
return c.getChannelServer().getEvent();
}
public void divideTeams() {
if (getEvent() != null) {
getPlayer().setTeam(getEvent().getLimit() % 2); //muhaha :D
}
}
public MapleCharacter getMapleCharacter(String player) {
MapleCharacter target = Server.getInstance().getWorld(c.getWorld()).getChannel(c.getChannel()).getPlayerStorage().getCharacterByName(player);
return target;
}
public void logLeaf(String prize) {
LogHelper.logLeaf(getPlayer(), true, prize);
}
public boolean createPyramid(String mode, boolean party) {//lol
PyramidMode mod = PyramidMode.valueOf(mode);
MapleParty partyz = getPlayer().getParty();
MapleMapFactory mf = c.getChannelServer().getMapFactory();
MapleMap map = null;
int mapid = 926010100;
if (party) {
mapid += 10000;
}
mapid += (mod.getMode() * 1000);
for (byte b = 0; b < 5; b++) {//They cannot warp to the next map before the timer ends (:
map = mf.getMap(mapid + b);
if (map.getCharacters().size() > 0) {
continue;
} else {
break;
}
}
if (map == null) {
return false;
}
if (!party) {
partyz = new MapleParty(-1, new MaplePartyCharacter(getPlayer()));
}
Pyramid py = new Pyramid(partyz, mod, map.getId());
getPlayer().setPartyQuest(py);
py.warp(mapid);
dispose();
return true;
}
}

View File

@@ -0,0 +1,141 @@
/*
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.npc;
import client.MapleCharacter;
import client.MapleClient;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.HashMap;
import java.util.Map;
import javax.script.Invocable;
import javax.script.ScriptException;
import scripting.AbstractScriptManager;
import server.life.MapleLifeFactory;
import tools.FilePrinter;
import tools.MaplePacketCreator;
/**
*
* @author Matze
*/
public class NPCScriptManager extends AbstractScriptManager {
private Map<MapleClient, NPCConversationManager> cms = new HashMap<>();
private Map<MapleClient, Invocable> scripts = new HashMap<>();
private static NPCScriptManager instance = new NPCScriptManager();
public synchronized static NPCScriptManager getInstance() {
return instance;
}
public void start(MapleClient c, int npc, MapleCharacter chr) {
start(c, npc, null, chr);
}
public void start(MapleClient c, int npc, String fileName, MapleCharacter chr) {
try {
NPCConversationManager cm = new NPCConversationManager(c, npc, fileName);
if (cms.containsKey(c)) {
dispose(c);
}
if (c.canClickNPC()) {
cms.put(c, cm);
Invocable iv = null;
if (fileName != null) {
iv = getInvocable("npc/world" + c.getWorld() + "/" + fileName + ".js", c);
}
if (iv == null) {
iv = getInvocable("npc/world" + c.getWorld() + "/" + npc + ".js", c);
}
if (iv == null) {
FilePrinter.printError(FilePrinter.NPC_UNCODED, "NPC " + MapleLifeFactory.getNPC(npc).getName() + "(" + npc + ") is not coded.\r\n");
}
if (iv == null || NPCScriptManager.getInstance() == null) {
dispose(c);
return;
}
engine.put("cm", cm);
scripts.put(c, iv);
c.setClickedNPC();
try {
iv.invokeFunction("start");
} catch (final NoSuchMethodException nsme) {
try {
iv.invokeFunction("start", chr);
} catch (final NoSuchMethodException nsma) {
nsma.printStackTrace();
}
}
} else {
c.announce(MaplePacketCreator.enableActions());
}
} catch (final UndeclaredThrowableException | ScriptException ute) {
FilePrinter.printError(FilePrinter.NPC + npc + ".txt", ute);
dispose(c);
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.NPC + npc + ".txt", e);
dispose(c);
}
}
public void action(MapleClient c, byte mode, byte type, int selection) {
Invocable iv = scripts.get(c);
if (iv != null) {
try {
c.setClickedNPC();
iv.invokeFunction("action", mode, type, selection);
} catch (ScriptException | NoSuchMethodException t) {
if (getCM(c) != null) {
FilePrinter.printError(FilePrinter.NPC + getCM(c).getNpc() + ".txt", t);
}
dispose(c);
}
}
}
public void dispose(NPCConversationManager cm) {
MapleClient c = cm.getClient();
c.getPlayer().setCS(false);
cms.remove(c);
scripts.remove(c);
if(cm.getScriptName() != null) {
resetContext("npc/world" + c.getWorld() + "/" + cm.getScriptName() + ".js", c);
} else {
resetContext("npc/world" + c.getWorld() + "/" + cm.getNpc() + ".js", c);
}
}
public void dispose(MapleClient c) {
if (cms.get(c) != null) {
dispose(cms.get(c));
}
}
public NPCConversationManager getCM(MapleClient c) {
return cms.get(c);
}
}

View File

@@ -0,0 +1,87 @@
/*
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.portal;
import client.MapleClient;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import scripting.AbstractPlayerInteraction;
import server.MaplePortal;
import tools.DatabaseConnection;
import tools.MaplePacketCreator;
public class PortalPlayerInteraction extends AbstractPlayerInteraction {
private MaplePortal portal;
public PortalPlayerInteraction(MapleClient c, MaplePortal portal) {
super(c);
this.portal = portal;
}
public MaplePortal getPortal() {
return portal;
}
public boolean hasLevel30Character() {
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = DatabaseConnection.getConnection().prepareStatement("SELECT `level` FROM `characters` WHERE accountid = ?");
ps.setInt(1, getPlayer().getAccountID());
rs = ps.executeQuery();
while (rs.next()) {
if (rs.getInt("level") >= 30) {
ps.close();
rs.close();
return true;
}
}
} catch (SQLException sqle) {
sqle.printStackTrace();
} finally {
try {
if (ps != null && !ps.isClosed()) {
ps.close();
}
if (rs != null && !rs.isClosed()) {
rs.close();
}
} catch (SQLException ex) {
}
}
return false;
}
public void blockPortal() {
c.getPlayer().blockPortal(getPortal().getScriptName());
}
public void unblockPortal() {
c.getPlayer().unblockPortal(getPortal().getScriptName());
}
public void playPortalSound() {
c.announce(MaplePacketCreator.playPortalSound());
}
}

View File

@@ -0,0 +1,26 @@
/*
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.portal;
public interface PortalScript {
public boolean enter(PortalPlayerInteraction ppi);
}

View File

@@ -0,0 +1,102 @@
/*
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.portal;
import client.MapleClient;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.HashMap;
import java.util.Map;
import javax.script.Compilable;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import server.MaplePortal;
import tools.FilePrinter;
public class PortalScriptManager {
private static PortalScriptManager instance = new PortalScriptManager();
private Map<String, PortalScript> scripts = new HashMap<>();
private ScriptEngineFactory sef;
private PortalScriptManager() {
ScriptEngineManager sem = new ScriptEngineManager();
sef = sem.getEngineByName("javascript").getFactory();
}
public static PortalScriptManager getInstance() {
return instance;
}
private PortalScript getPortalScript(String scriptName) {
if (scripts.containsKey(scriptName)) {
return scripts.get(scriptName);
}
File scriptFile = new File("scripts/portal/" + scriptName + ".js");
if (!scriptFile.exists()) {
scripts.put(scriptName, null);
return null;
}
FileReader fr = null;
ScriptEngine portal = sef.getScriptEngine();
try {
fr = new FileReader(scriptFile);
((Compilable) portal).compile(fr).eval();
} catch (ScriptException | IOException | UndeclaredThrowableException e) {
FilePrinter.printError(FilePrinter.PORTAL + scriptName + ".txt", e);
} finally {
if (fr != null) {
try {
fr.close();
} catch (IOException e) {
System.out.println("ERROR CLOSING " + e);
}
}
}
PortalScript script = ((Invocable) portal).getInterface(PortalScript.class);
scripts.put(scriptName, script);
return script;
}
public boolean executePortalScript(MaplePortal portal, MapleClient c) {
try {
PortalScript script = getPortalScript(portal.getScriptName());
if (script != null) {
return script.enter(new PortalPlayerInteraction(c, portal));
}
} catch (UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.PORTAL + portal.getScriptName() + ".txt", ute);
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.PORTAL + portal.getScriptName() + ".txt", e);
}
return false;
}
public void reloadPortalScripts() {
scripts.clear();
}
}

View File

@@ -0,0 +1,80 @@
/*
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.quest;
import client.MapleClient;
import scripting.npc.NPCConversationManager;
import server.quest.MapleQuest;
/**
*
* @author RMZero213
*/
public class QuestActionManager extends NPCConversationManager {
private boolean start; // this is if the script in question is start or end
private int quest;
public QuestActionManager(MapleClient c, int quest, int npc, boolean start) {
super(c, npc, null);
this.quest = quest;
this.start = start;
}
public int getQuest() {
return quest;
}
public boolean isStart() {
return start;
}
@Override
public void dispose() {
QuestScriptManager.getInstance().dispose(this, getClient());
}
public boolean forceStartQuest() {
return forceStartQuest(quest);
}
public boolean forceStartQuest(int id) {
return MapleQuest.getInstance(id).forceStart(getPlayer(), getNpc());
}
public boolean forceCompleteQuest() {
return forceCompleteQuest(quest);
}
// For compatability with some older scripts...
public void startQuest() {
forceStartQuest();
}
// For compatability with some older scripts...
public void completeQuest() {
forceCompleteQuest();
}
public boolean forceCompleteQuest(int id) {
return MapleQuest.getInstance(id).forceComplete(getPlayer(), getNpc());
}
}

View File

@@ -0,0 +1,164 @@
/*
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.quest;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.HashMap;
import java.util.Map;
import javax.script.Invocable;
import scripting.AbstractScriptManager;
import server.quest.MapleQuest;
import tools.FilePrinter;
import client.MapleClient;
import client.MapleQuestStatus;
/**
*
* @author RMZero213
*/
public class QuestScriptManager extends AbstractScriptManager {
private Map<MapleClient, QuestActionManager> qms = new HashMap<>();
private Map<MapleClient, Invocable> scripts = new HashMap<>();
private static QuestScriptManager instance = new QuestScriptManager();
public synchronized static QuestScriptManager getInstance() {
return instance;
}
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);
}
}
public void start(MapleClient c, byte mode, byte type, int selection) {
Invocable iv = scripts.get(c);
if (iv != null) {
try {
c.setClickedNPC();
iv.invokeFunction("start", mode, type, selection);
} catch (final UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", ute);
dispose(c);
} catch (final Throwable t) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", t);
dispose(c);
}
}
}
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);
}
}
public void end(MapleClient c, byte mode, byte type, int selection) {
Invocable iv = scripts.get(c);
if (iv != null) {
try {
c.setClickedNPC();
iv.invokeFunction("end", mode, type, selection);
} catch (final UndeclaredThrowableException ute) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", ute);
dispose(c);
} catch (final Throwable t) {
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", t);
dispose(c);
}
}
}
public void dispose(QuestActionManager qm, MapleClient c) {
qms.remove(c);
scripts.remove(c);
resetContext("quest/" + qm.getQuest() + ".js", c);
}
public void dispose(MapleClient c) {
QuestActionManager qm = qms.get(c);
if (qm != null) {
dispose(qm, c);
}
}
public QuestActionManager getQM(MapleClient c) {
return qms.get(c);
}
}

View File

@@ -0,0 +1,161 @@
/*
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.reactor;
import client.MapleClient;
import client.inventory.Equip;
import client.inventory.Item;
import client.inventory.MapleInventoryType;
import java.awt.Point;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import scripting.AbstractPlayerInteraction;
import server.MapleItemInformationProvider;
import server.life.MapleLifeFactory;
import server.life.MapleNPC;
import server.maps.MapMonitor;
import server.maps.MapleReactor;
import server.maps.ReactorDropEntry;
import tools.MaplePacketCreator;
/**
* @author Lerk
*/
public class ReactorActionManager extends AbstractPlayerInteraction {
private MapleReactor reactor;
private MapleClient client;
public ReactorActionManager(MapleClient c, MapleReactor reactor) {
super(c);
this.reactor = reactor;
this.client = c;
}
public void dropItems() {
dropItems(false, 0, 0, 0, 0);
}
public void dropItems(boolean meso, int mesoChance, int minMeso, int maxMeso) {
dropItems(meso, mesoChance, minMeso, maxMeso, 0);
}
public void dropItems(boolean meso, int mesoChance, int minMeso, int maxMeso, int minItems) {
List<ReactorDropEntry> chances = getDropChances();
List<ReactorDropEntry> items = new LinkedList<>();
int numItems = 0;
if (meso && Math.random() < (1 / (double) mesoChance)) {
items.add(new ReactorDropEntry(0, mesoChance, -1));
}
Iterator<ReactorDropEntry> iter = chances.iterator();
while (iter.hasNext()) {
ReactorDropEntry d = iter.next();
if (Math.random() < (1 / (double) d.chance)) {
numItems++;
items.add(d);
}
}
while (items.size() < minItems) {
items.add(new ReactorDropEntry(0, mesoChance, -1));
numItems++;
}
java.util.Collections.shuffle(items);
final Point dropPos = reactor.getPosition();
dropPos.x -= (12 * numItems);
for (ReactorDropEntry d : items) {
if (d.itemId == 0) {
int range = maxMeso - minMeso;
int displayDrop = (int) (Math.random() * range) + minMeso;
int mesoDrop = (displayDrop * client.getWorldServer().getMesoRate());
reactor.getMap().spawnMesoDrop(mesoDrop, dropPos, reactor, client.getPlayer(), false, (byte) 0);
} else {
Item drop;
MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
if (ii.getInventoryType(d.itemId) != MapleInventoryType.EQUIP) {
drop = new Item(d.itemId, (short) 0, (short) 1);
} else {
drop = ii.randomizeStats((Equip) ii.getEquipById(d.itemId));
}
reactor.getMap().spawnItemDrop(reactor, getPlayer(), drop, dropPos, false, false);
}
dropPos.x += 25;
}
}
private List<ReactorDropEntry> getDropChances() {
return ReactorScriptManager.getInstance().getDrops(reactor.getId());
}
public void spawnMonster(int id) {
spawnMonster(id, 1, getPosition());
}
public void createMapMonitor(int mapId, String portal) {
new MapMonitor(client.getChannelServer().getMapFactory().getMap(mapId), portal);
}
public void spawnMonster(int id, int qty) {
spawnMonster(id, qty, getPosition());
}
public void spawnMonster(int id, int qty, int x, int y) {
spawnMonster(id, qty, new Point(x, y));
}
private void spawnMonster(int id, int qty, Point pos) {
for (int i = 0; i < qty; i++) {
reactor.getMap().spawnMonsterOnGroudBelow(MapleLifeFactory.getMonster(id), pos);
}
}
public Point getPosition() {
Point pos = reactor.getPosition();
pos.y -= 10;
return pos;
}
public void spawnNpc(int npcId) {
spawnNpc(npcId, getPosition());
}
public void spawnNpc(int npcId, Point pos) {
MapleNPC npc = MapleLifeFactory.getNPC(npcId);
if (npc != null) {
npc.setPosition(pos);
npc.setCy(pos.y);
npc.setRx0(pos.x + 50);
npc.setRx1(pos.x - 50);
npc.setFh(reactor.getMap().getFootholds().findBelow(pos).getId());
reactor.getMap().addMapObject(npc);
reactor.getMap().broadcastMessage(MaplePacketCreator.spawnNPC(npc));
}
}
public MapleReactor getReactor() {
return reactor;
}
public void spawnFakeMonster(int id) {
reactor.getMap().spawnFakeMonsterOnGroundBelow(MapleLifeFactory.getMonster(id), getPosition());
}
}

View File

@@ -0,0 +1,115 @@
/*
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.reactor;
import client.MapleClient;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.script.Invocable;
import javax.script.ScriptException;
import scripting.AbstractScriptManager;
import server.maps.MapleReactor;
import server.maps.ReactorDropEntry;
import tools.DatabaseConnection;
import tools.FilePrinter;
/**
* @author Lerk
*/
public class ReactorScriptManager extends AbstractScriptManager {
private static ReactorScriptManager instance = new ReactorScriptManager();
private Map<Integer, List<ReactorDropEntry>> drops = new HashMap<>();
public synchronized static ReactorScriptManager getInstance() {
return instance;
}
public void act(MapleClient c, MapleReactor reactor) {
try {
ReactorActionManager rm = new ReactorActionManager(c, reactor);
Invocable iv = getInvocable("reactor/" + reactor.getId() + ".js", c);
if (iv == null) {
return;
}
engine.put("rm", rm);
iv.invokeFunction("act");
} catch (final ScriptException | NoSuchMethodException | NullPointerException e) {
FilePrinter.printError(FilePrinter.REACTOR + reactor.getId() + ".txt", e);
}
}
public List<ReactorDropEntry> getDrops(int rid) {
List<ReactorDropEntry> ret = drops.get(rid);
if (ret == null) {
ret = new LinkedList<>();
try {
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT itemid, chance, questid FROM reactordrops WHERE reactorid = ? AND chance >= 0")) {
ps.setInt(1, rid);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
ret.add(new ReactorDropEntry(rs.getInt("itemid"), rs.getInt("chance"), rs.getInt("questid")));
}
}
}
} catch (Throwable e) {
FilePrinter.printError(FilePrinter.REACTOR + rid + ".txt", e);
}
drops.put(rid, ret);
}
return ret;
}
public void clearDrops() {
drops.clear();
}
public void touch(MapleClient c, MapleReactor reactor) {
touching(c, reactor, true);
}
public void untouch(MapleClient c, MapleReactor reactor) {
touching(c, reactor, false);
}
public void touching(MapleClient c, MapleReactor reactor, boolean touching) {
try {
ReactorActionManager rm = new ReactorActionManager(c, reactor);
Invocable iv = getInvocable("reactor/" + reactor.getId() + ".js", c);
if (iv == null) {
return;
}
engine.put("rm", rm);
if (touching) {
iv.invokeFunction("touch");
} else {
iv.invokeFunction("untouch");
}
} catch (final ScriptException | NoSuchMethodException | NullPointerException ute) {
FilePrinter.printError(FilePrinter.REACTOR + reactor.getId() + ".txt", ute);
}
}
}