Search in sources :

Example 1 with NPCTrigger

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++;
        }
    }
}
Also used : NPCClass(mc.dragons.core.gameobject.npc.NPCClass) NPCCondition(mc.dragons.core.gameobject.npc.NPCCondition) NPCTrigger(mc.dragons.core.gameobject.npc.NPCConditionalActions.NPCTrigger) ArrayList(java.util.ArrayList) List(java.util.List) NPCAction(mc.dragons.core.gameobject.npc.NPCAction)

Example 2 with NPCTrigger

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;
}
Also used : NPCTrigger(mc.dragons.core.gameobject.npc.NPCConditionalActions.NPCTrigger) Document(org.bson.Document) StorageAccess(mc.dragons.core.storage.StorageAccess)

Example 3 with NPCTrigger

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");
    }
}
Also used : NPCClass(mc.dragons.core.gameobject.npc.NPCClass) NPCConditionalActions(mc.dragons.core.gameobject.npc.NPCConditionalActions) NPCTrigger(mc.dragons.core.gameobject.npc.NPCConditionalActions.NPCTrigger) Document(org.bson.Document)

Aggregations

NPCTrigger (mc.dragons.core.gameobject.npc.NPCConditionalActions.NPCTrigger)3 NPCClass (mc.dragons.core.gameobject.npc.NPCClass)2 Document (org.bson.Document)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 NPCAction (mc.dragons.core.gameobject.npc.NPCAction)1 NPCCondition (mc.dragons.core.gameobject.npc.NPCCondition)1 NPCConditionalActions (mc.dragons.core.gameobject.npc.NPCConditionalActions)1 StorageAccess (mc.dragons.core.storage.StorageAccess)1