Search in sources :

Example 6 with Faction

use of delta.games.lotro.lore.reputation.Faction in project lotro-companion by dmorcellet.

the class FactionHistoryChartController method buildChart.

private JFreeChart buildChart() {
    String title = "";
    if (_showTitle) {
        title = _stats.getFaction().getName();
    }
    updateData();
    JFreeChart jfreechart = ChartFactory.createXYStepChart(title, "Time", "Level", _data, PlotOrientation.VERTICAL, true, true, false);
    Color foregroundColor = GuiFactory.getForegroundColor();
    Paint backgroundPaint = GuiFactory.getBackgroundPaint();
    jfreechart.setBackgroundPaint(backgroundPaint);
    TextTitle t = new TextTitle(title);
    t.setFont(t.getFont().deriveFont(24.0f));
    t.setPaint(foregroundColor);
    jfreechart.setTitle(t);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainPannable(false);
    XYStepAreaRenderer xysteparearenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA_AND_SHAPES);
    Faction faction = _stats.getFaction();
    final FactionLevel[] levels = faction.getLevels();
    XYToolTipGenerator tooltip = new StandardXYToolTipGenerator() {

        @Override
        public String generateLabelString(XYDataset dataset, int series, int item) {
            String label = "???";
            int tier = (int) dataset.getYValue(series, item);
            for (FactionLevel level : levels) {
                if (level.getValue() == tier) {
                    label = level.getName();
                }
            }
            double timestamp = dataset.getXValue(series, item);
            String date = Formats.getDateString(Long.valueOf((long) timestamp));
            return label + " (" + date + ")";
        }
    };
    xysteparearenderer.setBaseToolTipGenerator(tooltip);
    xysteparearenderer.setSeriesPaint(0, new Color(0, 0, 255));
    xyplot.setRenderer(xysteparearenderer);
    DateAxis axis = (DateAxis) xyplot.getDomainAxis();
    SimpleDateFormat sdf = Formats.getDateFormatter();
    axis.setDateFormatOverride(sdf);
    axis.setAxisLinePaint(foregroundColor);
    axis.setLabelPaint(foregroundColor);
    axis.setTickLabelPaint(foregroundColor);
    NumberAxis valueAxis = (NumberAxis) xyplot.getRangeAxis();
    valueAxis.setAutoRange(false);
    valueAxis.setAxisLinePaint(foregroundColor);
    valueAxis.setLabelPaint(foregroundColor);
    valueAxis.setTickLabelPaint(foregroundColor);
    final int min = levels[0].getValue();
    int max = levels[levels.length - 1].getValue();
    valueAxis.setRange(min, max);
    NumberFormat nf = new NumberFormat() {

        private String format(int number) {
            String ret = levels[number - min].getName();
            return ret;
        }

        @Override
        public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {
            return toAppendTo.append(format((int) number));
        }

        @Override
        public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
            return toAppendTo.append(format((int) number));
        }

        @Override
        public Number parse(String source, ParsePosition parsePosition) {
            return null;
        }
    };
    valueAxis.setNumberFormatOverride(nf);
    LegendTitle legend = jfreechart.getLegend();
    legend.setItemPaint(foregroundColor);
    legend.setBackgroundPaint(backgroundPaint);
    return jfreechart;
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) Color(java.awt.Color) XYStepAreaRenderer(org.jfree.chart.renderer.xy.XYStepAreaRenderer) LegendTitle(org.jfree.chart.title.LegendTitle) Paint(java.awt.Paint) FieldPosition(java.text.FieldPosition) JFreeChart(org.jfree.chart.JFreeChart) FactionLevel(delta.games.lotro.lore.reputation.FactionLevel) Paint(java.awt.Paint) TextTitle(org.jfree.chart.title.TextTitle) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYPlot(org.jfree.chart.plot.XYPlot) XYDataset(org.jfree.data.xy.XYDataset) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) SimpleDateFormat(java.text.SimpleDateFormat) Faction(delta.games.lotro.lore.reputation.Faction) NumberFormat(java.text.NumberFormat) ParsePosition(java.text.ParsePosition)

Example 7 with Faction

use of delta.games.lotro.lore.reputation.Faction in project lotro-companion by dmorcellet.

the class DeedUiUtils method buildFactionCombo.

/**
 * Build a combo-box controller to choose a faction.
 * @return A new combo-box controller.
 */
