2022-05-23 16:59:49 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using GTA;
|
|
|
|
|
|
2022-05-23 19:19:56 +08:00
|
|
|
|
namespace RageCoop.Client
|
2022-05-23 16:59:49 +08:00
|
|
|
|
{
|
|
|
|
|
internal class SyncedProjectile:SyncedEntity
|
|
|
|
|
{
|
|
|
|
|
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-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; }
|
|
|
|
|
private bool _creatingProjectile{ get;set; }=false;
|
|
|
|
|
private ulong _projectileShotTime { get;set; }
|
2022-05-23 16:59:49 +08:00
|
|
|
|
public override void Update()
|
|
|
|
|
{
|
|
|
|
|
// Check if all data avalible
|
|
|
|
|
if (!IsReady) { return; }
|
|
|
|
|
|
|
|
|
|
// Skip update if no new sync message has arrived.
|
|
|
|
|
if (!NeedUpdate)
|
2022-05-23 19:19:56 +08:00
|
|
|
|
{ return; }
|
|
|
|
|
|
|
|
|
|
if (_creatingProjectile) { return; }
|
|
|
|
|
|
|
|
|
|
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-05-23 19:19:56 +08:00
|
|
|
|
MainProjectile.Position=Position+Velocity*Networking.Latency;
|
|
|
|
|
MainProjectile.Velocity=Velocity;
|
|
|
|
|
MainProjectile.Rotation=Rotation;
|
2022-05-23 16:59:49 +08:00
|
|
|
|
if (Exploded)
|
|
|
|
|
{
|
|
|
|
|
if (Exploded)
|
|
|
|
|
{
|
|
|
|
|
if(MainProjectile != null && MainProjectile.Exists())
|
|
|
|
|
{
|
|
|
|
|
MainProjectile.Explode();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-23 19:19:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreateProjectile()
|
|
|
|
|
{
|
|
|
|
|
Asset=new WeaponAsset(Hash);
|
|
|
|
|
if (!Asset.IsLoaded) { Asset.Request(); }
|
|
|
|
|
World.ShootBullet(Position,Position+Velocity,EntityPool.GetPedByID(ShooterID)?.MainPed,Asset,0,Velocity.Length());
|
|
|
|
|
_projectileShotTime=Main.Ticked;
|
|
|
|
|
_creatingProjectile=true;
|
|
|
|
|
|
|
|
|
|
EventHandler<ProjectileShotEventArgs> checker = null;
|
|
|
|
|
checker= (sender, e) =>
|
2022-05-23 16:59:49 +08:00
|
|
|
|
{
|
2022-05-23 19:19:56 +08:00
|
|
|
|
if (Main.Ticked<=_projectileShotTime+1)
|
2022-05-23 16:59:49 +08:00
|
|
|
|
{
|
2022-05-23 19:19:56 +08:00
|
|
|
|
if (e.Projectile.WeaponHash==Hash)
|
|
|
|
|
{
|
|
|
|
|
MainProjectile=e.Projectile;
|
|
|
|
|
_creatingProjectile=false;
|
|
|
|
|
SyncEvents.OnProjectileShot-=checker;
|
|
|
|
|
}
|
2022-05-23 16:59:49 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-05-23 19:19:56 +08:00
|
|
|
|
_creatingProjectile=false;
|
|
|
|
|
SyncEvents.OnProjectileShot-=checker;
|
2022-05-23 16:59:49 +08:00
|
|
|
|
}
|
2022-05-23 19:19:56 +08:00
|
|
|
|
};
|
|
|
|
|
SyncEvents.OnProjectileShot+=checker;
|
2022-05-23 16:59:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|