2022-07-20 17:50:01 +08:00
|
|
|
|
using GTA;
|
2022-05-26 14:05:46 +08:00
|
|
|
|
using GTA.Math;
|
2022-07-03 10:46:24 +08:00
|
|
|
|
using RageCoop.Core;
|
2022-05-23 16:59:49 +08:00
|
|
|
|
|
2022-05-23 19:19:56 +08:00
|
|
|
|
namespace RageCoop.Client
|
2022-05-23 16:59:49 +08:00
|
|
|
|
{
|
2022-05-25 10:09:59 +08:00
|
|
|
|
internal class SyncedProjectile : SyncedEntity
|
2022-05-23 16:59:49 +08:00
|
|
|
|
{
|
2022-05-25 10:09:59 +08:00
|
|
|
|
public SyncedProjectile(Projectile p)
|
|
|
|
|
{
|
|
|
|
|
ID=EntityPool.RequestNewID();
|
|
|
|
|
MainProjectile = p;
|
2022-05-26 14:05:46 +08:00
|
|
|
|
Origin=p.Position;
|
2022-06-02 12:44:05 +08:00
|
|
|
|
var shooter = EntityPool.GetPedByHandle((p.Owner?.Handle).GetValueOrDefault());
|
2022-06-17 11:33:53 +08:00
|
|
|
|
if (shooter==null)
|
2022-05-26 17:11:37 +08:00
|
|
|
|
{
|
|
|
|
|
// Owner will be the vehicle if projectile is shot with a vehicle
|
2022-06-02 12:44:05 +08:00
|
|
|
|
var shooterVeh = EntityPool.GetVehicleByHandle((p.Owner?.Handle).GetValueOrDefault());
|
2022-05-26 17:11:37 +08:00
|
|
|
|
if (shooterVeh!=null && shooterVeh.MainVehicle.Driver!=null)
|
|
|
|
|
{
|
2022-06-17 11:33:53 +08:00
|
|
|
|
shooter=shooterVeh.MainVehicle.Driver?.GetSyncEntity();
|
2022-05-26 17:11:37 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-06-02 12:44:05 +08:00
|
|
|
|
Main.Logger.Warning($"Could not find owner for projectile:{Hash}");
|
2022-05-26 17:11:37 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-20 17:50:01 +08:00
|
|
|
|
if (shooter != null)
|
2022-06-17 11:33:53 +08:00
|
|
|
|
{
|
|
|
|
|
if (shooter.MainPed!=null && (p.AttachedEntity==shooter.MainPed.Weapons.CurrentWeaponObject || p.AttachedEntity== shooter.MainPed))
|
|
|
|
|
{
|
|
|
|
|
// Reloading
|
|
|
|
|
IsValid=false;
|
|
|
|
|
}
|
|
|
|
|
ShooterID=shooter.ID;
|
2022-07-03 10:46:24 +08:00
|
|
|
|
IsLocal=shooter.IsLocal;
|
2022-06-17 11:33:53 +08:00
|
|
|
|
}
|
2022-07-20 17:50:01 +08:00
|
|
|
|
|
2022-05-25 10:09:59 +08:00
|
|
|
|
}
|
|
|
|
|
public SyncedProjectile(int id)
|
|
|
|
|
{
|
|
|
|
|
ID= id;
|
2022-07-03 10:46:24 +08:00
|
|
|
|
IsLocal=false;
|
2022-05-25 10:09:59 +08:00
|
|
|
|
}
|
2022-06-16 11:57:48 +08:00
|
|
|
|
public bool IsValid { get; private set; } = true;
|
2022-07-03 10:46:24 +08:00
|
|
|
|
public new bool IsLocal { get; private set; } = false;
|
2022-05-23 16:59:49 +08:00
|
|
|
|
public bool Exploded { get; set; } = false;
|
|
|
|
|
public Projectile MainProjectile { get; set; }
|
2022-05-23 19:19:56 +08:00
|
|
|
|
public int ShooterID { get; set; }
|
2022-07-20 17:50:01 +08:00
|
|
|
|
private SyncedPed Shooter { get; set; }
|
2022-05-26 14:05:46 +08:00
|
|
|
|
public Vector3 Origin { get; set; }
|
|
|
|
|
|
2022-05-25 10:09:59 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Invalid property for projectile.
|
|
|
|
|
/// </summary>
|
2022-07-20 17:50:01 +08:00
|
|
|
|
private new int OwnerID { set { } }
|
2022-05-23 16:59:49 +08:00
|
|
|
|
public WeaponHash Hash { get; set; }
|
2022-05-23 19:19:56 +08:00
|
|
|
|
private WeaponAsset Asset { get; set; }
|
2022-06-11 18:41:10 +08:00
|
|
|
|
internal override void Update()
|
2022-05-23 16:59:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// Skip update if no new sync message has arrived.
|
2022-07-20 17:50:01 +08:00
|
|
|
|
if (!NeedUpdate) { return; }
|
2022-05-23 19:19:56 +08:00
|
|
|
|
|
|
|
|
|
if (MainProjectile == null || !MainProjectile.Exists())
|
2022-05-23 16:59:49 +08:00
|
|
|
|
{
|
2022-05-23 19:19:56 +08:00
|
|
|
|
CreateProjectile();
|
2022-05-23 16:59:49 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-06-17 11:08:49 +08:00
|
|
|
|
MainProjectile.Velocity=Velocity+(Position+Networking.Latency*Velocity-MainProjectile.Position);
|
2022-05-23 19:19:56 +08:00
|
|
|
|
MainProjectile.Rotation=Rotation;
|
2022-05-25 10:09:59 +08:00
|
|
|
|
LastUpdated=Main.Ticked;
|
2022-05-23 19:19:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreateProjectile()
|
|
|
|
|
{
|
|
|
|
|
Asset=new WeaponAsset(Hash);
|
|
|
|
|
if (!Asset.IsLoaded) { Asset.Request(); }
|
2022-07-20 17:50:01 +08:00
|
|
|
|
World.ShootBullet(Position, Position+Velocity, (Shooter=EntityPool.GetPedByID(ShooterID))?.MainPed, Asset, 0);
|
2022-05-25 10:09:59 +08:00
|
|
|
|
var ps = World.GetAllProjectiles();
|
|
|
|
|
MainProjectile=ps[ps.Length-1];
|
2022-06-02 15:51:58 +08:00
|
|
|
|
if (Hash==(WeaponHash)VehicleWeaponHash.Tank)
|
|
|
|
|
{
|
|
|
|
|
var v = Shooter?.MainPed?.CurrentVehicle;
|
|
|
|
|
if (v!=null)
|
|
|
|
|
{
|
|
|
|
|
World.CreateParticleEffectNonLooped(SyncEvents.CorePFXAsset, "muz_tank", v.GetMuzzleInfo().Position, v.Bones[35].ForwardVector.ToEulerRotation(v.Bones[35].UpVector), 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-25 10:09:59 +08:00
|
|
|
|
EntityPool.Add(this);
|
2022-05-23 16:59:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|