001package com.fs.starfarer.api.impl.campaign.rulecmd; 002 003import java.util.List; 004import java.util.Map; 005 006import com.fs.starfarer.api.Global; 007import com.fs.starfarer.api.campaign.CommDirectoryEntryAPI; 008import com.fs.starfarer.api.campaign.CommDirectoryEntryAPI.EntryType; 009import com.fs.starfarer.api.campaign.InteractionDialogAPI; 010import com.fs.starfarer.api.campaign.RuleBasedDialog; 011import com.fs.starfarer.api.campaign.rules.MemoryAPI; 012import com.fs.starfarer.api.characters.ImportantPeopleAPI.PersonDataAPI; 013import com.fs.starfarer.api.characters.PersonAPI; 014import com.fs.starfarer.api.util.Misc.Token; 015 016/** 017 * Person must have been added to SectorAPI.getImportantPeople(). 018 * 019 * BeginConversation <person id> <minimal mode (no faction shown), optional> <show relationship bar> 020 * 021 * <person id> can also be POST:<post id> which will find the first person in the comm directory with that post. 022 */ 023public class BeginConversation extends BaseCommandPlugin { 024 025 public boolean execute(String ruleId, InteractionDialogAPI dialog, List<Token> params, Map<String, MemoryAPI> memoryMap) { 026 if (dialog == null) return false; 027 028 String id = null; 029 PersonAPI person = null; 030 031 Object o = params.get(0).getObject(memoryMap); 032 if (o instanceof PersonAPI) { 033 person = (PersonAPI) o; 034 } else { 035 id = params.get(0).getStringWithTokenReplacement(ruleId, dialog, memoryMap); 036 } 037 038 boolean minimal = false; 039 boolean showRel = true; 040 if (params.size() > 1) { 041 minimal = params.get(1).getBoolean(memoryMap); 042 } 043 if (params.size() > 2) { 044 showRel = params.get(2).getBoolean(memoryMap); 045 } 046 047 if (person == null) { 048 PersonDataAPI data = Global.getSector().getImportantPeople().getData(id); 049 050 if (data == null) { 051 if (dialog.getInteractionTarget() != null && dialog.getInteractionTarget().getMarket() != null) { 052 if (id.startsWith("POST:")) { 053 String postId = id.substring(id.indexOf(":") + 1); 054 for (CommDirectoryEntryAPI entry : dialog.getInteractionTarget().getMarket().getCommDirectory().getEntriesCopy()) { 055 if (entry.getType() == EntryType.PERSON && entry.getEntryData() instanceof PersonAPI) { 056 PersonAPI curr = (PersonAPI) entry.getEntryData(); 057 if (postId.equals(curr.getPostId())) { 058 person = curr; 059 break; 060 } 061 } 062 } 063 } else { 064 for (PersonAPI curr : dialog.getInteractionTarget().getMarket().getPeopleCopy()) { 065 if (curr.getId().equals(id)) { 066 person = curr; 067 break; 068 } 069 } 070 if (person == null) { 071 CommDirectoryEntryAPI entry = dialog.getInteractionTarget().getMarket().getCommDirectory().getEntryForPerson(id); 072 if (entry != null) { 073 person = (PersonAPI) entry.getEntryData(); 074 } 075 } 076 } 077 } 078 } else { 079 person = data.getPerson(); 080 } 081 } 082 083 if (person == null) return false; 084 085 dialog.getInteractionTarget().setActivePerson(person); 086 ((RuleBasedDialog) dialog.getPlugin()).notifyActivePersonChanged(); 087 dialog.getVisualPanel().showPersonInfo(person, minimal, showRel); 088 089 return true; 090 } 091 092} 093 094 095 096 097 098 099 100 101 102