mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-19 18:46:43 +00:00
execution time added
This commit is contained in:
parent
eb2635db73
commit
89f53a159a
@ -103,6 +103,16 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
private Map<Integer, HardwareModule> hardwareAddresses = new HashMap<>();
|
||||
private Map<Class<? extends HardwareModule>, Integer> hardwareModules = new HashMap<>();
|
||||
|
||||
/**
|
||||
* In game timer
|
||||
*/
|
||||
private int time;
|
||||
|
||||
/**
|
||||
* Real Life Timer for getting execution time
|
||||
*/
|
||||
private RealLifeTimer timer;
|
||||
|
||||
/**
|
||||
* Cubot's brain box
|
||||
*/
|
||||
@ -130,6 +140,10 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
shield = document.getInteger("shield");
|
||||
setDirection(Direction.getDirection(document.getInteger("direction")));
|
||||
|
||||
timer = new RealLifeTimer();
|
||||
timer.run();
|
||||
time = timer.getTime();
|
||||
|
||||
IServerConfiguration config = GameServer.INSTANCE.getConfig();
|
||||
maxHp = config.getInt("cubot_max_hp");
|
||||
maxShield = config.getInt("cubot_max_shield");
|
||||
@ -159,6 +173,12 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
int executionTime = timer.getTime();
|
||||
if(executionTime > time && currentAction != Action.IDLE){
|
||||
GameEvent event1 = new ExecutionTimeEvent(this, executionTime - time);
|
||||
GameServer.INSTANCE.getEventDispatcher().dispatch(event1);
|
||||
}
|
||||
time = executionTime;
|
||||
|
||||
if (currentAction == Action.WALKING) {
|
||||
if (spendEnergy(100)) {
|
||||
@ -166,8 +186,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
//Couldn't walk
|
||||
currentAction = Action.IDLE;
|
||||
}else{
|
||||
GameEvent event = new WalkDistanceEvent(this);
|
||||
GameServer.INSTANCE.getEventDispatcher().dispatch(event);
|
||||
GameEvent event2 = new WalkDistanceEvent(this);
|
||||
GameServer.INSTANCE.getEventDispatcher().dispatch(event2);
|
||||
}
|
||||
} else {
|
||||
currentAction = Action.IDLE;
|
||||
@ -269,6 +289,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
currentStatus = 0;
|
||||
lastStatus = 0;
|
||||
addStatus(CubotStatus.FACTORY_NEW);
|
||||
time = timer.getTime();
|
||||
|
||||
for (HardwareModule module : hardwareAddresses.values()) {
|
||||
module.reset();
|
||||
|
@ -18,6 +18,7 @@ public class CubotPlugin extends ServerPlugin {
|
||||
listeners.add(new SetInventoryPosition());
|
||||
listeners.add(new PutItemCommandListener());
|
||||
listeners.add(new PopItemCommandListener());
|
||||
//Leaderboard
|
||||
listeners.add(new DeathCountListener());
|
||||
listeners.add(new ExecutionTimeListener());
|
||||
listeners.add(new WalkDistanceListener());
|
||||
|
@ -5,8 +5,15 @@ import net.simon987.server.game.objects.GameObject;
|
||||
|
||||
public class ExecutionTimeEvent extends GameEvent {
|
||||
|
||||
public ExecutionTimeEvent(GameObject object) {
|
||||
private int Time = 0;
|
||||
|
||||
public ExecutionTimeEvent(GameObject object, int time) {
|
||||
setSource(object);
|
||||
this.Time = time;
|
||||
}
|
||||
|
||||
public int getTime(){
|
||||
return this.Time;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,7 +21,10 @@ public class ExecutionTimeListener implements GameEventListener {
|
||||
GameObject object = executionTimeEvent.getSource();
|
||||
if (object instanceof ControllableUnit) {
|
||||
count = ((ControllableUnit) object).getParent().getStats().getInt("executionTime");
|
||||
count++;
|
||||
count += executionTimeEvent.getTime();
|
||||
|
||||
LogManager.LOGGER.info(((ControllableUnit) object).getParent().getUsername() + " Execution Time " +
|
||||
count);
|
||||
|
||||
((ControllableUnit) object).getParent().getStats().setInt("executionTime",
|
||||
count);
|
||||
|
@ -0,0 +1,39 @@
|
||||
package net.simon987.cubotplugin.event;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class RealLifeTimer{
|
||||
|
||||
private int time;
|
||||
|
||||
private Timer timer;
|
||||
|
||||
public RealLifeTimer(){
|
||||
timer = new Timer();
|
||||
time = 0;
|
||||
}
|
||||
|
||||
public RealLifeTimer(int startTime){
|
||||
timer = new Timer();
|
||||
time = startTime;
|
||||
}
|
||||
|
||||
public void run(){
|
||||
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
public void run(){
|
||||
time++;
|
||||
}
|
||||
},0,1);
|
||||
}
|
||||
|
||||
public void stop(){
|
||||
timer.cancel();
|
||||
timer.purge();
|
||||
}
|
||||
|
||||
public int getTime(){
|
||||
return this.time;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user