001package com.fs.starfarer.api.impl.campaign.missions.cb; 002 003import java.awt.Color; 004import java.util.ArrayList; 005import java.util.List; 006import java.util.Random; 007 008import com.fs.starfarer.api.Global; 009import com.fs.starfarer.api.campaign.CampaignFleetAPI; 010import com.fs.starfarer.api.campaign.FactionAPI; 011import com.fs.starfarer.api.campaign.StarSystemAPI; 012import com.fs.starfarer.api.campaign.TextPanelAPI; 013import com.fs.starfarer.api.campaign.econ.MarketAPI; 014import com.fs.starfarer.api.characters.PersonAPI; 015import com.fs.starfarer.api.fleet.FleetMemberAPI; 016import com.fs.starfarer.api.fleet.FleetMemberType; 017import com.fs.starfarer.api.impl.campaign.DebugFlags; 018import com.fs.starfarer.api.impl.campaign.ids.Factions; 019import com.fs.starfarer.api.impl.campaign.ids.Tags; 020import com.fs.starfarer.api.impl.campaign.missions.hub.HubMissionWithBarEvent; 021import com.fs.starfarer.api.ui.TooltipMakerAPI; 022import com.fs.starfarer.api.util.Misc; 023import com.fs.starfarer.api.util.WeightedRandomPicker; 024 025public class CBRemnantStation extends BaseCustomBountyCreator { 026 027 @Override 028 public float getBountyDays() { 029 return CBStats.REMNANT_STATION_DAYS; 030 } 031 032 @Override 033 public float getFrequency(HubMissionWithBarEvent mission, int difficulty) { 034 String faction = mission.getPerson().getFaction().getId(); 035 if (!Factions.HEGEMONY.equals(faction) && 036 !Factions.LUDDIC_PATH.equals(faction) && 037 !Factions.LUDDIC_CHURCH.equals(faction)) { 038 return 0f; 039 } 040 if (getStations(mission, difficulty).isEmpty()) return 0f; 041 return super.getFrequency(mission, difficulty) * CBStats.REMNANT_STATION_FREQ; 042 } 043 044 public void addIntelAssessment(TextPanelAPI text, HubMissionWithBarEvent mission, CustomBountyData data) { 045 float opad = 10f; 046 List<FleetMemberAPI> list = new ArrayList<FleetMemberAPI>(); 047 List<FleetMemberAPI> members = data.fleet.getFleetData().getMembersListCopy(); 048 int max = 7; 049 int cols = 7; 050 float iconSize = 440 / cols; 051 Color h = Misc.getHighlightColor(); 052 053 for (FleetMemberAPI member : members) { 054 if (list.size() >= max) break; 055 056 if (member.isFighterWing()) continue; 057 058 FleetMemberAPI copy = Global.getFactory().createFleetMember(FleetMemberType.SHIP, member.getVariant()); 059 if (member.isFlagship()) { 060 copy.setCaptain(data.fleet.getCommander()); 061 } 062 list.add(copy); 063 } 064 065 if (!list.isEmpty()) { 066 TooltipMakerAPI info = text.beginTooltip(); 067 info.setParaSmallInsignia(); 068 info.addPara(Misc.ucFirst(mission.getPerson().getHeOrShe()) + " taps a data pad, and " + 069 "an intel assessment shows up on your tripad.", 0f); 070 info.addShipList(cols, 1, iconSize, data.fleet.getFaction().getBaseUIColor(), list, opad); 071 072 if (data.difficulty >= 9) { 073 info.addPara("The station is assessed to be fully functional and extremely dangerous.", opad); 074 } else { 075 info.addPara("The station is assessed to be damaged, but still highly dangerous.", opad); 076 } 077 text.addTooltip(); 078 } 079 return; 080 } 081 082 083 public void addFleetDescription(TooltipMakerAPI info, float width, float height, HubMissionWithBarEvent mission, CustomBountyData data) { 084 PersonAPI person = data.fleet.getCommander(); 085 FactionAPI faction = person.getFaction(); 086 int cols = 7; 087 float iconSize = width / cols; 088 float opad = 10f; 089 Color h = Misc.getHighlightColor(); 090 091 if (DebugFlags.PERSON_BOUNTY_DEBUG_INFO) { 092 093 } 094 boolean deflate = false; 095 if (!data.fleet.isInflated()) { 096 data.fleet.inflateIfNeeded(); 097 deflate = true; 098 } 099 100 List<FleetMemberAPI> list = new ArrayList<FleetMemberAPI>(); 101 Random random = new Random(person.getNameString().hashCode() * 170000); 102 103 List<FleetMemberAPI> members = data.fleet.getFleetData().getMembersListCopy(); 104 int max = 7; 105 for (FleetMemberAPI member : members) { 106 if (list.size() >= max) break; 107 108 if (member.isFighterWing()) continue; 109 110 float prob = (float) member.getFleetPointCost() / 20f; 111 prob += (float) max / (float) members.size(); 112 if (member.isFlagship()) prob = 1f; 113 //if (members.size() <= max) prob = 1f; 114 115 if (random.nextFloat() > prob) continue; 116 117 FleetMemberAPI copy = Global.getFactory().createFleetMember(FleetMemberType.SHIP, member.getVariant()); 118 if (member.isFlagship()) { 119 copy.setCaptain(person); 120 } 121 list.add(copy); 122 } 123 124 if (!list.isEmpty()) { 125 info.addPara("The bounty posting contains partial intel about the station.", opad); 126 info.addShipList(cols, 1, iconSize, faction.getBaseUIColor(), list, opad); 127 128 int num = members.size() - list.size(); 129 //num = Math.round((float)num * (1f + random.nextFloat() * 0.5f)); 130 131 if (num < 5) num = 0; 132 else if (num < 10) num = 5; 133 else if (num < 20) num = 10; 134 else num = 20; 135 136 if (data.difficulty >= 9) { 137 info.addPara("The station is assessed to be fully functional and extremely dangerous.", opad); 138 } else { 139 info.addPara("The station is assessed to be damaged, but still highly dangerous.", opad); 140 } 141 } 142 143 if (deflate) { 144 data.fleet.deflate(); 145 } 146 } 147 148 149 public List<CampaignFleetAPI> getStations(HubMissionWithBarEvent mission, int difficulty) { 150 List<CampaignFleetAPI> stations = new ArrayList<CampaignFleetAPI>(); 151 for (StarSystemAPI system : Global.getSector().getStarSystems()) { 152 if (!system.hasTag(Tags.THEME_REMNANT_MAIN)) continue; 153 if (system.hasTag(Tags.THEME_REMNANT_DESTROYED)) continue; 154 155 for (CampaignFleetAPI fleet : system.getFleets()) { 156 if (!fleet.isStationMode()) continue; 157 if (!Factions.REMNANTS.equals(fleet.getFaction().getId())) continue; 158 159 boolean damaged = fleet.getMemoryWithoutUpdate().getBoolean("$damagedStation"); 160 if ((difficulty == 7 || difficulty == 8) && damaged) { 161 stations.add(fleet); 162 } else if (!damaged && difficulty > 8) { 163 stations.add(fleet); 164 } 165 } 166 } 167 return stations; 168 } 169 170 public String getBountyNamePostfix(HubMissionWithBarEvent mission, CustomBountyData data) { 171 return " - Remnant Nexus"; 172 } 173 174 @Override 175 public String getIconName() { 176 return Global.getSettings().getSpriteName("campaignMissions", "remnant_bounty"); 177 } 178 179 @Override 180 public CustomBountyData createBounty(MarketAPI createdAt, HubMissionWithBarEvent mission, int difficulty, Object bountyStage) { 181 CustomBountyData data = new CustomBountyData(); 182 data.difficulty = difficulty; 183 184 185 WeightedRandomPicker<CampaignFleetAPI> picker = new WeightedRandomPicker<CampaignFleetAPI>(mission.getGenRandom()); 186 picker.addAll(getStations(mission, difficulty)); 187 188 data.fleet = picker.pick(); 189 if (data.fleet == null) return null; 190 191 data.system = data.fleet.getStarSystem(); 192 if (data.system == null) return null; 193 194 setRepChangesBasedOnDifficulty(data, difficulty); 195 data.baseReward = CBStats.getBaseBounty(difficulty, CBStats.REMNANT_STATION_MULT, mission); 196 197 return data; 198 } 199 200 201 @Override 202 public int getMaxDifficulty() { 203 return super.getMaxDifficulty(); 204 } 205 206 @Override 207 public int getMinDifficulty() { 208 return 7; 209 } 210 211} 212 213 214 215 216 217