protected override void ServerUpdate(ServerUpdateData data) { var privateState = data.PrivateState; var manufacturingState = privateState.ManufacturingState; var worldObject = data.GameObject; // update active recipe ManufacturingMechanic.UpdateRecipeOnly( worldObject, manufacturingState, this.ManufacturingConfig); var hasActiveRecipe = manufacturingState.HasActiveRecipe; bool isActive; var fuelBurningState = privateState.FuelBurningState; if (fuelBurningState == null) { // no fuel burning state - always active isActive = true; } else { // progress fuel burning FuelBurningMechanic.Update( worldObject, fuelBurningState, privateState.FuelBurningByproductsQueue, this.ManufacturingConfig, data.DeltaTime, isNeedFuelNow: hasActiveRecipe && !manufacturingState.CraftingQueue.IsContainerOutputFull); // active only when fuel is burning isActive = fuelBurningState.FuelUseTimeRemainsSeconds > 0; } data.PublicState.IsManufacturingActive = isActive; if (isActive && hasActiveRecipe) { // progress crafting ManufacturingMechanic.UpdateCraftingQueueOnly( manufacturingState, data.DeltaTime); // it's important to synchronize this property here // (because rollback might happen due to unable to spawn output items and container hash will be changed) // TODO: this is hack and we need a better way to track whether the container was actually changed or a better way to update the last state hash. manufacturingState.ContainerOutputLastStateHash = manufacturingState.CraftingQueue.ContainerOutputLastStateHash; } }
protected override void ServerUpdate(ServerUpdateData data) { var privateState = data.PrivateState; var publicState = data.PublicState; var liquidContainerState = privateState.LiquidState; var isFull = liquidContainerState.Amount >= this.LiquidContainerConfig.Capacity; ManufacturingMechanic.UpdateRecipeOnly( data.GameObject, privateState.ManufacturingState, this.ManufacturingConfig, force: !isFull); ManufacturingMechanic.UpdateCraftingQueueOnly( privateState.ManufacturingState, deltaTime: data.DeltaTime); // refill liquid LiquidContainerSystem.UpdateWithoutManufacturing( liquidContainerState, this.LiquidContainerConfig, data.DeltaTime, isProduceLiquid: false, wasUsed: out _, isUseRequested: publicState.IsActive, resetAmountToZeroWhenNotEnoughToUse: true); var isActive = publicState.ElectricityProducerState == ElectricityProducerState.PowerOnActive && privateState.LiquidState.Amount > 0; var fuelBurningState = privateState.FuelBurningState; if (fuelBurningState is not null) { // progress fuel burning FuelBurningMechanic.Update( data.GameObject, fuelBurningState, privateState.FuelBurningByproductsQueue, this.ManufacturingConfig, data.DeltaTime, byproductsQueueRate: 1, isNeedFuelNow: publicState.ElectricityProducerState == ElectricityProducerState.PowerOnActive && privateState.LiquidState.Amount > 0); // active only when fuel is burning isActive = fuelBurningState.FuelUseTimeRemainsSeconds > 0; } publicState.IsActive = isActive; }
protected override void ServerUpdate(ServerUpdateData data) { var worldObject = data.GameObject; var privateState = data.PrivateState; var objectDeposit = this.SharedGetDepositWorldObject(worldObject.OccupiedTile); if (objectDeposit == null) { // no deposit object - stop progressing privateState.LiquidContainerState.Amount = 0; privateState.FuelBurningState.FuelUseTimeRemainsSeconds = 0; return; } var fuelBurningState = privateState.FuelBurningState; // Please note: fuel is used only to produce oil. // Fuel is not used for "petroleum canister" crafting. var isFull = privateState.LiquidContainerState.Amount >= this.LiquidContainerConfig.Capacity; FuelBurningMechanic.Update( worldObject, fuelBurningState, null, this.ManufacturingConfig, data.DeltaTime, isNeedFuelNow: !isFull); var isFuelBurning = fuelBurningState.FuelUseTimeRemainsSeconds > 0; data.PublicState.IsManufacturingActive = isFuelBurning; LiquidContainerSystem.UpdateWithManufacturing( worldObject, data.PrivateState.LiquidContainerState, this.LiquidContainerConfig, data.PrivateState.ManufacturingState, this.ManufacturingConfig, data.DeltaTime, // the pump produce petroleum only when fuel is burning isProduceLiquid: isFuelBurning, forceUpdateRecipe: true); }
protected override void ServerUpdate(ServerUpdateData data) { var privateState = data.PrivateState; var manufacturingState = privateState.ManufacturingState; var worldObject = data.GameObject; // update active recipe ManufacturingMechanic.UpdateRecipeOnly( worldObject, manufacturingState, this.ManufacturingConfig); var hasActiveRecipe = manufacturingState.HasActiveRecipe; var isActive = false; var fuelBurningState = privateState.FuelBurningState; if (fuelBurningState is null) { // no fuel burning state if (this.ElectricityConsumptionPerSecondWhenActive <= 0) { // no fuel burning and no electricity consumption - always active isActive = true; } else { // Consuming electricity. // Active only if electricity state is on and has active recipe. var publicState = data.PublicState; if (publicState.ElectricityConsumerState == ElectricityConsumerState.PowerOnActive) { isActive = hasActiveRecipe && !manufacturingState.CraftingQueue.IsContainerOutputFull; } } } else { // progress fuel burning FuelBurningMechanic.Update( worldObject, fuelBurningState, privateState.FuelBurningByproductsQueue, this.ManufacturingConfig, deltaTime: data.DeltaTime, byproductsQueueRate: StructureConstants.ManufacturingSpeedMultiplier, isNeedFuelNow: hasActiveRecipe && !manufacturingState.CraftingQueue.IsContainerOutputFull); // active only when fuel is burning isActive = fuelBurningState.FuelUseTimeRemainsSeconds > 0; } data.PublicState.IsActive = isActive; if (isActive && hasActiveRecipe) { // progress crafting ManufacturingMechanic.UpdateCraftingQueueOnly( manufacturingState, deltaTime: data.DeltaTime * StructureConstants.ManufacturingSpeedMultiplier * this.ManufacturingSpeedMultiplier); // it's important to synchronize this property here // (because rollback might happen due to unable to spawn output items and container hash will be changed) // TODO: this is hack and we need a better way to track whether the container was actually changed or a better way to update the last state hash. manufacturingState.ContainerOutputLastStateHash = manufacturingState.CraftingQueue.ContainerOutputLastStateHash; } }
protected override void ServerUpdate(ServerUpdateData data) { var worldObject = data.GameObject; var privateState = data.PrivateState; var objectDeposit = this.SharedGetDepositWorldObject(worldObject.OccupiedTile); var isPvEserver = PveSystem.ServerIsPvE; var fuelBurningState = privateState.FuelBurningState; if (objectDeposit == null && !isPvEserver) { // no deposit object - stop progressing privateState.LiquidContainerState.Amount = 0; if (fuelBurningState != null) { fuelBurningState.FuelUseTimeRemainsSeconds = 0; } return; } var deltaTime = data.DeltaTime; var deltaTimeForManufacturing = deltaTime; if (objectDeposit == null && isPvEserver) { // On PvE servers extractors work on reduced speed // if there is no deposit (the extractor built by player anywhere). deltaTimeForManufacturing *= PveSystem.DepositExtractorWithoutDepositActionSpeedMultiplier; } else if (objectDeposit != null && !isPvEserver && objectDeposit.ProtoStaticWorldObject is IProtoObjectDeposit protoObjectDeposit && protoObjectDeposit.LifetimeTotalDurationSeconds <= 0) { // Public extractor (for infinite deposit) in PvP. Much faster extraction. deltaTimeForManufacturing *= PublicExtractorSpeedMultiplierInPvP; } // apply extraction rate multiplier deltaTimeForManufacturing *= StructureConstants.ManufacturingSpeedMultiplier; var isActive = false; var isFull = privateState.LiquidContainerState.Amount >= this.LiquidContainerConfig.Capacity; if (fuelBurningState == null) { // no fuel burning state if (this.ElectricityConsumptionPerSecondWhenActive <= 0) { // no fuel burning and no electricity consumption - always active isActive = true; } else { // Consuming electricity. // Active only if electricity state is on and has active recipe. var publicState = data.PublicState; if (publicState.ElectricityConsumerState == ElectricityConsumerState.PowerOn) { isActive = !isFull; } } } else { // Please note: fuel is used only to produce oil. // Fuel is not used for "petroleum canister" crafting. FuelBurningMechanic.Update( worldObject, fuelBurningState, byproductsCraftQueue: null, this.ManufacturingConfig, deltaTime, byproductsQueueRate: 1, isNeedFuelNow: !isFull); var isFuelBurning = fuelBurningState.FuelUseTimeRemainsSeconds > 0; isActive = isFuelBurning; } data.PublicState.IsActive = isActive; LiquidContainerSystem.UpdateWithManufacturing( worldObject, data.PrivateState.LiquidContainerState, this.LiquidContainerConfig, data.PrivateState.ManufacturingState, this.ManufacturingConfig, deltaTimeForManufacturing, // the pump produce petroleum only when active isProduceLiquid: data.PublicState.IsActive, forceUpdateRecipe: true); }
protected override void ServerUpdate(ServerUpdateData data) { var privateState = data.PrivateState; var publicState = data.PublicState; var liquidContainerState = privateState.LiquidState; var isFull = liquidContainerState.Amount >= this.LiquidContainerConfig.Capacity; ManufacturingMechanic.UpdateRecipeOnly( data.GameObject, privateState.ManufacturingState, this.ManufacturingConfig, force: !isFull); ManufacturingMechanic.UpdateCraftingQueueOnly( privateState.ManufacturingState, deltaTime: data.DeltaTime); // refill liquid LiquidContainerSystem.UpdateWithoutManufacturing( liquidContainerState, this.LiquidContainerConfig, data.DeltaTime, isProduceLiquid: false, wasUsed: out _, isUseRequested: privateState.CurrentTemperature >= SteamTemperatureGenerationStart, resetAmountToZeroWhenNotEnoughToUse: true); var isActive = privateState.LiquidState.Amount > 0; var fuelBurningState = privateState.FuelBurningState; if (fuelBurningState != null) { // progress fuel burning FuelBurningMechanic.Update( data.GameObject, fuelBurningState, privateState.FuelBurningByproductsQueue, this.ManufacturingConfig, data.DeltaTime * FuelBurningSpeedMultiplier, byproductsQueueRate: 1, isNeedFuelNow: publicState.ElectricityProducerState == ElectricityProducerState.PowerOnActive && privateState.LiquidState.Amount > 0); // active only when fuel is burning isActive = fuelBurningState.FuelUseTimeRemainsSeconds > 0; } publicState.IsActive = isActive; // update the temperature var temperature = privateState.CurrentTemperature; var delta = isActive ? (float)(SteamTemperatureIncreasePerSecond * data.DeltaTime) : -(float)(SteamTemperatureDecreasePerSecond * data.DeltaTime); // apply some variance in temperature gain delta *= RandomHelper.Range(0.8f, 1.2f); temperature += delta; privateState.CurrentTemperature = MathHelper.Clamp(temperature, SteamTemperatureMin, SteamTemperatureMax); }
protected override void ServerUpdate(ServerUpdateData data) { var worldObject = data.GameObject; var privateState = data.PrivateState; var objectDepletedDeposit = ObjectDepletedDeposit.SharedGetDepletedDepositWorldObject(worldObject.OccupiedTile); var objectDeposit = this.SharedGetDepositWorldObject(worldObject.OccupiedTile); var fuelBurningState = privateState.FuelBurningState; if (objectDepletedDeposit is not null) { // this is a depleted deposit - stop extraction data.PublicState.IsActive = false; privateState.LiquidContainerState.Amount = 0; if (fuelBurningState is not null) { fuelBurningState.FuelUseTimeRemainsSeconds = 0; } return; } var isActive = false; var isFull = privateState.LiquidContainerState.Amount >= this.LiquidContainerConfig.Capacity; if (fuelBurningState is null) { // no fuel burning state if (this.ElectricityConsumptionPerSecondWhenActive <= 0) { // no fuel burning and no electricity consumption - always active isActive = true; } else { // Consuming electricity. // Active only if electricity state is on and has active recipe. var publicState = data.PublicState; if (publicState.ElectricityConsumerState == ElectricityConsumerState.PowerOnActive) { isActive = !isFull; } } } else { // Please note: fuel is used only to produce oil. // Fuel is not used for "petroleum canister" crafting. FuelBurningMechanic.Update( worldObject, fuelBurningState, byproductsCraftQueue: null, this.ManufacturingConfig, data.DeltaTime * FuelBurningSpeedMultiplier, byproductsQueueRate: 1, isNeedFuelNow: !isFull); var isFuelBurning = fuelBurningState.FuelUseTimeRemainsSeconds > 0; isActive = isFuelBurning; } data.PublicState.IsActive = isActive; LiquidContainerSystem.UpdateWithManufacturing( worldObject, data.PrivateState.LiquidContainerState, this.LiquidContainerConfig, data.PrivateState.ManufacturingState, this.ManufacturingConfig, data.DeltaTime * SharedGetSpeedMultiplier(objectDeposit), // the pump produce petroleum only when active isProduceLiquid: data.PublicState.IsActive, forceUpdateRecipe: true); }
protected override void ServerUpdate(ServerUpdateData data) { var worldObject = data.GameObject; var deltaTime = data.DeltaTime; var privateState = data.PrivateState; var fuelBurningState = privateState.FuelBurningState; var manufacturingStateRawPetroleum = data.PrivateState.ManufacturingState; var manufacturingStateProcessedGasoline = data.PrivateState.ManufacturingStateGasoline; var manufacturingStateProcessedMineralOil = data.PrivateState.ManufacturingStateMineralOil; var liquidStateRawPetroleum = privateState.LiquidStateRawPetroleum; var liquidStateProcessedGasoline = privateState.LiquidStateGasoline; var liquidStateProcessedMineralOil = privateState.LiquidStateMineralOil; // Force update all recipes: // it will auto-detect and verify current recipes for every crafting queue. var isLiquidStatesChanged = privateState.IsLiquidStatesChanged; ManufacturingMechanic.UpdateRecipeOnly( worldObject, manufacturingStateRawPetroleum, this.ManufacturingConfig, force: isLiquidStatesChanged); ManufacturingMechanic.UpdateRecipeOnly( worldObject, manufacturingStateProcessedGasoline, this.ManufacturingConfigGasoline, force: isLiquidStatesChanged); ManufacturingMechanic.UpdateRecipeOnly( worldObject, manufacturingStateProcessedMineralOil, this.ManufacturingConfigMineralOil, force: isLiquidStatesChanged); privateState.IsLiquidStatesChanged = false; // Update fuel state: // need fuel when processed liquids capacities are not full // or any of the manufacturing states has active recipe. var isLiquidsCapacitiesFull = liquidStateProcessedGasoline.Amount >= this.LiquidConfigGasoline.Capacity && liquidStateProcessedMineralOil.Amount >= this.LiquidConfigMineralOil.Capacity; var isNeedFuelNow = (!isLiquidsCapacitiesFull && liquidStateRawPetroleum.Amount > 0) || manufacturingStateProcessedGasoline.HasActiveRecipe || manufacturingStateProcessedMineralOil.HasActiveRecipe; // update fuel burning progress FuelBurningMechanic.Update( worldObject, fuelBurningState, privateState.FuelBurningByproductsQueue, this.ManufacturingConfig, data.DeltaTime, isNeedFuelNow, forceRefreshFuel: isLiquidStatesChanged); var isFuelBurning = fuelBurningState.FuelUseTimeRemainsSeconds > 0; // set IsActive flag in public state - this is used to play sound and animation on client data.PublicState.IsManufacturingActive = isFuelBurning; // Update crafting queue for raw petroleum: // on complete it will consume petroleum canister (if available), increase oil level, produce empty canister. ManufacturingMechanic.UpdateCraftingQueueOnly(manufacturingStateRawPetroleum, deltaTime); if (!isFuelBurning) { // cannot progress while fuel is not burning return; } // fuel is burning, we can "transfer" liquids and progress crafting queues for processed liquids // try transfer ("use") raw petroleum bar LiquidContainerSystem.UpdateWithoutManufacturing( liquidStateRawPetroleum, this.LiquidConfigRawPetroleum, deltaTime, // petroleum is not produced via this system (it's produced on recipe completion) isProduceLiquid: false, // use petroleum liquid if other capacities are not full isUseRequested: !isLiquidsCapacitiesFull, wasUsed: out var wasUsedPetroleum, resetAmountToZeroWhenNotEnoughToUse: true); if (wasUsedPetroleum) { // increase gasoline level (if possible) LiquidContainerSystem.UpdateWithoutManufacturing( liquidStateProcessedGasoline, this.LiquidConfigGasoline, deltaTime, isProduceLiquid: true, isUseRequested: false, wasUsed: out _); // increase mineral oil level (if possible) LiquidContainerSystem.UpdateWithoutManufacturing( liquidStateProcessedMineralOil, this.LiquidConfigMineralOil, deltaTime, isProduceLiquid: true, isUseRequested: false, wasUsed: out _); // this flag is required to force recipes checking on next iteration privateState.IsLiquidStatesChanged = true; } // progress crafting queues for processed liquids (craft canisters with according liquids) ManufacturingMechanic.UpdateCraftingQueueOnly(manufacturingStateProcessedGasoline, deltaTime); ManufacturingMechanic.UpdateCraftingQueueOnly(manufacturingStateProcessedMineralOil, deltaTime); }