public void SendShieldMessage(int id) { string s = SerializationScript.SerlializeShieldMessage(id); SendData(s, 1, true); _processor.playerManager.TurnOnShield(s.Split(':')); }
internal void SpawnBall(string[] splitcode) { int index = int.Parse(splitcode[1]); Vector3 position = SerializationScript.StringToVector3(splitcode[2]); EventController.FireEvent(new NetworkAbilityBallMessage(index, position)); }
public void SendTriggerdAbilityEvent(int id, GameEvent theEvent, params object[] list) { string s = SerializationScript.SerializeTriggerdAbilityEvent(id, theEvent, list); SendData(s, 1, true); _processor.ballAbilityManager.DoAbilityEvent(s.Split(':'), 0); }
/// <summary> /// Deadreckons and updates veloctiy of a specific ball /// </summary> /// <param name="code">The message data from the packets.</param> /// <param name="delay">The delay between sending and recieving packets.</param> internal void UpdateBallMovement(string code, int delay) { string[] splitCode = code.Split(':'); int id = int.Parse(splitCode[1]); GameObject ball = bool.Parse(splitCode[splitCode.Length - 1]) ? GetAbilityBallOfID(id) : GetBallOfID(id); if (!ball) { return; } Vector3 movement = SerializationScript.StringToVector3(splitCode[2]); float delayInSeconds = ((float)delay / 1000.0f); float GravityConstant = ball.GetComponent <BetterGravity>().GetGravityConstant().y; float x = movement.x * delayInSeconds; float z = movement.z * delayInSeconds; float y = movement.y * delayInSeconds + 0.5f * GravityConstant * delayInSeconds * delayInSeconds; ball.transform.position += new Vector3(x, y, z); movement.y = movement.y + GravityConstant * delayInSeconds; ball.GetComponent <Rigidbody>().velocity = movement; ball.GetComponent <BetterGravity>().ShouldUpdateGravity = false; }
/// <summary> /// Hits the ball on the host. /// </summary> /// <param name="code">The message data from the packets.</param> internal void UpdateBalls(string code) { SerializationScript.BallShot ballShot = SerializationScript.DeserializeBallShot(code); GameObject ball = ballShot.isAbilityBall ? golfBallManager.GetAbilityBallOfId(ballShot.ballID) : golfBallManager.GetBallOfId(ballShot.ballID); BallRetrieval br = ball.GetComponent <BallRetrieval>(); ball.GetComponent <Rigidbody>().velocity = ballShot.direction; if (br) { ball.GetComponent <BallRetrieval>().SetNewBallPos(); } GolfBall golf = ball.GetComponent <GolfBall>(); golf.HitBall(ballShot.shooterID, network.IsHost()); if (network.IsHost()) { if (golf.IsAbilityBall()) { MovingAbilityBalls.Add(golf); } if (ballShot.shouldHome) { Honing theHone = ball.gameObject.GetComponent <Honing>(); if (theHone != null && ballShot.homingTargetID >= 0) { theHone.HoneToPlayer(network.GetPlayerOfID(ballShot.homingTargetID)); } } } }
public void UpdateAbilityBalls(int flag, int id, int value) { data.SetAbilityBall(id, value, flag); string s = SerializationScript.SerializeAbilityChangeEvent(id, flag, value); SendData(s, 1, true); }
public void SendReadyUp() { if (!_ready[_myID]) { _processor.gameStateManager.CallReadyEvent(new NetworkReadyUp(_myID)); _ready[_myID] = true; string s = SerializationScript.SerializeReadyUpMessage(_myID); SendData(s, 1, true); } if (IsHost()) { if (_ready.Contains(false)) { print("Waiting for all players to ready up!"); } else { string s = SerializationScript.SerializeRestartGameMessage(); SendData(s, 1, true); SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); } } else { print("Waiting on host!"); } }
/// <summary> /// Responsible for sending the item used and updating the particle effects on the effected players /// </summary> /// <param name="itemID"> ID of the item used </param> /// <param name="floatInfo"> Floats needed for the item </param> /// <param name="intInfo"> Ints needed for the item </param> /// <param name="sendToAll"> Should send to all players (false = just host)</param> public void SendItemUseRequest(ItemBoxController.Items itemID, List <float> floatInfo, List <int> intInfo, bool sendToAll = true) { string s = SerializationScript.SerializeItemGameMessage(_myID, itemID, floatInfo, intInfo); SendData(s, 1, sendToAll); if (network.IsHost()) { ProcessItem(s.Split(':')); } else { EventItemFeedEvent(new ItemFeedMessage(_myID, itemID)); switch (itemID) { case ItemBoxController.Items.SwingFuel: EventClientParticleEffect(new ParticleEffectMessage(ParticleEffectMessage.Effect.Inked, _myID)); break; case ItemBoxController.Items.ConfusedControls: EventClientParticleEffect(new ParticleEffectMessage(ParticleEffectMessage.Effect.Confused, _myID)); break; default: break; } } }
private void HandleRequestForTeam(int id) { data.AddToTeam(id, id % 2); string s = SerializationScript.SerializeTeamAssignment(NetworkStoredData.instance.GetTeam()); SendData(s, 1, true); EventController.FireEvent(new ConnectedUsersUpdate(data.GetTeam())); }
public void SendItemBoxUsed(int boxID, GameObject player) { int id = GetIdOfPlayer(player); string s = SerializationScript.SerializeItemBoxPickUp(id, boxID); SendData(s, 1, true); _processor.itemManager.UpdateItemBox(s.Split(':')); }
public void SendEndGameRequest() { if (IsHost()) { string s = SerializationScript.SerializeEndGameMessage(); SendData(s, 1, true); _processor.gameStateManager.CallEndGameEvent(); } }
public void SendRunAnimationState(PlayerAnimation.RunState state) { if (state != prevRunState) { string s = SerializationScript.SerlializeRunAnimationState(_myID, state); SendData(s, 1, true); prevRunState = state; } }
public void SendHealRequest(float healAmount, int id, int boxID = -1) { string s = SerializationScript.SerializeHealGameMessage(id, healAmount, boxID); SendData(s, 1, true); if (IsHost()) { _processor.itemManager.HealthPlayer(s.Split(':')); } }
public void SendDamageMessage(GameObject obj, int shooterID) { int id = _players.IndexOf(obj); IHaveHealth health = _players[id].GetComponent(typeof(IHaveHealth)) as IHaveHealth; float currentHealth = health.GetHealth(); string s = SerializationScript.SerializePlayerHealth(id, currentHealth, shooterID); SendData(s, 1, true); }
public void SendTeamScore(int team) { string s = SerializationScript.SerializeTeamScore(team); SendData(s, 2, _myID == 0); if (IsHost()) { _processor.gameStateManager.UpdateTeamScore(s.Split(':')); } }
public void SendAbilityBall(int index, Vector3 position) { string s = SerializationScript.SerializeAbilitySpawn(index, position); SendData(s, 1, true); if (IsHost()) { _processor.ballAbilityManager.SpawnBall(s.Split(':')); } }
private void SendJumpMessage() { string s = SerializationScript.SerlializeJumpMessage(_myID); SendData(s, 1, true); if (IsHost()) { //TODO: ADD to jump superlatives } }
public void SendKillFeedMessage(int killer, int victim) { string s = SerializationScript.SerializeKillFeed(killer, victim); SendData(s, 2, true); if (IsHost()) { _processor.gameStateManager.UpdateKillFeed(s.Split(':')); } }
public void SendBallMessage(GameObject ball, int id, bool isAbilityBall = false) { string s = SerializationScript.SerializeTransform("1", ball.transform, GameEvent.BALL_TRANSFORM, isAbilityBall); SendData(s, 1, true, id); Vector3 move = ball.GetComponent <Rigidbody>().velocity; s = SerializationScript.SerializeBallVelocityMessage(move, id, isAbilityBall); SendData(s, 1, true, id); }
public void SendMovementRequest() { Vector3 move = _localPlayerMovement.Movement; string s = SerializationScript.SerializePlayerVelocity(_myID, move); if (_myID == 0) { _processor.playerManager.UpdatePlayerMovement(s, 0); } SendData(s, 1, true); }
public void SendPortableSpeakers(Vector3 direction, Vector3 position, float blastDistance, float stunTime, float visualTime) { string s = "Item:Speakers:" + SerializationScript.Vector3ToString(direction) + ":" + SerializationScript.Vector3ToString(position) + ":" + blastDistance + ":" + stunTime + ":" + visualTime; if (_myID == 0) { _processor.itemManager.ProcessItem(s.Split(':')); } else { SendData(s, 1, true); } }
/// <summary> /// Respawn a player to the correct position on the network. /// </summary> /// <param name="splitCode">The message data from the packets</param> internal void UpdateRespawn(string[] splitCode) { int id = int.Parse(splitCode[1]); Vector3 pos = SerializationScript.StringToVector3(splitCode[2]); GameObject player = network.GetPlayerOfID(id); if (id == _myID) { RespawnManager.instance.Revive(player.GetComponent <PlayerHealth>(), pos); } else { RespawnManager.instance.Revive(player, pos); } }
public void SendRequestToHitBall(GameObject ball, int id, Vector3 dir, bool isAbilityBall, bool shouldHome, int targetID) { if (id < 0) { id = _processor.ballManager.golfBallManager.GetIdOfAbilityBall(ball.GetComponent <AbilityBall>()); } string s = SerializationScript.SerializeBallMessage(dir, id, _myID, isAbilityBall, shouldHome, targetID); if (_myID == 0) { _processor.ballManager.UpdateBalls(s); } else { SendData(s, 1, false); } }
/// <summary> /// Deadreckon and update the velocity of a specific player /// </summary> /// <param name="code">The message data from the packets</param> /// <param name="delay"> The delay between sending and recieving packets </param> internal void UpdatePlayerMovement(string code, int delay) { string[] splitCode = code.Split(':'); int id = int.Parse(splitCode[1]); float delayInSeconds = ((float)delay / 1000.0f); if (id == _myID || network.GetPlayerOfID(id) == null) { return; } Vector3 movement = SerializationScript.StringToVector3(splitCode[2]); float x = movement.x * delayInSeconds; float z = movement.z * delayInSeconds; float y = movement.y * delayInSeconds + 0.5f * PlayerGravity.y * delayInSeconds * delayInSeconds; network.GetPlayerOfID(id).transform.position += new Vector3(x, y, z); network.GetPlayerOfID(id).GetComponent <Rigidbody>().velocity = movement; }
public override void HandleEvent(EventMessage e) { if (!isConnect) { return; } if (e is NetworkSendBallRespawn respawn) { SendBallMessage(respawn.ball.gameObject, respawn.ball.transform.GetSiblingIndex()); SendTeamScore(respawn.teamScorer); } else if (e is ChangeHoleEvent) { string s = SerializationScript.SerlializeChangeHoleEvent(); SendData(s, 1, true); } else if (e is SendShieldMessage shield) { SendShieldMessage(shield.id); } else if (e is SendRunAnimMessage runAnim) { SendRunAnimationState(runAnim.state); } else if (e is JumpMessage) { SendJumpMessage(); } else if (e is ModeChangedMessage modeChange) { SendModeChange(modeChange.modeChangedToGolf); } else if (e is SendClubSwingAnimation swingAim) { SendClubSwingAnim(swingAim.activeClub); } else if (e is PersonalScoreMessage personalScore) { SendPersonalScore(personalScore.id, personalScore.type); } }
internal void AbilityBallVFX(string[] splitcode) { WorldSpaceVFX.WorldVFXType type = (WorldSpaceVFX.WorldVFXType)System.Enum.Parse(typeof(WorldSpaceVFX.WorldVFXType), splitcode[1]); Vector3 position = SerializationScript.StringToVector3(splitcode[2]); int id = int.Parse(splitcode[3]); int ballID = int.Parse(splitcode[4]); if (ballID >= 0) { EventController.FireEvent(new DeactivateBall(ballID)); } if (id > 0) { EventController.FireEvent(new WorldVFXMessage(type, position, network.GetPlayerOfID(id).transform)); } else { EventController.FireEvent(new WorldVFXMessage(type, position)); } }
/// <summary> /// Updates the scoreboard of a specific player. /// </summary> /// <param name="code">The message data from the packets</param> internal void UpdateScore(string code) { SerializationScript.ScoreUpdate score = SerializationScript.DeserializeScore(code); // network.GetPlayerOfID(score.ID).GetComponent<PlayerScoreTracker>().UpdateEntity(score.ID, score.CurrentStrokes, score.PersonalBest, score.Kills, score.Deaths, score.ID == _myID); }
public void SendWorldVFX(WorldSpaceVFX.WorldVFXType type, Vector3 positio, int idOfTransform = -1, int idOfBall = -1) { string s = SerializationScript.SerializeWorldVFX(type, positio, idOfTransform, idOfBall); SendData(s, 1, true); }
public void SendPayRespects() { string s = SerializationScript.SerializePayRespectMessage(_myID); SendData(s, 1, true); }
public void SendRespawnUpdate(Vector3 position, int id) { string s = SerializationScript.SerializeRespawnMessage(position, id); SendData(s, 1, true); }