public void NetworkUpdateTile(ITile t) { if (t == null) { return; } NetOutgoingMessage message = IoCManager.Resolve <ISS14NetServer>().CreateMessage(); message.Write((byte)NetMessage.MapMessage); message.Write((byte)MapMessage.TurfUpdate); message.Write(t.WorldPosition.X); message.Write(t.WorldPosition.Y); message.Write(GetTileIndex(t.GetType().Name)); message.Write((byte)t.TileState); if (t.GetType().Name == "Wall") { message.Write((byte)t.dir); } IoCManager.Resolve <ISS14NetServer>().SendToAll(message); }
public Type GetTileType(int x, int y) { ITile tile = GetTile(x, y); if (tile != null) { return(tile.GetType()); } return(null); }
public static EditTileWindow GetEditTileWindow(ITile tile) { var type = tile.GetType(); if (CachedEditors.ContainsKey(type)) { CachedEditors[type].SetValuesFromProperties(tile); return(CachedEditors[type]); } CachedEditors[type] = CreateEditTileWindow(tile); return(CachedEditors[type]); }
public void NetworkUpdateTile(ITile t) { if (t == null) return; NetOutgoingMessage message = IoCManager.Resolve<ISS13NetServer>().CreateMessage(); message.Write((byte) NetMessage.MapMessage); message.Write((byte) MapMessage.TurfUpdate); message.Write(t.WorldPosition.X); message.Write(t.WorldPosition.Y); message.Write(GetTileIndex(t.GetType().Name)); message.Write((byte) t.TileState); if (t.GetType().Name == "Wall") message.Write((byte)t.dir); IoCManager.Resolve<ISS13NetServer>().SendToAll(message); }
private static void AddTileToMap(ITile tile, int row, int column, SerializedMap serializedMap) { if (tile.GetType() == typeof (Conveyer) || tile.GetType() == typeof (ExpressConveyer)) { var conveyor = new SerializedConveyor() { Row = row, Column = column, In = (tile as Conveyer).Entrances.Select(o => o.ToString().ToLowerInvariant()).ToList(), Out = (tile as Conveyer).Exit.ToString().ToLowerInvariant(), Type = (tile.GetType() == typeof (ExpressConveyer) ? "express" : null) }; serializedMap.Conveyors.Add(conveyor); } else if (tile.GetType() == typeof (Gear)) { var gear = new SerializedGear() { Row = row, Column = column, Type = (tile as Gear).Direction.ToString().ToLowerInvariant() }; serializedMap.Gears.Add(gear); } else if (tile.GetType() == typeof (Wrench) || tile.GetType() == typeof (WrenchHammer)) { var wrench = new SerializedWrench() { Row = row, Column = column, Type = (tile.GetType() == typeof (WrenchHammer) ? "option" : null) }; serializedMap.Wrenches.Add(wrench); } else if (tile.GetType() == typeof (Pit)) { var pit = new SerializedPit() { Row = row, Column = column }; serializedMap.Pits.Add(pit); } //else if (tile.GetType() == typeof(Flag)) //{ // var flag = new SerializedFlag() // { // Row = row, // Column = column, // Order = (tile as Flag).Order // }; // serializedMap.Flags.Add(flag); //} // Any flor type can have walls/lasers if (tile is Floor) { if ((tile as Floor).Edges.Any()) { var wall = new SerializedWall() { Row = row, Column = column, Edges = (tile as Floor).Edges.Select(p => p.Item1.ToString().ToLowerInvariant()).ToList() }; serializedMap.Walls.Add(wall); } var laserWallEdge = (tile as Floor).Edges.FirstOrDefault(p => p.Item2 is WallLaserEdge); if (laserWallEdge != null) { // Little bit of a hack around converting directions from "wall edge orientation" to "laser direction" var laserDirection = (Orientation) (((int) laserWallEdge.Item1 + 2)%4); var laser = new SerializedLaser() { Row = row, Column = column, Damage = (laserWallEdge.Item2 as WallLaserEdge).Lasers, Direction = laserDirection }; if (laserWallEdge.Item1 == Orientation.Left || laserWallEdge.Item1 == Orientation.Right) laser.EndRow = laser.Row; else laser.EndColumn = laser.Column; serializedMap.Lasers.Add(laser); } var pusherWallEdge = (tile as Floor).Edges.FirstOrDefault(p => p.Item2 is WallPusherEdge); if (pusherWallEdge != null) { var pusher = new SerializedPusher() { Row = row, Column = column, Registers = (pusherWallEdge.Item2 as WallPusherEdge).Registers, Wall = pusherWallEdge.Item1.ToString().ToLowerInvariant() }; serializedMap.Pushers.Add(pusher); } } }
private void CreateRivers() { Log("Map: Stage 6 - Create rivers"); int rivers = 0; for (int i = 0; i < 256 && rivers < ((_climate + _landMass) * 2) + 6; i++) { ITile[,] tilesBackup = (ITile[, ])_tiles.Clone(); int riverLength = 0; int varA = Common.Random.Next(4) * 2; bool nearOcean = false; ITile tile = null; while (tile == null) { int x = Common.Random.Next(WIDTH); int y = Common.Random.Next(HEIGHT); if (_tiles[x, y].Type == Terrain.Hills) { tile = _tiles[x, y]; } } do { _tiles[tile.X, tile.Y] = new River(tile.X, tile.Y); int varB = varA; int varC = Common.Random.Next(2); varA = (((varC - riverLength % 2) * 2 + varA) & 0x07); varB = 7 - varB; riverLength++; nearOcean = NearOcean(tile.X, tile.Y); switch (varA) { case 0: case 1: tile = _tiles[tile.X, tile.Y - 1]; break; case 2: case 3: tile = _tiles[tile.X + 1, tile.Y]; break; case 4: case 5: tile = _tiles[tile.X, tile.Y + 1]; break; case 6: case 7: tile = _tiles[tile.X - 1, tile.Y]; break; } }while (!nearOcean && (tile.GetType() != typeof(Ocean) && tile.GetType() != typeof(River) && tile.GetType() != typeof(Mountains))); if ((nearOcean || tile.Type == Terrain.River) && riverLength > 5) { rivers++; ITile[,] mapPart = this[tile.X - 3, tile.Y - 3, 7, 7]; for (int x = 0; x < 7; x++) { for (int y = 0; y < 7; y++) { if (mapPart[x, y] == null) { continue; } int xx = mapPart[x, y].X, yy = mapPart[x, y].Y; if (_tiles[xx, yy].Type == Terrain.Forest) { _tiles[xx, yy] = new Jungle(xx, yy, TileIsSpecial(x, y)); } } } } else { _tiles = (ITile[, ])tilesBackup.Clone();; } } }
private void CreateControlsFromProperties(ITile tile) { var props = tile.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(prop => prop.GetCustomAttribute <ShowInEditorAttribute>() != null).ToList(); var properties = props .OrderByDescending(p => p.GetCustomAttribute <ShowInEditorAttribute>().IsBaseClass) .Separate(p => p.GetCustomAttribute <ShowInEditorAttribute>().IsAdvanced); var regularProperties = properties.FalseList; var advancedProperties = properties.TrueList; // create stackpanels var rows = CreateControlsFromProperties(regularProperties, tile); // set rows Grid.SetRow(rows.Left, 0); Grid.SetRow(rows.Right, 0); var saveButton = new Button { Height = ControlCreator.ControlHeight, Content = "Save" }; saveButton.Click += SaveButton_Click; // add save button to right side rows.Right.Children.Add(saveButton); _generatedHeight += ControlCreator.ControlHeight; MainGrid.Children.AddRange(new [] { rows.Left, rows.Right }); // add first row definition MainGrid.RowDefinitions.Add( new RowDefinition { Height = new GridLength(_generatedHeight) }); // reset height _collapsedHeight = _generatedHeight + 50; _generatedHeight = 0; // show advanced properties if any if (!advancedProperties.Any()) { ForceHeight(_collapsedHeight); return; } // initialize expander grid var expanderGrid = new Grid { ColumnDefinitions = { new ColumnDefinition { Width = new GridLength(0.5, GridUnitType.Star) }, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) } } }; var advancedRows = CreateControlsFromProperties(advancedProperties, tile); expanderGrid.Children.AddRange(new[] { advancedRows.Left, advancedRows.Right }); // add expander var advancedExpander = new Expander { Header = "Advanced", Content = expanderGrid }; Grid.SetColumn(advancedExpander, 0); Grid.SetColumnSpan(advancedExpander, 2); Grid.SetRow(advancedExpander, 1); const int expanderHeight = 30; _generatedHeight += expanderHeight; // add expander size _collapsedHeight += expanderHeight; MainGrid.Children.Add(advancedExpander); // add second row definition MainGrid.RowDefinitions.Add( new RowDefinition { Height = new GridLength(_generatedHeight) }); _expandedHeight = _collapsedHeight + _generatedHeight - expanderHeight; // force collapsed height to begin with ForceHeight(_collapsedHeight); // add events for collapsing/expanding advancedExpander.Collapsed += (obj, args) => { ForceHeight(_collapsedHeight); }; advancedExpander.Expanded += (obj, args) => { ForceHeight(_expandedHeight); }; }
protected double? WeightPlayableTile(ITile input) { PlayableTileSelector selector; double? weight = _playableTileRules.Value.TryGetValue(input.GetType(), out selector) ? selector(input) : GetDefaultPlayableTileWeight(input); return weight.HasValue ? weight+GetBasePlayableTileWeight(input) : null; }