mirror of
https://github.com/moparisthebest/MoparClassic
synced 2024-12-21 15:08:50 -05:00
Changed .gitignore a bit...
Added config for OS level blocking. Moved Cache. Removed Quiz.
This commit is contained in:
parent
1d7ded4829
commit
3701ea7a2f
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,11 +1,11 @@
|
||||
.classpath
|
||||
.project
|
||||
*.jar
|
||||
rscd.jar
|
||||
ls.jar
|
||||
*.ipr
|
||||
*.iws
|
||||
*.iml
|
||||
*.class
|
||||
Client/
|
||||
bin
|
||||
build
|
||||
.*
|
||||
|
@ -7,13 +7,38 @@
|
||||
<property name="jar" location="rscd.jar" />
|
||||
<property name="settings" location="settings.ini" />
|
||||
<property name="quests" location="conf/server/quests" />
|
||||
<property name="scala-library.jar" value="lib/scala-library.jar" />
|
||||
|
||||
<target name="build">
|
||||
<delete file="${jar}" />
|
||||
<delete dir="${build}" />
|
||||
<mkdir dir="${build}" />
|
||||
<taskdef resource="scala/tools/ant/antlib.xml">
|
||||
<classpath>
|
||||
<pathelement location="lib/scala-compiler.jar" />
|
||||
<pathelement location="${scala-library.jar}" />
|
||||
</classpath>
|
||||
</taskdef>
|
||||
<scalac srcdir="${src}" destdir="${build}">
|
||||
<classpath>
|
||||
<pathelement location="${scala-library.jar}" />
|
||||
<pathelement location="${lib}/mina.jar" />
|
||||
<pathelement location="${lib}/xpp3.jar" />
|
||||
<pathelement location="${lib}/slf4j.jar" />
|
||||
<pathelement location="${lib}/pircbot.jar" />
|
||||
<pathelement location="${lib}/bsh.jar" />
|
||||
<pathelement location="${lib}/commons-collections-3.2.1.jar" />
|
||||
<pathelement location="${lib}/xstream.jar" />
|
||||
<pathelement location="${lib}/mysql-connector.jar" />
|
||||
<pathelement location="${lib}/hex-string.jar" />
|
||||
<pathelement location="${lib}/jmf.jar" />
|
||||
<pathelement path="${java.class.path}/" />
|
||||
</classpath>
|
||||
<include name="**/*.scala" />
|
||||
</scalac>
|
||||
<javac srcdir="${src}" destdir="${build}" debug="on" target="1.6">
|
||||
<classpath>
|
||||
<pathelement location="${scala-library.jar}" />
|
||||
<pathelement location="${lib}/mina.jar" />
|
||||
<pathelement location="${lib}/xpp3.jar" />
|
||||
<pathelement location="${lib}/slf4j.jar" />
|
||||
|
@ -30,6 +30,7 @@ public class Config {
|
||||
public static double expRate, subExpRate;
|
||||
|
||||
public static String[] pmods, mods, admins;
|
||||
public static String UNUSED_IP;
|
||||
|
||||
static {
|
||||
loadEnv();
|
||||
@ -77,6 +78,8 @@ public class Config {
|
||||
mods = props.getProperty("mods").replaceAll(", +", ",").split(",");
|
||||
admins = props.getProperty("admins").replaceAll(", +", ",").split(",");
|
||||
|
||||
UNUSED_IP = props.getProperty("unused-ip");
|
||||
|
||||
props.clear();
|
||||
|
||||
Constants.GameServer.MOTD = "@yel@Welcome to @whi@" + Config.SERVER_NAME + "@yel@ - World @whi@" + (Config.SERVER_NUM == 0 ? 2 : Config.SERVER_NUM) + " (" + (Config.members ? "P2P" : "F2P") + ")";
|
||||
|
@ -1,27 +0,0 @@
|
||||
package org.moparscape.msc.gs;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.collections.map.LRUMap;
|
||||
|
||||
/**
|
||||
* A basic cache backed by a {@link LRUMap}.
|
||||
*
|
||||
* @author CodeForFame
|
||||
*
|
||||
*/
|
||||
public class Cache<K, V> {
|
||||
|
||||
// Shitty commons and their failure to support generics...
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<K, V> cache = new LRUMap();
|
||||
|
||||
public V get(K key) {
|
||||
return cache.get(key);
|
||||
}
|
||||
|
||||
public void put(K key, V value) {
|
||||
cache.put(key, value);
|
||||
}
|
||||
|
||||
}
|
@ -14,6 +14,7 @@ import org.apache.mina.transport.socket.nio.SocketSessionConfig;
|
||||
import org.moparscape.msc.config.Config;
|
||||
import org.moparscape.msc.config.Constants;
|
||||
import org.moparscape.msc.gs.connection.RSCConnectionHandler;
|
||||
import org.moparscape.msc.gs.connection.filter.ConnectionFilter;
|
||||
import org.moparscape.msc.gs.core.GameEngine;
|
||||
import org.moparscape.msc.gs.core.LoginConnector;
|
||||
import org.moparscape.msc.gs.event.DelayedEvent;
|
||||
@ -21,209 +22,221 @@ import org.moparscape.msc.gs.event.SingleEvent;
|
||||
import org.moparscape.msc.gs.model.World;
|
||||
import org.moparscape.msc.gs.util.Logger;
|
||||
|
||||
|
||||
/**
|
||||
* The entry point for RSC server.
|
||||
*/
|
||||
public class Server {
|
||||
|
||||
/**
|
||||
* World instance
|
||||
*/
|
||||
private static World world = null;
|
||||
/**
|
||||
* World instance
|
||||
*/
|
||||
private static World world = null;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
String configFile = "world.xml";
|
||||
if (args.length > 0) {
|
||||
File f = new File(args[0]);
|
||||
if (f.exists()) {
|
||||
configFile = f.getName();
|
||||
}
|
||||
public static void main(String[] args) throws IOException {
|
||||
String configFile = "world.xml";
|
||||
if (args.length > 0) {
|
||||
File f = new File(args[0]);
|
||||
if (f.exists()) {
|
||||
configFile = f.getName();
|
||||
}
|
||||
}
|
||||
|
||||
if (args[2] != null && args[2].equalsIgnoreCase("no"))
|
||||
Constants.IRC.USE_IRC = false;
|
||||
|
||||
world = Instance.getWorld();
|
||||
world.wl.loadObjects();
|
||||
|
||||
Config.initConfig(configFile);
|
||||
World.initilizeDB();
|
||||
|
||||
Logger.println(Config.SERVER_NAME + " ["
|
||||
+ (Config.members ? "P2P" : "F2P") + "] "
|
||||
+ "Server starting up...");
|
||||
|
||||
server = new Server();
|
||||
}
|
||||
|
||||
|
||||
if (args[2] != null && args[2].equalsIgnoreCase("no"))
|
||||
Constants.IRC.USE_IRC = false;
|
||||
|
||||
world = Instance.getWorld();
|
||||
world.wl.loadObjects();
|
||||
private static Server server;
|
||||
|
||||
Config.initConfig(configFile);
|
||||
World.initilizeDB();
|
||||
|
||||
Logger.println(Config.SERVER_NAME + " [" + (Config.members ? "P2P" : "F2P") + "] " + "Server starting up...");
|
||||
|
||||
new Server();
|
||||
}
|
||||
|
||||
public static boolean isMembers() {
|
||||
return Config.members;
|
||||
}
|
||||
|
||||
/**
|
||||
* The SocketAcceptor
|
||||
*/
|
||||
private IoAcceptor acceptor;
|
||||
/**
|
||||
* The login server connection
|
||||
*/
|
||||
private LoginConnector connector;
|
||||
/**
|
||||
* The game engine
|
||||
*/
|
||||
private GameEngine engine;
|
||||
|
||||
public IoAcceptor getAcceptor() {
|
||||
return acceptor;
|
||||
}
|
||||
|
||||
public void setAcceptor(IoAcceptor acceptor) {
|
||||
this.acceptor = acceptor;
|
||||
}
|
||||
|
||||
public LoginConnector getConnector() {
|
||||
return connector;
|
||||
}
|
||||
|
||||
public void setConnector(LoginConnector connector) {
|
||||
this.connector = connector;
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
public void setRunning(boolean running) {
|
||||
this.running = running;
|
||||
}
|
||||
|
||||
public DelayedEvent getUpdateEvent() {
|
||||
return updateEvent;
|
||||
}
|
||||
|
||||
public void setUpdateEvent(DelayedEvent updateEvent) {
|
||||
this.updateEvent = updateEvent;
|
||||
}
|
||||
|
||||
public static World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public void setEngine(GameEngine engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the server running still?
|
||||
*/
|
||||
private boolean running;
|
||||
|
||||
/**
|
||||
* Update event - if the server is shutting down
|
||||
*/
|
||||
private DelayedEvent updateEvent;
|
||||
|
||||
/**
|
||||
* Creates a new server instance, which in turn creates a new engine and
|
||||
* prepares the server socket to accept connections.
|
||||
*/
|
||||
public Server() {
|
||||
running = true;
|
||||
world.setServer(this);
|
||||
try {
|
||||
Instance.getPluginHandler().initPlugins();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
public static boolean isMembers() {
|
||||
return Config.members;
|
||||
}
|
||||
try {
|
||||
connector = new LoginConnector();
|
||||
engine = new GameEngine();
|
||||
engine.start();
|
||||
while (!connector.isRegistered()) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
|
||||
acceptor = new SocketAcceptor(Runtime.getRuntime().availableProcessors() + 1, Executors.newCachedThreadPool());
|
||||
IoAcceptorConfig config = new SocketAcceptorConfig();
|
||||
config.setDisconnectOnUnbind(true);
|
||||
/**
|
||||
* The SocketAcceptor
|
||||
*/
|
||||
private IoAcceptor acceptor;
|
||||
/**
|
||||
* The login server connection
|
||||
*/
|
||||
private LoginConnector connector;
|
||||
/**
|
||||
* The game engine
|
||||
*/
|
||||
private GameEngine engine;
|
||||
|
||||
config.setThreadModel(ThreadModel.MANUAL);
|
||||
SocketSessionConfig ssc = (SocketSessionConfig) config.getSessionConfig();
|
||||
ssc.setSendBufferSize(10000);
|
||||
ssc.setReceiveBufferSize(10000);
|
||||
acceptor.bind(new InetSocketAddress(Config.SERVER_IP, Config.SERVER_PORT), new RSCConnectionHandler(engine), config);
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
public IoAcceptor getAcceptor() {
|
||||
return acceptor;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the game engine for this server
|
||||
*/
|
||||
public GameEngine getEngine() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
public LoginConnector getLoginConnector() {
|
||||
return connector;
|
||||
}
|
||||
|
||||
public boolean isInitialized() {
|
||||
return engine != null && connector != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kills the game engine and irc engine
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void kill() {
|
||||
Logger.print(Config.SERVER_NAME + " shutting down...");
|
||||
running = false;
|
||||
engine.emptyWorld();
|
||||
connector.kill();
|
||||
System.exit(0);
|
||||
|
||||
}
|
||||
|
||||
public boolean running() {
|
||||
return running;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown the server in 60 seconds
|
||||
*/
|
||||
public boolean shutdownForUpdate() {
|
||||
if (updateEvent != null) {
|
||||
return false;
|
||||
public void setAcceptor(IoAcceptor acceptor) {
|
||||
this.acceptor = acceptor;
|
||||
}
|
||||
updateEvent = new SingleEvent(null, 59000) {
|
||||
public void action() {
|
||||
kill();
|
||||
}
|
||||
};
|
||||
Instance.getDelayedEventHandler().add(updateEvent);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* MS till the server shuts down
|
||||
*/
|
||||
public int timeTillShutdown() {
|
||||
if (updateEvent == null) {
|
||||
return -1;
|
||||
public LoginConnector getConnector() {
|
||||
return connector;
|
||||
}
|
||||
return updateEvent.timeTillNextRun();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbinds the socket acceptor
|
||||
*/
|
||||
public void unbind() {
|
||||
try {
|
||||
acceptor.unbindAll();
|
||||
} catch (Exception e) {
|
||||
public void setConnector(LoginConnector connector) {
|
||||
this.connector = connector;
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
public void setRunning(boolean running) {
|
||||
this.running = running;
|
||||
}
|
||||
|
||||
public DelayedEvent getUpdateEvent() {
|
||||
return updateEvent;
|
||||
}
|
||||
|
||||
public void setUpdateEvent(DelayedEvent updateEvent) {
|
||||
this.updateEvent = updateEvent;
|
||||
}
|
||||
|
||||
public static World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public void setEngine(GameEngine engine) {
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the server running still?
|
||||
*/
|
||||
private boolean running;
|
||||
|
||||
/**
|
||||
* Update event - if the server is shutting down
|
||||
*/
|
||||
private DelayedEvent updateEvent;
|
||||
|
||||
/**
|
||||
* Creates a new server instance, which in turn creates a new engine and
|
||||
* prepares the server socket to accept connections.
|
||||
*/
|
||||
public Server() {
|
||||
running = true;
|
||||
world.setServer(this);
|
||||
try {
|
||||
Instance.getPluginHandler().initPlugins();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
connector = new LoginConnector();
|
||||
engine = new GameEngine();
|
||||
engine.start();
|
||||
while (!connector.isRegistered()) {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
|
||||
acceptor = new SocketAcceptor(Runtime.getRuntime()
|
||||
.availableProcessors() + 1, Executors.newCachedThreadPool());
|
||||
acceptor.getFilterChain().addFirst("connectionfilter",
|
||||
new ConnectionFilter());
|
||||
IoAcceptorConfig config = new SocketAcceptorConfig();
|
||||
config.setDisconnectOnUnbind(true);
|
||||
|
||||
config.setThreadModel(ThreadModel.MANUAL);
|
||||
SocketSessionConfig ssc = (SocketSessionConfig) config
|
||||
.getSessionConfig();
|
||||
ssc.setSendBufferSize(10000);
|
||||
ssc.setReceiveBufferSize(10000);
|
||||
acceptor.bind(new InetSocketAddress(Config.SERVER_IP,
|
||||
Config.SERVER_PORT), new RSCConnectionHandler(engine),
|
||||
config);
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the game engine for this server
|
||||
*/
|
||||
public GameEngine getEngine() {
|
||||
return engine;
|
||||
}
|
||||
|
||||
public LoginConnector getLoginConnector() {
|
||||
return connector;
|
||||
}
|
||||
|
||||
public boolean isInitialized() {
|
||||
return engine != null && connector != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kills the game engine and irc engine
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void kill() {
|
||||
Logger.print(Config.SERVER_NAME + " shutting down...");
|
||||
running = false;
|
||||
engine.emptyWorld();
|
||||
connector.kill();
|
||||
System.exit(0);
|
||||
|
||||
}
|
||||
|
||||
public boolean running() {
|
||||
return running;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown the server in 60 seconds
|
||||
*/
|
||||
public boolean shutdownForUpdate() {
|
||||
if (updateEvent != null) {
|
||||
return false;
|
||||
}
|
||||
updateEvent = new SingleEvent(null, 59000) {
|
||||
public void action() {
|
||||
kill();
|
||||
}
|
||||
};
|
||||
Instance.getDelayedEventHandler().add(updateEvent);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* MS till the server shuts down
|
||||
*/
|
||||
public int timeTillShutdown() {
|
||||
if (updateEvent == null) {
|
||||
return -1;
|
||||
}
|
||||
return updateEvent.timeTillNextRun();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbinds the socket acceptor
|
||||
*/
|
||||
public void unbind() {
|
||||
try {
|
||||
acceptor.unbindAll();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static Server getServer() {
|
||||
return server;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import org.moparscape.msc.config.Formulae;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.connection.PacketQueue;
|
||||
import org.moparscape.msc.gs.connection.RSCPacket;
|
||||
import org.moparscape.msc.gs.connection.filter.OSLevelBlocking;
|
||||
import org.moparscape.msc.gs.event.DelayedEvent;
|
||||
import org.moparscape.msc.gs.event.MiniEvent;
|
||||
import org.moparscape.msc.gs.model.ActiveTile;
|
||||
@ -96,12 +97,6 @@ public final class GameEngine extends Thread {
|
||||
return time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes incoming packets.
|
||||
*/
|
||||
private Map<String, Integer> written = Collections
|
||||
.synchronizedMap(new HashMap<String, Integer>());
|
||||
|
||||
/**
|
||||
* Constructs a new game engine with an empty packet queue.
|
||||
*/
|
||||
@ -208,6 +203,10 @@ public final class GameEngine extends Thread {
|
||||
private void processEvents() {
|
||||
eventHandler.doEvents();
|
||||
}
|
||||
|
||||
public DelayedEventHandler getEventHandler() {
|
||||
return eventHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirects system err
|
||||
@ -242,29 +241,7 @@ public final class GameEngine extends Thread {
|
||||
&& p.getID() != 77 && p.getID() != 0) {
|
||||
final String ip = player.getCurrentIP();
|
||||
// flagSession(session);
|
||||
if (!written.containsKey(ip)) {
|
||||
eventHandler.add(new DelayedEvent(null, 1800000) {
|
||||
|
||||
public void run() {
|
||||
written.remove(ip);
|
||||
try {
|
||||
Runtime.getRuntime().exec(
|
||||
"sudo /sbin/route delete " + ip);
|
||||
} catch (Exception err) {
|
||||
Logger.error(err);
|
||||
}
|
||||
}
|
||||
});
|
||||
try {
|
||||
// Runtime.getRuntime().exec(
|
||||
// "sudo /sbin/route add " + ip + " gw 127.0.0.1");
|
||||
} catch (Exception err) {
|
||||
Logger.error(err);
|
||||
}
|
||||
Logger.println("Dummy packet from " + player.getCurrentIP()
|
||||
+ ": " + p.getID());
|
||||
written.put(ip, 1);
|
||||
}
|
||||
OSLevelBlocking.block(ip);
|
||||
continue;
|
||||
}
|
||||
PacketHandler handler = packetHandlers.get(p.getID());
|
||||
|
@ -851,7 +851,7 @@ public final class Player extends Mob {
|
||||
}
|
||||
|
||||
public boolean canLogout() {
|
||||
if(this.location.inWilderness()) {
|
||||
if(this != null && this.location != null && this.location.inWilderness()) {
|
||||
if(GameEngine.getTime() - this.getLastMoved() < 10000) {
|
||||
getActionSender().sendMessage("You must stand peacefully in one place for 10 seconds!");
|
||||
return false;
|
||||
|
@ -1,15 +0,0 @@
|
||||
package org.moparscape.msc.gs.model.mini;
|
||||
|
||||
/**
|
||||
* Data each player gets cached.
|
||||
*
|
||||
* @author xEnt
|
||||
*
|
||||
*/
|
||||
public class CacheObject {
|
||||
|
||||
public boolean muted = false;
|
||||
public boolean inRed = false;
|
||||
public boolean inBlue = false;
|
||||
|
||||
}
|
@ -1,77 +1,77 @@
|
||||
package org.moparscape.msc.gs.model.mini;
|
||||
|
||||
/**
|
||||
* Damage values
|
||||
*
|
||||
* @author CodeForFame
|
||||
*
|
||||
*/
|
||||
public class Damage {
|
||||
|
||||
public static final int COMBAT_DAMAGE = 0;
|
||||
public static final int MAGIC_DAMAGE = 1;
|
||||
public static final int RANGE_DAMAGE = 2;
|
||||
|
||||
private final int[] damage = new int[3];
|
||||
|
||||
public Damage(final int damage, final int type) {
|
||||
this.addDamage(damage, type);
|
||||
}
|
||||
|
||||
public int getMagicDamage() {
|
||||
return damage[MAGIC_DAMAGE];
|
||||
}
|
||||
|
||||
public void setMagicDamage(final int damage) {
|
||||
this.damage[MAGIC_DAMAGE] = damage;
|
||||
}
|
||||
|
||||
public void addMagicDamage(final int damage) {
|
||||
this.damage[MAGIC_DAMAGE] += damage;
|
||||
}
|
||||
|
||||
public int getRangeDamage() {
|
||||
return this.damage[RANGE_DAMAGE];
|
||||
}
|
||||
|
||||
public void setRangeDamage(final int damage) {
|
||||
this.damage[RANGE_DAMAGE] = damage;
|
||||
}
|
||||
|
||||
public void addRangeDamage(final int damage) {
|
||||
this.damage[RANGE_DAMAGE] += damage;
|
||||
}
|
||||
|
||||
public int getCombatDamage() {
|
||||
return damage[COMBAT_DAMAGE];
|
||||
}
|
||||
|
||||
public void setCombatDamage(final int damage) {
|
||||
this.damage[COMBAT_DAMAGE] = damage;
|
||||
}
|
||||
|
||||
public void addCombatDamage(final int damage) {
|
||||
this.damage[COMBAT_DAMAGE] += damage;
|
||||
}
|
||||
|
||||
public void addDamage(final int damage, final int damageType) {
|
||||
// CBF typing out legit bounds checking...
|
||||
this.damage[damageType % 3] += damage;
|
||||
}
|
||||
|
||||
public int getTotalDamage() {
|
||||
return getCombatDamage() + getRangeDamage() + getMagicDamage();
|
||||
}
|
||||
|
||||
public double getRangePortion() {
|
||||
return getRangeDamage() / getTotalDamage();
|
||||
}
|
||||
|
||||
public double getMagicPortion() {
|
||||
return getMagicDamage() / getTotalDamage();
|
||||
}
|
||||
|
||||
public double getCombatPortion() {
|
||||
return getCombatDamage() / getTotalDamage();
|
||||
}
|
||||
}
|
||||
package org.moparscape.msc.gs.model.mini;
|
||||
|
||||
/**
|
||||
* Damage values
|
||||
*
|
||||
* @author CodeForFame
|
||||
*
|
||||
*/
|
||||
public class Damage {
|
||||
|
||||
public static final int COMBAT_DAMAGE = 0;
|
||||
public static final int MAGIC_DAMAGE = 1;
|
||||
public static final int RANGE_DAMAGE = 2;
|
||||
|
||||
private final int[] damage = new int[3];
|
||||
|
||||
public Damage(final int damage, final int type) {
|
||||
this.addDamage(damage, type);
|
||||
}
|
||||
|
||||
public int getMagicDamage() {
|
||||
return damage[MAGIC_DAMAGE];
|
||||
}
|
||||
|
||||
public void setMagicDamage(final int damage) {
|
||||
this.damage[MAGIC_DAMAGE] = damage;
|
||||
}
|
||||
|
||||
public void addMagicDamage(final int damage) {
|
||||
this.damage[MAGIC_DAMAGE] += damage;
|
||||
}
|
||||
|
||||
public int getRangeDamage() {
|
||||
return this.damage[RANGE_DAMAGE];
|
||||
}
|
||||
|
||||
public void setRangeDamage(final int damage) {
|
||||
this.damage[RANGE_DAMAGE] = damage;
|
||||
}
|
||||
|
||||
public void addRangeDamage(final int damage) {
|
||||
this.damage[RANGE_DAMAGE] += damage;
|
||||
}
|
||||
|
||||
public int getCombatDamage() {
|
||||
return damage[COMBAT_DAMAGE];
|
||||
}
|
||||
|
||||
public void setCombatDamage(final int damage) {
|
||||
this.damage[COMBAT_DAMAGE] = damage;
|
||||
}
|
||||
|
||||
public void addCombatDamage(final int damage) {
|
||||
this.damage[COMBAT_DAMAGE] += damage;
|
||||
}
|
||||
|
||||
public void addDamage(final int damage, final int damageType) {
|
||||
// CBF typing out legit bounds checking...
|
||||
this.damage[damageType % 3] += damage;
|
||||
}
|
||||
|
||||
public int getTotalDamage() {
|
||||
return getCombatDamage() + getRangeDamage() + getMagicDamage();
|
||||
}
|
||||
|
||||
public double getRangePortion() {
|
||||
return getRangeDamage() / getTotalDamage();
|
||||
}
|
||||
|
||||
public double getMagicPortion() {
|
||||
return getMagicDamage() / getTotalDamage();
|
||||
}
|
||||
|
||||
public double getCombatPortion() {
|
||||
return getCombatDamage() / getTotalDamage();
|
||||
}
|
||||
}
|
@ -1,261 +0,0 @@
|
||||
package org.moparscape.msc.gs.plugins.extras;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.swing.Timer;
|
||||
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.model.Player;
|
||||
import org.moparscape.msc.gs.model.World;
|
||||
import org.moparscape.msc.gs.util.Logger;
|
||||
|
||||
|
||||
public class Quiz extends Thread {
|
||||
|
||||
private static final int timeBetweenQuestions = 30; // Seconds.
|
||||
|
||||
static final World world = Instance.getWorld();
|
||||
|
||||
int phaze = 0;
|
||||
|
||||
int question = 0;
|
||||
// Question, Option1(A), Option2(B), Option3(C), Option4(D), Correct Option
|
||||
private final String[][] Quiz = { { "What is another name for sodium chloride?", "Salt", "Flour", "Sugar", "Oil", "a" }, { "What was Adam Sandler's first film called?", "Airheads", "Coneheads", "Going Overboard", "Happy Gilmore", "c" }, { "In terms of the ancient Roman empire, how was Nero related to Caligula?", "His Uncle", "His Brother", "His Nephew", "His Dad", "b" }, { "What do the Danish call Danish pastries?", "Danish Pastries", "Flatbread", "Viennese Bread", "Alsatian Cakes", "c" }, { "Which of these was once the national drink of Scotland?", "Claret", "Amaretto", "Vodka", "Scotch", "a" }, { "Which of the following was a predecessor of the Milky Way bar?", "Penny Plump", "Fat Emma", "Lardy Larry", "Milky Max", "b" }, { "Which is the deepest loch in Scotland?", "Loch Ness", "Loch Lomand", "Loch Morar", "Loch Ollie", "c" }, { "What was the first of Earth's supercontinents?", "Pangaea", "Gondwanaland", "Asia", "Rodinia", "d" }, { "In which country was the Can-Can invented?", "USA", "UK", "Canada", "England", "b" }, { "1987 saw the first Rugby Union World Cup. Who won it?", "New Zealand", "USA", "Fiji", "Japan", "a" }, { "What will a male lion often do in order to establish his authority when taking over a new pride?", "Kills The Lioness", "Mates and Leaves", "Kills the Cubs", "Hunts with the Pride", "c" }, { "Who is known as the father of modern day printing?", "Aristotle", "Mendel", "Theophrastus", "Gutenberg", "d" }, { "What group had the one hit wonder in the 90s by the name of 'Lovefool'?", "The Cardigans", "Creed", "The Coors", "Chumbawumba", "a" }, { "The color blue is said to represent which of the following emotions?", "Embarrassment", "Sadness", "Envy", "Anger", "b" }, { "Asteroids that are always closer to the Sun than the Earth are called?", "Argon", "Amor", "Aten", "Apollo", "c" }, { "During the Black Death, or Bubonic Plague, in mid 1300's Europe (approx.), what percentage of the population perished?", "One Tenth", "One Quarter", "One Third", "One Half", "c" }, { "What is the capital of Australia?", "Sydney", "Melbourne", "Canberra", "Liverpool", "c" }, { "A brogue is a type of what?", "Hat", "Shoe", "Guitar", "Shirt", "b" }, { "How many Wonders of the Ancient World were there?", "6", "7", "8", "9", "b" }, { "Which African nation did Winston Churchill once call 'the pearl of Africa?'", "Uganda", "Congo", "Chad", "Ethiopia", "a" }, { "What is the atomic number for Neon?", "1", "10", "30", "17", "b" }, { "An animal that eats only meat is called?", "A Canine", "An Omnivore", "A Carnivore", "None of the above", "c" }, { "According to the calendar of the time, when was Sir Isaac Newton born?", "November 4, 1642", "October 1, 1642", "December 25, 1642", "July 4, 1642", "c" }, { "Which fictional character lived in the Hundred Acre Wood?", "Winnie The Pooh", "Bambi", "Snow White", "Snoopy", "a" }, { "Which of the following does NOT Belong?", "Lincoln", "Mercury", "Ford", "Saturn", "d" }, { "Which of the following does NOT Belong?", "Pontiac", "Cadillac", "Hummer", "Mazda", "d" }, { "What does the term 'GUI' stands for?", "Graphics Unused Input", "Graphical User Interface", "Graphing Ultimate Interface", "Graph Unit Input", "b" }, { "In medicine, to examine a body part by listening to it is called what?", "Audiology", "Palpation", "Auscultation", "Radiology", "c" }, { "Of what is Botany the study?", "Plants", "Rocks", "Bugs", "Animals", "a" }, { "What element has a symbol on the periodic table that comes from the Latin word Aurum?", "Platinum", "Gold", "Silver", "Aluminum", "b" }, { "Which one of the following human bones is found in the wrist?", "Cochlea", "Cranium", "Femur", "Capitate", "d" }, { "", "", "", "", "", "" } // Leave
|
||||
// this
|
||||
// one
|
||||
// Blank.
|
||||
// It
|
||||
// won't
|
||||
// include. (Make sure its the last one)
|
||||
};
|
||||
|
||||
void endQuiz() {
|
||||
|
||||
try {
|
||||
// Clean's up the shit, reset's variables etc.
|
||||
|
||||
world.Quiz = false;
|
||||
world.QuizSignup = false;
|
||||
world.lastAnswer = null;
|
||||
|
||||
for (Player p : world.getPlayers()) {
|
||||
p.lastAnswer = null;
|
||||
p.hasAnswered = false;
|
||||
p.quizPoints = 0;
|
||||
}
|
||||
Logger.println("Destroying Thread, will create a stack.. ignore it.");
|
||||
Thread.currentThread().destroy();
|
||||
} catch (Exception e) {
|
||||
Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
void Error(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
public void handleAnswer(Player p) throws Exception {
|
||||
|
||||
if (!world.Quiz) {
|
||||
p.getActionSender().sendMessage("Sorry, It's not Quiz time just yet.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (p.hasAnswered) {
|
||||
p.getActionSender().sendMessage("You have already answered, please wait for the next question");
|
||||
return;
|
||||
}
|
||||
|
||||
p.hasAnswered = true;
|
||||
|
||||
if (p.lastAnswer.equalsIgnoreCase(world.lastAnswer)) {
|
||||
p.quizPoints++;
|
||||
}
|
||||
|
||||
p.getActionSender().sendMessage("You have answered @gre@(@whi@" + p.lastAnswer + "@gre@)");
|
||||
|
||||
p.lastAnswer = null;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* void removePlayer(Player p) throws Exception {
|
||||
*
|
||||
* try {
|
||||
*
|
||||
* int index = -1; for(int i=0; i < players.size(); i++) { if
|
||||
* (players.get(i).equals(p.getUsername())) index = i;
|
||||
*
|
||||
* if(i == -1) { Logging.debug("Error removing " + p.getUsername() +
|
||||
* " from the Quiz list."); return; } else { Logging.debug("[QUIZ] " +
|
||||
* players.get(index) + " has left the Quiz"); players.remove(index);
|
||||
* p.getActionSender().sendMessage("You have Quit the Quiz Queue"); } }
|
||||
*
|
||||
* } catch (Exception e) { Error(e); } }
|
||||
*/
|
||||
|
||||
/*
|
||||
* public void addPlayer(Player p) {
|
||||
*
|
||||
* try {
|
||||
*
|
||||
* if(!world.QuizSignup) return; if(p == null) return; if(!world.Quiz)
|
||||
* return; if(players.contains(p.getUsername())) return;
|
||||
*
|
||||
* players.add(p.getUsername());
|
||||
* p.getActionSender().sendMessage("You have Joined the Quiz Queue");
|
||||
*
|
||||
* } catch (Exception e) { Error(e); } }
|
||||
*/
|
||||
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
if (world.Quiz)
|
||||
return;
|
||||
|
||||
world.QuizSignup = true;
|
||||
world.Quiz = false;
|
||||
|
||||
sayAll("@red@[QUIZ]@whi@ Quiz will be starting in @gre@" + timeBetweenQuestions + " @whi@seconds. Write @gre@::quiz@whi@ to join the quiz.", false, false);
|
||||
sayAll("@red@[QUIZ]@whi@ You will have @gre@" + timeBetweenQuestions + "@whi@ seconds to lock in the answers of each quiz.", false, false);
|
||||
sayAll("@red@[QUIZ]@whi@ Quiz results are tally'd up at the end. Use ::a ::b ::c ::d to answer.", false, false);
|
||||
|
||||
ActionListener phaze1 = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
try {
|
||||
|
||||
if (phaze == 0) { // the start of the quiz.
|
||||
phaze++;
|
||||
}
|
||||
|
||||
if (phaze == 1) {
|
||||
world.Quiz = true;
|
||||
if (question == 999) {
|
||||
tallyQuiz();
|
||||
endQuiz();
|
||||
}
|
||||
|
||||
for (Player p : world.getPlayers())
|
||||
p.hasAnswered = false;
|
||||
|
||||
sayAll("@red@[QUIZ]@gre@ " + question + "/" + (Quiz.length) + "@yel@ " + Quiz[question][0] + " @cya@(A) @whi@" + Quiz[question][1] + " @cya@(B)@whi@ " + Quiz[question][2] + " @cya@(C)@whi@ " + Quiz[question][3] + " @cya@(D) @whi@ " + Quiz[question][4], true, true);
|
||||
sayAll("@red@[QUIZ]@gre@ " + question + "/" + (Quiz.length) + "@yel@ " + Quiz[question][0] + " @cya@(A) @whi@" + Quiz[question][1] + " @cya@(B)@whi@ " + Quiz[question][2] + " @cya@(C)@whi@ " + Quiz[question][3] + " @cya@(D) @whi@ " + Quiz[question][4], false, true);
|
||||
world.lastAnswer = Quiz[question][5];
|
||||
question++;
|
||||
if (question == Quiz.length)
|
||||
question = 999;
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
Error(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
Timer timer = new Timer(timeBetweenQuestions * 1000, phaze1);
|
||||
timer.start();
|
||||
|
||||
} catch (Exception e) {
|
||||
Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
void sayAll(String message, boolean Alert, boolean inQuiz) throws Exception {
|
||||
if (inQuiz) {
|
||||
ArrayList playersToSend = new ArrayList();
|
||||
Player p;
|
||||
for (Iterator i$ = world.getPlayers().iterator(); i$.hasNext(); playersToSend.add(p))
|
||||
p = (Player) i$.next();
|
||||
Player pl;
|
||||
for (Iterator i$ = playersToSend.iterator(); i$.hasNext();) {
|
||||
pl = (Player) i$.next();
|
||||
if (Alert && pl.inQuiz)
|
||||
pl.getActionSender().sendAlert(message, false);
|
||||
else if (!Alert && pl.inQuiz)
|
||||
pl.getActionSender().sendMessage(message);
|
||||
}
|
||||
} else {
|
||||
ArrayList playersToSend = new ArrayList();
|
||||
Player p;
|
||||
for (Iterator i$ = world.getPlayers().iterator(); i$.hasNext(); playersToSend.add(p))
|
||||
p = (Player) i$.next();
|
||||
Player pl;
|
||||
for (Iterator i$ = playersToSend.iterator(); i$.hasNext();) {
|
||||
pl = (Player) i$.next();
|
||||
if (Alert)
|
||||
pl.getActionSender().sendAlert(message, false);
|
||||
else
|
||||
pl.getActionSender().sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rofl.. couldent be fucked figuring out another way to do this at the
|
||||
// time.
|
||||
void tallyQuiz() {
|
||||
try {
|
||||
|
||||
String First = null;
|
||||
int first = -1;
|
||||
int second = -1;
|
||||
int third = -1;
|
||||
String Second = null;
|
||||
String Third = null;
|
||||
int temp = 0;
|
||||
int count = 0;
|
||||
for (Player p : world.getPlayers()) {
|
||||
if (p.quizPoints != 0)
|
||||
count++;
|
||||
|
||||
if (p.quizPoints >= temp) {
|
||||
temp = p.quizPoints;
|
||||
First = p.getUsername();
|
||||
first = temp;
|
||||
}
|
||||
}
|
||||
temp = 0;
|
||||
for (Player p : world.getPlayers()) {
|
||||
if (p.quizPoints >= temp && p.getUsername() != First) {
|
||||
temp = p.quizPoints;
|
||||
Second = p.getUsername();
|
||||
second = temp;
|
||||
}
|
||||
}
|
||||
temp = 0;
|
||||
for (Player p : world.getPlayers()) {
|
||||
if (p.quizPoints >= temp && (p.getUsername() != First && p.getUsername() != Second)) {
|
||||
temp = p.quizPoints;
|
||||
Third = p.getUsername();
|
||||
third = temp;
|
||||
}
|
||||
}
|
||||
sayAll("Thank you all for Playing, the Quiz is over. " + count + " Players submitted Answers.", false, true);
|
||||
sayAll("@yel@Your Quiz Winners Are: @whi@" + First + "@gre@(" + first + ")@whi@, " + Second + "@gre@(" + second + ")@whi@, " + Third + "(@gre@" + third + ")", true, true);
|
||||
sayAll("@yel@Your Quiz Winners Are: @whi@" + First + "@gre@(" + first + ")@whi@, " + Second + "@gre@(" + second + ")@whi@, " + Third + "(@gre@" + third + ")", false, true);
|
||||
|
||||
/**
|
||||
*
|
||||
* Add SQL Here.
|
||||
*
|
||||
*/
|
||||
|
||||
for (Player p : world.getPlayers()) {
|
||||
if (p.quizPoints != 0) {
|
||||
int points = p.quizPoints; // Each players total questions
|
||||
// correct from lsat round of
|
||||
// Quiz
|
||||
|
||||
// Code here for adding to SQL etc.
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user