public static ComboBoxController<Faction> buildFactionCombo() {
    ComboBoxController<Faction> ctrl = new ComboBoxController<Faction>();
    ctrl.addEmptyItem("");
    List<Faction> factions = FactionsRegistry.getInstance().getAll();
    for (Faction faction : factions) {
        ctrl.addItem(faction, faction.getName());
    }
    ctrl.selectItem(null);
    return ctrl;
}
Also used : ComboBoxController(delta.common.ui.swing.combobox.ComboBoxController) Faction(delta.games.lotro.lore.reputation.Faction)

Example 8 with Faction

use of delta.games.lotro.lore.reputation.Faction in project lotro-tools by dmorcellet.

the class LotroCompendiumDeedsLoader method handleReputation.

@SuppressWarnings("unchecked")
private void handleReputation(Rewards rewards, List<Object> reputationItems) {
    // reputation={{val="+700 with Iron Garrison Guards"}}
    if (reputationItems == null) {
        return;
    }
    FactionsRegistry registry = FactionsRegistry.getInstance();
    Reputation reputation = rewards.getReputation();
    for (Object reputationItem : reputationItems) {
        Map<String, Object> reputationMap = (Map<String, Object>) reputationItem;
        String reputationStr = (String) reputationMap.get("val");
        int spaceIndex = reputationStr.indexOf(" ");
        Integer value = NumericTools.parseInteger(reputationStr.substring(0, spaceIndex));
        String factionStr = reputationStr.substring(spaceIndex + 1).trim();
        if (factionStr.startsWith("with "))
            factionStr = factionStr.substring(5);
        Faction faction = registry.getByName(factionStr);
        if ((faction != null) && (value != null)) {
            ReputationItem repItem = new ReputationItem(faction);
            repItem.setAmount(value.intValue());
            reputation.add(repItem);
        } else {
            System.out.println("Not handled [" + reputationStr + "]");
        }
    }
}
Also used : FactionsRegistry(delta.games.lotro.lore.reputation.FactionsRegistry) Reputation(delta.games.lotro.common.Reputation) Map(java.util.Map) ReputationItem(delta.games.lotro.common.ReputationItem) Faction(delta.games.lotro.lore.reputation.Faction)

Example 9 with Faction

use of delta.games.lotro.lore.reputation.Faction in project lotro-tools by dmorcellet.

the class LotroWikiDeedPageParser method extractFaction.

private Faction extractFaction(String line) {
    String factionName = getLineValue(line);
    if (factionName.endsWith(FACTION_SUFFIX)) {
        factionName = factionName.substring(0, factionName.length() - FACTION_SUFFIX.length());
    }
    Faction faction = FactionsRegistry.getInstance().getByName(factionName);
    return faction;
}
Also used : Faction(delta.games.lotro.lore.reputation.Faction)

Example 10 with Faction

use of delta.games.lotro.lore.reputation.Faction in project lotro-tools by dmorcellet.

the class LotroWikiDeedPageParser method parseDeed.

