/// <summary>(Re)loads portals data.</summary>
        internal bool Load()
        {
            ushort _zoneId     = _objective.ZoneId;
            int    objectiveId = _objective.ID;

            _objectivePortalData = BattlefrontService.GetPortalToWarcamp(_zoneId, objectiveId);
            _orderPortalData     = GetPortalToObjective(Realms.REALMS_REALM_ORDER);
            _destroPortalData    = GetPortalToObjective(Realms.REALMS_REALM_DESTRUCTION);

            if (_objectivePortalData != null && _orderPortalData != null && _destroPortalData != null)
            {
                return(true);
            }
#if DEBUG
            if (_region.GetTier() < 5)
            {
                List <string> missingInfo = new List <string>();
                if (_objectivePortalData == null)
                {
                    missingInfo.Add("objective portal");
                }
                if (_orderPortalData == null)
                {
                    missingInfo.Add("order portal");
                }
                if (_destroPortalData == null)
                {
                    missingInfo.Add("destro portal");
                }
                Log.Error("ObjectivePortalsMgr", $"Missing portal data for objective {_objective.Name} ({_objective.ID}) : " + string.Join(", ", missingInfo));
                BattlefrontService.LoadBattlefrontObjects();
            }
#endif


            return(false);
        }
Beispiel #2
0
        public static void Portal(Player plr, string objectiveName = null)
        {
            // Current player battlefront
            IBattlefront battlefront;

            if (plr.Region.GetTier() == 1)
            {
                battlefront = plr.Region.Bttlfront as RoRBattlefront;
            }
            else if (plr.Region.GetTier() > 1)
            {
                battlefront = plr.Region.Bttlfront as ProximityBattlefront;
            }
            else
            {
                return;
            }

            if (battlefront == null)
            {
                SendCsr(plr, "CAMPAIGN PORTAL: Must be in a battlefront.");
                return;
            }

            // Current flag
            ProximityFlag         flag;
            string                notFoundMessage;
            string                successMessage;
            BattlefrontObjectType type;

            if (objectiveName == null)
            {
                flag            = battlefront.GetClosestFlag(plr.WorldPosition) as ProximityFlag;
                type            = BattlefrontObjectType.WARCAMP_PORTAL;
                notFoundMessage = "CAMPAIGN PORTAL: Must be near a proximity flag in rvr lake if no name is given.";
                successMessage  = $"CAMPAIGN PORTAL: Portal from {(flag != null ? flag.Name : "")} to warcamp has been set.";
            }
            else
            {
                flag            = GetFlag(battlefront, objectiveName);
                notFoundMessage = "CAMPAIGN PORTAL: Could not find objective of name : " + objectiveName;
                type            = BattlefrontObjectType.OBJECTIVE_PORTAL;
                successMessage  = $"CAMPAIGN PORTAL: Portal from warcamp to {(flag != null ? flag.Name : "")} has been set for ";
            }

            if (flag == null)
            {
                SendCsr(plr, notFoundMessage);
                return;
            }

            // Database update
            BattlefrontService.LoadBattlefrontObjects();
            BattlefrontObject newObject = new BattlefrontObject()
            {
                Type        = (byte)type,
                ObjectiveID = flag.ID,
            };

            BattlefrontObject oldObject;

            if (type == BattlefrontObjectType.OBJECTIVE_PORTAL)
            {
                // Compute realm, depending on its location - quite a hack but will avoid parameter errors
                Realms realm;

                int orderDistance  = GetWarcampDistance(plr, Realms.REALMS_REALM_ORDER);
                int destroDistance = GetWarcampDistance(plr, Realms.REALMS_REALM_DESTRUCTION);
                if (orderDistance < destroDistance) // In order warcamp
                {
                    realm           = Realms.REALMS_REALM_ORDER;
                    successMessage += "Order.";
                }
                else // In destro warcamp
                {
                    realm           = Realms.REALMS_REALM_DESTRUCTION;
                    successMessage += "Destruction.";
                }

                newObject.Realm = (ushort)realm;
                oldObject       = BattlefrontService.GetPortalToObjective(plr.ZoneId.Value, flag.ID, realm);
            }
            else
            {
                oldObject = BattlefrontService.GetPortalToWarcamp(plr.ZoneId.Value, flag.ID);
            }

            if (oldObject != null)
            {
                WorldMgr.Database.DeleteObject(oldObject);
                oldObject.Dirty = true;
                WorldMgr.Database.ForceSave();
            }
            AddObject(plr, newObject);
            SendCsr(plr, successMessage);
        }