コード例 #1
0
        static bool Prefix(Mineable __instance, Map map, float yieldChance, bool moteOnWaste, Pawn pawn)
        {
            if (!Settings.MinedItemsAreDisabled)
            {
                var def = __instance.def;
                if (def.building.mineableThing != null && !(Rand.Value > def.building.mineableDropChance))
                {
                    int num = Mathf.Max(1, def.building.mineableYield);
                    if (def.building.mineableYieldWasteable)
                    {
                        num = Mathf.Max(1, GenMath.RoundRandom((float)num * (float)yieldPctFI.GetValue(__instance)));
                    }
                    Thing thing = ThingMaker.MakeThing(def.building.mineableThing);
                    thing.stackCount = num;
                    GenSpawn.Spawn(thing, __instance.Position, map);
                    if ((pawn == null || !pawn.Faction.IsPlayer) && thing.def.EverHaulable && !thing.def.designateHaulable)
                    {
                        thing.SetForbidden(value: true);
                    }
                }
                return(false);
            }

            return(true);
        }
コード例 #2
0
    public override void Start()
    {
        Mineable[] mineableObjects = GameObject.FindObjectsOfType <Mineable>();
        float      closestDist     = -1f;
        Mineable   closestMineable = null;
        var        beam            = controlledShip.GetComponent <MiningBeam>();

        foreach (var obj in mineableObjects)
        {
            if (obj.ResourceType == beam.MinedResource)
            {
                float dist = (controlledShip.transform.position - obj.transform.position).sqrMagnitude;
                if (closestMineable == null || dist < closestDist)
                {
                    closestMineable = obj;
                    closestDist     = dist;
                }
            }
        }

        if (closestMineable != null)
        {
            Succeed();
            targetFoundCallback(closestMineable);
        }
        else
        {
            Fail("NO TARGET FOUND");
        }
    }
コード例 #3
0
        public static void TrySpawnYield_Postfix(Mineable __instance, Map map, float yieldChance, bool moteOnWaste, Pawn pawn)
        {
            if (pawn?.story?.traits != null && pawn.story.traits.HasTrait(SyrTraitDefOf.SYR_KeenEye) && Rand.Value < FactorFromHilliness(map.TileInfo.hilliness))
            {
                ThingDef thingDef = DefDatabase <ThingDef> .AllDefs.RandomElementByWeightWithFallback(delegate(ThingDef d)
                {
                    if (d.building == null)
                    {
                        return(0f);
                    }
                    if (d.building.mineableYield < 5)
                    {
                        return(d.building.mineableScatterCommonality * 0.2f * d.building.mineableYield);
                    }
                    return(d.building.mineableScatterCommonality);
                }, null);

                int   num   = Mathf.Max(1, Mathf.RoundToInt(thingDef.building.mineableYield * Find.Storyteller.difficulty.mineYieldFactor * 0.2f * pawn.GetStatValue(StatDefOf.MiningYield, true)));
                Thing thing = ThingMaker.MakeThing(thingDef.building.mineableThing, null);
                thing.stackCount = num;
                GenSpawn.Spawn(thing, pawn.Position, map, WipeMode.Vanish);
                if ((pawn == null || !pawn.IsColonist) && thing.def.EverHaulable && !thing.def.designateHaulable)
                {
                    thing.SetForbidden(true, true);
                }
            }
        }
コード例 #4
0
        public int TileCount(bool onlyResources = false)
        {
            int cnt = 0;
            Map map = Find.AnyPlayerHomeMap;

            foreach (IntVec3 current in map.AllCells)
            {
                List <Thing> thingList = current.GetThingList(map);
                for (int i = 0; i < thingList.Count; i++)
                {
                    Mineable mineable = thingList[i] as Mineable;
                    if (mineable != null)
                    {
                        if (onlyResources && !isResource(mineable.def.building.mineableThing))
                        {
                            continue;
                        }
                        cnt++;
                        hint = "There is still some " + mineable.def.building.mineableThing.label + " to mine";
                    }
                }
            }
            Log.Message("Tile count: " + cnt);
            return(cnt);
        }
