Esempio n. 1
0
        private static void RepairBlock(WorldBase world, Vector3i pos)
        {
            var blockValue = world.GetBlock(pos);

            if (blockValue.Equals(BlockValue.Air))
            {
                SendOutput($"Target block is air @ {pos}");

                return;
            }

            var d = blockValue.damage;

            if (d > 0)
            {
                SendOutput($"Target block not damaged @ {pos}");

                return;
            }

            blockValue.damage = 0;
            world.SetBlockRPC(pos, blockValue);

            SendOutput($"Repairing block for '{d}' damage @ {pos}");
        }
Esempio n. 2
0
    public override bool CanPlaceBlockAt(WorldBase _world, int _clrIdx, Vector3i _blockPos, BlockValue _blockValue,
                                         bool _bOmitCollideCheck)
    {
        int type = _world.GetBlock(_clrIdx, _blockPos).type;

        DisplayChatAreaText(string.Format("Block name: {0}, Block Liquid_ {1}", Block.list[type].GetBlockName(),
                                          Block.list[type].blockMaterial.IsLiquid));
        return(Block.list[type].blockMaterial.IsLiquid);
    }
Esempio n. 3
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. 4
0
        private static void SetPaintFace(WorldBase world, Vector3i pos)
        {
            byte texture = 0;

            if (Options.ContainsKey("t"))
            {
                if (!byte.TryParse(Options["t"], out texture))
                {
                    SendOutput("Unable to parse texture value");

                    return;
                }
                if (BlockTextureData.list[texture] == null)
                {
                    SendOutput($"Unknown texture index {texture}");

                    return;
                }
            }
            uint setFace = 0;

            if (Options.ContainsKey("face"))
            {
                if (!uint.TryParse(Options["face"], out setFace))
                {
                    SendOutput("Unable to parse face value");

                    return;
                }
            }
            if (setFace > 5)
            {
                SendOutput("Face must be between 0 and 5");

                return;
            }

            var blockValue = world.GetBlock(pos);

            if (blockValue.Equals(BlockValue.Air))
            {
                SendOutput($"Target block is air @ {pos}");

                return;
            }
            if (blockValue.Block.shape.IsTerrain())
            {
                SendOutput($"Target block is terrain @ {pos}");

                return;
            }

            GameManager.Instance.SetBlockTextureServer(pos, (BlockFace)setFace, texture, -1);
            SendOutput($"Painting block on face '{((BlockFace)setFace).ToString()}' with texture '{BlockTextureData.GetDataByTextureID(texture)?.Name}' @ {pos}");
        }
Esempio n. 5
0
        private static void SetMeta(int metaIdx, WorldBase world, Vector3i pos)
        {
            byte meta = 0;

            if (Options.ContainsKey("meta"))
            {
                if (!byte.TryParse(Options["meta"], out meta))
                {
                    SendOutput($"Unable to parse meta '{Options["meta"]}'");

                    return;
                }
            }

            var blockValue = world.GetBlock(pos);

            if (blockValue.Equals(BlockValue.Air))
            {
                SendOutput($"Target block is air @ {pos}");

                return;
            }
            if (blockValue.ischild)
            {
                SendOutput($"Target child block can't be set @ {pos} - Parent@ {blockValue.parentx},{blockValue.parenty},{blockValue.parentz}");

                return;
            }

            var m = blockValue.meta;

            switch (metaIdx)
            {
            case 1:
                blockValue.meta = meta;
                break;

            case 2:
                blockValue.meta2 = meta;
                break;

            case 3:
                blockValue.meta3 = meta;
                break;

            default:
                return;
            }
            world.SetBlockRPC(pos, blockValue);

            SendOutput($"Changing meta{metaIdx} on block from '{m}' to '{meta}' @ {pos}");
        }
