public override bool SharedOnFire(ICharacter character, WeaponState weaponState) { var areasGroup = LandClaimSystem.SharedGetLandClaimAreasGroup(character.TilePosition); if (areasGroup is null) { return(false); } PowerGridSystem.ServerDeductBaseCharge(areasGroup, this.EnergyUsagePerShot); return(true); }
public SprinklerWateringRequestResult ServerTryWaterNow(IStaticWorldObject worldObjectSprinkler) { var privateState = GetPrivateState(worldObjectSprinkler); var publicState = GetPublicState(worldObjectSprinkler); var checkResult = this.SharedCanWaterNow(worldObjectSprinkler); if (checkResult != SprinklerWateringRequestResult.Success) { Logger.Info("Sprinkler cannot water: " + checkResult, characterRelated: ServerRemoteContext.IsRemoteCall ? ServerRemoteContext.Character : null); switch (checkResult) { case SprinklerWateringRequestResult.ErrorNotEnoughWater: privateState.NextWateringTime = double.MaxValue; break; case SprinklerWateringRequestResult.ErrorNotEnoughElectricity: privateState.NextWateringTime = Server.Game.FrameTime + WateringIntervalSeconds; break; } return(checkResult); } privateState.LastWateringTime = Server.Game.FrameTime; privateState.NextWateringTime = Server.Game.FrameTime + WateringIntervalSeconds; var plantObjectsToWater = this.ServerGetPlantObjectsToWater(worldObjectSprinkler); if (plantObjectsToWater.Count == 0) { Logger.Info("No plants to water", characterRelated: ServerRemoteContext.IsRemoteCall ? ServerRemoteContext.Character : null); return(SprinklerWateringRequestResult.Success); } // consume water privateState.SetWaterAmount(privateState.WaterAmount - this.WaterConsumptionPerWatering, this.WaterCapacity, publicState); // consume electricity var areasGroup = LandClaimSystem.SharedGetLandClaimAreasGroup(worldObjectSprinkler.Bounds); PowerGridSystem.ServerDeductBaseCharge(areasGroup, this.ElectricityConsumptionPerWatering); try { foreach (var worldObjectPlant in plantObjectsToWater) { if (worldObjectPlant.ProtoGameObject is IProtoObjectPlant protoPlant) { protoPlant.ServerOnWatered(worldObjectPlant, wateringDuration: WateringIntervalSeconds); } } } catch (Exception ex) { Logger.Exception(ex); } Logger.Info("Watered surroundings now: " + worldObjectSprinkler); // reset hashes to ensure the recipe will refresh (it will refill the water bar if there are bottles with water) privateState.ManufacturingState.ContainerInputLastStateHash = null; privateState.ManufacturingState.ContainerOutputLastStateHash = null; using var observers = Api.Shared.GetTempList <ICharacter>(); Server.World.GetScopedByPlayers(worldObjectSprinkler, observers); this.CallClient(observers.AsList(), _ => _.ClientRemote_OnWatered(worldObjectSprinkler)); return(SprinklerWateringRequestResult.Success); }