Example #1
0
        /// <summary>
        /// Processes the message
        /// </summary>
        /// <param name="connectionBase">The connection base</param>
        /// <param name="message">The playerio message</param>
        /// <param name="handled">Whether the message was already handled</param>
        public void Process(ConnectionBase connectionBase, Message message, bool handled)
        {
            WorldConnection worldCon = (WorldConnection)connectionBase;
            World           world    = worldCon.World;

            int width      = message.GetInt(0);
            int height     = message.GetInt(1);
            int borderId   = message.GetInt(2);
            int workareaId = message.GetInt(3);

            if (!handled)
            {
                world.Clear(width, height, (BlockID)borderId, (BlockID)workareaId);
                foreach (KeyValuePair <int, WorldPlayer> player in worldCon.Players.GetDictionary())
                {
                    player.Value.Reset();
                }
            }

            BlockID borderID   = (BlockID)borderId;
            BlockID workareaID = (BlockID)workareaId;

            ClearEvent clearEvent = new ClearEvent()
            {
                Raw             = message,
                World           = world,
                BorderBlockID   = borderID,
                WorkareaBlockID = workareaID
            };

            connectionBase.RaiseServerEvent <ClearEvent>(clearEvent);
        }
Example #2
0
 public BlockChange(CoordInt pos, BlockID block)
 {
     if (pos == null)
         throw new ArgumentNullException("pos");
     Position = pos;
     BlockType = block;
 }
 /// <summary>
 /// On inspector GUI
 /// </summary>
 public override void OnInspectorGUI()
 {
     base.OnInspectorGUI();
     if (target is IBlocksPrefabObject blocks_prefab)
     {
         blocks_prefab.Initialize();
         WorldManagerScript world_manager = WorldManagerScript.Instance;
         if (world_manager && world_manager.FollowTransformController)
         {
             bool is_showing_grid = (world_manager.ShowingBlocksPrefab == blocks_prefab);
             if (GUILayout.Toggle(is_showing_grid, "Show grid"))
             {
                 world_manager.ShowingBlocksPrefab = blocks_prefab;
             }
             else if (is_showing_grid)
             {
                 world_manager.ShowingBlocksPrefab = null;
             }
             if (GUILayout.Button("Spawn in world"))
             {
                 BlockID blockID = world_manager.FollowTransformController.BlockID;
                 world_manager.SetBlocks(new BlockID(blockID.X + blocks_prefab.Offset.x, blockID.Y + blocks_prefab.Offset.y, blockID.Z + blocks_prefab.Offset.z), blocks_prefab.Size, blocks_prefab.Blocks, ESetBlocksOperation.FillEmpty);
             }
             if (GUILayout.Button("Save from world"))
             {
                 // TODO
             }
         }
     }
     serializedObject.ApplyModifiedProperties();
 }
Example #4
0
        /// <summary>
        /// Gets whether a block can be jumped through
        /// </summary>
        /// <param name="blockId">The block</param>
        /// <returns>True if you can jump through; otherwise false</returns>
        public bool CanJumpThrough(BlockID blockId)
        {
            switch (blockId)
            {
            case (BlockID)61:
            case (BlockID)62:
            case (BlockID)63:
            case (BlockID)64:
            case (BlockID)89:
            case (BlockID)90:
            case (BlockID)91:
            case (BlockID)96:
            case (BlockID)97:
            case (BlockID)122:
            case (BlockID)123:
            case (BlockID)124:
            case (BlockID)125:
            case (BlockID)126:
            case (BlockID)127:
            case (BlockID)146:
            case (BlockID)154:
            case (BlockID)158:
            case (BlockID)194:
            case (BlockID)211:
            case (BlockID)216:
            case BlockID.OneWayCyan:
            case BlockID.OneWayRed:
            case BlockID.OneWayYellow:
            case BlockID.OneWayPink:
                return(true);
            }

            return(false);
        }
