Ejemplo n.º 1
0
        /// <summary>
        /// Used to confirm the position and PlotIndex are valid together when placing Decor
        /// </summary>
        private bool IsValidPlotForPosition(ClientHousingDecorUpdate.DecorUpdate update)
        {
            if (update.PlotIndex == int.MaxValue)
            {
                return(true);
            }

            WorldSocketEntry worldSocketEntry = GameTableManager.Instance.WorldSocket.GetEntry(residence.GetPlot((byte)update.PlotIndex).PlotEntry.WorldSocketId);

            // TODO: Calculate position based on individual maps on Community & Warplot residences
            Vector3 worldPosition = new Vector3(1472f + update.Position.X, update.Position.Y, 1440f + update.Position.Z);

            (uint gridX, uint gridZ)             = MapGrid.GetGridCoord(worldPosition);
            (uint localCellX, uint localCellZ)   = MapCell.GetCellCoord(worldPosition);
            (uint globalCellX, uint globalCellZ) = (gridX * MapDefines.GridCellCount + localCellX, gridZ *MapDefines.GridCellCount + localCellZ);

            // TODO: Investigate need for offset.
            // Offset added due to calculation being +/- 1 sometimes when placing very close to plots. They were valid placements in the client, though.
            uint maxBound = worldSocketEntry.BoundIds.Max() + 1;
            uint minBound = worldSocketEntry.BoundIds.Min() - 1;

            log.Debug($"IsValidPlotForPosition - PlotIndex: {update.PlotIndex}, Range: {minBound}-{maxBound}, Coords: {globalCellX}, {globalCellZ}");

            return(!(globalCellX >= minBound && globalCellX <= maxBound && globalCellZ >= minBound && globalCellZ <= maxBound));
        }
Ejemplo n.º 2
0
        private void DecorDelete(ClientHousingDecorUpdate.DecorUpdate update)
        {
            Decor decor = residence.GetDecor(update.DecorId);

            if (decor == null)
            {
                throw new InvalidPacketValueException();
            }

            if (decor.Position != Vector3.Zero)
            {
                throw new InvalidOperationException();
            }

            residence.DecorDelete(decor);

            // TODO: send packet to remove from decor list
            var residenceDecor = new ServerHousingResidenceDecor();

            residenceDecor.DecorData.Add(new ServerHousingResidenceDecor.Decor
            {
                RealmId     = WorldServer.RealmId,
                ResidenceId = residence.Id,
                DecorId     = decor.DecorId,
                DecorInfoId = 0
            });

            EnqueueToAll(residenceDecor);
        }
Ejemplo n.º 3
0
        private void DecorMove(ClientHousingDecorUpdate.DecorUpdate update)
        {
            Decor decor = residence.GetDecor(update.DecorId);

            if (decor == null)
            {
                throw new InvalidPacketValueException();
            }

            // TODO: research 0.835f
            if (decor.Type == DecorType.Crate)
            {
                if (decor.Entry.Creature2IdActiveProp != 0u)
                {
                    // TODO: used for decor that have an associated entity
                }

                // crate->world
                var position = new Vector3(update.Position.X, update.Position.Y + 0.835f, update.Position.Z);
                decor.Move(update.DecorType, position, update.Rotation, update.Scale);
            }
            else
            {
                if (update.DecorType == DecorType.Crate)
                {
                    decor.Crate();
                }
                else
                {
                    // world->world
                    var position = new Vector3(update.Position.X, update.Position.Y + 0.835f, update.Position.Z);
                    decor.Move(update.DecorType, position, update.Rotation, update.Scale);
                }
            }

            EnqueueToAll(new ServerHousingResidenceDecor
            {
                Operation = 0,
                DecorData = new List <ServerHousingResidenceDecor.Decor>
                {
                    new ServerHousingResidenceDecor.Decor
                    {
                        RealmId     = WorldServer.RealmId,
                        DecorId     = decor.DecorId,
                        ResidenceId = residence.Id,
                        DecorType   = decor.Type,
                        Scale       = decor.Scale,
                        Position    = decor.Position,
                        Rotation    = decor.Rotation,
                        DecorInfoId = decor.Entry.Id
                    }
                }
            });
        }
Ejemplo n.º 4
0
        private void DecorDelete(ClientHousingDecorUpdate.DecorUpdate update)
        {
            Decor decor = residence.GetDecor(update.DecorId);

            if (decor == null)
            {
                throw new InvalidPacketValueException();
            }

            if (decor.Position != Vector3.Zero)
            {
                throw new InvalidOperationException();
            }

            residence.DecorDelete(decor);

            // TODO: send packet to remove from decor list
        }
