Esempio n. 1
0
    /// <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);
    }
Esempio n. 2
0
    /// <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);
    }