Example #5
0
        /// <summary>
        /// Creates the UV mapping of a block.
        /// </summary>
        /// <param name="b">The block to get the mapping of.</param>
        /// <param name="d">The direction of the block to render.</param>
        /// <returns>UVMap representing the UV mapping of the current block.</returns>
        internal static UVMap?CreateUVMapping(this BlockID b, Direction d)
        {
            /*
             * Cheat Sheet
             * x * 2^y = x << y
             * x / 2^y = x >> y      - Except that / rounds up for negatives, and >> always rounds down
             * x % 2^y = x & (2^y - 1)
             */
            // Same as X % 256
            // 256 = (2^16) = 1 << 16
            // x % 256 = x & (256 - 1)
            // x % 256 = x & ((1 << 16) - 1)
            Vector2?posOrNull = b.TileVector(d);

            if (posOrNull == null)
            {
                return(null);
            }

            Vector2 tile = posOrNull.GetValueOrDefault();
            float   x    = ((int)tile.Y & ((1 << 16) - 1)) * Settings.Offset; // U
            float   y    = ((int)tile.X & ((1 << 16) - 1)) * Settings.Offset;

            return(new UVMap(
                       new Vector2(x + Settings.Offset, y),
                       new Vector2(x, y),
                       new Vector2(x + Settings.Offset, y + Settings.Offset),
                       new Vector2(x, y + Settings.Offset)
                       ));
        }
        public void Mine()
        {
            int division = int.MaxValue / Miners.minerIPs.Count;

            Nonce = 0;
            for (int a = 0; a < Miners.minerIPs.Count; a++)
            {
                if (Miners.minerIPs[a].Equals(TCP.myIP))
                {
                    Nonce = division * a;
                }
            }
            Console.WriteLine("Mine started");
            while (true)
            {
                //if(Nonce%1000 == 0)
                //    Console.WriteLine(Nonce);
                if (ChangeNonce(Nonce))
                {
                    Console.WriteLine("Mine ended");
                    Time = DateTime.Now;
                    Miners.SetMyMinerTrue(this);
                    TCP.SendAllMiners("checkNonce" + Time.ToString() + "$" + BlockID.ToString() + "$" + Nonce.ToString());
                    break;
                }
                else
                {
                    Nonce++;
                }
            }
            Console.WriteLine(
                "Block's hash is -> " + Hash +
                "\nBlock's nonce is -> " + Nonce + "\n" +
                "Found Date is -> " + Time + "\n");
        }
Example #7
0
        unsafe int ComputeOcclusion()
        {
            int *didFlags = stackalloc int[chunkSize2];

            OpenTK.MemUtils.memset((IntPtr)didFlags, 0x00, 0, chunkSize2 * sizeof(int));
            int *stack = stackalloc int[chunkSize3 * 4];

            int  i = 0;
            bool solidX = true, solidY = true, solidZ = true;

            for (int y = 0; y < 16; y++)
            {
                for (int z = 0; z < 16; z++)
                {
                    int flagIndex  = (y << 4) | z;
                    int chunkIndex = (y + 1) * extChunkSize2 + (z + 1) * extChunkSize + (0 + 1);
                    for (int x = 0; x < 16; x++)
                    {
                        BlockID block = chunk[chunkIndex];
                        if (info.FullOpaque[block])
                        {
                            didFlags[flagIndex] |= (1 << x);
                        }
                        else if ((didFlags[flagIndex] & (1 << x)) == 0)
                        {
                            FloodFill(didFlags, stack, i, ref solidX, ref solidY, ref solidZ);
                        }

                        i++;
                        chunkIndex++;
                    }
                }
            }
            return((solidX ? 0x1 : 0) | (solidZ ? 0x2 : 0) | (solidY ? 0x4 : 0));
        }
