public override void DoEffect(Pawn user)
        {
            base.DoEffect(user);
            Map map = user.MapHeld;

            if (map.passingShipManager.passingShips.Count >= 5)
            {
                Messages.Message("PolarisOrbitalTraderCouldNotArrival".Translate(), MessageTypeDefOf.NegativeEvent);
                return;
            }
            TraderKindDef traderKindDef = base.parent.TryGetComp <CompOrbitalTraderCaller>().traderKindDef;
            TradeShip     tradeShip     = new TradeShip(traderKindDef);

            if (map.listerBuildings.allBuildingsColonist.Any((Building b) => b.def.IsCommsConsole && b.GetComp <CompPowerTrader>().PowerOn))
            {
                Find.LetterStack.ReceiveLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(new object[]
                {
                    tradeShip.name,
                    tradeShip.def.label
                }), LetterDefOf.PositiveEvent, null);
            }
            map.passingShipManager.AddShip(tradeShip);
            tradeShip.GenerateThings();
            return;
        }
        // Token: 0x06003C5E RID: 15454 RVA: 0x0013ED34 File Offset: 0x0013CF34
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = (Map)parms.target;

            if (map.passingShipManager.passingShips.Count >= 5)
            {
                return(false);
            }
            //	Log.Message("TraderKindDefs with RecruiterExt: " + DefDatabase<TraderKindDef>.AllDefs.Where(x=> x.HasModExtension<RecruiterExt>()).Count());
            TraderKindDef traderKindDef;

            if ((from x in DefDatabase <TraderKindDef> .AllDefs.Where(x => x.stockGenerators.Any(y => y is StockGenerator_Recruits))
                 where this.CanSpawn(map, x)
                 select x).TryRandomElement(out traderKindDef))
            {
                TradeShip tradeShip = new TradeShip(traderKindDef, this.GetFaction(traderKindDef));
                if (map.listerBuildings.allBuildingsColonist.Any((Building b) => b.def.IsCommsConsole && (b.GetComp <CompPowerTrader>() == null || b.GetComp <CompPowerTrader>().PowerOn)))
                {
                    base.SendStandardLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(tradeShip.name, tradeShip.def.label, (tradeShip.Faction == null) ? "TraderArrivalNoFaction".Translate() : "TraderArrivalFromFaction".Translate(tradeShip.Faction.Named("FACTION"))), LetterDefOf.PositiveEvent, parms, LookTargets.Invalid, Array.Empty <NamedArgument>());
                }
                map.passingShipManager.AddShip(tradeShip);
                tradeShip.GenerateThings();
                return(true);
            }
            throw new InvalidOperationException();
        }
        // this is a weird amalgamation between CompDoEffect and IncidentWorker_OrbitalTraderArrival
        public override void DoEffect(Pawn usedBy)
        {
            base.DoEffect(usedBy);

            Map map = usedBy.Map;

            if (map.passingShipManager.passingShips.Count >= 5)
            {
                return;
            }

            if (DefDatabase <TraderKindDef> .AllDefs
                .Where(x => x.orbital)
                .TryRandomElementByWeight(traderDef => traderDef.commonality, out TraderKindDef def))
            {
                TradeShip tradeShip = new TradeShip(def);
                if (map.listerBuildings.allBuildingsColonist.Any((Building b) => b.def.IsCommsConsole && b.GetComp <CompPowerTrader>().PowerOn))
                {
                    Find.LetterStack.ReceiveLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(
                                                       tradeShip.name,
                                                       tradeShip.def.label,
                                                       "TraderArrivalNoFaction".Translate()
                                                       ), LetterDefOf.PositiveEvent, null);
                }
                map.passingShipManager.AddShip(tradeShip);
                tradeShip.GenerateThings();
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = (Map)parms.target;

            if (map.passingShipManager.passingShips.Count >= 5)
            {
                return(false);
            }
            TraderKindDef def;

            if ((from x in DefDatabase <TraderKindDef> .AllDefs
                 where x.orbital
                 select x).TryRandomElementByWeight((TraderKindDef traderDef) => traderDef.CalculatedCommonality, out def))
            {
                TradeShip tradeShip = new TradeShip(def);
                if (map.listerBuildings.allBuildingsColonist.Any((Building b) => b.def.IsCommsConsole && b.GetComp <CompPowerTrader>().PowerOn))
                {
                    var text = "TraderArrival".Translate(tradeShip.name, tradeShip.def.label);

                    if (Quote != null)
                    {
                        text += "\n\n";
                        text += Quote;
                    }

                    Find.LetterStack.ReceiveLetter(tradeShip.def.LabelCap, text, LetterDefOf.PositiveEvent, null);
                }
                map.passingShipManager.AddShip(tradeShip);
                tradeShip.GenerateThings();
                return(true);
            }
            throw new InvalidOperationException();
        }
