Yes bassoe, it's a FACTORY not a fucking handler. Idiot. Handler's are for packets.
MapleOxQuizFactory.java
MapleOxQuiz.javaCode:/*
* 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 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 net.sf.odinms.server;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import net.sf.odinms.provider.MapleData;
import net.sf.odinms.provider.MapleDataProvider;
import net.sf.odinms.provider.MapleDataProviderFactory;
import net.sf.odinms.provider.MapleDataTool;
//import net.sf.odinms.tools.StringUtil;
import net.sf.odinms.tools.Pair;
/**
*
* @author Bassoe
*/
public class MapleOxQuizFactory {
private static MapleDataProvider stringData = MapleDataProviderFactory.getDataProvider(new File(System.getProperty("net.sf.odinms.wzpath") + "/Etc.wz"));
public static String getOXQuestion(int imgdir, int id){
List<Pair<Integer, String>> itemPairs = new ArrayList<Pair<Integer, String>>();
MapleData itemsData;
itemsData = stringData.getData("OXQuiz.img").getChildByPath("" + imgdir + "");
MapleData itemFolder = itemsData.getChildByPath("" + id + "");
int itemId = Integer.parseInt(itemFolder.getName());
String itemName = MapleDataTool.getString("q", itemFolder, "NO-NAME");
itemPairs.add(new Pair<Integer, String>(itemId, itemName));
return itemPairs.toString();
}
public static int getOXAnswer(int imgdir, int id){
MapleData itemsData;
itemsData = stringData.getData("OXQuiz.img").getChildByPath("" + imgdir + "");
MapleData itemFolder = itemsData.getChildByPath("" + id + "");
int a = MapleDataTool.getInt(itemFolder.getChildByPath("a"));
return a;
}
public static String getOXExplain(int imgdir, int id){
List<Pair<Integer, String>> itemPairs = new ArrayList<Pair<Integer, String>>();
MapleData itemsData;
itemsData = stringData.getData("OXQuiz.img").getChildByPath("" + imgdir + "");
MapleData itemFolder = itemsData.getChildByPath("" + id + "");
int itemId = Integer.parseInt(itemFolder.getName());
String itemName = MapleDataTool.getString("d", itemFolder, "NO-NAME");
itemPairs.add(new Pair<Integer, String>(itemId, itemName));
return itemPairs.toString();
}
}
I broke most of my own copy to give you a half release. =)!Code:/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package net.sf.odinms.server;
import java.util.ArrayList;
import java.util.List;
import net.sf.odinms.client.MapleCharacter;
import net.sf.odinms.client.MapleStat;
import net.sf.odinms.server.maps.MapleMap;
import net.sf.odinms.tools.MaplePacketCreator;
import net.sf.odinms.tools.Pair;
/**
*
* @author Jay Estrella
*/
public class MapleOxQuiz {
private int round = 1;
private int question = 1;
private MapleMap map = null;
private long delay = 5 * 1000; // Default delay
private boolean isAnswered = false;
//private List<Pair<String, MapleOxQuiz>> allInstances = new ArrayList<Pair<String, MapleOxQuiz>>(); // can just use getMap().getOx()
private int expGain = 200; // WITHOUT Exp Rate.
public MapleOxQuiz(String ident, MapleMap map, int round, int question) {
this.map = map;
this.question = round;
this.round = question;
this.isAnswered = false;
//allInstances.add(new Pair<String, MapleOxQuiz>(ident, this));
}
public void scheduleOx(final MapleMap map) {
scheduleOx(map, delay);
}
public void scheduleOx(final MapleMap map, final long newDelay) {
TimerManager.getInstance().schedule(new Runnable() {
public void run() {
map.broadcastMessage(MaplePacketCreator.serverNotice(6, MapleOxQuizFactory.getOXQuestion(round, question)));
TimerManager.getInstance().schedule(new Runnable() {
public void run() {
for (MapleCharacter curChar : map.getCharacters()) {
if (isCorrectAnswer(curChar, map, MapleOxQuizFactory.getOXAnswer(round, question))) {
curChar.gainExp(expGain * curChar.getClient().getChannelServer().getExpRate(), true, false); // Multiply EXP Rate.
} else { // Kill player because I can.
curChar.setHp(0);
curChar.updateSingleStat(MapleStat.HP, 0);
}
}
}
}, 15 * 1000); // 15 Seconds to respond
}
}, newDelay);
}
public void doQuestion() {
doQuestion(1);
doQuestion(-Integer.MAX_VALUE);
}
public void doQuestion(int inc) {
question += inc;
}
public boolean isAnswered() {
return isAnswered;
}
public void setAnswered(boolean set) {
this.isAnswered = set;
}
public int getRound() {
return round;
}
public int getQuestion() {
return question;
}
public MapleMap getMap() {
return map;
}
}
Yes, this is a leak. I do hate you bassoe. :)
Credits to Bassoe for the factory
For people who want to finish it off for themselves(Mine is full) :
- code scheduleAnswer() Same as scheduleQuestion() except make it call handleAnswer();
- handleAnswer() Make it check the map's X/Y for the answer.
- Fix the XML bug inside of the Ox Quiz Map(Every XML has it broken, other then .55 I think.)
- Make a command/NPC to start Ox Quiz
To Start Ox Quiz :
- add MapleOxQuiz ox;
- add boolean isOx;
- Use the constructor to make a new OxQuiz then assign it to ox
- use getMap().getOx().scheduleQuestion();
- add a check to stop ox quiz after isOx is at false(Use scheduleQuestion())

