mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-19 10:36:43 +00:00
Added Factory object #31
This commit is contained in:
parent
3548928218
commit
4f1342593f
57
Plugin NPC/src/main/java/net/simon987/npcplugin/Factory.java
Normal file
57
Plugin NPC/src/main/java/net/simon987/npcplugin/Factory.java
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package net.simon987.npcplugin;
|
||||||
|
|
||||||
|
import net.simon987.server.game.GameObject;
|
||||||
|
import net.simon987.server.game.Updatable;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
public class Factory extends GameObject implements Updatable {
|
||||||
|
|
||||||
|
private static final int MAP_INFO = 0x0200;
|
||||||
|
|
||||||
|
public static final int ID = 3;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public char getMapInfo() {
|
||||||
|
return MAP_INFO;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
System.out.println("Updating Factory...");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAt(int x, int y) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Object is 2x2 tiles, the (x,y) coordinates of the object being
|
||||||
|
* at top-left.
|
||||||
|
* # .
|
||||||
|
* . .
|
||||||
|
*/
|
||||||
|
return (x == getX() + 1 || x == getX()) && (y == getY() + 1 || y == getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject serialise() {
|
||||||
|
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
|
||||||
|
json.put("i", getObjectId());
|
||||||
|
json.put("x", getX());
|
||||||
|
json.put("y", getY());
|
||||||
|
json.put("t", ID);
|
||||||
|
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Factory deserialise(JSONObject json) {
|
||||||
|
|
||||||
|
Factory factory = new Factory();
|
||||||
|
factory.setObjectId((int) (long) json.get("i"));
|
||||||
|
factory.setX((int) (long) json.get("x"));
|
||||||
|
factory.setY((int) (long) json.get("y"));
|
||||||
|
|
||||||
|
return factory;
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,6 @@
|
|||||||
package net.simon987.npcplugin;
|
package net.simon987.npcplugin;
|
||||||
|
|
||||||
|
|
||||||
import net.simon987.server.GameServer;
|
|
||||||
import net.simon987.server.assembly.Util;
|
import net.simon987.server.assembly.Util;
|
||||||
import net.simon987.server.game.Direction;
|
import net.simon987.server.game.Direction;
|
||||||
import net.simon987.server.game.GameObject;
|
import net.simon987.server.game.GameObject;
|
||||||
@ -85,16 +84,7 @@ public class HarvestTask extends NPCTask {
|
|||||||
|
|
||||||
if (nextWorldDirection == null) {
|
if (nextWorldDirection == null) {
|
||||||
|
|
||||||
//Stay near the center of the map 50% of the time
|
nextWorldDirection = Direction.getDirection(random.nextInt(3));
|
||||||
if (random.nextBoolean()) {
|
|
||||||
|
|
||||||
nextWorldDirection = Direction.getDirectionTo(npc.getX(), npc.getY(),
|
|
||||||
GameServer.INSTANCE.getConfig().getInt("new_user_worldX"),
|
|
||||||
GameServer.INSTANCE.getConfig().getInt("new_user_worldY"));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
nextWorldDirection = Direction.getDirection(random.nextInt(3));
|
|
||||||
}
|
|
||||||
|
|
||||||
pause += 6;
|
pause += 6;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import org.json.simple.JSONObject;
|
|||||||
|
|
||||||
public class HarvesterNPC extends NonPlayerCharacter {
|
public class HarvesterNPC extends NonPlayerCharacter {
|
||||||
|
|
||||||
public static final int ID = 10; //todo change
|
public static final int ID = 10;
|
||||||
|
|
||||||
|
|
||||||
public HarvesterNPC() {
|
public HarvesterNPC() {
|
||||||
@ -44,7 +44,7 @@ public class HarvesterNPC extends NonPlayerCharacter {
|
|||||||
json.put("hp", hp);
|
json.put("hp", hp);
|
||||||
json.put("energy", energy);
|
json.put("energy", energy);
|
||||||
json.put("action", getAction().ordinal());
|
json.put("action", getAction().ordinal());
|
||||||
json.put("t", 10);
|
json.put("t", ID);
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,8 @@ public class NpcPlugin extends ServerPlugin implements GameObjectDeserializer {
|
|||||||
|
|
||||||
if (objType == HarvesterNPC.ID) {
|
if (objType == HarvesterNPC.ID) {
|
||||||
return HarvesterNPC.deserialize(object);
|
return HarvesterNPC.deserialize(object);
|
||||||
|
} else if (objType == Factory.ID) {
|
||||||
|
return Factory.deserialise(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.simon987.npcplugin.event;
|
package net.simon987.npcplugin.event;
|
||||||
|
|
||||||
|
import net.simon987.npcplugin.Factory;
|
||||||
import net.simon987.npcplugin.HarvesterNPC;
|
import net.simon987.npcplugin.HarvesterNPC;
|
||||||
import net.simon987.npcplugin.NonPlayerCharacter;
|
import net.simon987.npcplugin.NonPlayerCharacter;
|
||||||
import net.simon987.server.GameServer;
|
import net.simon987.server.GameServer;
|
||||||
@ -31,7 +32,7 @@ public class WorldUpdateListener implements GameEventListener {
|
|||||||
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
ok = false;
|
ok = false;
|
||||||
LogManager.LOGGER.info("Spawning Harvester\n--------------------------------------");
|
LogManager.LOGGER.info("Spawning Harvester + Factory\n--------------------------------------");
|
||||||
|
|
||||||
NonPlayerCharacter npc = new HarvesterNPC();
|
NonPlayerCharacter npc = new HarvesterNPC();
|
||||||
|
|
||||||
@ -45,12 +46,22 @@ public class WorldUpdateListener implements GameEventListener {
|
|||||||
world.getGameObjects().add(npc);
|
world.getGameObjects().add(npc);
|
||||||
world.incUpdatable();
|
world.incUpdatable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Factory test
|
||||||
|
Factory factory = new Factory();
|
||||||
|
|
||||||
|
factory.setWorld(world);
|
||||||
|
factory.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId());
|
||||||
|
factory.setX(7);
|
||||||
|
factory.setY(11);
|
||||||
|
world.getGameObjects().add(factory);
|
||||||
|
world.incUpdatable();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ public class TileMap implements JSONSerialisable {
|
|||||||
deflaterOutputStream.close();
|
deflaterOutputStream.close();
|
||||||
byte[] compressedBytes = stream.toByteArray();
|
byte[] compressedBytes = stream.toByteArray();
|
||||||
|
|
||||||
json.put("zipTerrain", new String(Base64.getEncoder().encode(compressedBytes)));
|
json.put("z", new String(Base64.getEncoder().encode(compressedBytes)));
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -133,7 +133,7 @@ public class TileMap implements JSONSerialisable {
|
|||||||
TileMap tileMap = new TileMap(World.WORLD_SIZE, World.WORLD_SIZE);
|
TileMap tileMap = new TileMap(World.WORLD_SIZE, World.WORLD_SIZE);
|
||||||
|
|
||||||
|
|
||||||
byte[] compressedBytes = Base64.getDecoder().decode((String) object.get("zipTerrain"));
|
byte[] compressedBytes = Base64.getDecoder().decode((String) object.get("z"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
@ -17,7 +17,7 @@ cert_path=certificates
|
|||||||
# ----------------------------------------------
|
# ----------------------------------------------
|
||||||
|
|
||||||
# Length of a tick in ms
|
# Length of a tick in ms
|
||||||
tick_length=125
|
tick_length=1000
|
||||||
# Default offset of the origin (starting point of code execution) in words
|
# Default offset of the origin (starting point of code execution) in words
|
||||||
org_offset=512
|
org_offset=512
|
||||||
# Address of the stack bottom
|
# Address of the stack bottom
|
||||||
|
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user