Example #5
0
        static void addOptions(Map map, List <FloatMenuOption> opts)
        {
            if (orbitalTraders.Count == 0)
            {
                foreach (var d in DefDatabase <TraderKindDef> .AllDefsListForReading)
                {
                    if (d.orbital)
                    {
                        orbitalTraders.Add(d);
                    }
                }
                orbitalTraders.Sort(delegate(TraderKindDef d1, TraderKindDef d2)
                {
                    return(d1.label.CompareTo(d2.label));
                });
            }

            if (Settings.Cost > 0)
            {
                int found = 0;
                foreach (Thing t in TradeUtility.AllLaunchableThingsForTrade(map))
                {
                    if (t.def == ThingDefOf.Silver)
                    {
                        found += t.stackCount;
                        if (found > Settings.Cost)
                        {
                            break;
                        }
                    }
                }
                if (found < Settings.Cost)
                {
                    opts.Add(new FloatMenuOption("CallTradeShips.NotEnoughSilver".Translate(found, Settings.Cost), null));
                    return;
                }
            }

            foreach (var d in orbitalTraders)
            {
                opts.Add(new FloatMenuOption(getMenuLabel(d), delegate()
                {
                    TradeShip tradeShip = new TradeShip(d);
                    if (map.listerBuildings.allBuildingsColonist.Any((Building b) => b.def.IsCommsConsole && b.GetComp <CompPowerTrader>().PowerOn))
                    {
                        TradeUtility.LaunchSilver(map, Settings.Cost);
                        Find.LetterStack.ReceiveLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(
                                                           tradeShip.name,
                                                           tradeShip.def.label,
                                                           "TraderArrivalNoFaction".Translate()
                                                           ), LetterDefOf.PositiveEvent, null);
                    }
                    map.passingShipManager.AddShip(tradeShip);
                    tradeShip.GenerateThings();
                }, MenuOptionPriority.Low));
            }
        }
        public static void SummonTradeShip()
        {
            Map map = Find.CurrentMap;

            if (map == null)
            {
                return;
            }
            if (DefDatabase <TraderKindDef> .AllDefs.Where((TraderKindDef x) => CanSpawn(map, x)).TryRandomElementByWeight((TraderKindDef traderDef) => traderDef.CalculatedCommonality, out var result))
            {
                TradeShip tradeShip = new TradeShip(result, GetFaction(result));
                Messages.Message(new Message("Debug: Trade ship arrived: " + tradeShip.def.LabelCap, MessageTypeDefOf.PositiveEvent));
                //SendStandardLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(tradeShip.name, tradeShip.def.label, (tradeShip.Faction == null) ? "TraderArrivalNoFaction".Translate() : "TraderArrivalFromFaction".Translate(tradeShip.Faction.Named("FACTION"))), LetterDefOf.PositiveEvent, parms, LookTargets.Invalid);
                map.passingShipManager.AddShip(tradeShip);
                tradeShip.GenerateThings();
            }
        }
