Search in sources :

Example 6 with DeedDescription

use of delta.games.lotro.lore.deeds.DeedDescription in project lotro-tools by dmorcellet.

the class LotroCompendiumDeedsLoader method buildDeedFromRawData.

@SuppressWarnings("unchecked")
private DeedDescription buildDeedFromRawData(Object data) {
    if (!(data instanceof Map)) {
        return null;
    }
    Map<String, Object> map = (Map<String, Object>) data;
    DeedDescription deed = new DeedDescription();
    // [d, c, next, pois, o, virtues, prev, id, mobs, t, level, emotes, name, reputation, titles, traits, receive, zone]
    // [mobs]
    // ID
    Double id = (Double) map.get("id");
    deed.setIdentifier(id.intValue());
    // Name
    String name = (String) map.get("name");
    deed.setName(name);
    // Description
    String description = (String) map.get("d");
    if (description != null) {
        description = description.replace("  ", " ");
    }
    deed.setDescription(description);
    /*
    // c=Comments?
    List<String> comments=(List<String>)map.get("c");
    // TODO
     */
    // Previous
    List<Double> prevIds = (List<Double>) map.get("prev");
    if (prevIds != null) {
        if (prevIds.size() > 1) {
            System.out.println("Multiple previous deeds for id=" + deed.getIdentifier() + ": " + prevIds);
        }
        for (Double prevId : prevIds) {
            DeedProxy previousDeedProxy = new DeedProxy();
            previousDeedProxy.setId(prevId.intValue());
            deed.setPreviousDeedProxy(previousDeedProxy);
            _proxies.add(previousDeedProxy);
        }
    }
    // Next
    List<Double> nextIds = (List<Double>) map.get("next");
    if (nextIds != null) {
        if (nextIds.size() > 1) {
            System.out.println("Multiple next deeds for id=" + deed.getIdentifier() + ": " + nextIds);
        }
        for (Double nextId : nextIds) {
            DeedProxy nextDeedProxy = new DeedProxy();
            nextDeedProxy.setId(nextId.intValue());
            deed.setNextDeedProxy(nextDeedProxy);
            _proxies.add(nextDeedProxy);
        }
    }
    /*
    // pois
    // TODO
    // mobs
    // TODO
    List<Object> mobs=(List<Object>)map.get("mobs");
    */
    // Type
    String type = (String) map.get("t");
    handleType(deed, type);
    // Zone
    String zone = (String) map.get("zone");
    zone = normalizeZone(zone);
    deed.setCategory(zone);
    // Objectives
    String objectives = (String) map.get("o");
    if (objectives != null) {
        objectives = objectives.replace("  ", " ");
        objectives = objectives.replace("Find\n", "");
        objectives = objectives.replace("Find ", "");
    }
    deed.setObjectives(objectives);
    // Level
    Double level = (Double) map.get("level");
    if (level != null) {
        deed.setMinLevel(Integer.valueOf(level.intValue()));
    }
    // Rewards
    Rewards rewards = deed.getRewards();
    // - titles
    {
        List<Object> titles = (List<Object>) map.get("titles");
        if (titles != null) {
            for (Object title : titles) {
                Map<String, Object> titleMap = (Map<String, Object>) title;
                String titleLabel = (String) titleMap.get("val");
                Title titleRewards = new Title(titleLabel, titleLabel);
                rewards.addTitle(titleRewards);
            }
        }
    }
    // - traits
    {
        List<Object> traits = (List<Object>) map.get("traits");
        if (traits != null) {
            for (Object trait : traits) {
                Map<String, Object> traitMap = (Map<String, Object>) trait;
                String traitLabel = (String) traitMap.get("val");
                Trait traitRewards = new Trait(traitLabel);
                rewards.addTrait(traitRewards);
            }
        }
    }
    // - emotes
    {
        List<Object> emotes = (List<Object>) map.get("emotes");
        if (emotes != null) {
            for (Object emote : emotes) {
                Map<String, Object> emoteMap = (Map<String, Object>) emote;
                String emoteCommand = (String) emoteMap.get("val");
                if (emoteCommand.startsWith("/")) {
                    emoteCommand = emoteCommand.substring(1);
                }
                Emote emoteRewards = new Emote(emoteCommand);
                rewards.addEmote(emoteRewards);
            }
        }
    }
    // - items
    // receive={{id="70018CBD",q="(x2)",val="Yule Festival Token"}}
    {
        List<Object> items = (List<Object>) map.get("receive");
        if (items != null) {
            for (Object item : items) {
                Map<String, Object> itemMap = (Map<String, Object>) item;
                handleItem(rewards, itemMap);
            }
        }
    }
    // - virtues
    List<Object> virtueItems = (List<Object>) map.get("virtues");
    handleVirtues(rewards, virtueItems);
    // - reputation
    List<Object> reputationItems = (List<Object>) map.get("reputation");
    handleReputation(rewards, reputationItems);
    return deed;
}
Also used : DeedDescription(delta.games.lotro.lore.deeds.DeedDescription) Emote(delta.games.lotro.common.Emote) Title(delta.games.lotro.common.Title) DeedProxy(delta.games.lotro.lore.deeds.DeedProxy) Rewards(delta.games.lotro.common.Rewards) ArrayList(java.util.ArrayList) List(java.util.List) Trait(delta.games.lotro.common.Trait) Map(java.util.Map)

