Пример #1
0
 @Override
 public String toString() {
   return ItemFactory.toString(icons[0], false)
       + "@"
       + ItemFactory.toString(icons[1], false)
       + "@"
       + ItemFactory.toString(icons[2], false)
       + "#"
       + action.name();
 }
Пример #2
0
  @Override
  public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

    // Get objects
    Action action = (Action) scriptEntry.getObject("action");
    dLocation location = (dLocation) scriptEntry.getObject("location");
    Element range = (Element) scriptEntry.getObject("range");
    Element id = (Element) scriptEntry.getObject("id");

    // Report to dB
    dB.report(
        scriptEntry,
        getName(),
        aH.debugObj("NPC", scriptEntry.getNPC().toString())
            + action.name()
            + id.debug()
            + (location != null ? location.debug() : "")
            + (range != null ? range.debug() : ""));

    dNPC npc = scriptEntry.getNPC();

    switch (action) {
      case ADD:
        npc.getCitizen().getTrait(Anchors.class).addAnchor(id.asString(), location);
        return;

      case ASSUME:
        npc.getEntity()
            .teleport(
                npc.getCitizen().getTrait(Anchors.class).getAnchor(id.asString()).getLocation());
        return;

      case WALKNEAR:
        npc.getNavigator()
            .setTarget(
                Utilities.getWalkableLocationNear(
                    npc.getCitizen().getTrait(Anchors.class).getAnchor(id.asString()).getLocation(),
                    range.asInt()));
        return;

      case WALKTO:
        npc.getNavigator()
            .setTarget(
                npc.getCitizen().getTrait(Anchors.class).getAnchor(id.asString()).getLocation());
        return;

      case REMOVE:
        npc.getCitizen()
            .getTrait(Anchors.class)
            .removeAnchor(npc.getCitizen().getTrait(Anchors.class).getAnchor(id.asString()));
    }
  }
Пример #3
0
 public static void string2action(ArrayList<String> al, String name, ArrayList<Action> list)
     throws SQLException {
   while (!al.isEmpty()) {
     int ind = PurposeNet.list.indexOf(al.get(0));
     if (ind >= 0) {
       // System.out.println(al.get(0) + " " + ind + " "  + name);
       list.add((Action) PurposeNet.list_object.get(ind));
     } else {
       PurposeNet.list.add(al.get(0));
       Action temp = new Action();
       temp.name = al.get(0);
       list.add(temp);
       PurposeNet.list_object.add(temp);
       Boolean temp_bool = new Boolean(false);
       PurposeNet.list_print.add(temp_bool);
     }
     al.remove(0);
   }
 }
Пример #4
0
  private void buildAndAddActions(
      Object controller, String controllerName, List<Method> actions, ApiActionHolder holder)
      throws ApiException {

    for (Method method : actions) {
      final Action annotation = method.getAnnotation(Action.class);
      final String actionName = annotation.name();

      final RequestMethod requestMethod = getRequestMethod(annotation);
      final ActionName name = new ActionName(controllerName, actionName);
      final MethodRef methodRef = new MethodRef(controller, method);
      final ApiAction action = new ApiAction(name, methodRef, requestMethod);

      fillParamsMetadata(action, methodRef);
      fillValidatorMetadata(action, method);
      fillSecurityMetadata(action, method);

      holder.add(action);
    }
  }
Пример #5
0
  private List<Method> extractActions(Object object) throws ApiException {
    List<Method> result = Lists.newArrayList();
    Method[] methods = object.getClass().getMethods();
    for (Method method : methods) {
      Action annotation = method.getAnnotation(Action.class);
      if (annotation != null) {
        final String actionName = annotation.name();
        if (StringUtils.isEmpty(actionName)) {
          throw new ApiException(
              "Action name is not found on "
                  + object.getClass().getName()
                  + "."
                  + method.getName());
        }

        result.add(method);
      }
    }

    return result;
  }
 public void evaluatePostAction(
     LazyObjectAccessor source, LazyObjectAccessor target, Action action, boolean sourceAction)
     throws SynchronizationException {
   if (postAction != null) {
     Map<String, Object> scope = new HashMap<String, Object>();
     scope.put("sourceAction", sourceAction);
     scope.put("action", action.name());
     scope.put("situation", situation.name());
     if (source != null) {
       scope.put("source", source.asMap());
     }
     if (target != null) {
       scope.put("target", target.asMap());
     }
     try {
       postAction.exec(scope);
     } catch (ScriptException se) {
       LOGGER.debug("action script encountered exception", se);
       throw new SynchronizationException(se);
     }
   }
 }
