Ejemplo n.º 1
0
    public void ManualDrillWorkDone(Pawn driller, Building building)
    {
        var performFactor =
            ManualDrillUtility.GetPerformFactor(building, out var noWind, out var newroofFactor,
                                                out var newwindFactor);

        if (!noWind)
        {
            var statValue = driller.GetStatValue(StatDefOf.MiningSpeed) / 2f * performFactor;
            portionProgress += statValue;
            portionYieldPct += statValue * driller.GetStatValue(StatDefOf.MiningYield) /
                               WorkPerPortionCurrentDifficulty;
        }

        lastUsedTick = Find.TickManager.TicksGame;
        if (portionProgress > WorkPerPortionCurrentDifficulty)
        {
            TryManualProducePortion(portionYieldPct, building);
            portionProgress = 0f;
            portionYieldPct = 0f;
        }

        windOk     = !noWind;
        roofFactor = newroofFactor;
        windFactor = newwindFactor;
    }
Ejemplo n.º 2
0
    public override void CompTick()
    {
        base.CompTick();
        if (!drill.IsHashIntervalTick(240))
        {
            return;
        }

        ManualDrillUtility.GetPerformFactor(drill, out var noWind, out var newroofFactor, out var newwindFactor);
        windOk     = !noWind;
        roofFactor = newroofFactor;
        windFactor = newwindFactor;
    }
Ejemplo n.º 3
0
    public void ManualProspectWorkDone(Pawn driller, Building building)
    {
        var performFactor =
            ManualDrillUtility.GetPerformFactor(building, out var noWind, out var newroofFactor,
                                                out var newwindFactor);

        if (!noWind)
        {
            var statValue = driller.GetStatValue(StatDefOf.MiningSpeed) / 2f * performFactor;
            prospectProgress += statValue;
            prospectYieldPct += statValue * driller.GetStatValue(StatDefOf.MiningYield) /
                                WorkPerPortionCurrentDifficulty;
        }

        lastUsedTick = Find.TickManager.TicksGame;
        if (prospectProgress > WorkPerPortionCurrentDifficulty)
        {
            if (SetMaxCount(building, 9, out var foundDef, out var maxVal))
            {
                if (foundDef != null)
                {
                    TryManualProducePortion(prospectYieldPct, building);
                    string labelone = "Prospecting.AProspector".Translate();
                    string labeltwo = "Prospecting.Unknown".Translate();
                    if (driller.LabelShort != null)
                    {
                        labelone = driller.LabelShort;
                    }

                    if (foundDef.label != null)
                    {
                        labeltwo = foundDef.label;
                    }

                    Messages.Message(
                        "Prospecting.DrillProspect".Translate(labelone) +
                        "Prospecting.ResourceFound".Translate(labeltwo), building, MessageTypeDefOf.PositiveEvent);
                }

                maxCount = maxVal;
            }

            prospectProgress = 0f;
            prospectYieldPct = 0f;
            prospected       = true;
        }

        windOk     = !noWind;
        roofFactor = newroofFactor;
        windFactor = newwindFactor;
    }
Ejemplo n.º 4
0
    private void TryManualProducePortion(float yieldPct, Building building)
    {
        var nextResource = GetNextManualResource(building, out var resDef, out var countPresent, out var cell);

        if (resDef == null)
        {
            return;
        }

        var num = Mathf.Min(countPresent, (int)Mathf.Max(1f, resDef.deepCountPerPortion / 2f));

        if (nextResource)
        {
            var newCount = building.Map.deepResourceGrid.CountAt(cell) - num;
            parent.Map.deepResourceGrid.SetAt(cell, resDef, newCount);
        }

        var stackCount = Mathf.Max(1, GenMath.RoundRandom(num * yieldPct));
        var thing      = ThingMaker.MakeThing(resDef);

        thing.stackCount = stackCount;
        GenPlace.TryPlaceThing(thing, parent.InteractionCell, parent.Map, ThingPlaceMode.Near);
        var CMD = building.TryGetComp <CompManualDrill>();

        if (CMD == null)
        {
            return;
        }

        if (!nextResource ||
            ManualDrillUtility.DrillCanGetToCount(building, CMD.MDProps.shallowReach, 9, out _, out _) > 0)
        {
            return;
        }

        if (CMD.MDProps.mineRock &&
            DeepDrillUtility.GetBaseResource(parent.Map, parent.TrueCenter().ToIntVec3()) == null)
        {
            Messages.Message("Prospecting.ManualDrillExhaustedNoFallback".Translate(), parent,
                             MessageTypeDefOf.TaskCompletion);
            return;
        }

        Messages.Message(
            "Prospecting.ManualDrillExhausted".Translate(Find.ActiveLanguageWorker.Pluralize(DeepDrillUtility
                                                                                             .GetBaseResource(parent.Map, parent.TrueCenter().ToIntVec3()).label)), parent,
            MessageTypeDefOf.TaskCompletion);
        building.SetForbidden(true);
    }
