Exemplo n.º 1
0
        public static Command TradeCommand(LandedShip caravan)
        {
            Pawn           bestNegotiator = CaravanVisitUtility.BestNegotiator(caravan);
            Command_Action command_Action = new Command_Action();

            command_Action.defaultLabel = "CommandTrade".Translate();
            command_Action.defaultDesc  = "CommandTradeDesc".Translate();
            command_Action.icon         = DropShipUtility.TradeCommandTex;
            command_Action.action       = delegate
            {
                FactionBase factionBase = CaravanVisitUtility.FactionBaseVisitedNow(caravan);
                if (factionBase != null && factionBase.CanTradeNow)
                {
                    caravan.UnloadCargoForTrading();
                    Find.WindowStack.Add(new Dialog_TradeFromShips(caravan, bestNegotiator, factionBase));
                    string empty  = string.Empty;
                    string empty2 = string.Empty;
                    PawnRelationUtility.Notify_PawnsSeenByPlayer(factionBase.Goods.OfType <Pawn>(), ref empty, ref empty2, "LetterRelatedPawnsTradingWithFactionBase".Translate(), false);
                    if (!empty2.NullOrEmpty())
                    {
                        Find.LetterStack.ReceiveLetter(empty, empty2, LetterType.Good, factionBase, null);
                    }
                }
            };
            if (bestNegotiator == null)
            {
                command_Action.Disable("CommandTradeFailNoNegotiator".Translate());
            }
            return(command_Action);
        }
 public override void CompTick()
 {
     if (caravanIsWorking && Find.TickManager.TicksGame > workWillBeDoneAtTick)
     {
         CaravanVisitUtility.SettlementVisitedNow(caravan: (Caravan)parent)?.GetComponent <WorldObjectComp_SettlementBumperCropComp>().DoOutcome(caravan: (Caravan)parent);
     }
 }
