Vehicle projectile weapon is now synchronized!

This commit is contained in:
Sardelka 2022-05-26 14:05:46 +08:00
parent 92a59ec8e4
commit d6a230cd5a
3 changed files with 42 additions and 23 deletions

View File

@ -489,8 +489,16 @@ namespace RageCoop.Client
public static bool IsUsingProjectileWeapon(this Ped p)
{
var w = p.Weapons.Current;
return w.Group==WeaponGroup.Thrown||ProjectileWeapons.Contains(w.Hash);
var vp = p.VehicleWeapon;
if (vp!=VehicleWeaponHash.Invalid)
{
return VehicleProjectileWeapons.Contains(vp);
}
else
{
var w = p.Weapons.Current;
return w.Group==WeaponGroup.Thrown || ProjectileWeapons.Contains(w.Hash);
}
}
#endregion
@ -906,24 +914,11 @@ namespace RageCoop.Client
WeaponHash.CompactGrenadeLauncher,
WeaponHash.FlareGun,
};
/*
public static readonly Dictionary<WeaponHash, ExplosionType> WeaponExplosionTypes = new Dictionary<WeaponHash, ExplosionType> {
{ WeaponHash.Grenade,ExplosionType.Grenade},
{ WeaponHash.GrenadeLauncher,ExplosionType.Grenade},
{ WeaponHash.CompactGrenadeLauncher,ExplosionType.Grenade},
{ WeaponHash.SmokeGrenade,ExplosionType.SmokeG},
{ WeaponHash.GrenadeLauncherSmoke,ExplosionType.SmokeG},
{ WeaponHash.StickyBomb,ExplosionType.StickyBomb},
{ WeaponHash.Flare,ExplosionType.Flare},
{ WeaponHash.FlareGun,ExplosionType.Flare},
{ WeaponHash.Molotov,ExplosionType.Molotov1},
{ WeaponHash.BZGas,ExplosionType.BZGas},
{ WeaponHash.PipeBomb,ExplosionType.PipeBomb},
{ WeaponHash.ProximityMine,ExplosionType.ProxMine},
{ WeaponHash.Firework,ExplosionType.FireWork},
{ WeaponHash.RPG,ExplosionType.Rocket},
public static readonly HashSet<VehicleWeaponHash> VehicleProjectileWeapons = new HashSet<VehicleWeaponHash> {
VehicleWeaponHash.PlaneRocket,
VehicleWeaponHash.SpaceRocket,
VehicleWeaponHash.Tank,
};
*/
}
/// <summary>
///

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GTA;
using GTA.Math;
namespace RageCoop.Client
{
@ -14,11 +15,14 @@ namespace RageCoop.Client
ID=EntityPool.RequestNewID();
IsMine=true;
MainProjectile = p;
var shooter = p.Owner.GetSyncEntity();
Origin=p.Position;
var shooter = EntityPool.GetPedByHandle(p.Owner.Handle);
if(shooter != null)
{
Main.Logger.Warning($"Could not find owner for projectile, owner handle:{}");
ShooterID=shooter.ID;
}
}
public SyncedProjectile(int id)
{
@ -30,6 +34,8 @@ namespace RageCoop.Client
public Projectile MainProjectile { get; set; }
public int ShooterID { get; set; }
public Vector3 Origin { get; set; }
/// <summary>
/// Invalid property for projectile.
/// </summary>

View File

@ -55,6 +55,13 @@ namespace RageCoop.Client
ID_Vehicles.Clear();
Handle_Vehicles.Clear();
foreach(var p in ID_Projectiles.Values)
{
if (p.ShooterID!=Main.LocalPlayerID && p.MainProjectile!=null && p.MainProjectile.Exists())
{
p.MainProjectile.Delete();
}
}
ID_Projectiles.Clear();
Handle_Projectiles.Clear();
}
@ -287,7 +294,8 @@ namespace RageCoop.Client
#if BENCHMARK
Debug.TimeStamps[TimeStamp.GetAllEntities]=PerfCounter.ElapsedTicks;
#endif
#endif
lock (ProjectilesLock)
{
@ -296,7 +304,7 @@ namespace RageCoop.Client
if (!Handle_Projectiles.ContainsKey(p.Handle))
{
Add(new SyncedProjectile(p));
Main.Logger.Debug($"Projectile shot: {p.Handle}");
}
}
@ -308,6 +316,16 @@ namespace RageCoop.Client
{
if (p.MainProjectile.AttachedEntity==null)
{
/// Prevent projectiles from exploding next to vehicle
if (Util.VehicleProjectileWeapons.Contains((VehicleWeaponHash)p.MainProjectile.WeaponHash))
{
if (p.Origin.DistanceTo(p.MainProjectile.Position)<2)
{
continue;
}
}
Networking.SendProjectile(p);
}
}
@ -327,7 +345,7 @@ namespace RageCoop.Client
}
}
lock (PedsLock)
{