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; } }
// ---------------------------------------------------------------------- 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; }
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; }
@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; } }