/// <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)); }
/// <summary> /// Add <see cref="EntityModel"/> to be spawned when parent <see cref="MapGrid"/> is activated. /// </summary> public void AddEntity(EntityModel model) { var vector = new Vector3(model.X, model.Y, model.Z); (uint gridX, uint gridZ) = MapGrid.GetGridCoord(vector); ushort hash = GetGridHash(gridX, gridZ); if (!entities.ContainsKey(hash)) { entities.Add(hash, new HashSet <EntityModel>()); } entities[hash].Add(model); }
/// <summary> /// Activate one or more <see cref="MapGrid"/>'s at <see cref="Vector"/> depending on vision range of <see cref="GridEntity"/>. /// </summary> private void ActivateGrid(GridEntity entity, Vector3 vector) { float range = entity.ActivationRange; for (float z = vector.Z - range; z < vector.Z + range + MapDefines.GridSize; z += MapDefines.GridSize) { for (float x = vector.X - range; x < vector.X + range + MapDefines.GridSize; x += MapDefines.GridSize) { (uint gridX, uint gridZ) = MapGrid.GetGridCoord(new Vector3(x, 0f, z)); MapGrid grid = GetGrid(gridX, gridZ); if (grid == null) { ActivateGrid(gridX, gridZ); } } } }
private MapGrid GetGrid(Vector3 vector) { (uint gridX, uint gridZ) = MapGrid.GetGridCoord(vector); return(GetGrid(gridX, gridZ)); }