Пример #7
0
  /**
   * 逻辑:<br>
   * 1.若跑日常图,进度不为100%时跑日常图<br>
   * 2.若初始里图编号大于10万,分表里图存储;否则全存到表图<br>
   * 3.获取area信息
   */
  public static boolean run() throws Exception {
    response = null;
    try {
      response = Process.network.ConnectToServer(URL_AREA, new ArrayList<NameValuePair>(), false);
    } catch (Exception ex) {
      ErrorData.currentDataType = ErrorData.DataType.text;
      ErrorData.currentErrorType = ErrorData.ErrorType.ConnectionError;
      ErrorData.text = ex.getMessage();
      throw ex;
    }

    Document doc;
    try {
      doc = Process.ParseXMLBytes(response, Name.name());
    } catch (Exception ex) {
      ErrorData.currentDataType = ErrorData.DataType.bytes;
      ErrorData.currentErrorType = ErrorData.ErrorType.AreaDataError;
      ErrorData.bytes = response;
      throw ex;
    }

    try {
      XPathFactory factory = XPathFactory.newInstance();
      XPath xpath = factory.newXPath();
      if (!xpath.evaluate("/response/header/error/code", doc).equals("0")) {
        ErrorData.currentErrorType = ErrorData.ErrorType.AreaResponse;
        ErrorData.currentDataType = ErrorData.DataType.text;
        ErrorData.text = xpath.evaluate("/response/header/error/message", doc);
        return false;
      }

      int areaCount =
          ((NodeList) xpath.evaluate("//area_info_list/area_info", doc, XPathConstants.NODESET))
              .getLength();

      // area按编号从小到大排序
      for (int i = areaCount; i > 0; i--) {
        Area a = new Area();
        String p = String.format("//area_info_list/area_info[%d]/", i);
        a.areaId = Integer.parseInt(xpath.evaluate(p + "id", doc));

        if (Process.info.area.containsKey(a.areaId) == false) {
          a.areaName = xpath.evaluate(p + "name", doc);
          a.exploreProgress = Integer.parseInt(xpath.evaluate(p + "prog_area", doc));

          // 输出地图信息
          Go.log("地圖:" + a.areaName + ",編號:" + a.areaId, LogType.INFO);

          // 跑日常图
          if (Info.DailyMap == true
              && Info.DailyMapNo.contains(Integer.valueOf(a.areaId)) == true
              && a.exploreProgress < 100) {
            Process.info.area.put(a.areaId, a);
          }

          // 跑活动图
          if (a.areaId > MAP_NO) {
            // 判断第一张里图编号是否有效
            if (Info.firstInnerMapNo > MAP_NO) {
              // 里图 or 表图
              if (a.areaId >= Info.firstInnerMapNo) {
                Process.info.areaInner.put(a.areaId, a);
              } else {
                Process.info.area.put(a.areaId, a);
              }
            } else {
              Process.info.area.put(a.areaId, a);
            }
          }
        }
      } // end for

      return areaCount > 0;
    } catch (Exception ex) {
      if (ErrorData.currentErrorType == ErrorData.ErrorType.none) {
        throw ex;
      }
    }

    return false;
  }
Пример #8
0
 public static ModalAction action(Action action) {
   ModalAction modalAction = new ModalAction();
   modalAction.addParameter("'" + action.name() + "'");
   return modalAction;
 }
Пример #9
0
  @Override
  public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Get objects
    Action action = (Action) scriptEntry.getObject("state");
    Target target = (Target) scriptEntry.getObject("target");

    // Report to dB
    dB.report(
        getName(),
        aH.debugObj("Toggle", action.name())
            + aH.debugObj(
                "Target",
                target == Target.NPC
                    ? scriptEntry.getNPC().toString()
                    : scriptEntry.getPlayer().getName()));

    switch (target) {
      case NPC:
        if (!scriptEntry.getNPC().getCitizen().hasTrait(InvisibleTrait.class))
          scriptEntry.getNPC().getCitizen().addTrait(InvisibleTrait.class);
        InvisibleTrait trait = scriptEntry.getNPC().getCitizen().getTrait(InvisibleTrait.class);

        switch (action) {
          case FALSE:
            trait.setInvisible(false);
            break;

          case TRUE:
            trait.setInvisible(true);
            break;

          case TOGGLE:
            trait.toggle();
            break;
        }

        break;

      case PLAYER:
        if (scriptEntry.getPlayer() != null) {

          Player player = scriptEntry.getPlayer().getPlayerEntity();
          PotionEffect invis =
              new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1);

          switch (action) {
            case FALSE:
              player.removePotionEffect(PotionEffectType.INVISIBILITY);
              break;

            case TRUE:
              invis.apply(player);
              break;

            case TOGGLE:
              if (player.hasPotionEffect(PotionEffectType.INVISIBILITY))
                player.removePotionEffect(PotionEffectType.INVISIBILITY);
              else invis.apply(player);

              break;
          }
        }
    }
  }