mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-12-13 14:49:03 +00:00
committed by
Simon Fortier
parent
d71b3dc97c
commit
f99f327480
@@ -1,5 +1,7 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.cubotplugin.event.CubotWalkEvent;
|
||||
import net.simon987.cubotplugin.event.DeathEvent;
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.IServerConfiguration;
|
||||
import net.simon987.server.assembly.CPU;
|
||||
@@ -7,6 +9,7 @@ import net.simon987.server.assembly.HardwareModule;
|
||||
import net.simon987.server.assembly.Memory;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.exception.CancelledException;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.game.item.Item;
|
||||
import net.simon987.server.game.item.ItemVoid;
|
||||
import net.simon987.server.game.objects.*;
|
||||
@@ -152,17 +155,15 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
return MAP_INFO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called every tick
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
|
||||
if (currentAction == Action.WALKING) {
|
||||
if (spendEnergy(100)) {
|
||||
if (!incrementLocation()) {
|
||||
//Couldn't walk
|
||||
currentAction = Action.IDLE;
|
||||
}else{
|
||||
GameServer.INSTANCE.getEventDispatcher().dispatch(new CubotWalkEvent(this));
|
||||
}
|
||||
} else {
|
||||
currentAction = Action.IDLE;
|
||||
@@ -272,6 +273,9 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
||||
|
||||
@Override
|
||||
public boolean onDeadCallback() {
|
||||
GameEvent event = new DeathEvent(this);
|
||||
GameServer.INSTANCE.getEventDispatcher().dispatch(event);
|
||||
|
||||
reset();
|
||||
|
||||
//Teleport to spawn point
|
||||
|
||||
@@ -18,6 +18,9 @@ public class CubotPlugin extends ServerPlugin {
|
||||
listeners.add(new SetInventoryPosition());
|
||||
listeners.add(new PutItemCommandListener());
|
||||
listeners.add(new PopItemCommandListener());
|
||||
//Leaderboard
|
||||
listeners.add(new DeathListener());
|
||||
listeners.add(new WalkListener());
|
||||
|
||||
GameRegistry registry = gameServer.getRegistry();
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package net.simon987.cubotplugin.event;
|
||||
|
||||
import net.simon987.cubotplugin.Cubot;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
|
||||
public class CubotWalkEvent extends GameEvent {
|
||||
|
||||
public CubotWalkEvent(Cubot cubot) {
|
||||
setSource(cubot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cubot getSource() {
|
||||
return (Cubot) super.getSource();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package net.simon987.cubotplugin.event;
|
||||
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
|
||||
public class DeathEvent extends GameEvent {
|
||||
|
||||
public DeathEvent(GameObject object) {
|
||||
setSource(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameObject getSource() {
|
||||
return (GameObject) super.getSource();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
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;
|
||||
|
||||
public class DeathListener implements GameEventListener {
|
||||
|
||||
@Override
|
||||
public Class getListenedEventType() {
|
||||
return DeathEvent.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(GameEvent event) {
|
||||
DeathEvent DeathEvent = (DeathEvent) event;
|
||||
GameObject object = DeathEvent.getSource();
|
||||
if (object instanceof ControllableUnit) {
|
||||
((ControllableUnit) object).getParent().getStats().incrementStat("death", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.simon987.cubotplugin.event;
|
||||
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
|
||||
public class WalkListener implements GameEventListener {
|
||||
|
||||
@Override
|
||||
public Class getListenedEventType() {
|
||||
return CubotWalkEvent.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(GameEvent event) {
|
||||
CubotWalkEvent walkEvent = (CubotWalkEvent) event;
|
||||
walkEvent.getSource().getParent().getStats().incrementStat("walkDistance", 1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user