Merge pull request #135 from Joe0/pre-beta

Progress towards Beta milestone
This commit is contained in:
CodeForFame 2012-03-14 15:40:30 -07:00
commit b239070e33
8 changed files with 350 additions and 353 deletions

View File

@ -401,17 +401,13 @@ public final class GameEngine extends Thread {
long startTime = System.currentTimeMillis();
int curMemory = (int) (Runtime.getRuntime().totalMemory() - Runtime
.getRuntime().freeMemory()) / 1000;
int tileObjs = 0;
int cleaned = 0;
for (int i = 0; i < Instance.getWorld().tiles.length; i++) {
for (int in = 0; in < Instance.getWorld().tiles[i].length; in++) {
ActiveTile tile = Instance.getWorld().tiles[i][in];
if (tile != null) {
tileObjs++;
if (!tile.hasGameObject() && !tile.hasItems()
&& !tile.hasNpcs() && !tile.hasPlayers()) {
Instance.getWorld().tiles[i][in] = null;
cleaned++;
}
}
}

View File

@ -3,11 +3,9 @@ package org.moparscape.msc.gs.model;
import java.util.ArrayList;
import java.util.ConcurrentModificationException;
import org.moparscape.msc.config.Config;
import org.moparscape.msc.config.Constants;
import org.moparscape.msc.config.Formulae;
import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.Server;
import org.moparscape.msc.gs.core.GameEngine;
import org.moparscape.msc.gs.event.DelayedEvent;
import org.moparscape.msc.gs.event.FightEvent;

View File

@ -1,6 +1,5 @@
package org.moparscape.msc.gs.npchandler;
import org.moparscape.msc.config.Formulae;
import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.event.ShortEvent;
import org.moparscape.msc.gs.model.ChatMessage;
@ -13,7 +12,7 @@ import org.moparscape.msc.gs.model.World;
* @author xEnt
*
*/
public class OtherNPC implements NpcHandler {
public class OtherNpc implements NpcHandler {
public static final World world = Instance.getWorld();

View File

@ -2,7 +2,6 @@ package org.moparscape.msc.gs.phandler;
import org.apache.mina.common.IoSession;
import org.moparscape.msc.config.Config;
import org.moparscape.msc.config.Constants;
import org.moparscape.msc.config.Formulae;
import org.moparscape.msc.gs.Instance;
import org.moparscape.msc.gs.builders.RSCPacketBuilder;
@ -44,7 +43,6 @@ public class PlayerLogin implements PacketHandler {
player.getSession().close();
return;
}
boolean newchar = false;
RSCPacketBuilder pb = new RSCPacketBuilder();
pb.setBare(true);
pb.addByte(loginCode);
@ -67,7 +65,6 @@ public class PlayerLogin implements PacketHandler {
int x = p.readShort();
@SuppressWarnings("unused")
int y = p.readShort();
newchar = true;
} else {
player.setLocation(
Point.location(p.readShort(), p.readShort()), true);

View File

@ -27,10 +27,19 @@ object CommandHandler {
var STUCK_X = 122
var STUCK_Y = 647
val towns = List[String]("varrock", "falador", "draynor", "portsarim", "karamja", "alkharid", "lumbridge", "edgeville", "castle").toArray
val townLocations = List[Point](Point.location(122, 509), Point.location(304, 542), Point.location(214, 632), Point.location(269, 643), Point.location(370, 685), Point.location(89, 693), Point.location(120, 648), Point.location(217, 449), Point.location(270, 352))
val towns = List[(String, Point)](
("varrock", Point.location(122, 509)),
("falador", Point.location(304, 542)),
("draynor", Point.location(214, 632)),
("portsarim", Point.location(269, 643)),
("karamja", Point.location(370, 685)),
("alkharid", Point.location(89, 693)),
("lumbridge", Point.location(120, 648)),
("edgeville", Point.location(217, 449)),
("castle", Point.location(270, 352))
)
var permissions: Map[String, Int] = new HashMap[String, Int]
var permissions : Map[String, Int] = new HashMap[String, Int]
private def load {
val config = XML.loadFile(Config.COMMAND_CONFIG)
@ -44,7 +53,7 @@ object CommandHandler {
STUCK_STAND_STILL_TIME = p(s \ "stuck-stand-still-time")
STUCK_X = p(s \ "stuck-x")
STUCK_Y = p(s \ "stuck-y")
def p(n: NodeSeq) = {
def p(n : NodeSeq) = {
Integer.parseInt(n.text)
}
}
@ -57,7 +66,7 @@ class CommandHandler extends PacketHandler {
import org.moparscape.msc.gs.phandler.client.{ CommandHandler => CH }
@throws(classOf[Exception])
def handleCommand(cmd: String, args: Array[String], p: Player) {
def handleCommand(cmd : String, args : Array[String], p : Player) {
val ls = Instance.getServer.getLoginConnector.getActionSender
val world = Instance.getWorld
@ -111,11 +120,11 @@ class CommandHandler extends PacketHandler {
p.setLastCommandUsed(GameEngine.getTime)
}
def help(p: Player) {
def help(p : Player) {
alert(p, "A list of commands is shown on the forums.")
}
def time(p: Player) {
def time(p : Player) {
import java.util.{ Calendar, GregorianCalendar, TimeZone }
val cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"))
@ -124,27 +133,27 @@ class CommandHandler extends PacketHandler {
message(p, "The current time in UTC (24 hour) is: " + hour24 + ":" + minutes)
}
def skull(p: Player, minutes: Int = 20) {
def skull(p : Player, minutes : Int = 20) {
p.addSkull(minutes * 60000)
}
def fatigue(p: Player) {
def fatigue(p : Player) {
p.setFatigue(100)
p.getActionSender.sendFatigue
message(p, "Your fatigue is now 100%")
}
def online(p: Player) {
def online(p : Player) {
p.getActionSender.sendOnlinePlayers
}
def inView(p: Player) {
def inView(p : Player) {
message(p, "@yel@Players In View: @whi@" +
(p.getViewArea.getPlayersInView.size) +
" @yel@NPCs In View: @whi@" + p.getViewArea.getNpcsInView.size)
}
def stuck(p: Player) {
def stuck(p : Player) {
if (GameEngine.getTime - p.getCurrentLogin < CH.STUCK_LOGIN_WAIT_PERIOD) {
p.getActionSender.sendMessage("You cannot do this after you have recently logged in")
return ;
@ -163,7 +172,7 @@ class CommandHandler extends PacketHandler {
}
}
def info(p: Player, args: Array[String], ls: LSMiscPacketBuilder) {
def info(p : Player, args : Array[String], ls : LSMiscPacketBuilder) {
if (args.length != 1) {
message(p, "Invalid args. Syntax: INFO name")
return ;
@ -171,7 +180,7 @@ class CommandHandler extends PacketHandler {
ls.requestPlayerInfo(p, DataConversions.usernameToHash(args(0)))
}
def info(p: Player, args: Array[String], world: World) {
def info(p : Player, args : Array[String], world : World) {
val p1 = world.getPlayer(DataConversions.usernameToHash(args(0)))
if (p1 == null) {
message(p, args(0) + " is offline?")
@ -182,7 +191,7 @@ class CommandHandler extends PacketHandler {
message(p, "Requesting info.. please wait")
}
def info_(p: Player, args: Array[String], world: World) {
def info_(p : Player, args : Array[String], world : World) {
if (args(0) != null) {
val p = world.getPlayer(DataConversions.usernameToHash(args(0)))
var line = "@red@DONT SHOW THIS TO PUBLIC! @gre@Last 75 (Casting) Intervals for @yel@ " + p.getUsername + ": @whi@"
@ -193,17 +202,15 @@ class CommandHandler extends PacketHandler {
}
}
def town(p: Player, args: Array[String]) {
def town(p : Player, args : Array[String]) {
val town = args(0);
if (town != null) {
for (i <- 0 to CH.towns.length)
if (town.equalsIgnoreCase(CH.towns(i))) {
p.teleport(CH.townLocations(i).getX, CH.townLocations(i).getY, false)
}
CH.towns.find(e => e._1 equalsIgnoreCase town) match {
case Some(x) => p.teleport(x._2.getX, x._2.getY, false)
case None =>
}
}
def ban(p: Player, args: Array[String], ls: LSMiscPacketBuilder) {
def ban(p : Player, args : Array[String], ls : LSMiscPacketBuilder) {
if (args.length != 1) {
message(p, "Invalid args. Syntax: ban name")
return ;
@ -211,7 +218,7 @@ class CommandHandler extends PacketHandler {
ls.banPlayer(p, DataConversions.usernameToHash(args(0)), true)
}
def unban(p: Player, args: Array[String], ls: LSMiscPacketBuilder) {
def unban(p : Player, args : Array[String], ls : LSMiscPacketBuilder) {
if (args.length != 1) {
message(p, "Invalid args. Syntax: unban name")
return ;
@ -219,7 +226,7 @@ class CommandHandler extends PacketHandler {
ls.banPlayer(p, DataConversions.usernameToHash(args(0)), false)
}
def quest(p: Player, args: Array[String]) {
def quest(p : Player, args : Array[String]) {
if (args.length < 2) {
message(p, "Invalid syntax! ::quest INDEX STAGE")
return ;
@ -229,7 +236,7 @@ class CommandHandler extends PacketHandler {
p.getActionSender.sendQuestInfo
}
def questPoints(p: Player, args: Array[String]) {
def questPoints(p : Player, args : Array[String]) {
if (args.length < 1) {
message(p, "Invalid syntax! ::questpoints POINTS");
return ;
@ -239,7 +246,7 @@ class CommandHandler extends PacketHandler {
p.getActionSender.sendQuestInfo;
}
def dumpData(p: Player, args: Array[String]) {
def dumpData(p : Player, args : Array[String]) {
import org.moparscape.msc.gs.db.DataManager
if (args.length != 1) {
@ -251,12 +258,12 @@ class CommandHandler extends PacketHandler {
DataManager.reportHandler.submitDupeData(username, usernameHash)
}
def shutdown(p: Player) {
def shutdown(p : Player) {
Logger.mod(p.getUsername + " shut down the server!");
Instance.getServer.kill
}
def update(p: Player, args: Array[String], world: World) {
def update(p : Player, args : Array[String], world : World) {
var reason = ""
if (args.length > 0) {
args foreach { s =>
@ -276,19 +283,19 @@ class CommandHandler extends PacketHandler {
}
}
def clearInv(p: Player) {
def clearInv(p : Player) {
p.getInventory.getItems.clear
p.getActionSender.sendInventory
}
def enableMultiThreading(p: Player) {
def enableMultiThreading(p : Player) {
import org.moparscape.msc.gs.core.ClientUpdater
ClientUpdater.threaded = !ClientUpdater.threaded
message(p, "Threaded client updater: " + ClientUpdater.threaded)
}
def ipban(p: Player, args: Array[String], world: World) {
def ipban(p : Player, args : Array[String], world : World) {
val hash = DataConversions.usernameToHash(args(0))
val itr = world.getPlayers.iterator
@ -304,24 +311,24 @@ class CommandHandler extends PacketHandler {
message(p, "No user found with the name " + args(0))
}
def unipban(p: Player, args: Array[String]) {
def unipban(p : Player, args : Array[String]) {
IPBanManager.unblock(args(0))
message(p, "Ban on " + args(0) + " removed.")
}
def reloadIPBans(p: Player) {
def reloadIPBans(p : Player) {
IPBanManager.reloadIPBans
message(p, "IP bans reloaded")
}
def say(p: Player, args: Array[String]) {
def say(p : Player, args : Array[String]) {
val it = Instance.getWorld.getPlayers.iterator
while (it.hasNext) {
message(it.next, "[Global]" + p.getUsername + ": " + args.mkString(" "))
}
}
def goto(p: Player, args: Array[String]) {
def goto(p : Player, args : Array[String]) {
if (args.length < 1) {
message(p, "Please specify who to go to.")
} else {
@ -335,7 +342,7 @@ class CommandHandler extends PacketHandler {
}
}
def item(p: Player, args: Array[String]) {
def item(p : Player, args : Array[String]) {
import org.moparscape.msc.gs.model.InvItem
import org.moparscape.msc.gs.model.definition.EntityHandler
if (args.length < 1 || args.length > 2) {
@ -359,22 +366,22 @@ class CommandHandler extends PacketHandler {
// Helper methods
def message(p: Player, msg: String) {
def message(p : Player, msg : String) {
p.getActionSender.sendMessage(msg)
}
def alert(p: Player, msg: String) {
def alert(p : Player, msg : String) {
p.getActionSender.sendAlert(msg, true)
}
def alert(p: Player, msg: String, big: Boolean) {
def alert(p : Player, msg : String, big : Boolean) {
p.getActionSender.sendAlert(msg, big)
}
// Overriden methods
@throws(classOf[Exception])
override def handlePacket(p: Packet, session: IoSession) {
override def handlePacket(p : Packet, session : IoSession) {
val player = session.getAttachment.asInstanceOf[Player]
if (player.isBusy) {
player.resetPath
@ -392,7 +399,7 @@ class CommandHandler extends PacketHandler {
try {
handleCommand(cmd.toLowerCase, args, player)
} catch {
case e: Exception => e.printStackTrace
case e : Exception => e.printStackTrace
}
}
}

View File

@ -56,21 +56,6 @@ public class InvActionHandler implements PacketHandler {
+ item.getDef().getCommand()
+ "] at: " + player.getX() + "/" + player.getY()));
if (item.getID() == 1263) {
// player.resetPath(); // This isn't how it's done in RSC
// player.setBusy(true); // Shouldn't be here
player.getActionSender()
.sendMessage("You rest in the sleeping bag");
showBubble(player, item);
player.getActionSender().sendEnterSleep();
// player.setFatigue(0);
// player.getActionSender().sendFatigue();
// player.getActionSender().sendMessage("You wake up - feeling refreshed");
// player.isSleeping = true;
// player.setBusy(false);
return;
}
if (player.isBusy()) {
if (player.inCombat()) {
player.getActionSender().sendMessage(
@ -80,6 +65,22 @@ public class InvActionHandler implements PacketHandler {
}// sip
player.resetAll();
if (item.getID() == 1263) {
// player.resetPath(); // This isn't how it's done in RSC
// player.setBusy(true); // Shouldn't be here
player.getActionSender()
.sendMessage("You rest in the sleeping bag");
showBubble(player, item);
player.getActionSender().sendEnterSleep();
player.setSleeping(true);
// player.setFatigue(0);
// player.getActionSender().sendFatigue();
// player.getActionSender().sendMessage("You wake up - feeling refreshed");
// player.isSleeping = true;
// player.setBusy(false);
return;
}
if (World.getQuestManager().handleUseItem(item, player))
return;
if (item.getDef().getCommand().equalsIgnoreCase("identify")) {

View File

@ -327,9 +327,8 @@ public class ObjectAction implements PacketHandler {
}
});
}// create a
else if (object.getID() == 52
|| object.getID() == 173
&& object.containsItem() == 29) // hopper
else if ((object.getID() == 52 || object.getID() == 173) // hopper
&& object.containsItem() == 29) // Ensure it contains grain
{
owner.getActionSender().sendMessage(
"You operate the hopper..");

View File

@ -148,7 +148,7 @@ public class TalkToNpcHandler implements PacketHandler {
owner.getInterpreterThread().start();
} else {
try {
NpcHandler hand = new org.moparscape.msc.gs.npchandler.OtherNPC();
NpcHandler hand = new org.moparscape.msc.gs.npchandler.OtherNpc();
hand.handleNpc(affectedNpc, owner);
} catch (Exception e) {
Logger.error("Exception with npc["