Пример #1
0
        public void InitializeUpgradeTree()
        {
            upgradeList = new List <UpgradeNode>();
            foreach (UpgradeNode node in Props.upgrades)
            {
                try
                {
                    UpgradeNode permanentNode = (UpgradeNode)Activator.CreateInstance(node.GetType(), new object[] { node, Vehicle });
                    permanentNode.OnInit();
                    upgradeList.Add(permanentNode);
                }
                catch (Exception ex)
                {
                    SmashLog.Error($"Exception thrown while generating <text>{node.upgradeID}</text> of type <type>{node.GetType()}</type> for {Vehicle.LabelShort}\nException=\"{ex}\"");
                    upgradeList.Add(UpgradeNode.BlankUpgrade(node, Vehicle));
                }
            }

            if (upgradeList.Select(x => x.upgradeID).GroupBy(y => y).Where(y => y.Count() > 1).Select(z => z.Key).NotNullAndAny())
            {
                Log.Error(string.Format("Duplicate UpgradeID's detected on def {0}. This is not supported.", parent.def.defName));
                Debug.Message("====== Duplicate UpgradeID's for this Vehicle ======");
                foreach (UpgradeNode errorNode in upgradeList.GroupBy(grp => grp).Where(g => g.Count() > 1))
                {
                    Debug.Message($"UpgradeID: {errorNode.upgradeID} UniqueID: {errorNode.GetUniqueLoadID()} Location: {errorNode.gridCoordinate}");
                }
                Debug.Message("===========================================");
            }
        }
Пример #2
0
        public bool LastNodeUnlocked(UpgradeNode node)
        {
            UpgradeNode        nodeListed   = NodeListed(node);
            List <UpgradeNode> unlocksNodes = upgradeList.FindAll(x => x.prerequisiteNodes.Contains(nodeListed.upgradeID));

            return(!unlocksNodes.NotNullAndAny(x => x.upgradeActive));
        }
Пример #3
0
        public void FinishUnlock(UpgradeNode node)
        {
            var actualNode = NodeListed(node);

            actualNode.Upgrade(Vehicle);
            actualNode.upgradeActive    = true;
            actualNode.upgradePurchased = true;
        }
Пример #4
0
 public override void PostSpawnSetup(bool respawningAfterLoad)
 {
     base.PostSpawnSetup(respawningAfterLoad);
     NodeUnlocking = upgradeList.Find(x => x.upgradePurchased && !x.upgradeActive);
     foreach (UpgradeNode node in upgradeList)
     {
         node.ResolveReferences();
     }
 }
Пример #5
0
        public UpgradeNode RootNode(UpgradeNode child)
        {
            UpgradeNode parentOfChild = child;

            while (parentOfChild.prerequisiteNodes.NotNullAndAny())
            {
                parentOfChild = NodeListed(parentOfChild.prerequisiteNodes.First());
            }
            return(parentOfChild);
        }
Пример #6
0
        public UpgradeNode NodeListed(string upgradeID)
        {
            UpgradeNode matchedNode = upgradeList.Find(x => x.upgradeID == upgradeID);

            if (matchedNode is null)
            {
                Log.Error($"Unable to locate node {upgradeID} in upgrade list. Cross referencing comp upgrades?");
                return(null);
            }
            return(matchedNode);
        }
Пример #7
0
 public void RefundUnlock(UpgradeNode node)
 {
     if (node is null)
     {
         return;
     }
     if (!node.upgradeActive)
     {
         return;
     }
     node.itemContainer.TryDropAll(Vehicle.Position, Vehicle.Map, ThingPlaceMode.Near);
     node.Refund(Vehicle);
     node.ResetNode();
 }
