mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-12-13 14:49:03 +00:00
Added maven framework support. Started working on NPCs #19
This commit is contained in:
21
Plugin Plant/Plugin Plant.iml
Normal file
21
Plugin Plant/Plugin Plant.iml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: junit:junit:4.10" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||
<orderEntry type="module" module-name="Server" />
|
||||
<orderEntry type="library" name="Maven: org.java-websocket:Java-WebSocket:1.3.6" level="project" />
|
||||
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.42" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
36
Plugin Plant/pom.xml
Normal file
36
Plugin Plant/pom.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>net.simon987.pluginplant</groupId>
|
||||
<artifactId>Plugin Plant</artifactId>
|
||||
<version>1.2a</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.simon987.server</groupId>
|
||||
<artifactId>Server</artifactId>
|
||||
<version>1.2a</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,31 +1,13 @@
|
||||
package net.simon987.plantplugin;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.GameObject;
|
||||
import net.simon987.server.game.InventoryHolder;
|
||||
import net.simon987.server.game.Updatable;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class Plant extends GameObject implements Updatable, InventoryHolder{
|
||||
|
||||
public class Plant extends GameObject implements InventoryHolder {
|
||||
private static final char MAP_INFO = 0x4000;
|
||||
public static final int ID = 2;
|
||||
|
||||
/**
|
||||
* Grow time (see config.properties)
|
||||
*/
|
||||
private static final int GROW_TIME = GameServer.INSTANCE.getConfig().getInt("plant_grow_time");
|
||||
|
||||
/**
|
||||
* Game time of the creation of this Plant
|
||||
*/
|
||||
private long creationTime;
|
||||
|
||||
/**
|
||||
* Whether the plant is grown or not
|
||||
*/
|
||||
private boolean grown;
|
||||
|
||||
/**
|
||||
* Yield of the plant, in biomass units
|
||||
*/
|
||||
@@ -51,43 +33,12 @@ public class Plant extends GameObject implements Updatable, InventoryHolder{
|
||||
json.put("id", getObjectId());
|
||||
json.put("x", getX());
|
||||
json.put("y", getY());
|
||||
json.put("creationTime", creationTime);
|
||||
json.put("grown", grown);
|
||||
json.put("biomassCount", biomassCount);
|
||||
json.put("style", style);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called every tick
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
if (!grown) {
|
||||
//Check grow
|
||||
if (creationTime + GROW_TIME <= GameServer.INSTANCE.getGameUniverse().getTime()) {
|
||||
grown = true;
|
||||
biomassCount = GameServer.INSTANCE.getConfig().getInt("plant_yield");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public long getCreationTime() {
|
||||
return creationTime;
|
||||
}
|
||||
|
||||
public void setCreationTime(long creationTime) {
|
||||
this.creationTime = creationTime;
|
||||
}
|
||||
|
||||
public boolean isGrown() {
|
||||
return grown;
|
||||
}
|
||||
|
||||
public void setGrown(boolean grown) {
|
||||
this.grown = grown;
|
||||
}
|
||||
|
||||
public int getBiomassCount() {
|
||||
return biomassCount;
|
||||
@@ -105,17 +56,15 @@ public class Plant extends GameObject implements Updatable, InventoryHolder{
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
public static Plant deserialize(JSONObject json){
|
||||
public static Plant deserialize(JSONObject json) {
|
||||
|
||||
Plant plant = new Plant();
|
||||
|
||||
plant.setObjectId((int)(long)json.get("id"));
|
||||
plant.setX((int)(long)json.get("x"));
|
||||
plant.setY((int)(long)json.get("y"));
|
||||
plant.grown = (boolean)json.get("grown");
|
||||
plant.creationTime = (long)json.get("creationTime");
|
||||
plant.style = (int)(long)json.get("style");
|
||||
plant.biomassCount = (int)(long)json.get("biomassCount");
|
||||
plant.setObjectId((int) (long) json.get("id"));
|
||||
plant.setX((int) (long) json.get("x"));
|
||||
plant.setY((int) (long) json.get("y"));
|
||||
plant.style = (int) (long) json.get("style");
|
||||
plant.biomassCount = (int) (long) json.get("biomassCount");
|
||||
|
||||
return plant;
|
||||
}
|
||||
@@ -134,7 +83,7 @@ public class Plant extends GameObject implements Updatable, InventoryHolder{
|
||||
|
||||
@Override
|
||||
public boolean canTakeItem(int item) {
|
||||
return item == ITM_BIOMASS && grown && biomassCount >= 1;
|
||||
return item == ITM_BIOMASS && biomassCount >= 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,9 +97,9 @@ public class Plant extends GameObject implements Updatable, InventoryHolder{
|
||||
public void takeItem(int item) {
|
||||
|
||||
if (item == ITM_BIOMASS) {
|
||||
if (grown && biomassCount > 1) {
|
||||
if (biomassCount > 1) {
|
||||
biomassCount--;
|
||||
} else if (grown) {
|
||||
} else {
|
||||
//Delete plant
|
||||
setDead(true);
|
||||
}
|
||||
@@ -10,7 +10,6 @@ import org.json.simple.JSONObject;
|
||||
public class PlantPlugin extends ServerPlugin implements GameObjectDeserializer {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
listeners.add(new WorldCreationListener());
|
||||
@@ -20,9 +19,9 @@ public class PlantPlugin extends ServerPlugin implements GameObjectDeserializer
|
||||
@Override
|
||||
public GameObject deserializeObject(JSONObject object) {
|
||||
|
||||
int objType = (int)(long)object.get("type");
|
||||
int objType = (int) (long) object.get("type");
|
||||
|
||||
if(objType == Plant.ID) {
|
||||
if (objType == Plant.ID) {
|
||||
|
||||
return Plant.deserialize(object);
|
||||
}
|
||||
@@ -21,9 +21,9 @@ public class WorldCreationListener implements GameEventListener {
|
||||
@Override
|
||||
public void handle(GameEvent event) {
|
||||
|
||||
ArrayList<Plant> plants = generatePlants(((WorldGenerationEvent)event).getWorld());
|
||||
ArrayList<Plant> plants = generatePlants(((WorldGenerationEvent) event).getWorld());
|
||||
|
||||
((WorldGenerationEvent)event).getWorld().getGameObjects().addAll(plants);
|
||||
((WorldGenerationEvent) event).getWorld().getGameObjects().addAll(plants);
|
||||
|
||||
}
|
||||
|
||||
@@ -79,7 +79,6 @@ public class WorldCreationListener implements GameEventListener {
|
||||
plant.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId());
|
||||
plant.setStyle(0); //TODO: set style depending on difficulty level? or random? from config?
|
||||
plant.setBiomassCount(plant_yield);
|
||||
plant.setCreationTime(0); // Plants generated by the world generator always have creationTime of 0
|
||||
plant.setX(p.x);
|
||||
plant.setY(p.y);
|
||||
plant.setWorld(world);
|
||||
Reference in New Issue
Block a user