use of com.janfic.games.computercombat.model.Collection in project computercombat by janfic.
the class SQLAPI method getPlayerOwnedCards.
public Map<Card, Integer> getPlayerOwnedCards(String uid) {
System.out.println("[SERVER][MYSQL]: Querying for Player collection");
Map<Card, Integer> cards = new HashMap<>();
try {
// Get all player owned cards
String sql = "SELECT * FROM card \n" + "JOIN profile_owns_card ON card.id = profile_owns_card.card_id \n" + "JOIN profile ON profile.uid = profile_owns_card.profile_id \n" + "JOIN ability ON card.ability_id = ability.id\n" + "JOIN run_requirements ON card.id = run_requirements.card_id\n" + "JOIN components ON components.id = run_requirements.component_id\n" + "JOIN collection ON card.collection_id = collection.id\n" + "WHERE profile.uid = '" + uid + "' ORDER BY card.id;";
Statement statement = connection.createStatement();
ResultSet set = statement.executeQuery(sql);
boolean next = set.next();
while (next) {
int currentID = set.getInt("card.id");
Ability a = (Ability) shell.evaluate(set.getString("ability.code"));
a.setInformation(set.getString("ability.description"), set.getString("ability.textureName"), set.getString("ability.name"), set.getString("ability.code"), set.getInt("ability.id"));
Collection c = new Collection(set.getInt("collection.id"), set.getString("collection.name"), set.getString("collection.description"), set.getString("collection.textureName"), set.getString("collection.path"), set.getInt("collection.price"));
List<Integer> components = new ArrayList<>();
int id = set.getInt("card.id");
String name = set.getString("card.name");
String textureName = set.getString("card.textureName");
int level = set.getInt("card.level");
int maxHealth = set.getInt("card.maxHealth");
int maxDefense = set.getInt("card.maxDefense");
int maxAttack = set.getInt("card.maxAttack");
int runRequirements = set.getInt("card.runRequirements");
int rarity = set.getInt("card.rarity");
int amount = set.getInt("profile_owns_card.amount");
String description = set.getString("card.description");
do {
components.add(set.getInt("components.id"));
next = set.next();
} while (next && currentID == set.getInt("card.id"));
int[] componentTypes = new int[components.size()];
for (int i = 0; i < components.size(); i++) {
componentTypes[i] = components.get(i);
}
Card s = new Card(id, uid, name, c, textureName, level, maxHealth, maxDefense, maxAttack, // magic
1, componentTypes, runRequirements, a, rarity, description);
cards.put(s, amount);
}
} catch (Exception e) {
e.printStackTrace();
}
return cards;
}
use of com.janfic.games.computercombat.model.Collection in project computercombat by janfic.
the class FilterWindowActor method buildCollectionTable.
private void buildCollectionTable() {
collectionTable.clear();
List<Collection> collections = SQLAPI.getSingleton().getCollections();
for (Collection collection : collections) {
Table table = new Table();
table.defaults().pad(1);
TextureAtlas texturePack = game.getAssetManager().get("texture_packs/" + collection.getTextureName() + ".atlas", TextureAtlas.class);
TextureRegion icon = texturePack.findRegion(collection.getPath() + "_icon");
if (icon == null) {
continue;
}
table.add(new Image(icon)).row();
LEDActor led = new LEDActor(skin, "NETWORK") {
@Override
public void act(float delta) {
super.act(delta);
this.setLightOn(FilterWindowActor.this.collections.contains((Integer) collection.getID()));
}
};
table.add(led);
collectionTable.add(table);
table.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if (FilterWindowActor.this.collections.contains(collection.getID())) {
FilterWindowActor.this.collections.remove((Integer) collection.getID());
led.setLightOn(false);
} else {
FilterWindowActor.this.collections.add((Integer) collection.getID());
led.setLightOn(true);
}
}
});
}
}
use of com.janfic.games.computercombat.model.Collection in project computercombat by janfic.
the class OpenPackScreen method show.
@Override
public void show() {
this.camera = new OrthographicCamera(1920 / 4, 1080 / 4);
this.stage = ComputerCombatGame.makeNewStage(camera);
this.skin = game.getAssetManager().get(Assets.SKIN);
this.collections = SQLAPI.getSingleton().getCollections();
List<Integer> collectionIDs = new ArrayList<>();
collectionIDs.add(collection.getID());
if (collection.getID() == 0) {
for (Collection c : collections) {
collectionIDs.add(c.getID());
}
}
collectionIDs.remove((Integer) 0);
this.collectionCards = SQLAPI.getSingleton().getCardsInCollection(collectionIDs, game.getCurrentProfile().getUID());
System.out.println(collectionCards);
this.pack = new CollectionPackActor(game, skin, collection);
pack.setScale(1.25f);
Gdx.input.setInputProcessor(stage);
Table table = new Table();
table.setFillParent(true);
table.defaults().space(20);
TextButton openButton = new TextButton("Open!", skin);
openButton.setTouchable(Touchable.disabled);
List<Card> openCards = new ArrayList<>();
openCards.add(roll());
openCards.add(roll());
openCards.add(roll());
end = new TextButton("Okay", skin);
end.setVisible(false);
end.setPosition(10, 10);
end.setSize(100, 30);
end.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
Map<Integer, Integer> added = new HashMap<>();
for (Card openCard : openCards) {
added.put(openCard.getID(), added.getOrDefault(openCard.getID(), 0) + 1);
}
SQLAPI.getSingleton().addCardsToProfile(added, game.getCurrentProfile());
SQLAPI.getSingleton().saveProfile(game.getCurrentProfile());
game.popScreen();
}
});
table.add(pack).row();
table.add(openButton).width(100).row();
Action cardAction = Actions.sequence(Actions.visible(false), Actions.delay(1), Actions.moveBy(0, -stage.getHeight() * 2), Actions.visible(true), Actions.moveBy(0, stage.getHeight() * 2, 2, Interpolation.fastSlow), Actions.delay(2));
Action buttonAction = Actions.sequence(Actions.fadeOut(0), Actions.delay(3), Actions.fadeIn(1), Actions.touchable(Touchable.enabled));
openButton.addAction(buttonAction);
pack.addAction(cardAction);
cardActors = new ArrayList<>();
openButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
pack.open();
openButton.setVisible(false);
Action open = Actions.sequence(Actions.moveBy(0, -200, 1), Actions.run(() -> {
confetti();
for (CollectionCard openCard : cardActors) {
openCard.setPosition(pack.getX(), pack.getY());
openCard.setSize(pack.getWidth() - 4, pack.getHeight());
openCard.addAction(Actions.parallel(Actions.moveBy(0, 200, 1, Interpolation.circleOut), Actions.moveBy((cardActors.indexOf(openCard) - 1) * 150, 0, 1, Interpolation.circleIn)));
}
}), Actions.run(() -> {
end.setVisible(true);
}));
pack.addAction(open);
}
});
for (Card openCard : openCards) {
CollectionCard c = new CollectionCard(game, skin, openCard, 1);
cardActors.add(c);
stage.addActor(c);
}
stage.addActor(table);
stage.addActor(end);
table.layout();
}
use of com.janfic.games.computercombat.model.Collection in project computercombat by janfic.
the class DownloadScreen method show.
@Override
public void show() {
this.cam = new OrthographicCamera(1920 / 4, 1080 / 4);
this.stage = ComputerCombatGame.makeNewStage(cam);
this.collections = SQLAPI.getSingleton().getCollections();
packs.clear();
for (Collection collection : collections) {
packs.add(new CollectionPackActor(game, skin, collection));
}
Gdx.input.setInputProcessor(stage);
Table table = new Table();
table.setFillParent(true);
table.defaults().space(5);
table.pad(4);
packsTable = new Table(skin);
packsTable.defaults().space(5);
ScrollPane scrollPane = new ScrollPane(packsTable, skin);
makePacks();
Panel packInfoTable = new Panel(skin);
packInfoTable.defaults().space(3).pad(2);
packInfoTable.top();
Label packInfoLabel = new Label("About", skin, "title");
packInfoLabel.setAlignment(Align.center);
packInfoTable.add(packInfoLabel).growX().row();
packName = new Label("Press a Pack to learn more.", skin);
packDescription = new Label("Press a Pack to learn more.", skin);
Label packPriceLabel = new Label("Packets to Download:", skin);
packPrice = new Label("???", skin);
packName.setWrap(true);
packPrice.setWrap(true);
packDescription.setWrap(true);
packPriceLabel.setWrap(true);
packName.setAlignment(Align.center);
packPrice.setAlignment(Align.center);
packDescription.setAlignment(Align.center);
packPriceLabel.setAlignment(Align.center);
Image packetsImage = new Image(game.getAssetManager().get("texture_packs/components.atlas", TextureAtlas.class).findRegion("network"));
Table packetTable = new Table(skin);
packetTable.defaults().space(10);
packetTable.add(packetsImage).size(24, 24);
packetTable.add(packPrice);
packInfoTable.add(packName).growX().row();
packInfoTable.add(packDescription).grow().row();
packInfoTable.add(packPriceLabel).growX().expandY().bottom().row();
packInfoTable.add(packetTable).growX().row();
TextButton viewCollectionButton = new TextButton("View Collection", skin);
final TextButton downloadButton = new TextButton("Download", skin);
packInfoTable.add(viewCollectionButton).growX().row();
packInfoTable.add(downloadButton).growX();
Table titleTable = new Table(skin);
titleTable.setBackground("border");
Label title = new Label("Card Packs", skin);
title.setAlignment(Align.center);
TextButton backButton = new TextButton("Back", skin);
backButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
game.popScreen();
}
});
Image playerPacketImage = new Image(game.getAssetManager().get("texture_packs/components.atlas", TextureAtlas.class).findRegion("network"));
Table playerPacketTable = new Table(skin);
playerPacketTable.defaults().padRight(10);
playerPacketTable.add(new Label("Your Packets: ", skin));
playerPacketTable.add(playerPacketImage).size(24, 24);
playerPacketTable.add(new Label("" + game.getCurrentProfile().getPackets(), skin));
titleTable.add(backButton);
titleTable.add(title).growX();
titleTable.add(playerPacketTable).row();
table.add(scrollPane).grow();
table.add(packInfoTable).minWidth(200).growY().row();
table.add(titleTable).growX().colspan(2).row();
stage.addActor(table);
downloadButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if (game.getCurrentProfile().getPackets() >= collections.get(selected).getPrice()) {
downloadButton.addAction(Actions.sequence(Actions.touchable(Touchable.disabled), Actions.color(Color.GREEN), Actions.color(Color.WHITE, 1), Actions.run(() -> {
game.getCurrentProfile().setPackets(game.getCurrentProfile().getPackets() - collections.get(selected).getPrice());
game.pushScreen(new OpenPackScreen(game, collections.get(selected)));
}), Actions.touchable(Touchable.enabled)));
} else {
downloadButton.addAction(Actions.sequence(Actions.touchable(Touchable.disabled), Actions.color(Color.RED), Actions.color(Color.WHITE, 1), Actions.touchable(Touchable.enabled)));
}
}
});
viewCollectionButton.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
if (selected > 0) {
game.pushScreen(new CollectionScreen(game, collections.get(selected)));
}
}
});
}
use of com.janfic.games.computercombat.model.Collection in project computercombat by janfic.
the class SQLAPI method getCollections.
public List<Collection> getCollections() {
List<Collection> collections = new ArrayList<>();
try {
String sql = "SELECT * FROM collection;";
Statement statement = connection.createStatement();
ResultSet set = statement.executeQuery(sql);
while (set.next()) {
Collection c = new Collection(set.getInt("id"), set.getString("name"), set.getString("description"), set.getString("textureName"), set.getString("path"), set.getInt("price"));
collections.add(c);
}
} catch (Exception e) {
e.printStackTrace();
}
return collections;
}
Aggregations