Example #8
0
 /// <summary>
 /// Creates a new world block
 /// </summary>
 /// <param name="id">the block ID</param>
 /// <param name="layer">The layer</param>
 /// <param name="x">The x coorindate</param>
 /// <param name="y">The y coordinate</param>
 public Block(BlockID id, Layer layer, int x, int y)
 {
     m_ID  = id;
     Layer = layer;
     X     = x;
     Y     = y;
 }
        public void BlockID()
        {
            var blockID  = new BlockID("foofoofoofoo");
            var actual   = blockID.ToString();
            var expected = $"{blockID.Node} | {blockID.Round} | 666F6F666F6F";

            Assert.Equal(expected, actual);
        }
        public void ValidHash()
        {
            var blockID  = new BlockID("foo");
            var actual   = blockID.Valid();
            var expected = true;

            Assert.Equal(expected, actual);
        }
        public void InvalidHash()
        {
            var blockID  = new BlockID("");
            var actual   = blockID.Valid();
            var expected = false;

            Assert.Equal(expected, actual);
        }
        public void InvalidBlockID()
        {
            var blockID  = new BlockID("");
            var actual   = blockID.ToString();
            var expected = $"{blockID.Node} | {blockID.Round}";

            Assert.Equal(expected, actual);
        }
        /// <summary>
        /// Calculate block's hash with Time, ParantID, BlockID and Product object
        /// </summary>
        /// <returns>Hash of block</returns>
        public string CalculateHash()
        {
            SHA256 sHA256 = SHA256.Create();

            byte[] input  = Encoding.ASCII.GetBytes(BlockID.ToString() + Data.ToString() + Nonce.ToString());
            byte[] output = sHA256.ComputeHash(input);
            return(Convert.ToBase64String(output));
        }
Example #14
0
 public static BlockDef Get(BlockID ID)
 {
     if (BDefs.ContainsKey(ID))
     {
         return(BDefs[ID]);
     }
     return(null);
 }
Example #15
0
 public Attacked(Client attacker)
 {
     By = attacker;
     Timestamp = DateTime.Now;
     if (attacker.Session.ActiveItem == null)
         Item = BlockID.BareHands;
     else
         Item = attacker.Session.ActiveItem.ItemID;
 }
Example #16
0
        public override void FromBytes(byte[] bytes)
        {
            this.page_type        = bytes[0];
            this.page_type_repeat = bytes[1];

            this.signature = BitConverter.ToUInt16(bytes, 2);
            this.bid       = BitConverter.ToUInt32(bytes, 4);
            this.crc       = BitConverter.ToUInt32(bytes, 8);
        }
Example #17
0
 public BlockChange(CoordInt pos, BlockID block)
 {
     if (pos == null)
     {
         throw new ArgumentNullException("pos");
     }
     Position  = pos;
     BlockType = block;
 }
Example #18
0
        public BlockDef(BlockID ID, bool Transparent)
        {
            this.ID          = ID;
            TexID            = (ushort)ID;
            this.Transparent = Transparent;
            BDefs.Add(ID, this);

            //B = new Block(ID);
        }
Example #19
0
    public void SetPreviewBlock(BlockID InputID)
    {
        if (currentPreviewBlock != null)
        {
            currentPreviewBlock.SetActive(false);
        }

        currentPreviewBlock = PreviewGameObjectDic[InputID];

        currentPreviewBlock.SetActive(true);
    }
Example #20
0
        protected override void Parse(EndianBinaryReader r)
        {
            Position = CoordInt.Read(r);
            TypeState = r.ReadByte();
            PitchDirection = r.ReadByte();
            BlockType = (BlockID)ReadVarInt(r);

            #if DEBUGPACKET
            if (BlockType.ToString() == ((int)BlockType).ToString())
                throw new NotImplementedException(BlockType.ToString());
            #endif
        }
Example #21
0
        /// <summary>
        /// Gets the corresponding block pack to a block id
        /// </summary>
        /// <param name="blockId">The block id</param>
        /// <returns>The corresponding block pack if found; otherwise null</returns>
        public string GetBlockPack(BlockID blockId)
        {
            foreach (KeyValuePair <string, List <int> > blockPack in m_BlockPacks)
            {
                if (blockPack.Value.Contains((int)blockId))
                {
                    return(blockPack.Key);
                }
            }

            return(null);
        }