Example 7 with DeedDescription

use of delta.games.lotro.lore.deeds.DeedDescription in project lotro-tools by dmorcellet.

the class LotroCompendiumDeedsLoader method doIt.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void doIt() throws Exception {
    File root = new File(new File("data"), "deeds");
    File luaDb = new File(root, "deeds.lua");
    List<DeedDescription> deeds = new ArrayList<DeedDescription>();
    // File luaDb=new File("indexes.lua");
    LuaParser parser = new LuaParser();
    Object map = parser.readObject(luaDb);
    if (map instanceof Map) {
        System.out.println(((Map) map).keySet());
    } else if (map instanceof List) {
        List<Object> datas = (List<Object>) map;
        int length = datas.size();
        System.out.println("Array of " + length + " items.");
        for (Object data : datas) {
            DeedDescription deed = buildDeedFromRawData(data);
            normalizeDeed(deed);
            deeds.add(deed);
        }
    }
    resolveProxies(deeds);
    File loreDir = LotroCoreConfig.getInstance().getLoreDir();
    File out = new File(loreDir, "deeds_lc.xml");
    DeedsContainer.writeSortedDeeds(deeds, out);
}
Also used : LuaParser(delta.games.lotro.plugins.LuaParser) DeedDescription(delta.games.lotro.lore.deeds.DeedDescription) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) Map(java.util.Map)

Example 8 with DeedDescription

use of delta.games.lotro.lore.deeds.DeedDescription in project lotro-tools by dmorcellet.

the class MergeDeedsDatabases method mergeLorebook2LotroCompendium.

private void mergeLorebook2LotroCompendium() {
    List<DeedDescription> matchingLotroCompendiumDeeds = findMatchingDeeds(_lorebook, _lotroCompendium);
    List<DeedDescription> lorebookDeeds = _lorebook.getAll();
    int nbDeeds = lorebookDeeds.size();
    for (int i = 0; i < nbDeeds; i++) {
        DeedDescription lorebookDeed = lorebookDeeds.get(i);
        DeedDescription lotroCompendiumDeed = matchingLotroCompendiumDeeds.get(i);
        if (lotroCompendiumDeed != null) {
            // Categories
            String category = lotroCompendiumDeed.getCategory();
            lorebookDeed.setCategory(category);
            // IDs
            lotroCompendiumDeed.setIdentifier(lorebookDeed.getIdentifier());
            // Objectives
            String lorebookObjectives = lorebookDeed.getObjectives();
            if ((lorebookObjectives == null) || (lorebookObjectives.isEmpty())) {
                lorebookDeed.setObjectives(lotroCompendiumDeed.getObjectives());
            }
            // Item XP
            lotroCompendiumDeed.getRewards().setHasItemXP(lorebookDeed.getRewards().hasItemXP());
        } else {
            _lotroCompendium.addDeed(lorebookDeed);
        }
    }
    // Afterwards, merge proxy info (previous/next)
    for (int i = 0; i < nbDeeds; i++) {
        DeedDescription lorebookDeed = lorebookDeeds.get(i);
        DeedDescription lotroCompendiumDeed = matchingLotroCompendiumDeeds.get(i);
        if (lotroCompendiumDeed != null) {
            // Previous
            DeedProxy previousProxy = lotroCompendiumDeed.getPreviousDeedProxy();
            if (previousProxy != null) {
                int previousId = previousProxy.getId();
                if (previousId > 10000) {
                    DeedProxy lorebookPreviousProxy = new DeedProxy();
                    lorebookPreviousProxy.setId(previousId);
                    lorebookDeed.setPreviousDeedProxy(lorebookPreviousProxy);
                } else {
                    System.out.println("Warn: unresolved previous id=" + previousId);
                }
            }
            // Next
            DeedProxy nextProxy = lotroCompendiumDeed.getNextDeedProxy();
            if (nextProxy != null) {
                int nextId = nextProxy.getId();
                if (nextId > 10000) {
                    DeedProxy lorebookNextProxy = new DeedProxy();
                    lorebookNextProxy.setId(nextId);
                    lorebookDeed.setNextDeedProxy(lorebookNextProxy);
                } else {
                    System.out.println("Warn: unresolved next id=" + nextId);
                }
            }
        }
    }
}
Also used : DeedDescription(delta.games.lotro.lore.deeds.DeedDescription) DeedProxy(delta.games.lotro.lore.deeds.DeedProxy)