コード例 #5
0
        /// Convered into a transpiler.
        /// <summary>
        /// Adds extra materials to mined rock when the yield is over the default max.
        /// </summary>
        /// <param name="__instance">What was mined</param>
        /// <param name="___yieldPct">The max yield percentage</param>
        /// <param name="map">The map we are on</param>
        /// <param name="yieldChance">The chance to yield something (Ignored)</param>
        /// <param name="moteOnWaste">If we should do a mote on waste (Ignored)</param>
        /// <param name="pawn">The pawn mining</param>
        private static void CuteboldTrySpawnYieldMiningPostfix(Mineable __instance, float ___yieldPct, Map map, float yieldChance, bool moteOnWaste, Pawn pawn)
        {
            //Log.Message("CuteboldTrySapwnYieldMiningPostfix");

            if (pawn?.def.defName != Cutebold_Assemblies.RaceName || __instance == null || __instance.def.building.mineableThing == null || __instance.def.building.mineableDropChance < 1f || !__instance.def.building.mineableYieldWasteable)
            {
                return;
            }
            //if (pawn == null || pawn.def.defName != Cutebold_Assemblies.RaceName || __instance == null || __instance.def.building.mineableThing == null || __instance.def.building.mineableDropChance < 1f || !__instance.def.building.mineableYieldWasteable) return;

            //Log.Message("  Effective Mineable Yield="+ __instance.def.building.EffectiveMineableYield.ToString());
            //Log.Message("  Yield Percent=" + ___yieldPct.ToString());
            //Log.Message("  Mineable Thing=" + __instance.def.building.mineableThing.ToString());

            float extraPercent = CuteboldCalculateExtraPercent(StatDefOf.MiningYield, StatRequest.For(pawn));

            //Log.Message("  Pawn Additional Mining Percent=" + extraPercent);

            // Based on the RimWorld base code to allow for mining yield over 100% cause cutebolds are just that good at mining.
            if (___yieldPct >= 1f && extraPercent > 0f)
            {
                Thing minedMaterial = ThingMaker.MakeThing(__instance.def.building.mineableThing);
                minedMaterial.stackCount = GenMath.RoundRandom(__instance.def.building.EffectiveMineableYield * extraPercent);
// 1.1          minedMaterial.stackCount = GenMath.RoundRandom(__instance.def.building.mineableYield * extraPercent);
                GenPlace.TryPlaceThing(minedMaterial, __instance.Position, map, ThingPlaceMode.Near, ForbidIfNecessary);
            }

            void ForbidIfNecessary(Thing minedMaterial, int count)
            {
                if ((pawn == null || !pawn.IsColonist) && minedMaterial != null && minedMaterial.def.EverHaulable && !minedMaterial.def.designateHaulable)
                {
                    minedMaterial.SetForbidden(value: true, warnOnFail: false);
                }
            }
        }
コード例 #6
0
        private bool isMineableResourceSelected(out Mineable mineable)
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            var resourcesLayerMask = LayerMask.GetMask("Crystals");

            if (Physics.Raycast(ray, out hit, Mathf.Infinity, resourcesLayerMask))
            {
                Transform objectHit = hit.transform;

                if (hit.collider != null && hit.collider.gameObject != null)
                {
                    GameObject g = hit.collider.gameObject;
                    if (g.GetComponent <Mineable>() != null)
                    {
                        mineable = g.GetComponent <Mineable>();
                        return(true);
                    }
                }
            }

            mineable = null;
            return(false);
        }
コード例 #7
0
 static void Postfix(Mineable __instance, Map map, float yieldChance, bool moteOnWaste, Pawn pawn)
 {
     if (pawn is Pawn_Drone)
     {
         Patch_Pawn_IsColonist.overrideIsColonist = false;
     }
 }
コード例 #8
0
 void OnMineableTargetFound(Mineable target)
 {
     mineTargetOrder.AssignTarget(target);
     mineTargetOrder.Start();
     targetFound = true;
     Debug.Log("Target found");
 }