Example #22
0
        /// <summary>
        /// Gets whether a block is climbable
        /// </summary>
        /// <param name="blockId">The block</param>
        /// <returns>True if climbable; otherwise false</returns>
        public bool IsClimbable(BlockID blockId)
        {
            switch (blockId)
            {
            case BlockID.LadderNinja:
            case BlockID.LadderCastle:
            case BlockID.LadderJungleHorizontal:
            case BlockID.LadderJungleVertical:
                return(true);
            }

            return(false);
        }
Example #23
0
 public Attacked(Client attacker)
 {
     By        = attacker;
     Timestamp = DateTime.Now;
     if (attacker.Session.ActiveItem == null)
     {
         Item = BlockID.BareHands;
     }
     else
     {
         Item = attacker.Session.ActiveItem.ItemID;
     }
 }
Example #24
0
        public SlotItem(BlockID type, int count, int uses, string name)
        {
            this.ItemID = type;
            this.Count = (byte)count;
            this.Uses = uses;

            var t = new TagCompound();
            var td = new TagCompound();
            t ["display"] = td;
            td ["Name"] = new TagString(name);

            this.Data = t;
        }
Example #25
0
        /// <summary>
        /// Processes the message
        /// </summary>
        /// <param name="connectionBase">The connection base</param>
        /// <param name="message">The playerio message</param>
        /// <param name="handled">Whether the message was already handled</param>
        public void Process(ConnectionBase connectionBase, Message message, bool handled)
        {
            WorldConnection worldCon = (WorldConnection)connectionBase;
            World           world    = worldCon.World;

            Layer   layer   = (Layer)message.GetInt(0);
            int     x       = message.GetInt(1);
            int     y       = message.GetInt(2);
            BlockID blockId = (BlockID)message.GetInt(3);

            Block block = null;

            if (message.Count > 4)
            {
                int userId = message.GetInt(4);

                WorldPlayer player = worldCon.Players.GetPlayer(userId);
                block = new Block(worldCon, blockId, layer, x, y)
                {
                    Placer = player
                };
            }
            else
            {
                block = new Block(worldCon, blockId, layer, x, y);
            }

            if (!handled)
            {
                if (blockId == 0)
                {
                    Block old = world[x, y, layer];
                    if (old.ID == BlockID.CoinGold ||
                        old.ID == BlockID.CoinBlue)
                    {
                        worldCon.Physics.RemoveCoin(old);
                    }
                }

                world.SetBlock(block);
            }

            worldCon.CheckBlock(block);
            BlockEvent blockEvent = new BlockEvent()
            {
                Raw   = message,
                Block = block
            };

            connectionBase.RaiseServerEvent <BlockEvent>(blockEvent);
        }
Example #26
0
    void MapInit(int chunkX, int chunkY)
    {
        var treasureChunk = new Vector2Int(Random.Range(0, worldSize.x + 1), Random.Range(0, worldSize.y + 1));
        var chunkPosX     = (((chunkX + 1) / 2) * ((((chunkX + 1) % 2) * 2) - 1));

        mapData = new BlockID[mapSize.x][][];
        for (int x = 0; x < mapSize.x; x++)
        {
            mapData[x] = new BlockID[mapSize.y][];
            for (int y = 0; y < mapSize.y; y++)
            {
                mapData[x][y] = new BlockID[mapSize.z];
                for (int z = 0; z < mapSize.z; z++)
                {
                    LandFill(chunkX, chunkY, x, y, z);
                }
            }
        }

        for (int x = 0; x < mapSize.x; x++)
        {
            for (int y = 0; y < mapSize.y; y++)
            {
                for (int z = 0; z < mapSize.z; z++)
                {
                    if (chunkX == 0 && chunkY < (worldSize.y - 1))
                    {
                        if (x == mapSize.x / 2)
                        {
                            mapData[x][y][z]     = (y == 0 ? BlockID.rail : BlockID.air);
                            mapData[x - 1][y][z] = BlockID.air;
                            mapData[x + 1][y][z] = BlockID.air;
                        }
                    }
                    else
                    {
                        if (!((Random.value * 100) % 100 <= 100 - ((Mathf.Abs(chunkPosX) + chunkY) / 2)))
                        {
                            mapData[x][y][z] = BlockID.gem;
                        }
                        if (treasure == false && treasureChunk == new Vector2Int(chunkX, chunkY) && Random.Range(0, 100) <= 10)
                        {
                            Debug.Log(treasureChunk);
                            mapData[x][y][z] = BlockID.treasure;
                            treasure         = true;
                        }
                    }
                }
            }
        }
    }
