Package transientlibs.bindedobjects.gamecontent

Source Code of transientlibs.bindedobjects.gamecontent.Cards

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.bindedobjects.gamecontent;

import transientlibs.bindedobjects.core.datasets.Action;
import java.io.File;
import java.util.ArrayList;
import transientlibs.slick2d.util.Log;
import transientlibs.bindedobjects.core.Binding;
import transientlibs.bindedobjects.core.datasets.LesserBindedValue;
import transientlibs.bindedobjects.core.Tex;
import transientlibs.processors.misc.Detonator;
import transientlibs.preui.objects.gui.interfaces.IImage;
import transientlibs.objects.primitives.Int;
import transientlibs.tex.ActList;
import transientlibs.tex.ReqList;
import transientlibs.tex.StringAnalyst;

/**
*
* @author kibertoad
*/
public class Cards extends LesserBindedValue {

    public static float scale = 1;

    public Int price = new Int (1000);
    public Action action;
    public int cardType; //defined in cardgroups
    public boolean isStackable = false;
    public Int keepLimit = new Int(100000); //item limit
    public CombatEffect stats = null;
    public ReqList reqs = new ReqList();
    public static ReqList globalReqs = new ReqList();
    public static ReqList globalActivationReq = new ReqList();
    public static ActList globalActs = new ActList();
    public static ArrayList<String> globalTags = new ArrayList<String>();
    public static String globalGroup = "-";
    public static ArrayList<Cards> cards = new ArrayList<Cards>();
    public IImage image;
    public IImage largeImage;
    public static Cards lastCard;

    public static void loadAllCards() {
        File dir = new File(Detonator.INSTANCE.currentModule.dirName + "cards");
        String[] fileList = dir.list();

        if (fileList == null) {

            Log.warn(Detonator.INSTANCE.currentModule.dirName + "cards");
            Log.warn("Specified directory does not exist!");
        } else {

            for (int x = 0; x < fileList.length; x++) {

                if (fileList[x].endsWith(".dat")) {
                    Log.info(fileList[x]);
                    //loadMap("maps/" + fileList[x]);

                    globalActs.clear();
                    globalActivationReq.clear();
                    globalTags.clear();
                    globalReqs.clear();
                    globalGroup = "-";

                    loadCards("cards/" + fileList[x]);
                }


            }


        }
    }

    public static void loadCards(String fromFile) {

        if (StringAnalyst.isFileExist(fromFile)) {

            StringAnalyst reader = new StringAnalyst();


            reader.openFile(fromFile);

            while (!reader.eof) {

                reader.readRow();
                analyzeStringForCards(reader);
            }

            reader.closeFile();
        }
    }

    public static void analyzeStringForCards(StringAnalyst analyst) {
        analyzeStringForCards("-NO-", analyst);
    }

    public static void analyzeStringForCards(String getString, StringAnalyst analyst) {

        if (!"-NO-".equals(getString)) {
            analyst.fullStr = getString;
        }

        analyst.getNextString();
        String nowStr = analyst.lastStr;

        boolean withResult = false;

        if (nowStr.equals("card")) {

            cards.add(new Cards());
            lastCard = cards.get(cards.size() - 1);
            lastCard.ID = analyst.getBinding(Binding.cardBinding);

            //ReqList.lastReqList = lastItems.trainReqs;

            withResult = true;

        }

        if (nowStr.equals("combateffect")) {
            lastCard.stats = new CombatEffect();
            CombatEffect.lastCombatEffect = lastCard.stats;

            CombatEffect.continousAnalysisForCombatEffect(analyst);

            withResult = true;
        }

        if (nowStr.equals("type")) {
            lastCard.cardType = analyst.readBinding(Binding.cardTypeBinding);
            withResult = true;
        }
       
        if (nowStr.equals("reqs")) {
            ReqList.lastReqList = lastCard.reqs;

            withResult = true;
        }


        if (nowStr.equals("name")) {
            lastCard.LName.value = analyst.restOfRow();
            withResult = true;
        }
       
        if (nowStr.equals("price")) {
            lastCard.price.value = analyst.getNextNumber();
            withResult = true;
        }
       
        if (nowStr.equals("action")) {
            lastCard.action = Action.getActionByCode(analyst.getNextString());
            withResult = true;
        }

        if (nowStr.equals("desc")) {
            lastCard.desc = analyst.restOfRow();
            withResult = true;
        }
       
        if (nowStr.equals("tag")) {
            lastCard.tags.add(analyst.getNextString());
            withResult = true;
        }

        if (nowStr.equals("image")) {
            //Log.info(nowStr);
            IImage images = Detonator.INSTANCE.imageProvider.getImage(analyst.getNextString());
            if (scale != 1) {
                Log.info("Rescale: "+images.getName());
                //images = TransientSlickImage.rescaleImage(images, scale);
                images = Detonator.INSTANCE.imageProvider.rescaleImage (images, scale);
            }
            lastCard.image = images;

            withResult = true;
        }

        if (nowStr.equals("largeimage")) {
            //Log.info(nowStr);
            lastCard.largeImage = Detonator.INSTANCE.imageProvider.getImage(analyst.getNextString());

            withResult = true;
        }

       
        if (withResult == false) {
            withResult = Tex.analyzeStringForTex(analyst.fullStr, analyst, false);
        }
       

        if ((withResult == false) && (nowStr.length() > 2) && (!nowStr.startsWith("//"))) {
            Log.error("Unknown string: " + nowStr);
        }

    }



    public static Cards getCardsByCode(String byCode) {
        //return items.get(Binding.readBinding(Binding.itemBinding, byCode.toLowerCase()));
        return getCardsByID(Binding.readBinding(Binding.cardBinding, byCode.toLowerCase()));
    }

    public static Cards getCardsByID(int getCode) {

        for (Cards l : cards) {
            if (l.ID == getCode) {
                return l;
            }
        }

        return null;
    }

    public static ArrayList<Cards> getAllCardsByGroup(String itemGroup) {

        ArrayList<Cards> list = new ArrayList<Cards>();

        for (Cards l : cards) {
            if (l.group == null ? itemGroup == null : l.group.equals(itemGroup)) {
                list.add(l);
            }
        }

        return list;
    }

    public static ArrayList<Cards> getAllCardsByType(String itemGroup) {

        Log.info("All items: " + cards.size());

        int byType = Binding.getBinding(Binding.cardTypeBinding, itemGroup);
        ArrayList<Cards> list = new ArrayList<Cards>();

        for (Cards l : cards) {
            if (l.cardType == byType) {
                list.add(l);
            }

            Log.info("Has type: " + l.cardType);
            Log.info("need: " + byType);
        }

        Log.info("Hits for " + itemGroup + ": " + list.size());
        return list;
    }

    public boolean isCardType(String currentMode) {
        return  (cardType == Binding.getBinding(Binding.cardTypeBinding, currentMode));
    }
}
TOP

Related Classes of transientlibs.bindedobjects.gamecontent.Cards

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.