Пример #8
0
        public static StatUpgrade BlankUpgrade(UpgradeNode failedNode, VehiclePawn parent) => new StatUpgrade(parent)
        {
            values                      = new Dictionary <StatUpgradeCategoryDef, float>(),
            label                       = failedNode.label,
            upgradeID                   = failedNode.upgradeID + "_FAILED",
            rootNodeLabel               = string.Empty,
            informationHighlighted      = failedNode.informationHighlighted,
            disableIfUpgradeNodeEnabled = string.Empty,

            ingredients           = new List <IngredientFilter>(),
            researchPrerequisites = new List <ResearchProjectDef>(),
            prerequisiteNodes     = new List <string>(),
            imageFilePath         = BaseContent.BadTexPath,
            gridCoordinate        = failedNode.gridCoordinate,
            upgradeTime           = new RimWorldTime("999y")
        };
Пример #9
0
 private static void UpgradeAtRandom(VehiclePawn vehicle, int upgradeCount)
 {
     if (vehicle.CompUpgradeTree != null)
     {
         Rand.PushState();
         for (int i = 0; i < upgradeCount; i++)
         {
             var potentialUpgrades = vehicle.CompUpgradeTree.upgradeList.Where(u => !u.upgradeActive && vehicle.CompUpgradeTree.PrerequisitesMet(u));
             if (potentialUpgrades.NotNullAndAny())
             {
                 UpgradeNode node = potentialUpgrades.RandomElement();
                 vehicle.CompUpgradeTree.FinishUnlock(node);
             }
         }
         Rand.PopState();
     }
 }
Пример #10
0
        protected Job UpgradeNodeDeliverJob(Pawn pawn, VehiclePawn vehicle)
        {
            UpgradeNode u = vehicle.CompUpgradeTree.NodeUnlocking;
            List <ThingDefCountClass> materials = u.MaterialsRequired().ToList();
            int count = materials.Count;

            bool flag = false;
            ThingDefCountClass thingDefCountClass = null;
            var reservationManager = vehicle.Map.GetCachedMapComponent <VehicleReservationManager>();

            for (int i = 0; i < count; i++)
            {
                ThingDefCountClass materialRequired = materials[i];

                if (!pawn.Map.itemAvailability.ThingsAvailableAnywhere(materialRequired, pawn))
                {
                    flag = true;
                    thingDefCountClass = materialRequired;
                    break;
                }

                Thing foundResource = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(materialRequired.thingDef), PathEndMode.ClosestTouch, TraverseParms.For(pawn,
                                                                                                                                                                                            Danger.Deadly, TraverseMode.ByPawn, false), 9999f, (Thing t) => t.def == materialRequired.thingDef && !t.IsForbidden(pawn) && pawn.CanReserve(t, 1, -1, null, false));

                if (foundResource != null && pawn.Map.GetCachedMapComponent <VehicleReservationManager>().CanReserve <ThingDefCountClass, VehicleNodeReservation>(vehicle, pawn, null))
                {
                    FindAvailableNearbyResources(foundResource, pawn, out int resourceTotalAvailable);
                    Job job      = JobMaker.MakeJob(JobDefOf_Vehicles.LoadUpgradeMaterials, foundResource, vehicle);
                    int matCount = reservationManager.GetReservation <VehicleNodeReservation>(vehicle)?.MaterialsLeft().FirstOrDefault(m => m.thingDef == foundResource.def)?.count ?? int.MaxValue;
                    job.count = foundResource.stackCount > matCount ? matCount : foundResource.stackCount;
                    return(job);
                }
                else
                {
                    flag = true;
                    thingDefCountClass = materialRequired;
                }
            }

            if (flag)
            {
                JobFailReason.Is(string.Format($"{"MissingMaterials".Translate()}: {thingDefCountClass.thingDef.label}"), null);
            }
            return(null);
        }
Пример #11
0
        public Dialog_NodeSettings(VehicleDef def, UpgradeNode node, Vector2 origin)
        {
            VehicleDef  = def;
            UpgradeNode = node;

            closeOnClickedOutside  = true;
            closeOnAnyClickOutside = true;
            closeOnCancel          = true;
            doCloseX = true;

            float width  = 400;
            int   rows   = Mathf.Max(1, Mathf.FloorToInt(UpgradeNode.ListerCount / 2f));
            float height = rows * 100 + 50;

            windowSize = new Vector2(width, height);
            drawLoc    = origin;

            Lister = new Listing_Settings(SettingsPage.Upgrades);
        }
