/// <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); }
public bool OnServerStartProgress(StartProgressInfo info) { if (used) { Logger.LogError("Attempted to reuse a StandardProgressAction that has already been used." + " Please create a new StandardProgressAction each time you start a new action.", Category.ProgressAction); return(false); } startProgressInfo = info; //interrupt if hand contents are changed playerScript = info.Performer.Player().Script; if (!progressActionConfig.AllowMultiple) { try { //check if the performer is already doing this action type anywhere else var existingAction = UIManager.Instance.ProgressBars .Where(pb => pb.RegisterPlayer != null && pb.RegisterPlayer.gameObject == info.Performer) .FirstOrDefault(pb => { if (pb.ServerProgressAction is StandardProgressAction standardProgressAction) { return(standardProgressAction.progressActionConfig.StandardProgressActionType == progressActionConfig.StandardProgressActionType); } return(false); }); if (existingAction != null) { Logger.LogTraceFormat( "Server cancelling progress bar {0} start because AllowMultiple=true and progress bar {1} " + " has same progress type and is already in progress.", Category.ProgressAction, info.ProgressBar.ID, existingAction.ID); return(false); } } catch { Logger.LogError( "Something terrible happened to ProgressBars but we have recovered.", Category.ProgressAction); return(false); } } //check if there is already progress of this type at this location by this player var targetParent = info.Target.TargetMatrixInfo.Objects; var existingBar = UIManager.Instance.ProgressBars .Where(pb => pb.RegisterPlayer != null && pb.RegisterPlayer.gameObject == info.Performer) .Where(pb => pb.transform.parent == targetParent) .FirstOrDefault(pb => Vector3.Distance(pb.transform.localPosition, info.Target.TargetLocalPosition) < 0.1); if (existingBar != null) { //progress already started by this player at this position Logger.LogTraceFormat("Server cancelling progress bar {0} start because progress bar {1} " + " has same progress type and is already in progress at the target location by this player.", Category.ProgressAction, info.ProgressBar.ID, existingBar.ID); return(false); } //is this cross matrix? if so, don't start progress if either matrix is moving var performerMatrix = playerScript.registerTile.Matrix; crossMatrix = performerMatrix != info.Target.TargetMatrixInfo.Matrix; if (crossMatrix && (performerMatrix.IsMovingServer || info.Target.TargetMatrixInfo.Matrix.IsMovingServer)) { //progress already started by this player at this position Logger.LogTraceFormat("Server cancelling progress bar {0} start because it is cross matrix and one of" + " the matrices is moving.", Category.ProgressAction, info.ProgressBar.ID); return(false); } //we are going to start progress, so set up the hooks RegisterHooks(); return(true); }