Newly registered users can now login on the game server,

This commit is contained in:
simon
2017-11-04 10:41:57 -04:00
parent 56c0bee586
commit cdfdab09f8
13 changed files with 162 additions and 50 deletions

View File

@@ -1,6 +1,7 @@
package net.simon987.cubotplugin;
import net.simon987.server.game.*;
import net.simon987.server.user.User;
import org.json.simple.JSONObject;
import java.util.ArrayList;
@@ -23,6 +24,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
private ArrayList<Integer> keyboardBuffer = new ArrayList<>();
private User parent;
public Cubot() {
}
@@ -67,6 +70,9 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
json.put("heldItem", heldItem);
json.put("hp", hp);
json.put("action", lastAction.ordinal());
if(parent != null){
json.put("parent", parent.getUsername()); //Only used client-side for now
}
return json;
}
@@ -80,6 +86,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
cubot.hp = (int)(long)json.get("hp");
cubot.setDirection(Direction.getDirection((int)(long)json.get("direction")));
cubot.heldItem = (int)(long)json.get("heldItem");
cubot.heldItem = (int)(long)json.get("heldItem");
return cubot;
@@ -110,4 +117,12 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
public void setCurrentAction(CubotAction currentAction) {
this.currentAction = currentAction;
}
public User getParent() {
return parent;
}
public void setParent(User parent) {
this.parent = parent;
}
}

View File

@@ -7,6 +7,8 @@ import net.simon987.server.event.GameEventListener;
import net.simon987.server.event.UserCreationEvent;
import net.simon987.server.user.User;
import java.awt.*;
public class UserCreationListener implements GameEventListener {
@Override
public Class getListenedEventType() {
@@ -20,12 +22,18 @@ public class UserCreationListener implements GameEventListener {
Cubot cubot = new Cubot();
cubot.setWorld(GameServer.INSTANCE.getGameUniverse().getWorld(0,0));
cubot.getWorld().getGameObjects().add(cubot);
cubot.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId());
cubot.setX(6);
cubot.setY(6);
cubot.setParent(user);
Point point = cubot.getWorld().getRandomPassableTile();
cubot.setX(point.x);
cubot.setY(point.y);
user.setControlledUnit(cubot);