001package com.fs.starfarer.api.impl.campaign.econ;
002
003import java.util.Map;
004
005import com.fs.starfarer.api.Global;
006import com.fs.starfarer.api.impl.campaign.procgen.ConditionGenDataSpec;
007import com.fs.starfarer.api.ui.TooltipMakerAPI;
008import com.fs.starfarer.api.util.Misc;
009
010
011/**
012 * Requires corresponding entry in condition_gen_data.csv.
013 *  
014 * @author Alex Mosolov
015 *
016 * Copyright 2020 Fractal Softworks, LLC
017 */
018public class BaseHazardCondition extends BaseMarketConditionPlugin {
019        
020        public void apply(String id) {
021                Object test = Global.getSettings().getSpec(ConditionGenDataSpec.class, condition.getId(), true);
022                if (test instanceof ConditionGenDataSpec) {
023                        ConditionGenDataSpec spec = (ConditionGenDataSpec) test;
024                        float hazard = spec.getHazard();
025                        if (hazard != 0) {
026                                market.getHazard().modifyFlat(id, hazard, condition.getName());
027                        }
028                }
029        }
030
031        public void unapply(String id) {
032                market.getHazard().unmodifyFlat(id);
033        }
034
035        @Override
036        public Map<String, String> getTokenReplacements() {
037                return super.getTokenReplacements();
038        }
039
040        
041        protected void createTooltipAfterDescription(TooltipMakerAPI tooltip, boolean expanded) {
042                super.createTooltipAfterDescription(tooltip, expanded);
043                
044                Object test = Global.getSettings().getSpec(ConditionGenDataSpec.class, condition.getId(), true);
045                if (test instanceof ConditionGenDataSpec) {
046                        ConditionGenDataSpec spec = (ConditionGenDataSpec) test;
047                        float hazard = spec.getHazard();
048                        //hazard = 0.25f;
049                        if (hazard != 0) {
050                                String pct = "" + (int)(hazard * 100f) + "%";
051                                if (hazard > 0) pct = "+" + pct;
052                                tooltip.addPara("%s hazard rating", 10f, Misc.getHighlightColor(), pct);
053                        }
054                }
055        }
056}
057
058
059
060