001package com.fs.starfarer.api.impl.campaign.rulecmd.salvage.special; 002 003import com.fs.starfarer.api.Global; 004import com.fs.starfarer.api.campaign.CampaignFleetAPI; 005import com.fs.starfarer.api.campaign.InteractionDialogAPI; 006import com.fs.starfarer.api.characters.PersonAPI; 007import com.fs.starfarer.api.impl.campaign.ids.Commodities; 008import com.fs.starfarer.api.impl.campaign.rulecmd.AddRemoveCommodity; 009import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.SalvageSpecialInteraction.SalvageSpecialData; 010import com.fs.starfarer.api.impl.campaign.rulecmd.salvage.SalvageSpecialInteraction.SalvageSpecialPlugin; 011 012public class SleeperPodsSpecial extends BaseSalvageSpecial { 013 014 public static final String OPEN = "open"; 015 public static final String NOT_NOW = "not_now"; 016 017 public static enum SleeperSpecialType { 018 CREW, 019 MARINES, 020 OFFICER, 021 ADMIN, 022 ORGANS, 023 } 024// public static enum SleeperSpecialQuantity { 025// LOW, 026// MEDIUM, 027// HIGH, 028// } 029 030 public static class SleeperPodsSpecialData implements SalvageSpecialData { 031 public SleeperSpecialType type; 032 //public SleeperSpecialQuantity quantity; 033 public int min, max; 034 public PersonAPI officer; 035 public SleeperPodsSpecialData(SleeperSpecialType type, PersonAPI officer) { 036 this.type = type; 037 this.officer = officer; 038 min = max = 1; 039 } 040 public SleeperPodsSpecialData(SleeperSpecialType type, int min, int max) { 041 this.type = type; 042 this.min = min; 043 this.max = max; 044 } 045 046 public SalvageSpecialPlugin createSpecialPlugin() { 047 return new SleeperPodsSpecial(); 048 } 049 } 050 051 private SleeperPodsSpecialData data; 052 053 private int quantity = 1; 054 055 public SleeperPodsSpecial() { 056 } 057 058 @Override 059 public void init(InteractionDialogAPI dialog, Object specialData) { 060 super.init(dialog, specialData); 061 062 data = (SleeperPodsSpecialData) specialData; 063 064// if (data.quantity != null) { 065// switch (data.quantity) { 066// case LOW: 067// quantity = random.nextInt(10) + 5; 068// break; 069// case MEDIUM: 070// quantity = random.nextInt(20) + 10; 071// break; 072// case HIGH: 073// quantity = random.nextInt(50) + 25; 074// break; 075// } 076// } 077 quantity = data.min + random.nextInt(data.max - data.min + 1); 078 079 if (data.type == SleeperSpecialType.ORGANS) { 080 //quantity *= 0.5f; 081 if (quantity < 1) quantity = 1; 082 } 083 084 CampaignFleetAPI player = Global.getSector().getPlayerFleet(); 085 086 int crewBerths = (int) (player.getCargo().getMaxPersonnel() - player.getCargo().getTotalPersonnel()); 087// int officerBerths = (int) (Global.getSector().getPlayerPerson().getStats().getOfficerNumber().getModifiedValue() - 088// player.getFleetData().getOfficersCopy().size()); 089 if (crewBerths < 0) crewBerths = 0; 090// if (officerBerths < 0) officerBerths = 0; 091 092 SleeperSpecialType type = data.type; 093 094 if (type == SleeperSpecialType.CREW) quantity = Math.min(crewBerths, quantity); 095 if (type == SleeperSpecialType.MARINES) quantity = Math.min(crewBerths, quantity); 096 //if (type == SleeperSpecialType.OFFICER) quantity = Math.min(officerBerths, quantity); 097 if (type == SleeperSpecialType.ADMIN || type == SleeperSpecialType.OFFICER) quantity = 1; 098 099 switch (type) { 100 case CREW: 101 initCrew(); 102 break; 103 case MARINES: 104 initMarines(); 105 break; 106 case OFFICER: 107 initOfficer(); 108 break; 109 case ADMIN: 110 initOfficer(); 111 break; 112 case ORGANS: 113 initOrgans(); 114 break; 115 } 116 } 117 118 119 protected void initCrew() { 120 if (quantity <= 0) { 121 initNothing(); 122 } else { 123 addText("While making a preliminary assessment, your salvage crews " + 124 "find some occupied sleeper pods still running on backup power."); 125 126 options.clearOptions(); 127 options.addOption("Attempt to open the pods", OPEN); 128 options.addOption("Not now", NOT_NOW); 129 } 130 } 131 132 protected void initMarines() { 133 if (quantity <= 0) { 134 initNothing(); 135 } else { 136 addText("While making a preliminary assessment, your salvage crews " + 137 "find some occupied mil-grade sleeper pods still running on backup power."); 138 139 options.clearOptions(); 140 options.addOption("Attempt to open the pods", OPEN); 141 options.addOption("Not now", NOT_NOW); 142 } 143 } 144 145 protected void initOfficer() { 146 if (quantity <= 0) { 147 initNothing(); 148 } else { 149 addText("While making a preliminary assessment, your salvage crews " + 150 "find a single occupied sleeper pod still running on backup power."); 151 152 options.clearOptions(); 153 options.addOption("Attempt to open the pod", OPEN); 154 options.addOption("Not now", NOT_NOW); 155 } 156 157 } 158 159 protected void initOrgans() { 160 if (quantity <= 0) { 161 initNothing(); 162 } else { 163 addText("While making a preliminary assessment, your salvage crews " + 164 "find some occupied sleeper pods still running on backup power."); 165 166 options.clearOptions(); 167 options.addOption("Attempt to open the pods", OPEN); 168 options.addOption("Not now", NOT_NOW); 169 } 170 171 } 172 173 174 @Override 175 public void optionSelected(String optionText, Object optionData) { 176 if (OPEN.equals(optionData)) { 177 178 switch (data.type) { 179 case CREW: 180 addText("One by one, the pods begin to open as the thawing process completes. " + 181 "Most of the occupants come through alive, if somewhat dazed."); 182 183 playerFleet.getCargo().addCommodity(Commodities.CREW, quantity); 184 AddRemoveCommodity.addCommodityGainText(Commodities.CREW, quantity, text); 185 186 break; 187 case MARINES: 188 addText("One by one, the pods begin to open as the thawing process completes. " + 189 "Most of the occupants come through alive, if somewhat dazed."); 190 191 playerFleet.getCargo().addCommodity(Commodities.MARINES, quantity); 192 AddRemoveCommodity.addCommodityGainText(Commodities.MARINES, quantity, text); 193 194 break; 195 case OFFICER: 196 addText("The thawing process completes, and the pod opens. " + 197 "It contains an experienced officer, who joins you out of gratitude for being rescued."); 198 199 playerFleet.getFleetData().addOfficer(data.officer); 200 AddRemoveCommodity.addOfficerGainText(data.officer, text); 201 CryopodOfficerGen.incrNumExceptionalCreated(); 202 break; 203 case ADMIN: 204 addText("The thawing process completes, and the pod opens. " + 205 "It contains an experienced planetary administrator, who joins you out of gratitude for being rescued."); 206 207 Global.getSector().getCharacterData().addAdmin(data.officer); 208 AddRemoveCommodity.addAdminGainText(data.officer, text); 209 break; 210 case ORGANS: 211 addText("One by one, the pods begin to open as the thawing process completes. " + 212 "Unfortunately, it's been too long, or something went wrong along the way, and there are no survivors - at least, not with any brain activity."); 213 214 playerFleet.getCargo().addCommodity(Commodities.ORGANS, quantity); 215 AddRemoveCommodity.addCommodityGainText(Commodities.ORGANS, quantity, text); 216 break; 217 } 218 219 220 setDone(true); 221 setShowAgain(false); 222 } else if (NOT_NOW.equals(optionData)) { 223 setDone(true); 224 setEndWithContinue(false); 225 setShowAgain(true); 226 } 227 } 228 229 230 231} 232 233