Gizmo not appearing on reload

Started by Oreoplanes, April 30, 2024, 06:37:31 AM

Previous topic - Next topic

Oreoplanes

Hi I am rewriting the request for items quest and as such have 'rewritten' the related classes and methods and it all works fine until i reload the game from a save file. In which case the caravan gizmo to complete the quest no longer appears even though the quest is active.

I guess the relevant code would be:
    public class TradeRequestCompPE : WorldObjectComp
    {
        public XenotypeDef requestThingDef;

        public int requestCount;

        public int expiration = -1;

        public string outSignalFulfilled;

        private static readonly Texture2D TradeCommandTex = ContentFinder<Texture2D>.Get("UI/Commands/FulfillTradeRequest");

        public bool ActiveRequest => expiration > Find.TickManager.TicksGame;

        public override string CompInspectStringExtra()
        {
            if (ActiveRequest)
            {
                return "CaravanRequestInfo".Translate(TradeRequestUtility.RequestedThingLabel(requestThingDef).CapitalizeFirst(), requestCount, (expiration - Find.TickManager.TicksGame).ToStringTicksToDays());
            }
            return null;
        }

        public override IEnumerable<Gizmo> GetCaravanGizmos(Caravan caravan)
        {
            if (ActiveRequest && CaravanVisitUtility.SettlementVisitedNow(caravan) == parent)
            {
                yield return FulfillRequestCommand(caravan);
            }
        }

        public void Disable()
        {
            expiration = -1;
        }

        public override void PostExposeData()
        {
            base.PostExposeData();
            Scribe_Defs.Look(ref requestThingDef, "requestXenoThingDef");
            Scribe_Values.Look(ref requestCount, "requestXenoCount", 0);
            Scribe_Values.Look(ref expiration, "expiration", 0);
            BackCompatibility.PostExposeData(this);
        }

        private Command FulfillRequestCommand(Caravan caravan)
        {
            Command_Action command_Action = new Command_Action();
            command_Action.defaultLabel = "CommandFulfillTradeOffer".Translate();
            command_Action.defaultDesc = "CommandFulfillTradeOfferDesc".Translate();
            command_Action.icon = TradeCommandTex;
            command_Action.action = delegate
            {
                if (!ActiveRequest)
                {
                    Log.Error("Attempted to fulfill an unavailable request");
                }
                else if (!CaravanInventoryUtility.HasThings(caravan, requestThingDef, requestCount))
                {
                    Messages.Message("CommandFulfillTradeOfferFailInsufficient".Translate(TradeRequestUtility.RequestedThingLabel(requestThingDef)), MessageTypeDefOf.RejectInput, historical: false);
                }
                else
                {
                    Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("CommandFulfillTradeOfferConfirm".Translate(TradeRequestUtility.RequestedThingLabel(requestThingDef)), delegate
                    {
                        Fulfill(caravan);
                    }));
                }
            };
            if (!CaravanInventoryUtility.HasThings(caravan, requestThingDef, requestCount))
            {
                command_Action.Disable("CommandFulfillTradeOfferFailInsufficient".Translate(TradeRequestUtility.RequestedThingLabel(requestThingDef)));
            }
            return command_Action;
        }

        private void Fulfill(Caravan caravan)
        {
            List<Pawn> list = CaravanInventoryUtility.TakeThings(caravan, requestThingDef, requestCount);
            for (int i = 0; i < list.Count; i++)
            {
                caravan.RemovePawn(list[i]);
            }
            if (parent.Faction != null)
            {
                Faction.OfPlayer.TryAffectGoodwillWith(parent.Faction, 12, canSendMessage: true, canSendHostilityLetter: true, HistoryEventDefOf.QuestGoodwillReward);
            }
            QuestUtility.SendQuestTargetSignals(parent.questTags, "TradeRequestFulfilled", parent.Named("SUBJECT"), caravan.Named("CARAVAN"));
            Disable();
        }
    }

Though personally I don't think the code is wrong, more like the code just isn't being ran again when the game reloads? Anyone got any idea what triggers the original TradeRequestComp at game load?


Aforementioned Gizmo that disappears on reload.