Package transientlibs.bindedobjects.core

Source Code of transientlibs.bindedobjects.core.Req

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

import transientlibs.bindedobjects.gamecontent.Tech;

import transientlibs.objects.primitives.Comparison;

import transientlibs.objects.general.Node;
import transientlibs.processors.misc.Detonator;
import transientlibs.tex.ReqList;
import transientlibs.tex.StringAnalyst;
import transientlibs.bindedobjects.core.Binding;

import transientlibs.objects.primitives.IntSlot;

/**
*
* @author Elwin
*/
public class Req extends Node {

    public final static int SkillReq = 1;
    public final static int PerkReq = 2;
    public final static int StatReq = 3;
    public final static int StageReq = 4;
    public static final int valueReq2 = 55;

    public static final int localTriggerReq = 6;
    public static final int techReq = 7;
    public static final int globalTriggerReq = 8;
    public static final int globalValueReq = 9;
    public static final int tileEffectReq = 10;
    public static final int tileLandmarkReq = 11;
    public static final int standOnItemReq = 12;
    public static final int haveItemReq = 13;
    public static final int landmarkEffectReq = 14; //effect on landmark tile
    public static final int movableTileReq = 15; //
    public static final int standableTileReq = 16; //
    //value subtypes
    public static final int StartStage = 1;
    public boolean sign;
    public int value;
    public int value2;
    public IntSlot linkedValue = null;
    public IntSlot linkedValue2 = null;
    public Node linkedNode = null;
    public Comparison comparison = null;

    public Req(int setType, int setID, int setValue, int setValue2, boolean setSign) {
        ofType = setType;
        ID = setID;
        sign = setSign;
        value = setValue;
        value2 = setValue2;
    }

    public Req(int setType, int setValue, IntSlot setLinkedValue, Comparison setComparison, boolean setSign) {
        ofType = setType;

        value = setValue;
        linkedValue = setLinkedValue;

        comparison = setComparison;
        sign = setSign;
    }

    public Req(int setType, IntSlot setLinkedValue, IntSlot setLinkedValue2, Comparison setComparison, boolean setSign) {

        ofType = setType;
        linkedValue = setLinkedValue;
        linkedValue2 = setLinkedValue2;

        comparison = setComparison;
        sign = setSign;
    }

    public Req(int setType, int setID, int setValue, int setValue2, IntSlot setLinkedValue, boolean setSign) {
        ofType = setType;
        ID = setID;
        sign = setSign;
        value = setValue;
        value2 = setValue2;
        linkedValue = setLinkedValue;
    }

    public Req(int setType, int setID, int setValue, IntSlot setLinkedValue, boolean setSign) {
        ofType = setType;
        ID = setID;
        sign = setSign;
        value = setValue;
        linkedValue = setLinkedValue;
    }

    public Req(int setType, int setID, int setValue, IntSlot setLinkedValue, Comparison setComparison, boolean setSign) {
        ofType = setType;
        ID = setID;
        sign = setSign;
        value = setValue;
        comparison = setComparison;
        linkedValue = setLinkedValue;
    }

    public Req(int setType, int setID, int setValue, int setValue2, IntSlot setLinkedValue, Node setLinkedNode, boolean setSign) {
        ofType = setType;
        ID = setID;
        sign = setSign;
        value = setValue;
        value2 = setValue2;
        linkedValue = setLinkedValue;
        linkedNode = setLinkedNode;
    }

    public Req(int setType, int setID, int setValue, int setValue2, IntSlot setLinkedValue, IntSlot setLinkedValue2, Node setLinkedNode, boolean setSign) {
        ofType = setType;
        ID = setID;
        sign = setSign;
        value = setValue;
        value2 = setValue2;
        linkedValue = setLinkedValue;
        linkedValue2 = setLinkedValue2;
        linkedNode = setLinkedNode;
    }

    public Req(int setType, int setID, int setValue, boolean setSign) {
        ofType = setType;
        ID = setID;
        sign = setSign;
        value = setValue;
        value2 = 0;
    }

