@Override
  public Value execute(final Interpreter interpreter) {
    if (!KoLmafia.permitsContinue()) {
      interpreter.setState(Interpreter.STATE_EXIT);
      return null;
    }

    interpreter.traceIndent();

    if (interpreter.isTracing()) {
      interpreter.trace("Invoke: " + this);
      interpreter.trace("Function name: " + this.name);
    }

    // Get the function name
    Value funcValue = this.name.execute(interpreter);

    if (interpreter.isTracing()) {
      interpreter.trace("[" + interpreter.getState() + "] <- " + funcValue);
    }

    if (funcValue == null) {
      interpreter.traceUnindent();
      return null;
    }

    interpreter.setLineAndFile(this.fileName, this.lineNumber);

    String func = funcValue.toString();
    Function function = this.scope.findFunction(func, this.params);
    if (function == null) {
      throw interpreter.undefinedFunctionException(func, this.params);
    }

    if (!Parser.validCoercion(this.type, function.getType(), "return")) {
      throw interpreter.runtimeException(
          "Calling \""
              + func
              + "\", which returns "
              + function.getType()
              + " but "
              + this.type
              + " expected");
    }

    this.target = function;

    // Invoke it.
    Value result = super.execute(interpreter);
    interpreter.traceUnindent();

    return result;
  }
예제 #2
0
    private void buff(boolean maxBuff) {
      UseSkillRequest request = (UseSkillRequest) SkillBuffFrame.this.skillSelect.getSelectedItem();
      if (request == null) {
        return;
      }

      String buffName = request.getSkillName();
      if (buffName == null) {
        return;
      }

      String[] targets =
          StaticEntity.getClient()
              .extractTargets((String) SkillBuffFrame.this.targetSelect.getSelectedItem());

      int buffCount =
          !maxBuff
              ? InputFieldUtilities.getValue(SkillBuffFrame.this.amountField, 1)
              : Integer.MAX_VALUE;
      if (buffCount == 0) {
        return;
      }

      SpecialOutfit.createImplicitCheckpoint();

      if (targets.length == 0) {
        RequestThread.postRequest(
            UseSkillRequest.getInstance(buffName, KoLCharacter.getUserName(), buffCount));
      } else {
        for (int i = 0; i < targets.length && KoLmafia.permitsContinue(); ++i) {
          if (targets[i] != null) {
            RequestThread.postRequest(UseSkillRequest.getInstance(buffName, targets[i], buffCount));
          }
        }
      }

      SpecialOutfit.restoreImplicitCheckpoint();
    }