Ejemplo n.º 1
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));
            }
        }
Ejemplo n.º 2
0
 public virtual IEnumerable <Thing> ColonyThingsWillingToBuy(Pawn playerNegotiator)
 {
     foreach (Thing item in TradeUtility.AllLaunchableThingsForTrade(Find.CurrentMap))
     {
         if (item.def == BankDefOf.BankNote || item.def == ThingDefOf.Silver)
         {
             yield return(item);
         }
     }
 }
Ejemplo n.º 3
0
 public IEnumerable <Thing> ColonyThingsWillingToBuy(Pawn playerNegotiator)
 {
     //The result is a list of things that the pawn HAS, that are in a sellable position and that the trader accepts.
     if (playerNegotiator != null)
     {
         if (playerNegotiator.Map != null)
         {
             return(TradeUtility.AllLaunchableThingsForTrade(playerNegotiator.Map).Where(t => TraderKind.WillTrade(t.def)));
         }
         else if (playerNegotiator.GetCaravan() != null)
         {
             return(playerNegotiator.GetCaravan().trader.Goods.Where(t => TraderKind.WillTrade(t.def)));
         }
     }
     return(new List <Thing>());
 }
        private void GenerateDemands(List <Thing> demand, float silver)
        {
            for (int i = 0; i < TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(x => (x.stackCount * x.MarketValue) < silver).Count(); i++)
            {
                Thing thing = TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).RandomElementByWeight(x => x.MarketValue);

                if (demand.Contains(thing) || GenThing.GetMarketValue(demand) + thing.MarketValue * thing.stackCount > 1.3f * silver)
                {
                    continue;
                }
                demand.Add(thing);
                if (GenThing.GetMarketValue(demand) > silver)
                {
                    break;
                }
            }
            if (GenThing.GetMarketValue(demand) == 0 || GenThing.GetMarketValue(demand) < silver * 0.75)
            {
                Thing min = TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => !demand.Contains(t)).First();
                foreach (Thing t in TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap))
                {
                    if (t != min && !demand.Contains(t) && t.MarketValue * t.stackCount < min.MarketValue * min.stackCount)
                    {
                        if (t.MarketValue * t.stackCount < silver)
                        {
                            demand.Add(t);
                            if (GenThing.GetMarketValue(demand) >= silver)
                            {
                                break;
                            }
                        }
                        min = t;
                    }
                }
                if (GenThing.GetMarketValue(demand) < silver)
                {
                    demand.Add(min);
                }
            }
        }
Ejemplo n.º 5
0
        public IEnumerable <Thing> ColonyThingsWillingToBuy(Pawn playerNegotiator)
        {
            List <Thing> thingsWillingToBuy = new List <Thing>();

            foreach (Thing thing in TradeUtility.AllLaunchableThingsForTrade(this.Map))
            {
                thingsWillingToBuy.Add(thing);
            }
            foreach (IntVec3 cell in this.OccupiedRect().Cells)
            {
                foreach (Thing thing in cell.GetThingList(this.Map))
                {
                    if ((TradeUtility.EverPlayerSellable(thing.def)) &&
                        this.TraderKind.WillTrade(thing.def) &&
                        (thingsWillingToBuy.Contains(thing) == false))    // Do not count thing twice.
                    {
                        thingsWillingToBuy.Add(thing);
                    }
                }
            }
            return(thingsWillingToBuy);
        }
Ejemplo n.º 6
0
        public static bool CanUpgradeRelations(Faction faction, List <Thing> requirements, int level)
        {
            requirements.Clear();
            Thing gold = ThingMaker.MakeThing(ThingDefOf.Gold);

            switch (level)
            {
            case 0:
                gold.stackCount = 375;
                requirements.Add(gold);

                if (TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where <Thing>(t => t.def == gold.def).Sum <Thing>(t => t.stackCount) >= gold.stackCount)
                {
                    return(true);
                }
                return(false);

            case 1:
                gold.stackCount = 500;
                requirements.Add(gold);
                if (TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == gold.def).Sum(t => t.stackCount) >= gold.stackCount)
                {
                    return(true);
                }
                return(false);

            case 2:
                gold.stackCount = 1000;
                requirements.Add(gold);
                if (TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == gold.def).Sum(t => t.stackCount) >= gold.stackCount)
                {
                    return(true);
                }
                return(false);

            default:
                return(false);
            }
        }
