Search in sources :

Example 1 with AbilityImpl

use of main.ability.AbilityImpl in project Eidolons by IDemiurge.

the class ScriptParser method parseScript.

public static <T> ScriptTrigger parseScript(String script, DC_Game game, ScriptExecutor<T> executor, Class<T> funcClass) {
    // TODO
    script = ScriptMaster.getScriptByName(script);
    // non-trigger scripts?
    String originalText = script;
    String processedPart = StringMaster.getFirstItem(script, ScriptSyntax.PART_SEPARATOR);
    STANDARD_EVENT_TYPE event_type = parseEvent(processedPart);
    script = StringMaster.cropFirstSegment(script, ScriptSyntax.PART_SEPARATOR);
    Condition condition = null;
    condition = getDefaultCondition(event_type, VariableManager.getVars(processedPart));
    if (condition != null) {
        condition.setXml(XML_Converter.wrap("ScriptedCondition", XML_Converter.wrap("STANDARD_EVENT_TYPE", event_type.toString()) + XML_Converter.wrap("STRING", VariableManager.getVars(processedPart))));
    } else {
        String conditionPart = StringMaster.getFirstItem(script, ScriptSyntax.PART_SEPARATOR);
        condition = parseConditions(conditionPart);
        condition.setXml(conditionPart);
    }
    boolean isRemove = true;
    // if (contains("cyclic"))remove = false;
    Ability abilities = null;
    // TODO Global
    Ref ref = new Ref(game);
    script = StringMaster.getLastPart(script, ScriptSyntax.PART_SEPARATOR);
    String funcPart = VariableManager.removeVarPart(script);
    @Refactor T // TODO this won't work in generic way!!!!
    func = new EnumMaster<T>().retrieveEnumConst(funcClass, funcPart);
    if (func != null) {
        // TODO for multiple scripts, need another SEPARATOR!
        String separator = executor.getSeparator(func);
        List<String> strings = StringMaster.openContainer(VariableManager.getVars(script), separator);
        String[] args = strings.toArray(new String[strings.size()]);
        abilities = new AbilityImpl() {

            @Override
            public boolean activatedOn(Ref ref) {
                executor.execute(func, ref, args);
                // reset after? not like normal action certainly...
                return true;
            }
        };
    } else {
        abilities = AbilityConstructor.getAbilities(script, ref);
        if (abilities.getEffects().getEffects().isEmpty()) {
            main.system.auxiliary.log.LogMaster.log(1, "SCRIPT NOT FOUND: " + funcPart);
            return null;
        }
    }
    abilities.setRef(ref);
    ScriptTrigger trigger = new ScriptTrigger(originalText, event_type, condition, abilities);
    trigger.setRemoveAfterTriggers(isRemove);
    return trigger;
}
Also used : Condition(main.elements.conditions.Condition) Ability(main.ability.Ability) AbilityImpl(main.ability.AbilityImpl) STANDARD_EVENT_TYPE(main.game.logic.event.Event.STANDARD_EVENT_TYPE) Refactor(main.system.util.Refactor) Ref(main.entity.Ref)

Aggregations

Ability (main.ability.Ability)1 AbilityImpl (main.ability.AbilityImpl)1 Condition (main.elements.conditions.Condition)1 Ref (main.entity.Ref)1 STANDARD_EVENT_TYPE (main.game.logic.event.Event.STANDARD_EVENT_TYPE)1 Refactor (main.system.util.Refactor)1