コード例 #9
0
    public static bool PreFix(ref Mineable __instance, ref float ___yieldPct, Map map, float yieldChance,
                              bool moteOnWaste, Pawn pawn)
    {
        if (__instance.def.building.mineableThing == null ||
            !(Rand.Value <= __instance.def.building.mineableDropChance) || !__instance.def.building.isResourceRock)
        {
            return(true);
        }

        var num = Mathf.Max(1,
                            Mathf.RoundToInt(
                                __instance.def.building.mineableYield * Find.Storyteller.difficulty.mineYieldFactor));

        if (__instance.def.building.mineableYieldWasteable)
        {
            num = Mathf.Max(1, GenMath.RoundRandom(num * ___yieldPct));
        }

        var thing = ThingMaker.MakeThing(__instance.def.building.mineableThing);

        if (num > thing.def.stackLimit)
        {
            num = thing.def.stackLimit;
        }

        thing.stackCount = num;
        GenSpawn.Spawn(thing, __instance.Position, map);
        if ((pawn == null || !pawn.IsColonist) && thing.def.EverHaulable && !thing.def.designateHaulable)
        {
            thing.SetForbidden(true);
        }

        return(false);
    }
コード例 #10
0
    private void ActivateMiningOn(Mineable mineable)
    {
        Debug.DrawLine(transform.position, shipControllerInput.CurrentPilot.targetedPosition + (Vector2)transform.position);
        mineBuffer[(uint)mineableResource] += miningStrength * Time.deltaTime;
        if (mineBuffer[(uint)mineableResource] >= 1f)
        {
            uint minedInBuffer = (uint)Mathf.FloorToInt(mineBuffer[(uint)mineableResource]);
            mineBuffer[(uint)mineableResource] -= minedInBuffer;

            uint mined = mineable.Mine((uint)mineableResource, minedInBuffer);
            if (!cargo.AddResource((uint)mineableResource, mined))
            {
                Debug.LogWarning("Warning - Not enough cargo to fit mined resources ! Yield has been lost.");
            }
        }
        if (!activatedLastFrame)
        {
            activatedLastFrame = true;
            OnActivation(shipControllerInput.CurrentPilot.targetedPosition + (Vector2)transform.position, mineable.gameObject);
        }
        else
        {
            OnRunning(shipControllerInput.CurrentPilot.targetedPosition + (Vector2)transform.position, mineable.gameObject);
        }
    }