Example #27
0
        void GetBlockData(int x, int y, int z, BlockID B, BlockFace F)
        {
            B.GetFaceVerts(x, y, z, F, Mesh, MeshT);
            B.GetFaceUVs(F, Atlas, UVs, UVsT);

            if (B.IsTransparent())
            {
                for (int i = 0; i < 4; i++)
                {
                    ClrsT.Add(new Vector3(1, 1, 1));
                }
            }
            else
            {
                Sides++;
            }

            Vector3 Normal;

            if (F == BlockFace.Forward)
            {
                Normal = new Vector3(1, 0, 0);
            }
            else if (F == BlockFace.Backward)
            {
                Normal = new Vector3(-1, 0, 0);
            }
            else if (F == BlockFace.Left)
            {
                Normal = new Vector3(0, 1, 0);
            }
            else if (F == BlockFace.Right)
            {
                Normal = new Vector3(0, -1, 0);
            }
            else if (F == BlockFace.Top)
            {
                Normal = new Vector3(0, 0, 1);
            }
            else
            {
                Normal = new Vector3(0, 0, -1);
            }

            List <Vector4> Lst = B.IsTransparent() == false ? BlockData : BlockDataT;

            Lst.Add(new Vector4(Normal, (int)B));
            Lst.Add(new Vector4(Normal, (int)B));
            Lst.Add(new Vector4(Normal, (int)B));
            Lst.Add(new Vector4(Normal, (int)B));
        }
Example #28
0
        protected override void Parse(EndianBinaryReader r)
        {
            Position       = CoordInt.Read(r);
            TypeState      = r.ReadByte();
            PitchDirection = r.ReadByte();
            BlockType      = (BlockID)ReadVarInt(r);

#if DEBUG
            if (BlockType.ToString() == ((int)BlockType).ToString())
            {
                throw new NotImplementedException(BlockType.ToString());
            }
#endif
        }
Example #29
0
        public SlotItem(BlockID type, int count, int uses, string name)
        {
            this.ItemID = type;
            this.Count  = (byte)count;
            this.Uses   = uses;

            var t  = new TagCompound();
            var td = new TagCompound();

            t ["display"] = td;
            td ["Name"]   = new TagString(name);

            this.Data = t;
        }
