Esempio n. 1
0
        void InitializePlots()
        {
            var plots = Global.GarrisonMgr.GetGarrPlotInstForSiteLevel(_siteLevel.Id);

            for (var i = 0; i < plots.Count; ++i)
            {
                uint garrPlotInstanceId             = plots[i].GarrPlotInstanceID;
                GarrPlotInstanceRecord plotInstance = CliDB.GarrPlotInstanceStorage.LookupByKey(garrPlotInstanceId);
                GameObjectsRecord      gameObject   = Global.GarrisonMgr.GetPlotGameObject(_siteLevel.MapID, garrPlotInstanceId);
                if (plotInstance == null || gameObject == null)
                {
                    continue;
                }

                GarrPlotRecord plot = CliDB.GarrPlotStorage.LookupByKey(plotInstance.GarrPlotID);
                if (plot == null)
                {
                    continue;
                }

                Plot plotInfo = _plots[garrPlotInstanceId];
                plotInfo.PacketInfo.GarrPlotInstanceID = garrPlotInstanceId;
                plotInfo.PacketInfo.PlotPos.Relocate(gameObject.Pos.X, gameObject.Pos.Y, gameObject.Pos.Z, 2 * (float)Math.Acos(gameObject.Rot[3]));
                plotInfo.PacketInfo.PlotType     = plot.PlotType;
                plotInfo.Rotation                = new Quaternion(gameObject.Rot[0], gameObject.Rot[1], gameObject.Rot[2], gameObject.Rot[3]);
                plotInfo.EmptyGameObjectId       = gameObject.Id;
                plotInfo.GarrSiteLevelPlotInstId = plots[i].Id;
            }
        }
Esempio n. 2
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);
            }