Beispiel #1
0
            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 { }
            }