예제 #1
0
        public TileType(Texture2D[] textures, string name, short breakTime, Texture2D[] breakOverlay, TileMaterial tileMaterial, EventHandler OnInteraction = null, int millisecondsBetweenFrames = 0, bool requiresSupport = false, bool collidable = true, bool lightSource = false, byte radianceLevel = 0, ItemType droppedItemType = null, bool breakable = true, object[,,] craftingRecipe = null, int amountFromCraft = 1)
        {
            this.textures                  = textures;
            this.name                      = name;
            this.breakTime                 = breakTime;
            this.breakOverlay              = breakOverlay;
            this.breakable                 = breakable;
            this.tileMaterial              = tileMaterial;
            this.lightSource               = lightSource;
            this.radianceLevel             = radianceLevel;
            this.collidable                = collidable;
            this.requiresSupport           = requiresSupport;
            this.millisecondsBetweenFrames = millisecondsBetweenFrames;

            if (OnInteraction == null)
            {
                this.OnInteraction = new EventHandler((sender, e) => { });
            }
            else
            {
                this.OnInteraction = OnInteraction;
            }

            //Create item type and action
            ItemType.ItemAction rightClickAction = () =>
            {
                if (Game1.currentMap.isConnectedTile(Game1.currentMap.positionSelected, requiresSupport))
                {
                    Game1.currentMap.tileMap[Game1.currentMap.positionSelected[0], Game1.currentMap.positionSelected[1]] = new Tile(this, Game1.currentMap.positionSelected, Game1.currentMap.tileSize, collidable: collidable, requiresSupport: requiresSupport);

                    //Remove decorative tiles
                    if (collidable)
                    {
                        Game1.currentMap.decorativeTileMap[Game1.currentMap.positionSelected[0], Game1.currentMap.positionSelected[1]].Clear();
                    }

                    //Update server
                    string tileSerialized = JsonConvert.SerializeObject(Game1.currentMap.tileMap[Game1.currentMap.positionSelected[0], Game1.currentMap.positionSelected[1]]);
                    Game1.networkManager.messagesToSendToServer += ((int)GameServer.NetworkKeyword.mapInfo).ToString() + GameServer.dataSeparator + ((int)GameServer.NetworkKeyword.tileInfo).ToString() + GameServer.dataSeparator + ((int)GameServer.NetworkKeyword.tileChange).ToString() + GameServer.dataSeparator + Game1.mainPlayer.playerGUI.playerInventory.selectedCell.items[0].itemType.name + GameServer.dataSeparator + tileSerialized + GameServer.messageSeparator;

                    //Update lighting
                    LightingManager.updateSurroundingTiles(Game1.currentMap.positionSelected);

                    return(true);
                }

                return(false);
            };
            tileItemType = new TileItemType(name, this, Color.White, rightClickAction: rightClickAction, craftingRecipe: craftingRecipe, amountMadeFromCraft: amountFromCraft);

            if (droppedItemType == null)
            {
                this.droppedItemType = tileItemType;
            }
            else
            {
                this.droppedItemType = droppedItemType;
            }

            //Add to registry
            tileTypes.Add(this);
            //Give tiletype ID
            tileTypeID = tileTypes.Count - 1;
        }
예제 #2
0
        public void breakTile(bool brokenByPlayer, Player playerBrokenBy = null)
        {
            currentBreakTime    = 0;
            currentBreakOverlay = null;

            //Remove dependent surface tile
            removeDependentSurfaceTiles();

            if (brokenByPlayer)
            {
                if (playerBrokenBy != null)
                {
                    playerBrokenBy.breakTile();
                }

                //Update server
                Game1.networkManager.messagesToSendToServer += ((int)GameServer.NetworkKeyword.mapInfo).ToString() + GameServer.dataSeparator + ((int)GameServer.NetworkKeyword.tileInfo).ToString() + GameServer.dataSeparator + ((int)GameServer.NetworkKeyword.tileChange).ToString() + GameServer.dataSeparator + mapPosition[0] + GameServer.dataSeparator + mapPosition[1] + GameServer.dataSeparator + ((int)GameServer.NetworkKeyword.tileNull).ToString() + GameServer.dataSeparator + ((int)GameServer.NetworkKeyword.falseIdentifier).ToString() + GameServer.messageSeparator;

                //Drop to map
                if (tileType.droppedItemType != null)
                {
                    Game1.currentMap.entityAddQueue.Add(new Drop(new Item[] { new Item(tileType.droppedItemType) }, new RigidBody(Drop.massesOfPlayer), new Vector2(rectangle.Center.X, rectangle.Center.Y)));
                }

                Random random = Game1.currentMap.syncedRandom;
                for (int i = 0; i < particlesFromBreak; i++)
                {
                    Game1.currentMap.particleAddQueue.Add(new TileParticle(random.Next(particleSize - particleSizeVariation, particleSize + particleSizeVariation + 1), new Vector2(rectangle.Center.X, rectangle.Center.Y), tileType.textures[textureArrayLocation], 2000, random, initialVelocity: new Vector2(random.Next(-1, 2) * maxParticleFromBreakVelocity, random.Next(-1, 2) * maxParticleFromBreakVelocity)));
                }
            }
            if (terrain)
            {
                //Add background tile
                Game1.currentMap.backgroundTileMap[mapPosition[0], mapPosition[1]] = new BackgroundTile(tileType.textures[0], mapPosition);
            }
            Game1.currentMap.tileMap[mapPosition[0], mapPosition[1]] = null;

            OnBreak.Invoke(this, null);

            //Check tile above for requiring support
            if (mapPosition[1] - 1 >= 0 && Game1.currentMap.tileMap[mapPosition[0], mapPosition[1] - 1] != null)
            {
                //Check
                if (Game1.currentMap.tileMap[mapPosition[0], mapPosition[1] - 1].requiresSupport)
                {
                    if (brokenByPlayer)
                    {
                        Game1.currentMap.tileMap[mapPosition[0], mapPosition[1] - 1].breakTile(true, playerBrokenBy);
                    }
                    else
                    {
                        Game1.currentMap.tileMap[mapPosition[0], mapPosition[1] - 1].breakTile(false);
                    }
                }
            }

            if (brokenByPlayer)
            {
                //Update lighting
                LightingManager.updateSurroundingTiles(mapPosition);
            }
        }