Starsector API
Loading...
Searching...
No Matches
CoreRuleTokenReplacementGeneratorImpl.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign;
2
3import java.util.HashMap;
4import java.util.Map;
5
6import com.fs.starfarer.api.Global;
7import com.fs.starfarer.api.campaign.CampaignFleetAPI;
8import com.fs.starfarer.api.campaign.CustomEntitySpecAPI;
9import com.fs.starfarer.api.campaign.FactionAPI;
10import com.fs.starfarer.api.campaign.RepLevel;
11import com.fs.starfarer.api.campaign.SectorEntityToken;
12import com.fs.starfarer.api.campaign.StarSystemAPI;
13import com.fs.starfarer.api.campaign.econ.MarketAPI;
14import com.fs.starfarer.api.campaign.rules.MemoryAPI;
15import com.fs.starfarer.api.campaign.rules.RuleTokenReplacementGeneratorPlugin;
16import com.fs.starfarer.api.characters.PersonAPI;
17import com.fs.starfarer.api.impl.campaign.ids.Factions;
18import com.fs.starfarer.api.impl.campaign.ids.MemFlags;
19import com.fs.starfarer.api.util.Misc;
20
21public class CoreRuleTokenReplacementGeneratorImpl implements RuleTokenReplacementGeneratorPlugin {
22
23 public Map<String, String> getTokenReplacements(String ruleId, Object entity, Map<String, MemoryAPI> memoryMap) {
24
25 SectorEntityToken target = null;
26 PersonAPI person = null;
27 MarketAPI market = null;
28 FactionAPI faction = null;
29 FactionAPI personFaction = null;
30 if (entity instanceof SectorEntityToken) {
31 target = (SectorEntityToken) entity;
32 market = target.getMarket();
33 faction = target.getFaction();
34 }
35
36 if (entity instanceof CampaignFleetAPI && market == null) {
37 market = Misc.getSourceMarket((CampaignFleetAPI) entity);
38 }
39
40 if (entity instanceof SectorEntityToken) {
41 person = ((SectorEntityToken) entity).getActivePerson();
42 }
43
44 if (person == null) {
45 if (entity instanceof CampaignFleetAPI) {
46 person = ((CampaignFleetAPI) entity).getCommander();
47 } else if (entity instanceof PersonAPI ){
48 person = (PersonAPI) entity; // can't actually happen as entity is always a SectorEntityToken
49 }
50 }
51
52 if (person != null) {
53 personFaction = person.getFaction();
54 }
55
56 CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
57
58 Map<String, String> map = new HashMap<String, String>();
59
60 map.put("$Playername", Global.getSector().getCharacterData().getName());
61 map.put("$playername", Global.getSector().getCharacterData().getName());
62 map.put("$playerName", Global.getSector().getCharacterData().getName());
63 map.put("$PlayerName", Global.getSector().getCharacterData().getName());
64
65 map.put("$playerFirstName", Global.getSector().getCharacterData().getPerson().getName().getFirst());
66 map.put("$playerFirstname", Global.getSector().getCharacterData().getPerson().getName().getFirst());
67 map.put("$playerLastName", Global.getSector().getCharacterData().getPerson().getName().getLast());
68 map.put("$playerLastname", Global.getSector().getCharacterData().getPerson().getName().getLast());
69
70 PersonAPI playerPerson = Global.getSector().getPlayerPerson();
71 String honorific = Global.getSector().getCharacterData().getHonorific();
72 if (playerPerson != null) {
73 if (playerPerson.isMale()) {
74 map.put("$playerSirOrMadam", "sir");
75 map.put("$PlayerSirOrMadam", "Sir");
76
77 map.put("$playerBrotherOrSister", "brother");
78 map.put("$PlayerBrotherOrSister", "Brother");
79
80 map.put("$playerHisOrHer", "his");
81 map.put("$PlayerHisOrHer", "His");
82 map.put("$playerHimOrHer", "him");
83 map.put("$PlayerHimOrHer", "Him");
84 map.put("$playerHeOrShe", "he");
85 map.put("$PlayerHeOrShe", "He");
86 } else {
87 map.put("$playerSirOrMadam", "ma'am");
88 map.put("$PlayerSirOrMadam", "Ma'am");
89
90 map.put("$playerBrotherOrSister", "sister");
91 map.put("$PlayerBrotherOrSister", "Sister");
92
93 map.put("$playerHisOrHer", "her");
94 map.put("$PlayerHisOrHer", "Her");
95 map.put("$playerHimOrHer", "her");
96 map.put("$PlayerHimOrHer", "Her");
97 map.put("$playerHeOrShe", "she");
98 map.put("$PlayerHeOrShe", "She");
99 }
100
101 if (honorific != null && !honorific.isEmpty()) {
102 map.put("$playerSirOrMadam", Misc.lcFirst(honorific));
103 map.put("$PlayerSirOrMadam", honorific);
104
105 if (!Misc.SIR.toLowerCase().equals(honorific.toLowerCase()) &&
106 !Misc.MAAM.toLowerCase().equals(honorific.toLowerCase())) {
107 map.put("$playerBrotherOrSister", "walker");
108 map.put("$PlayerBrotherOrSister", "Walker");
109 }
110 }
111 }
112
113 if (market != null) {
114 //map.put("$market", market.getName());
115 map.put("$marketName", market.getName());
116
117 if (target.getLocation() instanceof StarSystemAPI) {
118 map.put("$marketSystem", ((StarSystemAPI)target.getLocation()).getBaseName() + " star system");
119 } else {
120 map.put("$marketSystem", "hyperspace");
121 }
122
123 MemoryAPI mem = market.getMemoryWithoutUpdate();
124 if (mem.contains(MemFlags.MEMORY_KEY_PLAYER_HOSTILE_ACTIVITY_NEAR_MARKET)) {
125 float expire = mem.getExpire(MemFlags.MEMORY_KEY_PLAYER_HOSTILE_ACTIVITY_NEAR_MARKET);
126 String days = Misc.getAtLeastStringForDays((int) expire);
127 map.put("$playerHostileTimeoutStr", days.toLowerCase());
128 mem.set("$playerHostileTimeoutStr", days.toLowerCase(), 0);
129 }
130 }
131
132 if (target != null) {
133 map.put("$entityName", target.getName());
134 map.put("$fleetName", target.getName().toLowerCase());
135 map.put("$relayName", target.getName());
136
137
138 if (target.getCustomEntityType() != null) {
139 if (target.getCustomEntitySpec() != null) {
140 CustomEntitySpecAPI spec = target.getCustomEntitySpec();
141 map.put("$nameInText", spec.getNameInText());
142 map.put("$shortName", spec.getShortName());
143 map.put("$isOrAre", spec.getIsOrAre());
144 map.put("$aOrAn", spec.getAOrAn());
145 }
146 }
147
148// map.put("$factionEntityPrefix", target.getFaction().getEntityNamePrefix());
149// map.put("$FactionEntityPrefix", Misc.ucFirst(target.getFaction().getEntityNamePrefix()));
150 if (target.getFaction() != null) {
151 String factionName = target.getFaction().getEntityNamePrefix();
152 if (factionName == null || factionName.isEmpty()) {
153 factionName = target.getFaction().getDisplayName();
154 }
155
156 map.put("$factionAOrAn", target.getFaction().getPersonNamePrefixAOrAn());
157
158 map.put("$factionIsOrAre", target.getFaction().getDisplayNameIsOrAre());
159
160 map.put("$faction", factionName);
161 map.put("$ownerFaction", factionName);
162 map.put("$marketFaction", factionName);
163 map.put("$Faction", Misc.ucFirst(factionName));
164 map.put("$OwnerFaction", Misc.ucFirst(factionName));
165 map.put("$MarketFaction", Misc.ucFirst(factionName));
166 map.put("$theFaction", target.getFaction().getDisplayNameWithArticle());
167 map.put("$theOwnerFaction", target.getFaction().getDisplayNameWithArticle());
168 map.put("$theMarketFaction", target.getFaction().getDisplayNameWithArticle());
169 map.put("$TheFaction", Misc.ucFirst(target.getFaction().getDisplayNameWithArticle()));
170 map.put("$TheOwnerFaction", Misc.ucFirst(target.getFaction().getDisplayNameWithArticle()));
171 map.put("$TheMarketFaction", Misc.ucFirst(target.getFaction().getDisplayNameWithArticle()));
172
173 map.put("$factionLong", target.getFaction().getDisplayNameLong());
174 map.put("$FactionLong", Misc.ucFirst(target.getFaction().getDisplayNameLong()));
175 map.put("$theFactionLong", target.getFaction().getDisplayNameLongWithArticle());
176 map.put("$TheFactionLong", Misc.ucFirst(target.getFaction().getDisplayNameLongWithArticle()));
177 }
178 }
179
180 if (target != null) {
181 map.put("$entityName", target.getName());
182 map.put("$fleetName", target.getName().toLowerCase());
183 map.put("$relayName", target.getName());
184
185// map.put("$factionEntityPrefix", target.getFaction().getEntityNamePrefix());
186// map.put("$FactionEntityPrefix", Misc.ucFirst(target.getFaction().getEntityNamePrefix()));
187 if (target.getFaction() != null) {
188 String factionName = target.getFaction().getEntityNamePrefix();
189 if (factionName == null || factionName.isEmpty()) {
190 factionName = target.getFaction().getDisplayName();
191 }
192
193 map.put("$factionIsOrAre", target.getFaction().getDisplayNameIsOrAre());
194
195 map.put("$faction", factionName);
196 map.put("$ownerFaction", factionName);
197 map.put("$marketFaction", factionName);
198 map.put("$Faction", Misc.ucFirst(factionName));
199 map.put("$OwnerFaction", Misc.ucFirst(factionName));
200 map.put("$MarketFaction", Misc.ucFirst(factionName));
201 map.put("$theFaction", target.getFaction().getDisplayNameWithArticle());
202 map.put("$theOwnerFaction", target.getFaction().getDisplayNameWithArticle());
203 map.put("$theMarketFaction", target.getFaction().getDisplayNameWithArticle());
204 map.put("$TheFaction", Misc.ucFirst(target.getFaction().getDisplayNameWithArticle()));
205 map.put("$TheOwnerFaction", Misc.ucFirst(target.getFaction().getDisplayNameWithArticle()));
206 map.put("$TheMarketFaction", Misc.ucFirst(target.getFaction().getDisplayNameWithArticle()));
207
208 map.put("$factionLong", target.getFaction().getDisplayNameLong());
209 map.put("$FactionLong", Misc.ucFirst(target.getFaction().getDisplayNameLong()));
210 map.put("$theFactionLong", target.getFaction().getDisplayNameLongWithArticle());
211 map.put("$TheFactionLong", Misc.ucFirst(target.getFaction().getDisplayNameLongWithArticle()));
212 }
213 }
214
215
216 String shipOrFleet = "fleet";
217 if (playerFleet.getFleetData().getMembersListCopy().size() == 1) {
218 shipOrFleet = "ship";
219 if (playerFleet.getFleetData().getMembersListCopy().get(0).isFighterWing()) {
220 shipOrFleet = "fighter wing";
221 }
222 }
223 map.put("$shipOrFleet", shipOrFleet);
224 map.put("$fleetOrShip", shipOrFleet);
225 map.put("$ShipOrFleet", Misc.ucFirst(shipOrFleet));
226 map.put("$FleetOrShip", Misc.ucFirst(shipOrFleet));
227
228 if (target instanceof CampaignFleetAPI) {
229 CampaignFleetAPI fleet = (CampaignFleetAPI) target;
230 String otherShipOrFleet = "fleet";
231 if (fleet.getFleetData().getMembersListCopy().size() == 1) {
232 shipOrFleet = "ship";
233 if (fleet.getFleetData().getMembersListCopy().get(0).isFighterWing()) {
234 shipOrFleet = "fighter wing";
235 }
236 }
237 map.put("$otherShipOrFleet", otherShipOrFleet);
238
239 map.put("$otherFleetName", fleet.getName().toLowerCase());
240 }
241
242 if (person != null) {
243 if (person.isMale()) {
244 map.put("$hisOrHer", "his");
245 map.put("$HisOrHer", "His");
246 map.put("$himOrHer", "him");
247 map.put("$HimOrHer", "Him");
248 map.put("$heOrShe", "he");
249 map.put("$HeOrShe", "He");
250 map.put("$himOrHerself", "himself");
251 map.put("$HimOrHerself", "Himself");
252 map.put("$manOrWoman", "man");
253 map.put("$ManOrWoman", "Man");
254 map.put("$brotherOrSister", "brother");
255 map.put("$BrotherOrSister", "Brother");
256 map.put("$sirOrMadam", "sir");
257 map.put("$SirOrMadam", "Sir");
258 } else {
259 map.put("$hisOrHer", "her");
260 map.put("$HisOrHer", "Her");
261 map.put("$himOrHer", "her");
262 map.put("$HimOrHer", "Her");
263 map.put("$heOrShe", "she");
264 map.put("$HeOrShe", "She");
265 map.put("$himOrHerself", "herself");
266 map.put("$HimOrHerself", "Herself");
267 map.put("$manOrWoman", "woman");
268 map.put("$ManOrWoman", "Woman");
269 map.put("$brotherOrSister", "sister");
270 map.put("$BrotherOrSister", "Sister");
271 map.put("$sirOrMadam", "ma'am");
272 map.put("$SirOrMadam", "Ma'am");
273 }
274
275 if (person.getRank() != null) {
276 map.put("$personRank", person.getRank().toLowerCase());
277 map.put("$PersonRank", Misc.ucFirst(person.getRank()));
278 }
279
280 if (person.getPost() != null) {
281 map.put("$personPost", person.getPost().toLowerCase());
282 map.put("$PersonPost", Misc.ucFirst(person.getPost()));
283 }
284
285 map.put("$PersonName", person.getName().getFullName());
286 map.put("$personName", person.getName().getFullName());
287 map.put("$personFirstName", person.getName().getFirst());
288 map.put("$personLastName", person.getName().getLast());
289 }
290
291
292 if (faction != null) {
293 float rel = faction.getRelationship(Factions.PLAYER);
294 RepLevel level = RepLevel.getLevelFor(rel);
295 map.put("$relAdjective", level.getDisplayName().toLowerCase());
296 }
297
298 if (personFaction != null) {
299 String factionName = personFaction.getEntityNamePrefix();
300 if (factionName == null || factionName.isEmpty()) {
301 factionName = personFaction.getDisplayName();
302 }
303
304 map.put("$personFactionIsOrAre", personFaction.getDisplayNameIsOrAre());
305
306 map.put("$personFaction", factionName);
307 map.put("$PersonFaction", Misc.ucFirst(factionName));
308 map.put("$thePersonFaction", personFaction.getDisplayNameWithArticle());
309 map.put("$ThePersonFaction", Misc.ucFirst(personFaction.getDisplayNameWithArticle()));
310
311 map.put("$personFactionLong", personFaction.getDisplayNameLong());
312 map.put("$PersonFactionLong", Misc.ucFirst(personFaction.getDisplayNameLong()));
313 map.put("$thePersonFactionLong", personFaction.getDisplayNameLongWithArticle());
314 map.put("$ThePersonFactionLong", Misc.ucFirst(personFaction.getDisplayNameLongWithArticle()));
315 }
316
317 return map;
318 }
319
320}
321
322
323
324
325
326
327
328
329
static SectorAPI getSector()
Definition Global.java:59
Map< String, String > getTokenReplacements(String ruleId, Object entity, Map< String, MemoryAPI > memoryMap)