private DeedDescription parseDeed(int startIndex, String[] lines, String deedName) {
    DeedDescription deed = new DeedDescription();
    deed.setName(deedName);
    deed.setType(null);
    Rewards rewards = deed.getRewards();
    // Reputation
    Faction faction = null;
    Integer reputation = null;
    // Virtues
    VirtueId virtueId = null;
    Integer virtueCount = null;
    // Item rewards
    String[] itemRewards = null;
    Integer[] itemRewardCounts = null;
    // Categories
    String deedType = null;
    String deedSubtype = null;
    String regionalSub = null;
    // Deeds chain
    List<String> deedsChain = new ArrayList<String>();
    for (int index = startIndex + 1; index < lines.length; index++) {
        String line = lines[index].trim();
        if (line.contains("{{Deed"))
            break;
        String lineKey = fetchLineKey(line);
        // System.out.println(line);
        if ("name".equals(lineKey)) {
        // String name=getLineValue(line);
        // deed.setName(name);
        } else if ("Lore-text".equals(lineKey)) {
            String description = getLineValue(line);
            description = normalize(description);
            deed.setDescription(description);
        } else if ("Objective".equals(lineKey)) {
            StringBuilder sb = new StringBuilder();
            String firstLine = getLineValue(line);
            sb.append(firstLine);
            while (true) {
                String nextLine = lines[index + 1].trim();
                if (nextLine.startsWith("|")) {
                    break;
                }
                sb.append('\n').append(nextLine);
                index++;
            }
            String objectives = sb.toString().trim();
            objectives = normalize(objectives);
            deed.setObjectives(objectives);
        } else if ("Faction".equals(lineKey)) {
            faction = extractFaction(line);
        } else if ("Reputation".equals(lineKey)) {
            String repValue = getLineValue(line).replace(",", "");
            reputation = NumericTools.parseInteger(repValue);
        } else if ("Title".equals(lineKey)) {
            Title title = extractTitle(line);
            if (title != null) {
                rewards.addTitle(title);
            }
        } else if ("Virtue".equals(lineKey)) {
            virtueId = extractVirtue(line);
        } else if ("Virtue-value".equals(lineKey)) {
            virtueCount = NumericTools.parseInteger(getLineValue(line));
        } else if ("TP-reward".equals(lineKey)) {
            String tpStr = getLineValue(line);
            if ((!tpStr.isEmpty()) && (!"???".equals(tpStr))) {
                Integer tp = NumericTools.parseInteger(tpStr, false);
                if (tp != null) {
                    rewards.setLotroPoints(tp.intValue());
                } else {
                    _logger.warn("Bad LOTRO points value in file " + _currentFile + ": [" + tpStr + "]");
                }
            }
        } else if ("SM-reward".equals(lineKey)) {
            String smStr = getLineValue(line);
            if (!smStr.isEmpty()) {
                Integer marks = NumericTools.parseInteger(smStr, false);
                if (marks != null) {
                    ObjectsSet objects = deed.getRewards().getObjects();
                    ObjectItem item = new ObjectItem("Mark");
                    item.setItemId(1879224343);
                    objects.addObject(item, marks.intValue());
                } else {
                    _logger.warn("Bad SM value in file " + _currentFile + ": [" + smStr + "]");
                }
            }
        } else if ("CTP-reward".equals(lineKey)) {
            String value = getLineValue(line);
            if ("Y".equals(value)) {
            // TODO Class Trait Point
            }
        } else if ("Trait-reward".equals(lineKey)) {
            String traitStr = getLineValue(line);
            if (!traitStr.isEmpty()) {
                handleTraitReward(rewards, traitStr);
            }
        } else if ("Emote-reward".equals(lineKey)) {
            String emoteStr = getLineValue(line);
            if (!emoteStr.isEmpty()) {
                handleEmoteReward(rewards, emoteStr);
            }
        } else if ("Skill-reward".equals(lineKey)) {
            String skillStr = getLineValue(line);
            if (!skillStr.isEmpty()) {
                handleSkillReward(rewards, skillStr);
            }
        } else if ("Level".equals(lineKey)) {
            String levelStr = getLineValue(line);
            if ("?".equals(levelStr))
                levelStr = "";
            if ("???".equals(levelStr))
                levelStr = "";
            if (!levelStr.isEmpty()) {
                levelStr = levelStr.replace("&lt;", "<");
                if (levelStr.startsWith("<="))
                    levelStr = levelStr.substring(2);
                if (levelStr.equals("{{Level Cap}}"))
                    levelStr = "1000";
                if (levelStr.endsWith("+"))
                    levelStr = levelStr.substring(0, levelStr.length() - 1);
                levelStr = removeXmlComments(levelStr);
                Integer level = NumericTools.parseInteger(levelStr, false);
                if (level != null) {
                    deed.setMinLevel(level);
                } else {
                    _logger.warn("Bad level value in file " + _currentFile + ": [" + levelStr + "]");
                }
            }
        } else if ("Deed-type".equals(lineKey)) {
            deedType = getLineValue(line);
        } else if ("Deed-subtype".equals(lineKey)) {
            deedSubtype = getLineValue(line);
        } else if ("Regional-sub".equals(lineKey)) {
            regionalSub = getLineValue(line);
        } else if ((lineKey != null) && (lineKey.startsWith(DEED_CHAIN_SEED))) {
            Integer deedIndex = NumericTools.parseInteger(lineKey.substring(DEED_CHAIN_SEED.length()));
            if (deedIndex != null) {
                // Add missing entries
                int nbMissingEntries = deedIndex.intValue() - deedsChain.size();
                for (int i = 0; i < nbMissingEntries; i++) {
                    deedsChain.add(null);
                }
                // Set deed name in chain
                String deedNameInChain = getLineValue(line);
                deedsChain.set(deedIndex.intValue() - 1, deedNameInChain);
            }
        } else if ("Parent-deed".equals(lineKey)) {
            String parentDeed = getLineValue(line);
            if (!parentDeed.isEmpty()) {
                if (useParentDeedInfo(parentDeed, deedName)) {
                    parentDeed = fixParentDeedInfo(parentDeed, deedName);
                    DeedProxy parentProxy = new DeedProxy();
                    parentProxy.setName(parentDeed);
                    deed.getParentDeedProxies().add(parentProxy);
                }
            }
        }
        for (int i = 1; i <= 3; i++) {
            String suffix = (i != 1) ? String.valueOf(i) : "";
            if (("Item-reward" + suffix).equals(lineKey)) {
                String itemName = getLineValue(line);
                if (!itemName.isEmpty()) {
                    if (itemRewards == null) {
                        itemRewards = new String[3];
                    }
                    itemRewards[i - 1] = itemName;
                }
            }
            if (("Item-amount" + suffix).equals(lineKey)) {
                String itemCountStr = getLineValue(line);
                if (!itemCountStr.isEmpty()) {
                    if (itemRewardCounts == null) {
                        itemRewardCounts = new Integer[3];
                    }
                    itemRewardCounts[i - 1] = NumericTools.parseInteger(itemCountStr);
                }
            }
        }
    /*
| DP-reward    = 
| Hidden       = 
| Meta-deed     = 
| Extra         = 
       */
    }
    if ((faction != null) && (reputation != null)) {
        ReputationItem item = new ReputationItem(faction);
        item.setAmount(reputation.intValue());
        rewards.getReputation().add(item);
    }
    if (virtueId != null) {
        int count = (virtueCount != null) ? virtueCount.intValue() : 1;
        Virtue virtue = new Virtue(virtueId, count);
        rewards.addVirtue(virtue);
    }
    if (itemRewards != null) {
        handleItemRewards(deed, itemRewards, itemRewardCounts);
    }
    // Categories
    handleCategories(deed, deedType, deedSubtype, regionalSub);
    // Deeds chain
    handleDeedsChain(deed, deedsChain);
    return deed;
}
Also used : DeedDescription(delta.games.lotro.lore.deeds.DeedDescription) ArrayList(java.util.ArrayList) Title(delta.games.lotro.common.Title) ReputationItem(delta.games.lotro.common.ReputationItem) ObjectItem(delta.games.lotro.common.objects.ObjectItem) VirtueId(delta.games.lotro.common.VirtueId) DeedProxy(delta.games.lotro.lore.deeds.DeedProxy) Rewards(delta.games.lotro.common.Rewards) ObjectsSet(delta.games.lotro.common.objects.ObjectsSet) Virtue(delta.games.lotro.common.Virtue) Faction(delta.games.lotro.lore.reputation.Faction)