    public Req(int setType, int setID, boolean setSign) {
        ofType = setType;
        ID = setID;
        sign = setSign;
        value = 0;
        value2 = 0;
    }

    public boolean isFulfilled() {

        boolean result = false;

        if (ofType == SkillReq) {
            result = (Detonator.INSTANCE.reqCreature.hasSkill(value, value2) == sign);
        }

        if (ofType == localTriggerReq) {
            result = (Detonator.INSTANCE.localTriggers.get(ID).referencedBoolean.value == sign);

            //Log.info("Checked trigger, result is "+result);
        }

        if (ofType == globalTriggerReq) {
            result = (Detonator.INSTANCE.getBindedTrigger(ID).value == sign);

            //Log.info("Checked trigger, result is "+result);
        }

        if (ofType == techReq) {
            result =

                    //(Detonator.INSTANCE.techResearched.get(ID).value == sign)
                    //||
                    (Tech.techs.get(ID).isResearched == sign);
        }

        if (ofType == landmarkEffectReq) {

            //finish later
            result = ((comparison.compare(Detonator.INSTANCE.activeUnit.currentTile().returnEffect(value).unitsLeft, linkedValue.referencedInt)) == sign);
        }

        if (ofType == tileEffectReq) {

            //Log.info("check tile for effect "+ID);

            result = (Detonator.INSTANCE.activeUnit.currentTile().hasEffect(ID) == sign);

            //Log.info("result = "+result);
        }


        if (ofType == standOnItemReq) {
            result = (!(Detonator.INSTANCE.activeUnit.currentTile().items.items.isEmpty()));
        }


        if (ofType == movableTileReq) {
            result = ((Detonator.INSTANCE.activeUnit.deltaTile(ID/1000, value/1000).terrain.moveCost != -1) == sign);
        }

        if (ofType == standableTileReq) {
            result = (Detonator.INSTANCE.activeUnit.deltaTile(ID, value).terrain.canStandOn == sign);
        }



        if (ofType == tileLandmarkReq) {

            //Log.info("check tile for effect "+ID);

            result = (Detonator.INSTANCE.activeUnit.currentTile().hasLandmark(ID) == sign);

            //Log.info("result = "+result);
        }


        if (ofType == valueReq2) {
            if (linkedValue2 != null) {

                result = (comparison.compare(linkedValue.referencedInt, linkedValue2.referencedInt) == sign);
            } else {

                result = (comparison.compare(linkedValue.referencedInt, value) == sign);
            }
        }




        if (ofType == haveItemReq) {
           
            //result = (Detonator.INSTANCE.activeUnit.inventory.hasItem(ID) == sign);
            result = (Detonator.INSTANCE.conditionProcessor.hasItem(ID, 1) == sign);
        }



        return result;
    }

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

    public static boolean analyzeStringForReqs(String getString, StringAnalyst analyst) {

        //if (!"-NO-".equals(getString)) {analyst.loadNewString(getString);}

        String nowStr = analyst.lastStr;
        int setID;
        int setValue;

        boolean withResult = false;


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

            setID = analyst.getBinding(Binding.itemBinding);

            ReqList.lastReqList.add(new Req(haveItemReq, setID, true));

            withResult = true;
        }

        if (nowStr.equals("standonitem")) {
            ReqList.lastReqList.add(new Req(standOnItemReq, -1, true));

            withResult = true;
        }

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

            setID = analyst.getNextNumber();
            setValue = analyst.getNextNumber();

            ReqList.lastReqList.add(new Req(movableTileReq, setID, setValue, true));