Example 9 with DeedDescription

use of delta.games.lotro.lore.deeds.DeedDescription in project lotro-tools by dmorcellet.

the class MergeDeedsDatabases method findMatchingDeeds.

private List<DeedDescription> findMatchingDeeds(DeedsContainer toMatch, DeedsContainer matchCandidates) {
    List<DeedDescription> matchingDeeds = new ArrayList<DeedDescription>();
    int nbMatches = 0;
    List<DeedDescription> sourceDeeds = toMatch.getAll();
    for (DeedDescription sourceDeed : sourceDeeds) {
        DeedDescription matchingDeed = findMatchingDeedInContainer(matchCandidates, sourceDeed);
        if (matchingDeed != null) {
            matchingDeeds.add(matchingDeed);
            nbMatches++;
        } else {
            matchingDeeds.add(null);
        }
    }
    System.out.println("Nb matches=" + nbMatches + " / " + sourceDeeds.size());
    return matchingDeeds;
}
Also used : DeedDescription(delta.games.lotro.lore.deeds.DeedDescription) ArrayList(java.util.ArrayList)

Example 10 with DeedDescription

use of delta.games.lotro.lore.deeds.DeedDescription in project lotro-tools by dmorcellet.

the class CheckDeedLinks method loadPreviousDeedsOfChildren.

private Set<String> loadPreviousDeedsOfChildren(DeedDescription deed) {
    Set<String> previousDeeds = new HashSet<String>();
    List<DeedProxy> childProxies = deed.getChildDeedProxies().getDeedProxies();
    for (DeedProxy childProxy : childProxies) {
        DeedDescription childDeed = childProxy.getDeed();
        previousDeeds.addAll(loadPreviousDeeds(childDeed));
    }
    return previousDeeds;
}
Also used : DeedDescription(delta.games.lotro.lore.deeds.DeedDescription) DeedProxy(delta.games.lotro.lore.deeds.DeedProxy) HashSet(java.util.HashSet)

Aggregations

DeedDescription (delta.games.lotro.lore.deeds.DeedDescription)45 DeedProxy (delta.games.lotro.lore.deeds.DeedProxy)13 ArrayList (java.util.ArrayList)13 File (java.io.File)6 Rewards (delta.games.lotro.common.Rewards)5 DeedsManager (delta.games.lotro.lore.deeds.DeedsManager)4 HashSet (java.util.HashSet)4 DeedXMLParser (delta.games.lotro.lore.deeds.io.xml.DeedXMLParser)3 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 List (java.util.List)3 Title (delta.games.lotro.common.Title)2 Virtue (delta.games.lotro.common.Virtue)2 VirtueId (delta.games.lotro.common.VirtueId)2 ObjectItem (delta.games.lotro.common.objects.ObjectItem)2 ObjectsSet (delta.games.lotro.common.objects.ObjectsSet)2 DeedXMLWriter (delta.games.lotro.lore.deeds.io.xml.DeedXMLWriter)2 BorderLayout (java.awt.BorderLayout)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2