Aggregations

Faction (delta.games.lotro.lore.reputation.Faction)20 FactionLevel (delta.games.lotro.lore.reputation.FactionLevel)6 JPanel (javax.swing.JPanel)5 FactionLevelStatus (delta.games.lotro.character.reputation.FactionLevelStatus)3 FactionStatus (delta.games.lotro.character.reputation.FactionStatus)3 ReputationItem (delta.games.lotro.common.ReputationItem)3 FactionsRegistry (delta.games.lotro.lore.reputation.FactionsRegistry)3 GridBagLayout (java.awt.GridBagLayout)3 CellDataProvider (delta.common.ui.swing.tables.CellDataProvider)2 TableColumnController (delta.common.ui.swing.tables.TableColumnController)2 Reputation (delta.games.lotro.common.Reputation)2 VirtueId (delta.games.lotro.common.VirtueId)2 ReputationRewardFilter (delta.games.lotro.common.rewards.filters.ReputationRewardFilter)2 BorderLayout (java.awt.BorderLayout)2 GridBagConstraints (java.awt.GridBagConstraints)2 Insets (java.awt.Insets)2 TableCellRenderer (javax.swing.table.TableCellRenderer)2 CheckboxController (delta.common.ui.swing.checkbox.CheckboxController)1 ComboBoxController (delta.common.ui.swing.combobox.ComboBoxController)1 ItemSelectionListener (delta.common.ui.swing.combobox.ItemSelectionListener)1