import java.io.PrintStream;
import java.io.FileOutputStream;
import java.net.Socket;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
+import java.util.Optional;
import java.util.Properties;
/**
public Log log;
//Prefs:
public int port = 7400,
- trackerport = 7401,
- maxconnections = 0,
- petcost = 100,
- merchantimage,
- signimage,
- battlesound = -1,
- mobrespawnspeed,
- viewrange = 5,
- oldviewrange = 0,
- mapsize = 11,
- titlecap = 0,
- noChannelMax = 600, // defalut 600=10 minutes
- namecap = 20, //default 20
- messagecap = 120, //default 120
- changeRaceCpLimit = 100, //default 100cp
- logLevel = Log.ERROR,
- traincost = 100,
- expgainmod = 10;
+ trackerport = 7401,
+ maxconnections = 0,
+ petcost = 100,
+ merchantimage,
+ signimage,
+ battlesound = -1,
+ mobrespawnspeed,
+ viewrange = 5,
+ oldviewrange = 0,
+ mapsize = 11,
+ titlecap = 0,
+ noChannelMax = 600, // defalut 600=10 minutes
+ namecap = 20, //default 20
+ messagecap = 120, //default 120
+ changeRaceCpLimit = 100, //default 100cp
+ logLevel = Log.ERROR,
+ traincost = 100,
+ expgainmod = 10;
double gplosemod = 1D / 16D, //default 1/16
- explosemod = 1D / 16D,
- gpfleemod = 1D / 64D, //default 1/64
- expfleemod = 1D / 64D;
+ explosemod = 1D / 16D,
+ gpfleemod = 1D / 64D, //default 1/64
+ expfleemod = 1D / 64D;
public long lngMobTicks = 1000, //default 1000 milliseconds(1 second) per tick
- lngPlayerTicks = 250, //default 250 milliseconds(1/4 second) per tick
- floodLimit = 1000; //default 1000 milliseconds(1 second) btw messages
+ lngPlayerTicks = 250, //default 250 milliseconds(1/4 second) per tick
+ floodLimit = 1000; //default 1000 milliseconds(1 second) btw messages
public String trackername = "Just Some World.",
- site = "none",
- strRCAddress,
- strRCName,
- strLogFile = null,
- strMusicAddress;
+ site = "none",
+ strRCAddress,
+ strRCName,
+ strLogFile = null,
+ strMusicAddress;
public boolean blnMusic = false,
- blnLineOfSight = false,
- blnAI = false,
- blnIPF = false,
- tracker = true,
- blnSavingGame = false,
- blnShuttingDown = false;
+ blnLineOfSight = false,
+ blnAI = false,
+ blnIPF = false,
+ tracker = true,
+ blnSavingGame = false,
+ blnShuttingDown = false;
// FIXME: Not public
public Script scrCanSeeLivingThing = null,
- scrCanMoveThroughLivingThing = null,
- scrCanAttack = null,
- scrOnStart = null,
- scrOnDeath = null,
- scrOnLogOut = null;
+ scrCanMoveThroughLivingThing = null,
+ scrCanAttack = null,
+ scrOnStart = null,
+ scrOnDeath = null,
+ scrOnLogOut = null;
//End Prefs
public final static String version = "3.0 dev";
public final Date datStart = new Date(System.currentTimeMillis());
final private HashMap<String, Integer> failureAddress = new HashMap<>();
private long nextid = 0;
boolean blnVariableListChanged = false,
- blnMapHasChanged = false,
- blnMobListChanged = false,
- blnSignListChanged = false,
- blnMerchantListChanged = false,
- blnPropListChanged = false;
+ blnMapHasChanged = false,
+ blnMobListChanged = false,
+ blnSignListChanged = false,
+ blnMerchantListChanged = false,
+ blnPropListChanged = false;
public DuskEngine() {
RandomAccessFile rafFile = null;
try {
int x = 0,
- y = 0;
+ y = 0;
String line;
loadPrefs();
// Load Map
File newmap = new File("defMaps");
if (newmap.exists()) {
- for (File mapfile : newmap.listFiles()) {
+ for (File mapfile: newmap.listFiles()) {
TileMap map;
log.printMessage(Log.INFO, "Loading Layered Maps...");
map = TileMap.loadLayered(mapfile);
}
rafFile.close();
}*/
-
// FIXME: use some sort of common file format or at least conventions
// between all these state files.
-
// Load Merchants
+ // FIXME: better version handling
+ int fmt = 0;
try {
rafFile = new RandomAccessFile("merchants", "r");
Merchant mrcStore;
log.printMessage(Log.INFO, "Loading Merchants...");
line = rafFile.readLine();
while (!(line == null || line.equals(""))) {
+ log.printMessage(Log.VERBOSE, "merchant: " + fmt + " " + line);
+ String mapname;
+ int locx, locy;
+ if (fmt == 0) {
+ mapname = line;
+ if (maps.containsKey(mapname)) {
+ locx = Integer.parseInt(rafFile.readLine());
+ fmt = 2;
+ } else {
+ locx = Integer.parseInt(mapname);
+ mapname = "main";
+ fmt = 1;
+ }
+ locy = Integer.parseInt(rafFile.readLine());
+ } else if (fmt == 1) {
+ mapname = "main";
+ locx = Integer.parseInt(line);
+ locy = Integer.parseInt(rafFile.readLine());
+ } else {
+ mapname = line;
+ locx = Integer.parseInt(rafFile.readLine());
+ locy = Integer.parseInt(rafFile.readLine());
+ }
mrcStore = new Merchant(this);
- TileMap map = maps.get(line);
- mrcStore.x = Integer.parseInt(rafFile.readLine());
- mrcStore.y = Integer.parseInt(rafFile.readLine());
- log.printMessage(Log.VERBOSE, "Merchant(" + mrcStore.x + "," + mrcStore.y + ")");
+ mrcStore.map = maps.get(mapname);
+ mrcStore.x = locx;
+ mrcStore.y = locy;
+ log.printMessage(Log.VERBOSE, "Merchant(" + mapname + "@" + mrcStore.x + "," + mrcStore.y + ")");
line = rafFile.readLine();
while (line != null && !line.equals("") && !line.equalsIgnoreCase("end")) {
log.printMessage(Log.DEBUG, "\t" + line);
mrcStore.items.add(line);
line = rafFile.readLine();
}
- if (!map.inside(mrcStore.x, mrcStore.y)) {
+ if (!mrcStore.map.inside(mrcStore.x, mrcStore.y)) {
log.printMessage(Log.VERBOSE, "Previous merchant is off of the map, ignoring");
blnMerchantListChanged = true;
} else {
// map
// x
// y
- if (line.equals("mob")) {
+ if (line.equals("mob") || line.equals("mob2.3")) {
try {
String mobtype = rafFile.readLine();
- String mapname = rafFile.readLine();
+ String mapname = line.equals("mob") ? rafFile.readLine() : "main";
int locx = Integer.parseInt(rafFile.readLine());
int locy = Integer.parseInt(rafFile.readLine());
TileMap map = maps.get(mapname);
thnStore = new Mob(mobtype,
- locx,
- locy,
- this);
+ locx,
+ locy,
+ this);
if (!map.inside(thnStore.x, thnStore.y)) {
log.printMessage(Log.VERBOSE, "Previous mob is off of the map, ignoring");
// Load signs
Sign sgnStore;
+ fmt = 0;
rafFile = new RandomAccessFile("signs", "r");
log.printMessage(Log.INFO, "Loading Signs...");
line = rafFile.readLine();
while (!(line == null || line.equals(""))) {
- String mapname = rafFile.readLine();
- int locx = Integer.parseInt(rafFile.readLine());
- int locy = Integer.parseInt(rafFile.readLine());
+ String mapname;
+ int locx, locy;
+ if (fmt == 0) {
+ mapname = rafFile.readLine();
+ if (maps.containsKey(mapname)) {
+ locx = Integer.parseInt(rafFile.readLine());
+ fmt = 2;
+ } else {
+ locx = Integer.parseInt(mapname);
+ mapname = "main";
+ fmt = 1;
+ }
+ locy = Integer.parseInt(rafFile.readLine());
+ } else {
+ mapname = fmt == 1 ? "main" : rafFile.readLine();
+ locx = Integer.parseInt(rafFile.readLine());
+ locy = Integer.parseInt(rafFile.readLine());
+ }
TileMap map = maps.get(mapname);
log.printMessage(Log.VERBOSE, line);
sgnStore = new Sign(this, "sign", line, locx, locy, getID());
rafFile = new RandomAccessFile("props", "r");
log.printMessage(Log.INFO, "Loading Props...");
line = rafFile.readLine();
+ fmt = 0;
while (!(line == null || line.equals(""))) {
- String mapname = rafFile.readLine();
- int locx = Integer.parseInt(rafFile.readLine());
- int locy = Integer.parseInt(rafFile.readLine());
+ String mapname;
+ int locx, locy;
+ if (fmt == 0) {
+ mapname = rafFile.readLine();
+ if (maps.containsKey(mapname)) {
+ locx = Integer.parseInt(rafFile.readLine());
+ fmt = 2;
+ } else {
+ locx = Integer.parseInt(mapname);
+ mapname = "main";
+ fmt = 1;
+ }
+ locy = Integer.parseInt(rafFile.readLine());
+ } else {
+ mapname = fmt == 1 ? "main" : rafFile.readLine();
+ locx = Integer.parseInt(rafFile.readLine());
+ locy = Integer.parseInt(rafFile.readLine());
+ }
TileMap map = maps.get(mapname);
log.printMessage(Log.VERBOSE, line);
while (!(strVarName == null || strVarName.equals(""))) {
intType = Integer.parseInt(rafFile.readLine());
switch (intType) {
- case 0: {
- dblObject = (double) Double.parseDouble(rafFile.readLine());
- varVariables.addVariable(strVarName, dblObject);
- log.printMessage(Log.VERBOSE, strVarName + " = " + dblObject);
- break;
- }
- case 1: {
- strObject = rafFile.readLine();
- varVariables.addVariable(strVarName, strObject);
- log.printMessage(Log.VERBOSE, strVarName + " = '" + strObject + "'");
- break;
- }
+ case 0: {
+ dblObject = (double)Double.parseDouble(rafFile.readLine());
+ varVariables.addVariable(strVarName, dblObject);
+ log.printMessage(Log.VERBOSE, strVarName + " = " + dblObject);
+ break;
+ }
+ case 1: {
+ strObject = rafFile.readLine();
+ varVariables.addVariable(strVarName, strObject);
+ log.printMessage(Log.VERBOSE, strVarName + " = '" + strObject + "'");
+ break;
+ }
}
strVarName = rafFile.readLine();
}
return false;
}
if (strName.equals("")
- || strName.length() > namecap
- || strName.toLowerCase().equals("god")
- || strName.toLowerCase().equals("default")) {
+ || strName.length() > namecap
+ || strName.toLowerCase().equals("god")
+ || strName.toLowerCase().equals("default")) {
return false;
}
if (viewrange != oldviewrange) {
oldviewrange = viewrange;
mapsize = 1 + (2 * viewrange);
- for (LivingThing thnStore : playersByName.values()) {
+ for (LivingThing thnStore: playersByName.values()) {
thnStore.initMap();
}
}
// FIXME: all this 'synchronized' stuff is busted to shit, you can't lock on something
// that might be null or will be replaced by a new object.
-
try {
if (scrCanSeeLivingThing != null) {
synchronized (scrCanSeeLivingThing) {
try (FileInputStream fis = new FileInputStream(f)) {
props.load(fis);
- for (Entry e : props.entrySet()) {
- String key = (String) e.getKey();
- String val = (String) e.getValue();
+ for (Entry e: props.entrySet()) {
+ String key = (String)e.getKey();
+ String val = (String)e.getValue();
HashMap<Integer, Script> target = null;
String path = null;
void loadTileScripts(HashMap<Integer, Script> scripts, String path) {
try {
int i;
- for (Script s : scripts.values()) {
+ for (Script s: scripts.values()) {
s.close();
}
scripts.clear();
public void chatMessage(String msg, String from) {
from = from.toLowerCase();
log.printMessage(Log.ALWAYS, msg);
- for (LivingThing lt : playersByName.values()) {
+ for (LivingThing lt: playersByName.values()) {
if (!lt.ignoreList.contains(from)) {
lt.chatMessage(msg);
}
LivingThing thnStore;
log.printMessage(Log.ALWAYS, inMessage);
- for (TileMap.MapData md : map.range(locx, locy, viewrange)) {
- for (DuskObject o : md.entities) {
+ for (TileMap.MapData md: map.range(locx, locy, viewrange)) {
+ for (DuskObject o: md.entities) {
if (o.isLivingThing()) {
- thnStore = (LivingThing) o;
+ thnStore = (LivingThing)o;
if (thnStore.isPlayer()
- && !thnStore.ignoreList.contains(strFrom)) {
+ && !thnStore.ignoreList.contains(strFrom)) {
thnStore.chatMessage(inMessage);
}
}
public void chatMessage(String msg, String clan, String from) {
from = from.toLowerCase();
log.printMessage(Log.ALWAYS, msg);
- for (LivingThing lt : playersByName.values()) {
+ for (LivingThing lt: playersByName.values()) {
if (lt.clan.equals(clan)
- && !lt.ignoreList.contains(from)) {
+ && !lt.ignoreList.contains(from)) {
lt.chatMessage(msg);
}
}
public void refreshEntities(LivingThing refresh) {
LinkedList<DuskObject> newEntities = new LinkedList<>();
- for (TileMap.MapData md : refresh.map.range(refresh.x, refresh.y, viewrange)) {
+ for (TileMap.MapData md: refresh.map.range(refresh.x, refresh.y, viewrange)) {
if (!md.entities.isEmpty()
- && canSeeTo(refresh, md.x, md.y)) {
- for (DuskObject o : md.entities) {
+ && canSeeTo(refresh, md.x, md.y)) {
+ for (DuskObject o: md.entities) {
newEntities.add(o);
//old = thnRefresh.removeEntity(objStore.ID);
//for (i4 = 0; i4 < thnRefresh.nearEntities.size(); i4++) {
// }
//}
if (o.isPlayerMerchant()) {
- PlayerMerchant shop = (PlayerMerchant) o;
+ PlayerMerchant shop = (PlayerMerchant)o;
if (refresh.x == shop.x && refresh.y == shop.y) {
TransactionMessage tm = new TransactionMessage(MSG_UPDATE_MERCHANT);
- for (String name : shop.vctItems.keySet()) {
+ for (String name: shop.vctItems.keySet()) {
LinkedList<Item> vctStore = shop.vctItems.get(name);
- Item item = (Item) vctStore.element();
+ Item item = (Item)vctStore.element();
int intCost = (item.intCost * 3) / 4;
if (refresh.name.equalsIgnoreCase(shop.strOwner)) {
}
}
if (o.isMerchant()) {
- Merchant merchant = (Merchant) o;
+ Merchant merchant = (Merchant)o;
if (refresh.x == merchant.x && refresh.y == merchant.y) {
HashMap<String, TransactionItem> items = new HashMap<>();
- for (String itemname : merchant.items) {
+ for (String itemname: merchant.items) {
TransactionItem titem = items.get(itemname);
if (titem == null) {
Item item = getItem(itemname);
// FIXME: move to map or livingthing?
@Deprecated
public void addEntity(TileMap map, DuskObject add) {
- for (TileMap.MapData md : map.range(add.x, add.y, viewrange)) {
- for (DuskObject o : md.entities) {
+ for (TileMap.MapData md: map.range(add.x, add.y, viewrange)) {
+ for (DuskObject o: md.entities) {
if (o.isLivingThing()) {
- LivingThing lt = (LivingThing) o;
+ LivingThing lt = (LivingThing)o;
if (lt.isPlayer()) {
// FIXME: see if this can be merged with updateEntity() above
if (canSeeTo(lt, add.x, add.y)) {
if ((!add.isLivingThing()
- || canSeeLivingThing(lt, (LivingThing) add))) {
+ || canSeeLivingThing(lt, (LivingThing)add))) {
lt.addEntity(add);
}
}
public void cleanup() {
log.printMessage(Log.INFO, "Starting cleanup.");
- for (TileMap map : maps.values()) {
- for (TileMap.MapData md : map) {
- for (DuskObject o : md.entities) {
+ for (TileMap map: maps.values()) {
+ for (TileMap.MapData md: map) {
+ for (DuskObject o: md.entities) {
if (o.isLivingThing()) {
- LivingThing lt = (LivingThing) o;
+ LivingThing lt = (LivingThing)o;
if (lt.isPlayer()) {
if (!playersByName.containsKey(lt.name)) {
log.printMessage(Log.INFO, "**found defunct player at " + md.x + "," + md.y + " during cleanup.");
// FIXME: Move to map?
@Deprecated
void notifyRemoved(DuskObject remove) {
- for (TileMap.MapData md : remove.map.range(remove.x, remove.y, viewrange)) {
- for (DuskObject o : md.entities) {
+ for (TileMap.MapData md: remove.map.range(remove.x, remove.y, viewrange)) {
+ for (DuskObject o: md.entities) {
if (o.isLivingThing()) {
- LivingThing lt = (LivingThing) o;
+ LivingThing lt = (LivingThing)o;
if (lt.isPlayer()) {
if (canSeeTo(lt, remove.x, remove.y)) {
int i;
Sign sgnStore;
for (i = 0; i < signList.size(); i++) {
- sgnStore = (Sign) signList.get(i);
+ sgnStore = (Sign)signList.get(i);
if (inName.equals(sgnStore.name)) {
return sgnStore;
}
public LivingThing getPet(String name) {
// FIXME: hash map?
- for (LivingThing pet : petList) {
+ for (LivingThing pet: petList) {
if (name.equalsIgnoreCase(pet.name)) {
return pet;
}
public Faction getFaction(String name) {
Faction faction;
-
- faction = factionMap.get(name);
+ String key = name.toLowerCase();
+ faction = factionMap.get(key);
if (faction == null) {
faction = new Faction(name, this);
- factionMap.put(name, faction);
+ factionMap.put(key, faction);
}
return faction;
}
public LivingThing getMobFromVct(String inName) {
// FIXME: hash map?
synchronized (mobList) {
- for (Mob mob : mobList) {
+ for (Mob mob: mobList) {
if (mob.name.equals(inName)) {
return mob;
}
Prop getProp(String strName) {
Prop prpStore = null;
try {
- RandomAccessFile rafPropDef = new RandomAccessFile("defProps/" + strName, "r");
- prpStore = new Prop(getID(), strName);
- String strStore = rafPropDef.readLine();
- while (!(strStore == null || strStore.equals("."))) {
- if (strStore.equalsIgnoreCase("description")) {
- prpStore.description = rafPropDef.readLine();
- } else if (strStore.equalsIgnoreCase("image")) {
- prpStore.intImage = Integer.parseInt(rafPropDef.readLine());
- }
- strStore = rafPropDef.readLine();
- }
- rafPropDef.close();
+ String key = strName.toLowerCase();
+ Optional<Path> path = Files.find(Path.of("defProps"), 1, (t, a) -> t.getFileName().toString().toLowerCase().equals(key)).findAny();
+ if (path.isPresent()) {
+ RandomAccessFile rafPropDef = new RandomAccessFile(path.get().toFile(), "r");
+ prpStore = new Prop(getID(), strName);
+ String strStore = rafPropDef.readLine();
+ while (!(strStore == null || strStore.equals("."))) {
+ if (strStore.equalsIgnoreCase("description")) {
+ prpStore.description = rafPropDef.readLine();
+ } else if (strStore.equalsIgnoreCase("image")) {
+ prpStore.intImage = Integer.parseInt(rafPropDef.readLine());
+ }
+ strStore = rafPropDef.readLine();
+ }
+ rafPropDef.close();
+ } else {
+ throw new FileNotFoundException("defProps/" + key);
+ }
} catch (Exception e) {
log.printError("getProp():While trying to get prop \"" + strName + "\"", e);
}
int i = 0;
Prop prpStore;
while (true) {
- prpStore = (Prop) propList.get(i);
+ prpStore = (Prop)propList.get(i);
if (prpStore.name.equals(inName)) {
return prpStore;
}
int i = 0;
Prop prpStore;
while (true) {
- prpStore = (Prop) propList.get(i);
+ prpStore = (Prop)propList.get(i);
if (prpStore.name.equals(inName)) {
//vctProps.remove(i);
removeDuskObject(prpStore);
String strStore = tokName.nextToken();
i = Integer.parseInt(strStore);
strStore = inName.substring(strStore.length() + 1, inName.length());
- itmStore = (Item) itemList.get(i);
+ itmStore = (Item)itemList.get(i);
if (itmStore.name.equals(strStore)) {
return itmStore;
}
String strStore = tokName.nextToken();
i = Integer.parseInt(strStore);
strStore = inName.substring(strStore.length() + 1, inName.length());
- itmStore = (Item) itemList.get(i);
+ itmStore = (Item)itemList.get(i);
if (itmStore.name.equals(strStore)) {
//vctItems.remove(i);
removeDuskObject(itmStore);
// FIXME: move to map or livinghting?
void playSound(TileMap map, int sfxid, int locx, int locy) {
- for (TileMap.MapData md : map.range(locx, locy, viewrange)) {
- for (DuskObject o : md.entities) {
+ for (TileMap.MapData md: map.range(locx, locy, viewrange)) {
+ for (DuskObject o: md.entities) {
if (o.isLivingThing()) {
- LivingThing lt = (LivingThing) o;
+ LivingThing lt = (LivingThing)o;
if (lt.isPlayer()) {
lt.playSFX(sfxid);
}
Script scrStore;
boolean blnStore;
+ System.out.printf("can move %d,%d\n", inLocX, inLocY);
if (!lt.map.inside(inLocX, inLocY))
return false;
//System.out.printf("can move to: %d,%d tid=%3d on map %s\n", inLocX, inLocY, lt.map.getTile(inLocX, inLocY), lt.map.name);
-
- for (DuskObject o : lt.map.getEntities(inLocX, inLocY, null)) {
+ for (DuskObject o: lt.map.getEntities(inLocX, inLocY, null)) {
if (o.isLivingThing()) {
- thnStore2 = (LivingThing) o;
+ thnStore2 = (LivingThing)o;
if (!canMoveThrougLivingThing(lt, thnStore2))
return false;
}
scrStore.close();
return blnStore;
} catch (Exception e) {
+ //e.printStackTrace();
}
try {
int tid = lt.map.getTile(inLocX, inLocY);
- scrStore = (Script) tileCanMove.get(tid);
+ scrStore = (Script)tileCanMove.get(tid);
synchronized (scrStore) {
scrStore.varVariables.clearVariables();
scrStore.varVariables.addVariable("trigger", lt);
} catch (Exception e) {
}
try {
- script = (Script) tileCanSee.get((int) lt.map.getTile(inLocX, inLocY));
+ script = (Script)tileCanSee.get((int)lt.map.getTile(inLocX, inLocY));
synchronized (script) {
script.varVariables.clearVariables();
script.varVariables.addVariable("trigger", lt);
return true;
}
- for (TileMap.MapData md : lt.map.look(lt.x, lt.y, destX, destY)) {
+ for (TileMap.MapData md: lt.map.look(lt.x, lt.y, destX, destY)) {
if (!canSee(lt, md.x, md.y))
return false;
}
}
void updateMap(LivingThing thing, int locx, int locy) {
- for (TileMap.MapData md : thing.map.range(locx, locy, viewrange)) {
- for (DuskObject o : md.entities) {
+ for (TileMap.MapData md: thing.map.range(locx, locy, viewrange)) {
+ for (DuskObject o: md.entities) {
if (o.isLivingThing()) {
- LivingThing lt = (LivingThing) o;
+ LivingThing lt = (LivingThing)o;
if (lt.isPlayer()) {
lt.updateMap();
}
synchronized void resizeMap(TileMap map, int x, int y) {
map.resize(x, y);
// FIXME: only the map that changed
- for (LivingThing thing : playersByName.values()) {
+ for (LivingThing thing: playersByName.values()) {
thing.initMap();
}
blnMapHasChanged = true;
File deleteme;
RandomAccessFile rafFile;
int i,
- i2;
+ i2;
if (blnMapHasChanged) {
System.err.println("save map not implemented");
log.printMessage(Log.ALWAYS, "Saving map...");
deleteme = new File("mobs");
deleteme.delete();
rafFile = new RandomAccessFile("mobs", "rw");
- for (Mob mob : mobList) {
+ for (Mob mob: mobList) {
if (mob.blnOneUse == false) {
if (mob.level == -1) {
rafFile.writeBytes("mob2.3\n" + mob.name + "\n" + mob.originalX + "\n" + mob.originalY + "\n");
deleteme = new File("signs");
deleteme.delete();
rafFile = new RandomAccessFile("signs", "rw");
- for (Sign sign : signList) {
+ for (Sign sign: signList) {
rafFile.writeBytes(sign.strMessage + "\n" + sign.x + "\n" + sign.y + "\n");
}
rafFile.close();
deleteme.delete();
try (RandomAccessFile out = new RandomAccessFile("merchants", "rw")) {
// FIXME: i/o on object
- for (Merchant m : merchantList) {
+ for (Merchant m: merchantList) {
out.writeBytes(m.x + "\n" + m.y + "\n");
for (i2 = 0; i2 < m.items.size(); i2++) {
- out.writeBytes((String) m.items.get(i2) + "\n");
+ out.writeBytes((String)m.items.get(i2) + "\n");
}
out.writeBytes("end\n");
}
deleteme = new File("props");
deleteme.delete();
rafFile = new RandomAccessFile("props", "rw");
- for (Prop prop : propList) {
+ for (Prop prop: propList) {
rafFile.writeBytes(prop.name + "\n" + prop.x + "\n" + prop.y + "\n");
}
rafFile.close();
deleteme = new File("globals");
deleteme.delete();
rafFile = new RandomAccessFile("globals", "rw");
- for (Variable varStore : varVariables.vctVariables.values()) {
+ for (Variable varStore: varVariables.vctVariables.values()) {
if (varStore.isString() || varStore.isNumber()) {
rafFile.writeBytes(varStore.strName + "\n");
rafFile.writeBytes(varStore.bytType + "\n");
int i, i2;
// map.saveMap(new File("backup/shortmap.backup"));
-
deleteme = new File("backup/mobs.backup");
deleteme.delete();
rafFile = new RandomAccessFile("backup/mobs.backup", "rw");
synchronized (mobList) {
- for (Mob mob : mobList) {
+ for (Mob mob: mobList) {
if (mob.blnOneUse == false) {
tknStore = new StringTokenizer(mob.name, " ");
rafFile.writeBytes(tknStore.nextToken() + "\n" + mob.level + "\n" + mob.originalX + "\n" + mob.originalY + "\n");
deleteme = new File("backup/signs.backup");
deleteme.delete();
rafFile = new RandomAccessFile("backup/signs.backup", "rw");
- for (Sign sign : signList) {
+ for (Sign sign: signList) {
rafFile.writeBytes(sign.strMessage + "\n" + sign.x + "\n" + sign.y + "\n");
}
rafFile.close();
deleteme = new File("backup/merchants.backup");
deleteme.delete();
rafFile = new RandomAccessFile("backup/merchants.backup", "rw");
- for (Merchant m : merchantList) {
+ for (Merchant m: merchantList) {
rafFile.writeBytes(m.x + "\n" + m.y + "\n");
for (i2 = 0; i2 < m.items.size(); i2++) {
- rafFile.writeBytes((String) m.items.get(i2) + "\n");
+ rafFile.writeBytes((String)m.items.get(i2) + "\n");
}
rafFile.writeBytes("end\n");
}
deleteme = new File("backup/props.backup");
deleteme.delete();
rafFile = new RandomAccessFile("backup/props.backup", "rw");
- for (Prop prop : propList) {
+ for (Prop prop: propList) {
rafFile.writeBytes(prop.name + "\n" + prop.x + "\n" + prop.y + "\n");
}
rafFile.close();
}
public void addDuskObject(TileMap map, DuskObject obj) {
+ System.out.printf("xx add '%s' %d %d\n", obj.name, obj.x, obj.y);
if (obj.isLivingThing()) {
- LivingThing lt = (LivingThing) obj;
+ LivingThing lt = (LivingThing)obj;
if (!lt.isLoaded) {
return;
}
if (obj instanceof Mob) {
synchronized (mobList) {
- mobList.add((Mob) obj);
+ mobList.add((Mob)obj);
}
blnMobListChanged = true;
} else if (lt.isPet()) {
petList.add(lt);
}
} else if (obj.isItem()) {
- itemList.add((Item) obj);
+ itemList.add((Item)obj);
} else if (obj.isSign()) {
- signList.add((Sign) obj);
+ signList.add((Sign)obj);
blnSignListChanged = true;
} else if (obj.isMerchant()) {
- merchantList.add((Merchant) obj);
+ merchantList.add((Merchant)obj);
blnMerchantListChanged = true;
} else if (obj.isProp()) {
- propList.add((Prop) obj);
+ propList.add((Prop)obj);
blnPropListChanged = true;
}
/**
* When a mob is killed, it isn't really removed, but the player needs
* to know about it.
- *
+ * <p>
* This 'cheats' by removing it from the game but temporarily
* corrupting the mob index.
*
}
public void removeDuskObject(DuskObject obj) {
+ System.out.printf("xx rem '%s' %d %d\n", obj.name, obj.x, obj.y);
if (obj.isLivingThing()) {
- LivingThing lt = (LivingThing) obj;
+ LivingThing lt = (LivingThing)obj;
if (!lt.isLoaded) {
return;
}
/**
* Move a living thing, updating any other living things within range.
- *
+ * <p>
* Only moves wihin the same map
*
* @param thing
*/
// FIXME: after moving here now i think this probably needs to be moved back to livingthing ...
public void moveDuskObject(LivingThing thing, int inlocx, int inlocy, byte dir) {
- for (TileMap.MapData md : thing.map.range(thing.x, thing.y, viewrange)) {
- for (DuskObject o : md.entities) {
+ for (TileMap.MapData md: thing.map.range(thing.x, thing.y, viewrange)) {
+ for (DuskObject o: md.entities) {
if (o.isLivingThing()) {
- LivingThing lt = (LivingThing) o;
+ LivingThing lt = (LivingThing)o;
if (lt.isPlayer()) {
boolean canSee = canSeeTo(lt, inlocx, inlocy)
- && (!thing.isLivingThing()
- || canSeeLivingThing(lt, thing));
+ && (!thing.isLivingThing()
+ || canSeeLivingThing(lt, thing));
if (canSee) {
// Add/update it if now visible
}
} else if (lt.isMob()) {
// Is this true?
- Mob thnMob = (Mob) lt;
+ Mob thnMob = (Mob)lt;
thnMob.blnCanSeePlayer = true;
}
}
/**
* Find a visible object of the given name.
- *
+ * <p>
* Name may also be the id.
*
* @param thing
}
//Search surrounding area
- for (TileMap.MapData md : thing.map.range(thing.x, thing.y, viewrange)) {
- for (DuskObject o : md.entities) {
+ for (TileMap.MapData md: thing.map.range(thing.x, thing.y, viewrange)) {
+ for (DuskObject o: md.entities) {
if (byid == o.ID
- || (byid == -1 && o.name.equalsIgnoreCase(name))) {
+ || (byid == -1 && o.name.equalsIgnoreCase(name))) {
if ((!o.isLivingThing()
- || canSeeLivingThing(thing, (LivingThing) o))
- && canSeeTo(thing, o.x, o.y)) {
+ || canSeeLivingThing(thing, (LivingThing)o))
+ && canSeeTo(thing, o.x, o.y)) {
if (number == 0) {
return o;
} else {
log.printMessage(Log.ALWAYS, "Player ticks = " + lngPlayerTicks);
log.printMessage(Log.ALWAYS, "Starting Ticks");
int tick = 0,
- i;
+ i;
LivingThing thnStore,
- thnStore2;
+ thnStore2;
Battle batStore;
long lngTime = System.currentTimeMillis(),
- lngPause = 0;
+ lngPause = 0;
while (true) {
try {
//250 milliseconds per tick
}
lngTime = System.currentTimeMillis();
if (tick % 73 == 0) {
- for (LivingThing pet : petList) {
+ for (LivingThing pet: petList) {
if (pet.battle == null) {
if (pet.isSleeping) {
pet.hp += 3 + (pet.cons + pet.consbon);
pet.savePlayer();
}
}
- for (LivingThing pet : petList) {
+ for (LivingThing pet: petList) {
pet.moveTick();
}
//Following code submitted by Randall Leeds, revised by Tom Weingarten:
- for (LivingThing lt : playersByName.values()) {
+ for (LivingThing lt: playersByName.values()) {
if (!lt.isWorking) {
//thnStore.closeNoMsgPlayer();
continue;
if (tick % 10 == 0) {
for (i = 0; i < battleList.size(); i++) {
- batStore = (Battle) battleList.get(i);
+ batStore = (Battle)battleList.get(i);
if (batStore.blnRunning == false) {
battleList.remove(i);
i--;
if (tick > 72) {
tick = 0;
synchronized (mobList) {
- for (Mob mob : mobList) {
+ for (Mob mob: mobList) {
if (mob.battle == null) {
// FIXME: magic number
if (mob.x != -6) {
}
}
}
- for (Faction f : factionMap.values()) {
+ for (Faction f: factionMap.values()) {
f.saveFactionData();;
}
}
/**
* This registers a new player atomically.
- *
+ * <p>
* Any existing player with the same name is booted
*/
public void registerPlayer(LivingThing lt, String name) throws BlockedIPException {
if (blnIPF) {
String address = lt.getAddress();
- for (LivingThing thing : playersByName.values()) {
+ for (LivingThing thing: playersByName.values()) {
if (thing.getAddress().equalsIgnoreCase(address)) {
throw new BlockedIPException("Already a player connected from your address");
}