public void AppendAddItem(Item item, Position position) { lock (lockThis) { gameMap.AddThing(item, position); byte stackpos = gameMap.GetStackPosition(item, position); ThingSet tSet = gameMap.GetThingsInVicinity(position); foreach (Thing thing in tSet.GetThings()) { thing.AddItem(item, position, stackpos); } } }
public Map LoadMap(string mapPath) { // try { BinaryReader bReader = new BinaryReader(File.Open(mapPath, FileMode.Open)); int sizex = bReader.ReadUInt16(); //Height int sizey = bReader.ReadUInt16(); //Width Map map = new Map(sizex, sizey); uint tileCount = bReader.ReadUInt32(); //Tile Count for (int i = 0; i < tileCount; i++) { ushort x = bReader.ReadUInt16(); //X position ushort y = bReader.ReadUInt16(); //Y position byte z = bReader.ReadByte(); //Z position ushort id = bReader.ReadUInt16(); //Tile ID map.SetTile(x, y, z, new Tile(Item.CreateItem(id))); byte itemCount = bReader.ReadByte(); for (int j = 0; j < itemCount; j++) { ushort itemID = bReader.ReadUInt16(); Item item = Item.CreateItem(itemID); map.AddThing(item, new Position(x, y, z)); } } bReader.Close(); //TODO: Remove this code map.SetTile(320, 320, 6, new Tile(Item.CreateItem("Grass"))); return(map); //} catch (Exception e) { // lastError = e.ToString(); // return null; //} }
public Map LoadMap(string mapPath) { // try { BinaryReader bReader = new BinaryReader(File.Open(mapPath, FileMode.Open)); int sizex = bReader.ReadUInt16(); //Height int sizey = bReader.ReadUInt16(); //Width Map map = new Map(sizex, sizey); uint tileCount = bReader.ReadUInt32(); //Tile Count for (int i = 0; i < tileCount; i++) { ushort x = bReader.ReadUInt16(); //X position ushort y = bReader.ReadUInt16(); //Y position byte z = bReader.ReadByte(); //Z position ushort id = bReader.ReadUInt16(); //Tile ID map.SetTile(x, y, z, new Tile(Item.CreateItem(id))); byte itemCount = bReader.ReadByte(); for (int j = 0; j < itemCount; j++) { ushort itemID = bReader.ReadUInt16(); Item item = Item.CreateItem(itemID); map.AddThing(item, new Position(x, y, z)); } } bReader.Close(); //TODO: Remove this code map.SetTile(320, 320, 6, new Tile(Item.CreateItem("Grass"))); return map; //} catch (Exception e) { // lastError = e.ToString(); // return null; //} }
/// <summary> /// Move the specified thing to the ground. /// </summary> /// <param name="thingToMove">Thing to move.</param> /// <param name="posTo">Position to move to.</param> /// <param name="thingsPrepared">A reference to the things /// already prepared.</param> private void MoveToGround() { Thing topThing = map.GetTopThing(posTo); Item topItem = null; if (topThing.IsOfType(Constants.TYPE_STACKABLE)) { topItem = (Item)topThing; } bool stackable = false; bool addItem = true; if (topItem != null && itemToMove != null && topItem.ItemID == itemToMove.ItemID) //Both stackable items of same type { stackable = true; if (topItem.Count + itemToMove.Count > MAX_STACK_COUNT) { byte countRemainder = (byte)(MAX_STACK_COUNT - topItem.Count); topItem.Count += countRemainder; itemToMove.Count -= countRemainder; } else { topItem.Count += itemToMove.Count; addItem = false; } } ThingSet tSet = map.GetThingsInVicinity(posTo); byte stackpos = map.GetStackPosition(itemToMove, posTo); if (stackable) { foreach (Thing thing in tSet.GetThings()) { thing.UpdateItem(posTo, topItem, map.GetStackPosition(topItem, posTo)); } } if (addItem) { map.AddThing(itemToMove, posTo); foreach (Thing thing in tSet.GetThings()) { thing.AddThingToGround(itemToMove, posTo, map.GetStackPosition(itemToMove, posTo)); } } }