GarrisonError CheckBuildingPlacement(uint garrPlotInstanceId, uint garrBuildingId) { GarrPlotInstanceRecord plotInstance = CliDB.GarrPlotInstanceStorage.LookupByKey(garrPlotInstanceId); Plot plot = GetPlot(garrPlotInstanceId); if (plotInstance == null || plot == null) { return(GarrisonError.InvalidPlotInstanceId); } GarrBuildingRecord building = CliDB.GarrBuildingStorage.LookupByKey(garrBuildingId); if (building == null) { return(GarrisonError.InvalidBuildingId); } if (!Global.GarrisonMgr.IsPlotMatchingBuilding(plotInstance.GarrPlotID, garrBuildingId)) { return(GarrisonError.InvalidPlotBuilding); } // Cannot place buldings of higher level than garrison level if (building.Level > _siteLevel.Level) { return(GarrisonError.InvalidBuildingId); } if (building.Flags.HasAnyFlag(GarrisonBuildingFlags.NeedsPlan)) { if (!_knownBuildings.Contains(garrBuildingId)) { return(GarrisonError.RequiresBlueprint); } } else // Building is built as a quest reward { return(GarrisonError.InvalidBuildingId); } // Check all plots to find if we already have this building GarrBuildingRecord existingBuilding; foreach (var p in _plots) { if (p.Value.BuildingInfo.PacketInfo.HasValue) { existingBuilding = CliDB.GarrBuildingStorage.LookupByKey(p.Value.BuildingInfo.PacketInfo.Value.GarrBuildingID); if (existingBuilding.Type == building.Type) { if (p.Key != garrPlotInstanceId || existingBuilding.Level + 1 != building.Level) // check if its an upgrade in same plot { return(GarrisonError.BuildingExists); } } } } if (!_owner.HasCurrency(building.CostCurrencyID, (uint)building.CostCurrencyAmount)) { return(GarrisonError.NotEnoughCurrency); } if (!_owner.HasEnoughMoney(building.CostMoney * MoneyConstants.Gold)) { return(GarrisonError.NotEnoughGold); } // New building cannot replace another building currently under construction if (plot.BuildingInfo.PacketInfo.HasValue) { if (!plot.BuildingInfo.PacketInfo.Value.Active) { return(GarrisonError.NoBuilding); } } return(GarrisonError.Success); }
public GameObject CreateGameObject(Map map, uint faction) { uint entry = EmptyGameObjectId; if (BuildingInfo.PacketInfo.HasValue) { GarrPlotInstanceRecord plotInstance = CliDB.GarrPlotInstanceStorage.LookupByKey(PacketInfo.GarrPlotInstanceID); GarrPlotRecord plot = CliDB.GarrPlotStorage.LookupByKey(plotInstance.GarrPlotID); GarrBuildingRecord building = CliDB.GarrBuildingStorage.LookupByKey(BuildingInfo.PacketInfo.Value.GarrBuildingID); entry = faction == GarrisonFactionIndex.Horde ? plot.HordeConstructObjID : plot.AllianceConstructObjID; if (BuildingInfo.PacketInfo.Value.Active || entry == 0) { entry = faction == GarrisonFactionIndex.Horde ? building.HordeGameObjectID : building.AllianceGameObjectID; } } if (Global.ObjectMgr.GetGameObjectTemplate(entry) == null) { Log.outError(LogFilter.Garrison, "Garrison attempted to spawn gameobject whose template doesn't exist ({0})", entry); return(null); } GameObject go = GameObject.CreateGameObject(entry, map, PacketInfo.PlotPos, Rotation, 255, GameObjectState.Ready); if (!go) { return(null); } if (BuildingInfo.CanActivate() && BuildingInfo.PacketInfo.HasValue && !BuildingInfo.PacketInfo.Value.Active) { FinalizeGarrisonPlotGOInfo finalizeInfo = Global.GarrisonMgr.GetPlotFinalizeGOInfo(PacketInfo.GarrPlotInstanceID); if (finalizeInfo != null) { Position pos2 = finalizeInfo.factionInfo[faction].Pos; GameObject finalizer = GameObject.CreateGameObject(finalizeInfo.factionInfo[faction].GameObjectId, map, pos2, Quaternion.fromEulerAnglesZYX(pos2.GetOrientation(), 0.0f, 0.0f), 255, GameObjectState.Ready); if (finalizer) { // set some spell id to make the object delete itself after use finalizer.SetSpellId(finalizer.GetGoInfo().Goober.spell); finalizer.SetRespawnTime(0); ushort animKit = finalizeInfo.factionInfo[faction].AnimKitId; if (animKit != 0) { finalizer.SetAnimKitId(animKit, false); } map.AddToMap(finalizer); } } } if (go.GetGoType() == GameObjectTypes.GarrisonBuilding && go.GetGoInfo().garrisonBuilding.SpawnMap != 0) { foreach (var cellGuids in Global.ObjectMgr.GetMapObjectGuids((uint)go.GetGoInfo().garrisonBuilding.SpawnMap, (byte)map.GetDifficultyID())) { foreach (var spawnId in cellGuids.Value.creatures) { Creature spawn = BuildingSpawnHelper <Creature>(go, spawnId, map); if (spawn) { BuildingInfo.Spawns.Add(spawn.GetGUID()); } } foreach (var spawnId in cellGuids.Value.gameobjects) { GameObject spawn = BuildingSpawnHelper <GameObject>(go, spawnId, map); if (spawn) { BuildingInfo.Spawns.Add(spawn.GetGUID()); } } } } BuildingInfo.Guid = go.GetGUID(); return(go); }