Ejemplo n.º 5
0
        private void DecorCreate(Player player, ClientHousingDecorUpdate.DecorUpdate update)
        {
            HousingDecorInfoEntry entry = GameTableManager.HousingDecorInfo.GetEntry(update.DecorInfoId);

            if (entry == null)
            {
                throw new InvalidPacketValueException();
            }

            if (entry.CostCurrencyTypeId != 0u && entry.Cost != 0u)
            {
                /*if (!player.CurrencyManager.CanAfford((byte)entry.CostCurrencyTypeId, entry.Cost))
                 * {
                 *  // TODO: show error
                 *  return;
                 * }
                 *
                 * player.CurrencyManager.CurrencySubtractAmount((byte)entry.CostCurrencyTypeId, entry.Cost);*/
            }

            Decor decor = residence.DecorCreate(entry);

            decor.Type = update.DecorType;

            if (update.ColourShiftId != decor.ColourShiftId)
            {
                if (update.ColourShiftId != 0u)
                {
                    ColorShiftEntry colourEntry = GameTableManager.ColorShift.GetEntry(update.ColourShiftId);
                    if (colourEntry == null)
                    {
                        throw new InvalidPacketValueException();
                    }
                }
                decor.ColourShiftId = update.ColourShiftId;
            }

            if (update.DecorType != DecorType.Crate)
            {
                if (update.Scale < 0f)
                {
                    throw new InvalidPacketValueException();
                }

                // new decor is being placed directly in the world
                decor.Position = update.Position;
                decor.Rotation = update.Rotation;
                decor.Scale    = update.Scale;
            }

            EnqueueToAll(new ServerHousingResidenceDecor
            {
                Operation = 0,
                DecorData = new List <ServerHousingResidenceDecor.Decor>
                {
                    new ServerHousingResidenceDecor.Decor
                    {
                        RealmId     = WorldServer.RealmId,
                        DecorId     = decor.DecorId,
                        ResidenceId = residence.Id,
                        DecorType   = decor.Type,
                        Scale       = decor.Scale,
                        Position    = decor.Position,
                        Rotation    = decor.Rotation,
                        DecorInfoId = decor.Entry.Id,
                        ColourShift = decor.ColourShiftId
                    }
                }
            });
        }
Ejemplo n.º 6
0
        private void DecorMove(Player player, ClientHousingDecorUpdate.DecorUpdate update)
        {
            Decor decor = residence.GetDecor(update.DecorId);

            if (decor == null)
            {
                throw new InvalidPacketValueException();
            }

            HousingResult GetResult()
            {
                if (!IsValidPlotForPosition(update))
                {
                    return(HousingResult.Decor_InvalidPosition);
                }

                return(HousingResult.Success);
            }

            HousingResult result = GetResult();

            if (result == HousingResult.Success)
            {
                if (update.PlotIndex != decor.PlotIndex)
                {
                    decor.PlotIndex = update.PlotIndex;
                }

                if (update.ColourShiftId != decor.ColourShiftId)
                {
                    if (update.ColourShiftId != 0u)
                    {
                        ColorShiftEntry colourEntry = GameTableManager.Instance.ColorShift.GetEntry(update.ColourShiftId);
                        if (colourEntry == null)
                        {
                            throw new InvalidPacketValueException();
                        }
                    }

                    decor.ColourShiftId = update.ColourShiftId;
                }

                if (decor.Type == DecorType.Crate)
                {
                    if (decor.Entry.Creature2IdActiveProp != 0u)
                    {
                        // TODO: used for decor that have an associated entity
                    }

                    // crate->world
                    decor.Move(update.DecorType, update.Position, update.Rotation, update.Scale);
                }
                else
                {
                    if (update.DecorType == DecorType.Crate)
                    {
                        decor.Crate();
                    }
                    else
                    {
                        // world->world
                        decor.Move(update.DecorType, update.Position, update.Rotation, update.Scale);
                        decor.DecorParentId = update.ParentDecorId;
                    }
                }
            }
            else
            {
                player.Session.EnqueueMessageEncrypted(new ServerHousingResult
                {
                    RealmId     = WorldServer.RealmId,
                    ResidenceId = residence.Id,
                    PlayerName  = player.Name,
                    Result      = result
                });
            }

            EnqueueToAll(new ServerHousingResidenceDecor
            {
                Operation = 0,
                DecorData = new List <ServerHousingResidenceDecor.Decor>
                {
                    new ServerHousingResidenceDecor.Decor
                    {
                        RealmId       = WorldServer.RealmId,
                        DecorId       = decor.DecorId,
                        ResidenceId   = residence.Id,
                        DecorType     = decor.Type,
                        PlotIndex     = decor.PlotIndex,
                        Scale         = decor.Scale,
                        Position      = decor.Position,
                        Rotation      = decor.Rotation,
                        DecorInfoId   = decor.Entry.Id,
                        ParentDecorId = decor.DecorParentId,
                        ColourShift   = decor.ColourShiftId
                    }
                }
            });
        }