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-26 14:05:46 +08:00
|
|
|
|
using GTA.Math;
|
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();
|
|
|
|
|
IsMine=true;
|
|
|
|
|
MainProjectile = p;
|
2022-05-26 14:05:46 +08:00
|
|
|
|
Origin=p.Position;
|
|
|
|
|
var shooter = EntityPool.GetPedByHandle(p.Owner.Handle);
|
2022-05-25 21:54:25 +08:00
|
|
|
|
if(shooter != null)
|
|
|
|
|
{
|
2022-05-26 14:05:46 +08:00
|
|
|
|
Main.Logger.Warning($"Could not find owner for projectile, owner handle:{}");
|
2022-05-25 21:54:25 +08:00
|
|
|
|
ShooterID=shooter.ID;
|
|
|
|
|
}
|
2022-05-26 14:05:46 +08:00
|
|
|
|
|
2022-05-25 10:09:59 +08:00
|
|
|
|
}
|
|
|
|
|
public SyncedProjectile(int id)
|
|
|
|
|
{
|
|
|
|
|
ID= id;
|
|
|
|
|
IsMine=false;
|
|
|
|
|
}
|
|
|
|
|
public new bool IsMine { get; private set; }
|
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-05-25 10:09:59 +08:00
|
|
|
|
|
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>
|
|
|
|
|
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-05-23 16:59:49 +08:00
|
|
|
|
public override void Update()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// Skip update if no new sync message has arrived.
|
2022-05-25 10:09:59 +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-05-25 10:09:59 +08:00
|
|
|
|
MainProjectile.PositionNoOffset=Position+Velocity*Networking.Latency;
|
2022-05-23 19:19:56 +08:00
|
|
|
|
MainProjectile.Velocity=Velocity;
|
|
|
|
|
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-05-25 10:09:59 +08:00
|
|
|
|
World.ShootBullet(Position,Position+Velocity,EntityPool.GetPedByID(ShooterID)?.MainPed,Asset,0);
|
|
|
|
|
var ps = World.GetAllProjectiles();
|
|
|
|
|
MainProjectile=ps[ps.Length-1];
|
|
|
|
|
EntityPool.Add(this);
|
2022-05-23 16:59:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|