Ejemplo n.º 5
0
    public override string CompInspectStringExtra()
    {
        var progressMsg = "";
        var resMsg      = "\n";
        var weatherMsg  = "";

        if (drill.Spawned)
        {
            var drillpoint = drill.TrueCenter().ToIntVec3();
            if (prospected)
            {
                var resources = ManualDrillUtility.DrillCanGetToCount(drill, MDProps.shallowReach, 9, out _,
                                                                      out _);
                if (resources > 0)
                {
                    var resDef = drill.Map.deepResourceGrid.ThingDefAt(drillpoint);
                    if (resDef != null)
                    {
                        progressMsg = "ResourceBelow".Translate() + ": " + resDef.LabelCap + "\n" +
                                      "ProgressToNextPortion".Translate() + ": " +
                                      ProgressToNextPortionPercent.ToStringPercent("F0");
                        resMsg += "Prospecting.DeepResources".Translate(resources.ToString(),
                                                                        MDProps.shallowReach.ToStringPercent());
                    }
                }
                else
                {
                    var zero = 0;
                    progressMsg = "DeepDrillNoResources".Translate();
                    resMsg     += "Prospecting.DeepResources".Translate(zero.ToString(),
                                                                        MDProps.shallowReach.ToStringPercent());
                }
            }
            else
            {
                progressMsg = "Prospecting.DrillNotProspected".Translate() + "\n" +
                              "Prospecting.ProgressProspect".Translate() + ": " +
                              ProgressToProspectingPercent.ToStringPercent("F0");
                resMsg = "";
            }

            if (!windOk)
            {
                weatherMsg = "\n" + "Prospecting.InsufficientWind".Translate();
            }
            else if (UsedLastTick())
            {
                var roofpct = roofFactor / 1f;
                var windpct = windFactor / 1f;
                weatherMsg = "\n" + "Prospecting.RoofPerform".Translate(roofpct.ToStringPercent("F0")) + ", " +
                             "Prospecting.WindPerform".Translate(windpct.ToStringPercent("F0"));
            }
        }
        else
        {
            progressMsg = "Prospecting.InstallDrill".Translate();
            resMsg      = "";
        }

        return(progressMsg + resMsg + weatherMsg);
    }
Ejemplo n.º 6
0
 private bool GetNextManualResource(Building building, out ThingDef resDef, out int countPresent,
                                    out IntVec3 cell)
 {
     return(ManualDrillUtility.GetNextManualResource(building, building.TrueCenter().ToIntVec3(), building.Map,
                                                     out resDef, out countPresent, out cell));
 }
    protected override IEnumerable <Toil> MakeNewToils()
    {
        this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
        this.FailOnBurningImmobile(TargetIndex.A);
        this.FailOnThingHavingDesignation(TargetIndex.A, DesignationDefOf.Uninstall);
        this.FailOn(delegate
        {
            var compManualDrill = job.targetA.Thing.TryGetComp <CompManualDrill>();
            if (compManualDrill == null)
            {
                return(true);
            }

            if (!compManualDrill.prospected)
            {
                return(true);
            }

            if (!compManualDrill.windOk)
            {
                return(true);
            }

            var value = ManualDrillUtility.DrillCanGetToCount(job.targetA.Thing as Building,
                                                              compManualDrill.MDProps.shallowReach, 9, out _, out _) > 0;
            var baseRock = false;
            var thing    = job.targetA.Thing;
            if (thing?.Map != null)
            {
                baseRock = DeepDrillUtility.GetBaseResource(job.targetA.Thing.Map,
                                                            job.targetA.Thing.TrueCenter().ToIntVec3()) != null;
            }

            if (compManualDrill.MDProps.mineRock)
            {
                if (!value && !baseRock)
                {
                    return(true);
                }
            }
            else if (!value)
            {
                return(true);
            }

            return(false);
        });
        yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell));

        var work = new Toil();

        work.tickAction = delegate
        {
            var actor    = work.actor;
            var building = (Building)actor.CurJob.targetA.Thing;
            building.GetComp <CompManualDrill>().ManualDrillWorkDone(actor, building);
            actor.skills.Learn(SkillDefOf.Mining, 0.07f);
        };
        work.defaultCompleteMode = ToilCompleteMode.Never;
        if (Controller.Settings.AllowManualSound)
        {
            work.WithEffect(ProspectDef.PrsManualDrillEff, TargetIndex.A);
        }

        work.FailOnCannotTouch(TargetIndex.A, PathEndMode.InteractionCell);
        work.activeSkill = () => SkillDefOf.Mining;
        yield return(work);
    }