use of mc.dragons.core.gameobject.npc.NPCConditionalActions.NPCTrigger in project DragonsOnline by UniverseCraft.
the class NPCCommand method displayBehavior.
private void displayBehavior(CommandSender sender, String[] args) {
NPCClass npcClass = lookupNPCClass(sender, args[0]);
if (npcClass == null)
return;
sender.sendMessage(ChatColor.GREEN + "NPC Behaviors:");
for (NPCTrigger trigger : NPCTrigger.values()) {
sender.sendMessage(ChatColor.GRAY + "- Trigger: " + trigger);
int i = 0;
for (Entry<List<NPCCondition>, List<NPCAction>> entry : npcClass.getConditionalActions(trigger).getConditionals().entrySet()) {
sender.sendMessage(ChatColor.GRAY + " - Behavior " + ChatColor.DARK_GREEN + "#" + i + ChatColor.GRAY + ":");
sender.sendMessage(ChatColor.GRAY + " - Conditions:");
int j = 0;
for (NPCCondition condition : entry.getKey()) {
sender.sendMessage(ChatColor.DARK_GREEN + " #" + j + ": " + ChatColor.GRAY + displayNPCCondition(condition));
j++;
}
sender.sendMessage(ChatColor.GRAY + " - Actions:");
j = 0;
for (NPCAction action : entry.getValue()) {
sender.sendMessage(ChatColor.DARK_GREEN + " #" + j + ": " + ChatColor.GRAY + displayNPCAction(action));
j++;
}
i++;
}
}
}
use of mc.dragons.core.gameobject.npc.NPCConditionalActions.NPCTrigger in project DragonsOnline by UniverseCraft.
the class NPCClassLoader method registerNew.
public NPCClass registerNew(String className, String name, EntityType entityType, double maxHealth, int level, NPC.NPCType npcType) {
lazyLoadAll();
LOGGER.trace("Registering new NPC class (" + className + ")");
Document emptyConditionals = new Document();
for (NPCTrigger trigger : NPCTrigger.values()) {
emptyConditionals.append(trigger.toString(), new ArrayList<>());
}
Document data = new Document("_id", UUID.randomUUID()).append("className", className).append("name", name).append("entityType", entityType.toString()).append("maxHealth", Double.valueOf(maxHealth)).append("level", Integer.valueOf(level)).append("ai", Boolean.valueOf(npcType.hasAIByDefault())).append("immortal", Boolean.valueOf(npcType.isImmortalByDefault())).append("attributes", new Document()).append("npcType", npcType.toString()).append("lootTable", new Document()).append("conditionals", emptyConditionals).append("addons", new ArrayList<String>());
StorageAccess storageAccess = storageManager.getNewStorageAccess(GameObjectType.NPC_CLASS, data);
NPCClass npcClass = new NPCClass(storageManager, storageAccess);
masterRegistry.getRegisteredObjects().add(npcClass);
cachedNPCClasses.put(npcClass.getClassName(), npcClass);
return npcClass;
}
use of mc.dragons.core.gameobject.npc.NPCConditionalActions.NPCTrigger in project DragonsOnline by UniverseCraft.
the class NPCCommand method manageBehavior.
private void manageBehavior(CommandSender sender, String[] args) {
NPCClass npcClass = lookupNPCClass(sender, args[0]);
if (npcClass == null)
return;
if (args.length == 2) {
displayBehavior(sender, args);
return;
}
NPCTrigger trigger = NPCTrigger.valueOf(args[2]);
NPCConditionalActions behaviorsLocal = npcClass.getConditionalActions(trigger);
NPCConditionalActions parsedBehaviors = npcClass.getConditionalActions(trigger);
Document conditionals = npcClass.getStorageAccess().getDocument().get("conditionals", Document.class);
List<Document> behaviors = conditionals.getList(trigger.toString(), Document.class);
Document base = Document.parse(npcClass.getData().toJson());
boolean changed = false;
if (args[3].equalsIgnoreCase("add")) {
changed = addBehavior(sender, behaviors, conditionals, trigger, npcClass, parsedBehaviors);
} else if (args[3].equalsIgnoreCase("remove")) {
changed = removeBehavior(sender, args, behaviors, conditionals, trigger, npcClass, parsedBehaviors);
} else {
changed = manageBehavior(sender, args, behaviors, conditionals, trigger, npcClass, behaviorsLocal);
}
if (changed) {
AUDIT_LOG.saveEntry(npcClass, user(sender), base, "Updated behaviors");
}
}
Aggregations