Example #7
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            var map = (Map)parms.target;

            if (map.passingShipManager.passingShips.Count >= MaxShips)
            {
                return(false);
            }

            var tradeShip = new TradeShip(RSDefOf.RSSRSTradeShip);

            if (map.listerBuildings.allBuildingsColonist.Any((Building b) => b.def.IsCommsConsole && (b.GetComp <CompPowerTrader>() == null || b.GetComp <CompPowerTrader>().PowerOn)))
            {
                base.SendStandardLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(tradeShip.name, tradeShip.def.label, (tradeShip.Faction == null) ? "TraderArrivalNoFaction".Translate() : "TraderArrivalFromFaction".Translate(tradeShip.Faction.Named("FACTION"))), LetterDefOf.PositiveEvent, parms, LookTargets.Invalid, Array.Empty <NamedArgument>());
            }
            map.passingShipManager.AddShip(tradeShip);
            tradeShip.GenerateThings();
            return(true);
        }
        public override void DoEffect(Pawn user)
        {
            base.DoEffect(user);
            Map map = user.MapHeld;

            if (map.passingShipManager.passingShips.Count >= 5)
            {
                Messages.Message("PolarisOrbitalTraderCouldNotArrival".Translate(), MessageTypeDefOf.NegativeEvent);
                return;
            }
            TraderKindDef traderKindDef = base.parent.TryGetComp <CompOrbitalTraderCaller>().traderKindDef;
            TradeShip     tradeShip     = new TradeShip(traderKindDef, this.GetFaction(traderKindDef));

            if (map.listerBuildings.allBuildingsColonist.Any((Building b) => b.def.IsCommsConsole && (b.GetComp <CompPowerTrader>() == null || b.GetComp <CompPowerTrader>().PowerOn)))
            {
                //Find.LetterStack.ReceiveLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(tradeShip.name, tradeShip.def.label), LetterDefOf.PositiveEvent, null);
                //Find.LetterStack.ReceiveLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(tradeShip.name, tradeShip.def.label, "TraderArrivalNoFaction".Translate()), LetterDefOf.PositiveEvent, null);
                Find.LetterStack.ReceiveLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(tradeShip.name, tradeShip.def.label, (tradeShip.Faction == null) ? "TraderArrivalNoFaction".Translate() : "TraderArrivalFromFaction".Translate(tradeShip.Faction.Named("FACTION"))), LetterDefOf.PositiveEvent, null);
            }
            map.passingShipManager.AddShip(tradeShip);
            tradeShip.GenerateThings();
            return;
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).FailOnDespawnedOrNull(TargetIndex.A));

            yield return(new Toil
            {
                initAction = delegate
                {
                    var job = this.job as Job_CallTradeShip;
                    if (job == null)
                    {
                        Log.Error("CallTradeShips: Job is not of type Job_CallTradeShip.");
                        return;
                    }

                    ThingWithComps twc = job.targetA.Thing as ThingWithComps;
                    if (twc?.def?.IsCommsConsole == false)
                    {
                        Log.Error("CallTradeShips: Target is not a CommsConsole");
                        return;
                    }

                    if (!Util.HasEnoughSilver(twc.Map, out int found))
                    {
                        Log.Warning("Not enough silver");
                        return;
                    }
                    TradeUtility.LaunchSilver(twc.Map, Settings.Cost);

                    if (job.TraderKind == TraderKindEnum.Orbital)
                    {
                        if (twc.GetComp <CompPowerTrader>()?.PowerOn == true)
                        {
                            TradeShip tradeShip = new TradeShip(job.TraderKindDef);
                            twc.Map.passingShipManager.AddShip(tradeShip);
                            tradeShip.GenerateThings();
                            Find.LetterStack.ReceiveLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(tradeShip.name, tradeShip.def.label, "TraderArrivalNoFaction".Translate()), LetterDefOf.PositiveEvent, null);
                        }
                    }
                    else if (job.TraderKind == TraderKindEnum.Lander)
                    {
                        foreach (var id in DefDatabase <IncidentDef> .AllDefsListForReading)
                        {
                            if (id.Worker is IncidentWorker_OrbitalTraderArrival)
                            {
                                if (id.Worker.TryExecute(new IncidentParms()
                                {
                                    target = twc.Map
                                }))
                                {
                                    return;
                                }
                                break;
                            }
                        }
                        Log.Error("CallTradShips failed to create trade ship from mod TraderShips");
                        return;
                    }
                    else
                    {
                        Log.Error("CallTradeShips: Unknown TraderKindEnum: " + job.TraderKind);
                        return;
                    }
                }
            });