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 registerTile.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 (SpawnsCaseing) { if (casingPrefab == null) { casingPrefab = Resources.Load("BulletCasing") as GameObject; } Spawn.ServerPrefab(casingPrefab, 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 : NetworkInstanceId.Invalid, Direction = direction, DamageZone = damageZone, Shooter = shooter ? shooter.GetComponent <NetworkIdentity>().netId : NetworkInstanceId.Invalid, IsSuicideShot = isSuicide }; msg.SendToAll(); return(msg); }
public async Task PlayerShoot(GameMessage message) { ShootMessage shootMsg = message as ShootMessage; if (shootMsg == null) { throw new Exception($"Player shoot recieved a message that was not of type {typeof(ShootMessage)} but was {message.GetType()}"); } logger.LogInformation($"Player {shootMsg.PlayerId} shot in direction {shootMsg.Direction}"); await stream.OnNextAsync(message); }
//public static ShootMessage Send(GameObject weapon, Vector2 endPos, string bulletName, // BodyPartType damageZone, GameObject shotBy) //{ // var msg = new ShootMessage { // }; // msg.SendTo(recipient); // return msg; //} /// <param name="transformedObject">object to hide</param> /// <param name="state"></param> /// <param name="forced"> /// Used for client simulation, use false if already updated by prediction /// (to avoid updating it twice) /// </param> public static ShootMessage SendToAll(GameObject weapon, Vector2 endPos, string bulletName, BodyPartType damageZone, GameObject shotBy) { var msg = new ShootMessage { Weapon = weapon ? weapon.GetComponent <NetworkIdentity>().netId : NetworkInstanceId.Invalid, EndPos = endPos, BulletName = bulletName, DamageZone = damageZone, ShotBy = shotBy ? shotBy.GetComponent <NetworkIdentity>().netId : NetworkInstanceId.Invalid }; 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.ammoRemains <= 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); //tell all the clients to display the shot ShootMessage.SendToAll(nextShot.finalDirection, nextShot.damageZone, nextShot.shooter, this.gameObject, nextShot.isSuicide); if (SpawnsCaseing) { if (casingPrefab == null) { casingPrefab = Resources.Load("BulletCasing") as GameObject; } PoolManager.PoolNetworkInstantiate(casingPrefab, nextShot.shooter.transform.position, nextShot.shooter.transform.parent); } } }
private void ExecuteShoot(ServerDiepConnection connection, ShootMessage shootMessage) { Broadcast(null, shootMessage); // var spawnMessage = new ShootSpawnMessage() { Id = ++CurrentShootId, IdSupport = connection.Tank.Id, SupportType = shootMessage.SupportType, ShootServerId = CurrentShootId, CannonIndex = shootMessage.CannonIndex }; // Broadcast(null, spawnMessage); }
static public void printExecueQue_MsgList(string text, List <SyncFrame> syn_list) { string str = "Tool " + text + " frame_count = " + syn_list[0].frame_count; foreach (SyncFrame syncFrame in syn_list) { if (syncFrame.msg_list == null) { str += " |msg_list_is_empty| "; } else { foreach (CustomSyncMsg msg in syncFrame.msg_list) { if (msg.msg_type == (int)RequestType.INPUT) { InputMessage input = msg as InputMessage; str += " |msg_type = INPUT" + " moving_x = " + input.moving_x + " moving_y = " + input.moving_y + " moving_z = " + input.moving_z + "clientID = " + msg.player_id + "|"; } else if ((msg.msg_type == (int)RequestType.ROTATE)) { RotateMessage rot = msg as RotateMessage; str += "| msg_type = ROTATE" + " rot.moving_x = " + rot.delta_x + " rot.moving_z = " + rot.delta_y + " clientID = " + msg.player_id + "|"; } else if ((msg.msg_type == (int)RequestType.SHOOT)) { ShootMessage shoot = msg as ShootMessage; str += "|msg_type = SHOOT" + "shoot.direction_x = " + shoot.direction_x + "shoot.direction_y = " + shoot.direction_y + " | "; } } } } Debug.Log(str); }
static public void printMsgList(string text, List <CustomSyncMsg> msg_list) { string str = "Tool " + text; if (msg_list == null) { str += " msg_list is empty"; } else { foreach (CustomSyncMsg msg in msg_list) { if (msg.msg_type == (int)RequestType.INPUT) { InputMessage input = msg as InputMessage; str += " msg_type = INPUT" + " input.moving_x = " + input.moving_x + " input.moving_y = " + input.moving_y + " input.moving_z=" + input.moving_z; } else if ((msg.msg_type == (int)RequestType.ROTATE)) { RotateMessage rot = msg as RotateMessage; str += " msg_type = ROTATE" + "rot.moving_x = " + rot.delta_x + "rot.moving_z = " + rot.delta_y; } else if ((msg.msg_type == (int)RequestType.SHOOT)) { ShootMessage shoot = msg as ShootMessage; str += " msg_type = SHOOT" + "shoot.direction_x = " + shoot.direction_x + "shoot.direction_y = " + shoot.direction_y; } } } Debug.Log(str); }
public static List <CustomSyncMsg> extract_msg(List <p_AllMsg.p_CustomSyncMsg> pmsg_list) { List <CustomSyncMsg> customSyncMsgs = new List <CustomSyncMsg>(); if (pmsg_list == null) { return(null); } foreach (p_AllMsg.p_CustomSyncMsg pmsg in pmsg_list) { if (pmsg.msg_type == (int)RequestType.ROTATE) { p_AllMsg.p_RotateMessage pRotate = pmsg as p_AllMsg.p_RotateMessage; RotateMessage rotate_msg = new RotateMessage(pmsg.player_id, new Vector2(pRotate.delta_x, pRotate.delta_y)); customSyncMsgs.Add(rotate_msg); } else if (pmsg.msg_type == (int)RequestType.SPAWN) { } else if (pmsg.msg_type == (int)RequestType.INPUT) { p_AllMsg.p_InputMessage pInput = pmsg as p_AllMsg.p_InputMessage; InputMessage input_msg = new InputMessage(pmsg.player_id, new Vector3(pInput.moving_x, pInput.moving_y, pInput.moving_z)); customSyncMsgs.Add(input_msg); } else if (pmsg.msg_type == (int)RequestType.SHOOT) { p_AllMsg.p_ShootMessage pshoot = pmsg as p_AllMsg.p_ShootMessage; ShootMessage shoot_msg = new ShootMessage(pmsg.player_id, new Vector3(pshoot.origin_x, pshoot.origin_y, pshoot.origin_z), new Vector3(pshoot.direction_x, pshoot.direction_y, pshoot.direction_z)); customSyncMsgs.Add(shoot_msg); } } return(customSyncMsgs); }
public static List <p_AllMsg.p_CustomSyncMsg> Buffer_SyncFrame_msg_list(List <CustomSyncMsg> msg_list) { List <p_AllMsg.p_CustomSyncMsg> p_msg_list = new List <p_AllMsg.p_CustomSyncMsg>(); foreach (CustomSyncMsg msg in msg_list) { if (msg.msg_type == (int)RequestType.ENTERAREA) { EnterAreaMessage enterArea = msg as EnterAreaMessage; p_AllMsg.p_EnterAreaMessage p_msg = new p_AllMsg.p_EnterAreaMessage(); p_msg.id = enterArea.id; p_msg.health = enterArea.health;; p_msg.position_x = enterArea.position.x; p_msg.position_y = enterArea.position.y; p_msg.position_z = enterArea.position.z; p_msg.direction_x = enterArea.direction.x; p_msg.direction_y = enterArea.direction.y; p_msg.direction_z = enterArea.direction.z; p_msg.rotation_x = enterArea.rotation.x; p_msg.rotation_y = enterArea.rotation.y; p_msg.msg_type = enterArea.msg_type; p_msg.player_id = enterArea.player_id; p_msg.area_id = enterArea.area_id; p_msg_list.Add(p_msg); } if (msg.msg_type == (int)RequestType.INPUT) { InputMessage input = msg as InputMessage; p_AllMsg.p_InputMessage p_msg = new p_AllMsg.p_InputMessage(); p_msg.id = input.id; p_msg.moving_x = input.moving.x; p_msg.moving_y = input.moving.y; p_msg.moving_z = input.moving.z; p_msg.msg_type = input.msg_type; p_msg.player_id = input.player_id; p_msg.area_id = input.area_id; p_msg_list.Add(p_msg); } if (msg.msg_type == (int)RequestType.LEAVEAREA) { LeaveAreaMessage leaveArea = msg as LeaveAreaMessage; p_AllMsg.p_LeaveAreaMessage p_msg = new p_AllMsg.p_LeaveAreaMessage(); p_msg.id = leaveArea.id; p_msg.msg_type = leaveArea.msg_type; p_msg.player_id = leaveArea.player_id; p_msg.area_id = leaveArea.area_id; p_msg_list.Add(p_msg); } if (msg.msg_type == (int)RequestType.ROTATE) { RotateMessage rotate = msg as RotateMessage; p_AllMsg.p_RotateMessage p_msg = new p_AllMsg.p_RotateMessage(); p_msg.id = rotate.id; p_msg.delta_x = rotate.delta.x; p_msg.delta_y = rotate.delta.y; p_msg.msg_type = rotate.msg_type; p_msg.player_id = rotate.player_id; p_msg.area_id = rotate.area_id; p_msg_list.Add(p_msg); } if (msg.msg_type == (int)RequestType.SPAWN) { SpawnMessage spawn = msg as SpawnMessage; p_AllMsg.p_SpawnMessage p_msg = new p_AllMsg.p_SpawnMessage(); p_msg.id = spawn.id; p_msg.position_x = spawn.position.x; p_msg.position_y = spawn.position.y; p_msg.position_z = spawn.position.z; p_msg.msg_type = spawn.msg_type; p_msg.player_id = spawn.player_id; p_msg.area_id = spawn.area_id; p_msg_list.Add(p_msg); } if (msg.msg_type == (int)RequestType.SHOOT) { ShootMessage shoot = msg as ShootMessage; p_AllMsg.p_ShootMessage p_msg = new p_AllMsg.p_ShootMessage(); p_msg.direction_x = shoot.direction_x; p_msg.direction_y = shoot.direction_y; p_msg.direction_z = shoot.direction_z; p_msg.origin_x = shoot.origin_x; p_msg.origin_y = shoot.origin_y; p_msg.origin_z = shoot.origin_z; p_msg.player_id = shoot.player_id; p_msg.msg_type = shoot.msg_type; p_msg_list.Add(p_msg); } } return(p_msg_list); }
protected virtual void HandleShootMessage(ShootMessage Message) { Message.Projectile.ResolveResources(resourceManager, false); Message.Projectile.DecompressResources(); }
public void execute_frames(List <SyncFrame> syncFrames) { foreach (SyncFrame syncFrame in syncFrames) { if (syncFrame.msg_list == null) { Debug.Log("executing frame----" + syncFrame.frame_count + "no msg_list"); continue; } foreach (CustomSyncMsg msg in syncFrame.msg_list) { int clientID = msg.player_id; //Debug.Log("executing frame----" + syncFrame.frame_count + "clientID = " + clientID + "msg.type=" + msg.msg_type); ViewPlayer viewPlayer; if (viewPlayers.ContainsKey(clientID)) { viewPlayer = viewPlayers[clientID]; } else { viewPlayer = generate_other_viewPlayer(clientID); viewPlayer.Start(); viewPlayer.connectID = clientID; } if (msg.msg_type == (int)RequestType.INPUT) { InputMessage Input_msg = msg as InputMessage; viewPlayer.Move(Input_msg.moving_x, Input_msg.moving_z);//接收到的都是非零的x,z Debug.Log("executing frame----" + syncFrame.frame_count + " clientID " + clientID.ToString() + "..........is moving..." + " dist_x = " + Input_msg.moving_x * viewPlayer.get_speed() * Time.deltaTime + " dist_z= " + Input_msg.moving_z * viewPlayer.get_speed() * Time.deltaTime + "y = " + Input_msg.moving_y); } else if (msg.msg_type == (int)RequestType.ROTATE) { RotateMessage rot_msg = msg as RotateMessage; viewPlayer.Rotate(rot_msg.delta_x, rot_msg.delta_y); } else if (msg.msg_type == (int)RequestType.SHOOT) { ShootMessage shoot_msg = msg as ShootMessage; Ray shootRay = new Ray(new Vector3(shoot_msg.origin_x, shoot_msg.origin_y, shoot_msg.origin_z), new Vector3(shoot_msg.direction_x, shoot_msg.direction_y, shoot_msg.direction_z)); OnShootJudging(viewPlayer, shootRay); } else if (msg.msg_type == (int)RequestType.SPAWN) { } //如果是currentPlayer -->cameraFolllow if (viewPlayer.connectID == currentPlayer.connectID) { viewPlayer.camera.CameraUpdate(); InGameGUI.show_infotext("currentHealth:" + viewPlayer.currentHealth); currentPlayerHealthSlider.value = viewPlayer.currentHealth;//只有currentPlayer才显示healthSlider } } } }
private void HandleShootMessage(GameMessage msg) { ShootMessage shootMsg = msg as ShootMessage; this.logger.LogInformation($"{shootMsg.PlayerId} shot in direction {shootMsg.Direction}"); }