コード例 #11
0
 public void StopMiner()
 {
     if (_process != null)
     {
         try
         {
             _process.CloseMainWindow();
         }
         catch (Exception ex)
         {
             Console.WriteLine("Couldn't close miner process: " + ex.Message);
         }
         try
         {
             if (!_process.HasExited)
             {
                 _process.Kill();
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine("Couldn't kill miner process: " + ex.Message);
         }
         _process.Dispose();
         _process  = null;
         _mineable = null;
     }
     if (_cpuMiner != null)
     {
         _cpuMiner.StopMiner();
         _cpuMiner = null;
     }
 }
コード例 #12
0
        public override AcceptanceReport CanDesignateCell(IntVec3 c)
        {
            if (!GenGrid.InBounds(c, base.Map))
            {
                return(false);
            }
            if (base.Map.designationManager.DesignationAt(c, DesignationDefOf.Mine) != null)
            {
                return(AcceptanceReport.WasRejected);
            }
            if (GridsUtility.Fogged(c, base.Map))
            {
                return(true);
            }
            Mineable firstMineable = GridsUtility.GetFirstMineable(c, base.Map);

            if (firstMineable == null)
            {
                return(Translator.Translate("MessageMustDesignateMineable"));
            }
            AcceptanceReport result = this.CanDesignateThing(firstMineable);

            if (result.Accepted)
            {
                return(AcceptanceReport.WasAccepted);
            }
            return(result);
        }
コード例 #13
0
        public bool IsValidMiningTarget(Mineable target)
        {
            // mineable
            return(target != null &&
                   target.def.mineable

                   // allowed
                   && AllowedMineral(target.def)

                   // discovered
                   // NOTE: also in IsReachable, but we expect a lot of fogged tiles, so move this check up a bit.
                   && !target.Position.Fogged(manager.map)

                   // not yet designated
                   && manager.map.designationManager.DesignationOn(target) == null

                   // matches settings
                   && IsInAllowedArea(target) &&
                   IsRelevantMiningTarget(target) &&
                   !IsARoomDivider(target)
                   &&
                   !IsARoofSupport_Basic(
                       target)  // note, returns true if advanced checking is enabled - checks will then be done before designating

                   // can be reached
                   && IsReachable(target));
        }
コード例 #14
0
 //Mineable
 public static void DestroyMined(Mineable __instance, Pawn pawn)
 {
     if (Find.World.GetComponent <WorldComponent_Uvhash>() is WorldComponent_Uvhash uvhashComp &&
         !uvhashComp.SpawnedCrystal && __instance.def == UvhashDefOf.Uvhash_Bloodstone)
     {
         uvhashComp.DecrementCellsUntilCrystalCount(pawn);
     }
 }
コード例 #15
0
 public override void OnDestroyMined(Mineable block, Pawn actor)
 {
     count = -1;
     if (targetTiles <= 0)
     {
         Complete();
     }
 }
コード例 #16
0
 public MineTarget(GameObject ship) : base(ship)
 {
     target                      = null;
     miningRange                 = controlledShip.GetComponent <MiningBeam>().Range;
     goToOrder                   = new GoToOrder(ship);
     goToOrder.OnStateFailed    += GoToOrder_OnStateFailed;
     goToOrder.OnStateSucceeded += GoToOrder_OnStateSucceeded;
 }
コード例 #17
0
    public MineTarget(GameObject ship, Mineable target) : base(ship)
    {
        this.target = target;
        miningRange = controlledShip.GetComponent <MiningBeam>().Range;

        goToOrder = new GoToOrder(ship, target.transform.position, miningRange);
        goToOrder.OnStateFailed    += GoToOrder_OnStateFailed;
        goToOrder.OnStateSucceeded += GoToOrder_OnStateSucceeded;
    }
コード例 #18
0
        public double GetReward(Profit profit, Mineable mineable, ProfitTimeframe timeframe)
        {
            double reward = 0;

            if (profit.CoinRewardDay > 0 && profit.CoinRewardLive > 0)
            {
                reward = profit.CoinRewardLive / profit.CoinRewardDay;
            }
            return(reward);
        }
コード例 #19
0
        public override void OnDestroyMined(Mineable block, Pawn actor)
        {
            if (actor != null && actor.Faction.IsPlayer)
            {
                progress++;
            }

            if (progress >= def.targetValue)
            {
                Complete();
            }
        }
コード例 #20
0
 private static void StopMiner()
 {
     if (_currentMiner != null)
     {
         Log.Information($"Stopping {_currentMiner.Name}.");
     }
     _watchdogCts?.Cancel();
     _currentMiner?.StopMiner();
     _currentMiner      = null;
     _currentMineable   = null;
     _watchdogOvershots = 0;
 }
コード例 #21
0
        public void StopMiner()
        {
            if (_process != null)
            {
                try
                {
                    _process.CloseMainWindow();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Couldn't close miner process: " + ex.Message);
                }
                try
                {
                    if (!_process.HasExited)
                    {
                        _process.Kill();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Couldn't kill miner process: " + ex.Message);
                }

                _process.Dispose();
                _process = null;

                if (Helpers.IsLinux())
                {
                    try
                    {
                        var killProcess = new Process();
                        killProcess.StartInfo.FileName = "x-terminal-emulator";
                        string xmrName = Path.GetFileName(_mineable.XmrStakPath);
                        Console.WriteLine("Kill: " + xmrName);
                        killProcess.StartInfo.Arguments              = $"-e \"killall -9 {xmrName}\"";
                        killProcess.StartInfo.UseShellExecute        = true;
                        killProcess.StartInfo.CreateNoWindow         = false;
                        killProcess.StartInfo.RedirectStandardOutput = false;
                        killProcess.Start();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Couldn't kill process: " + ex.Message);
                    }
                }


                _mineable = null;
            }
        }
コード例 #22
0
        public static Mineable GetFirstMineable(this IntVec3 c, Map map)
        {
            List <Thing> thingList = c.GetThingList(map);

            for (int i = 0; i < thingList.Count; i++)
            {
                Mineable mineable = thingList[i] as Mineable;
                if (mineable != null)
                {
                    return(mineable);
                }
            }
            return(null);
        }
コード例 #23
0
        private static void StartMiner(Mineable mineable, Settings settings, string appRoot, DirectoryInfo appRootFolder)
        {
            var differenceToLastProfitSwitch = DateTimeOffset.Now.Subtract(_lastProfitSwitch).TotalSeconds;

            if (differenceToLastProfitSwitch > settings.ProfitSwitchCooldown)
            {
                StopMiner();

                _currentMineable = mineable;

                ExecuteScript(mineable.PrepareScript, appRoot);

                _currentMiner     = MinerFactory.GetMiner(mineable.Miner);
                _lastProfitSwitch = DateTimeOffset.Now;

                try
                {
                    Log.Information($"Starting {_currentMiner.Name} with {mineable.DisplayName}.");
                    _currentMiner.StartMiner(mineable, settings, appRoot, appRootFolder);
                }
                catch (Exception ex)
                {
                    Log.Warning("Couldn't start miner: " + ex);
                    ResetApp(settings, appRoot, false);
                }

                if (_manualWatchdogEnabled.HasValue)
                {
                    if (_manualWatchdogEnabled.Value)
                    {
                        _watchdogCts?.Cancel();
                        _watchdogCts = new CancellationTokenSource();
                        var watchdogTask = WatchdogTaskAsync(settings, appRoot, appRootFolder, _watchdogCts.Token);
                    }
                }
                else
                {
                    if (settings.EnableWatchdog)
                    {
                        _watchdogCts?.Cancel();
                        _watchdogCts = new CancellationTokenSource();
                        var watchdogTask = WatchdogTaskAsync(settings, appRoot, appRootFolder, _watchdogCts.Token);
                    }
                }
            }
            else
            {
                Console.WriteLine($"Didn't switched to {mineable.DisplayName}! Waiting {settings.ProfitSwitchCooldown} seconds to cooldown.");
            }
        }
コード例 #24
0
 public static bool Prefix(MethodBase __originalMethod, Mineable __instance, Map map, float yieldChance, bool moteOnWaste, Pawn pawn)
 {
     if (pawn != null)
     {
         if (!pawn.IsColonist)
         {
             if (pawn.ThingID.StartsWith("RPP_Bot_"))
             {
                 __originalMethod.Invoke(__instance, new object[] { map, yieldChance, moteOnWaste, tempPawn });
                 return(false);
             }
         }
     }
     return(true);
 }
コード例 #25
0
        private void tellSelectedUnitsToGoMine(Mineable mineable)
        {
            foreach (PlayerUnit u in selectedUnits)
            {
                if (u.GetComponent <Miner>() == null)
                {
                    return;
                }

                u.ClearTaskList();

                if ((mineable is MineableCrystal))
                {
                    u.AddTask(u.gameObject.AddComponent <CrystalMinerTask>().SetMaxResource(9999).SetSelected((MineableCrystal)mineable));
                }
            }
        }
コード例 #26
0
        public double GetReward(Profit profit, Mineable mineable, ProfitTimeframe timeframe)
        {
            timeframe = mineable.OverrideProfitTimeframe.HasValue ? mineable.OverrideProfitTimeframe.Value : timeframe;
            double reward = 0;

            switch (timeframe)
            {
            case ProfitTimeframe.Day:
                reward = profit.UsdRewardDay;
                break;

            default:
                reward = profit.UsdRewardLive;
                break;
            }
            return(reward);
        }
コード例 #27
0
    private void DestroyBlock()
    {
        if (!_areControlsLocked)
        {
            // Raycast for break block
            RaycastHit hit;
            Physics.Raycast(transform.position, transform.forward, out hit, _interactDistance);

            if (hit.collider != null)
            {
                Mineable mineable = hit.collider.gameObject.GetComponent <Mineable>();
                if (mineable != null)
                {
                    Destroy(hit.collider.transform.parent.gameObject);
                }
            }
        }
    }
コード例 #28
0
    private void tryAcquireTarget()
    {
        // find closest asteroid
        Mineable[] asteroids = FindObjectsOfType<Mineable>();
        float minDistance = float.MaxValue;
        _target = null;
        foreach (Mineable target in asteroids)
        {
            float distance = (target.transform.position - transform.position).sqrMagnitude;
            if (distance < minDistance)
            {
                _target = target;
                minDistance = distance;
            }
        }

        // if it's too far away, don't start mining
        if (minDistance > _sqMiningDistance) _target = null;
    }
コード例 #29
0
        private static string GeneratePoolConfigJson(Mineable mineable)
        {
            var dict = new Dictionary <string, object>();

            dict["pools"] = new Dictionary <string, object>[]
            {
                new Dictionary <string, object>
                {
                    { "pool", mineable.PoolAddress },
                    { "wallet", mineable.PoolWalletAddress },
                    { "password", mineable.PoolPassword },
                    { "nicehash", mineable is NicehashAlgorithm },
                    { "pool_use_tls", mineable.PoolUseTls },
                    { "worker", mineable.PoolRigId },
                }
            };

            return(JsonConvert.SerializeObject(dict, Formatting.Indented));
        }
コード例 #30
0
        public MineableRewardResult GetBestPoolminedCoin(IList <Coin> coins, Mineable currentMineable, Dictionary <ProfitProvider, Dictionary <string, Profit> > poolProfitsDictionary, Settings settings)
        {
            MineableReward currentReward           = null;
            Coin           bestPoolminedCoin       = null;
            double         bestPoolminedCoinProfit = 0;

            foreach (var coin in coins.Where(c => c.IsEnabled()))
            {
                var    profit     = Helpers.GetPoolProfitForCoin(coin, poolProfitsDictionary, settings);
                double reward     = GetReward(profit, coin, settings.ProfitTimeframe);
                double calcProfit = coin.PreferFactor.HasValue ? reward * coin.PreferFactor.Value : reward;
                if (currentMineable != null && coin.Id == currentMineable.Id)
                {
                    currentReward = new MineableReward(currentMineable, calcProfit);
                }
                if (bestPoolminedCoin == null || calcProfit > bestPoolminedCoinProfit)
                {
                    bestPoolminedCoinProfit = calcProfit;
                    bestPoolminedCoin       = coin;
                }
            }
            return(new MineableRewardResult(new MineableReward(bestPoolminedCoin, bestPoolminedCoinProfit), currentReward));
        }
コード例 #31
0
    public static void PostFix(ref Mineable __instance, Map map, float yieldChance, bool moteOnWaste, Pawn pawn)
    {
        if (map == null || pawn == null || !ProspectingUtility.IsValidToIndicate(__instance, map))
        {
            return;
        }

        var mining      = 0;
        var skills      = pawn.skills;
        var miningSkill = skills?.GetSkill(SkillDefOf.Mining) != null;

        if (miningSkill)
        {
            mining = pawn.skills.GetSkill(SkillDefOf.Mining).Level / 4;
        }

        var chance = (int)(Controller.Settings.BaseChance + mining);

        if (ProspectingUtility.Rnd100() <= chance &&
            ProspectingUtility.ProspectCandidate(map, __instance.Position, out var def))
        {
            ProspectingUtility.YieldExtra(pawn, def);
        }
    }