mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-20 02:56:44 +00:00
Testing
This commit is contained in:
parent
c50cc8c364
commit
5b019b3e63
@ -11,6 +11,8 @@ import net.simon987.server.game.item.Item;
|
|||||||
import net.simon987.server.game.item.ItemVoid;
|
import net.simon987.server.game.item.ItemVoid;
|
||||||
import net.simon987.server.game.objects.*;
|
import net.simon987.server.game.objects.*;
|
||||||
import net.simon987.server.user.User;
|
import net.simon987.server.user.User;
|
||||||
|
import net.simon987.server.event.GameEvent;
|
||||||
|
import net.simon987.cubotplugin.event.*;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
@ -22,6 +24,14 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
|||||||
|
|
||||||
private static final char MAP_INFO = 0x0200;
|
private static final char MAP_INFO = 0x0200;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Walk Distance
|
||||||
|
*/
|
||||||
|
private int walkDistance;
|
||||||
|
/**
|
||||||
|
* Death Count
|
||||||
|
*/
|
||||||
|
private int deathCount;
|
||||||
/**
|
/**
|
||||||
* Hit points
|
* Hit points
|
||||||
*/
|
*/
|
||||||
@ -126,6 +136,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
|||||||
|
|
||||||
hp = document.getInteger("hp");
|
hp = document.getInteger("hp");
|
||||||
shield = document.getInteger("shield");
|
shield = document.getInteger("shield");
|
||||||
|
deathCount = 0;
|
||||||
|
walkDistance = 0;
|
||||||
setDirection(Direction.getDirection(document.getInteger("direction")));
|
setDirection(Direction.getDirection(document.getInteger("direction")));
|
||||||
|
|
||||||
IServerConfiguration config = GameServer.INSTANCE.getConfig();
|
IServerConfiguration config = GameServer.INSTANCE.getConfig();
|
||||||
@ -164,6 +176,9 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
|||||||
//Couldn't walk
|
//Couldn't walk
|
||||||
currentAction = Action.IDLE;
|
currentAction = Action.IDLE;
|
||||||
}
|
}
|
||||||
|
walkDistance++;
|
||||||
|
GameEvent event = new WalkDistanceEvent(this,walkDistance);
|
||||||
|
GameServer.INSTANCE.getEventDispatcher().dispatch(event);
|
||||||
} else {
|
} else {
|
||||||
currentAction = Action.IDLE;
|
currentAction = Action.IDLE;
|
||||||
}
|
}
|
||||||
@ -263,6 +278,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
|||||||
lastConsoleMessagesBuffer.clear();
|
lastConsoleMessagesBuffer.clear();
|
||||||
currentStatus = 0;
|
currentStatus = 0;
|
||||||
lastStatus = 0;
|
lastStatus = 0;
|
||||||
|
walkDistance = 0;
|
||||||
addStatus(CubotStatus.FACTORY_NEW);
|
addStatus(CubotStatus.FACTORY_NEW);
|
||||||
|
|
||||||
for (HardwareModule module : hardwareAddresses.values()) {
|
for (HardwareModule module : hardwareAddresses.values()) {
|
||||||
@ -272,6 +288,10 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onDeadCallback() {
|
public boolean onDeadCallback() {
|
||||||
|
deathCount++;
|
||||||
|
GameEvent event = new DeathCountEvent(this,deathCount);
|
||||||
|
GameServer.INSTANCE.getEventDispatcher().dispatch(event);
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
//Teleport to spawn point
|
//Teleport to spawn point
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
package net.simon987.cubotplugin.event;
|
||||||
|
|
||||||
|
import net.simon987.server.event.GameEvent;
|
||||||
|
import net.simon987.server.game.objects.GameObject;
|
||||||
|
|
||||||
|
public class DeathCountEvent extends GameEvent {
|
||||||
|
|
||||||
|
public DeathCountEvent(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeathCountEvent(GameObject object, int c) {
|
||||||
|
setSource(object);
|
||||||
|
if(c>=0){
|
||||||
|
object.setCounter(c);
|
||||||
|
}else{
|
||||||
|
object.setCounter(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GameObject getSource() {
|
||||||
|
return (GameObject) super.getSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCounter() {
|
||||||
|
return (int) getSource().getCounter();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package net.simon987.cubotplugin.event;
|
||||||
|
|
||||||
|
import net.simon987.server.event.GameEvent;
|
||||||
|
import net.simon987.server.event.GameEventListener;
|
||||||
|
import net.simon987.server.game.objects.ControllableUnit;
|
||||||
|
import net.simon987.server.game.objects.GameObject;
|
||||||
|
import net.simon987.server.logging.LogManager;
|
||||||
|
|
||||||
|
public class DeathCountListener implements GameEventListener {
|
||||||
|
@Override
|
||||||
|
public Class getListenedEventType() {
|
||||||
|
return DeathCountEvent.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(GameEvent event) {
|
||||||
|
DeathCountEvent DeathCountEvent = (DeathCountEvent) event;
|
||||||
|
GameObject object = DeathCountEvent.getSource();
|
||||||
|
if (object instanceof ControllableUnit) {
|
||||||
|
LogManager.LOGGER.info(((ControllableUnit) object).getParent().getUsername() + " Death Count " +
|
||||||
|
Integer.toString(object.getCounter()));
|
||||||
|
|
||||||
|
((ControllableUnit) object).getParent().getStats().setInt("deathCount",
|
||||||
|
DeathCountEvent.getCounter());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package net.simon987.cubotplugin.event;
|
||||||
|
|
||||||
|
import net.simon987.server.event.GameEvent;
|
||||||
|
import net.simon987.server.game.objects.GameObject;
|
||||||
|
|
||||||
|
public class TotalExecutionTimeEvent extends GameEvent {
|
||||||
|
|
||||||
|
public TotalExecutionTimeEvent(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public TotalExecutionTimeEvent(GameObject object, double c) {
|
||||||
|
setSource(object);
|
||||||
|
if(c>=0){
|
||||||
|
object.setTime(c);
|
||||||
|
}else{
|
||||||
|
object.setTime(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GameObject getSource() {
|
||||||
|
return (GameObject) super.getSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getTime() {
|
||||||
|
return (int) getSource().getTime();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package net.simon987.cubotplugin.event;
|
||||||
|
|
||||||
|
import net.simon987.server.event.GameEvent;
|
||||||
|
import net.simon987.server.event.GameEventListener;
|
||||||
|
import net.simon987.server.game.objects.ControllableUnit;
|
||||||
|
import net.simon987.server.game.objects.GameObject;
|
||||||
|
import net.simon987.server.logging.LogManager;
|
||||||
|
|
||||||
|
public class TotalExecutionTimeListener implements GameEventListener {
|
||||||
|
@Override
|
||||||
|
public Class getListenedEventType() {
|
||||||
|
return TotalExecutionTimeEvent.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(GameEvent event) {
|
||||||
|
TotalExecutionTimeEvent TotalExecutionTimeEvent = (TotalExecutionTimeEvent) event;
|
||||||
|
GameObject object = TotalExecutionTimeEvent.getSource();
|
||||||
|
if (object instanceof ControllableUnit) {
|
||||||
|
LogManager.LOGGER.info(((ControllableUnit) object).getParent().getUsername() + " Death Count " +
|
||||||
|
Double.toString(object.getTime()));
|
||||||
|
|
||||||
|
((ControllableUnit) object).getParent().getStats().setDouble("totalExecutionTime",
|
||||||
|
TotalExecutionTimeEvent.getTime());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package net.simon987.cubotplugin.event;
|
||||||
|
|
||||||
|
import net.simon987.server.event.GameEvent;
|
||||||
|
import net.simon987.server.game.objects.GameObject;
|
||||||
|
|
||||||
|
public class WalkDistanceEvent extends GameEvent {
|
||||||
|
|
||||||
|
private int count;
|
||||||
|
|
||||||
|
public WalkDistanceEvent(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public WalkDistanceEvent(GameObject object, int c) {
|
||||||
|
setSource(object);
|
||||||
|
if(c>=0){
|
||||||
|
object.setCounter(c);
|
||||||
|
}else{
|
||||||
|
object.setCounter(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GameObject getSource() {
|
||||||
|
return (GameObject) super.getSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCounter() {
|
||||||
|
return (int) getSource().getCounter();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package net.simon987.cubotplugin.event;
|
||||||
|
|
||||||
|
import net.simon987.server.event.GameEvent;
|
||||||
|
import net.simon987.server.event.GameEventListener;
|
||||||
|
import net.simon987.server.game.objects.ControllableUnit;
|
||||||
|
import net.simon987.server.game.objects.GameObject;
|
||||||
|
import net.simon987.server.logging.LogManager;
|
||||||
|
|
||||||
|
public class WalkDistanceListener implements GameEventListener {
|
||||||
|
@Override
|
||||||
|
public Class getListenedEventType() {
|
||||||
|
return WalkDistanceEvent.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(GameEvent event) {
|
||||||
|
WalkDistanceEvent WalkDistanceEvent = (WalkDistanceEvent) event;
|
||||||
|
GameObject object = WalkDistanceEvent.getSource();
|
||||||
|
if (object instanceof ControllableUnit) {
|
||||||
|
LogManager.LOGGER.info(((ControllableUnit) object).getParent().getUsername() + " Death Count " +
|
||||||
|
Integer.toString(object.getCounter()));
|
||||||
|
|
||||||
|
((ControllableUnit) object).getParent().getStats().setInt("walkDistance",
|
||||||
|
WalkDistanceEvent.getCounter());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -43,6 +43,14 @@ public abstract class GameObject implements JSONSerializable, MongoSerializable
|
|||||||
* Current World of the object
|
* Current World of the object
|
||||||
*/
|
*/
|
||||||
private World world;
|
private World world;
|
||||||
|
/**
|
||||||
|
* Counter for user stats
|
||||||
|
*/
|
||||||
|
private int counter;
|
||||||
|
/**
|
||||||
|
* Execution Time
|
||||||
|
*/
|
||||||
|
private double time;
|
||||||
|
|
||||||
public GameObject() {
|
public GameObject() {
|
||||||
|
|
||||||
@ -63,6 +71,9 @@ public abstract class GameObject implements JSONSerializable, MongoSerializable
|
|||||||
int newX = getX() + direction.dX;
|
int newX = getX() + direction.dX;
|
||||||
int newY = getY() + direction.dY;
|
int newY = getY() + direction.dY;
|
||||||
|
|
||||||
|
counter = 0;
|
||||||
|
time = 0;
|
||||||
|
|
||||||
if (newX < 0 || newY < 0 || newX >= world.getWorldSize() || newY >= world.getWorldSize()) {
|
if (newX < 0 || newY < 0 || newX >= world.getWorldSize() || newY >= world.getWorldSize()) {
|
||||||
//Next tile is out of world bounds, move to next world
|
//Next tile is out of world bounds, move to next world
|
||||||
World nextWorld = GameServer.INSTANCE.getGameUniverse().getWorld(
|
World nextWorld = GameServer.INSTANCE.getGameUniverse().getWorld(
|
||||||
@ -230,6 +241,22 @@ public abstract class GameObject implements JSONSerializable, MongoSerializable
|
|||||||
this.world = world;
|
this.world = world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCounter(int c){
|
||||||
|
counter=c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCounter(){
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTime(double t){
|
||||||
|
time=t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getTime(){
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject jsonSerialise() {
|
public JSONObject jsonSerialise() {
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
|
@ -61,6 +61,27 @@ public class UserStats implements MongoSerializable {
|
|||||||
return stats.getInteger(name, 0);
|
return stats.getInteger(name, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the value of a stat
|
||||||
|
*
|
||||||
|
* @param name Name of the stat
|
||||||
|
* @param value new value
|
||||||
|
*/
|
||||||
|
public void setDouble(String name, double value) {
|
||||||
|
|
||||||
|
stats.put(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of at stat
|
||||||
|
*
|
||||||
|
* @param name Name of the value
|
||||||
|
* @return The value of the stat. Returns 0 if not found
|
||||||
|
*/
|
||||||
|
public double getDouble(String name) {
|
||||||
|
return stats.getDouble(name);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an string item to a set
|
* Add an string item to a set
|
||||||
*
|
*
|
||||||
|
@ -13,9 +13,12 @@ public class LeaderBoardPage implements TemplateViewRoute {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModelAndView handle(Request request, Response response) {
|
public ModelAndView handle(Request request, Response response) {
|
||||||
Map<String, Object> model = new HashMap<>(2);
|
Map<String, Object> model = new HashMap<>(5);
|
||||||
model.put("session", request.session());
|
model.put("session", request.session());
|
||||||
model.put("stats", GameServer.INSTANCE.getUserStatsHelper().getTopNSetLength("completedVaults", 25));
|
model.put("stats", GameServer.INSTANCE.getUserStatsHelper().getTopNSetLength("completedVaults", 25));
|
||||||
|
model.put("stats", GameServer.INSTANCE.getUserStatsHelper().getTopNSetLength("deathCount", 25));
|
||||||
|
model.put("stats", GameServer.INSTANCE.getUserStatsHelper().getTopNSetLength("totalExecutionTime", 25));
|
||||||
|
model.put("stats", GameServer.INSTANCE.getUserStatsHelper().getTopNSetLength("walkDistance", 25));
|
||||||
return new ModelAndView(model, "leaderboard.vm");
|
return new ModelAndView(model, "leaderboard.vm");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,6 +16,9 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Player</th>
|
<th>Player</th>
|
||||||
<th>Completed vaults</th>
|
<th>Completed vaults</th>
|
||||||
|
<th>Death counts</th>
|
||||||
|
<th>Total execution time (ms)</th>
|
||||||
|
<th>Walk distance</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -23,6 +26,9 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>$row.getKey().getUsername()</td>
|
<td>$row.getKey().getUsername()</td>
|
||||||
<td>$row.getValue().size()</td>
|
<td>$row.getValue().size()</td>
|
||||||
|
<td>$row.getValue().size()</td>
|
||||||
|
<td>$row.getValue().size()</td>
|
||||||
|
<td>$row.getValue().size()</td>
|
||||||
</tr>
|
</tr>
|
||||||
#end
|
#end
|
||||||
</tbody>
|
</tbody>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user