/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.objects.cards;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import java.util.ArrayList;
import transientlibs.slick2d.util.Log;
import transientlibs.bindedobjects.core.datasets.Action;
import transientlibs.bindedobjects.gamecontent.Cards;
import transientlibs.processors.misc.Detonator;
import transientlibs.objects.general.Dice;
import transientlibs.objects.general.NodeArrayList;
import transientlibs.preui.objects.gui.elements.ButtonGroup;
import transientlibs.preui.objects.states.IState;
/**
*
* @author kibertoad
*/
public class Deck {
public ButtonGroup handButtons;
public Card selectedCard;
public int handX = 0;
public int handY = 0;
public int handSpacingX = 20;
public ArrayList<Card> hand = new ArrayList<Card>();
public ArrayList<Card> cards = new ArrayList<Card>(); //all available
public int handLimit;
public NodeArrayList<Action> availableCards = new NodeArrayList<Action>();
public NodeArrayList<Action> collectCardsByGroup(String withGroup) {
NodeArrayList<Action> collector = new NodeArrayList<Action>();
for (Action a : Action.container.elements) {
if (a.group.equals(withGroup)) {
collector.add(a);
}
}
return collector;
}
public NodeArrayList<Action> collectCardsByTag(String withTag) {
NodeArrayList<Action> collector = new NodeArrayList<Action>();
for (Action a : Action.container.elements) {
if (a.hasTag(withTag)) {
collector.add(a);
}
}
return collector;
}
public Action getRandomCardActionByGroup(String withGroup) {
NodeArrayList<Action> collector = collectCardsByGroup(withGroup);
return collector.returnRandomElement();
}
public Action getRandomCardActionByTag(String withTag) {
NodeArrayList<Action> collector = collectCardsByTag(withTag);
return collector.returnRandomElement();
}
public void getCard(Action ofAction) {
hand.add(new Card(ofAction));
}
public void drawCard(NodeArrayList<Action> collectedCards) {
Dice cardRoller = new Dice();
for (Action a : collectedCards) {
cardRoller.addOption(a.adjustedChanceToDraw, a.ID);
}
cardRoller.rollDice();
getCard(Action.getActionByID(cardRoller.resultID));
Log.info("Card drawn: " + hand.get(hand.size() - 1).action.LName);
}
public void drawCardFromGroup (String withGroup) {
NodeArrayList<Action> collector = collectCardsByGroup(withGroup);
drawCard(collector);
}
public void placeHandPanel (IState state){
handButtons = new ButtonGroup (100, 100, Detonator.INSTANCE.fontProvider.getDefaultFont(), state);
}
public void attachHandPanel (IState state){
state.passMarker(handButtons);
}
public void drawHand (){
handButtons.restartFilling();
for (Card c : hand) {
handButtons.addOption(c.action.LName.value);
}
handButtons.complete();
}
public void drawHandCards (){
//Log.info("Cards in hand: "+ hand.size());
for (Card c: hand) {
//Log.info("Draw card");
//if (c != selectedCard) {c.draw();} else {
// c.draw(c.screenCoords.getIntX(), c.screenCoords.getIntY() - 20);
//}
c.draw();
}
}
public void drawHandCards (SpriteBatch spriteBatch){
//Log.info("Cards in hand: "+ hand.size());
//if (spriteBatch == null) {
// Log.error("NO BATCH");
//}
for (Card c: hand) {
//Log.info("Draw card");
//if (c != selectedCard) {c.draw();} else {
// c.draw(c.screenCoords.getIntX(), c.screenCoords.getIntY() - 20);
//}
c.draw(spriteBatch);
}
}
public void addCard(String cardid) {
cards.add(new Card (Cards.getCardsByCode(cardid)));
//cards.add(Cards.getCardsByCode(cardid).ca);
}
public void addCard(Cards card) {
cards.add(new Card (card));
//cards.add(Cards.getCardsByCode(cardid).ca);
}
public void addCardToHand (Card card){
if (!(hand.contains(card))) {
hand.add(card);
Log.info("Move to: Width"+ card.getWidth());
card.moveMarker(handX + ( (handSpacingX + card.getWidth()) * (hand.size())), handY);
}
}
public void resetHand (IState state) {
if (state != null) {
for (Card c: hand) {
state.removeMarker(c);
}
}
hand.clear();
selectedCard = null;
}
public void selectCard(Card card) {
if (selectedCard != null) {
selectedCard.moveMarkerByDelta(0, 20);
}
selectedCard = card;
selectedCard.moveMarkerByDelta(0, -20);
}
public void selectRandomCard() {
selectCard(hand.get(Detonator.INSTANCE.rng.nextInt(hand.size())));
}
public boolean containsCards(Cards i) {
for (Card c : cards) {
if (c.cards == i) return true;
Log.info("have card "+i.name());
}
return false;
}
}