예제 #1
0
        public static void TradeRequests()
        {
            Map currentMap = Find.CurrentMap;
            IncidentWorker_QuestTradeRequest incidentWorker_QuestTradeRequest = (IncidentWorker_QuestTradeRequest)IncidentDefOf.Quest_TradeRequest.Worker;
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Randomly-generated trade requests for map " + currentMap.ToString() + ":");
            stringBuilder.AppendLine();
            for (int i = 0; i < 50; i++)
            {
                SettlementBase settlementBase = IncidentWorker_QuestTradeRequest.RandomNearbyTradeableSettlement(currentMap.Tile);
                if (settlementBase == null)
                {
                    break;
                }
                stringBuilder.AppendLine("Settlement: " + settlementBase.LabelCap);
                TradeRequestComp component = settlementBase.GetComponent <TradeRequestComp>();
                if (incidentWorker_QuestTradeRequest.TryGenerateTradeRequest(component, currentMap))
                {
                    stringBuilder.AppendLine("Duration: " + (component.expiration - Find.TickManager.TicksGame).ToStringTicksToDays("F1"));
                    string str = GenLabel.ThingLabel(component.requestThingDef, null, component.requestCount) + " ($" + (component.requestThingDef.BaseMarketValue * (float)component.requestCount).ToString("F0") + ")";
                    stringBuilder.AppendLine("Request: " + str);
                    string str2 = GenThing.ThingsToCommaList(component.rewards, false, true, -1) + " ($" + (from t in component.rewards
                                                                                                            select t.MarketValue * (float)t.stackCount).Sum().ToString("F0") + ")";
                    stringBuilder.AppendLine("Reward: " + str2);
                }
                else
                {
                    stringBuilder.AppendLine("TryGenerateTradeRequest failed.");
                }
                stringBuilder.AppendLine();
                settlementBase.GetComponent <TradeRequestComp>().Disable();
            }
            Log.Message(stringBuilder.ToString(), false);
        }
예제 #2
0
        public static void TradeRequestsSampled()
        {
            Map currentMap = Find.CurrentMap;
            IncidentWorker_QuestTradeRequest incidentWorker_QuestTradeRequest = (IncidentWorker_QuestTradeRequest)IncidentDefOf.Quest_TradeRequest.Worker;
            Dictionary <ThingDef, int>       counts = new Dictionary <ThingDef, int>();

            for (int i = 0; i < 100; i++)
            {
                SettlementBase settlementBase = IncidentWorker_QuestTradeRequest.RandomNearbyTradeableSettlement(currentMap.Tile);
                if (settlementBase == null)
                {
                    break;
                }
                TradeRequestComp component = settlementBase.GetComponent <TradeRequestComp>();
                if (incidentWorker_QuestTradeRequest.TryGenerateTradeRequest(component, currentMap))
                {
                    if (!counts.ContainsKey(component.requestThingDef))
                    {
                        counts.Add(component.requestThingDef, 0);
                    }
                    Dictionary <ThingDef, int> dictionary;
                    ThingDef requestThingDef;
                    (dictionary = counts)[requestThingDef = component.requestThingDef] = dictionary[requestThingDef] + 1;
                }
                settlementBase.GetComponent <TradeRequestComp>().Disable();
            }
            DebugTables.MakeTablesDialog(from d in DefDatabase <ThingDef> .AllDefs
                                         where counts.ContainsKey(d)
                                         orderby counts[d] descending
                                         select d, new TableDataGetter <ThingDef>("defName", (ThingDef d) => d.defName), new TableDataGetter <ThingDef>("appearance rate in " + 100 + " trade requests", (ThingDef d) => ((float)counts[d] / 100f).ToStringPercent()));
        }
예제 #3
0
        private static bool TryGetRandomAvailableTargetMap(out Map map)
        {
            tmpAvailableMaps.Clear();
            List <Map> maps = Find.Maps;

            foreach (Map potentialTargetMap in maps)
            {
                if (potentialTargetMap.IsPlayerHome && IncidentWorker_QuestTradeRequest.RandomNearbyTradeableSettlement(originTile: potentialTargetMap.Tile) != null)
                {
                    tmpAvailableMaps.Add(item: potentialTargetMap);
                }
            }
            return(tmpAvailableMaps.TryRandomElement(result: out map));
        }
예제 #4
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            if (!TryGetRandomAvailableTargetMap(map: out Map map))
            {
                return(false);
            }
            SettlementBase settlement = IncidentWorker_QuestTradeRequest.RandomNearbyTradeableSettlement(originTile: map.Tile);

            if (settlement != null)
            {
                //TODO: look into making the below dynamic based on requester's biome, faction, pirate outpost vicinity and other stuff.
                ThingCategoryDef thingCategoryDef = DetermineThingCategoryDef();

                string letterToSend  = DetermineLetterToSend(thingCategoryDef: thingCategoryDef);
                int    feeRequest    = Math.Max(val1: Rand.Range(min: 150, max: 300), val2: (int)parms.points);
                string categorylabel = (thingCategoryDef == ThingCategoryDefOf.PlantFoodRaw) ? thingCategoryDef.label + " items" : thingCategoryDef.label;
                ChoiceLetter_ReverseTradeRequest choiceLetterReverseTradeRequest = (ChoiceLetter_ReverseTradeRequest)LetterMaker.MakeLetter(label: this.def.letterLabel, text: letterToSend.Translate(
                                                                                                                                                settlement.Faction.leader.LabelShort,
                                                                                                                                                settlement.Faction.def.leaderTitle,
                                                                                                                                                settlement.Faction.Name,
                                                                                                                                                settlement.Label,
                                                                                                                                                categorylabel,
                                                                                                                                                feeRequest
                                                                                                                                                ).AdjustedFor(p: settlement.Faction.leader), def: this.def.letterDef);

                choiceLetterReverseTradeRequest.title            = "MFI_ReverseTradeRequestTitle".Translate(map.info.parent.Label).CapitalizeFirst();
                choiceLetterReverseTradeRequest.thingCategoryDef = thingCategoryDef;
                choiceLetterReverseTradeRequest.map = map;
                parms.target = map;
                choiceLetterReverseTradeRequest.incidentParms = parms;
                choiceLetterReverseTradeRequest.faction       = settlement.Faction;
                choiceLetterReverseTradeRequest.fee           = feeRequest;
                choiceLetterReverseTradeRequest.StartTimeout(duration: TimeoutTicks);
                choiceLetterReverseTradeRequest.tile = settlement.Tile;
                Find.LetterStack.ReceiveLetter(let: choiceLetterReverseTradeRequest);
                return(true);
            }
            return(false);
        }
예제 #5
0
 protected override bool CanFireNowSub(IncidentParms parms)
 {
     return(base.CanFireNowSub(parms: parms) && TryGetRandomAvailableTargetMap(map: out Map map) &&
            IncidentWorker_QuestTradeRequest.RandomNearbyTradeableSettlement(originTile: map.Tile) != null &&
            CommsConsoleUtility.PlayerHasPoweredCommsConsole(map));
 }