public override void UpdateState(List <UnturnedPlayer> players) { var generators = Object.FindObjectsOfType <InteractableGenerator>(); foreach (var generator in generators) { var pos = generator.gameObject.transform.position; if (RegionsPlugin.Instance.GetRegionAt(pos) != Region) { continue; } ushort oldFuel = generator.fuel; ushort newFuel = oldFuel; if (GetValueSafe()) { newFuel = (ushort)(generator.capacity + 1); } else if (generator.fuel > generator.capacity) { newFuel = generator.capacity; } if (newFuel == oldFuel) //Prevent spamming packets to clients { continue; } BarricadeManager.sendFuel(generator.transform, newFuel); } }
private CommandResult RefuelGeneratorCommand(ICommandSource src, ICommandArgs args) { float radius = 20; float percentage = 100; if (args.Length > 0) { if (!args[0].IsFloat) { return(CommandResult.Lang("INVALID_NUMBER", args[0])); } if ((radius = args[0].ToFloat) <= 0) { return(CommandResult.Lang("MUST_POSITIVE")); } } if (args.Length > 1) { if (!args[1].IsFloat) { return(CommandResult.Lang("INVALID_NUMBER", args[1])); } if (!args[1].IsInRange(0, 100)) { return(CommandResult.Lang("NUMBER_BETWEEN", 0, 100)); } percentage = args[1].ToFloat / 100; } var count = 0; var player = src.ToPlayer(); var rayResult = Physics.SphereCastAll(player.Position, radius, Vector3.forward, RayMasks.BARRICADE); rayResult .Select(r => r.transform.GetComponent <InteractableGenerator>()) .Where(r => r != null) .ForEach(r => { BarricadeManager.sendFuel(r.transform, (ushort)Math.Floor(r.capacity * percentage)); count++; }); EssLang.Send(player, "REFUEL_GENERATOR_REFUELED", count); return(CommandResult.Success()); }
public void Execute(IRocketPlayer caller, string[] command) { UnturnedPlayer Player = (UnturnedPlayer)caller; Transform trans = Base.Tracer.TraceToHit(Player).transform; if (trans == null) { Base.Messages.CommonMessage(Utilities.Messages.CommonMessages.CNoObjectFound, caller); return; } InteractableVehicle vehicle = trans.gameObject.GetComponent <InteractableVehicle>(); if (vehicle != null) { vehicle.askFillFuel(10000); UnturnedChat.Say(caller, Base.Instance.Translate("refuel_vehicle")); } else { if (trans.GetComponent <InteractableDoorHinge>() != null) { trans = trans.parent.parent; } if (BarricadeManager.tryGetInfo(trans, out byte x, out byte y, out ushort plant, out ushort index, out BarricadeRegion BarricRegion)) { if (trans.name == "458" || trans.name == "1230") { InteractableGenerator i = trans.GetComponent <InteractableGenerator>(); BarricadeManager.sendFuel(trans, i.capacity); UnturnedChat.Say(caller, Base.Instance.Translate("refuel_object")); } return; } Base.Messages.CommonMessage(Utilities.Messages.CommonMessages.CNoObjectFound, caller); } }
// Token: 0x0600397E RID: 14718 RVA: 0x001AAFB4 File Offset: 0x001A93B4 private bool fire(bool mode) { if (base.channel.isOwner) { Ray ray = new Ray(base.player.look.aim.position, base.player.look.aim.forward); RaycastInfo raycastInfo = DamageTool.raycast(ray, 3f, RayMasks.DAMAGE_CLIENT); if (raycastInfo.vehicle != null) { if (mode) { if (this.fuel == 0) { return(false); } if (!raycastInfo.vehicle.isRefillable) { return(false); } } else { if (this.fuel == ((ItemFuelAsset)base.player.equipment.asset).fuel) { return(false); } if (!raycastInfo.vehicle.isSiphonable) { return(false); } } } else { if (!(raycastInfo.transform != null)) { return(false); } InteractableGenerator component = raycastInfo.transform.GetComponent <InteractableGenerator>(); InteractableOil component2 = raycastInfo.transform.GetComponent <InteractableOil>(); InteractableTank component3 = raycastInfo.transform.GetComponent <InteractableTank>(); InteractableObjectResource component4 = raycastInfo.transform.GetComponent <InteractableObjectResource>(); if (component != null) { if (mode) { if (this.fuel == 0) { return(false); } if (!component.isRefillable) { return(false); } } else { if (this.fuel == ((ItemFuelAsset)base.player.equipment.asset).fuel) { return(false); } if (!component.isSiphonable) { return(false); } } } else if (!(component2 != null)) { if (component3 != null) { if (component3.source != ETankSource.FUEL) { return(false); } if (mode) { if (this.fuel == 0) { return(false); } if (!component3.isRefillable) { return(false); } } else { if (this.fuel == ((ItemFuelAsset)base.player.equipment.asset).fuel) { return(false); } if (!component3.isSiphonable) { return(false); } } } else { if (!(component4 != null)) { return(false); } if (component4.objectAsset.interactability != EObjectInteractability.FUEL) { return(false); } if (mode) { if (this.fuel == 0) { return(false); } if (component4.amount == component4.capacity) { return(false); } } else { if (this.fuel == ((ItemFuelAsset)base.player.equipment.asset).fuel) { return(false); } if (component4.amount == 0) { return(false); } } } } } base.player.input.sendRaycast(raycastInfo); } if (Provider.isServer) { if (!base.player.input.hasInputs()) { return(false); } InputInfo input = base.player.input.getInput(true); if (input == null) { return(false); } if ((input.point - base.player.look.aim.position).sqrMagnitude > 49f) { return(false); } if (input.type == ERaycastInfoType.VEHICLE) { if (input.vehicle == null) { return(false); } if (mode) { if (this.fuel == 0) { return(false); } if (!input.vehicle.isRefillable) { return(false); } ushort num = (ushort)Mathf.Min((int)this.fuel, (int)(input.vehicle.asset.fuel - input.vehicle.fuel)); input.vehicle.askFillFuel(num); this.fuel -= num; } else { if (this.fuel == ((ItemFuelAsset)base.player.equipment.asset).fuel) { return(false); } if (!input.vehicle.isSiphonable) { return(false); } ushort num2 = (ushort)Mathf.Min((int)input.vehicle.fuel, (int)(((ItemFuelAsset)base.player.equipment.asset).fuel - this.fuel)); input.vehicle.askBurnFuel(num2); VehicleManager.sendVehicleFuel(input.vehicle, input.vehicle.fuel); this.fuel += num2; } } else if (input.type == ERaycastInfoType.BARRICADE) { if (input.transform == null || !input.transform.CompareTag("Barricade")) { return(false); } InteractableGenerator component5 = input.transform.GetComponent <InteractableGenerator>(); InteractableOil component6 = input.transform.GetComponent <InteractableOil>(); InteractableTank component7 = input.transform.GetComponent <InteractableTank>(); if (component5 != null) { if (mode) { if (this.fuel == 0) { return(false); } if (!component5.isRefillable) { return(false); } ushort num3 = (ushort)Mathf.Min((int)this.fuel, (int)(component5.capacity - component5.fuel)); component5.askFill(num3); BarricadeManager.sendFuel(input.transform, component5.fuel); this.fuel -= num3; } else { if (this.fuel == ((ItemFuelAsset)base.player.equipment.asset).fuel) { return(false); } if (!component5.isSiphonable) { return(false); } ushort num4 = (ushort)Mathf.Min((int)component5.fuel, (int)(((ItemFuelAsset)base.player.equipment.asset).fuel - this.fuel)); component5.askBurn(num4); BarricadeManager.sendFuel(input.transform, component5.fuel); this.fuel += num4; } } else if (component6 != null) { if (mode) { if (this.fuel == 0) { return(false); } if (!component6.isRefillable) { return(false); } ushort num5 = (ushort)Mathf.Min((int)this.fuel, (int)(component6.capacity - component6.fuel)); component6.askFill(num5); BarricadeManager.sendOil(input.transform, component6.fuel); this.fuel -= num5; } else { if (this.fuel == ((ItemFuelAsset)base.player.equipment.asset).fuel) { return(false); } if (!component6.isSiphonable) { return(false); } ushort num6 = (ushort)Mathf.Min((int)component6.fuel, (int)(((ItemFuelAsset)base.player.equipment.asset).fuel - this.fuel)); component6.askBurn(num6); BarricadeManager.sendOil(input.transform, component6.fuel); this.fuel += num6; } } else { if (!(component7 != null)) { return(false); } if (component7.source != ETankSource.FUEL) { return(false); } if (mode) { if (this.fuel == 0) { return(false); } if (!component7.isRefillable) { return(false); } ushort num7 = (ushort)Mathf.Min((int)this.fuel, (int)(component7.capacity - component7.amount)); BarricadeManager.updateTank(input.transform, component7.amount + num7); this.fuel -= num7; } else { if (this.fuel == ((ItemFuelAsset)base.player.equipment.asset).fuel) { return(false); } if (!component7.isSiphonable) { return(false); } ushort num8 = (ushort)Mathf.Min((int)component7.amount, (int)(((ItemFuelAsset)base.player.equipment.asset).fuel - this.fuel)); BarricadeManager.updateTank(input.transform, component7.amount - num8); this.fuel += num8; } } } else if (input.type == ERaycastInfoType.OBJECT) { if (input.transform == null) { return(false); } InteractableObjectResource component8 = input.transform.GetComponent <InteractableObjectResource>(); if (component8 == null || component8.objectAsset.interactability != EObjectInteractability.FUEL) { return(false); } if (mode) { if (this.fuel == 0) { return(false); } if (!component8.isRefillable) { return(false); } ushort num9 = (ushort)Mathf.Min((int)this.fuel, (int)(component8.capacity - component8.amount)); ObjectManager.updateObjectResource(component8.transform, component8.amount + num9, true); this.fuel -= num9; } else { if (this.fuel == ((ItemFuelAsset)base.player.equipment.asset).fuel) { return(false); } if (!component8.isSiphonable) { return(false); } ushort num10 = (ushort)Mathf.Min((int)component8.amount, (int)(((ItemFuelAsset)base.player.equipment.asset).fuel - this.fuel)); ObjectManager.updateObjectResource(component8.transform, component8.amount - num10, true); this.fuel += num10; } } } return(true); }
protected override async UniTask OnExecuteAsync() { if (Context.Parameters.Length != 0) { throw new CommandWrongUsageException(Context); } UnturnedUser uPlayer = (UnturnedUser)Context.Actor; await UniTask.SwitchToMainThread(); var currentVehicle = uPlayer.Player.Player.movement.getVehicle(); if (currentVehicle != null) { if (!RefuelVehicle(currentVehicle)) { throw new UserFriendlyException(m_StringLocalizer["refuel:vehicle:no_fuel"]); } await PrintAsync(m_StringLocalizer["refuel:vehicle:success"]); return; } PlayerLook look = uPlayer.Player.Player.look; RaycastInfo raycast = DamageTool.raycast(new(look.aim.position, look.aim.forward), 100f, RayMasks.DAMAGE_SERVER); if (raycast.vehicle != null) { if (!RefuelVehicle(raycast.vehicle)) { throw new UserFriendlyException(m_StringLocalizer["refuel:vehicle:no_fuel"]); } await PrintAsync(m_StringLocalizer["refuel:vehicle:success"]); return; } if (raycast.transform == null) { throw new UserFriendlyException(m_StringLocalizer["refuel:none"]); } var interactable = raycast.transform.GetComponent <Interactable>(); if (interactable != null) { if (interactable is InteractableGenerator generator) { if (!generator.isRefillable) { throw new UserFriendlyException(m_StringLocalizer["refuel:object:no_fuel", new { Object = generator.name }]); } generator.askFill(generator.capacity); BarricadeManager.sendFuel(raycast.transform, generator.fuel); await PrintAsync(m_StringLocalizer["refuel:object:generator"]); return; } else if (interactable is InteractableOil oil) { if (!oil.isRefillable) { throw new UserFriendlyException(m_StringLocalizer["refuel:object:no_fuel", new { Object = oil.name }]); } oil.askFill(oil.capacity); BarricadeManager.sendFuel(raycast.transform, oil.fuel); await PrintAsync(m_StringLocalizer["refuel:object:oil"]); return; } else if (interactable is InteractableTank { source : ETankSource.FUEL } tank) { if (!tank.isRefillable) { throw new UserFriendlyException(m_StringLocalizer["refuel:object:no_fuel", new { Object = tank.name }]); } BarricadeManager.updateTank(raycast.transform, tank.capacity); await PrintAsync(m_StringLocalizer["refuel:object:tank"]); return; } else if (interactable is InteractableObjectResource { objectAsset : { interactability : EObjectInteractability.FUEL } } @object) { if ([email protected]) { throw new UserFriendlyException(m_StringLocalizer["refuel:object:no_fuel", new { Object = @object.name }]); } ObjectManager.updateObjectResource(interactable.transform, @object.capacity, true); // todo await PrintAsync(m_StringLocalizer["refuel:object:object"]); return; } }