Пример #12
0
        /// <summary>
        /// preferred method of node instantiation. Copy over from XML defined values
        /// </summary>
        /// <param name="reference"></param>
        /// <param name="parent"></param>
        public UpgradeNode(UpgradeNode reference, VehiclePawn parent)
        {
            nodeID      = VehicleIdManager.Instance.GetNextUpgradeId();
            this.parent = parent;

            label                       = reference.label;
            upgradeID                   = reference.upgradeID;
            rootNodeLabel               = reference.rootNodeLabel;
            informationHighlighted      = reference.informationHighlighted;
            disableIfUpgradeNodeEnabled = reference.disableIfUpgradeNodeEnabled;

            ingredients           = reference.ingredients;
            researchPrerequisites = reference.researchPrerequisites;
            prerequisiteNodes     = reference.prerequisiteNodes;
            imageFilePath         = reference.imageFilePath;
            gridCoordinate        = reference.gridCoordinate;
            upgradeTime           = reference.upgradeTime;

            itemContainer = new ThingOwner <Thing>(this, false, LookMode.Deep);
        }
Пример #13
0
 public void StartUnlock(UpgradeNode node)
 {
     NodeUnlocking = NodeListed(node);
     NodeUnlocking.ResetTimer();
 }
Пример #14
0
 private bool Equals(UpgradeNode u)
 {
     return(upgradeID == u.upgradeID);
 }
