Skip to content

Commit

Permalink
rewrote spawning logic to use WorldIconManager and support multiple t…
Browse files Browse the repository at this point in the history
…eams. Also landmine restrictions.
  • Loading branch information
DanielWillett committed Dec 22, 2024
1 parent 1cf85bf commit cf6829d
Show file tree
Hide file tree
Showing 32 changed files with 1,748 additions and 845 deletions.
3 changes: 3 additions & 0 deletions UncreatedWarfare.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=FOB/@EntryIndexedValue">FOB</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=UAV/@EntryIndexedValue">UAV</s:String></wpf:ResourceDictionary>
6 changes: 3 additions & 3 deletions UncreatedWarfare/Commands/Group/GroupJoinCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public async UniTask ExecuteAsync(CancellationToken token)
{
Context.AssertRanByPlayer();

Context.AssertArgs(2);
Context.AssertArgs(1);

Team? newTeam;
if (!Context.TryGet(1, out ulong groupId))
if (!Context.TryGet(0, out ulong groupId))
{
string groupInput = Context.Get(1)!;
string groupInput = Context.Get(0)!;

newTeam = _teamManager.FindTeam(groupInput);
if (newTeam == null)
Expand Down
53 changes: 34 additions & 19 deletions UncreatedWarfare/Components/LaserGuidedMissileComponent.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Uncreated.Warfare.Configuration;
using Uncreated.Warfare.Layouts.Teams;
using Uncreated.Warfare.Players;
using Uncreated.Warfare.Squads.Spotted;

namespace Uncreated.Warfare.Components;

internal class LaserGuidedMissileComponent : MonoBehaviour
{
#nullable disable
private Player _firer;
private WarfarePlayer _firer;
private Team _team;
private GameObject _projectile;
private Transform _aim;
private Rigidbody _rigidbody;
private List<BoxCollider> _colliders;
#nullable restore

private SpottedComponent? _laserTarget;
private SpottableObjectComponent? _laserTarget;
private SpottedService? _spottedService;
private float _guiderDistance;
private float _aquisitionRange;
private float _projectileSpeed;
Expand All @@ -34,10 +40,11 @@ internal class LaserGuidedMissileComponent : MonoBehaviour
public float InitializationTime { get; private set; }
public bool LockedOn => _laserTarget != null;

public void Initialize(GameObject projectile, Player firer, IServiceProvider serviceProvider, float projectileSpeed, float responsiveness, float aquisitionRange, float armingDistance, float fullGuidanceDelay)
public void Initialize(GameObject projectile, WarfarePlayer firer, IServiceProvider serviceProvider, float projectileSpeed, float responsiveness, float aquisitionRange, float armingDistance, float fullGuidanceDelay)
{
_projectile = projectile;
_firer = firer;
_team = firer.Team;
_maxTurnDegrees = responsiveness;
_projectileSpeed = projectileSpeed;
_aquisitionRange = aquisitionRange;
Expand All @@ -46,6 +53,8 @@ public void Initialize(GameObject projectile, Player firer, IServiceProvider ser
_guiderDistance = 30;
_turnMultiplier = 0;

_spottedService = serviceProvider.GetRequiredService<SpottedService>();

AssetConfiguration assetConfig = serviceProvider.GetRequiredService<AssetConfiguration>();
_fxSilent = assetConfig.GetAssetLink<EffectAsset>("Effects:Projectiles:GuidedMissileSilent");
_fxSound = assetConfig.GetAssetLink<EffectAsset>("Effects:Projectiles:GuidedMissileSound");
Expand All @@ -65,12 +74,12 @@ public void Initialize(GameObject projectile, Player firer, IServiceProvider ser
return;
}

InteractableVehicle? vehicle = firer.movement.getVehicle();
InteractableVehicle? vehicle = firer.UnturnedPlayer.movement.getVehicle();
if (vehicle != null)
{
foreach (Passenger turret in vehicle.turrets)
{
if (turret.player == null || turret.player.player != firer)
if (turret.player == null || !firer.Equals(turret.player.player))
continue;

_aim = turret.turretAim;
Expand All @@ -90,7 +99,7 @@ public void Initialize(GameObject projectile, Player firer, IServiceProvider ser
}
else
{
_aim = firer.look.aim.transform;
_aim = firer.UnturnedPlayer.look.aim.transform;
_isActive = true;
projectile.transform.forward = _aim.forward;
_rigidbody.velocity = projectile.transform.forward * projectileSpeed;
Expand All @@ -103,29 +112,34 @@ private bool TryAcquireTarget()
{
if (_laserTarget != null)
{
if (_laserTarget.IsActive)
if (_laserTarget.IsLaserTarget(_team))
return true;

_laserTarget = null;
}

float minAngle = 45;

if (_firer is null)
if (_firer is null || _spottedService == null)
return false;

foreach (SpottedComponent spotted in SpottedComponent.ActiveMarkers)
foreach (SpottableObjectComponent spotted in _spottedService.AliveSpottableObjects)
{
if (spotted.SpottingTeam == _firer.quests.groupID.m_SteamID && spotted.IsLaserTarget)
if (!spotted.IsLaserTarget(_team))
{
if ((spotted.transform.position - _projectile.transform.position).sqrMagnitude < _aquisitionRange * _aquisitionRange)
{
float angleBetween = Vector3.Angle(spotted.transform.position - _projectile.transform.position, _projectile.transform.forward);
if (angleBetween < minAngle)
{
minAngle = angleBetween;
_laserTarget = spotted;
}
}
continue;
}

if ((spotted.transform.position - _projectile.transform.position).sqrMagnitude >= _aquisitionRange * _aquisitionRange)
{
continue;
}

float angleBetween = Vector3.Angle(spotted.transform.position - _projectile.transform.position, _projectile.transform.forward);
if (angleBetween < minAngle)
{
minAngle = angleBetween;
_laserTarget = spotted;
}
}

Expand All @@ -136,6 +150,7 @@ private bool TryAcquireTarget()
private float _lastSent;

[UsedImplicitly]
[SuppressMessage("CodeQuality", "IDE0051")]
private void FixedUpdate()
{
if (!_isActive)
Expand Down
Loading

0 comments on commit cf6829d

Please sign in to comment.