Esempio n. 6
0
        public static bool Prefix(Block __instance, WorldBase _world, int _clrIdx, Vector3i _blockPos, BlockValue _blockValue)
        {
            if (!Configuration.CheckFeatureStatus(AdvFeatureClass, Feature))
            {
                return(true);
            }

            if (!__instance.isMultiBlock)
            {
                int type = _world.GetBlock(_clrIdx, _blockPos).type;
                return((type != 0 || Block.list[type].GetBlockName() == "caveBlock02") && !Block.list[type].blockMaterial.IsGroundCover && !Block.list[type].blockMaterial.IsLiquid);
            }
            byte rotation = _blockValue.rotation;

            for (int i = __instance.multiBlockPos.Length - 1; i >= 0; i--)
            {
                int type2 = _world.GetBlock(_clrIdx, _blockPos + __instance.multiBlockPos.Get(i, _blockValue.type, (int)rotation)).type;
                if (type2 != 0 && !Block.list[type2].blockMaterial.IsGroundCover && !Block.list[type2].blockMaterial.IsLiquid)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 7
0
    protected virtual void addParticles(WorldBase _world, int _clrIdx, int _x, int _y, int _z, BlockValue _blockValue)
    {
        if (this.particleName == null || this.particleName == string.Empty)
        {
            return;
        }
        float num = 0f;

        if (_y > 0 && Block.list[_blockValue.type].IsTerrainDecoration && Block.list[_world.GetBlock(_x, _y - 1, _z).type].shape.IsTerrain())
        {
            sbyte density  = _world.GetDensity(_clrIdx, _x, _y, _z);
            sbyte density2 = _world.GetDensity(_clrIdx, _x, _y - 1, _z);
            num = MarchingCubes.GetDecorationOffsetY(density, density2);
        }
        _world.GetGameManager().SpawnBlockParticleEffect(new Vector3i(_x, _y, _z), new ParticleEffect(this.particleName, new Vector3((float)_x, (float)_y + num, (float)_z) + this.getParticleOffset(_blockValue), this.shape.GetRotation(_blockValue), 1f, Color.white));
    }
Esempio n. 8
0
        private static void SetRotation(WorldBase world, Vector3i pos)
        {
            byte rotation = 0;

            if (Options.ContainsKey("rot"))
            {
                if (!byte.TryParse(Options["rot"], out rotation))
                {
                    SendOutput($"Unable to parse rotation '{Options["rot"]}'");

                    return;
                }
            }

            var blockValue = world.GetBlock(pos);

            if (blockValue.Equals(BlockValue.Air))
            {
                SendOutput($"Target block is air @ {pos}");

                return;
            }
            if (blockValue.ischild)
            {
                SendOutput($"Target child block can't be rotated @ {pos} - Parent@ {blockValue.parentx},{blockValue.parenty},{blockValue.parentz}");

                return;
            }
            if (!blockValue.Block.shape.IsRotatable)
            {
                SendOutput($"Target block can't be rotated @ {pos}");

                return;
            }

            var r = blockValue.rotation;

            blockValue.rotation = rotation;
            world.SetBlockRPC(pos, blockValue);

            SendOutput($"Changing rotation on block from '{r}' to '{rotation}' @ {pos}");
        }
Esempio n. 9
0
        private static void RemovePaint(WorldBase world, Vector3i pos)
        {
            var blockValue = world.GetBlock(pos);

            if (blockValue.Equals(BlockValue.Air))
            {
                SendOutput($"Target block is air @ {pos}");

                return;
            }
            if (blockValue.Block.shape.IsTerrain())
            {
                SendOutput($"Target block is terrain @ {pos}");

                return;
            }

            GameManager.Instance.SetBlockTextureServer(pos, BlockFace.None, 0, -1);
            SendOutput($"Paint removed from block @ {pos}");
        }
Esempio n. 10
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. 11
0
        private static void SetDensity(WorldBase world, Vector3i pos)
        {
            sbyte density = 1;

            if (Options.ContainsKey("d"))
            {
                if (sbyte.TryParse(Options["d"], out density))
                {
                    SendOutput($"Using density {density}");
                }
            }

            var blockValue = world.GetBlock(pos);

            if (blockValue.Equals(BlockValue.Air))
            {
                SendOutput($"Target block is air @ {pos}");

                return;
            }
            if (blockValue.ischild)
            {
                SendOutput($"Target block is a child block @ {pos} - Parent@ {blockValue.parentx},{blockValue.parenty},{blockValue.parentz}");

                return;
            }

            var d = world.GetDensity(0, pos);

            if (d == density)
            {
                SendOutput($"No change in density @ {pos}");

                return;
            }

            world.SetBlockRPC(pos, blockValue, density);
            SendOutput($"Changing density on block from '{d}' to '{density}' @ {pos}");
        }
Esempio n. 12
0
        private static void SetPaint(WorldBase world, Vector3i pos)
        {
            byte texture = 0;

            if (Options.ContainsKey("t"))
            {
                if (!byte.TryParse(Options["t"], out texture))
                {
                    SendOutput("Unable to parse texture value");

                    return;
                }
                if (BlockTextureData.list[texture] == null)
                {
                    SendOutput($"Unknown texture index {texture}");

                    return;
                }
            }

            var blockValue = world.GetBlock(pos);

            if (blockValue.Equals(BlockValue.Air))
            {
                SendOutput($"Target block is air @ {pos}");

                return;
            }
            if (blockValue.Block.shape.IsTerrain())
            {
                SendOutput($"Target block is terrain @ {pos}");

                return;
            }

            GameManager.Instance.SetBlockTextureServer(pos, BlockFace.None, texture, -1);
            SendOutput($"Painting block with texture '{BlockTextureData.GetDataByTextureID(texture)?.Name}' @ {pos}");
        }
Esempio n. 13
0
        public static bool Prefix(Block __instance, WorldBase world, int _clrIdx, Vector3i _myBlockPos, BlockValue _myBlockValue, Vector3i _blockPosThatChanged, BlockValue _newNeighborBlockValue, BlockValue _oldNeighborBlockValue)
        {
            if (!Configuration.CheckFeatureStatus(AdvFeatureClass, Feature))
            {
                return(true);
            }

            // skip this check if its terrain
            if (_myBlockValue.Block.shape.IsTerrain())
            {
                return(true);
            }

            // if the block that's changed is an air block, and it's below the block, crumble it, since we don't want it floating.
            if (_newNeighborBlockValue.Block.GetBlockName() == "caveBlock02" && _blockPosThatChanged == _myBlockPos + Vector3i.down)
            {
                var block = world.GetBlock(_myBlockPos);
                block.Block.DamageBlock(world, _clrIdx, _myBlockPos, _myBlockValue, block.Block.MaxDamage, -1);
                return(false);
            }

            return(true);
        }
Esempio n. 14
0
        private static void UpgradeBlock(WorldBase world, Vector3i pos)
        {
            var blockValue        = world.GetBlock(pos);
            var upgradeBlockValue = blockValue.Block.UpgradeBlock;

            if (upgradeBlockValue.Equals(BlockValue.Air))
            {
                SendOutput($"Target block has no upgrade @ {pos}");

                return;
            }
            if (blockValue.ischild)
            {
                SendOutput($"Can't upgrade a child block @ {pos} - Parent@ {blockValue.parentx},{blockValue.parenty},{blockValue.parentz}");

                return;
            }

            upgradeBlockValue.rotation = blockValue.rotation;
            world.SetBlockRPC(pos, upgradeBlockValue);

            SendOutput($"Upgrading block from '{blockValue.Block.GetBlockName()}' to '{upgradeBlockValue.Block.GetBlockName()}' @ {pos}");
        }
    public void Initialize(WorldBase _world, Vector3i _blockPos)
    {
        Position  = _blockPos;
        Positionf = Position.ToVector3();

        BlockValue  = _world.GetBlock(0, Position);
        SpawnerType = BlockValue.type;

        var props     = Block.list[BlockValue.type].Properties.Values;
        var blockName = Block.list[BlockValue.type].GetBlockName();

        TickRateSeconds = 10;
        if (props.ContainsKey(PropTickRate) && !uint.TryParse(props[PropTickRate], out TickRateSeconds))
        {
            Debug.Log("Unable to parse " + PropTickRate + " as a uint in " + blockName);
        }
        TickRate = TickRateSeconds * 20uL;

        CheckRadius = 10;
        if (props.ContainsKey(PropSpawnRadius) && !uint.TryParse(props[PropSpawnRadius], out CheckRadius))
        {
            Debug.Log("Unable to parse " + PropSpawnRadius + " as an int in " + blockName);
        }

        NumberToSpawn = 6;
        if (props.ContainsKey(PropNumberToSpawn) && !uint.TryParse(props[PropNumberToSpawn], out NumberToSpawn))
        {
            Debug.Log("Unable to parse " + PropNumberToSpawn + " as an int in " + blockName);
        }

        MaxSpawn = 10;
        if (props.ContainsKey(PropMaxSpawned) && !uint.TryParse(props[PropMaxSpawned], out MaxSpawn))
        {
            Debug.Log("Unable to parse " + PropMaxSpawned + " as an int in " + blockName);
        }

        EntityGroup = !props.ContainsKey(PropEntityGroup) ? string.Empty : props[PropEntityGroup];

        SpawnArea = 10;
        if (props.ContainsKey(PropSpawnArea) && !uint.TryParse(props[PropSpawnArea], out SpawnArea))
        {
            Debug.Log("Unable to parse " + PropSpawnArea + " as an int in " + blockName);
        }

        RadiationArea = 0;
        if (props.ContainsKey(PropRadiationArea) && !uint.TryParse(props[PropRadiationArea], out RadiationArea))
        {
            Debug.Log("Unable to parse " + PropRadiationArea + " as an int in " + blockName);
        }

        CheckArea = 10;
        if (props.ContainsKey(PropCheckArea) && !uint.TryParse(props[PropCheckArea], out CheckArea))
        {
            Debug.Log("Unable to parse " + PropCheckArea + " as an int in " + blockName);
        }

        PauseTimeMinutes = 0;
        if (props.ContainsKey(PropPauseTime) && !uint.TryParse(props[PropPauseTime], out PauseTimeMinutes))
        {
            Debug.Log("Unable to parse " + PropPauseTime + " as an int in " + blockName);
        }
        PauseTime = PauseTimeMinutes * 1200;

        NumberToPause = 0;
        if (props.ContainsKey(PropNumberToPause) && !uint.TryParse(props[PropNumberToPause], out NumberToPause))
        {
            Debug.Log("Unable to parse " + PropNumberToPause + " as an int in " + blockName);
        }
        NumberToPauseCounter = NumberToPause;

        RadiationDamage = 0;
        if (props.ContainsKey(PropRadiationDamage) && !uint.TryParse(props[PropRadiationDamage], out RadiationDamage))
        {
            Debug.Log("Unable to parse " + PropRadiationDamage + " as an int in " + blockName);
        }

        //buffs
        Buffs = !props.ContainsKey(PropBuffs) ? string.Empty : props[PropBuffs];
        if (Buffs == string.Empty)
        {
            return;
        }

        var buffList = Buffs.Split(',');
        //if (BuffActions == null) BuffActions = new List<MultiBuffClassAction>();
        //foreach (var buffItem in buffList)
        //{
        //  if (!MultiBuffClass.s_classes.ContainsKey(buffItem.Trim())) continue;

        //  BuffActions.Add(MultiBuffClassAction.NewAction(buffItem.Trim()));
        //}
    }
Esempio n. 16
0
        private static void DamageBlock(WorldBase world, Vector3i pos)
        {
            var damageMin = 0;
            var damageMax = 0;

            if (Options.ContainsKey("d"))
            {
                if (Options["d"].IndexOf(",", StringComparison.InvariantCulture) > -1)
                {
                    var dRange = Options["d"].Split(',');
                    if (dRange.Length != 2)
                    {
                        SendOutput("Unable to parse damage values");

                        return;
                    }

                    if (!int.TryParse(dRange[0], out damageMin))
                    {
                        SendOutput("Unable to parse damage min value");

                        return;
                    }

                    if (!int.TryParse(dRange[1], out damageMax))
                    {
                        SendOutput("Unable to parse damage max value");

                        return;
                    }
                }
                else
                {
                    if (!int.TryParse(Options["d"], out damageMin))
                    {
                        SendOutput("Unable to parse damage value");

                        return;
                    }
                }
            }

            var blockValue = world.GetBlock(pos);

            if (blockValue.Equals(BlockValue.Air))
            {
                return;
            }

            var max    = blockValue.Block.blockMaterial.MaxDamage;
            var impact = damageMax != 0 ? UnityEngine.Random.Range(damageMin, damageMax) : damageMin;
            var damage = impact + blockValue.damage;

            if (Options.ContainsKey("nobreak"))
            {
                blockValue.damage = Math.Min(damage, max - 1);
            }
            else if (Options.ContainsKey("overkill"))
            {
                if (damage >= max)
                {
                    var downgradeBlock = blockValue.Block.DowngradeBlock;
                    while (damage >= max)
                    {
                        downgradeBlock          = blockValue.Block.DowngradeBlock;
                        damage                 -= max;
                        max                     = downgradeBlock.Block.blockMaterial.MaxDamage;
                        downgradeBlock.rotation = blockValue.rotation;
                        blockValue              = downgradeBlock;
                    }
                    blockValue.damage = damage;

                    SendOutput($"Damaging block for {-impact} caused downgrade to '{downgradeBlock.Block.GetBlockName()}' @ {pos}");
                }
                else
                {
                    blockValue.damage = damage;
                }
            }
            else
            {
                //needs to downgrade if damage > max, no overflow damage
                if (damage >= max)
                {
                    var downgrade = blockValue.Block.DowngradeBlock;
                    SendOutput($"Damaging block for {-impact} caused downgrade to '{downgrade.Block.GetBlockName()}' @ {pos}");
                    downgrade.rotation = blockValue.rotation;
                    blockValue         = downgrade;
                }
                else
                {
                    blockValue.damage = damage;
                }
            }

            world.SetBlockRPC(pos, blockValue);
            if (!blockValue.Equals(BlockValue.Air))
            {
                SendOutput($"Damaging block for '{-impact}' leaving {blockValue.Block.blockMaterial.MaxDamage - blockValue.damage}/{blockValue.Block.blockMaterial.MaxDamage} @ {pos}");
            }
        }