public override void ProcessPacket(VegeMinedPacket packet, NebulaConnection conn) { if (GameMain.galaxy.PlanetById(packet.PlanetId)?.factory != null && GameMain.galaxy.PlanetById(packet.PlanetId)?.factory?.vegePool != null) { using (Multiplayer.Session.Planets.IsIncomingRequest.On()) { PlanetFactory factory = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory; if (packet.Amount == 0 && factory != null) { if (packet.IsVein) { VeinData veinData = factory.GetVeinData(packet.VegeId); VeinProto veinProto = LDB.veins.Select((int)veinData.type); factory.RemoveVeinWithComponents(packet.VegeId); if (veinProto != null) { VFEffectEmitter.Emit(veinProto.MiningEffect, veinData.pos, Maths.SphericalRotation(veinData.pos, 0f)); VFAudio.Create(veinProto.MiningAudio, null, veinData.pos, true, 0, -1, -1L); } } else { VegeData vegeData = factory.GetVegeData(packet.VegeId); VegeProto vegeProto = LDB.veges.Select(vegeData.protoId); factory.RemoveVegeWithComponents(packet.VegeId); if (vegeProto != null) { VFEffectEmitter.Emit(vegeProto.MiningEffect, vegeData.pos, Maths.SphericalRotation(vegeData.pos, 0f)); VFAudio.Create(vegeProto.MiningAudio, null, vegeData.pos, true, 0, -1, -1L); } } } else if (factory != null) { VeinData veinData = factory.GetVeinData(packet.VegeId); PlanetData.VeinGroup[] veinGroups = factory.planet.veinGroups; short groupIndex = veinData.groupIndex; // must be a vein/oil patch (i think the game treats them same now as oil patches can run out too) factory.veinPool[packet.VegeId].amount = packet.Amount; factory.planet.veinAmounts[(int)veinData.type] -= 1L; veinGroups[groupIndex].amount = veinGroups[groupIndex].amount - 1L; } else { Log.Warn("Received VegeMinedPacket but could not do as i was told :C"); } } } }
// This function is based on PlayerAction_Mine.GameTick public void DroneGameTick() { double powerFactor = 0.01666666753590107; PlanetFactory factory = this.player.factory; if (factory == null) { // This has only been seen briefly when the Render Distance mod is transitioning to or from a planet view. return; } double miningEnergyCost = this.player.mecha.miningPower * powerFactor; double energyAvailable; float fractionOfEnergyAvailable; this.player.mecha.QueryEnergy(miningEnergyCost, out energyAvailable, out fractionOfEnergyAvailable); int miningTime = (int)(this.player.mecha.miningSpeed * configSpeedScaleFactor * fractionOfEnergyAvailable * 10000f + 0.49f); VegeData vegeData = factory.GetVegeData(this.miningId); this.miningProtoId = (int)vegeData.protoId; VegeProto vegeProto = LDB.veges.Select((int)vegeData.protoId); if (vegeProto != null) { this.miningTick += miningTime; this.player.mecha.coreEnergy -= energyAvailable; this.player.mecha.MarkEnergyChange(5, -miningEnergyCost); this.percent = Mathf.Clamp01((float)((double)this.miningTick / (double)(vegeProto.MiningTime * 10000))); if (this.miningTick >= vegeProto.MiningTime * 10000) { System.Random random = new System.Random(vegeData.id + ((this.player.planetData.seed & 16383) << 14)); bool inventoryOverflowFlag = false; int popupQueueIndex = 0; for (int itemIdx = 0; itemIdx < vegeProto.MiningItem.Length; itemIdx++) { float randomMiningChance = (float)random.NextDouble(); if (randomMiningChance < vegeProto.MiningChance[itemIdx]) { int minedItem = vegeProto.MiningItem[itemIdx]; int minedItemCount = (int)((float)vegeProto.MiningCount[itemIdx] * (vegeData.scl.y * vegeData.scl.y) + 0.5f); if (minedItemCount > 0 && LDB.items.Select(minedItem) != null) { int inventoryOverflowCount = this.player.package.AddItemStacked(minedItem, minedItemCount); if (inventoryOverflowCount != 0) { UIItemup.Up(minedItem, inventoryOverflowCount); UIRealtimeTip.PopupItemGet(minedItem, inventoryOverflowCount, vegeData.pos + vegeData.pos.normalized, popupQueueIndex++); } else // Unable to fit all items { inventoryOverflowFlag = true; } } } } VFEffectEmitter.Emit(vegeProto.MiningEffect, vegeData.pos, vegeData.rot); VFAudio.Create(vegeProto.MiningAudio, null, vegeData.pos, true); factory.RemoveVegeWithComponents(vegeData.id); GameMain.gameScenario.NotifyOnVegetableMined((int)vegeData.protoId); this.miningType = EObjectType.Entity; // This change will cause the mission to be completed. this.miningId = 0; if (inventoryOverflowFlag) { //Logger.LogInfo("Inventory overflow detected."); } this.miningTick = 0; } } else { //Logger.LogInfo("null vegeProto. Icarus likely removed clearing target."); this.miningType = EObjectType.Entity; // This change will cause the mission to be completed. this.miningId = 0; this.miningTick = 0; this.percent = 0f; factory.RemoveVegeWithComponents(vegeData.id); } }