Ejemplo n.º 7
0
        public static bool HasEnoughSilver(Map map, out int found)
        {
            found = 0;

            int need = Settings.Cost;

            if (need == 0)
            {
                return(true);
            }

            foreach (Thing t in TradeUtility.AllLaunchableThingsForTrade(map))
            {
                if (t.def == ThingDefOf.Silver)
                {
                    found += t.stackCount;
                    if (found >= Settings.Cost)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
 private static int AmountSendableSilver(Map map)
 {
     return((from t in TradeUtility.AllLaunchableThingsForTrade(map)
             where t.def == ThingDefOf.Silver
             select t).Sum((Thing t) => t.stackCount));
 }
Ejemplo n.º 9
0
        public static bool CanUpgradeComponents(Faction faction, List <Thing> requirements, int level)
        {
            requirements.Clear();
            Thing silver = ThingMaker.MakeThing(ThingDefOf.Silver);
            Thing steel  = ThingMaker.MakeThing(ThingDefOf.Steel);

            switch (level)
            {
            case 0:
                silver.stackCount = 2000;
                requirements.Add(silver);
                steel.stackCount = 1600;
                requirements.Add(steel);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount) && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == steel.def).Sum(t => t.stackCount) >= steel.stackCount)
                {
                    return(true);
                }
                return(false);

            case 1:
                silver.stackCount = 4500;
                requirements.Add(silver);
                steel.stackCount = 2500;
                requirements.Add(steel);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount) && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == steel.def).Sum(t => t.stackCount) >= steel.stackCount)
                {
                    return(true);
                }
                return(false);

            case 2:
                silver.stackCount = 7000;
                requirements.Add(silver);
                steel.stackCount = 4000;
                requirements.Add(steel);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount) && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == steel.def).Sum(t => t.stackCount) >= steel.stackCount)
                {
                    return(true);
                }
                return(false);

            default:
                return(false);
            }
        }
Ejemplo n.º 10
0
        public static bool CanUpgradeFood(Faction faction, List <Thing> requirements, int level)
        {
            requirements.Clear();
            Thing silver = ThingMaker.MakeThing(ThingDefOf.Silver);
            Thing hay    = ThingMaker.MakeThing(ThingDefOf.Hay);

            switch (level)
            {
            case 0:
                silver.stackCount = 250;
                requirements.Add(silver);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount))
                {
                    return(true);
                }
                return(false);

            case 1:
                silver.stackCount = 500;
                requirements.Add(silver);
                hay.stackCount = 300;
                requirements.Add(hay);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount) && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == hay.def).Sum(t => t.stackCount) >= hay.stackCount)
                {
                    return(true);
                }
                return(false);

            case 2:
                silver.stackCount = 1350;
                requirements.Add(silver);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount))
                {
                    return(true);
                }
                return(false);

            default:
                return(false);
            }
        }
Ejemplo n.º 11
0
        public static bool CanUpgradeProstheticslabs(Faction faction, List <Thing> requirements, int level)
        {
            requirements.Clear();
            Thing silver      = ThingMaker.MakeThing(ThingDefOf.Silver);
            Thing steel       = ThingMaker.MakeThing(ThingDefOf.Steel);
            Thing comp        = ThingMaker.MakeThing(ThingDefOf.ComponentIndustrial);
            Thing compAdvence = ThingMaker.MakeThing(ThingDefOf.ComponentSpacer);

            switch (level)
            {
            case 0:
                silver.stackCount = 2000;
                requirements.Add(silver);
                steel.stackCount = 800;
                requirements.Add(steel);
                comp.stackCount = 30;
                requirements.Add(comp);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount) && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == steel.def).Sum(t => t.stackCount) >= steel.stackCount && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == comp.def).Sum(t => t.stackCount) >= comp.stackCount)
                {
                    return(true);
                }
                return(false);

            case 1:
                silver.stackCount = 4500;
                requirements.Add(silver);
                steel.stackCount = 2000;
                requirements.Add(steel);
                compAdvence.stackCount = 15;
                requirements.Add(comp);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount) && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == steel.def).Sum(t => t.stackCount) >= steel.stackCount && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == compAdvence.def).Sum(t => t.stackCount) >= compAdvence.stackCount)
                {
                    return(true);
                }
                return(false);

            case 2:
                silver.stackCount = 7000;
                requirements.Add(silver);
                steel.stackCount = 2000;
                requirements.Add(steel);
                compAdvence.stackCount = 30;
                requirements.Add(comp);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount) && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == steel.def).Sum(t => t.stackCount) >= steel.stackCount && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == compAdvence.def).Sum(t => t.stackCount) >= compAdvence.stackCount)
                {
                    return(true);
                }
                return(false);

            case 3:
                silver.stackCount = 10000;
                requirements.Add(silver);
                steel.stackCount = 2000;
                requirements.Add(steel);
                compAdvence.stackCount = 50;
                requirements.Add(comp);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount) && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == steel.def).Sum(t => t.stackCount) >= steel.stackCount && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == compAdvence.def).Sum(t => t.stackCount) >= compAdvence.stackCount)
                {
                    return(true);
                }
                return(false);

            default:
                return(false);
            }
        }
