001package com.fs.starfarer.api.impl.campaign.submarkets; 002 003import java.awt.Color; 004 005import com.fs.starfarer.api.Global; 006import com.fs.starfarer.api.Script; 007import com.fs.starfarer.api.campaign.CampaignFleetAPI; 008import com.fs.starfarer.api.campaign.CargoStackAPI; 009import com.fs.starfarer.api.campaign.CoreUIAPI; 010import com.fs.starfarer.api.campaign.econ.SubmarketAPI; 011import com.fs.starfarer.api.fleet.FleetMemberAPI; 012import com.fs.starfarer.api.impl.campaign.ids.Strings; 013import com.fs.starfarer.api.ui.TooltipMakerAPI; 014import com.fs.starfarer.api.util.Highlights; 015import com.fs.starfarer.api.util.Misc; 016 017public class StoragePlugin extends BaseSubmarketPlugin { 018 019 private boolean playerPaidToUnlock = false; 020 021 public void init(SubmarketAPI submarket) { 022 super.init(submarket); 023 } 024 025 public void updateCargoPrePlayerInteraction() { 026 027 } 028 029 @Override 030 public boolean isIllegalOnSubmarket(CargoStackAPI stack, TransferAction action) { 031 if (market.isPlayerOwned()) return false; 032 return super.isIllegalOnSubmarket(stack, action); 033 } 034 035 @Override 036 public boolean isIllegalOnSubmarket(String commodityId, TransferAction action) { 037 if (market.isPlayerOwned()) return false; 038 return super.isIllegalOnSubmarket(commodityId, action); 039 } 040 041 @Override 042 public boolean isIllegalOnSubmarket(FleetMemberAPI member, TransferAction action) { 043 if (market.isPlayerOwned() || 044 (market.getFaction() != null && market.getFaction().isNeutralFaction())) return false; 045 return super.isIllegalOnSubmarket(member, action); 046 } 047 048 public boolean isParticipatesInEconomy() { 049 return false; 050 } 051 052 public float getTariff() { 053 return 0f; 054 } 055 056 @Override 057 public boolean isFreeTransfer() { 058 return true; 059 } 060 061 @Override 062 public String getBuyVerb() { 063 return "Take"; 064 } 065 066 @Override 067 public String getSellVerb() { 068 return "Leave"; 069 } 070 071 public String getIllegalTransferText(CargoStackAPI stack, TransferAction action) { 072 return "Illegal to put into storage here"; 073 } 074 075// @Override 076// public void reportPlayerMarketTransaction(PlayerMarketTransaction transaction) { 077// // do nothing; don't want to adjust market stockpiles since player storage 078// // doesn't affect those 079// // don't need to do this since isParticipatesInEconomy() returns false 080// } 081 082 083 084 public boolean isEnabled(CoreUIAPI ui) { 085 //if (mode == CoreUITradeMode.SNEAK) return false; 086 //return playerPaidToUnlock; 087 return true; 088 } 089 090 public void setPlayerPaidToUnlock(boolean playerPaidToUnlock) { 091 this.playerPaidToUnlock = playerPaidToUnlock; 092 } 093 094 public OnClickAction getOnClickAction(CoreUIAPI ui) { 095 if (playerPaidToUnlock) return OnClickAction.OPEN_SUBMARKET; 096 return OnClickAction.SHOW_TEXT_DIALOG; 097 } 098 099 private int getUnlockCost() { 100 return 5000; 101 } 102 103 private boolean canPlayerAffordUnlock() { 104 CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet(); 105 int credits = (int) playerFleet.getCargo().getCredits().get(); 106 return credits >= getUnlockCost(); 107 } 108 109 public String getDialogText(CoreUIAPI ui) { 110 if (canPlayerAffordUnlock()) { 111 return "Gaining access to storage at this colony requires a one-time fee of " + getUnlockCost() + " credits."; 112 } else { 113 return "Gaining access to storage at this colony requires a one-time fee of " + getUnlockCost() + " credits, which you can't afford."; 114 } 115 } 116 public Highlights getDialogTextHighlights(CoreUIAPI ui) { 117 Highlights h = new Highlights(); 118 h.setText("" + getUnlockCost()); 119 if (canPlayerAffordUnlock()) { 120 h.setColors(Misc.getHighlightColor()); 121 } else { 122 h.setColors(Misc.getNegativeHighlightColor()); 123 } 124 return h; 125 } 126 public DialogOption [] getDialogOptions(CoreUIAPI ui) { 127 if (canPlayerAffordUnlock()) { 128 return new DialogOption [] { 129 new DialogOption("Pay", new Script() { 130 public void run() { 131 CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet(); 132 playerFleet.getCargo().getCredits().subtract(getUnlockCost()); 133 playerPaidToUnlock = true; 134 } 135 }), 136 new DialogOption("Never mind", null) 137 }; 138 } else { 139 return new DialogOption [] { 140 new DialogOption("Never mind", null) 141 }; 142 } 143 } 144 public String getTooltipAppendix(CoreUIAPI ui) { 145// if (!playerPaidToUnlock) { 146// return "Requires a one-time access fee of " + getUnlockCost() + " credits."; 147// } 148 return null; 149 } 150 public Highlights getTooltipAppendixHighlights(CoreUIAPI ui) { 151// String appendix = getTooltipAppendix(ui); 152// if (appendix == null) return null; 153// 154// Highlights h = new Highlights(); 155// h.setText("" + getUnlockCost()); 156// if (canPlayerAffordUnlock()) { 157// h.setColors(Misc.getHighlightColor()); 158// } else { 159// h.setColors(Misc.getNegativeHighlightColor()); 160// } 161// return h; 162 return null; 163 } 164 165 @Override 166 protected void createTooltipAfterDescription(TooltipMakerAPI tooltip, boolean expanded) { 167 168 if (!market.isInEconomy()) return; 169 170 float opad = 10f; 171 float pad = 3f; 172 if (market.isPlayerOwned()) { 173 tooltip.addPara(Misc.getTokenReplaced("$marketName is under your control, and there " + 174 "are no storage fees or expenses.", market.getPrimaryEntity()), opad); 175 return; 176 } 177 178 float f = Misc.getStorageFeeFraction(); 179 int percent = (int) (f * 100f); 180 181 Color h = Misc.getHighlightColor(); 182 183 if (!playerPaidToUnlock) { 184 tooltip.addPara("Requires a one-time access fee of %s, and a monthly fee equal to %s of the " + 185 "base value of the items in storage.", opad, h, 186 "" + getUnlockCost() + Strings.C, "" + percent + "%"); 187 return; 188 } 189 190 int cargoCost = (int) (Misc.getStorageCargoValue(market) * f); 191 int shipCost = (int) (Misc.getStorageShipValue(market) * f); 192 193 if (cargoCost + shipCost > 0) { 194 //tooltip.beginGrid(150, 1); 195 tooltip.addPara("Monthly fees and expenses (%s of base value of stored items):", opad, h, "" + percent + "%"); 196 tooltip.beginGridFlipped(300, 1, 80, 10); 197 int j = 0; 198 tooltip.addToGrid(0, j++, "Ships in storage", Misc.getDGSCredits(shipCost)); 199 tooltip.addToGrid(0, j++, "Cargo in storage", Misc.getDGSCredits(cargoCost)); 200 tooltip.addGrid(pad); 201 } else { 202 tooltip.addPara("Monthly fees and expenses are equal to %s of base value of the stored items.", opad, h, "" + percent + "%"); 203 } 204 } 205 206 207} 208 209 210 211 212