Commit 0d6185c7 authored by moonbase420's avatar moonbase420

updated wing system

parent 86573ec3
......@@ -17,6 +17,7 @@ import com.drakelinglabs.ironarmada.client.oldsystem.TickSys;
import com.drakelinglabs.ironarmada.client.renderers.ui.AnnouncementUIRenderer;
import com.drakelinglabs.ironarmada.client.renderers.ui.UniversalUIRenderer;
import com.drakelinglabs.ironarmada.client.renderers.ui.windows.FactionInfoUIRenderer;
import com.drakelinglabs.ironarmada.client.renderers.ui.windows.WingInfoUIRenderer;
import com.drakelinglabs.ironarmada.client.voice.VoiceSys;
import com.drakelinglabs.ironarmada.common.NetworkedInvocationStrategy;
import com.drakelinglabs.ironarmada.common.NetworkingConstants;
......@@ -33,6 +34,7 @@ import com.drakelinglabs.ironarmada.common.serialization.SerializableComponent;
import com.drakelinglabs.ironarmada.common.system.FactionSystem;
import com.drakelinglabs.ironarmada.common.system.NetSys;
import com.drakelinglabs.ironarmada.common.system.ShipSys;
import com.drakelinglabs.ironarmada.common.system.WingSystem;
import com.drakelinglabs.ironarmada.common.utility.Utils;
import net.mostlyoriginal.api.event.common.EventSystem;
import net.mostlyoriginal.api.system.core.PassiveSystem;
......@@ -86,9 +88,13 @@ public class ClientMessageProcessor extends PassiveSystem {
@Wire
private FactionSystem factionSystem;
@Wire
private WingSystem wingSystem;
@Wire
private UniversalUIRenderer universalUIRenderer;
@Wire
private FactionInfoUIRenderer factionInfoUIRenderer;
@Wire
private WingInfoUIRenderer wingInfoUIRenderer;
@Wire
private ComponentMapper<Net> mNet;
......@@ -313,13 +319,17 @@ public class ClientMessageProcessor extends PassiveSystem {
}
}
public void sendCreateWingMessage() {
public void sendCreateWingMessage(String wingName) {
try {
outStream.writeInt(CS_CREATE_WING);
outStream.writeUTF(wingName);
outStream.writeInt(myPlayer());
writeOutStreamMessage(client);
} catch (IOException e) {
Utils.throwRuntimeException("Could not send Create Wing message", e);
}
wingInfoUIRenderer.updateWings();
wingInfoUIRenderer.updatePlayers();
}
public void sendPromotePlayerMessage(int playerID) {
......@@ -360,6 +370,16 @@ public class ClientMessageProcessor extends PassiveSystem {
}
}
public void sendKickPlayerMessage(int playerToKick) {
try {
outStream.writeInt(CS_KICK_PLAYER_FROM_WING);
outStream.writeInt(playerToKick);
writeOutStreamMessage(client);
}catch (IOException e) {
Utils.throwRuntimeException("Could not send kick player from wing message", e);
}
}
public void sendDisbandWingMessage() {
try {
outStream.writeInt(CS_DISBAND_WING);
......@@ -606,6 +626,9 @@ public class ClientMessageProcessor extends PassiveSystem {
case D_FACTION_DATA:
readFactionData(digestStats, dis);
break;
case D_WING_DATA:
readWingData(digestStats, dis);
break;
}
}
......@@ -781,6 +804,21 @@ public class ClientMessageProcessor extends PassiveSystem {
}
break;
case SC_SEND_WING_DATA: {
wingSystem.clearWings();
int totalWings = dis.readInt();
for(int i = 0; i < totalWings; i++) {
String wingName = dis.readUTF();
int leaderId = dis.readInt();
int factionId = dis.readInt();
boolean invite = dis.readBoolean();
wingSystem.createWing(wingName, leaderId, factionId, invite);
}
wingInfoUIRenderer.updateWings();
wingInfoUIRenderer.updatePlayers();
}
break;
default:
log.error("Unknown server message received " + messageType);
break;
......@@ -920,6 +958,32 @@ public class ClientMessageProcessor extends PassiveSystem {
digestStats.addToComponentStats(Faction.class, bytesRead, instances);
}
public void readWingData(DigestStats digestStats, DataInputStream dis) throws IOException {
// rely on available() for lack of better way to count number of bytes read
final int bytesLeftBefore = dis.available();
int instances = 0;
while (true) {
int totalWings = dis.readInt();
if(totalWings <= 0)
break;
for(int i = 0; i < totalWings; i++) {
String wingName = dis.readUTF();
int leaderId = dis.readInt();
int factionId = dis.readInt();
boolean invite = dis.readBoolean();
wingSystem.createWing(wingName, leaderId, factionId, invite);
wingInfoUIRenderer.updateWings();
wingInfoUIRenderer.updatePlayers();
}
instances++;
}
final int bytesRead = bytesLeftBefore - dis.available() - 4; // subtract end of list int
digestStats.addToComponentStats(Faction.class, bytesRead, instances);
}
private void readEventData(DigestStats digestStats, DataInputStream dis) throws IOException {
// pass this to SerializableEvent.readOrWrite()
......
......@@ -78,16 +78,6 @@ public class PlayerInfoSys extends IteratingSystem {
protected void process(int ePlayer) {
int e = netSys.getEntityByNetID(mPlayer.get(ePlayer).getHumanNetID());
int wing = -1;
IntBag wings = netSys.getBagOf(Aspect.all(Wing.class));
for(int i = 0; i < wings.size(); i++) {
int eWing = wings.get(i);
if(mWing.has(eWing)) {
Wing w = mWing.get(eWing);
if(w.hasMember(netSys.getNetID(ePlayer)))
wing = eWing;
}
}
if (e > 0) {
addPlayerID(e);
......@@ -96,7 +86,6 @@ public class PlayerInfoSys extends IteratingSystem {
(int) mHealth.get(e).getHealth(),
(int) mOxygen.get(e).getOxygen(),
mFaction.get(e).getFaction(),
wing,
0,
mStancing.get(e).isSeated());
} else {
......@@ -105,7 +94,6 @@ public class PlayerInfoSys extends IteratingSystem {
0,
0,
mFaction.get(ePlayer).getFaction(),
wing,
0,
false);
}
......@@ -127,7 +115,7 @@ public class PlayerInfoSys extends IteratingSystem {
}
}
private void addPlayerInfo(int eHuman, int ePlayer, String name, int hp, int oxygen, int fac, int wing, int scrap, boolean sit) {
private void addPlayerInfo(int eHuman, int ePlayer, String name, int hp, int oxygen, int fac, int scrap, boolean sit) {
String labelName;
switch (fac) {
......@@ -163,7 +151,6 @@ public class PlayerInfoSys extends IteratingSystem {
info.labelName = labelName;
info.worldPos = pos;
info.faction = fac;
info.wing = wing;
info.sitting = sit;
info.scrap = scrap;
playerInfos.add(info);
......
......@@ -73,6 +73,7 @@ public class FactionInfoUIRenderer extends UniversalUIRenderer implements LmlVie
// private HashMap<Integer, Table> factionTables;
private String selectedPlayer;
private int selectedPlayerId;
private String selectedFaction;
private String selectedPlayerName;
private TextButton selectedButton;
......@@ -93,7 +94,6 @@ public class FactionInfoUIRenderer extends UniversalUIRenderer implements LmlVie
public void initialize() {
super.initialize();
playerList = new HashMap<>();
// factionTables = new HashMap<>();
}
@Override
......@@ -194,20 +194,20 @@ public class FactionInfoUIRenderer extends UniversalUIRenderer implements LmlVie
});
game_ref.lmlParser.getData().addActorConsumer("mute", (ActorConsumer<Boolean, TextButton>) actor -> {
// if(selectedPlayer > 0) {
// if (mMute.has(selectedPlayer)) {
// log.info("Unmuting {}", selectedPlayer);
// mMute.remove(selectedPlayer);
// Label l = (Label) selectedButton.getChildren().get(1);
// l.setText("");
// } else {
// log.info("Muting {}", selectedPlayer);
// mMute.create(selectedPlayer);
// Label l = (Label) selectedButton.getChildren().get(1);
// l.setColor(Color.BLACK);
// l.setText("Muted");
// }
// }
if(selectedPlayerId > 0) {
if (mMute.has(selectedPlayerId)) {
log.info("Unmuting {}", selectedPlayer);
mMute.remove(selectedPlayerId);
Label l = (Label) selectedButton.getChildren().get(1);
l.setText("");
} else {
log.info("Muting {}", selectedPlayer);
mMute.create(selectedPlayerId);
Label l = (Label) selectedButton.getChildren().get(1);
l.setColor(Color.BLACK);
l.setText("Muted");
}
}
return null;
});
game_ref.lmlParser.getData().addActorConsumer("back", (ActorConsumer<Boolean, TextButton>) actor -> {
......@@ -257,10 +257,6 @@ public class FactionInfoUIRenderer extends UniversalUIRenderer implements LmlVie
});
game_ref.lmlParser.createView(this, new FileHandle(game_ref.app.clientDataDir() + File.separator + "windows" + File.separator + "Factions Window.lml"));
//
// factionList.setScrollingDisabled(true, false);
// factionList.getStyle().vScroll=null;
// factionList.getStyle().vScrollKnob=null;
factionList.setFillParent(true);
stage.addListener(new InputListener(){
......@@ -306,10 +302,11 @@ public class FactionInfoUIRenderer extends UniversalUIRenderer implements LmlVie
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
selectedPlayer = b.getName();
selectedPlayerId = ePlayer;
}
});
playerList.get(factionSystem.getFactionName(i)).top();
playerList.get(factionSystem.getFactionName(i)).add(b).width(780-180).height(20).padTop(10).padLeft(5).padRight(5).row();
playerList.get(factionSystem.getFactionName(i)).add(b).width(780-180).height(20).padTop(5).padLeft(5).padRight(5).row();
}
}
}
......
......@@ -100,6 +100,7 @@ public class GameScreen extends IAScreen {
new ShipSys(),
new PlanetProximitySys(),
new FactionSystem(),
new WingSystem(),
new ZoneSystem(),
new SysClientHuman(),
new TileAnimationSys(),
......
......@@ -129,6 +129,7 @@ public final class NetworkingConstants {
public static final int CS_DISBAND_WING = 36; //
public static final int CS_PROMOTE_PLAYER = 37; //
public static final int CS_LOCK_WING = 38; //
public static final int CS_KICK_PLAYER_FROM_WING = 39; //
......@@ -145,6 +146,7 @@ public final class NetworkingConstants {
public static final int SC_VOICE_DATA = 8;
public static final int SC_SEND_BLUEPRINT_DATA = 9;
public static final int SC_SEND_FACTION_DATA = 10;
public static final int SC_SEND_WING_DATA = 11;
// Text commands
public static final String CMD_HELP = "help";
......@@ -192,6 +194,7 @@ public final class NetworkingConstants {
public static final int D_EVENT_DATA = 4;
public static final int D_CURRENT_TICK = 5; // long, float (tick, time)
public static final int D_FACTION_DATA = 6;
public static final int D_WING_DATA = 7;
// Server states (sent to client)
// !!! NOTE: If you add/remove/modify these, you MUST add/remove/modify ServerState.getStateText()
......
......@@ -10,153 +10,33 @@ import java.io.IOException;
public class Wing extends SerializableComponent {
@NotNull
private final NetProp<String> name = new NetProp<>("Wing");
private final NetProp<Integer> wing = new NetProp<>(-1);
@NotNull
private final NetProp<Integer> faction = new NetProp<>(-1);
@NotNull
private final NetProp<Integer> leader = new NetProp<>(-1);
@NotNull
private final NetProp<String> leaderName = new NetProp<>("");
@NotNull
private final NetProp<int[]> members = new NetProp<>(new int[0]);
@NotNull
private final NetProp<Boolean> locked = new NetProp<>(false);
private final NetProp<Boolean> leader = new NetProp<>(false);
public void readOrWrite(@NotNull ReaderOrWriter r) throws IOException
{
this.setName(r.x(this.getName()));
this.setWing(r.x(this.getWing()));
this.setLeader(r.x(this.getLeader()));
this.setLeaderName(r.x(this.getLeaderName()));
this.setFaction(r.x(this.getFaction()));
this.setMembers(r.x(this.getMembers()));
this.setLocked(r.x(this.getLocked()));
}
public String getName()
public int getWing()
{
return name.getValue();
return wing.getValue();
}
public void setName(String name)
public void setWing(int wingId)
{
this.name.setValue(name);
this.wing.setValue(wingId);
}
public int getLeader()
public boolean getLeader()
{
return leader.getValue();
}
public void setLeader(int playerID)
{
this.leader.setValue(playerID);
}
public String getLeaderName()
{
return leaderName.getValue();
}
public void setLeaderName(String playerName)
{
this.leaderName.setValue(playerName);
}
public int getFaction()
{
return faction.getValue();
}
public void setFaction(int faction)
{
this.faction.setValue(faction);
}
public int[] getMembers()
{
return members.getValue();
}
public void setMembers(int[] members)
public void setLeader(boolean leader)
{
this.members.setValue(members);
}
public boolean getLocked() {
return this.locked.getValue();
}
public void setLocked(boolean locked) {
this.locked.setValue(locked);
}
public void addPlayer(int ePlayer) {
int[] members = new int[getMembers().length + 1];
for(int i = 0; i < this.members.getValue().length; i++) {
members[i] = this.members.getValue()[i];
}
members[getMembers().length] = ePlayer;
this.members.setValue(members);
}
public boolean hasMember(int eMember) {
for(int i = 0; i < getMembers().length; i++) {
if(getMembers()[i] == eMember)
return true;
}
return false;
}
public void removeMember(int ePlayer) {
for(int i = 0; i < getMembers().length; i++) {
if(getMembers()[i] == ePlayer)
getMembers()[i] = -1;
}
}
public static final String AlphaCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static final String ALPHA = "ALPHA";
public static final String BRAVO = "BRAVO";
public static final String CHARLIE = "CHARLIE";
public static final String DELTA = "DELTA";
private static String randomCharacter()
{
return String.valueOf(Core.AlphaCharacters.charAt(MathUtils.random(Core.AlphaCharacters.length() - 1)));
}
private static String randomNumber()
{
return String.valueOf(MathUtils.random(0,99));
}
public static String generateName()
{
return generateName(MathUtils.random(99));
}
public static String generateName(int seed) {
StringBuilder name = new StringBuilder();
int r = MathUtils.random(0,3);
switch (r) {
case 0:
name.append(Wing.ALPHA);
break;
case 1:
name.append(Wing.BRAVO);
break;
case 2:
name.append(Wing.CHARLIE);
break;
case 3:
name.append(Wing.DELTA);
break;
}
name.append(" ");
name.append(randomNumber());
name.append("-");
name.append(randomCharacter());
// name.append(String.format("%01d", seed % 10000));
return name.toString();
this.leader.setValue(leader);
}
}
package com.drakelinglabs.ironarmada.common.system;
import com.artemis.Aspect;
import com.artemis.BaseEntitySystem;
import com.artemis.ComponentMapper;
import com.artemis.annotations.Wire;
import com.artemis.utils.IntBag;
import com.badlogic.gdx.math.MathUtils;
import com.drakelinglabs.ironarmada.common.component.*;
import net.mostlyoriginal.api.system.core.PassiveSystem;
import org.slf4j.LoggerFactory;
import java.util.*;
public class WingSystem extends BaseEntitySystem {
private final org.slf4j.Logger log = LoggerFactory.getLogger(getClass());
private HashMap<Integer, WingInfo> wings;
@Wire
private NetSys netSys;
@Wire
private ComponentMapper<Wing> mWing;
@Wire
private ComponentMapper<Player> mPlayer;
@Wire
private ComponentMapper<PlayerID> mPlayerId;
@Wire
private ComponentMapper<ComHuman> mHuman;
@Override
protected void initialize() {
wings = new HashMap<>();
}
public WingSystem() {
super(Aspect.all(Wing.class));
}
@Override
protected void processSystem() {
IntBag wingBag = netSys.getBagOf(Aspect.all(Wing.class));
for(int i = 0; i < wingBag.size(); i++) {
int wingId = wingBag.get(i);
if(mWing.has(wingId)) {
}
}
}
public boolean isWingLocked(int wing) {
return wings.get(wing).locked;
}
public int createWing(String name, int leaderId, int factionId, boolean locked){
int wingId = -1;
if (!checkWingExists(name)) {
wingId = getNextID();
WingInfo wingInfo = new WingInfo(wingId, leaderId, factionId, name, locked);
wings.put(wingId, wingInfo);
}
return wingId;
}
public WingInfo getWing(int id) {
WingInfo wingInfo = null;
for(Map.Entry e : wings.entrySet()){
wingInfo = (WingInfo) e.getValue();
if(wingInfo.getWingId() == id)
return wingInfo;
}
return wingInfo;
}
public String getWingName(int id) {
String wingName = "";
for(Map.Entry e : wings.entrySet()){
if((int)e.getKey() == id) {
WingInfo wingInfo = (WingInfo) e.getValue();
wingName = wingInfo.wingName;
}
}
return wingName;
}
public int getWingIdByName(String wingName) {
int wingId = 0;
for(Map.Entry e : wings.entrySet()) {
WingInfo wingInfo = (WingInfo) e.getValue();
if(wingInfo.getWingName().equals(wingName))
wingId = wingInfo.getWingId();
}
return wingId;
}
public void deleteWing(String name) {
wings.remove(getWingIdByName(name));
}
public ArrayList<WingInfo> getWings() {
ArrayList<WingInfo> wingInfos = new ArrayList<>();
for(Map.Entry e : wings.entrySet()) {
if(!wingInfos.contains(e.getValue()))
wingInfos.add((WingInfo) e.getValue());
}
return wingInfos;
}
private int getNextID(){
int id = 1;
while (wings.containsKey(id)) {
id++;
}
return id;
}
public void clearWings() {
wings.clear();
}
public int getTotalWings() {
return wings.size();
}
private boolean checkWingExists(String name) {
boolean doesExist = false;
for (Map.Entry e : wings.entrySet()) {
WingInfo wingInfo = (WingInfo) e.getValue();
if(wingInfo.wingName.equals(name)){
doesExist = true;
}
}
return doesExist;
}
public int getPlayersInWing(int wingId) {
int playerCount = 0;
IntBag players = netSys.getBagOf(Aspect.all(Player.class));
for(int i = 0; i < players.size(); i++) {
if(mWing.get(players.get(i)).getWing() == wingId)
playerCount++;
}
return playerCount;
}
public int getRandomPlayerInWing(int wingId) {
ArrayList<Integer> players = new ArrayList<>();
IntBag playerBag = netSys.getBagOf(Aspect.all(Player.class));
for(int i = 0; i < playerBag.size(); i++) {
if(mWing.get(playerBag.get(i)).getWing() == wingId && !mWing.get(playerBag.get(i)).getLeader())
players.add(playerBag.get(i));
}
int playerIndex = MathUtils.random(players.size());
return players.get(playerIndex);
}
public static class WingInfo {
private int wingId;
private int leaderId;
private int factionId;
private String wingName;
private boolean locked;
public WingInfo(int wingId, int leaderId, int factionId, String wingName, boolean locked) {
this.wingId = wingId;
this.leaderId = leaderId;
this.factionId = factionId;
this.wingName = wingName;
this.locked = locked;
}
public int getWingId() {
return wingId;
}
public int getLeaderId() {
return leaderId;
}
public int getFactionId() {
return factionId;
}
public String getWingName() {
return wingName;
}
public void setWingName(String wingName) {
this.wingName = wingName;
}
public boolean getLocked() {
return locked;
}
public void setLocked(boolean locked) {
this.locked = locked;
}
}
public static final String AlphaCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static final String ALPHA = "ALPHA";
public static final String BRAVO = "BRAVO";
public static final String CHARLIE = "CHARLIE";
public static final String DELTA = "DELTA";
private static String randomCharacter()
{
return String.valueOf(Core.AlphaCharacters.charAt(MathUtils.random(Core.AlphaCharacters.length() - 1)));
}
private static String randomNumber()
{
return String.valueOf(MathUtils.random(0,99));
}
public static String generateName()
{
return generateName(MathUtils.random(99));
}