Ejemplo n.º 12
0
        public static bool CanUpgradeDruglabs(Faction faction, List <Thing> requirements, int level)
        {
            requirements.Clear();
            Thing silver    = ThingMaker.MakeThing(ThingDefOf.Silver);
            Thing hops      = ThingMaker.MakeThing(ThingCategoryDefOf.PlantMatter.childThingDefs.Find(x => x.defName == "RawHops"));
            Thing smokeleaf = ThingMaker.MakeThing(ThingCategoryDefOf.PlantMatter.childThingDefs.Find(x => x.defName == "SmokeleafLeaves"));
            Thing psyLeaves = ThingMaker.MakeThing(ThingCategoryDefOf.PlantMatter.childThingDefs.Find(x => x.defName == "PsychoidLeaves"));

            switch (level)
            {
            case 0:
                silver.stackCount = 1000;
                requirements.Add(silver);
                hops.stackCount = 200;
                requirements.Add(hops);
                smokeleaf.stackCount = 200;
                requirements.Add(smokeleaf);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount) && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == hops.def).Sum(t => t.stackCount) >= hops.stackCount && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == smokeleaf.def).Sum(t => t.stackCount) >= smokeleaf.stackCount)
                {
                    return(true);
                }
                return(false);

            case 1:
                silver.stackCount = 4500;
                requirements.Add(silver);
                psyLeaves.stackCount = 150;
                requirements.Add(psyLeaves);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount) && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == psyLeaves.def).Sum(t => t.stackCount) >= psyLeaves.stackCount)
                {
                    return(true);
                }
                return(false);

            case 2:
                silver.stackCount = 7000;
                requirements.Add(silver);
                psyLeaves.stackCount = 500;
                requirements.Add(psyLeaves);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount) && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == psyLeaves.def).Sum(t => t.stackCount) >= psyLeaves.stackCount)
                {
                    return(true);
                }
                return(false);

            case 3:
                silver.stackCount = 13000;
                requirements.Add(silver);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount))
                {
                    return(true);
                }
                return(false);

            default:
                return(false);
            }
        }
Ejemplo n.º 13
0
        public static bool CanUpgradeMedicine(Faction faction, List <Thing> requirements, int level)
        {
            requirements.Clear();
            Thing silver = ThingMaker.MakeThing(ThingDefOf.Silver);
            Thing cloth  = ThingMaker.MakeThing(ThingDefOf.Cloth, ThingDefOf.Cloth.IsStuff ? GenStuff.RandomStuffByCommonalityFor(ThingDefOf.Cloth, faction.def.techLevel) : null);

            switch (level)
            {
            case 0:
                silver.stackCount = 2500;
                requirements.Add(silver);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount))
                {
                    return(true);
                }
                return(false);

            case 1:
                silver.stackCount = 5000;
                cloth.stackCount  = 300;
                requirements.Add(silver);
                requirements.Add(cloth);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount) && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == cloth.def).Sum(t => t.stackCount) >= cloth.stackCount)
                {
                    return(true);
                }
                return(false);

            case 2:
                silver.stackCount = 7000;
                cloth.stackCount  = 600;
                requirements.Add(silver);
                requirements.Add(cloth);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount) && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == cloth.def).Sum(t => t.stackCount) >= cloth.stackCount)
                {
                    return(true);
                }
                return(false);

            default:
                return(false);
            }
        }
Ejemplo n.º 14
0
        public static bool CanUpgradeArmoryNWeaponry(Faction faction, List <Thing> requirements, int level)
        {
            requirements.Clear();
            Thing silver   = ThingMaker.MakeThing(ThingDefOf.Silver);
            Thing steel    = ThingMaker.MakeThing(ThingDefOf.Steel);
            Thing plasteel = ThingMaker.MakeThing(ThingDefOf.Plasteel);

            switch (level)
            {
            case 0:
                // 1000 silver, 150 steel
                silver.stackCount = 1000;
                steel.stackCount  = 150;
                requirements.Add(silver);
                requirements.Add(steel);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount) && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == steel.def).Sum(t => t.stackCount) >= steel.stackCount)
                {
                    return(true);
                }
                return(false);

            case 1:
                // 1000 silver, 150 steel
                silver.stackCount = 1750;
                steel.stackCount  = 300;
                requirements.Add(silver);
                requirements.Add(steel);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount) && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == steel.def).Sum(t => t.stackCount) >= steel.stackCount)
                {
                    return(true);
                }
                return(false);

            case 2:
                // 1000 silver, 150 steel
                silver.stackCount = 3000;
                steel.stackCount  = 500;
                requirements.Add(silver);
                requirements.Add(steel);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount) && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == steel.def).Sum(t => t.stackCount) >= steel.stackCount)
                {
                    return(true);
                }
                return(false);

            case 3:
                // 1000 silver, 150 steel
                silver.stackCount   = 3000;
                steel.stackCount    = 875;
                plasteel.stackCount = 300;
                requirements.Add(silver);
                requirements.Add(steel);
                requirements.Add(plasteel);
                if (TradeUtility.ColonyHasEnoughSilver(Find.AnyPlayerHomeMap, silver.stackCount) && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == steel.def).Sum(t => t.stackCount) >= steel.stackCount && TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).Where(t => t.def == plasteel.def).Sum(t => t.stackCount) >= plasteel.stackCount)
                {
                    return(true);
                }
                return(false);

            default:
                return(false);
            }
        }
 private bool HasEnoughValuableThings() => GenThing.GetMarketValue(TradeUtility.AllLaunchableThingsForTrade(Find.AnyPlayerHomeMap).ToList()) > (int)silverCurve.Evaluate(1 - (1 / Find.AnyPlayerHomeMap.wealthWatcher.WealthTotal))
         ? true
         : false;