Exemplo n.º 3
0
        public bool ShouldCancel()
        {
            if (!trader.CanTradeNow)
            {
                return(true);
            }

            if (trader is Pawn traderPawn)
            {
                if (!traderPawn.Spawned || !playerNegotiator.Spawned)
                {
                    return(true);
                }
                return(traderPawn.Position.DistanceToSquared(playerNegotiator.Position) > 2 * 2);
            }

            if (trader is Settlement traderBase)
            {
                var caravan = playerNegotiator.GetCaravan();
                if (caravan == null)
                {
                    return(true);
                }

                if (CaravanVisitUtility.SettlementVisitedNow(caravan) != traderBase)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 4
0
        public override IEnumerable <Gizmo> GetGizmos()
        {
            if (this.IsPlayerControlled)
            {
                Command_Action command_Action = new Command_Action();
                command_Action.defaultLabel = "CommandLaunchShip".Translate();
                command_Action.defaultDesc  = "CommandLaunchShipDesc".Translate();
                command_Action.icon         = DropShipUtility.LaunchSingleCommandTex;
                command_Action.action       = delegate
                {
                    SoundDef.Named("ShipTakeoff_SuborbitalLaunch").PlayOneShotOnCamera();
                    this.ships[0].StartChoosingDestination(this.ships[0], false);
                };
                yield return(command_Action);

                if (Find.WorldSelector.SingleSelectedObject == this)
                {
                    yield return(TravelingShipsUtility.ShipTouchdownCommand(this, true));

                    yield return(TravelingShipsUtility.ShipTouchdownCommand(this, false));
                }
                FactionBase factionBase = CaravanVisitUtility.FactionBaseVisitedNow(this);
                if (factionBase != null && factionBase.CanTradeNow)
                {
                    yield return(TravelingShipsUtility.TradeCommand(this));
                }
                if (CaravanJourneyDestinationUtility.AnyJurneyDestinationAt(base.Tile))
                {
                    yield return(CaravanJourneyDestinationUtility.TakeOffCommand(base.Tile));
                }
            }
        }
 public override string CompInspectStringExtra()
 {
     if (CaravanVisitUtility.SettlementVisitedNow(caravan: (Caravan)parent)?.GetComponent <WorldObjectComp_SettlementBumperCropComp>()?.CaravanIsWorking ?? false)
     {
         return("MFI_CaravanWorking".Translate());
     }
     return(string.Empty);
 }
        private static void WorldReachUtility_PostFix(ref bool __result, Caravan c)
        {
            var settlement = CaravanVisitUtility.SettlementVisitedNow(caravan: c);
            WorldObjectComp_SettlementBumperCropComp bumperCropComponent = settlement?.GetComponent <WorldObjectComp_SettlementBumperCropComp>();

            if (bumperCropComponent != null)
            {
                __result = !bumperCropComponent.CaravanIsWorking;
            }
        }
Exemplo n.º 7
0
        public override IEnumerable <Gizmo> GetCaravanGizmos(Caravan caravan)
        {
            if (Visitable)
            {
                // TODO refactor
                if (!(this is Citadel))
                {
                    var enterLabel = Find.World.GetComponent <WorldComponent_QuestTracker>().quests
                                     .Where(q => q.Targets != null && q.Targets.targets.Contains(this))
                                     .Select(q => q.def.EnterCityLabel)
                                     .FirstOrDefault() ?? "EnterCity".Translate();

                    var action = new Command_Action {
                        icon         = SettleUtility.SettleCommandTex,
                        defaultLabel = enterLabel,
                        defaultDesc  = "EnterCityDesc".Translate(),
                        action       = () => {
                            LongEventHandler.QueueLongEvent(() => {
                                var orGenerateMap = GetOrGenerateMapUtility.GetOrGenerateMap(Tile, null);
                                CaravanEnterMapUtility.Enter(caravan, orGenerateMap, CaravanEnterMode.Edge,
                                                             CaravanDropInventoryMode.DoNotDrop, true);
                            }, "GeneratingMapForNewEncounter", false, null);
                        },
                    };
                    if (this.EnterCooldownBlocksEntering())
                    {
                        action.disabled       = true;
                        action.disabledReason =
                            "MessageEnterCooldownBlocksEntering".Translate(this.EnterCooldownDaysLeft().ToString("0.#"));
                    }

                    yield return(action);
                }

                if (!Abandoned)
                {
                    yield return(CaravanVisitUtility.TradeCommand(caravan));
                }
            }

            foreach (var gizmo in base.GetCaravanGizmos(caravan))
            {
                if (gizmo is Command command && command.defaultLabel == "CommandTrade".Translate())
                {
                    continue;
                }

                yield return(gizmo);
            }
        }
Exemplo n.º 8
0
        public override IEnumerable <Gizmo> GetGizmos()
        {
            if (this.IsPlayerControlled)
            {
                Command_Action command_Action = new Command_Action();
                command_Action.defaultLabel = "CommandLaunchShip".Translate();
                command_Action.defaultDesc  = "CommandLaunchShipDesc".Translate();
                command_Action.icon         = DropShipUtility.LaunchSingleCommandTex;
                command_Action.action       = delegate
                {
                    SoundDef.Named("ShipTakeoff_SuborbitalLaunch").PlayOneShotOnCamera();
                    this.ships[0].StartChoosingDestination(this.ships[0], false);
                };
                yield return(command_Action);

                if (Find.WorldSelector.SingleSelectedObject == this)
                {
                    yield return(TravelingShipsUtility.ShipTouchdownCommand(this, true));

                    yield return(TravelingShipsUtility.ShipTouchdownCommand(this, false));
                }
                Settlement factionBase = CaravanVisitUtility.SettlementVisitedNow(this);
                if (factionBase != null && factionBase.CanTradeNow)
                {
                    yield return(TravelingShipsUtility.TradeCommand(this));
                }
                if (CaravanJourneyDestinationUtility.AnyJurneyDestinationAt(base.Tile))
                {
                    yield return(CaravanJourneyDestinationUtility.TakeOffCommand(base.Tile));
                }

                if (!this.ships.Any(x => x.ParkingMap == null))
                {
                    Command_Action command_Action4 = new Command_Action();
                    command_Action4.defaultLabel = "CommandTravelParkingPosition".Translate();
                    command_Action4.defaultDesc  = "CommandTravelParkingPositionDesc".Translate();
                    command_Action4.icon         = DropShipUtility.ReturnParkingFleet;
                    command_Action4.action       = delegate
                    {
                        foreach (ShipBase ship in this.ships)
                        {
                            ship.TryLaunch(new GlobalTargetInfo(ship.ParkingPosition, ship.ParkingMap), PawnsArriveMode.CenterDrop, TravelingShipArrivalAction.EnterMapFriendly, false);
                        }
                    };
                    yield return(command_Action4);
                }
            }
        }
Exemplo n.º 9
0
        public override string GetInspectString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (this.Resting)
            {
                stringBuilder.Append("CaravanResting".Translate());
            }
            else if (this.AllOwnersDowned)
            {
                stringBuilder.Append("AllCaravanMembersDowned".Translate());
            }
            else if (this.pather.Moving)
            {
                if (this.pather.arrivalAction != null)
                {
                    stringBuilder.Append(this.pather.arrivalAction.ReportString);
                }
                else
                {
                    stringBuilder.Append("CaravanTraveling".Translate());
                }
            }
            else
            {
                Settlement factionBase = CaravanVisitUtility.SettlementVisitedNow(this);
                if (factionBase != null)
                {
                    stringBuilder.Append("CaravanVisiting".Translate(new object[]
                    {
                        factionBase.Label
                    }));
                }
                else
                {
                    stringBuilder.Append("CaravanWaiting".Translate());
                }
            }

            return(stringBuilder.ToString());
        }
Exemplo n.º 10
0
        public override string GetInspectString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (this.Resting)
            {
                stringBuilder.Append("CaravanResting".Translate());
            }
            else if (this.AnyPawnHasExtremeMentalBreak)
            {
                stringBuilder.Append("CaravanMemberMentalBreak".Translate(new object[]
                {
                    this.FirstPawnWithExtremeMentalBreak.LabelShort
                }));
            }
            else if (this.AllOwnersDowned)
            {
                stringBuilder.Append("AllCaravanMembersDowned".Translate());
            }
            else if (this.pather.Moving)
            {
                if (this.pather.arrivalAction != null)
                {
                    stringBuilder.Append(this.pather.arrivalAction.ReportString);
                }
                else
                {
                    stringBuilder.Append("CaravanTraveling".Translate());
                }
            }
            else
            {
                FactionBase factionBase = CaravanVisitUtility.FactionBaseVisitedNow(this);
                if (factionBase != null)
                {
                    stringBuilder.Append("CaravanVisiting".Translate(new object[]
                    {
                        factionBase.Label
                    }));
                }
                else
                {
                    stringBuilder.Append("CaravanWaiting".Translate());
                }
            }
            if (this.pather.Moving)
            {
                stringBuilder.AppendLine();
                stringBuilder.Append("CaravanEstimatedTimeToDestination".Translate(new object[]
                {
                    CaravanArrivalTimeEstimator.EstimatedTicksToArrive(this, true).ToStringTicksToPeriod(true)
                }));
            }
            if (this.ImmobilizedByMass)
            {
                stringBuilder.AppendLine();
                stringBuilder.Append("CaravanImmobilizedByMass".Translate());
            }
            string text;

            if (CaravanPawnsNeedsUtility.AnyPawnOutOfFood(this, out text))
            {
                stringBuilder.AppendLine();
                stringBuilder.Append("CaravanOutOfFood".Translate());
                if (!text.NullOrEmpty())
                {
                    stringBuilder.Append(" ");
                    stringBuilder.Append(text);
                    stringBuilder.Append(".");
                }
            }
            else
            {
                stringBuilder.AppendLine();
                stringBuilder.Append("CaravanDaysOfFood".Translate(new object[]
                {
                    this.DaysWorthOfFood.ToString("0.#")
                }));
            }
            stringBuilder.AppendLine();
            stringBuilder.AppendLine(string.Concat(new string[]
            {
                "CaravanBaseMovementTime".Translate(),
                ": ",
                ((float)this.TicksPerMove / 2500f).ToString("0.##"),
                " ",
                "CaravanHoursPerTile".Translate()
            }));

            double actualTicksPerMove = ((double)this.TicksPerMove / 2500f) * (2500f + WorldPathGrid.CalculatedCostAt(base.Tile, false, -1f));

            stringBuilder.Append("CurrentTileMovementTime".Translate() + ": " + ((int)actualTicksPerMove).ToStringTicksToPeriod(true));
            return(stringBuilder.ToString());
        }
Exemplo n.º 11
0
        static void ReopenTradingWindowLocally(Caravan caravan, Command __result)
        {
            var original = ((Command_Action)__result).action;

            ((Command_Action)__result).action = () =>
            {
                if (Multiplayer.Client != null && Multiplayer.WorldComp.trading.Any(t => t.trader == CaravanVisitUtility.SettlementVisitedNow(caravan)))
                {
                    Find.WindowStack.Add(new TradingWindow());
                    return;
                }

                original();
            };
        }