Esempio n. 1
0
        public static void Packet_PlaceFurniture(int index, ref byte[] data)
        {
            ByteStream buffer  = new ByteStream(data);
            int        x       = buffer.ReadInt32();
            int        y       = buffer.ReadInt32();
            int        invslot = buffer.ReadInt32();

            buffer.Dispose();
            int ItemNum = modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].Inv[invslot].Num;

            checked
            {
                if (!(ItemNum < 1 || ItemNum > 500))
                {
                    if (modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].InHouse == index)
                    {
                        if (Types.Item[ItemNum].Type == 6)
                        {
                            int i = 1;
                            for (; ;)
                            {
                                if (S_Players.GetPlayerRawStat(index, (Enums.StatType)i) < (int)Types.Item[ItemNum].Stat_Req[i])
                                {
                                    break;
                                }
                                i++;
                                if (i > 6)
                                {
                                    goto Block_6;
                                }
                            }
                            S_NetworkSend.PlayerMsg(index, "You do not meet the stat requirements to use this item.", 12);
                            return;

Block_6:
                            if (S_Players.GetPlayerLevel(index) < Types.Item[ItemNum].LevelReq)
                            {
                                S_NetworkSend.PlayerMsg(index, "You do not meet the level requirement to use this item.", 12);
                            }
                            else
                            {
                                if (Types.Item[ItemNum].ClassReq > 0)
                                {
                                    if (S_Players.GetPlayerClass(index) != Types.Item[ItemNum].ClassReq)
                                    {
                                        S_NetworkSend.PlayerMsg(index, "You do not meet the class requirement to use this item.", 12);
                                        return;
                                    }
                                }
                                if (S_Players.GetPlayerAccess(index) < Types.Item[ItemNum].AccessReq)
                                {
                                    S_NetworkSend.PlayerMsg(index, "You do not meet the access requirement to use this item.", 12);
                                }
                                else
                                {
                                    if (modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].InHouse != index)
                                    {
                                        S_NetworkSend.PlayerMsg(index, "You must be inside your house to place furniture!", 14);
                                    }
                                    else
                                    {
                                        if (modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.FurnitureCount >= S_Housing.HouseConfig[modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Houseindex].MaxFurniture)
                                        {
                                            if (S_Housing.HouseConfig[modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Houseindex].MaxFurniture > 0)
                                            {
                                                S_NetworkSend.PlayerMsg(index, "Your house cannot hold any more furniture!", 12);
                                                return;
                                            }
                                        }
                                        if (!(x < 0 || x > (int)modTypes.Map[S_Players.GetPlayerMap(index)].MaxX))
                                        {
                                            if (!(y < 0 || y > (int)modTypes.Map[S_Players.GetPlayerMap(index)].MaxY))
                                            {
                                                int x2;
                                                int widthoffset;
                                                if (Types.Item[ItemNum].FurnitureWidth > 2)
                                                {
                                                    x2          = (int)Math.Round(unchecked ((double)x + (double)Types.Item[ItemNum].FurnitureWidth / 2.0));
                                                    widthoffset = x2 - x;
                                                    x2         -= Types.Item[ItemNum].FurnitureWidth - widthoffset;
                                                }
                                                x2          = x;
                                                widthoffset = 0;
                                                int y2 = y;
                                                if (widthoffset > 0)
                                                {
                                                    int num  = x2;
                                                    int num2 = x2 + widthoffset;
                                                    for (x = num; x <= num2; x++)
                                                    {
                                                        int num3 = y2;
                                                        int num4 = y2 - Types.Item[ItemNum].FurnitureHeight + 1;
                                                        for (y = num3; y >= num4; y += -1)
                                                        {
                                                            if (modTypes.Map[S_Players.GetPlayerMap(index)].Tile[x, y].Type == 1)
                                                            {
                                                                return;
                                                            }
                                                            int playersOnline = S_GameLogic.GetPlayersOnline();
                                                            for (i = 1; i <= playersOnline; i++)
                                                            {
                                                                if (S_NetworkConfig.IsPlaying(i) && i != index && S_Players.GetPlayerMap(i) == S_Players.GetPlayerMap(index))
                                                                {
                                                                    if (modTypes.Player[i].Character[(int)modTypes.TempPlayer[i].CurChar].InHouse == modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].InHouse)
                                                                    {
                                                                        if ((int)modTypes.Player[i].Character[(int)modTypes.TempPlayer[i].CurChar].X == x && (int)modTypes.Player[i].Character[(int)modTypes.TempPlayer[i].CurChar].Y == y)
                                                                        {
                                                                            return;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                            if (modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.FurnitureCount > 0)
                                                            {
                                                                int furnitureCount = modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.FurnitureCount;
                                                                for (i = 1; i <= furnitureCount; i++)
                                                                {
                                                                    if (x >= modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[i].X && x <= modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[i].X + Types.Item[modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[i].ItemNum].FurnitureWidth - 1)
                                                                    {
                                                                        if (y <= modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[i].Y && y >= modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[i].Y - Types.Item[modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[i].ItemNum].FurnitureHeight + 1)
                                                                        {
                                                                            return;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                    int num5 = x2;
                                                    int num6 = x2 - (Types.Item[ItemNum].FurnitureWidth - widthoffset);
                                                    for (x = num5; x >= num6; x += -1)
                                                    {
                                                        int num7 = y2;
                                                        int num8 = y2 - Types.Item[ItemNum].FurnitureHeight + 1;
                                                        for (y = num7; y >= num8; y += -1)
                                                        {
                                                            if (modTypes.Map[S_Players.GetPlayerMap(index)].Tile[x, y].Type == 1)
                                                            {
                                                                return;
                                                            }
                                                            int playersOnline2 = S_GameLogic.GetPlayersOnline();
                                                            for (i = 1; i <= playersOnline2; i++)
                                                            {
                                                                if (S_NetworkConfig.IsPlaying(i) && i != index && S_Players.GetPlayerMap(i) == S_Players.GetPlayerMap(index))
                                                                {
                                                                    if (modTypes.Player[i].Character[(int)modTypes.TempPlayer[i].CurChar].InHouse == modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].InHouse)
                                                                    {
                                                                        if ((int)modTypes.Player[i].Character[(int)modTypes.TempPlayer[i].CurChar].X == x && (int)modTypes.Player[i].Character[(int)modTypes.TempPlayer[i].CurChar].Y == y)
                                                                        {
                                                                            return;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                            if (modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.FurnitureCount > 0)
                                                            {
                                                                int furnitureCount2 = modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.FurnitureCount;
                                                                for (i = 1; i <= furnitureCount2; i++)
                                                                {
                                                                    if (x >= modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[i].X && x <= modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[i].X + Types.Item[modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[i].ItemNum].FurnitureWidth - 1)
                                                                    {
                                                                        if (y <= modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[i].Y && y >= modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[i].Y - Types.Item[modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[i].ItemNum].FurnitureHeight + 1)
                                                                        {
                                                                            return;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    int num9  = x2;
                                                    int num10 = x2 + Types.Item[ItemNum].FurnitureWidth - 1;
                                                    for (x = num9; x <= num10; x++)
                                                    {
                                                        int num11 = y2;
                                                        int num12 = y2 - Types.Item[ItemNum].FurnitureHeight + 1;
                                                        for (y = num11; y >= num12; y += -1)
                                                        {
                                                            if (modTypes.Map[S_Players.GetPlayerMap(index)].Tile[x, y].Type == 1)
                                                            {
                                                                return;
                                                            }
                                                            int playersOnline3 = S_GameLogic.GetPlayersOnline();
                                                            for (i = 1; i <= playersOnline3; i++)
                                                            {
                                                                if (S_NetworkConfig.IsPlaying(i) && i != index && S_Players.GetPlayerMap(i) == S_Players.GetPlayerMap(index))
                                                                {
                                                                    if (modTypes.Player[i].Character[(int)modTypes.TempPlayer[i].CurChar].InHouse == modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].InHouse)
                                                                    {
                                                                        if ((int)modTypes.Player[i].Character[(int)modTypes.TempPlayer[i].CurChar].X == x && (int)modTypes.Player[i].Character[(int)modTypes.TempPlayer[i].CurChar].Y == y)
                                                                        {
                                                                            return;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                            if (modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.FurnitureCount > 0)
                                                            {
                                                                int furnitureCount3 = modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.FurnitureCount;
                                                                for (i = 1; i <= furnitureCount3; i++)
                                                                {
                                                                    if (x >= modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[i].X && x <= modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[i].X + Types.Item[modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[i].ItemNum].FurnitureWidth - 1)
                                                                    {
                                                                        if (y <= modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[i].Y && y >= modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[i].Y - Types.Item[modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[i].ItemNum].FurnitureHeight + 1)
                                                                        {
                                                                            return;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                x = x2;
                                                y = y2;
                                                modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.FurnitureCount = modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.FurnitureCount + 1;
                                                modTypes.CharacterRec[] character = modTypes.Player[index].Character;
                                                byte curChar = modTypes.TempPlayer[index].CurChar;
                                                character[(int)curChar].House.Furniture = (S_Housing.FurnitureRec[])Utils.CopyArray(character[(int)curChar].House.Furniture, new S_Housing.FurnitureRec[modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.FurnitureCount + 1]);
                                                modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.FurnitureCount].ItemNum = ItemNum;
                                                modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.FurnitureCount].X       = x;
                                                modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.Furniture[modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].House.FurnitureCount].Y       = y;
                                                S_Players.TakeInvItem(index, ItemNum, 0);
                                                S_Housing.SendFurnitureToHouse(modTypes.Player[index].Character[(int)modTypes.TempPlayer[index].CurChar].InHouse);
                                                modDatabase.SavePlayer(index);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        S_NetworkSend.PlayerMsg(index, "You cannot place furniture unless you are in your own house!", 12);
                    }
                }
            }
        }