/// <summary> /// Even if this TiledImage has already been constructed, we can initialize the tile collection later. /// </summary> /// <param name="width"></param> /// <param name="height"></param> public void Init(int width, int height) { _tiles = new TileCollection(width, height); _typeName = "TileImage"; _support = SpaceTimeSupport.Spatial; }
private void ReadGrayIndex() { int tw = TileCollection.TileWidth; int th = TileCollection.TileHeight; for (int row = 0; row < TileCollection.NumTilesTall(); row++) { for (int col = 0; col < TileCollection.NumTilesWide(); col++) { int width = TileCollection.GetTileWidth(col); int height = TileCollection.GetTileHeight(row); InRamImageData id = new(width, height); byte[] red = new byte[width * height]; _red.ReadRaster(col * tw, row * th, width, height, red, width, height, 0, 0); Bitmap image = new(width, height); BitmapData bData = image.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); Stride = bData.Stride; image.UnlockBits(bData); byte[] vals = new byte[width * height * 4]; int stride = Stride; const int Bpp = 4; for (int r = 0; r < height; r++) { for (int c = 0; c < width; c++) { vals[(r * stride) + (c * Bpp)] = red[(r * width) + c]; vals[(r * stride) + (c * Bpp) + 1] = red[(r * width) + c]; vals[(r * stride) + (c * Bpp) + 2] = red[(r * width) + c]; vals[(r * stride) + (c * Bpp) + 3] = 255; } } id.Values = vals; id.CopyValuesToBitmap(); TileCollection.Tiles[row, col] = id; } } SetTileBounds(Bounds.AffineCoefficients); }
internal void CommitTiles(TileCollection tiles) { using (var tileGraphics = System.Drawing.Graphics.FromImage(tileImage)) { for (int row = 0; row < tiles.Height; ++row) { for (int col = 0; col < tiles.Width; ++col) { if (!tiles[row, col].Updated) { continue; } Bitmap source = Resources.Tiles.Clone(GraphicsUtils.GetGraphicSourceRectangle(tiles[row, col].GraphicsID, GraphicsConstants.TileWidth, Resources.Tiles.Width / GraphicsConstants.TileWidth), Resources.Tiles.PixelFormat); GraphicsUtils.SwapColors(source, tiles[row, col].Palette); tileGraphics.DrawImage(source, new Point(col * GraphicsConstants.TileWidth, row * GraphicsConstants.TileWidth)); tiles[row, col].Updated = false; } } } }
public TileCollectionWindow() { // main window Closing += MainWindow_Closing; InitializeComponent(); if (Settings.Current.IsDefault) { UseDefaultSettings(); } else { UseSettings(); } _tiles = Settings.Current.Tiles; PathVariables.UseSettings(Settings.Current); Settings.SetMainWindow(this); #if DEBUG Title = "[DEBUG MODE] " + Title; #endif }
void ShowErrorTile() { _downloadQueue.Clear(); TileCollection tiles = flickrTiles.Groups[0].Tiles; flickrTiles.BeginUpdate(); tiles.Clear(true); var tile = new Tile(); tile.HorizontalSize = 4; tile.VerticalSize = 2; tile.Template = tempError; tile.Click += ErrorTile_Click; tiles.Add(tile); flickrTiles.EndUpdate(); }
public TileSet() { m_PaletteZero = 0; m_Palettes = new byte[4] { 0, 0, 0, 0 }; m_Tilegfx = new TileCollection(); int tile = m_Tilegfx.GetIndexFromTileAndPage(0, 0, create: true); m_Metatiles = new int[Data.TileSet.TilesPerSet][]; m_Bitfields = new byte[Data.TileSet.TilesPerSet]; m_Attributes = new byte[Data.TileSet.TilesPerSet]; for (int i = 0; i < TileSet.TilesPerSet; i++) { m_Metatiles[i] = new int[4] { tile, tile, tile, tile }; m_Bitfields[i] = 0; } }
/// <summary> /// If this TileCollection is rectangular in form, converts it to a literal /// rectangular array of Tiles, for the purposes of serialization. /// </summary> public static Tile[,] UnJaggedize(this TileCollection input) { foreach (TileList ary in input) { if (null == ary || input[0].Count != ary.Count) { throw new ArgumentException("Can't un-jaggedize a jagged jagged array"); } } Tile[,] output = new Tile[input.Count, input[0].Count]; for (int i = 0; i < input.Count; i++) { for (int j = 0; j < input[0].Count; j++) { output[i, j] = input[i][j]; } } return(output); }
public virtual object CreateMemento() { var imageBox = this.ImageViewer.SelectedImageBox as PrintViewImageBox; object displaySetMemento = null; if (imageBox.DisplaySet != null) { displaySetMemento = imageBox.DisplaySet.CreateMemento(); } int IndexOfSelectedTile; if (imageBox.SelectedTile == null) { IndexOfSelectedTile = -1; } else { IndexOfSelectedTile = imageBox.Tiles.IndexOf(imageBox.SelectedTile); } TileCollection tileCollection = new TileCollection(); tileCollection.AddRange(imageBox.Tiles); PrintImageBoxMemento imageBoxMemento = new PrintImageBoxMemento(imageBox.DisplaySet.Clone(), imageBox.DisplaySetLocked, displaySetMemento, tileCollection, imageBox.TopLeftPresentationImageIndex, imageBox.NormalizedRectangle, IndexOfSelectedTile, imageBox.TotleImageCount); return(imageBoxMemento); }
private void Start() { _tileCollection = GetComponent <TileCollection>(); }
/// <summary>Recalculates tile system. </summary> public static void FixTiles(TileLayer tiles, TileCollection collection) { Logger.Info("Recalculating tile LAT system"); // change all CLAT tiles to their corresponding LAT tiles foreach (MapTile t in tiles) { // If this tile comes from a CLAT (connecting lat) set, // then replace it's set and tilenr by corresponding LAT sets' t.SetNum = collection.GetSetNum(t.TileNum); if (collection.IsCLAT(t.SetNum)) { t.SetNum = collection.GetLAT(t.SetNum); t.TileNum = collection.GetTileNumFromSet(t.SetNum); } } // apply autolat foreach (MapTile t in tiles) { // If this tile is a LAT tile, we might have to connect it if (collection.IsLAT(t.SetNum)) { // Which tile to use from CLAT tileset byte transitionTile = 0; MapTile tileTopRight = tiles.GetNeighbourTile(t, TileLayer.TileDirection.TopRight); MapTile tileBottomRight = tiles.GetNeighbourTile(t, TileLayer.TileDirection.BottomRight); MapTile tileBottomLeft = tiles.GetNeighbourTile(t, TileLayer.TileDirection.BottomLeft); MapTile tileTopLeft = tiles.GetNeighbourTile(t, TileLayer.TileDirection.TopLeft); // Find out setnums of adjacent cells if (tileTopRight != null && collection.ConnectTiles(t.SetNum, tileTopRight.SetNum)) { transitionTile += 1; } if (tileBottomRight != null && collection.ConnectTiles(t.SetNum, tileBottomRight.SetNum)) { transitionTile += 2; } if (tileBottomLeft != null && collection.ConnectTiles(t.SetNum, tileBottomLeft.SetNum)) { transitionTile += 4; } if (tileTopLeft != null && collection.ConnectTiles(t.SetNum, tileTopLeft.SetNum)) { transitionTile += 8; } if (transitionTile > 0) { // Find Tileset that contains the connecting pieces short clatSet = collection.GetCLATSet(t.SetNum); // Do not change this setnum, as then we could recognize it as // a different tileset for later tiles around this one. // (T->SetNum = clatSet;) t.TileNum = collection.GetTileNumFromSet(clatSet, transitionTile); t.Drawable = collection.GetDrawable(t); } } // apply ramp fixup else if (t.SetNum == collection.RampBase) { var ti = t.GetTileImage(); if (ti.RampType < 1 || 4 < ti.TerrainType) { continue; } int fixup = -1; MapTile tileTopRight = tiles.GetNeighbourTile(t, TileLayer.TileDirection.TopRight); MapTile tileBottomRight = tiles.GetNeighbourTile(t, TileLayer.TileDirection.BottomRight); MapTile tileBottomLeft = tiles.GetNeighbourTile(t, TileLayer.TileDirection.BottomLeft); MapTile tileTopLeft = tiles.GetNeighbourTile(t, TileLayer.TileDirection.TopLeft); switch (ti.RampType) { case 1: // northwest facing if (tileTopLeft != null && tileTopLeft.GetTileImage().RampType == 0) { fixup++; } if (tileBottomRight != null && tileBottomRight.GetTileImage().RampType == 0) { fixup += 2; } break; case 2: // northeast facing if (tileTopRight != null && tileTopRight.GetTileImage().RampType == 0) { fixup++; } if (tileBottomLeft != null && tileBottomLeft.GetTileImage().RampType == 0) { fixup += 2; } break; case 3: // southeast facing if (tileBottomRight != null && tileBottomRight.GetTileImage().RampType == 0) { fixup++; } if (tileTopLeft != null && tileTopLeft.GetTileImage().RampType == 0) { fixup += 2; } break; case 4: // southwest facing if (tileBottomLeft != null && tileBottomLeft.GetTileImage().RampType == 0) { fixup++; } if (tileTopRight != null && tileTopRight.GetTileImage().RampType == 0) { fixup += 2; } break; } if (fixup != -1) { t.TileNum = collection.GetTileNumFromSet(collection.RampSmooth, (byte)((ti.RampType - 1) * 3 + fixup)); // update drawable too t.Drawable = collection.GetDrawable(t); } } } }
public MapManager() { tileIndexer = new TileCollection(this); NewMap(); }
/// <summary> /// Loads the tileset from the game resources. /// </summary> /// <param name="contentManager">The content manager to use.</param> /// <param name="name">The relative filename of the XML file describing the tileset.</param> public void Load(ContentManager contentManager, String name) { if (contentManager == null) throw new ArgumentNullException("contentManager"); if (String.IsNullOrEmpty(name)) throw new ArgumentNullException("name"); String path = Path.Combine(contentManager.RootDirectory, name); if (!File.Exists(path)) throw new FileNotFoundException(null, path); this.tiles = new TileCollection(); XmlDocument doc = new XmlDocument(); doc.Load(path); XmlElement rootElement = doc.DocumentElement; this.name = rootElement.GetAttribute("Name"); this.resource = rootElement.GetAttribute("Resource"); foreach (XmlNode childNode in rootElement.ChildNodes) { if (childNode.NodeType != XmlNodeType.Element) continue; XmlElement childElement = (XmlElement)childNode; if(childElement.Name.Equals("Tile")) { Tile t = new Tile( childElement.InnerText, Convert.ToBoolean(childElement.GetAttribute("Passable"))); t.Frames.Enqueue(Convert.ToUInt32(childElement.GetAttribute("ID"))); // :: Add the tile to the index. this.tiles.Add(t.Name, t); } else if (childElement.Name.Equals("AnimatedTile")) { Tile t = new Tile( childElement.GetAttribute("Name"), Convert.ToBoolean(childElement.GetAttribute("Passable")), true); t.Speed = Convert.ToSingle(childElement.GetAttribute("Speed")); foreach (XmlNode frameNode in childElement.ChildNodes) { if (frameNode.NodeType != XmlNodeType.Element) continue; XmlElement frameElement = (XmlElement)frameNode; if (frameElement.Name.Equals("Frame")) { t.Frames.Enqueue( Convert.ToUInt32(frameElement.GetAttribute("ID"))); } } // :: Add the animated tile to the index. this.tiles.Add(t.Name, t); } } // :: We can only initialise the tileset once. if (this.initialised) throw new InvalidOperationException("Tileset is already initialised."); // :: Load the texture tileset texture. this.texture = contentManager.Load<Texture2D>(this.resource); this.initialised = true; }
public bool GoToBed(Food foodEaten = null) { this.TimeOfLastLogin = Environment.TickCount; if (!this.Parent.Player.Connected) { return(true); } int oneHour = 1000 * 60 * 60, regenTime = foodEaten != null ? (int)(maxRegenTime - foodEaten.RegenerationTime) : 0; int timeToSleep = this.Parent.Player.Mana >= this.SpellMana ? 1000 * 60 * 45 // wait 45 minutes if no blanks are present : (int)Math.Ceiling(((float)(this.SpellMana - this.Parent.Player.Mana) / (float)manaPerHour) * oneHour + 1000 * 3); if (regenTime > 0 && timeToSleep > regenTime) { timeToSleep = regenTime; } if (timeToSleep > maxRegenTime) { timeToSleep = maxRegenTime; } this.TimeNeededToRegen = timeToSleep; System.IO.File.AppendAllText("bedmagedebug.txt", DateTime.UtcNow.TimeOfDay.ToString() + " - " + this.CharacterName + " - sleep time: " + TimeSpan.FromMilliseconds(this.TimeNeededToRegen).ToString() + " ate food: " + (foodEaten != null ? "yes" : "no") + "\n"); TileCollection tiles = null; while (!this.Parent.Player.Location.IsAdjacentTo(this.BedLocation)) { Thread.Sleep(500); if (this.Parent.Player.IsWalking) { continue; } if (!this.Parent.Player.Location.IsOnScreen(this.BedLocation)) { return(false); } tiles = this.Parent.Map.GetTilesOnScreen(); // find closest adjacent tile int closestDistance = 50; Location closestLocation = Location.Invalid; foreach (Tile adjTile in tiles.GetAdjacentTiles(this.BedLocation)) { var tilesToAdjLocation = this.Parent.Player.Location.GetTilesToLocation(this.Parent, adjTile.WorldLocation, tiles, this.Parent.PathFinder).ToArray(); if (tilesToAdjLocation.Length == 0) { continue; } if (closestDistance <= tilesToAdjLocation.Length) { continue; } closestDistance = tilesToAdjLocation.Length; closestLocation = adjTile.WorldLocation; } if (!closestLocation.IsValid()) { return(false); } this.Parent.Player.GoTo = closestLocation; } tiles = this.Parent.Map.GetTilesOnScreen(); Tile tile = tiles.GetTile(this.BedLocation); if (tile == null) { return(false); } TileObject topItem = tile.GetTopUseItem(false); if (topItem == null) { return(false); } while (this.Parent.Player.Connected) { topItem.Use(); Thread.Sleep(500); } return(true); }
public static void Main(Client client) { List <ushort> depotLockers = new List <ushort>() { 2589, 2590, 2591, 2592 //7.6+ 3497, 3498, 3499, 3500 }; List <DepotItem> itemsToDeposit = new List <DepotItem>() { new DepotItem(2599, 2594) //new DepotItem(2004, 2594) // yellow (ankrahmun) bps to depot chest }; List <DepotItem> itemsToTake = new List <DepotItem>() { new DepotItem(2599, 2594, 1) //new DepotItem(2004, 2004, 1) // yellow bps from a yellow bp inside locker }; Location currentLockerLocation = Location.Invalid; TileCollection tilesOnScreen = null; Tile playerTile = null; // find and reach depot locker while (true) { Thread.Sleep(500); if (client.Player.IsWalking) { continue; } if (currentLockerLocation.IsValid() && client.Player.Location == currentLockerLocation) { break; } tilesOnScreen = client.Map.GetTilesOnScreen(); var lockerTiles = tilesOnScreen.GetTileCollectionWithObjects(depotLockers); if (lockerTiles.IsEmpty()) { break; } playerTile = tilesOnScreen.GetPlayerTile(); if (playerTile == null) { break; } var tiles = lockerTiles.GetTiles().ToList(); tiles.Sort(delegate(Tile first, Tile second) { return(playerTile.WorldLocation.DistanceTo(first.WorldLocation).CompareTo( playerTile.WorldLocation.DistanceTo(second.WorldLocation))); }); foreach (Tile t in tiles) { TileObject topItem = t.GetTopUseItem(false); if (!depotLockers.Contains(topItem.ID)) { continue; } Tile closestTile = tilesOnScreen.GetClosestNearbyTile(playerTile, t); if (closestTile == null) { continue; } currentLockerLocation = closestTile.WorldLocation; client.Player.GoTo = currentLockerLocation; break; } } if (!currentLockerLocation.IsValid() || client.Player.Location != currentLockerLocation) { return; } // open depot locker tilesOnScreen = client.Map.GetTilesOnScreen(); playerTile = tilesOnScreen.GetPlayerTile(); if (playerTile == null) { return; } foreach (Tile adjacentTile in tilesOnScreen.GetAdjacentTiles(playerTile)) { Container depotContainer = client.Inventory.GetFirstClosedContainer(); for (int i = 0; i < 5; i++) { adjacentTile.UpdateObjects(); TileObject topItem = adjacentTile.GetTopUseItem(false); if (!depotLockers.Contains(topItem.ID)) { break; } topItem.Use(); Thread.Sleep(500); if (!depotContainer.IsOpen) { continue; } break; } if (!depotContainer.IsOpen) { continue; } // locker is open, run deposit logic // sort by depth itemsToDeposit.Sort(delegate(DepotItem first, DepotItem second) { return(first.Depth.CompareTo(second.Depth)); }); DepotItem last = null, current = null; for (int i = 0; i < itemsToDeposit.Count; i++) { current = itemsToDeposit[i]; // get back to root container if necessary if (last == null || current.ContainerID != last.ContainerID || current.Depth != last.Depth) { while (depotContainer.HasParent) { depotContainer.OpenParentContainer(); Thread.Sleep(500); } } // open containers if necessary byte depth = 0; while (current.Depth > depth && depotContainer.IsOpen) { Item subContainer = null; if (current.ContainerID != 0) { subContainer = depotContainer.GetItem(current.ContainerID); if (subContainer == null) { break; } if (!subContainer.HasFlag(Enums.ObjectPropertiesFlags.IsContainer)) { break; } } else { foreach (Item item in depotContainer.GetItems()) { if (!item.HasFlag(Enums.ObjectPropertiesFlags.IsContainer)) { continue; } subContainer = item; break; } } if (subContainer == null) { break; } subContainer.Use(); Thread.Sleep(1000); depth++; } // check if we reached the depth // if not, skip this item if (current.Depth != depth) { continue; } // move items to depot foreach (Item item in client.Inventory.GetItems()) { if (!depotContainer.IsOpen) { break; } if (current.ItemID != item.ID) { continue; } if (current.ContainerID == 0) // no container specified, put in current container { if (depotContainer.IsFull) { break; } ItemLocation slot = depotContainer.GetFirstEmptySlot(); if (slot == null) { break; } item.Move(slot); item.WaitForInteraction(500); break; } // put item inside container Item subContainer = depotContainer.GetItem(current.ContainerID); if (subContainer == null) { break; } item.Move(subContainer.ToItemLocation()); item.WaitForInteraction(500); break; } last = current; } // deposit logic done, run withdraw logic if (itemsToTake.Count == 0 || !depotContainer.IsOpen) { return; } last = null; for (int i = 0; i < itemsToTake.Count; i++) { current = itemsToTake[i]; // get back to root container if necessary if (last == null || current.ContainerID != last.ContainerID || current.Depth != last.Depth) { while (depotContainer.HasParent) { depotContainer.OpenParentContainer(); Thread.Sleep(500); } } // open containers if necessary byte depth = 0; while (current.Depth > depth && depotContainer.IsOpen) { Item subContainer = null; if (current.ContainerID != 0) { subContainer = depotContainer.GetItem(current.ContainerID); if (subContainer == null) { break; } if (!subContainer.HasFlag(Enums.ObjectPropertiesFlags.IsContainer)) { break; } } else { foreach (Item item in depotContainer.GetItems()) { if (!item.HasFlag(Enums.ObjectPropertiesFlags.IsContainer)) { continue; } subContainer = item; break; } } if (subContainer == null) { break; } subContainer.Use(); Thread.Sleep(1000); depth++; } // check if we reached the depth // if not, skip this item if (current.Depth != depth) { continue; } // move items to the player's inventory foreach (Item item in depotContainer.GetItems()) { if (!depotContainer.IsOpen) { break; } if (current.ItemID != item.ID) { continue; } ItemLocation slot = client.Inventory.GetFirstSuitableSlot(item); if (slot == null) { break; } item.Move(slot); item.WaitForInteraction(500); break; } } if (depotContainer != null && depotContainer.IsOpen) { depotContainer.Close(); } return; } }
public static bool Valid(this TileCollection t, int X, int Y) { return(X >= 0 && Y >= 0 && X < Main.maxTilesX && Y < Main.maxTilesY && Main.tile[X, Y] != null); }
private protected override void NextFrame(TileCollection tiles, IDictionary <string, GameObject> gameObjects) { throw new NotImplementedException(); }
public void SaveXMLTiles() { var tileContainer = TileCollection.Load(Path.Combine(Application.dataPath, "Tiles.xml")); tileContainer.Save(Path.Combine(Application.persistentDataPath, "Tiles.xml")); }
//READING / SAVING XML FILE public void ReadXMLTiles() { var tileContainer = TileCollection.Load(Path.Combine(Application.dataPath, "Tiles.xml")); // var xmlData = @"<TileCollection><tiles><Tiles name=""a""><model_path></model_path>x<material_path>y</material_path></Tiles></tiles></TileCollection>"; // var tileContainer = TileCollection.LoadFromText(xmlData); // Debug.Log("Number of tiles in database: " + tileContainer.tiles.Length); // Debug.Log(tileContainer.tiles[0].model_path); // AddButton(tileContainer.tiles.Length); //ADD BUTTONS TO UI var parentDatabase = new GameObject(); parentDatabase.name = "Tile_Database"; parentDatabase.layer = 10; for (int c = 0; c < tileContainer.tiles.Length; c++) { FilePath = tileContainer.tiles[c].model_path; Debug.Log(tileContainer.tiles[c].model_path); // FilePath = "Models/Tiles/Floors/nukeguard/mesh1"; GameObject model = Resources.Load <GameObject>(FilePath); GameObject obj = (GameObject)Instantiate(model); // obj.AddComponent(typeof(LODGroup)); foreach (Transform child in obj.transform) { child.gameObject.layer = 10; } // obj.SetActive(false); obj.transform.SetParent(parentDatabase.transform); // obj.name = tileContainer.tiles[c].Name; obj.name = c.ToString(); newButton = Instantiate(Button); but = newButton.GetComponent <SelectTileButton>(); but.TileID = c; newButton.GetComponentInChildren <Text>().text = tileContainer.tiles[c].Name; newButton.transform.SetParent(BuildingMenu.transform); // TO REMOVE WHEN ALL TILES IS UNIFIED if (obj.transform.Find("Camera") != null) { obj.transform.Find("Camera").GetComponent <Camera>().enabled = false; } // END REMOVE //obj.GetComponent<LODGroup>(). // /* if (obj.transform.Find("model") != null) { group = obj.AddComponent <LODGroup>(); // Add 4 LOD levels LOD[] lods = new LOD[4]; for (int i = 0; i < 4; i++) { GameObject primType = obj.transform.Find("model").gameObject; switch (i) { case 1: primType = obj.transform.Find("lod1").gameObject; break; case 2: primType = obj.transform.Find("lod2").gameObject; break; case 3: primType = obj.transform.Find("lod3").gameObject; break; } Renderer[] renderers = new Renderer[1]; renderers[0] = primType.GetComponentInChildren <Renderer>(); lods[i] = new LOD(1.0F / (i + 1.2f), renderers); } group.SetLODs(lods); group.RecalculateBounds(); } } }
void WebClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { if (e.Cancelled || _targetItem == null) { return; } Exception ex = e.Error; if (ex == null) { try { if (_targetItem.Tile == null) { var doc = new XmlDocument(); doc.Load(e.Result); var nameTable = new NameTable(); var nm = new XmlNamespaceManager(nameTable); nm.AddNamespace("ns", "http://www.w3.org/2005/Atom"); nm.AddNamespace("flickr", "urn:flickr:user"); List <FlickrPhoto> result = new List <FlickrPhoto>(); TileCollection tiles = flickrTiles.Groups[0].Tiles; bool keepExistent = _targetItem.IsBuddyIcon; foreach (XmlNode node in doc.DocumentElement.SelectNodes("ns:entry", nm)) { string id = node.SelectSingleNode("ns:id", nm).InnerText; if (keepExistent) { bool found = false; foreach (Tile tile in tiles) { if (((FlickrPhoto)tile.Tag).ID == id) { found = true; break; } } if (found) { continue; } } var photo = new FlickrPhoto(); photo.ID = id; photo.Title = PrepareTitle(node.SelectSingleNode("ns:title", nm).InnerText); var authorNode = node.SelectSingleNode("ns:author", nm); if (authorNode != null) { photo.AuthorName = authorNode.SelectSingleNode("ns:name", nm).InnerText; photo.AuthorBuddyIconUri = authorNode.SelectSingleNode("flickr:buddyicon", nm).InnerText; } var linkNode = node.SelectSingleNode("ns:link[@rel='enclosure']", nm); if (linkNode != null) { photo.ContentUri = linkNode.Attributes["href"].Value; photo.ThumbnailUri = photo.ContentUri.Replace("_b.jpg", "_m.jpg"); } result.Add(photo); } UpdatePhotos(result, tiles, keepExistent); } else { Image img = Image.FromStream(e.Result); Tile tile = _targetItem.Tile; if (!_targetItem.IsBuddyIcon) { tile.Image = img; } else { tile.Image1 = img; } } } catch (Exception exception) { ex = exception; } } if (ex != null && _targetItem.Tile == null && !_targetItem.IsBuddyIcon) { _targetItem = null; _lastError = ex.Message; ShowErrorTile(); } else { _targetItem = null; _lastError = null; if (_outOfTurnItem != null) { _targetItem = _outOfTurnItem; _outOfTurnItem = null; } else if (_downloadQueue.Count > 0) { _targetItem = _downloadQueue.Dequeue(); } if (_targetItem != null) { _client.OpenReadAsync(new Uri(_targetItem.Uri)); } } waitLabel.Visible = false; }
private protected abstract void NextFrame(TileCollection tiles, IDictionary <string, GameObject> gameObjects);
private void Start() { _tileCollection = FindObjectOfType <TileCollection>(); }
private static Tileset TilesetFromStream(BinaryReader reader, uint offset, string tilesetDirectory) { if (!Directory.Exists(tilesetDirectory)) { throw new ArgumentException(string.Format("Directory {0} does not exists", tilesetDirectory), tilesetDirectory); } reader.BaseStream.Seek(offset, SeekOrigin.Begin); Tileset output = new Tileset(reader.ReadBoolean(), reader.ReadBoolean()); output.Field2 = reader.ReadByte(); output.Field3 = reader.ReadByte(); uint imageOffset = reader.ReadUInt32() & 0x1FFFFFF; uint palOffset = reader.ReadUInt32() & 0x1FFFFFF; uint blockOffset = reader.ReadUInt32() & 0x1FFFFFF; uint animationOffset = reader.ReadUInt32(); uint behaviorOffset = reader.ReadUInt32() & 0x1FFFFFF; /* NOTE: Check on second tileset palette */ if (output.Secondary) { palOffset = palOffset + 0xE0; } reader.BaseStream.Seek(palOffset, SeekOrigin.Begin); int palette_cnt = output.Secondary ? 6 : 7; ShortColor[][] palette = new ShortColor[palette_cnt][]; for (int i = 0; i < palette_cnt; ++i) { palette[i] = new ShortColor[16]; for (int j = 0; j < 16; ++j) { palette[i][j] = new ShortColor(reader.ReadUInt16()); } output.Palettes[i] = new Palette(palette[i]); } reader.BaseStream.Seek(imageOffset, SeekOrigin.Begin); byte[] tileset = reader.ReadLzArray().ToArray(); TileCollection set = new TileCollection(tileset); set.ToImage(16, palette[1]).Save(tilesetDirectory + "/tileset_" + (offset + 0x08000000).ToString("X8") + "_" + (output.Secondary ? "secondary" : "primary") + ".png"); reader.BaseStream.Seek(blockOffset, SeekOrigin.Begin); int maxBlocks = output.Secondary ? Tileset.MAX_SECOND_TILESET_SIZE : Tileset.MAX_FIRST_TILESET_SIZE; for (int i = 0; i < maxBlocks; ++i) { output.Blocks[i] = new TilesetEntry(null, new BlockTilemap[] { new BlockTilemap(reader.ReadUInt16()), new BlockTilemap(reader.ReadUInt16()), new BlockTilemap(reader.ReadUInt16()), new BlockTilemap(reader.ReadUInt16()), new BlockTilemap(reader.ReadUInt16()), new BlockTilemap(reader.ReadUInt16()), new BlockTilemap(reader.ReadUInt16()), new BlockTilemap(reader.ReadUInt16()) }); } output.AnimationInitFunctionInternal = animationOffset; output.AnimationInitFunction = "0x" + animationOffset.ToString("X8"); reader.BaseStream.Seek(behaviorOffset, SeekOrigin.Begin); for (int i = 0; i < maxBlocks; ++i) { output.Blocks[i].Behaviour = new BlockBehaviour(reader.ReadUInt32()); } return(output); }
private Maze(TileCollection tiles, List <RectangleF> walls, (List <Vector2> pellets, List <Vector2> powerPellets) pelletInfo,
/// <summary> /// Attempts to open a container on the ground. Returns null if unsuccessful. /// </summary> /// <param name="client">The client to use.</param> /// <param name="tiles">A collection of tiles.</param> /// <param name="loc">The world location of the container.</param> /// <returns></returns> public Container OpenContainer(TileCollection tiles, Location loc) { Tile tile = tiles.GetTile(loc); if (tile == null) { return(null); } TileObject topItem = tile.GetTopUseItem(false); if (topItem == null || !topItem.HasFlag(Enums.ObjectPropertiesFlags.IsContainer)) { return(null); } while (!this.Parent.Player.Location.IsAdjacentTo(loc) && this.Parent.Player.Location != loc) { Thread.Sleep(500); if (this.Parent.Player.IsWalking) { continue; } var tilesToLocation = this.Parent.Player.Location.GetTilesToLocation(this.Parent, loc, tiles, this.Parent.PathFinder, true, true).ToArray(); if (tilesToLocation.Length == 0) { return(null); } // get closest adjacent tile Tile playerTile = tiles.GetTile(count: this.Parent.Player.ID); if (playerTile == null) { break; } Tile closestTile = tiles.GetClosestNearbyTile(playerTile, tile); if (closestTile == null) { break; } this.Parent.Player.GoTo = closestTile.WorldLocation; } if (!this.Parent.Player.Location.IsAdjacentTo(loc) && this.Parent.Player.Location != loc) { return(null); } // open container on ground Container closedContainer = this.Parent.Inventory.GetFirstClosedContainer(); if (closedContainer == null) { return(null); } for (int i = 0; i < 3; i++) { topItem.Use(); for (int j = 0; j < 5; j++) { Thread.Sleep(100); if (closedContainer.IsOpen) { break; } } if (closedContainer.IsOpen) { break; } } if (!closedContainer.IsOpen) { return(null); } return(closedContainer); }
private protected override void NextFrame(TileCollection tiles, IDictionary <string, GameObject> gameObjects) { switch (CurrentFrame) { case 0: graphicsHandler.PreventAnimatedSpriteUpdates = true; tiles.DrawText(4, 7, CharacterNicknameString); tiles.DrawText(27, 5, "CTRL-H HIGHSCORES"); tiles.DrawText(28, 5, "CTRL-R RESET"); tiles.DrawText(29, 5, "WASD MOVE"); tiles.DrawText(30, 5, "P PAUSE"); tiles.DrawText(31, 5, "ENTER START"); break; case 1: UntilNextFrame = 1000; gameObjects[StaticBlinkyObjName] = new GameObject(GraphicsConstants.SpriteSize) { Position = Game.Vector2FromTilePosition(5, 6.5) }; graphicsHandler.SetStaticSprite(gameObjects[StaticBlinkyObjName], GraphicsID.SpriteGhostRight0, PaletteID.Blinky); break; case 2: UntilNextFrame = 500; tiles.DrawText(6, 7, $"-{BlinkyName}", PaletteID.Blinky); break; case 3: UntilNextFrame = 500; tiles.DrawText(6, 18, $"\"{BlinkyNickname}\"", PaletteID.Blinky); break; case 4: UntilNextFrame = 1000; gameObjects[StaticPinkyObjName] = new GameObject(GraphicsConstants.SpriteSize) { Position = Game.Vector2FromTilePosition(5, 9.5) }; graphicsHandler.SetStaticSprite(gameObjects[StaticPinkyObjName], GraphicsID.SpriteGhostRight0, PaletteID.Pinky); break; case 5: UntilNextFrame = 500; tiles.DrawText(9, 7, $"-{PinkyName}", PaletteID.Pinky); break; case 6: UntilNextFrame = 500; tiles.DrawText(9, 18, $"\"{PinkyNickname}\"", PaletteID.Pinky); break; case 7: UntilNextFrame = 1000; gameObjects[StaticInkyObjName] = new GameObject(GraphicsConstants.SpriteSize) { Position = Game.Vector2FromTilePosition(5, 12.5) }; graphicsHandler.SetStaticSprite(gameObjects[StaticInkyObjName], GraphicsID.SpriteGhostRight0, PaletteID.Inky); break; case 8: UntilNextFrame = 500; tiles.DrawText(12, 7, $"-{InkyName}", PaletteID.Inky); break; case 9: UntilNextFrame = 500; tiles.DrawText(12, 18, $"\"{InkyNickname}\"", PaletteID.Inky); break; case 10: UntilNextFrame = 1000; gameObjects[StaticClydeObjName] = new GameObject(GraphicsConstants.SpriteSize) { Position = Game.Vector2FromTilePosition(5, 15.5) }; graphicsHandler.SetStaticSprite(gameObjects[StaticClydeObjName], GraphicsID.SpriteGhostRight0, PaletteID.Clyde); break; case 11: UntilNextFrame = 500; tiles.DrawText(15, 7, $"-{ClydeName}", PaletteID.Clyde); break; case 12: UntilNextFrame = 500; tiles.DrawText(15, 18, $"\"{ClydeNickname}\"", PaletteID.Clyde); break; case 13: UntilNextFrame = 1000; gameObjects[PelletDemoObjName] = new GameObject(GraphicsConstants.TileSize) { Position = Game.Vector2FromTilePosition(10.5, 23.5) }; graphicsHandler.SetStaticSprite(gameObjects[PelletDemoObjName], GraphicsID.TilePelletSmall, PaletteID.Pellet, Resources.Tiles, GraphicsConstants.TileWidth); tiles.DrawText(23, 12, PelletObject.Worth.ToString()); tiles.DrawPts(23, 15); gameObjects[PowerPelletDemoObjName] = new PowerPelletObject(graphicsHandler) { Position = Game.Vector2FromTilePosition(10.5, 25.5) }; tiles.DrawText(25, 12, PowerPelletObject.Worth.ToString()); tiles.DrawPts(25, 15); break; } }
/// <summary> /// Attempts to open a container on the ground. Returns null if unsuccessful. /// </summary> /// <param name="client">The client to use.</param> /// <param name="tiles">A collection of tiles.</param> /// <param name="loc">The world location of the container.</param> /// <returns></returns> public Container OpenContainer(TileCollection tiles, Location loc) { Tile tile = tiles.GetTile(loc); if (tile == null) return null; TileObject topItem = tile.GetTopUseItem(false); if (topItem == null || !topItem.HasFlag(Enums.ObjectPropertiesFlags.IsContainer)) return null; while (!this.Parent.Player.Location.IsAdjacentTo(loc) && this.Parent.Player.Location != loc) { Thread.Sleep(500); if (this.Parent.Player.IsWalking) continue; var tilesToLocation = this.Parent.Player.Location.GetTilesToLocation(this.Parent, loc, tiles, this.Parent.PathFinder, true, true).ToArray(); if (tilesToLocation.Length == 0) return null; // get closest adjacent tile Tile playerTile = tiles.GetTile(count: this.Parent.Player.ID); if (playerTile == null) break; Tile closestTile = tiles.GetClosestNearbyTile(playerTile, tile); if (closestTile == null) break; this.Parent.Player.GoTo = closestTile.WorldLocation; } if (!this.Parent.Player.Location.IsAdjacentTo(loc) && this.Parent.Player.Location != loc) { return null; } // open container on ground Container closedContainer = this.Parent.Inventory.GetFirstClosedContainer(); if (closedContainer == null) return null; for (int i = 0; i < 3; i++) { topItem.Use(); for (int j = 0; j < 5; j++) { Thread.Sleep(100); if (closedContainer.IsOpen) break; } if (closedContainer.IsOpen) break; } if (!closedContainer.IsOpen) return null; return closedContainer; }
private void ReadRgb() { if (_dataset.RasterCount < 3) { throw new GdalException("RGB Format was indicated but there are only " + _dataset.RasterCount + " bands!"); } _green = _dataset.GetRasterBand(2); _blue = _dataset.GetRasterBand(3); int tw = TileCollection.TileWidth; int th = TileCollection.TileHeight; int ntt = TileCollection.NumTilesTall(); int ntw = TileCollection.NumTilesWide(); ProgressMeter pm = new ProgressMeter(ProgressHandler, "Reading Tiles ", ntt * ntw); for (int row = 0; row < ntt; row++) { for (int col = 0; col < ntw; col++) { int width = TileCollection.GetTileWidth(col); int height = TileCollection.GetTileHeight(row); InRamImageData id = new InRamImageData(width, height); Bitmap image = new Bitmap(width, height, PixelFormat.Format32bppArgb); byte[] red = new byte[width * height]; byte[] g = new byte[width * height]; byte[] b = new byte[width * height]; _red.ReadRaster(col * tw, row * th, width, height, red, width, height, 0, 0); _green.ReadRaster(col * tw, row * th, width, height, g, width, height, 0, 0); _blue.ReadRaster(col * tw, row * th, width, height, b, width, height, 0, 0); BitmapData bData = image.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); Stride = bData.Stride; image.UnlockBits(bData); byte[] vals = new byte[width * height * 4]; int stride = Stride; const int Bpp = 4; for (int r = 0; r < height; r++) { for (int c = 0; c < width; c++) { vals[(r * stride) + (c * Bpp)] = b[(r * width) + c]; vals[(r * stride) + (c * Bpp) + 1] = g[(r * width) + c]; vals[(r * stride) + (c * Bpp) + 2] = red[(r * width) + c]; vals[(r * stride) + (c * Bpp) + 3] = 255; } } id.Values = vals; id.CopyValuesToBitmap(); TileCollection.Tiles[row, col] = id; pm.CurrentValue = (row * ntw) + col; } } pm.Reset(); SetTileBounds(Bounds.AffineCoefficients); }
private static double PercentageObjectsKnown(MapFile mf, VFS vfs, IniFile rules, TheaterSettings ths) { if (rules == null || ths == null) { return(0.0); } var theaterIni = vfs.OpenFile <IniFile>(ths.TheaterIni); if (theaterIni == null) { return(0.0); } Func <MapObject, IniFile.IniSection, bool> objectKnown = (obj, section) => { if (obj is NamedMapObject) { string name = (obj as NamedMapObject).Name; return(section.OrderedEntries.Any(kvp => kvp.Value.ToString().Equals(name, StringComparison.InvariantCultureIgnoreCase))); } else if (obj is NumberedMapObject) { int number = (obj as NumberedMapObject).Number; return(section.HasKey(number.ToString())); } return(false); // should not happen }; int known = 0; int total = 0; var tiles = mf.Tiles.Where(t => t != null).DistinctBy(t => t.TileNum); var tilesCollection = new TileCollection(ths, vfs.OpenFile <IniFile>(ths.TheaterIni)); tilesCollection.InitTilesets(); known += mf.Tiles.Count(o => o.TileNum <= tilesCollection.NumTiles); total += mf.Tiles.Count(); var infs = mf.Infantries.DistinctBy(o => o.Name); known += infs.Count(o => objectKnown(o, rules.GetSection("InfantryTypes"))); total += infs.Count(); var terrains = mf.Infantries.DistinctBy(o => o.Name); known += terrains.Count(o => objectKnown(o, rules.GetSection("TerrainTypes"))); total += terrains.Count(); var units = mf.Infantries.DistinctBy(o => o.Name); known += units.Count(o => objectKnown(o, rules.GetSection("VehicleTypes"))); total += units.Count(); var aircrafts = mf.Aircrafts.DistinctBy(o => o.Name); known += aircrafts.Count(o => objectKnown(o, rules.GetSection("AircraftTypes"))); total += aircrafts.Count(); var smudges = mf.Smudges.DistinctBy(o => o.Name); known += smudges.Count(o => objectKnown(o, rules.GetSection("SmudgeTypes"))); total += smudges.Count(); var structures = mf.Structures.DistinctBy(o => o.Name); known += structures.Count(o => objectKnown(o, rules.GetSection("BuildingTypes")) || objectKnown(o, rules.GetSection("OverlayTypes"))); total += structures.Count(); var overlays = mf.Overlays.DistinctBy(o => o.Number); known += overlays.Count(o => objectKnown(o, rules.GetSection("OverlayTypes"))); total += overlays.Count(); return(known / (double)total); }
public MapManager() { tileIndexer = new TileCollection(this); }
maxRegenTime = 1000 * 60 * 100; // max 100 minutes of regen while sleeping public static void Main(Client client) { // bed food blanks, finished runes // x, y, z // x+ = ->, x- = <- // y+ = \/, y- = /\ List <Bedmage> bedmages = new List <Bedmage>() { new Bedmage(client, 600789, "oldani778", "Darkoz", "adori gran", 70, new Location(32178, 31659, 7), new Location(32177, 31659, 7), new Location(32177, 31658, 7), new Location(32177, 31660, 7)), new Bedmage(client, 600789, "oldani778", "Maloz", "adori gran", 70, new Location(32178, 31658, 7), new Location(32177, 31659, 7), new Location(32177, 31658, 7), new Location(32177, 31660, 7)) }; List <Food> foods = new List <Food>() { new Food() { ItemID = client.ItemList.Food.Ham, RegenerationTime = 360 * 5 * 1000 }, new Food() { ItemID = client.ItemList.Food.Meat, RegenerationTime = 180 * 5 * 1000 }, new Food() { ItemID = client.ItemList.Food.Fish, RegenerationTime = 144 * 5 * 1000 } }; TimeSpan timeOfServerSave = new TimeSpan(4, 0, 0); // 4 AM UTC Random rand = new Random(); while (true) { #region logic if (resetEvent.WaitOne(rand.Next(1000 * 3, 1000 * 7))) { break; } TimeSpan currentTime = DateTime.UtcNow.TimeOfDay; // check if server save is about to happen if (currentTime < timeOfServerSave && (timeOfServerSave - currentTime).TotalMinutes <= 5) { System.IO.File.AppendAllText("bedmagedebug.txt", "waiting for server save\n"); continue; } // check if server save has happened // wait until server save + 30 mins before continuing if (currentTime >= timeOfServerSave && (currentTime - timeOfServerSave).TotalMinutes <= 30) { System.IO.File.AppendAllText("bedmagedebug.txt", "waiting for server save\n"); continue; } long time = Environment.TickCount; foreach (Bedmage bmage in bedmages) { try { // check if one hour has passed // if not, skip this bedmage if (bmage.TimeOfLastLogin != 0 && bmage.TimeOfLastLogin + bmage.TimeNeededToRegen > time) { continue; } // skip if login failed if (!bmage.Login()) { System.IO.File.AppendAllText("bedmagedebug.txt", "login failed\n"); if (client.Player.Connected) { bmage.GoToBed(); } continue; } if (!client.Player.Connected) { System.IO.File.AppendAllText("bedmagedebug.txt", "login failed\n"); continue; } // check if food and rune locations are visible if (!client.Player.Location.IsOnScreen(bmage.FoodLocation) || (!bmage.IsInstantSpell && !client.Player.Location.IsOnScreen(bmage.BlankRuneLocation))) { System.IO.File.AppendAllText("bedmagedebug.txt", "locations offscreen\n"); bmage.GoToBed(); continue; } TileCollection tiles = client.Map.GetTilesOnScreen(); // get tiles and check their validity Tile foodTile = tiles.GetTile(bmage.FoodLocation), runeTile = bmage.IsInstantSpell ? null : tiles.GetTile(bmage.BlankRuneLocation); if (foodTile == null || (!bmage.IsInstantSpell && runeTile == null)) { System.IO.File.AppendAllText("bedmagedebug.txt", "tile null\n"); bmage.GoToBed(); continue; } // get top items and check their validity TileObject topItemFood = foodTile.GetTopUseItem(false), topItemRune = bmage.IsInstantSpell ? null : runeTile.GetTopUseItem(false); if (topItemFood == null || (!bmage.IsInstantSpell && topItemRune == null)) { System.IO.File.AppendAllText("bedmagedebug.txt", "top item null\n"); bmage.GoToBed(); continue; } if (!topItemFood.HasFlag(Enums.ObjectPropertiesFlags.IsPickupable) || (!bmage.IsInstantSpell && !topItemRune.HasFlag(Enums.ObjectPropertiesFlags.IsContainer))) { System.IO.File.AppendAllText("bedmagedebug.txt", "bad flags\n"); bmage.GoToBed(); continue; } // open blank rune container while (client.Player.Connected && client.Player.Mana >= bmage.SpellMana) { Thread.Sleep(1000); if (!client.Player.Connected) { break; } if (bmage.IsInstantSpell) { client.Packets.Say(bmage.SpellName); break; } tiles = client.Map.GetTilesOnScreen(); Container container = bmage.OpenContainer(tiles, bmage.BlankRuneLocation); if (container == null || !container.IsOpen) { bmage.GoToBed(); continue; } var blankRunes = container.GetItems(client.ItemList.Runes.Blank).ToArray(); if (blankRunes.Length > 0) { client.Player.MakeRune(bmage.SpellName, bmage.SpellMana); } // check if there still are blank runes blankRunes = container.GetItems(client.ItemList.Runes.Blank).ToArray(); if (blankRunes.Length > 0) { break; } // no blanks, move container if (!client.Player.Location.IsOnScreen(bmage.FinishedRunesLocation)) { break; } runeTile = tiles.GetTile(bmage.BlankRuneLocation); if (runeTile == null) { break; } topItemRune = runeTile.GetTopMoveItem(); if (topItemRune == null || !topItemRune.HasFlag(Enums.ObjectPropertiesFlags.IsContainer)) { break; } topItemRune.Move(new ItemLocation(bmage.FinishedRunesLocation)); } Food foodEaten = null; // eat food while (client.Player.Connected) { Thread.Sleep(500); if (!client.Player.Connected) { break; } if (client.Window.StatusBar.GetText() == Enums.StatusBar.YouAreFull) { break; } if (!client.Player.Location.IsOnScreen(bmage.FoodLocation)) { break; } // walk to food if we're not there if (client.Player.Location.DistanceTo(bmage.FoodLocation) >= 2) { if (client.Player.IsWalking) { continue; } client.Player.GoTo = bmage.FoodLocation; continue; } foodTile = client.Map.GetTile(bmage.FoodLocation); if (foodTile == null) { break; } topItemFood = foodTile.GetTopUseItem(false); if (topItemFood == null) { break; } bool found = false; foreach (ushort foodID in client.ItemList.Food.All) { if (topItemFood.ID != foodID) { continue; } foreach (Food food in foods) { if (food.ItemID != foodID) { continue; } foodEaten = food; break; } found = true; break; } if (!found) { break; } topItemFood.Use(); } if (!client.Player.Connected) { System.IO.File.AppendAllText("bedmagedebug.txt", "disconnected\n"); continue; } bmage.GoToBed(foodEaten); break; } catch (Exception ex) { DateTime utcNow = DateTime.UtcNow; System.IO.File.AppendAllText("bedmagedebug.txt", "[" + utcNow.Year + "." + utcNow.Month + "." + utcNow.Day + " " + utcNow.Hour + ":" + utcNow.Minute + ":" + utcNow.Second + "]\n" + ex.Message + "\nSource: " + ex.Source + "\n" + ex.StackTrace + "\n\n"); } } #endregion } }