AI захватит мир

This commit is contained in:
Oscar
2025-06-26 23:24:52 +03:00
parent 793165bb03
commit 875d594038
28 changed files with 1263 additions and 266 deletions

View File

@@ -10,6 +10,7 @@ public sealed class Weapon : AmmoUseableBase
[Property] public GameObject MuzzleLight { get; private set; }
[Property] public GameObject particlePrefab { get; set; }
[Property] public GameObject bloodParticle { get; set; }
[Property] public WeaponItemDefinition WeaponDefinition { get; set; }
private SoundPointComponent _sound;
private Rigidbody _rigidbody;
@@ -17,7 +18,7 @@ public sealed class Weapon : AmmoUseableBase
protected override void OnStart()
{
base.OnStart();
_sound = GameObject.GetComponent<SoundPointComponent>( true );
_sound = GameObject.GetComponent<SoundPointComponent>(true);
}
public override void OnEquipped()
@@ -27,66 +28,73 @@ public sealed class Weapon : AmmoUseableBase
GameObject.Components.Get<PickupItem>().Enabled = false;
}
protected override WeaponItemDefinition GetWeaponDefinition()
{
return WeaponDefinition;
}
public void Attack()
{
AttackEffects();
Vector3 startPos = Scene.Camera.WorldPosition;
Vector3 dir = Scene.Camera.WorldRotation.Forward;
float maxDistance = 1000f;
float maxDistance = WeaponDefinition?.Range ?? 1000f;
var tr = Scene.Trace
.Ray( startPos, startPos + dir * maxDistance )
.IgnoreGameObjectHierarchy( Dedugan.Local.GameObject )
.WithoutTags( "weapon" )
.Ray(startPos, startPos + dir * maxDistance)
.IgnoreGameObjectHierarchy(Dedugan.Local.GameObject)
.WithoutTags("weapon")
.UseHitboxes()
.Run();
if ( tr.Hit && tr.Hitbox != null )
if (tr.Hit)
{
var components = tr.GameObject.Components;
var boneIndex = tr.Hitbox.Bone.Index;
// Log.Info($"{tr.GameObject.Name} attacked");
var dedugan = components.Get<Dedugan>();
var enemy = components.Get<Enemy>();
if ( dedugan.IsValid() || enemy.IsValid() )
if (tr.Hitbox != null)
{
CreateHitEffects( tr.EndPosition, tr.Normal, true );
}
var boneIndex = tr.Hitbox.Bone.Index;
var components = tr.GameObject.Components;
// Кэшируем компоненты для избежания повторных поисков
var dedugan = components.Get<Dedugan>();
var enemy = components.Get<Enemy>();
var hasTarget = dedugan.IsValid() || enemy.IsValid();
if ( dedugan.IsValid() )
{
dedugan.ReportHit( dir, boneIndex );
}
if (hasTarget)
{
CreateHitEffects(tr.EndPosition, tr.Normal, true);
}
if ( enemy.IsValid() )
{
enemy.ReportHit( dir, boneIndex );
Log.Info( boneIndex );
if (dedugan.IsValid())
{
dedugan.ReportHit(dir, boneIndex);
}
if (enemy.IsValid())
{
enemy.ReportHit(dir, boneIndex);
}
}
else
{
CreateHitEffects(tr.EndPosition, tr.Normal);
}
}
else if ( tr.Hitbox == null )
{
CreateHitEffects( tr.EndPosition, tr.Normal );
}
}
[Rpc.Broadcast]
private void CreateHitEffects( Vector3 position, Vector3 normal, bool blood = false )
private void CreateHitEffects(Vector3 position, Vector3 normal, bool blood = false)
{
var rot = Rotation.LookAt( normal );
var rot = Rotation.LookAt(normal);
DestroyAsync(
blood
? bloodParticle.Clone( position, rot )
: particlePrefab.Clone( position, rot ), 0.5f );
? bloodParticle.Clone(position, rot)
: particlePrefab.Clone(position, rot), 0.5f);
}
async void DestroyAsync( GameObject go, float delay )
async void DestroyAsync(GameObject go, float delay)
{
await GameTask.DelaySeconds( delay );
await GameTask.DelaySeconds(delay);
go.Destroy();
}
@@ -95,12 +103,12 @@ public sealed class Weapon : AmmoUseableBase
{
_sound?.StartSound();
MuzzleLight.Enabled = true;
GunRenderer.Set( "Fire", true );
GunRenderer.Set("Fire", true);
GameTask.DelaySeconds( 0.05f ).ContinueWith( ( _ ) =>
GameTask.DelaySeconds(0.05f).ContinueWith((_) =>
{
MuzzleLight.Enabled = false;
} );
});
}
protected override void OnUse()