示例#1
0
        //private void Initialize(CompUpgradable c)
        //{
        //    // basically CheckTurretIsReadyToUpgrade but doesn't return anything

        //    List<ThingDefCountClass> upgradeCost = c.upgradeCostListFinalized;
        //    if (upgradeCost != null)
        //    {
        //        Dictionary<string, int> upgradeCostDict = c.GetTurretUpgradeCost(upgradeCost);
        //        Dictionary<string, int> storedMatsDict = c.GetTurretHeldItems(c.GetDirectlyHeldThings());
        //        List<string> requiredDefs = new List<string>(upgradeCostDict.Keys);

        //        int i = 0;

        //        while (i < requiredDefs.Count)
        //        {
        //            string curDef = requiredDefs[i];
        //            try
        //            {
        //                if (storedMatsDict[curDef] < upgradeCostDict[curDef])
        //                {
        //                    UpdateFirstMissingIngredient(curDef, upgradeCostDict[curDef], storedMatsDict[curDef]);
        //                    break;
        //                }
        //                i++;
        //            }
        //            catch (KeyNotFoundException)
        //            {
        //                UpdateFirstMissingIngredient(curDef, upgradeCostDict[curDef]);
        //                break;
        //            }
        //        }
        //    }
        //}

        private bool CheckTurretIsReadyToUpgrade(CompUpgradable c)
        {
            List <ThingDefCountClass> upgradeCost = c.upgradeCostListFinalized;

            // If there's no upgrade cost, no material hauling required, thus returning true
            if (upgradeCost == null)
            {
                return(true);
            }

            // Compare stored materials to cost list. Done by converting both objects to common ground (i.e. dictionary), then comparing keys and values.
            else
            {
                bool readyToUpgrade = true;


                // Setting up dicts
                Dictionary <string, int> upgradeCostDict = c.GetTurretUpgradeCost(upgradeCost);
                Dictionary <string, int> storedMatsDict  = c.GetTurretHeldItems(c.GetDirectlyHeldThings());

                // Comparing dicts
                List <string> requiredDefs = new List <string>(upgradeCostDict.Keys);
                int           i            = 0;

                while (i < requiredDefs.Count)
                {
                    string curDef = requiredDefs[i];
                    try
                    {
                        if (storedMatsDict[curDef] < upgradeCostDict[curDef])
                        {
                            UpdateFirstMissingIngredient(curDef, upgradeCostDict[curDef], storedMatsDict[curDef]);
                            readyToUpgrade = false;
                            break;
                        }
                        i++;
                    }
                    // If one of the required things aren't present in the turret
                    catch (KeyNotFoundException)
                    {
                        UpdateFirstMissingIngredient(curDef, upgradeCostDict[curDef]);
                        readyToUpgrade = false;
                        break;
                    }
                }

                return(readyToUpgrade);
            }
        }
        public static bool IsUpgradedTurret(this Thing thing, out CompUpgradable uC)
        {
            bool isUpgradableTurret = thing.IsUpgradableTurret(out uC);

            return(isUpgradableTurret && uC.upgraded);
        }
 public static bool IsUpgradableTurret(this Thing thing, out CompUpgradable uC)
 {
     uC = thing.TryGetComp <CompUpgradable>();
     return(uC != null);
 }
示例#4
0
        public static bool IsUpgraded(this Thing thing, out CompUpgradable upgradableComp)
        {
            bool upgradable = thing.IsUpgradable(out upgradableComp);

            return(upgradable && upgradableComp.upgraded);
        }
示例#5
0
 public static bool IsUpgradable(this Thing thing, out CompUpgradable upgradableComp)
 {
     upgradableComp = thing.TryGetComp <CompUpgradable>();
     return(upgradableComp != null);
 }
 (t is Building_Turret turret && turret.Faction == Faction.OfPlayer && turret.IsUpgradableTurret(out CompUpgradable upgradableComp) &&
  !upgradableComp.upgraded && Map.designationManager.DesignationOn(t, Designation) == null);
示例#7
0
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            // Setting up variables
            Building_Turret turret              = t as Building_Turret;
            CompUpgradable  upgradableComp      = turret?.TryGetComp <CompUpgradable>();
            float           workerSuccessChance = pawn.GetStatValue(StatDefOf.ConstructSuccessChance);

            // Using the check as an initialisor
            if (upgradableComp != null)
            {
                CheckTurretIsReadyToUpgrade(upgradableComp);
            }

            // Conditions to return false
            if (turret == null)
            {
                return(false);
            }
            if (upgradableComp == null)
            {
                return(false);
            }
            if (turret.Faction != pawn.Faction)
            {
                return(false);
            }
            if (pawn.skills.GetSkill(SkillDefOf.Construction).Level < upgradableComp.Props.constructionSkillPrerequisite)
            {
                return(false);
            }
            if (!forced && workerSuccessChance * upgradableComp.Props.upgradeSuccessChanceFactor < 1f &&
                (turret.HitPoints <= Mathf.Floor(turret.MaxHitPoints * (1 - upgradableComp.Props.upgradeFailMajorDmgPctMax)) ||
                 turret.HitPoints <= Mathf.Floor(turret.MaxHitPoints * (1 - upgradableComp.Props.upgradeFailMajorDmgPctRange.TrueMax))))
            {
                return(false);
            }
            if (upgradableComp.upgraded)
            {
                return(false);
            }
            if (upgradableComp.upgradeCostListFinalized != null && ClosestMissingIngredient(pawn) == null)
            {
                return(false);
            }

            // Final condition set - the only set that can return true
            else
            {
                if (upgradableComp.Props.researchPrerequisites != null)
                {
                    foreach (ResearchProjectDef research in upgradableComp.Props.researchPrerequisites)
                    {
                        if (!research.IsFinished)
                        {
                            return(false);
                        }
                    }
                }
                return(pawn.CanReserve(turret, 1, -1, null, forced) && !turret.IsBurning());
            }
        }