public void ServerShoot(GameObject shotBy, Vector2 direction, string bulletName, BodyPartType damageZone, bool isSuicideShot) { PlayerMove shooter = shotBy.GetComponent <PlayerMove>(); if (!shooter.allowInput || shooter.isGhost) { return; } Shoot(shotBy, direction, bulletName, damageZone, isSuicideShot); //This is used to determine where bullet shot should head towards on client Ray2D ray = new Ray2D(shotBy.transform.position, direction); ShootMessage.SendToAll(gameObject, ray.GetPoint(30f), bulletName, damageZone, shotBy); if (SpawnsCaseing) { if (casingPrefab == null) { casingPrefab = Resources.Load("BulletCasing") as GameObject; } ItemFactory.SpawnItem(casingPrefab, shotBy.transform.position, shotBy.transform.parent); } }
private void DequeueAndProcessServerShot() { if (queuedShots.Count > 0) { QueuedShot nextShot = queuedShots.Dequeue(); // check if we can still shoot PlayerMove shooter = nextShot.shooter.GetComponent <PlayerMove>(); PlayerScript shooterScript = nextShot.shooter.GetComponent <PlayerScript>(); if (!shooter.allowInput || shooterScript.IsGhost) { Logger.Log("A player tried to shoot when not allowed or when they were a ghost.", Category.Exploits); Logger.LogWarning("A shot was attempted when shooter is a ghost or is not allowed to shoot.", Category.Firearms); return; } if (CurrentMagazine == null || CurrentMagazine.ServerAmmoRemains <= 0 || Projectile == null) { Logger.LogTrace("Player tried to shoot when there was no ammo.", Category.Exploits); Logger.LogWarning("A shot was attempted when there is no ammo.", Category.Firearms); return; } if (FireCountDown > 0) { Logger.LogTrace("Player tried to shoot too fast.", Category.Exploits); Logger.LogWarning("Shot was attempted to be dequeued when the fire count down is not yet at 0.", Category.Exploits); return; } //perform the actual server side shooting, creating the bullet that does actual damage DisplayShot(nextShot.shooter, nextShot.finalDirection, nextShot.damageZone, nextShot.isSuicide); //trigger a hotspot caused by gun firing shooterRegisterTile.Matrix.ReactionManager.ExposeHotspotWorldPosition(nextShot.shooter.TileWorldPosition(), 3200, 0.005f); //tell all the clients to display the shot ShootMessage.SendToAll(nextShot.finalDirection, nextShot.damageZone, nextShot.shooter, this.gameObject, nextShot.isSuicide); //kickback shooterScript.pushPull.Pushable.NewtonianMove((-nextShot.finalDirection).NormalizeToInt()); if (SpawnsCasing) { if (casingPrefabOverride == null) { //no casing override set, use normal casing prefab casingPrefabOverride = Resources.Load("BulletCasing") as GameObject; } Spawn.ServerPrefab(casingPrefabOverride, nextShot.shooter.transform.position, nextShot.shooter.transform.parent); } } }
/// <summary> /// Tell all clients + server to perform a shot with the specified parameters. /// </summary> /// <param name="direction">Direction of shot from shooter</param> /// <param name="damageZone">body part being targeted</param> /// <param name="shooter">gameobject of player making the shot</param> /// <param name="isSuicide">if the shooter is shooting themselves</param> /// <returns></returns> public static ShootMessage SendToAll(Vector2 direction, BodyPartType damageZone, GameObject shooter, GameObject weapon, bool isSuicide) { var msg = new ShootMessage { Weapon = weapon ? weapon.GetComponent <NetworkIdentity>().netId : NetId.Invalid, Direction = direction, DamageZone = damageZone, Shooter = shooter ? shooter.GetComponent <NetworkIdentity>().netId : NetId.Invalid, IsSuicideShot = isSuicide }; msg.SendToAll(); return(msg); }
private void DequeueAndProcessServerShot() { if (queuedShots.Count > 0) { QueuedShot nextShot = queuedShots.Dequeue(); // check if we can still shoot PlayerMove shooter = nextShot.shooter.GetComponent <PlayerMove>(); PlayerScript shooterScript = nextShot.shooter.GetComponent <PlayerScript>(); if (!shooter.allowInput || shooterScript.IsGhost) { Logger.Log("A player tried to shoot when not allowed or when they were a ghost.", Category.Exploits); Logger.LogWarning("A shot was attempted when shooter is a ghost or is not allowed to shoot.", Category.Firearms); return; } if (CurrentMagazine == null || CurrentMagazine.ServerAmmoRemains <= 0 || CurrentMagazine.containedBullets[0] == null) { Logger.LogTrace("Player tried to shoot when there was no ammo.", Category.Exploits); Logger.LogWarning("A shot was attempted when there is no ammo.", Category.Firearms); return; } if (FireCountDown > 0) { Logger.LogTrace("Player tried to shoot too fast.", Category.Exploits); Logger.LogWarning("Shot was attempted to be dequeued when the fire count down is not yet at 0.", Category.Exploits); return; } GameObject toShoot = CurrentMagazine.containedBullets[0]; int quantity = CurrentMagazine.containedProjectilesFired[0]; if (toShoot == null) { Logger.LogError("Shot was attempted but no projectile or quantity was found to use", Category.Firearms); return; } //perform the actual server side shooting, creating the bullet that does actual damage DisplayShot(nextShot.shooter, nextShot.finalDirection, nextShot.damageZone, nextShot.isSuicide, toShoot.name, quantity); //trigger a hotspot caused by gun firing shooterRegisterTile.Matrix.ReactionManager.ExposeHotspotWorldPosition(nextShot.shooter.TileWorldPosition()); //tell all the clients to display the shot ShootMessage.SendToAll(nextShot.finalDirection, nextShot.damageZone, nextShot.shooter, this.gameObject, nextShot.isSuicide, toShoot.name, quantity); if (isSuppressed == false && nextShot.isSuicide == false) { Chat.AddActionMsgToChat(serverHolder, $"You fire your {gameObject.ExpensiveName()}", $"{serverHolder.ExpensiveName()} fires their {gameObject.ExpensiveName()}"); } //kickback shooterScript.pushPull.Pushable.NewtonianMove((-nextShot.finalDirection).NormalizeToInt()); if (SpawnsCasing) { if (casingPrefabOverride == null) { //no casing override set, use normal casing prefab casingPrefabOverride = CustomNetworkManager.Instance.GetSpawnablePrefabFromName("BulletCasing"); } Spawn.ServerPrefab(casingPrefabOverride, nextShot.shooter.transform.position, nextShot.shooter.transform.parent); } } }