internal void relocateItem(int itemID, int X, int Y, byte Z) { try { floorItem Item = (floorItem)_Items[itemID]; catalogueManager.itemTemplate Template = catalogueManager.getTemplate(Item.templateID); int Length = 0; int Width = 0; if (Z == 2 || Z == 6) { Length = Template.Length; Width = Template.Width; } else { Length = Template.Width; Width = Template.Length; } double baseFloorH = _Room.sqFLOORHEIGHT[X, Y]; double H = baseFloorH; if (_Room.sqSTACK[X, Y] != null) { floorItem topItem = (floorItem)_Items[_Room.sqSTACK[X, Y].topItemID()]; if (topItem != Item) { catalogueManager.itemTemplate topTemplate = catalogueManager.getTemplate(topItem.templateID); if (topTemplate.typeID == 1) H = topItem.H + topTemplate.topH; } else if (_Room.sqSTACK[X, Y].Count > 1) H = topItem.H; } for (int jX = X; jX < X + Width; jX++) { for (int jY = Y; jY < Y + Length; jY++) { if (Template.typeID != 2 && _Room.sqUNIT[jX, jY]) return; squareState jState = _Room.sqSTATE[jX, jY]; furnitureStack Stack = _Room.sqSTACK[jX, jY]; if (jState != squareState.Open) { if (Stack == null) { if (jX != Item.X || jY != Item.Y) return; } else { floorItem topItem = (floorItem)_Items[Stack.topItemID()]; if (topItem != Item) { catalogueManager.itemTemplate topItemTemplate = catalogueManager.getTemplate(topItem.templateID); if (topItemTemplate.typeID == 1 && topItemTemplate.topH > 0) { if (topItem.H + topItemTemplate.topH > H) H = topItem.H + topItemTemplate.topH; } else { if (topItemTemplate.typeID == 2) return; } //return; } } } } } int oldLength = 1; int oldWidth = 1; if (Template.Length > 1 || Template.Width > 1) { if (Item.Z == 2 || Item.Z == 6) { oldLength = Template.Length; oldWidth = Template.Width; } else { oldLength = Template.Width; oldWidth = Template.Length; } } if (H > Config.Items_Stacking_maxHeight) H = Config.Items_Stacking_maxHeight; for (int jX = Item.X; jX < Item.X + oldWidth; jX++) { for (int jY = Item.Y; jY < Item.Y + oldLength; jY++) { furnitureStack Stack = _Room.sqSTACK[jX, jY]; if (Stack != null && Stack.Count > 1) { if (itemID == Stack.bottomItemID()) { if (catalogueManager.getTemplate(((floorItem)_Items[Stack.topItemID()]).templateID).typeID == 2) _Room.sqSTATE[jX, jY] = squareState.Seat; else _Room.sqSTATE[jX, jY] = squareState.Open; } else if (itemID == Stack.topItemID()) { floorItem belowItem = (floorItem)_Items[Stack.getBelowItemID(itemID)]; byte typeID = catalogueManager.getTemplate(belowItem.templateID).typeID; _Room.sqSTATE[jX, jY] = (squareState)typeID; if (typeID == 2 || typeID == 3) { _Room.sqITEMROT[jX, jY] = belowItem.Z; _Room.sqITEMHEIGHT[jX, jY] = belowItem.H + catalogueManager.getTemplate(belowItem.templateID).topH; if (Template.typeID == 3 && (jX != X || jY != Y)) if (Width == 1) _Room.sqSTATE[jX, jY] = squareState.Blocked; else if ((Z == 2 && jX != X) || (Z == 0 && jY != Y)) _Room.sqSTATE[jX, jY] = squareState.Blocked; } else if (typeID == 4) _Room.sqITEMHEIGHT[jX, jY] = belowItem.H; } Stack.Remove(itemID); _Room.sqSTACK[jX, jY] = Stack; } else { _Room.sqSTATE[jX, jY] = 0; _Room.sqITEMHEIGHT[jX, jY] = 0; _Room.sqITEMROT[jX, jY] = 0; _Room.sqSTACK[jX, jY] = null; } if (Template.typeID == 2 || Template.typeID == 3) _Room.refreshCoord(jX, jY); } } Item.X = X; Item.Y = Y; Item.Z = Z; Item.H = H; _Room.sendData("A_" + Item.ToString()); using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient()) { dbClient.runQuery("UPDATE furniture SET x = '" + X + "',y = '" + Y + "',z = '" + Z + "',h = '" + H.ToString().Replace(',', '.') + "' WHERE id = '" + itemID + "' LIMIT 1"); } for (int jX = X; jX < X + Width; jX++) { for (int jY = Y; jY < Y + Length; jY++) { furnitureStack Stack = null; if (_Room.sqSTACK[jX, jY] == null) { if (Template.topH > 0 && Template.typeID != 2 && Template.typeID != 3 && Template.typeID != 4) { Stack = new furnitureStack(); Stack.Add(itemID); } } else { Stack = _Room.sqSTACK[jX, jY]; Stack.Add(itemID); } _Room.sqSTATE[jX, jY] = (squareState)Template.typeID; _Room.sqSTACK[jX, jY] = Stack; if (Template.typeID == 2 || Template.typeID == 3) { _Room.sqITEMHEIGHT[jX, jY] = H + Template.topH; _Room.sqITEMROT[jX, jY] = Z; _Room.refreshCoord(jX, jY); } else if (Template.typeID == 4) _Room.sqITEMHEIGHT[jX, jY] = H; } } } catch { } }
/// <summary> /// Adds a new virtual flooritem to the manager at initialization. /// </summary> /// <param name="itemID">The ID of the new item.</param> /// <param name="templateID">The template ID of the new item.</param> /// <param name="X">The X position of the new item.</param> /// <param name="Y">The Y position of the new item.</param> /// <param name="Z">The Z [rotation] of the new item.</param> /// <param name="H">The H position [height] of the new item.</param> /// <param name="Var">The variable of the new item.</param> internal void addItem(int itemID, int templateID, int X, int Y, int Z, double H, string Var) { try { catalogueManager.itemTemplate Template = catalogueManager.getTemplate(templateID); if (stringManager.getStringPart(Template.Sprite, 0, 13) == "sound_machine") soundMachineID = itemID; int Length = 0; int Width = 0; if (Z == 2 || Z == 6) { Length = Template.Length; Width = Template.Width; } else { Length = Template.Width; Width = Template.Length; } for (int jX = X; jX < X + Width; jX++) for (int jY = Y; jY < Y + Length; jY++) { furnitureStack Stack = _Room.sqSTACK[jX, jY]; if (Stack == null) { if (Template.typeID != 2 && Template.typeID != 3) { Stack = new furnitureStack(); Stack.Add(itemID); } } else Stack.Add(itemID); _Room.sqSTATE[jX, jY] = (squareState)Template.typeID; if (Template.typeID == 2 || Template.typeID == 3) { _Room.sqITEMHEIGHT[jX, jY] = H + Template.topH; _Room.sqITEMROT[jX, jY] = Convert.ToByte(Z); } else { if (Template.typeID == 4) _Room.sqITEMHEIGHT[jX, jY] = H; } _Room.sqSTACK[jX, jY] = Stack; } if (Template.isDoor) { if (_Room.squareBlocked(X, Y, Length, Width)) return; if (Var.ToLower() == "c") _Room.setSquareState(X, Y, Length, Width, squareState.Blocked); else if (Var.ToLower() == "o") _Room.setSquareState(X, Y, Length, Width, squareState.Open); else _Room.setSquareState(X, Y, Length, Width, squareState.Blocked); } floorItem Item = new floorItem(itemID, templateID, X, Y, Z, H, Var); _Items.Add(itemID, Item); } catch (Exception ex) { Out.WriteError("[" + ex.Source + "] Exception Error - " + ex.Message); } }
internal void placeItem(int itemID, int templateID, int X, int Y, byte typeID, byte Z) { if (_Items.ContainsKey(itemID)) return; try { catalogueManager.itemTemplate Template = catalogueManager.getTemplate(templateID); bool isSoundMachine = (stringManager.getStringPart(Template.Sprite, 0, 13) == "sound_machine"); if (isSoundMachine && soundMachineID > 0) return; int Length = 0; int Width = 0; if (Z == 2 || Z == 6) { Length = Template.Length; Width = Template.Width; } else { Length = Template.Width; Width = Template.Length; } double testH = _Room.sqFLOORHEIGHT[X, Y]; double H = testH; if (_Room.sqSTACK[X, Y] != null) { floorItem topItem = (floorItem)_Items[_Room.sqSTACK[X, Y].topItemID()]; H = topItem.H + catalogueManager.getTemplate(topItem.templateID).topH; } for (int jX = X; jX < X + Width; jX++) { for (int jY = Y; jY < Y + Length; jY++) { if (_Room.sqUNIT[jX, jY]) // Dynamical unit here return; squareState jState = _Room.sqSTATE[jX, jY]; if (jState != squareState.Open) { if (jState == squareState.Blocked) { if (_Room.sqSTACK[jX, jY] == null) // Square blocked and no stack here return; else { floorItem topItem = (floorItem)_Items[_Room.sqSTACK[jX, jY].topItemID()]; catalogueManager.itemTemplate topItemTemplate = catalogueManager.getTemplate(topItem.templateID); if (topItemTemplate.topH == 0 || topItemTemplate.typeID == 2 || topItemTemplate.typeID == 3) // No stacking on seat/bed return; else { if (topItem.H + topItemTemplate.topH > H) // Higher than previous topheight H = topItem.H + topItemTemplate.topH; } } } else if (jState == squareState.Rug && _Room.sqSTACK[jX, jY] != null) { double jH = ((floorItem)_Items[_Room.sqSTACK[jX, jY].topItemID()]).H + 0.1; if (jH > H) H = jH; } else // Seat etc return; } } } if (H > Config.Items_Stacking_maxHeight) H = Config.Items_Stacking_maxHeight; for (int jX = X; jX < X + Width; jX++) { for (int jY = Y; jY < Y + Length; jY++) { furnitureStack Stack = null; if (_Room.sqSTACK[jX, jY] == null) { if ((Template.typeID == 1 && Template.topH > 0) || Template.typeID == 4) { Stack = new furnitureStack(); Stack.Add(itemID); } } else { Stack = _Room.sqSTACK[jX, jY]; Stack.Add(itemID); } _Room.sqSTATE[jX, jY] = (squareState)Template.typeID; _Room.sqSTACK[jX, jY] = Stack; if (Template.typeID == 2 || Template.typeID == 3) { _Room.sqITEMHEIGHT[jX, jY] = H + Template.topH; _Room.sqITEMROT[jX, jY] = Z; _Room.sqITEMROT[jX, jY] = Z; if (Template.typeID == 3 && (jX != X || jY != Y)) if (Width == 1) _Room.sqSTATE[jX, jY] = squareState.Blocked; else if ((Z == 2 && jX != X) || (Z == 0 && jY != Y)) _Room.sqSTATE[jX, jY] = squareState.Blocked; } else if (Template.typeID == 4) _Room.sqITEMHEIGHT[jX, jY] = H; } } string Var; using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient()) { Var = dbClient.getString("SELECT var FROM furniture WHERE id = '" + itemID + "'"); dbClient.runQuery("UPDATE furniture SET roomid = '" + _Room.roomID + "',x = '" + X + "',y = '" + Y + "',z = '" + Z + "',h = '" + H.ToString().Replace(',', '.') + "' WHERE id = '" + itemID + "' LIMIT 1"); } floorItem Item = new floorItem(itemID, templateID, X, Y, Z, H, Var); _Items.Add(itemID, Item); _Room.sendData("A]" + Item.ToString()); if (isSoundMachine) this.soundMachineID = itemID; } catch { } }
/// <summary> /// Adds a new virtual flooritem to the manager at initialization. /// </summary> /// <param name="itemID">The ID of the new item.</param> /// <param name="templateID">The template ID of the new item.</param> /// <param name="X">The X position of the new item.</param> /// <param name="Y">The Y position of the new item.</param> /// <param name="Z">The Z [rotation] of the new item.</param> /// <param name="H">The H position [height] of the new item.</param> /// <param name="Var">The variable of the new item.</param> internal void addItem(int itemID, int templateID, int X, int Y, int Z, double H, string Var) { catalogueManager.itemTemplate Template = catalogueManager.getTemplate(templateID); if (stringManager.getStringPart(Template.Sprite, 0, 13) == "sound_machine") soundMachineID = itemID; int Length = 0; int Width = 0; if (Z == 2 || Z == 6) { Length = Template.Length; Width = Template.Width; } else { Length = Template.Width; Width = Template.Length; } for (int jX = X; jX < X + Width; jX++) for (int jY = Y; jY < Y + Length; jY++) { furnitureStack Stack = _Room.sqSTACK[jX,jY]; if (Stack == null) { if (Template.typeID != 2 && Template.typeID != 3) { Stack = new furnitureStack(); Stack.Add(itemID); } } else Stack.Add(itemID); _Room.sqSTATE[jX, jY] = (squareState)Template.typeID; if (Template.typeID == 2 || Template.typeID == 3) { _Room.sqITEMHEIGHT[jX, jY] = H + Template.topH; _Room.sqITEMROT[jX, jY] = Convert.ToByte(Z); } else { if (Template.typeID == 4) _Room.sqITEMHEIGHT[jX, jY] = H; } _Room.sqSTACK[jX, jY] = Stack; } floorItem Item = new floorItem(itemID, templateID, X, Y, Z, H, Var); _Items.Add(itemID, Item); }