Esempio n. 1
0
    public override BlockActivationCommand[] GetBlockActivationCommands(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
    {
        var tileEntity       = _world.GetTileEntity(_clrIdx, _blockPos);
        var secureLootEntity = tileEntity as TileEntitySecureLootContainer;

        if (secureLootEntity == null)
        {
            return(new BlockActivationCommand[0]);
        }
        string _steamID = GamePrefs.GetString(EnumGamePrefs.PlayerId);
        PersistentPlayerData playerData = _world.GetGameManager().GetPersistentPlayerList().GetPlayerData(secureLootEntity.GetOwner());
        bool flag = !secureLootEntity.IsOwner(_steamID) && (playerData != null && playerData.ACL != null && playerData.ACL.Contains(_steamID));

        _activationCommands[0].enabled = true;
        _activationCommands[1].enabled = !secureLootEntity.IsLocked() && (secureLootEntity.IsOwner(_steamID) || flag);
        _activationCommands[2].enabled = secureLootEntity.IsLocked() && secureLootEntity.IsOwner(_steamID);
        _activationCommands[3].enabled = !secureLootEntity.IsUserAllowed(_steamID) && secureLootEntity.HasPassword() && secureLootEntity.IsLocked() || secureLootEntity.IsOwner(_steamID);
        bool isMyLandProtectedBlock = _world.IsMyLandProtectedBlock(_blockPos, _world.GetGameManager().GetPersistentLocalPlayer(), false);

        _activationCommands[4].enabled = isMyLandProtectedBlock && secureLootEntity.IsOwner(_steamID) && _takeDelay > 0.0;

        _activationCommands[5].enabled = secureLootEntity.IsOwner(_steamID);

        return(_activationCommands);
    }
Esempio n. 2
0
    /**
     * This happens when the block is placed in the world.
     */

    public override void PlaceBlock(WorldBase _world, BlockPlacement.Result _result, EntityAlive _ea)
    {
        Block block = Block.list[_result.blockValue.type];

        if (block.shape.IsTerrain())
        {
            _world.SetBlockRPC(_result.clrIdx, _result.blockPos, _result.blockValue, this.Density);
        }
        else if (!block.IsTerrainDecoration)
        {
            _world.SetBlockRPC(_result.clrIdx, _result.blockPos, _result.blockValue, MarchingCubes.DensityAir);
        }
        else
        {
            _world.SetBlockRPC(_result.clrIdx, _result.blockPos, _result.blockValue);
        }

        TileEntityBlockTransformer tileEntityBlockTransformer = _world.GetTileEntity(_result.clrIdx, _result.blockPos) as TileEntityBlockTransformer;

        if (tileEntityBlockTransformer == null)
        {
            Log.Warning("Failed to create tile entity");
            return;
        }
        if (_ea != null && _ea.entityType == EntityType.Player)
        {
            tileEntityBlockTransformer.bPlayerStorage   = true;
            tileEntityBlockTransformer.worldTimeTouched = _world.GetWorldTime();
            tileEntityBlockTransformer.SetEmpty();
        }
        Log.Out("Created successfullly.");
    }
Esempio n. 3
0
    // We want to set down the file if it doesn't already exist, but we don't want to do the Loot container check
    // We want it to only have a 1,1 slot, but don't want to waste a loot container id for it.
    public override void OnBlockAdded(WorldBase world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
    {
        #region OnBlockAdded
        if (_blockValue.ischild)
        {
            return;
        }
        this.shape.OnBlockAdded(world, _chunk, _blockPos, _blockValue);
        if (this.isMultiBlock)
        {
            this.multiBlockPos.AddChilds(world, _chunk.ClrIdx, _blockPos, _blockValue);
        }

        if (!(world.GetTileEntity(_chunk.ClrIdx, _blockPos) is TileEntitySecureLootContainer))
        {
            TileEntityLootContainer tileEntityLootContainer = new TileEntityLootContainer(_chunk);
            tileEntityLootContainer.localChunkPos = World.toBlock(_blockPos);
            tileEntityLootContainer.lootListIndex = 25;
            tileEntityLootContainer.SetContainerSize(vLootContainerSize, true);
            _chunk.AddTileEntity(tileEntityLootContainer);
        }

        _chunk.AddEntityBlockStub(new BlockEntityData(_blockValue, _blockPos)
        {
            bNeedsTemperature = true
        });

        #endregion
    }
Esempio n. 4
0
    public override bool OnBlockActivated(int _indexInBlockActivationCommands, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player)
    {
        EntityPlayerLocal entityPlayerLocal = _player as EntityPlayerLocal;
        LocalPlayerUI     uiForPlayer       = LocalPlayerUI.GetUIForPlayer(entityPlayerLocal);
        var tileEntity = _world.GetTileEntity(_cIdx, _blockPos) as TileEntitySecureLootContainer;

        if (_indexInBlockActivationCommands == 4)
        {
            if (!tileEntity.IsEmpty())
            {
                GameManager.ShowTooltipWithAlert(entityPlayerLocal, Localization.Get("ttEmptyLootContainerBeforePickup", string.Empty), "ui_denied");
                return(false);
            }
            TakeItemWithTimer(_cIdx, _blockPos, _blockValue, _player);
            return(true);
        }

        if (_indexInBlockActivationCommands == 5)
        {
            if (uiForPlayer != null)
            {
                ((XUiWindowGroup)uiForPlayer.windowManager.GetWindow("storage_box")).Controller.GetChildByType <XUiC_StorageBoxLabelWindow>().SetTileEntity(tileEntity);
                uiForPlayer.windowManager.Open("storage_box", true, false, true);
            }
            return(true);
        }

        return(base.OnBlockActivated(_indexInBlockActivationCommands, _world, _cIdx, _blockPos, _blockValue, _player));
    }
Esempio n. 5
0
    public override bool OnBlockActivated(int _indexInBlockActivationCommands, WorldBase _world, int _cIdx,
                                          Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player)
    {
        if (_blockValue.ischild)
        {
            Vector3i   parentPos = Block.list[_blockValue.type].multiBlockPos.GetParentPos(_blockPos, _blockValue);
            BlockValue block     = _world.GetBlock(parentPos);
            return(this.OnBlockActivated(_indexInBlockActivationCommands, _world, _cIdx, parentPos, block, _player));
        }
        TileEntitySign tileEntitySign = _world.GetTileEntity(_cIdx, _blockPos) as TileEntitySign;

        if (tileEntitySign == null)
        {
            return(false);
        }
        switch (_indexInBlockActivationCommands)
        {
        case 0:
            if (GameManager.Instance.IsEditMode() || !tileEntitySign.IsLocked() || tileEntitySign.IsUserAllowed(GamePrefs.GetString(EnumGamePrefs.PlayerId)))
            {
                return(this.OnBlockActivated(_world, _cIdx, _blockPos, _blockValue, _player));
            }
            Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, "Misc/locked");
            return(false);

        case 1:
            tileEntitySign.SetLocked(true);
            Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, "Misc/locking");
            GameManager.ShowTooltip(_player as EntityPlayerLocal, "containerLocked");
            return(true);

        case 2:
            tileEntitySign.SetLocked(false);
            Manager.BroadcastPlayByLocalPlayer(_blockPos.ToVector3() + Vector3.one * 0.5f, "Misc/unlocking");
            GameManager.ShowTooltip(_player as EntityPlayerLocal, "containerUnlocked");
            return(true);

        case 3:
            XUiC_KeypadWindow.Open(LocalPlayerUI.GetUIForPlayer(_player as EntityPlayerLocal), tileEntitySign);
            return(true);

        case 4:
            LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(_player as EntityPlayerLocal);
            ItemStack     itemStack   = new ItemStack(_blockValue.ToItemValue(), 1);
            if (!uiforPlayer.xui.PlayerInventory.AddItem(itemStack))
            {
                uiforPlayer.xui.PlayerInventory.DropItem(itemStack);
            }
            _world.SetBlockRPC(_cIdx, _blockPos, BlockValue.Air);

            return(true);

        default:
            return(false);
        }
    }
