Starsector API
Loading...
Searching...
No Matches
BeginConversation.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.rulecmd;
2
3import java.util.List;
4import java.util.Map;
5
6import com.fs.starfarer.api.Global;
7import com.fs.starfarer.api.campaign.CommDirectoryEntryAPI;
8import com.fs.starfarer.api.campaign.CommDirectoryEntryAPI.EntryType;
9import com.fs.starfarer.api.campaign.InteractionDialogAPI;
10import com.fs.starfarer.api.campaign.RuleBasedDialog;
11import com.fs.starfarer.api.campaign.rules.MemoryAPI;
12import com.fs.starfarer.api.characters.ImportantPeopleAPI.PersonDataAPI;
13import com.fs.starfarer.api.characters.PersonAPI;
14import com.fs.starfarer.api.util.Misc.Token;
15
24
25 public boolean execute(String ruleId, InteractionDialogAPI dialog, List<Token> params, Map<String, MemoryAPI> memoryMap) {
26 if (dialog == null) return false;
27
28 String id = null;
29 PersonAPI person = null;
30
31 Object o = params.get(0).getObject(memoryMap);
32 if (o instanceof PersonAPI) {
33 person = (PersonAPI) o;
34 } else {
35 id = params.get(0).getStringWithTokenReplacement(ruleId, dialog, memoryMap);
36 }
37
38 boolean minimal = false;
39 boolean showRel = true;
40 if (params.size() > 1) {
41 minimal = params.get(1).getBoolean(memoryMap);
42 }
43 if (params.size() > 2) {
44 showRel = params.get(2).getBoolean(memoryMap);
45 }
46
47 if (person == null) {
48 PersonDataAPI data = Global.getSector().getImportantPeople().getData(id);
49
50 if (data == null) {
51 if (dialog.getInteractionTarget() != null && dialog.getInteractionTarget().getMarket() != null) {
52 if (id.startsWith("POST:")) {
53 String postId = id.substring(id.indexOf(":") + 1);
54 for (CommDirectoryEntryAPI entry : dialog.getInteractionTarget().getMarket().getCommDirectory().getEntriesCopy()) {
55 if (entry.getType() == EntryType.PERSON && entry.getEntryData() instanceof PersonAPI) {
56 PersonAPI curr = (PersonAPI) entry.getEntryData();
57 if (postId.equals(curr.getPostId())) {
58 person = curr;
59 break;
60 }
61 }
62 }
63 } else {
64 for (PersonAPI curr : dialog.getInteractionTarget().getMarket().getPeopleCopy()) {
65 if (curr.getId().equals(id)) {
66 person = curr;
67 break;
68 }
69 }
70 if (person == null) {
71 CommDirectoryEntryAPI entry = dialog.getInteractionTarget().getMarket().getCommDirectory().getEntryForPerson(id);
72 if (entry != null) {
73 person = (PersonAPI) entry.getEntryData();
74 }
75 }
76 }
77 }
78 } else {
79 person = data.getPerson();
80 }
81 }
82
83 if (person == null) return false;
84
85 dialog.getInteractionTarget().setActivePerson(person);
86 ((RuleBasedDialog) dialog.getPlugin()).notifyActivePersonChanged();
87 dialog.getVisualPanel().showPersonInfo(person, minimal, showRel);
88
89 return true;
90 }
91
92}
93
94
95
96
97
98
99
100
101
102
static SectorAPI getSector()
Definition Global.java:59
boolean execute(String ruleId, InteractionDialogAPI dialog, List< Token > params, Map< String, MemoryAPI > memoryMap)