public override void SharedOnHit( WeaponFinalCache weaponCache, IWorldObject damagedObject, double damage, WeaponHitData hitData, out bool isDamageStop) { base.SharedOnHit(weaponCache, damagedObject, damage, hitData, out isDamageStop); if (IsClient) { // on client we cannot consume energy return; } // consume energy on hit var byCharacter = weaponCache.Character; var requiredEnergyAmount = SkillWeaponsEnergy.SharedGetRequiredEnergyAmount(byCharacter, this.EnergyUsePerHit); CharacterEnergySystem.ServerDeductEnergyCharge(byCharacter, requiredEnergyAmount); }
private void ServerRemote_OnActionCompletedInternal(IItem itemVehicleRemote, ICharacter character, Vector2D mousePosition) { if (!(itemVehicleRemote.ProtoItem is IProtoItemVehicleRemoteControl protoRemote)) { return; } if (!CharacterEnergySystem.SharedHasEnergyCharge(character, protoRemote.EngeryUse)) { return; } List <GarageVehicleEntry> list = VehicleGarageSystem.ServerGetCharacterVehicles(character, false); TakeVehicleResult result = TakeVehicleResult.Unknown; if (list.Count > 0) { var privateState = itemVehicleRemote.GetPrivateState <ItemVehicleRemoteControlPrivateState>(); result = this.ServerTakeVehicle(privateState, character, mousePosition); } if (result == TakeVehicleResult.Success) { CharacterEnergySystem.ServerDeductEnergyCharge(character, protoRemote.EngeryUse); ItemDurabilitySystem.ServerModifyDurability(itemVehicleRemote, delta: -1); } }
// Please note: the check SharedCanFire() has been already passed public override bool SharedOnFire(ICharacter character, WeaponState weaponState) { if (IsClient) { // on client we cannot consume energy return true; } var requiredEnergyAmount = SkillWeaponsEnergy.SharedGetRequiredEnergyAmount(character, this.EnergyUsePerShot); return CharacterEnergySystem.ServerDeductEnergyCharge(character, requiredEnergyAmount); }
public override void ServerOnDamageApplied( IItem weapon, ICharacter byCharacter, IWorldObject damagedObject, double damage) { base.ServerOnDamageApplied(weapon, byCharacter, damagedObject, damage); if (IsClient) { // on client we cannot deduct energy return; } // deduct energy on hit var requiredEnergyAmount = SkillWeaponsEnergy.SharedGetRequiredEnergyAmount( byCharacter, this.EnergyUsePerHit); CharacterEnergySystem.ServerDeductEnergyCharge(byCharacter, requiredEnergyAmount); }
protected override void ServerUpdate(ServerUpdateData data) { var item = data.GameObject; var privateState = data.PrivateState; var character = item.Container.OwnerAsCharacter; if (!IsItemSelectedByPlayer(character, item)) { // not a selected player item this.ServerSetUpdateRate(item, isRare: true); return; } privateState.ServerTimeToPing -= data.DeltaTime; if (privateState.ServerTimeToPing > 0) { return; } privateState.ServerTimeToPing = ServerScanInterval; if (!CharacterEnergySystem.ServerDeductEnergyCharge( character, requiredEnergyAmount: this.EnergyConsumptionPerSecond * ServerScanInterval)) { // no power this.CallClient(character, _ => _.ClientRemote_NoPower()); return; } ItemDurabilitySystem.ServerModifyDurability( item, delta: -(int)Math.Round(this.DurabilityDecreasePerSecond * ServerScanInterval)); if (item.IsDestroyed) { // zero durability reached return; } // update signal strength using var tempSignalStrength = Api.Shared.GetTempList <byte>(); this.ServerCalculateStrengthToTheClosestPragmiumSpires(character, tempSignalStrength.AsList(), MaxNumberOfPongsPerScan); var previousSignalStrength = -1; foreach (var signalStrength in tempSignalStrength.AsList()) { if (signalStrength == previousSignalStrength) { // don't send multiple pongs for the signals of the same strength continue; } previousSignalStrength = signalStrength; var serverTimeToPong = SharedCalculateTimeToPong(signalStrength); ServerTimersSystem.AddAction( serverTimeToPong, () => { var currentCharacter = item.Container.OwnerAsCharacter; if (IsItemSelectedByPlayer(currentCharacter, item)) { this.CallClient(currentCharacter, _ => _.ClientRemote_OnSignal(item, PragmiumSensorSignalKind.Pong)); } }); //Logger.Dev(string.Format("Pragmium scanner signal: {0} strength. Time to send pong: {1} ms.", // signalStrength, // (int)(serverTimeToPong * 1000))); } this.CallClient(character, _ => _.ClientRemote_OnSignal(item, PragmiumSensorSignalKind.Ping)); bool IsItemSelectedByPlayer(ICharacter c, IItem i) => c is not null && ReferenceEquals(i, c.SharedGetPlayerSelectedHotbarItem()); }