Beispiel #1
0
    // Handles what happens to the contents of the box when you pick up the block.
    private void EventData_Event(TimerEventData timerData)
    {
        #region EventData_Event
        World world = GameManager.Instance.World;

        object[]                array                   = (object[])timerData.Data;
        int                     clrIdx                  = (int)array[0];
        BlockValue              blockValue              = (BlockValue)array[1];
        Vector3i                vector3i                = (Vector3i)array[2];
        BlockValue              block                   = world.GetBlock(vector3i);
        EntityPlayerLocal       entityPlayerLocal       = array[3] as EntityPlayerLocal;
        TileEntityLootContainer tileEntityLootContainer = world.GetTileEntity(clrIdx, vector3i) as TileEntityLootContainer;
        if (tileEntityLootContainer == null)
        {
            world.GetGameManager().DropContentOfLootContainerServer(blockValue, vector3i, tileEntityLootContainer.entityId);
        }

        // Pick up the item and put it inyor your inventory.
        LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(entityPlayerLocal);
        ItemStack     itemStack   = new ItemStack(block.ToItemValue(), 1);
        if (!uiforPlayer.xui.PlayerInventory.AddItem(itemStack, true))
        {
            uiforPlayer.xui.PlayerInventory.DropItem(itemStack);
        }
        world.SetBlockRPC(clrIdx, vector3i, BlockValue.Air);

        #endregion
    }
Beispiel #2
0
 public void TakeItemWithTimer(int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player)
 {
     if (_blockValue.damage > 0)
     {
         GameManager.ShowTooltipWithAlert(_player as EntityPlayerLocal, Localization.Get("ttRepairBeforePickup", string.Empty), "ui_denied");
     }
     else
     {
         LocalPlayerUI playerUi = (_player as EntityPlayerLocal).PlayerUI;
         playerUi.windowManager.Open("timer", true, false, true);
         XUiC_Timer     childByType = playerUi.xui.GetChildByType <XUiC_Timer>();
         TimerEventData _eventData  = new TimerEventData
         {
             Data = new object[4]
             {
                 _cIdx,
                 _blockValue,
                 _blockPos,
                 _player
             }
         };
         _eventData.Event += new TimerEventHandler(this.EventData_Event);
         childByType.SetTimer(_takeDelay, _eventData);
     }
 }
