Search in sources :

Example 6 with Card

use of com.janfic.games.computercombat.model.Card in project computercombat by janfic.

the class SQLAPI method getCardsInfo.

public List<Card> getCardsInfo(List<Integer> cardIDs, String optionalUID) {
    List<Card> cards = new ArrayList<>();
    try {
        String sql = "SELECT * FROM card\n" + "JOIN ability ON card.ability_id = ability.id\n" + "JOIN join_components ON card.id = join_components.card\n" + "JOIN collection ON card.collection_id = collection.id ;";
        Statement statement = connection.createStatement();
        ResultSet set = statement.executeQuery(sql);
        boolean areRowsLeft = set.next();
        while (areRowsLeft) {
            Card c = readCardFromSet(set, optionalUID);
            if ((cardIDs == null || cardIDs.contains(c.getID())) && c.getID() != 0) {
                cards.add(c);
            }
            areRowsLeft = set.next();
        }
    } catch (Exception e) {
        e.printStackTrace();
        return cards;
    }
    return cards;
}
Also used : Statement(java.sql.Statement) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) Card(com.janfic.games.computercombat.model.Card)

Example 7 with Card

use of com.janfic.games.computercombat.model.Card 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;
}
Also used : Ability(com.janfic.games.computercombat.model.Ability) HashMap(java.util.HashMap) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) Card(com.janfic.games.computercombat.model.Card) ResultSet(java.sql.ResultSet) Collection(com.janfic.games.computercombat.model.Collection)

Example 8 with Card

use of com.janfic.games.computercombat.model.Card in project computercombat by janfic.

the class CardToFrontAnimation method animate.

@Override
public List<List<Action>> animate(String currentPlayerUID, String playerUID, MatchScreen screen, float animationSpeed) {
    List<List<Action>> animation = new ArrayList<>();
    List<Action> toFrontActions = new ArrayList<>();
    for (Card card : cards) {
        SoftwareActor first = screen.getSoftwareActors().get(card.getOwnerUID()).get(0);
        SoftwareActor actor = screen.getSoftwareActorByMatchID(card.getOwnerUID(), card.getMatchID());
        screen.getSoftwareActors().get(card.getOwnerUID()).remove(actor);
        screen.getSoftwareActors().get(card.getOwnerUID()).add(0, actor);
        Action toFrontAction = Actions.sequence(Actions.moveTo(first.getX(), first.getY(), 1 * animationSpeed), Actions.run(() -> {
            screen.buildPanels();
        }));
        toFrontAction.setActor(actor);
        toFrontActions.add(toFrontAction);
    }
    animation.add(toFrontActions);
    return animation;
}
Also used : Action(com.badlogic.gdx.scenes.scene2d.Action) SoftwareActor(com.janfic.games.computercombat.actors.SoftwareActor) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Card(com.janfic.games.computercombat.model.Card)

Example 9 with Card

use of com.janfic.games.computercombat.model.Card in project computercombat by janfic.

the class ChangeStatAnim method animate.

@Override
public List<List<Action>> animate(String currentPlayerUID, String playerUID, MatchScreen screen, float animationSpeed) {
    List<List<Action>> animation = new ArrayList<>();
    List<Action> actions = new ArrayList<>();
    if (card instanceof Card) {
        SoftwareActor softwareActor = screen.getSoftwareActorByMatchID(this.playerUID, card.getMatchID());
        Action action = new ChangeStatAction(1 * animationSpeed, statChange, newAmount);
        action.setActor(softwareActor);
        actions.add(action);
    }
    animation.add(actions);
    return animation;
}
Also used : Action(com.badlogic.gdx.scenes.scene2d.Action) TemporalAction(com.badlogic.gdx.scenes.scene2d.actions.TemporalAction) SoftwareActor(com.janfic.games.computercombat.actors.SoftwareActor) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Card(com.janfic.games.computercombat.model.Card)

Example 10 with Card

use of com.janfic.games.computercombat.model.Card in project computercombat by janfic.

the class DestroyCardAnimation method animate.

@Override
public List<List<Action>> animate(String currentPlayerUID, String playerUID, MatchScreen screen, float animationSpeed) {
    List<List<Action>> animation = new ArrayList<>();
    List<Action> actions = new ArrayList<>();
    for (Card card : destroyed) {
        SoftwareActor actor = screen.getSoftwareActorByMatchID(this.playerUID, card.getMatchID());
        Action action = Actions.sequence(Actions.fadeOut(1 * animationSpeed), Actions.removeActor(), Actions.run(new Runnable() {

            @Override
            public void run() {
                screen.getSoftwareActors().get(DestroyCardAnimation.this.playerUID).remove(actor);
                screen.buildPanels();
            }
        }));
        action.setActor(actor);
        actions.add(action);
    }
    animation.add(actions);
    return animation;
}
Also used : Action(com.badlogic.gdx.scenes.scene2d.Action) SoftwareActor(com.janfic.games.computercombat.actors.SoftwareActor) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Card(com.janfic.games.computercombat.model.Card)

Aggregations

Card (com.janfic.games.computercombat.model.Card)42 ArrayList (java.util.ArrayList)28 List (java.util.List)12 MoveResult (com.janfic.games.computercombat.model.moves.MoveResult)11 MoveAnimation (com.janfic.games.computercombat.model.moves.MoveAnimation)10 Action (com.badlogic.gdx.scenes.scene2d.Action)9 SoftwareActor (com.janfic.games.computercombat.actors.SoftwareActor)8 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)7 Component (com.janfic.games.computercombat.model.Component)6 ResultSet (java.sql.ResultSet)6 Statement (java.sql.Statement)6 HashMap (java.util.HashMap)6 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)5 Deck (com.janfic.games.computercombat.model.Deck)5 UseAbilityMove (com.janfic.games.computercombat.model.moves.UseAbilityMove)5 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)4 CollectionCard (com.janfic.games.computercombat.actors.CollectionCard)4 Collection (com.janfic.games.computercombat.model.Collection)4 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)3 ComputerActor (com.janfic.games.computercombat.actors.ComputerActor)3