public SprinklerWateringRequestResult SharedCanWaterNow(IStaticWorldObject worldObjectSprinkler) { var time = IsServer ? Server.Game.FrameTime : Client.CurrentGame.ServerFrameTimeApproximated; var privateState = GetPrivateState(worldObjectSprinkler); if (privateState.LastWateringTime < double.MaxValue && time - privateState.LastWateringTime < WateringCooldownSeconds) { return(SprinklerWateringRequestResult.ErrorWateredRecently); } if (GetPublicState(worldObjectSprinkler).ElectricityConsumerState == ElectricityConsumerState.PowerOff) { return(SprinklerWateringRequestResult.ErrorPowerOff); } if (privateState.WaterAmount < this.WaterConsumptionPerWatering) { return(SprinklerWateringRequestResult.ErrorNotEnoughWater); } if (IsServer) { var areasGroup = LandClaimSystem.SharedGetLandClaimAreasGroup(worldObjectSprinkler.Bounds); if (!PowerGridSystem.ServerBaseHasCharge(areasGroup, this.ElectricityConsumptionPerWatering)) { return(SprinklerWateringRequestResult.ErrorNotEnoughElectricity); } } return(SprinklerWateringRequestResult.Success); }
public static void ClientRechargeShield(ILogicObject areasGroup, double targetChargeElectricity) { Api.Assert(targetChargeElectricity > 0, "Incorrect charge amount"); var electricityCost = CalculateRequiredElectricityCost(areasGroup, targetChargeElectricity); if (electricityCost <= 0) { return; } var state = SharedGetShieldPublicStatus(areasGroup); if (state == ShieldProtectionStatus.Active) { throw new Exception("Cannot recharge active shield. It should be disabled."); } if (!PowerGridSystem.ServerBaseHasCharge(areasGroup, electricityCost)) { var message = PowerGridSystem.SetPowerModeResult.NotEnoughPower.GetDescription(); NotificationSystem.ClientShowNotification( message, null, color: NotificationColor.Bad); return; } Instance.CallServer(_ => _.ServerRemote_RechargeShield(areasGroup, targetChargeElectricity)); Logger.Important( $"Sent request to charge shield to {targetChargeElectricity:F2} (+{electricityCost:F2} EU)"); }
public override bool SharedCanFire(ICharacter character, WeaponState weaponState) { var areasGroup = LandClaimSystem.SharedGetLandClaimAreasGroup(character.TilePosition); return(areasGroup is not null && PowerGridSystem.ServerBaseHasCharge(areasGroup, this.EnergyUsagePerShot)); }