/// <summary> /// For progress action system internal use only. Please use ProgressAction.ServerStartProgress to initiate a progress action /// on the server side. /// /// Initiate this progress bar's behavior on server side. Assumes position is already set to where the progress /// bar should appear. /// </summary> /// <param name="progressAction">progress action being performed</param> /// <param name="startInfo">info on the started action</param> public void _ServerStartProgress(IProgressAction progressAction, StartProgressInfo startInfo) { done = true; progress = 0f; lastSpriteIndex = 0; timeToFinish = startInfo.TimeForCompletion; registerPlayer = startInfo.Performer.GetComponent <RegisterPlayer>(); this.progressAction = progressAction; id = GetInstanceID(); if (startInfo.Performer != PlayerManager.LocalPlayer) { //server should not see clients progress bar spriteRenderer.enabled = false; } else { spriteRenderer.enabled = true; } spriteRenderer.sprite = progressSprites[0]; CommonStartProgress(); //Start the progress for the player: //note: using transform position for the offset, because progress bar has no register tile and //otherwise it would give an incorrect offset if player is on moving matrix ProgressBarMessage.SendCreate(startInfo.Performer, 0, (transform.position - startInfo.Performer.transform.position).To2Int(), id); }
//Server only: private void UpdateProgressBars() { for (int i = playerProgress.Count - 1; i >= 0; i--) { playerProgress[i].progress += Time.deltaTime; if (playerProgress[i].timeToNotifyPlayer) { //Update the players progress bar ProgressBarMessage.Send(playerProgress[i].player, playerProgress[i].spriteIndex, playerProgress[i].position); if (playerProgress[i].spriteIndex == 12) { //Almost done, check to see if there is an additionalSFX to play: playerProgress[i].PlayAdditionalSound(); } } //Cancel the progress bar if the player moves away or faces another direction: if (playerProgress[i].HasMovedAway()) { playerProgress[i].completedAction.Finish(FinishProgressAction.FinishReason.INTERRUPTED); CloseProgressBar(playerProgress[i]); continue; } //Finished! Invoke the action and close the progress bar for the player if (playerProgress[i].progress >= playerProgress[i].timeToFinish) { playerProgress[i].completedAction.Finish(FinishProgressAction.FinishReason.COMPLETED); CloseProgressBar(playerProgress[i]); } } }
private void CloseProgressBar(PlayerProgressEntry playerProg) { //Notify player to turn off progress bar: ProgressBarMessage.Send(playerProg.player, -1, playerProg.position); //remove from the player progress list: playerProgress.Remove(playerProg); }
/// <summary> /// Sends the message to update the progress bar with the specified id /// </summary> /// <param name="recipient"></param> /// <param name="spriteIndex"></param> /// <param name="progressBarID"></param> /// <returns></returns> public static ProgressBarMessage SendUpdate(GameObject recipient, int spriteIndex, int progressBarID) { ProgressBarMessage msg = new ProgressBarMessage { Recipient = recipient.GetComponent <NetworkIdentity>().netId, SpriteIndex = spriteIndex, ProgressBarID = progressBarID }; msg.SendTo(recipient); return(msg); }
public static ProgressBarMessage Send(GameObject recipient, int spriteIndex, Vector3 pos) { ProgressBarMessage msg = new ProgressBarMessage { Recipient = recipient.GetComponent <NetworkIdentity>().netId, SpriteIndex = spriteIndex, Position = pos }; msg.SendTo(recipient); return(msg); }
/// <summary> /// Sends the message to create the progress bar client side /// </summary> /// <param name="recipient"></param> /// <param name="spriteIndex"></param> /// <param name="offsetFromPlayer">offset from player performing the progress action</param> /// <param name="progressBarID"></param> /// <returns></returns> public static ProgressBarMessage SendCreate(GameObject recipient, int spriteIndex, Vector2Int offsetFromPlayer, int progressBarID) { ProgressBarMessage msg = new ProgressBarMessage { Recipient = recipient.GetComponent <NetworkIdentity>().netId, SpriteIndex = spriteIndex, OffsetFromPlayer = offsetFromPlayer, ProgressBarID = progressBarID }; msg.SendTo(recipient); return(msg); }
void Update() { if (done) { return; } if (animIdx != -1 && lastSpriteIndex >= animIdx) { anim += Time.deltaTime * animSpd; var deg = Mathf.Lerp(0, 360, Mathf.SmoothStep(0f, 1f, Mathf.SmoothStep(0f, 1f, anim / 360f))); spriteRenderer.transform.parent.localRotation = Quaternion.Euler(0, 0, deg); if (deg >= 360) { spriteRenderer.transform.parent.localRotation = Quaternion.identity; animIdx = -1; } } //server only if (registerPlayer == null) { return; } progress += Time.deltaTime; if (timeToNotifyPlayer) { //Update the players progress bar ProgressBarMessage.SendUpdate(registerPlayer.gameObject, spriteIndex, id); lastSpriteIndex = spriteIndex; } //Cancel the progress bar if the player moves away or faces another direction: if (Interrupted()) { completedEndAction.OnEnd(ProgressEndReason.INTERRUPTED); ServerCloseProgressBar(); return; } //Finished! Invoke the action and close the progress bar for the player if (progress >= timeToFinish) { completedEndAction.OnEnd(ProgressEndReason.COMPLETED); if (progressAction.InterruptsOverlapping) { //interrupt all other progress actions of this type at this location UIManager.ServerInterruptProgress(this, progressAction, transform.localPosition, transform.parent); } ServerCloseProgressBar(); } }
void UpdateMe() { if (done) { return; } if (animIdx != -1 && lastSpriteIndex >= animIdx) { anim += Time.deltaTime * animSpd; var deg = Mathf.Lerp(0, 360, Mathf.SmoothStep(0f, 1f, Mathf.SmoothStep(0f, 1f, anim / 360f))); spriteRenderer.transform.parent.localRotation = Quaternion.Euler(0, 0, deg); if (deg >= 360) { spriteRenderer.transform.parent.localRotation = Quaternion.identity; animIdx = -1; } } //server only if (registerPlayer == null) { return; } progress += Time.deltaTime; if (timeToNotifyPlayer) { //Update the players progress bar ProgressBarMessage.SendUpdate(registerPlayer.gameObject, spriteIndex, id); lastSpriteIndex = spriteIndex; } //check if progress should continue if (!progressAction.OnServerContinueProgress(new InProgressInfo(progress))) { // Remove from UpdateMe before invoking action, lest action fails and so infinite loop. ServerCloseProgressBar(); progressAction.OnServerEndProgress(new EndProgressInfo(false)); Logger.LogTraceFormat("Server progress bar {0} interrupted.", Category.ProgressAction, ID); } //Finished! Invoke the action and close the progress bar for the player if (progress >= timeToFinish) { // Remove from UpdateMe before invoking action, lest action fails and so infinite loop. ServerCloseProgressBar(); progressAction.OnServerEndProgress(new EndProgressInfo(true)); Logger.LogTraceFormat("Server progress bar {0} completed.", Category.ProgressAction, ID); } }
private void ServerCloseProgressBar() { done = true; //Notify player to turn off progress bar: if (PlayerManager.LocalPlayer == registerPlayer.gameObject) { //server player's bar, just destroy it DestroyProgressBar(); } else { //inform client ProgressBarMessage.SendUpdate(registerPlayer.gameObject, COMPLETE_INDEX, id); //destroy server's local copy DestroyProgressBar(); } }
void Update() { if (done) { return; } if (animIdx != -1 && lastSpriteIndex >= animIdx) { anim += Time.deltaTime * animSpd; var deg = Mathf.Lerp(0, 360, Mathf.SmoothStep(0f, 1f, Mathf.SmoothStep(0f, 1f, anim / 360f))); spriteRenderer.transform.parent.localRotation = Quaternion.Euler(0, 0, deg); if (deg >= 360) { spriteRenderer.transform.parent.localRotation = Quaternion.identity; animIdx = -1; } } //server only if (registerPlayer == null) { return; } progress += Time.deltaTime; if (timeToNotifyPlayer) { //Update the players progress bar ProgressBarMessage.SendUpdate(registerPlayer.gameObject, spriteIndex, id); lastSpriteIndex = spriteIndex; } //check if progress should continue if (!progressAction.OnServerContinueProgress(new InProgressInfo(progress))) { progressAction.OnServerEndProgress(new EndProgressInfo(false)); ServerCloseProgressBar(); } //Finished! Invoke the action and close the progress bar for the player if (progress >= timeToFinish) { progressAction.OnServerEndProgress(new EndProgressInfo(true)); ServerCloseProgressBar(); } }
/// <summary> /// Initiate this progress bar's behavior on server side. Assumes position is already set to where the progress /// bar should appear. /// </summary> /// <param name="progressAction">progress action being performed</param> /// <param name="timeForCompletion">how long in seconds the action should take</param> /// <param name="progressEndAction">callback for when action completes or is interrupted</param> /// <param name="player">player performing the action</param> public void ServerStartProgress(ProgressAction progressAction, float timeForCompletion, IProgressEndAction progressEndAction, GameObject player) { done = true; playerDirectional = player.GetComponent <Directional>(); progress = 0f; lastSpriteIndex = 0; timeToFinish = timeForCompletion; completedEndAction = progressEndAction; facingDirectionCache = playerDirectional.CurrentDirection; registerPlayer = player.GetComponent <RegisterPlayer>(); playerSync = player.GetComponent <PlayerSync>(); this.progressAction = progressAction; id = GetInstanceID(); //check if something is in hand so we can interrupt if it's dropped var usedItemObj = player.Player().Script.playerNetworkActions.GetActiveHandItem(); if (usedItemObj != null) { usedItem = usedItemObj.GetComponent <Pickupable>(); if (usedItem != null) { usedItem.OnDropServer.AddListener(ServerInterruptOnDrop); } } if (player != PlayerManager.LocalPlayer) { //server should not see clients progress bar spriteRenderer.enabled = false; } else { spriteRenderer.enabled = true; } spriteRenderer.sprite = progressSprites[0]; CommonStartProgress(); //Start the progress for the player: //note: using transform position for the offset, because progress bar has no register tile and //otherwise it would give an incorrect offset if player is on moving matrix ProgressBarMessage.SendCreate(player, 0, (transform.position - player.transform.position).To2Int(), id); }
private void ServerCloseProgressBar() { done = true; //Notify player to turn off progress bar: if (PlayerManager.LocalPlayer == registerPlayer.gameObject) { //server player's bar, just destroy it DestroyProgressBar(); } else { Logger.LogTraceFormat("Server telling {0} to close progress bar {1}", Category.ProgressAction, registerPlayer.gameObject, ID); ProgressBarMessage.SendUpdate(registerPlayer.gameObject, COMPLETE_INDEX, id); //destroy server's local copy DestroyProgressBar(); } }
/// <summary> /// Initiate this progress bar's behavior on server side. Assumes position is already set to where the progress /// bar should appear. /// </summary> /// <param name="progressAction">progress action being performed</param> /// <param name="timeForCompletion">how long in seconds the action should take</param> /// <param name="progressEndAction">callback for when action completes or is interrupted</param> /// <param name="player">player performing the action</param> public void ServerStartProgress(ProgressAction progressAction, float timeForCompletion, IProgressEndAction progressEndAction, GameObject player) { done = true; playerDirectional = player.GetComponent <Directional>(); progress = 0f; lastSpriteIndex = 0; timeToFinish = timeForCompletion; completedEndAction = progressEndAction; facingDirectionCache = playerDirectional.CurrentDirection; registerPlayer = player.GetComponent <RegisterPlayer>(); playerSync = player.GetComponent <PlayerSync>(); this.progressAction = progressAction; id = GetInstanceID(); //interrupt if hand contents are changed var activeSlot = player.Player().Script.ItemStorage.GetActiveHandSlot(); activeSlot.OnSlotContentsChangeServer.AddListener(ServerInterruptOnInvChange); this.usedSlot = activeSlot; if (player != PlayerManager.LocalPlayer) { //server should not see clients progress bar spriteRenderer.enabled = false; } else { spriteRenderer.enabled = true; } spriteRenderer.sprite = progressSprites[0]; CommonStartProgress(); //Start the progress for the player: //note: using transform position for the offset, because progress bar has no register tile and //otherwise it would give an incorrect offset if player is on moving matrix ProgressBarMessage.SendCreate(player, 0, (transform.position - player.transform.position).To2Int(), id); }
public void StartProgress(Vector3 pos, float timeForCompletion, FinishProgressAction finishProgressAction, GameObject _player, string _additionalSfx = "", float _additionalSfxPitch = 1f) { var _playerSprites = _player.GetComponent <PlayerSprites>(); playerProgress.Add(new PlayerProgressEntry { player = _player, timeToFinish = timeForCompletion, completedAction = finishProgressAction, position = pos, playerSprites = _playerSprites, playerPositionCache = _player.transform.position, facingDirectionCache = _playerSprites.CurrentDirection, additionalSfx = _additionalSfx, additionalSfxPitch = _additionalSfxPitch }); //Start the progress for the player: ProgressBarMessage.Send(_player, 0, pos); }
public void StartProgress(Vector3 pos, float timeForCompletion, FinishProgressAction finishProgressAction, GameObject _player, string _additionalSfx = "", float _additionalSfxPitch = 1f, bool _allowTurning = true) { var _playerDirectional = _player.GetComponent <Directional>(); playerProgress.Add(new PlayerProgressEntry { player = _player, timeToFinish = timeForCompletion, completedAction = finishProgressAction, position = pos, playerDirectional = _playerDirectional, playerPositionCache = _player.TileWorldPosition(), facingDirectionCache = _playerDirectional.CurrentDirection, additionalSfx = _additionalSfx, additionalSfxPitch = _additionalSfxPitch, allowTurning = _allowTurning }); //Start the progress for the player: ProgressBarMessage.Send(_player, 0, pos); }