Example #1
0
            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.CreateFromRotationMatrix(Extensions.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, 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);
            }
Example #2
0
        public bool LoadFromDB(SQLResult garrison, SQLResult blueprints, SQLResult buildings, SQLResult followers, SQLResult abilities)
        {
            if (garrison.IsEmpty())
            {
                return(false);
            }

            _siteLevel = CliDB.GarrSiteLevelStorage.LookupByKey(garrison.Read <uint>(0));
            _followerActivationsRemainingToday = garrison.Read <uint>(1);
            if (_siteLevel == null)
            {
                return(false);
            }

            InitializePlots();

            if (!blueprints.IsEmpty())
            {
                do
                {
                    GarrBuildingRecord building = CliDB.GarrBuildingStorage.LookupByKey(blueprints.Read <uint>(0));
                    if (building != null)
                    {
                        _knownBuildings.Add(building.Id);
                    }
                } while (blueprints.NextRow());
            }

            if (!buildings.IsEmpty())
            {
                do
                {
                    uint plotInstanceId = buildings.Read <uint>(0);
                    uint buildingId     = buildings.Read <uint>(1);
                    long timeBuilt      = buildings.Read <long>(2);
                    bool active         = buildings.Read <bool>(3);


                    Plot plot = GetPlot(plotInstanceId);
                    if (plot == null)
                    {
                        continue;
                    }

                    if (!CliDB.GarrBuildingStorage.ContainsKey(buildingId))
                    {
                        continue;
                    }

                    plot.BuildingInfo.PacketInfo.HasValue = true;
                    plot.BuildingInfo.PacketInfo.Value.GarrPlotInstanceID = plotInstanceId;
                    plot.BuildingInfo.PacketInfo.Value.GarrBuildingID     = buildingId;
                    plot.BuildingInfo.PacketInfo.Value.TimeBuilt          = timeBuilt;
                    plot.BuildingInfo.PacketInfo.Value.Active             = active;
                } while (buildings.NextRow());
            }

            if (!followers.IsEmpty())
            {
                do
                {
                    ulong dbId       = followers.Read <ulong>(0);
                    uint  followerId = followers.Read <uint>(1);
                    if (!CliDB.GarrFollowerStorage.ContainsKey(followerId))
                    {
                        continue;
                    }

                    _followerIds.Add(followerId);

                    var follower = new Follower();
                    follower.PacketInfo.DbID            = dbId;
                    follower.PacketInfo.GarrFollowerID  = followerId;
                    follower.PacketInfo.Quality         = followers.Read <uint>(2);
                    follower.PacketInfo.FollowerLevel   = followers.Read <uint>(3);
                    follower.PacketInfo.ItemLevelWeapon = followers.Read <uint>(4);
                    follower.PacketInfo.ItemLevelArmor  = followers.Read <uint>(5);
                    follower.PacketInfo.Xp = followers.Read <uint>(6);
                    follower.PacketInfo.CurrentBuildingID = followers.Read <uint>(7);
                    follower.PacketInfo.CurrentMissionID  = followers.Read <uint>(8);
                    follower.PacketInfo.FollowerStatus    = followers.Read <uint>(9);
                    if (!CliDB.GarrBuildingStorage.ContainsKey(follower.PacketInfo.CurrentBuildingID))
                    {
                        follower.PacketInfo.CurrentBuildingID = 0;
                    }

                    //if (!sGarrMissionStore.LookupEntry(follower.PacketInfo.CurrentMissionID))
                    //    follower.PacketInfo.CurrentMissionID = 0;
                    _followers[followerId] = follower;
                } while (followers.NextRow());

                if (!abilities.IsEmpty())
                {
                    do
                    {
                        ulong             dbId    = abilities.Read <ulong>(0);
                        GarrAbilityRecord ability = CliDB.GarrAbilityStorage.LookupByKey(abilities.Read <uint>(1));

                        if (ability == null)
                        {
                            continue;
                        }

                        var garrisonFollower = _followers.LookupByKey(dbId);
                        if (garrisonFollower == null)
                        {
                            continue;
                        }

                        garrisonFollower.PacketInfo.AbilityID.Add(ability);
                    } while (abilities.NextRow());
                }
            }

            return(true);
        }
Example #3
0
        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.UpgradeLevel > _siteLevel.MaxBuildingLevel)
            {
                return(GarrisonError.InvalidBuildingId);
            }

            if (building.Flags.HasAnyFlag(GarrisonBuildingFlags.NeedsPlan))
            {
                if (HasBlueprint(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.BuildingType == building.BuildingType)
                    {
                        if (p.Key != garrPlotInstanceId || existingBuilding.UpgradeLevel + 1 != building.UpgradeLevel)    // check if its an upgrade in same plot
                        {
                            return(GarrisonError.BuildingExists);
                        }
                    }
                }
            }

            if (!_owner.HasCurrency(building.CurrencyTypeID, (uint)building.CurrencyQty))
            {
                return(GarrisonError.NotEnoughCurrency);
            }

            if (!_owner.HasEnoughMoney(building.GoldCost * 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);
        }