Package transientlibs.bindedobjects.gamecontent

Source Code of transientlibs.bindedobjects.gamecontent.Creatures

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


import transientlibs.objects.primitives.Int;
import transientlibs.tex.StringAnalyst;
import java.util.ArrayList;
import java.util.HashMap;
import transientlibs.slick2d.util.Log;

import transientlibs.bindedobjects.core.Binding;
import transientlibs.bindedobjects.core.datasets.LesserBindedValue;
import static transientlibs.bindedobjects.gamecontent.Creatures.lastCreature;
import transientlibs.processors.misc.Detonator;
import transientlibs.preui.objects.gui.interfaces.IAnimation;
import transientlibs.preui.objects.gui.interfaces.IImage;
import transientlibs.preui.objects.gui.interfaces.ISound;
import transientlibs.preui.objects.gui.misc.ImageSections;
import transientlibs.preui.objects.gui.misc.ViewInfo;

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

    public static ArrayList<Creatures> creatures = new ArrayList<Creatures>();
   
    public IImage masterImage;
    public IImage secondImage;
   
   
   
    //public Images image;
   
    public IImage rightSideImage;
    public IImage leftSideImage;
    //public TransientImages transientImages;
    public int defaultSide = 0;
    public IAnimation walkAnimation;
    public int movementSpeed;
    public int speed;
    public int maxHP = 1;
    public ArrayList<ISound> focusSounds = new ArrayList<ISound>();
    public ArrayList<ISound> orderSounds = new ArrayList<ISound>();
    public Int shootingDamage = new Int(0);
    public Int meleeDamage = new Int(0);
    public int defaultDirection = 6;
    public ArrayList<Int> equippedItems = new ArrayList<Int>();
    public HashMap<String, Int> customValues = new HashMap<String, Int>();
    public static Creatures lastCreature;
    public ArrayList<Cards> cards = null;
    public ViewInfo visualInformation = new ViewInfo();

    public static void loadCreatures() {

        if (StringAnalyst.isFileExist("creatures.dat")) {

            StringAnalyst reader = new StringAnalyst();


            reader.openFile("creatures.dat");

            while (!reader.eof) {


                reader.readRow();
                analyzeStringForCreaturess(reader);
            }

            reader.closeFile();
        }
       
        finalizeVisualInformation();
    }
   
    public static void finalizeVisualInformation (){
        for (Creatures c: creatures) {
            Log.info("habr");
            c.visualInformation.fillEmptySlots();
        }
    }

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

    public void playOrderSound() {
        if (!(orderSounds.isEmpty())) {
            //Sounds.play(orderSounds.get(0));
            Detonator.INSTANCE.musicPlayer.playSound(orderSounds.get(0));
        }

    }

    public int getCustomValue(String byCode) {
        if (customValues.containsKey(byCode)) {
            return customValues.get(byCode).value;
        } else {
            return 0;
        }
    }

    public void playFocusSound() {
        if (!(focusSounds.isEmpty())) {
            //Sounds.play(focusSounds.get(0));
            Detonator.INSTANCE.musicPlayer.playSound(focusSounds.get(0));
        }
    }

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

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

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

        boolean withResult = false;

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

            creatures.add(new Creatures());
            lastCreature = creatures.get(creatures.size() - 1);

            lastCreature.LName.value = analyst.getNextString();

            //lastCreature.ID = analyst.getBinding (Binding.creatureBinding);
            lastCreature.ID = Binding.getBinding(Binding.creatureBinding, lastCreature.LName.value.toLowerCase());

            //ReqList.lastReqList = lastCreatures.trainReqs;

            withResult = true;

        }

        if (nowStr.equals("name")) {
            lastCreature.LName.value = analyst.restOfRow();
            withResult = true;
        }


        if (nowStr.equals("custom")) {
            String nextString = analyst.getNextString();
            int var = analyst.getNextNumber();
            lastCreature.customValues.put(nextString, new Int(var));

            withResult = true;
        }


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

            if (lastCreature.cards == null) {
                lastCreature.cards = new ArrayList<Cards>();
            }
            lastCreature.cards.add(Cards.getCardsByCode(analyst.getNextString()));
            withResult = true;
        }

        if (nowStr.equals("focussound")) {
            //lastCreature.focusSounds.add(Sounds.getSoundByCode(analyst.getNextString()));
            lastCreature.focusSounds.add(SoundsGDX.getSoundByCode(analyst.getNextString()));
            withResult = true;
        }

        if (nowStr.equals("ordersound")) {
            //lastCreature.orderSounds.add(Sounds.getSoundByCode(analyst.getNextString()));
            lastCreature.orderSounds.add(SoundsGDX.getSoundByCode(analyst.getNextString()));
            withResult = true;
        }


        if (nowStr.equals("equip")) {
            lastCreature.equippedItems.add(new Int(analyst.getBinding(Binding.itemBinding)));
            withResult = true;
        }


        if (nowStr.equals("group")) {
            lastCreature.group = analyst.getNextString();
            withResult = true;
        }

        if (nowStr.equals("hp")) {
            lastCreature.maxHP = analyst.getNextNumber();
            withResult = true;
        }

        if (nowStr.equals("shootingdamage")) {
            lastCreature.shootingDamage.value = analyst.getNextNumber();
            withResult = true;
        }

        if (nowStr.equals("meleedamage")) {
            lastCreature.meleeDamage.value = analyst.getNextNumber();
            withResult = true;
        }


        if (nowStr.equals("movement")) {
            lastCreature.movementSpeed = analyst.getNextNumber();
            //Log.info("MOVEMENT SPEED SET TO "+lastCreature.movementSpeed);
            withResult = true;
        }

        if (nowStr.equals("speed")) {
            lastCreature.speed = analyst.getNextNumber();
            withResult = true;
        }


        if (nowStr.equals("desc")) {
            lastCreature.desc = analyst.restOfRow();
            withResult = true;
        }

        if (nowStr.equals("side")) {
            lastCreature.defaultSide = analyst.getNextBindedValue().referencedInt.value;
            withResult = true;
        }


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

            //String imageCode = analyst.getNextString();
           
            /*
            if (Detonator.INSTANCE.useGDXImages == false) {
                int imageID = Binding.readBinding(Binding.imageBinding, imageCode);
                lastCreature.image = Images.imageList.get(imageID);
            } else {
                int imageID = Binding.readBinding(Binding.transientImageBinding, imageCode);
                lastCreature.transientImages = TransientImages.images.get(imageID);
            }
            */
           
            lastCreature.masterImage = Detonator.INSTANCE.imageProvider.getImage(analyst.getNextString());
            lastCreature.visualInformation.addDirectionImage(6, lastCreature.masterImage);
            lastCreature.visualInformation.addDirectionImage(4, lastCreature.masterImage);
           
            if (lastCreature.hasTag("multitile")) {
            //lastCreature.visualInformation.cutImage = new ImageSections();
            //lastCreature.visualInformation.cutImage.cutFromImage(lastCreature.masterImage);
            }
           

            withResult = true;
        }

        if (nowStr.equals("image2")) {
            //int imageID = Binding.readBinding(Binding.imageBinding, analyst.getNextString());
            //lastCreature.secondImage = SlickImageCatalog.imageList.get(imageID);
            lastCreature.secondImage = Detonator.INSTANCE.imageProvider.getImage(analyst.getNextString());

            withResult = true;
        }

        if (nowStr.equals("direction")) {
            lastCreature.defaultDirection = analyst.getNextNumber();
            withResult = true;
        }

        if (nowStr.equals("rightimage")) {
            if (Detonator.INSTANCE.useGDXImages == false) {
                lastCreature.rightSideImage = Detonator.INSTANCE.imageProvider.getImage(analyst.getNextString());
            } else {
                lastCreature.visualInformation.addDirectionImage(6, Detonator.INSTANCE.imageProvider.getImage(analyst.getNextString()));
               
                //lastCreature.masterImage = lastCreature.visualInformation.getDirectionImages(6);
            }
            withResult = true;
        }

        if (nowStr.equals("downimage")) {
            if (Detonator.INSTANCE.useGDXImages == false) {
                //lastCreature.rightSideImage = Detonator.INSTANCE.imageProvider.getImage(analyst.getNextString());
            } else {
                lastCreature.visualInformation.addDirectionImage(2, Detonator.INSTANCE.imageProvider.getImage(analyst.getNextString()));
               
                lastCreature.masterImage = lastCreature.visualInformation.getDirectionImages(2);
            }
            withResult = true;
        }

       
        if (nowStr.equals("upimage")) {
            if (Detonator.INSTANCE.useGDXImages == false) {
                //lastCreature.rightSideImage = Detonator.INSTANCE.imageProvider.getImage(analyst.getNextString());
            } else {
                lastCreature.visualInformation.addDirectionImage(8, Detonator.INSTANCE.imageProvider.getImage(analyst.getNextString()));
               
                //lastCreature.masterImage = lastCreature.visualInformation.getDirectionImages(8);
            }
            withResult = true;
        }
       

        if (nowStr.equals("leftimage")) {
            if (Detonator.INSTANCE.useGDXImages == false) {
                lastCreature.leftSideImage = Detonator.INSTANCE.imageProvider.getImage(analyst.getNextString());
            } else {
                lastCreature.visualInformation.addDirectionImage(4, Detonator.INSTANCE.imageProvider.getImage(analyst.getNextString()));
            }            withResult = true;
        }



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

            //lastCreature.walkAnimation = Animations.getAnimationByID(analyst.getBinding(Binding.animationBinding)).animation;
            Log.notImplemented();
            withResult = true;
        }

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



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

    }

    public static String getBindCode(int forType) {
        return Binding.getBindCode(Binding.creatureBinding, forType);
    }

    public static Creatures getCreatureByID(int getCode) {
        //return creatures.get(byID);

        for (Creatures l : creatures) {
            if (l.ID == getCode) {
                return l;
            }
        }

        return null;
    }

    public static Creatures getCreatureByCode(String byCode) {
        //return creatures.get(Binding.readBinding(Binding.creatureBinding, byCode.toLowerCase()));                       
        return getCreatureByID(Binding.readBinding(Binding.creatureBinding, byCode.toLowerCase()));
    }

    public static Creatures getCreatureByRandom() {
        return creatures.get(Detonator.INSTANCE.rng.nextInt(creatures.size()));
    }

}
TOP

Related Classes of transientlibs.bindedobjects.gamecontent.Creatures

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.