            withResult = true;
        }


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

            setID = analyst.getNextNumber();
            setValue = analyst.getNextNumber();

            ReqList.lastReqList.add(new Req(standableTileReq, setID, setValue, true));

            withResult = true;
        }



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

            setValue = analyst.getBinding(Binding.landmarkBinding);
            setID = analyst.getBinding(Binding.effectBinding);

            Comparison comp = analyst.getNextComparison();

            IntSlot setIntValue = analyst.getNextBindedValue();


            ReqList.lastReqList.add(new Req(landmarkEffectReq, setValue, setID, setIntValue, comp, true));

            withResult = true;
        }

        if (nowStr.equals("iftileeffect")) {
            setID = analyst.getBinding(Binding.effectBinding);

            ReqList.lastReqList.add(new Req(tileEffectReq, setID, true));

            withResult = true;
        }

        if (nowStr.equals("iftilelandmark")) {
            setID = analyst.getBinding(Binding.landmarkBinding);

            ReqList.lastReqList.add(new Req(tileLandmarkReq, setID, true));

            withResult = true;
        }


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

            IntSlot setInt = analyst.getNextBindedValue();
            Comparison comp = analyst.getNextComparison();

            if (!(analyst.checkIfNextIsNumber())) {

                IntSlot setInt2 = analyst.getNextBindedValue();
                ReqList.lastReqList.add(new Req(valueReq2, setInt, setInt2, comp, true));
            } else {
                setValue = analyst.getNextNumber();
                ReqList.lastReqList.add(new Req(valueReq2, setValue, setInt, comp, true));
            }

            withResult = true;
        }





        if ((nowStr.equals("ifskill")) || (nowStr.equals("ifnotskill"))) {

            setID = analyst.getNextSkill();
            setValue = analyst.getNextNumber();

            if (nowStr.equals("ifskill")) {ReqList.lastReqList.add(new Req(SkillReq, setID, setValue, true));} else
            if (nowStr.equals("ifnotskill")) {ReqList.lastReqList.add(new Req(SkillReq, setID, setValue, false));}

            withResult = true;
        }



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

            setID = analyst.getNextPerk();
            setValue = analyst.getNextNumber();

            ReqList.lastReqList.add(new Req(PerkReq, setID, setValue, true));
            withResult = true;
        }

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

            setID = analyst.getNextPerk();
            setValue = analyst.getNextNumber();

            ReqList.lastReqList.add(new Req(PerkReq, setID, setValue, false));
            withResult = true;
        }

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

            setID = analyst.getNextStat();
            setValue = analyst.getNextNumber();

            ReqList.lastReqList.add(new Req(StatReq, setID, setValue, true));
            withResult = true;
        }

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

            setID = analyst.getNextStat();
            setValue = analyst.getNextNumber();

            ReqList.lastReqList.add(new Req(StatReq, setID, setValue, false));
            withResult = true;
        }

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

            ReqList.lastReqList.add(new Req(StageReq, StartStage, true));
            withResult = true;

        }

        if ((nowStr.equals("if")) || (nowStr.equals("iftrigger")) || (nowStr.equals("ift"))) {
            setID = analyst.getBinding(Binding.globalTriggerBinding);

            //Log.info("parsed if");

            ReqList.lastReqList.add(new Req(globalTriggerReq, setID, true));
            withResult = true;
        }

        if ((nowStr.equals("ifnot")) || (nowStr.equals("ifnottrigger")) || (nowStr.equals("ift-"))) {
            setID = analyst.getBinding(Binding.globalTriggerBinding);

            //Log.info("parsed ifnot");

            ReqList.lastReqList.add(new Req(globalTriggerReq, setID, false));
            withResult = true;
        }

        if (nowStr.equals("iflocalt")) {
            setID = analyst.getBinding(Binding.localTriggerBinding);

            //Log.info("parsed if");

            ReqList.lastReqList.add(new Req(localTriggerReq, setID, true));
            withResult = true;
        }

        if (nowStr.equals("ifnotlocat")) {
            setID = analyst.getBinding(Binding.localTriggerBinding);

            //Log.info("parsed ifnot");

            ReqList.lastReqList.add(new Req(localTriggerReq, setID, false));
            withResult = true;
        }

        if (nowStr.equals("iftech")) {
            setID = analyst.getBinding(Binding.techBinding);

            ReqList.lastReqList.add(new Req(techReq, setID, true));
            withResult = true;
        }

        if (nowStr.equals("ifnottech")) {
            setID = analyst.getBinding(Binding.techBinding);

            ReqList.lastReqList.add(new Req(techReq, setID, false));
            withResult = true;
        }


        return withResult;

    }
}
TOP

Related Classes of transientlibs.bindedobjects.core.Req

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.