Example #30
0
        public bool SetBlock(int x, int y, int z, BlockID B)
        {
            var Chnk = GetChunk(x / Macroblock.ChunkSize, y / Macroblock.ChunkSize, z / Macroblock.ChunkSize);

            if (Chnk != null)
            {
                if (Chnk.SetBlock(x % Macroblock.ChunkSize, y % Macroblock.ChunkSize, z % Macroblock.ChunkSize, B))
                {
                    ReloadNbChunks(new Vector3(x / Macroblock.ChunkSize, y / Macroblock.ChunkSize, z / Macroblock.ChunkSize));
                    return(true);
                }
            }
            return(false);
        }
        // 타일의 타입으로 해제
        public bool ReleaseTile(BlockID blockID, PlayerTile tile)
        {
            switch (blockID)
            {
            case BlockID.PlayerTile1x1:
                PoolManager.Instance.Release <PlayerTile1x1>("Prefabs/PlayerTile1x1", (PlayerTile1x1)tile);
                return(true);

            case BlockID.PlayerTile1x4:
                PoolManager.Instance.Release <PlayerTile1x4>("Prefabs/PlayerTile1x4", (PlayerTile1x4)tile);
                return(true);

            case BlockID.PlayerTile4x1:
                PoolManager.Instance.Release <PlayerTile4x1>("Prefabs/PlayerTile4x1", (PlayerTile4x1)tile);
                return(true);

            case BlockID.PlayerTile2x2:
                PoolManager.Instance.Release <PlayerTile2x2>("Prefabs/PlayerTile2x2", (PlayerTile2x2)tile);
                return(true);

            case BlockID.PlayerTile3x3:
                PoolManager.Instance.Release <PlayerTile3x3>("Prefabs/PlayerTile3x3", (PlayerTile3x3)tile);
                return(true);

            case BlockID.PlayerTilePlus:
                PoolManager.Instance.Release <PlayerTilePlus>("Prefabs/PlayerTilePlus", (PlayerTilePlus)tile);
                return(true);

            case BlockID.PlayerTileSickle01:
                PoolManager.Instance.Release <PlayerTileSickle01>("Prefabs/PlayerTileSickle01", (PlayerTileSickle01)tile);
                return(true);

            case BlockID.PlayerTileSickle02:
                PoolManager.Instance.Release <PlayerTileSickle02>("Prefabs/PlayerTileSickle02", (PlayerTileSickle02)tile);
                return(true);

            case BlockID.PlayerTileVane01:
                PoolManager.Instance.Release <PlayerTileVane01>("Prefabs/PlayerTileVane01", (PlayerTileVane01)tile);
                return(true);

            case BlockID.PlayerTileVane02:
                PoolManager.Instance.Release <PlayerTileVane02>("Prefabs/PlayerTileVane02", (PlayerTileVane02)tile);
                return(true);

            default:
                return(false);
            }
        }
Example #32
0
        public void Init(BlockID block)
        {
            PlayerTile playerTile = (PlayerTile)FieldObjectManager.Instance.CreateTile(block);

            value          = playerTile.GetValue();
            value          = playerTile.GetValue();
            blockText.text = playerTile.GetName();

            FieldObjectManager.Instance.ReleaseTile(block, playerTile);

            this.block = block;

            coinText.text      = GameManager.Instance.CardSystem.GetUnitValue(value).ToString();
            cardFrame.sprite   = GameManager.Instance.CardSystem.GetCardFrame(value);
            blockSprite.sprite = GameManager.Instance.CardSystem.GetSprite(block);
        }
Example #33
0
        public static bool Solid(this BlockID b)
        {
            if (Transparent(b))
            {
                return(false);
            }
            switch (b)
            {
            case BlockID.Air:
            case BlockID.None:
                return(false);

            default:
                return(true);
            }
        }
Example #34
0
 public bool SetBlock(int X, int Y, int Z, BlockID B, bool Update = true)
 {
     if (Blocks != null && CheckPosition(X, Y, Z))
     {
         if (Blocks[X, Y, Z] == B)
         {
             return(false);
         }
         Blocks[X, Y, Z] = B;
         if (Update)
         {
             Dirty = true;
         }
         return(true);
     }
     return(false);
 }
Example #35
0
 public BlockPos(BlockID id, int meta, int light, CoordInt pos) : base(id, meta, light)
 {
     this.Position = pos;
 }
Example #36
0
 public SlotItem(BlockID type, int count, int uses)
 {
     this.ItemID = type;
     this.Count = (byte)count;
     this.Uses = uses;
 }
Example #37
0
 public Block(BlockID id, int meta, int light)
 {
     this.ID = id;
     this.Meta = meta;
     this.Light = light;
 }
Example #38
0
 public ChargeState(BlockID item)
 {
     this.Item = item;
     this.Timestamp = DateTime.Now;                
 }