Skip to content

Commit

Permalink
Added configurable projectile gun assets that can ignore advanced veh…
Browse files Browse the repository at this point in the history
…icle damage
  • Loading branch information
benvalkin committed Dec 28, 2024
1 parent dcb5533 commit 76caabc
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using Uncreated.Warfare.Configuration;
using Uncreated.Warfare.Events.Models;
using Uncreated.Warfare.Events.Models.Projectiles;
using Uncreated.Warfare.Events.Models.Vehicles;
Expand All @@ -13,6 +16,13 @@ public class AdvancedVehicleDamageTweaks :
IEventListener<ProjectileSpawned>,
IEventListener<DamageVehicleRequested>
{
private readonly AssetConfiguration _assetConfiguration;

public AdvancedVehicleDamageTweaks(AssetConfiguration assetConfiguration)
{
_assetConfiguration = assetConfiguration;
}

public UniTask StartAsync(CancellationToken token)
{
UseableGun.onBulletHit += UseableGunOnBulletHit;
Expand Down Expand Up @@ -40,6 +50,12 @@ public void HandleEvent(DamageVehicleRequested e, IServiceProvider serviceProvid

public void HandleEvent(ProjectileSpawned e, IServiceProvider serviceProvider)
{
if (_ignoreAdvancedDamage.ContainsAsset(e.Asset))
return;

e.Object.AddComponent<AdvancedVehicleDamageProjectile>();
}

private IEnumerable<IAssetLink<ItemGunAsset>> _ignoreAdvancedDamage => _assetConfiguration.GetRequiredSection("Projectiles:GunsThatIgnoreAdvancedDamage")?
.Get<IEnumerable<IAssetLink<ItemGunAsset>>>() ?? Array.Empty<IAssetLink<ItemGunAsset>>();
}

0 comments on commit 76caabc

Please sign in to comment.