Пример #15
0
        private void DrawVehicleUpgrades(Rect menuRect)
        {
            Rect vehicleIconContainer = menuRect.ContractedBy(10);

            vehicleIconContainer.width /= 4;
            vehicleIconContainer.height = vehicleIconContainer.width;
            vehicleIconContainer.x     += vehicleIconContainer.width;

            Rect vehicleDetailsContainer = menuRect.ContractedBy(10);

            vehicleDetailsContainer.x     += vehicleIconContainer.width - 1;
            vehicleDetailsContainer.width -= vehicleIconContainer.width;

            Widgets.DrawBoxSolid(vehicleDetailsContainer, Color.grey);
            Rect vehicleDetailsRect = vehicleDetailsContainer.ContractedBy(1);

            Widgets.DrawBoxSolid(vehicleDetailsRect, ListingExtension.MenuSectionBGFillColor);

            listingStandard = new Listing_Standard();
            listingStandard.Begin(vehicleDetailsContainer.ContractedBy(1));
            listingStandard.Header($"{VehicleMod.selectedDef?.LabelCap ?? string.Empty}", ListingExtension.BannerColor, GameFont.Medium, TextAnchor.MiddleCenter);
            listingStandard.End();
            vehicleDetailsContainer.y += 5;

            if (VehicleMod.selectedDef != null && VehicleMod.selectedDefUpgradeComp != null)
            {
                try
                {
                    foreach (UpgradeNode upgradeNode in VehicleMod.selectedDefUpgradeComp.upgrades)
                    {
                        if (!upgradeNode.prerequisiteNodes.NullOrEmpty())
                        {
                            foreach (UpgradeNode prerequisite in VehicleMod.selectedDefUpgradeComp.upgrades.FindAll(x => upgradeNode.prerequisiteNodes.Contains(x.upgradeID)))
                            {
                                Vector2 start = new Vector2(vehicleDetailsContainer.x + ITab_Vehicle_Upgrades.GridOrigin.x + (ITab_Vehicle_Upgrades.GridSpacing.x * prerequisite.GridCoordinate.x),
                                                            vehicleDetailsContainer.y + ITab_Vehicle_Upgrades.GridOrigin.y + (ITab_Vehicle_Upgrades.GridSpacing.y * prerequisite.GridCoordinate.z) + (ITab_Vehicle_Upgrades.TopPadding * 2));
                                Vector2 end = new Vector2(vehicleDetailsContainer.x + ITab_Vehicle_Upgrades.GridOrigin.x + (ITab_Vehicle_Upgrades.GridSpacing.x * upgradeNode.GridCoordinate.x),
                                                          vehicleDetailsContainer.y + ITab_Vehicle_Upgrades.GridOrigin.y + (ITab_Vehicle_Upgrades.GridSpacing.y * upgradeNode.GridCoordinate.z) + (ITab_Vehicle_Upgrades.TopPadding * 2));
                                Color color = Color.grey;
                                Widgets.DrawLine(start, end, color, 2f);
                            }
                        }
                    }

                    for (int i = 0; i < VehicleMod.selectedDefUpgradeComp.upgrades.Count; i++)
                    {
                        UpgradeNode upgradeNode = VehicleMod.selectedDefUpgradeComp.upgrades[i];
                        float       imageWidth  = ITab_Vehicle_Upgrades.TotalIconSizeScalar / upgradeNode.UpgradeImage.width;
                        float       imageHeight = ITab_Vehicle_Upgrades.TotalIconSizeScalar / upgradeNode.UpgradeImage.height;

                        Rect upgradeRect = new Rect(vehicleDetailsContainer.x + ITab_Vehicle_Upgrades.GridOrigin.x + (ITab_Vehicle_Upgrades.GridSpacing.x * upgradeNode.GridCoordinate.x) - (imageWidth / 2),
                                                    vehicleDetailsContainer.y + ITab_Vehicle_Upgrades.GridOrigin.y + (ITab_Vehicle_Upgrades.GridSpacing.y * upgradeNode.GridCoordinate.z) - (imageHeight / 2) + (ITab_Vehicle_Upgrades.TopPadding * 2),
                                                    imageWidth, imageHeight);
                        Widgets.DrawTextureFitted(upgradeRect, upgradeNode.UpgradeImage, 1);

                        if (!upgradeNode.prerequisiteNodes.NotNullAndAny())
                        {
                            if (!string.IsNullOrEmpty(upgradeNode.rootNodeLabel))
                            {
                                float textWidth     = Text.CalcSize(upgradeNode.rootNodeLabel).x;
                                Rect  nodeLabelRect = new Rect(upgradeRect.x - (textWidth - upgradeRect.width) / 2, upgradeRect.y - 20f, 10f * upgradeNode.rootNodeLabel.Length, 25f);
                                Widgets.Label(nodeLabelRect, upgradeNode.rootNodeLabel);
                            }
                        }
                        Rect buttonRect = new Rect(vehicleDetailsContainer.x + ITab_Vehicle_Upgrades.GridOrigin.x + (ITab_Vehicle_Upgrades.GridSpacing.x * upgradeNode.GridCoordinate.x) - (imageWidth / 2),
                                                   vehicleDetailsContainer.y + ITab_Vehicle_Upgrades.GridOrigin.y + (ITab_Vehicle_Upgrades.GridSpacing.y * upgradeNode.GridCoordinate.z) - (imageHeight / 2) + (ITab_Vehicle_Upgrades.TopPadding * 2),
                                                   imageWidth, imageHeight);

                        if (Mouse.IsOver(upgradeRect) || VehicleMod.selectedNode == upgradeNode)
                        {
                            GUI.DrawTexture(upgradeRect, TexUI.HighlightTex);
                        }
                        if (Mouse.IsOver(upgradeRect))
                        {
                            TooltipHandler.TipRegion(upgradeRect, upgradeNode.label);
                        }

                        if (Widgets.ButtonInvisible(buttonRect, true))
                        {
                            if (VehicleMod.selectedNode != upgradeNode)
                            {
                                VehicleMod.selectedNode = upgradeNode;
                                Find.WindowStack.Add(new Dialog_NodeSettings(VehicleMod.selectedDef, VehicleMod.selectedNode, new Vector2(buttonRect.x + imageWidth * 2, buttonRect.y + imageHeight / 2)));
                                SoundDefOf.Checkbox_TurnedOn.PlayOneShotOnCamera();
                            }
                            else
                            {
                                VehicleMod.selectedNode = null;
                                SoundDefOf.Checkbox_TurnedOff.PlayOneShotOnCamera();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error($"Exception thrown while trying to select {VehicleMod.selectedDef.defName}. Disabling vehicle to preserve mod settings.\nException={ex.Message}");
                    VehicleMod.settingsDisabledFor.Add(VehicleMod.selectedDef.defName);
                    VehicleMod.selectedDef = null;
                    VehicleMod.selectedPatterns.Clear();
                    VehicleMod.selectedDefUpgradeComp = null;
                    VehicleMod.selectedNode           = null;
                    VehicleMod.SetVehicleTex(null);
                }
            }
        }
Пример #16
0
        public static Rect DrawVehicleList(Rect rect, Func <bool, string> tooltipGetter = null, Predicate <VehicleDef> validator = null)
        {
            Rect scrollContainer = rect.ContractedBy(10);

            scrollContainer.width /= 4;
            Widgets.DrawBoxSolid(scrollContainer, Color.grey);
            Rect innerContainer = scrollContainer.ContractedBy(1);

            Widgets.DrawBoxSolid(innerContainer, ListingExtension.MenuSectionBGFillColor);
            Rect scrollList = innerContainer.ContractedBy(1);
            Rect scrollView = scrollList;

            scrollView.height = VehicleDefs.Count * 22f;

            Widgets.BeginScrollView(scrollList, ref vehicleDefsScrollPosition, scrollView);
            Listing_Standard listingStandard = new Listing_Standard();

            listingStandard.Begin(scrollList);
            string currentModTitle = string.Empty;

            foreach (VehicleDef vehicle in VehicleDefs)
            {
                try
                {
                    if (currentModTitle != vehicle.modContentPack.Name)
                    {
                        currentModTitle = vehicle.modContentPack.Name;
                        listingStandard.Header(currentModTitle, ListingExtension.BannerColor, GameFont.Medium, TextAnchor.MiddleCenter);
                    }
                    bool   validated = validator is null || validator(vehicle);
                    string tooltip   = tooltipGetter != null?tooltipGetter(validated) : string.Empty;

                    if (listingStandard.ListItemSelectable(vehicle.defName, Color.yellow, selectedDef == vehicle, validated, tooltip))
                    {
                        if (selectedDef == vehicle)
                        {
                            selectedDef = null;
                            selectedPatterns.Clear();
                            selectedDefUpgradeComp = null;
                            selectedNode           = null;
                            SetVehicleTex(null);
                        }
                        else
                        {
                            selectedDef = vehicle;
                            ClearSelectedDefCache();
                            selectedPatterns = DefDatabase <PatternDef> .AllDefs.Where(d => d.ValidFor(selectedDef)).ToList();

                            selectedDefUpgradeComp = vehicle.GetSortedCompProperties <CompProperties_UpgradeTree>();
                            RecalculateHeight(selectedDef);
                            SetVehicleTex(selectedDef);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error($"Exception thrown while trying to select {vehicle.defName}. Disabling vehicle to preserve mod settings.\nException={ex.Message}");
                    selectedDef = null;
                    selectedPatterns.Clear();
                    selectedDefUpgradeComp = null;
                    selectedNode           = null;
                    SetVehicleTex(null);
                    settingsDisabledFor.Add(vehicle.defName);
                }
            }
            listingStandard.End();
            Widgets.EndScrollView();
            return(scrollContainer);
        }
Пример #17
0
 public override void WriteSettings()
 {
     base.WriteSettings();
     selectedNode = null;
     Find.WindowStack.Windows.FirstOrDefault(w => w is Dialog_NodeSettings)?.Close();
 }
Пример #18
0
 public bool PrerequisitesMet(UpgradeNode node)
 {
     return(upgradeList.Where(x => node.prerequisiteNodes.Contains(x.upgradeID)).All(y => y.upgradeActive));
 }
Пример #19
0
 public override void DoWindowContents(Rect inRect)
 {
     Lister.Begin(inRect, 2);
     UpgradeNode.SettingsWindow(VehicleDef, Lister);
     Lister.End();
 }
Пример #20
0
 public bool Disabled(UpgradeNode node)
 {
     return(!string.IsNullOrEmpty(node.disableIfUpgradeNodeEnabled) && upgradeList.FirstOrDefault(x => x.upgradeID == node.disableIfUpgradeNodeEnabled).upgradeActive);
 }