Beispiel #3
0
 public void OnTimerExpired(TimerEventData eventData)
 {
     if (onTimerExpired != null)
     {
         onTimerExpired(eventData);
     }
 }
    // Displays the UI for the timer, calling TakeTarget when its done.
    public void TakeItemWithTimer(int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player)
    {
        LocalPlayerUI playerUI = (_player as EntityPlayerLocal).PlayerUI;

        playerUI.windowManager.Open("timer", true, false, true);
        XUiC_Timer     xuiC_Timer     = (XUiC_Timer)playerUI.xui.GetChildByType <XUiC_Timer>();
        TimerEventData timerEventData = new TimerEventData();

        timerEventData.Data = new object[]
        {
            _cIdx,
            _blockValue,
            _blockPos,
            _player
        };
        timerEventData.Event += this.TakeTarget;

        float newTakeTime = this.fTakeDelay;

        // If the entity is holding a crow bar or hammer, then reduce the take time.
        if (_player.inventory.holdingItem.Name == "CrowBar" || _player.inventory.holdingItem.Name == "meleeToolClawHammer")
        {
            // Make sure the item can still be used
            if (_player.inventory.holdingItemItemValue.MaxUseTimes > 0)
            {
                // Bump the Use time by one.
                global::ItemValue itemValue = _player.inventory.holdingItemItemValue;


                // Calculate the degradation value.
                itemValue.UseTimes += (int)EffectManager.GetValue(PassiveEffects.DegradationPerUse, itemValue, 1f, _player, null, default(FastTags), true, true, true, true);
                _player.inventory.holdingItemData.itemValue = itemValue;

                // Automatically reduce the take delay by half if you have a crow bar or claw hammer.
                newTakeTime = (this.fTakeDelay / 2);

                float blockDamage = EffectManager.GetValue(PassiveEffects.BlockDamage, null, 1f, _player, null, default(FastTags), true, true, true, true);
                Debug.Log("Block Damage is: " + blockDamage);

                // Don't divde by 0, but take it as a full timer, since it's level 0.
                if (blockDamage == 0f)
                {
                    newTakeTime = newTakeTime * 1f;
                }
                else
                {
                    newTakeTime = newTakeTime * blockDamage;
                }
            }
        }

        xuiC_Timer.SetTimer(newTakeTime, timerEventData);
    }
    // Displays the UI for the timer, calling TakeTarget when its done.
    public void TakeItemWithTimer(int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player)
    {
        LocalPlayerUI playerUI = (_player as EntityPlayerLocal).PlayerUI;

        playerUI.windowManager.Open("timer", true, false, true);
        XUiC_Timer     xuiC_Timer     = (XUiC_Timer)playerUI.xui.GetChildByType <XUiC_Timer>();
        TimerEventData timerEventData = new TimerEventData();

        timerEventData.Data = new object[]
        {
            _cIdx,
            _blockValue,
            _blockPos,
            _player
        };
        timerEventData.Event += this.TakeTarget;

        float newTakeTime = this.fTakeDelay;

        // If the entity is holding a crow bar or hammer, then reduce the take time.
        if (_player.inventory.holdingItem.Name == "CrowBar" || _player.inventory.holdingItem.Name == "clawHammer")
        {
            // Make sure the item can still be used
            if (_player.inventory.holdingItemItemValue.MaxUseTimes > 0)
            {
                // Bump the Use time by one.
                global::ItemValue itemValue = _player.inventory.holdingItemItemValue;
                itemValue.UseTimes += global::AttributeBase.GetVal <global::AttributeDegradationRate>(itemValue, 1);
                _player.inventory.holdingItemData.itemValue = itemValue;

                // Automatically reduce the take delay by half if you have a crow bar or claw hammer.
                newTakeTime = (this.fTakeDelay / 2);

                Skill tmpSkill = (_player as EntityPlayerLocal).Skills.GetSkillByName("Breaking And Entering");

                // Don't divde by 0, but take it as a full timer, since it's level 0.
                if (tmpSkill.Level == 0)
                {
                    newTakeTime = newTakeTime / 1f;
                }
                else
                {
                    newTakeTime = newTakeTime / tmpSkill.Level;
                }
            }
        }

        xuiC_Timer.SetTimer(newTakeTime, timerEventData);
    }
    // Take logic to replace it with the Downgrade block, matching rotations.
    private void TakeTarget(TimerEventData timerData)
    {
        World world = GameManager.Instance.World;

        object[]          array             = (object[])timerData.Data;
        int               clrIdx            = (int)array[0];
        BlockValue        _blockValue       = (BlockValue)array[1];
        Vector3i          vector3i          = (Vector3i)array[2];
        BlockValue        block             = world.GetBlock(vector3i);
        EntityPlayerLocal entityPlayerLocal = array[3] as EntityPlayerLocal;
        // Find the block value for the pick up value, and add it to the inventory
        BlockValue    pickUpBlock = Block.GetBlockValue(this.PickedUpItemValue, true);
        LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(entityPlayerLocal);
        ItemStack     itemStack   = new ItemStack(pickUpBlock.ToItemValue(), 1);

        if (!uiforPlayer.xui.PlayerInventory.AddItem(itemStack, true))
        {
            uiforPlayer.xui.PlayerInventory.DropItem(itemStack);
        }
        entityPlayerLocal.PlayOneShot("Sounds/DestroyBlock/wooddestroy1");
        // Damage the block for its full health
        this.DamageBlock(world, clrIdx, vector3i, block, block.Block.blockMaterial.MaxDamage, entityPlayerLocal.entityId, false);
    }
Beispiel #7
0
 // We want to give the user the ability to pick up the blocks too, but the loot containers don't support that directly.
 public void TakeItemWithTimer(int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player)
 {
     #region TakeItemWithTimer
     if (_blockValue.damage > 0)
     {
         GameManager.ShowTooltipWithAlert(_player as EntityPlayerLocal, Localization.Get("ttRepairBeforePickup", string.Empty), "ui_denied");
         return;
     }
     LocalPlayerUI playerUI = (_player as EntityPlayerLocal).PlayerUI;
     playerUI.windowManager.Open("timer", true, false, true);
     XUiC_Timer     childByType    = playerUI.xui.GetChildByType <XUiC_Timer>();
     TimerEventData timerEventData = new TimerEventData();
     timerEventData.Data = new object[]
     {
         _cIdx,
         _blockValue,
         _blockPos,
         _player
     };
     timerEventData.Event += this.EventData_Event;
     childByType.SetTimer(this.TakeDelay, timerEventData);
     #endregion
 }
Beispiel #8
0
 private void StartTiming()
 {
     isTiming = true;
     TimerEventData startData = new TimerEventData("start", owner, this);
     if ( startEventName != null )
         EventManager.Instance.CastEvent(EventManager.Instance, startEventName, startData);
 }
Beispiel #9
0
 private void StopTiming()
 {
     if(isTiming) {
         isTiming = false;
         TimerEventData stopData = new TimerEventData("stop", owner, this);
         if (stopEventName != null)
             EventManager.Instance.CastEvent(EventManager.Instance, stopEventName, stopData);
     }
 }