Esempio n. 6
0
    public override Block.DestroyedResult OnBlockDestroyedBy(WorldBase _world, int _clrIdx, Vector3i _blockPos, BlockValue _blockValue, int _entityId, bool _bUseHarvestTool)
    {
        var controller = GetStorageWindowController();

        if (controller != null)
        {
            var tileEntity = _world.GetTileEntity(_clrIdx, _blockPos);
            controller.OnBlockOnBlockDestroyedBy(tileEntity.ToWorldPos().ToString());
        }

        return(base.OnBlockDestroyedBy(_world, _clrIdx, _blockPos, _blockValue, _entityId, _bUseHarvestTool));
    }
    public override BlockActivationCommand[] GetBlockActivationCommands(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
    {
        bool       flag = _world.IsMyLandProtectedBlock(_blockPos, _world.GetGameManager().GetPersistentLocalPlayer(), false);
        TileEntity tileEntityWorkstation = (TileEntity)_world.GetTileEntity(_clrIdx, _blockPos);
        bool       flag2 = false;

        if (tileEntityWorkstation != null)
        {
            flag2 = (tileEntityWorkstation as TileEntityPoweredWorkstationSDX).IsPlayerPlaced;
        }
        this.cmds[1].enabled = (flag && flag2 && this.TakeDelay > 0f);
        return(this.cmds);
    }
Esempio n. 8
0
    public override void OnBlockEntityTransformAfterActivated(WorldBase _world, Vector3i _blockPos, int _cIdx, BlockValue _blockValue, BlockEntityData _ebcd)
    {
        var controller = GetStorageWindowController();

        if (controller != null)
        {
            var tileEntity = _world.GetTileEntity(_cIdx, _blockPos);
            controller.SetTileEntity(tileEntity as TileEntitySecureLootContainer);
            controller.OnBlockEntityTransformAfterActivated(tileEntity.ToWorldPos().ToString());
        }

        base.OnBlockEntityTransformAfterActivated(_world, _blockPos, _cIdx, _blockValue, _ebcd);
    }
Esempio n. 9
0
        public static bool Prefix(ref Block __instance, int _indexInBlockActivationCommands, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player)
        {
            // Check if this feature is enabled.
            if (!Configuration.CheckFeatureStatus(AdvFeatureClass, Feature))
            {
                return(true);
            }

            if (_blockValue.ischild)
            {
                return(true);
            }
            TileEntitySecureDoor tileEntitySecureDoor = (TileEntitySecureDoor)_world.GetTileEntity(_cIdx, _blockPos);

            if (tileEntitySecureDoor == null)
            {
                return(true);
            }


            if (!tileEntitySecureDoor.IsLocked() || tileEntitySecureDoor.IsUserAllowed(GamePrefs.GetString(EnumGamePrefs.PlayerId)))
            {
                return(true);
            }


            if (tileEntitySecureDoor.IsLocked())
            {
                // 1 == try to open locked door.
                if (_indexInBlockActivationCommands == 1)
                {
                    // Check if the player has lock picks.
                    LocalPlayerUI        playerUI        = (_player as EntityPlayerLocal).PlayerUI;
                    XUiM_PlayerInventory playerInventory = playerUI.xui.PlayerInventory;
                    ItemValue            item            = ItemClass.GetItem("resourceLockPick", false);
                    if (playerInventory.GetItemCount(item) == 0)
                    {
                        playerUI.xui.CollectedItemList.AddItemStack(new ItemStack(item, 0), true);
                        GameManager.ShowTooltip(_player as EntityPlayerLocal, Localization.Get("ttLockpickMissing"));
                        return(false);
                    }

                    tileEntitySecureDoor.SetLocked(true);
                    XUiC_PickLocking.Open(playerUI, tileEntitySecureDoor, _blockValue, _blockPos);
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 10
0
    /**
     * This is called when the player presses the activation key (usually E) on the block.
     */

    public override bool OnBlockActivated(WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player)
    {
        TileEntityBlockTransformer tileEntityBlockTransformer = _world.GetTileEntity(_cIdx, _blockPos) as TileEntityBlockTransformer;

        if (tileEntityBlockTransformer == null)
        {
            return(false);
        }
        _player.AimingGun = false;
        Vector3i blockPos = tileEntityBlockTransformer.ToWorldPos();

        tileEntityBlockTransformer.bWasTouched = tileEntityBlockTransformer.bTouched;
        _world.GetGameManager().TELockServer(_cIdx, blockPos, tileEntityBlockTransformer.entityId, _player.entityId);
        return(true);
    }
Esempio n. 11
0
 public override void OnBlockAdded(WorldBase world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
 {
     base.OnBlockAdded(world, _chunk, _blockPos, _blockValue);
     if (_blockValue.ischild)
     {
         return;
     }
     if (!(world.GetTileEntity(_chunk.ClrIdx, _blockPos) is ImprovedTileEntitySecureLootContainer))
     {
         ImprovedTileEntitySecureLootContainer tileEntitySecureLootContainer = new ImprovedTileEntitySecureLootContainer(_chunk);
         tileEntitySecureLootContainer.localChunkPos = World.toBlock(_blockPos);
         tileEntitySecureLootContainer.lootListIndex = (int)((ushort)this.lootList);
         tileEntitySecureLootContainer.SetContainerSize(LootContainer.lootList[this.lootList].size, true);
         _chunk.AddTileEntity(tileEntitySecureLootContainer);
     }
 }
Esempio n. 12
0
    /**
     * Called when a block is destroyed by an entity. It cam be useful for separating things out if needed depending on what
     * entity destroyed it.
     */

    public override bool OnBlockDestroyedBy(WorldBase _world, int _clrIdx, Vector3i _blockPos, BlockValue _blockValue, int _entityId, bool _bUseHarvestTool)
    {
        TileEntityBlockTransformer tileEntityBlockTransformer = _world.GetTileEntity(_clrIdx, _blockPos) as TileEntityBlockTransformer;

        if (tileEntityBlockTransformer != null)
        {
            tileEntityBlockTransformer.OnDestroy();
        }
        LocalPlayerUI uiforPlayer = LocalPlayerUI.GetUIForPlayer(GameManager.Instance.World.GetEntity(_entityId) as EntityPlayerLocal);

        if (null != uiforPlayer && uiforPlayer.windowManager.IsWindowOpen("looting") && ((XUiC_LootWindow)uiforPlayer.xui.GetWindow("windowLooting").Controller).GetLootBlockPos() == _blockPos)
        {
            uiforPlayer.windowManager.Close("looting");
        }
        if (tileEntityBlockTransformer != null)
        {
            _world.GetGameManager().DropContentOfLootContainerServer(_blockValue, _blockPos, tileEntityBlockTransformer.entityId);
        }
        return(true);
    }
Esempio n. 13
0
    public override BlockActivationCommand[] GetBlockActivationCommands(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
    {
        TileEntitySign tileEntitySign = (TileEntitySign)_world.GetTileEntity(_clrIdx, _blockPos);

        if (tileEntitySign == null)
        {
            return(new BlockActivationCommand[0]);
        }
        string @string = GamePrefs.GetString(EnumGamePrefs.PlayerId);
        PersistentPlayerData playerData = _world.GetGameManager().GetPersistentPlayerList().GetPlayerData(tileEntitySign.GetOwner());

        bool flag = !tileEntitySign.IsOwner(@string) && (playerData != null && playerData.ACL != null) && playerData.ACL.Contains(@string);

        this.cmds[0].enabled = true;
        this.cmds[1].enabled = (!tileEntitySign.IsLocked() && (tileEntitySign.IsOwner(@string) || flag));
        this.cmds[2].enabled = (tileEntitySign.IsLocked() && tileEntitySign.IsOwner(@string));
        this.cmds[3].enabled = ((!tileEntitySign.IsUserAllowed(@string) && tileEntitySign.HasPassword() && tileEntitySign.IsLocked()) || tileEntitySign.IsOwner(@string));
        this.cmds[4].enabled = ((!tileEntitySign.IsUserAllowed(@string) && tileEntitySign.HasPassword() && tileEntitySign.IsLocked()) || tileEntitySign.IsOwner(@string));

        return(this.cmds);
    }
Esempio n. 14
0
 //Used for severs, block will be NOT be powered directly. Also used in SP if AllowRemotePower is true in the xml.
 public static bool HasActivePower(WorldBase _world, int _cIdx, Vector3i _blockPos)
 {
     Vector3i[] locations = PowerInputLocations(_blockPos);
     foreach (Vector3i vector in locations)
     {
         BlockValue inputBlockValue = _world.GetBlock(vector);
         Type       inputBlockType  = Block.list[inputBlockValue.type].GetType();
         if (inputBlockType == typeof(BlockPowered))
         {
             TileEntityPowered tileEntityPowered = (TileEntityPowered)_world.GetTileEntity(_cIdx, vector);
             if (tileEntityPowered != null)
             {
                 if (tileEntityPowered.IsPowered)
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Esempio n. 15
0
    /**
     * This is the activation text that displays when the player looks at this block.
     */

    public override string GetActivationText(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
    {
        TileEntityBlockTransformer tileEntityBlockTransformer = _world.GetTileEntity(_clrIdx, _blockPos) as TileEntityBlockTransformer;

        if (tileEntityBlockTransformer == null)
        {
            return(string.Empty);
        }
        string             arg           = Localization.Get(Block.list[_blockValue.type].GetBlockName(), "");
        PlayerActionsLocal playerInput   = ((EntityPlayerLocal)_entityFocusing).playerInput;
        string             keybindString = UIUtils.GetKeybindString(playerInput.Activate, playerInput.PermanentActions.Activate);

        if (!tileEntityBlockTransformer.bTouched)
        {
            return(string.Format(Localization.Get("lootTooltipNew", ""), keybindString, arg));
        }
        if (tileEntityBlockTransformer.IsEmpty())
        {
            return(string.Format(Localization.Get("lootTooltipEmpty", ""), keybindString, arg));
        }
        return(string.Format(Localization.Get("lootTooltipTouched", ""), keybindString, arg));
    }
    public override void OnBlockEntityTransformBeforeActivated(WorldBase _world, Vector3i _blockPos, int _cIdx, BlockValue _blockValue, BlockEntityData _ebcd)
    {
        this.shape.OnBlockEntityTransformBeforeActivated(_world, _blockPos, _cIdx, _blockValue, _ebcd);
        DebugMsg("OnBlockEntityTransformBeforeActivated");
        try
        {
            if (_ebcd != null && _ebcd.bHasTransform)
            {
                GameObject gameObject = _ebcd.transform.gameObject;
                PerpetualMotionGeneratorControl PMGControlScript = gameObject.GetComponent <PerpetualMotionGeneratorControl>();
                if (PMGControlScript == null)
                {
                    PMGControlScript = gameObject.AddComponent <PerpetualMotionGeneratorControl>();
                }
                PMGControlScript.enabled     = true;
                PMGControlScript.cIdx        = _cIdx;
                PMGControlScript.blockPos    = _blockPos;
                PMGControlScript.soundRepeat = soundRepeat;
            }
            else
            {
                DebugMsg("ERROR: _ebcd null (OnBlockEntityTransformBeforeActivated)");
            }
        }
        catch (Exception ex)
        {
            DebugMsg("Error Message: " + ex.ToString());
        }

        // Offset wire so that it's at the base of the Healing Pod
        TileEntityPowerSource tileEntityPowerSource = (TileEntityPowerSource)_world.GetTileEntity(_cIdx, _blockPos);

        if (tileEntityPowerSource != null)
        {
            tileEntityPowerSource.WireOffset = new Vector3(0.25f, 0.4f, 0);
        }
    }
Esempio n. 17
0
    /**
     * This is called when block is removed. We want to destroy existing tile entity too.
     */

    public override void OnBlockRemoved(WorldBase _world, Chunk _chunk, Vector3i _blockPos, BlockValue _blockValue)
    {
        if (!_blockValue.ischild)
        {
            this.shape.OnBlockRemoved(_world, _chunk, _blockPos, _blockValue);
            if (this.isMultiBlock)
            {
                this.multiBlockPos.RemoveChilds(_world, _chunk.ClrIdx, _blockPos, _blockValue);
                return;
            }
        }
        else if (this.isMultiBlock)
        {
            this.multiBlockPos.RemoveParentBlock(_world, _chunk.ClrIdx, _blockPos, _blockValue);
        }

        TileEntityBlockTransformer tileEntityBlockTransformer = _world.GetTileEntity(_chunk.ClrIdx, _blockPos) as TileEntityBlockTransformer;

        if (tileEntityBlockTransformer != null)
        {
            tileEntityBlockTransformer.OnDestroy();
        }
        this.removeTileEntity(_world, _chunk, _blockPos, _blockValue);
    }
Esempio n. 18
0
    public override void OnBlockEntityTransformBeforeActivated(WorldBase _world, Vector3i _blockPos, int _cIdx, BlockValue _blockValue, BlockEntityData _ebcd)
    {
        this.shape.OnBlockEntityTransformBeforeActivated(_world, _blockPos, _cIdx, _blockValue, _ebcd);
        DebugMsg("OnBlockEntityTransformBeforeActivated");
        try
        {
            if (_ebcd != null && _ebcd.bHasTransform)
            {
                GameObject        gameObject = _ebcd.transform.gameObject;
                HealingPodControl healingPodControlScript = gameObject.GetComponent <HealingPodControl>();
                if (healingPodControlScript == null)
                {
                    healingPodControlScript = gameObject.AddComponent <HealingPodControl>();
                }
                healingPodControlScript.enabled  = true;
                healingPodControlScript.cIdx     = _cIdx;
                healingPodControlScript.blockPos = _blockPos;
            }
            else
            {
                DebugMsg("ERROR: _ebcd null (OnBlockEntityTransformBeforeActivated)");
            }
        }
        catch (Exception ex)
        {
            DebugMsg("Error Message: " + ex.ToString());
        }

        // Offset wire so that it's at the base of the Healing Pod
        TileEntityPowered tileEntityPowered = (TileEntityPowered)_world.GetTileEntity(_cIdx, _blockPos);

        if (tileEntityPowered != null)
        {
            tileEntityPowered.WireOffset = new Vector3(0, -0.5f, 0);
        }
    }
Esempio n. 19
0
    /**
     * This is the activation text that displays when the player looks at this block.
     * It will display whether the block is working, and if not, what conditions need to be fulfilled to make it work.
     */

    public override string GetActivationText(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
    {
        TileEntityBlockTransformer tileEntityBlockTransformer = _world.GetTileEntity(_clrIdx, _blockPos) as TileEntityBlockTransformer;

        if (tileEntityBlockTransformer == null)
        {
            return(string.Empty);
        }
        string             lBlockName  = Localization.Get(Block.list[_blockValue.type].GetBlockName(), "");
        PlayerActionsLocal playerInput = ((EntityPlayerLocal)_entityFocusing).playerInput;
        string             playerKey   = playerInput.Activate.GetBindingXuiMarkupString(XUiUtils.EmptyBindingStyle.EmptyString, XUiUtils.DisplayStyle.Plain) + playerInput.PermanentActions.Activate.GetBindingXuiMarkupString(XUiUtils.EmptyBindingStyle.EmptyString, XUiUtils.DisplayStyle.Plain);
        string             tooltip     = "";

        // If updates cannot happen we need to display this to the user and say why they can't happen yet.
        if (!tileEntityBlockTransformer.UpdateCanHappen((World)_world))
        {
            // If no power, display this when looking at the block.
            if (!tileEntityBlockTransformer.IsPowered())
            {
                tooltip = Localization.Get("transformerTooltipNoPower", "");
                List <string> lPowerSources = new List <string>();
                if (this.transformationPropertyParser.powerSources.Count > 0)
                {
                    foreach (string powerSource in this.transformationPropertyParser.powerSources)
                    {
                        lPowerSources.Add(Localization.Get(powerSource));
                    }
                }
                string sources = StringHelpers.WriteListToString(lPowerSources);
                return(string.Format(tooltip, playerKey, lBlockName, sources));
            }

            // If no heat, display this when looking at the block.
            else if (!tileEntityBlockTransformer.IsHeated())
            {
                tooltip = Localization.Get("transformerTooltipNoHeat", "");
                List <string> lHeatSources = new List <string>();
                if (this.transformationPropertyParser.heatSources.Count > 0)
                {
                    foreach (string heatSource in this.transformationPropertyParser.heatSources)
                    {
                        lHeatSources.Add(Localization.Get(heatSource));
                    }
                }
                string sources = StringHelpers.WriteListToString(lHeatSources);
                return(string.Format(tooltip, playerKey, lBlockName, sources));
            }

            // Checks we have nearby blocks
            else if (!tileEntityBlockTransformer.HasNearbyBlocks())
            {
                tooltip = Localization.Get("transformerTooltipNoBlocksNearby", "");
                List <string> lNearbyBlocks = new List <string>();
                if (this.transformationPropertyParser.nearbyBlockNames.Count > 0)
                {
                    foreach (string blockName in this.transformationPropertyParser.nearbyBlockNames)
                    {
                        lNearbyBlocks.Add(Localization.Get(blockName));
                    }
                }

                if (this.transformationPropertyParser.nearbyBlockTags.Count > 0)
                {
                    foreach (string blockTag in this.transformationPropertyParser.nearbyBlockTags)
                    {
                        lNearbyBlocks.Add(blockTag);
                    }
                }

                string sources = StringHelpers.WriteListToString(lNearbyBlocks);
                string needed  = this.transformationPropertyParser.nearbyBlockCount.ToString();

                return(string.Format(tooltip, playerKey, lBlockName, needed, sources));
            }

            // If all else fails,  the block must be empty so needs items.
            else
            {
                tooltip = Localization.Get("transformerTooltipReady", "");
                return(string.Format(tooltip, playerKey, lBlockName));
            }
        }

        // Transforming here...
        tooltip = Localization.Get("transformerTooltipWorking", "");
        return(string.Format(tooltip, playerKey, lBlockName));
    }
    public override bool OnBlockActivated(WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player)
    {
        TileEntityPoweredWorkstationSDX tileEntityWorkstation = (TileEntityPoweredWorkstationSDX)_world.GetTileEntity(_cIdx, _blockPos);

        if (tileEntityWorkstation == null)
        {
            return(false);
        }
        _player.AimingGun = false;
        Vector3i blockPos = tileEntityWorkstation.ToWorldPos();

        _world.GetGameManager().TELockServer(_cIdx, blockPos, tileEntityWorkstation.entityId, _player.entityId);
        return(true);
    }
    public override void PlaceBlock(WorldBase _world, BlockPlacement.Result _result, EntityAlive _ea)
    {
        base.PlaceBlock(_world, _result, _ea);

        TileEntityPoweredWorkstationSDX tileEntityWorkstation = (TileEntityPoweredWorkstationSDX)_world.GetTileEntity(_result.clrIdx, _result.blockPos);

        if (tileEntityWorkstation != null)
        {
            tileEntityWorkstation.IsPlayerPlaced = true;
        }
    }
Esempio n. 22
0
    // Play the music when its activated. We stop the sound broadcasting, in case they want to restart it again; otherwise we can get two sounds playing.
    public override bool OnBlockActivated(int _indexInBlockActivationCommands, WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player)
    {
        #region OnBlockActivated

        // If there's no transform, no sense on keeping going for this class.
        BlockEntityData _ebcd = _world.GetChunkFromWorldPos(_blockPos).GetBlockEntity(_blockPos);
        if (_ebcd == null || _ebcd.transform == null)
        {
            return(false);
        }

        MusicBoxScript myMusicBoxScript = _ebcd.transform.GetComponent <MusicBoxScript>();
        if (myMusicBoxScript == null)
        {
            myMusicBoxScript = _ebcd.transform.gameObject.AddComponent <MusicBoxScript>();
        }

        bool bRuntimeSwitch = myMusicBoxScript.enabled;


        // Turn off the music box before we do anything with it.
        myMusicBoxScript.enabled = false;

        if (_indexInBlockActivationCommands != 0)
        {
            if (_indexInBlockActivationCommands == 1)
            {
                base.OnBlockActivated(_world, _cIdx, _blockPos, _blockValue, _player);
            }

            if (_indexInBlockActivationCommands == 2)
            {
                TakeItemWithTimer(_cIdx, _blockPos, _blockValue, _player);
            }
        }
        else
        {
            bRuntimeSwitch = !bRuntimeSwitch;

            // Check if we have an animator and set it
            myMusicBoxScript.anim = _ebcd.transform.GetComponent <Animator>();

            // Check if we have a video player as well.
            myMusicBoxScript.videoPlayer = _ebcd.transform.GetComponent <VideoPlayer>();

            myMusicBoxScript.myBlockPos = _blockPos;
            // If the switch is on, then we want to look in the loot container to find a reference to any potential items,
            // which will over-ride the default audio clip / video clip.
            if (bRuntimeSwitch)
            {
                // We'll try to support getting sounds from multiple sound data nodes, based on all the items in the loot container.
                List <String> mySounds = new List <String>();
                List <String> myVideos = new List <String>();

                TileEntityLootContainer tileLootContainer = (TileEntityLootContainer)_world.GetTileEntity(_cIdx, _blockPos);

                if (tileLootContainer.items != null)
                {
                    ItemStack[] array = tileLootContainer.items;
                    for (int i = 0; i < array.Length; i++)
                    {
                        if (array[i].IsEmpty())
                        {
                            continue;
                        }

                        // Check for a SoundDataNode for a potential sound clip.
                        if (array[i].itemValue.ItemClass.Properties.Values.ContainsKey("SoundDataNode"))
                        {
                            String strSound = array[i].itemValue.ItemClass.Properties.Values["SoundDataNode"];
                            if (!mySounds.Contains(strSound))
                            {
                                mySounds.Add(strSound);
                            }
                        }
                        // Check for a video Source for a video clip. If we find it, load the asset and add it to the music box script.
                        if (array[i].itemValue.ItemClass.Properties.Values.ContainsKey("VideoSource"))
                        {
                            // Check if the video source is an asset bundle, and if so, load it directly into the video clip on
                            String strVideo = array[i].itemValue.ItemClass.Properties.Values["VideoSource"];
                            if (strVideo.IndexOf('#') == 0 && strVideo.IndexOf('?') > 0)
                            {
                                if (!myVideos.Contains(strVideo))
                                {
                                    myVideos.Add(strVideo);
                                }
                            }
                        }
                    }
                }

                // Initialize the data with our defaults.
                myMusicBoxScript.strAudioSource = this.strAudioSource;
                myMusicBoxScript.strSoundSource = this.strSoundSource;
                myMusicBoxScript.strVideoSource = this.strVideoSource;
                myMusicBoxScript.myEntity       = _player;

                // List of Videos and Sound clips.
                myMusicBoxScript.VideoGroups = myVideos;
                myMusicBoxScript.SoundGroups = mySounds;

                myMusicBoxScript.myVideoClip = null;
                myMusicBoxScript.enabled     = bRuntimeSwitch;
            }
        }


        return(false);

        #endregion
    }