public static Mob mob(int depth) {
   @SuppressWarnings("unchecked")
   Class<? extends Mob> cl = (Class<? extends Mob>) mobClass(depth);
   try {
     return ClassReflection.newInstance(cl);
   } catch (Exception e) {
     return null;
   }
 }
Exemplo n.º 2
0
  /**
   * Event handler so FlxGame can toggle keys.
   *
   * @param FlashEvent A <code>KeyboardEvent</code> object.
   */
  public void handleKeyUp(KeyboardEvent FlashEvent) {
    KeyState object = _map.get(FlashEvent.keyCode);

    if (object == null) return;
    if (object.current > 0) object.current = -1;
    else object.current = 0;

    try {
      ClassReflection.getField(Keyboard.class, object.name).set(this, false);
    } catch (Exception e) {
      FlxG.log("Keyboard", e.getMessage());
    }
  }
Exemplo n.º 3
0
  /**
   * Event handler so FlxGame can toggle keys.
   *
   * @param FlashEvent A <code>KeyboardEvent</code> object.
   */
  public void handleKeyDown(KeyboardEvent FlashEvent) {
    KeyState object = _map.get(FlashEvent.keyCode);

    if (object == null) return;
    if (object.current > 0) object.current = 1;
    else object.current = 2;

    try { // TODO: Reflection is fairly slow, could we use a BooleanMap instead?
      ClassReflection.getField(Keyboard.class, object.name).set(this, true);
    } catch (Exception e) {
      FlxG.log("Keyboard", e.getMessage());
    }
  }
  public static Action createByClass(String className, HashMap<String, String> params) {

    Action a = null;

    try {
      Class<?> c = ClassReflection.forName(className);
      a = (Action) ClassReflection.newInstance(c);

      if (params != null) {
        //				a.setParams(params);

        for (String key : params.keySet()) {
          String value = params.get(key);

          try {
            ActionUtils.setParam(a, key, value);
          } catch (NoSuchFieldException
              | SecurityException
              | IllegalArgumentException
              | IllegalAccessException e) {
            EngineLogger.error(
                "Error Setting Action Param - Action:"
                    + className
                    + " Param: "
                    + key
                    + " Value: "
                    + value
                    + " Msg: NOT FOUND "
                    + e.getMessage());
          }
        }
      }
    } catch (ReflectionException e) {
      EngineLogger.error(e.getMessage());
    }

    return a;
  }
  // ----------------------------------------------------------------------
  public static AbstractRoomGenerator load(Element xml) {
    Class<AbstractRoomGenerator> c = ClassMap.get(xml.getName().toUpperCase());
    AbstractRoomGenerator type = null;

    try {
      type = ClassReflection.newInstance(c);
    } catch (Exception e) {
      System.err.println(xml.getName());
      e.printStackTrace();
    }

    type.parse(xml);

    return type;
  }
Exemplo n.º 6
0
  @Override
  public void parse(Element xmlElement) {
    String path = xmlElement.getAttribute("Path");

    XmlReader importXml = new XmlReader();
    Element importXmlElement = null;

    try {
      importXmlElement = importXml.parse(Gdx.files.internal("AI/" + path));
    } catch (IOException e) {
      e.printStackTrace();
    }

    try {
      Class<BehaviourTreeNode> c = ClassMap.get(importXmlElement.getName().toUpperCase());
      BehaviourTreeNode node = (BehaviourTreeNode) ClassReflection.newInstance(c);

      setNode(node);

      node.parse(importXmlElement);
    } catch (ReflectionException e) {
      e.printStackTrace();
    }
  }
  public static Mob mutable(int depth) {
    @SuppressWarnings("unchecked")
    Class<? extends Mob> cl = (Class<? extends Mob>) mobClass(depth);

    if (Random.Int(30) == 0) {
      if (cl == Rat.class) {
        cl = Albino.class;
      } else if (cl == Thief.class) {
        cl = Bandit.class;
      } else if (cl == Brute.class) {
        cl = Shielded.class;
      } else if (cl == Monk.class) {
        cl = Senior.class;
      } else if (cl == Scorpio.class) {
        cl = Acidic.class;
      }
    }

    try {
      return ClassReflection.newInstance(cl);
    } catch (Exception e) {
      return null;
    }
  }