public static void Create(RegionMgr region, PQuest_Info info, ref Dictionary <uint, ContributionInfo> players, float bagCountMod)
        {
            if (region == null)
            {
                Log.Error("GoldChest", "Attempt to create for NULL region");
                return;
            }

            if (info == null)
            {
                Log.Error("GoldChest", "NULL PQuest in Region " + region);
                return;
            }

            if (bagCountMod == 0.0f)
            {
                return;
            }

            GameObject_proto proto = GameObjectService.GetGameObjectProto(188);

            GameObject_spawn spawn = new GameObject_spawn
            {
                Guid   = (uint)GameObjectService.GenerateGameObjectSpawnGUID(),
                WorldO = 0,
                WorldY = info.GoldChestWorldY,
                WorldZ = info.GoldChestWorldZ,
                WorldX = info.GoldChestWorldX,
                ZoneId = info.ZoneId
            };

            spawn.BuildFromProto(proto);

            GoldChest chest = new GoldChest(spawn, info, ref players, bagCountMod, region);

            region.AddObject(chest, info.ZoneId);
        }
Example #2
0
        public void LockZone(Realms realm, int zoneId, bool announce, bool reset, bool noRewards = false, bool draw = false)
        {
            Log.Debug("Battlefront.LockT4Zone", "Locking zone " + zoneId + " for " + realm);

            foreach (ProximityFlag flag in _Objectives.ToList())
            {
                if (flag.Ruin)
                {
                    _Objectives.Remove(flag);
                    flag.RemoveFromWorld();
                    continue;
                }

                if (flag.ZoneId == zoneId)
                {
                    flag.LockObjective(realm, announce);
                    flag._owningRealm = realm;
                    flag.BroadcastFlagInfo(false);
                }
            }

            if (realm == Realms.REALMS_REALM_ORDER)
            {
                _held[Zones.FindIndex(z => z.ZoneId == zoneId), 0] = 0;
                _held[Zones.FindIndex(z => z.ZoneId == zoneId), 1] = 4;
                _held[Zones.FindIndex(z => z.ZoneId == zoneId), 2] = 0;
                HeldObjectives[0] = 0;
                HeldObjectives[1] = 4;
                HeldObjectives[2] = 0;
            }
            else
            {
                _held[Zones.FindIndex(z => z.ZoneId == zoneId), 0] = 0;
                _held[Zones.FindIndex(z => z.ZoneId == zoneId), 1] = 0;
                _held[Zones.FindIndex(z => z.ZoneId == zoneId), 2] = 4;
                HeldObjectives[0] = 0;
                HeldObjectives[1] = 0;
                HeldObjectives[2] = 4;
            }

            foreach (Keep keep in _Keeps)
            {
                if (keep.Info.ZoneId == zoneId)
                {
                    Realms targetRealm = keep.GetContestedRealm();
                    Dictionary <uint, ContributionInfo> contributors = GetContributorsFromRealm(targetRealm);

                    if (contributors.Count > 0 && !noRewards)
                    {
                        if (DefenderPopTooSmall)
                        {
                            WinnerShare = 0.0f;
                        }

                        if (draw)
                        {
                            WinnerShare = 0.1f;
                            LoserShare  = 0.1f;
                        }

                        Log.Success("Logging keep rewards...", "");
                        Log.Success("Zone", ActiveZoneName);
                        Log.Success("Is defender pop too small to award rewards", DefenderPopTooSmall.ToString());
                        Log.Success("ProgressingBattlefront", $"Creating gold chest for {keep.Info.Name} for {contributors.Count} {(targetRealm == Realms.REALMS_REALM_ORDER ? "Order" : "Destruction")} contributors");
                        GoldChest.Create(Region, keep.Info.PQuest, ref contributors, targetRealm == realm ? WinnerShare : LoserShare);
                    }

                    keep.Realm = realm;
                    keep.LockKeep(realm, announce, reset);
                }
            }

            if (DefenderPopTooSmall)
            {
                Broadcast($"The forces of {(realm == Realms.REALMS_REALM_ORDER ? "Order " : "Destruction ")} conquered abandoned keep, no spoils of war were found!");
            }

            if (draw)
            {
                Broadcast("As forces of Order and Destruction were reluctant to trade final blows the war moved elsewhere!");
            }

            if (!announce)
            {
                return;
            }

            DisableSupplies();

            // Where 0 = Destromost zone, and 2 = Ordermost zone
            int campaignProgress = Zones.FindIndex(z => z.ZoneId == zoneId);

            string message;
            float  winnerRewardScale;

            if (realm == Realms.REALMS_REALM_DESTRUCTION)
            {
                campaignProgress = 2 - campaignProgress;
            }

            switch (campaignProgress)
            {
            case 0:
                // The realm has captured the zone closest to the enemy fort, leave the last zone locked and give them a reward
                UpdateStateOfTheRealm();
                PairingLocked = true;

#if DEBUG
                EvtInterface.AddEvent(EndGrace, 90 * 1000, 1);
#else
                EvtInterface.AddEvent(EndGrace, 10 * 60 * 1000, 1);
#endif


                Log.Info("Battlefront.LockT4Zone", "Locked all of region " + Region.RegionId);

                winnerRewardScale = 1.25f;

                if (realm == Realms.REALMS_REALM_ORDER)
                {
                    message = Zones[0].Name + " has been liberated by the forces of Order! The forces of Destruction have been cleansed from this region, but the fighting continues on elsewhere!";
                }
                else
                {
                    message = Zones[2].Name + " has been conquered by the forces of Destruction! The forces of Order flee like cowards, but the fighting continues on elsewhere!";
                }

                LockingRealm = realm;

                WorldMgr.EvaluateT4CampaignStatus(Region.RegionId);
                break;

            case 1:
                // The realm has captured the middle zone, unlock zone closest to enemy fort.
                if (Constants.DoomsdaySwitch > 0)
                {
                    //LiftZoneLock(Zones[realm == Realms.REALMS_REALM_ORDER ? 0 : 2].ZoneId, true);
                    CheckUnlockZone(true, Zones[realm == Realms.REALMS_REALM_ORDER ? 0 : 2].ZoneId, true);
                }
                else
                {
                    //LiftZoneLock(Zones[realm == Realms.REALMS_REALM_ORDER ? 0 : 2].ZoneId, false);
                    CheckUnlockZone(true, Zones[realm == Realms.REALMS_REALM_ORDER ? 0 : 2].ZoneId, false);
                }

                winnerRewardScale = 1f;

                if (realm == Realms.REALMS_REALM_ORDER)
                {
                    message        = Zones[1].Name + " has been reclaimed by the forces of Order! The forces of Destruction have retreated to " + Zones[0].Name + ", to build up for a renewed assault.";
                    DefendingRealm = Realms.REALMS_REALM_DESTRUCTION;
                }
                else
                {
                    message        = Zones[1].Name + " has been seized by the forces of Destruction! The forces of Order have fallen back to " + Zones[2].Name + " to make a last stand.";
                    DefendingRealm = Realms.REALMS_REALM_ORDER;
                }

                UpdateStateOfTheRealm();
                break;

            case 2:
                // The realm has recaptured the zone closest to their fort, unlock the middle zone
                if (Constants.DoomsdaySwitch > 0)
                {
                    CheckUnlockZone(true, Zones[1].ZoneId, true);
                }
                //LiftZoneLock(Zones[1].ZoneId, true);
                else
                {
                    CheckUnlockZone(true, Zones[1].ZoneId, false);
                }
                //LiftZoneLock(Zones[1].ZoneId, false);

                winnerRewardScale = 0.75f;

                if (realm == Realms.REALMS_REALM_ORDER)
                {
                    message = Zones[2].Name + " has been saved by the forces of Order! The forces of Destruction fall back to " + Zones[1].Name + "!";
                }
                else
                {
                    message = "The forces of Destruction tighten their grip on " + Zones[0].Name + ", and the forces of Order fall back to " + Zones[1].Name + "!";
                }

                DefendingRealm = Realms.REALMS_REALM_NEUTRAL;

                UpdateStateOfTheRealm();
                break;

            default:
                Log.Error("Battlefront.LockT4Zone", "The campaign progress was somehow at stage " + campaignProgress + ". This is not supposed to happen.");
                return;
            }

            VictoryPoints = 50;
            LastAnnouncedVictoryPoints = 50;

            WorldMgr.SendCampaignStatus(null);

            winnerRewardScale *= RelativeActivityFactor;

            try
            {
                Log.Info("Zone Lock", ZoneService.GetZone_Info((ushort)zoneId).Name);
                HandleLockReward(realm, winnerRewardScale, message, zoneId);
            }
            catch (Exception e)
            {
                Log.Error("HandleLockReward", "Exception thrown: " + e);
            }

            TotalContribFromRenown = (ulong)(Tier * 50);
            PlayerContributions.Clear();

            PlayerContributions = new Dictionary <uint, ContributionInfo>();

            int arr;
            if (Constants.DoomsdaySwitch == 2)
            {
                arr = (int)pairing;
            }
            else
            {
                arr = Tier;
            }

            if (BattlefrontList.ActiveFronts[arr - 1] == this)
            {
                BattlefrontList.ActiveFronts[arr - 1] = null;
            }

            // This should be 2 to make it work correct with 3 open zones, codeword c4rr0t
            if (Constants.DoomsdaySwitch != 2)
            {
                int i = 0;
                foreach (IBattlefront b in BattlefrontList.Battlefronts[Tier - 1])
                {
                    if (i > 0)
                    {
                        ProximityBattlefront front = b as ProximityBattlefront;
                        if (front != this && !front.PairingLocked)
                        {
                            front.EvtInterface.AddEvent(front.SupplyLineReset, 1, 1);
                        }
                    }
                    i++;
                }
            }

            /*else
             * {
             *  foreach (ProximityBattlefront b in BattlefrontList.RegionManagers[arr - 1])
             *      if (b != this && !b.PairingLocked && b.pairing == pairing)
             *          //b.EvtInterface.AddEvent(b.SupplyLineReset, 1, 1);
             * }*/
            DefenderPopTooSmall = false;
            _totalMaxOrder      = 0;
            _totalMaxDestro     = 0;

            PairingDrawTime = 0;
        }
        public void LockZone(Realms realm, int zoneId, bool announce, bool reset, bool noRewards = false)
        {
            Log.Debug("Battlefront.LockT4Zone", "Locking zone " + zoneId + " for " + realm);

            foreach (BattlefrontFlag flag in _Objectives)
            {
                if (flag.ZoneId == zoneId)
                {
                    flag.LockObjective(realm, announce);
                }
            }

            if (realm == Realms.REALMS_REALM_ORDER)
            {
                _held[Zones.FindIndex(z => z.ZoneId == zoneId), 0] = 4;
                _held[Zones.FindIndex(z => z.ZoneId == zoneId), 1] = 0;
            }
            else
            {
                _held[Zones.FindIndex(z => z.ZoneId == zoneId), 0] = 0;
                _held[Zones.FindIndex(z => z.ZoneId == zoneId), 1] = 4;
            }

            HeldObjectives[0] = 0;
            HeldObjectives[1] = 0;

            foreach (Keep keep in _Keeps)
            {
                if (keep.Info.ZoneId == zoneId)
                {
                    Realms targetRealm = keep.GetContestedRealm();
                    Dictionary <uint, ContributionInfo> contributors = GetContributorsFromRealm(targetRealm);

                    if (contributors.Count > 0 && !noRewards)
                    {
                        Log.Info("ProgressingBattlefront", $"Creating gold chest for {keep.Info.Name} for {contributors.Count} {(targetRealm == Realms.REALMS_REALM_ORDER ? "Order" : "Destruction")} contributors");
                        GoldChest.Create(Region, keep.Info.PQuest, ref contributors, targetRealm == realm ? WinnerShare : LoserShare);
                    }

                    keep.LockKeep(realm, announce, reset);
                }
            }

            if (!announce)
            {
                return;
            }

            DisableSupplies();

            // Where 0 = Destromost zone, and 2 = Ordermost zone
            int campaignProgress = Zones.FindIndex(z => z.ZoneId == zoneId);

            string message;
            float  winnerRewardScale;

            if (realm == Realms.REALMS_REALM_DESTRUCTION)
            {
                campaignProgress = 2 - campaignProgress;
            }

            switch (campaignProgress)
            {
            case 0:
                // The realm has captured the zone closest to the enemy fort, leave the last zone locked and give them a reward
                UpdateStateOfTheRealm();
                PairingLocked = true;

                    #if DEBUG
                EvtInterface.AddEvent(EndGrace, 90 * 1000, 1);
                    #else
                EvtInterface.AddEvent(EndGrace, 10 * 60 * 1000, 1);
                    #endif


                Log.Info("Battlefront.LockT4Zone", "Locked all of region " + Region.RegionId);

                winnerRewardScale = 1.25f;

                if (realm == Realms.REALMS_REALM_ORDER)
                {
                    message = Zones[0].Name + " has been liberated by the forces of Order! The forces of Destruction have been cleansed from this region, but the fighting continues on elsewhere!";
                }
                else
                {
                    message = Zones[2].Name + " has been conquered by the forces of Destruction! The forces of Order flee like cowards, but the fighting continues on elsewhere!";
                }

                LockingRealm = realm;

                WorldMgr.EvaluateT4CampaignStatus(Region.RegionId);
                break;

            case 1:
                // The realm has captured the middle zone, unlock zone closest to enemy fort.
                if (Constants.DoomsdaySwitch > 0)
                {
                    LiftZoneLock(Zones[realm == Realms.REALMS_REALM_ORDER ? 0 : 2].ZoneId, true);
                }
                else
                {
                    LiftZoneLock(Zones[realm == Realms.REALMS_REALM_ORDER ? 0 : 2].ZoneId, false);
                }

                winnerRewardScale = 1f;

                if (realm == Realms.REALMS_REALM_ORDER)
                {
                    message        = Zones[1].Name + " has been reclaimed by the forces of Order! The forces of Destruction have retreated to " + Zones[0].Name + ", to build up for a renewed assault.";
                    DefendingRealm = Realms.REALMS_REALM_DESTRUCTION;
                }
                else
                {
                    message        = Zones[1].Name + " has been seized by the forces of Destruction! The forces of Order have fallen back to " + Zones[2].Name + " to make a last stand.";
                    DefendingRealm = Realms.REALMS_REALM_ORDER;
                }

                UpdateStateOfTheRealm();
                break;

            case 2:
                // The realm has recaptured the zone closest to their fort, unlock the middle zone
                if (Constants.DoomsdaySwitch > 0)
                {
                    LiftZoneLock(Zones[1].ZoneId, true);
                }
                else
                {
                    LiftZoneLock(Zones[1].ZoneId, false);
                }

                winnerRewardScale = 0.75f;

                if (realm == Realms.REALMS_REALM_ORDER)
                {
                    message = Zones[2].Name + " has been saved by the forces of Order! The forces of Destruction fall back to " + Zones[1].Name + "!";
                }
                else
                {
                    message = "The forces of Destruction tighten their grip on " + Zones[0].Name + ", and the forces of Order fall back to " + Zones[1].Name + "!";
                }

                DefendingRealm = Realms.REALMS_REALM_NEUTRAL;

                UpdateStateOfTheRealm();
                break;

            default:
                Log.Error("Battlefront.LockT4Zone", "The campaign progress was somehow at stage " + campaignProgress + ". This is not supposed to happen.");
                return;
            }

            VictoryPoints = 50;
            LastAnnouncedVictoryPoints = 50;

            WorldMgr.SendCampaignStatus(null);

            winnerRewardScale *= RelativeActivityFactor;

            try
            {
                Log.Info("Zone Lock", ZoneService.GetZone_Info((ushort)zoneId).Name);
                HandleLockReward(realm, winnerRewardScale, message, zoneId);
            }
            catch (Exception e)
            {
                Log.Error("HandleLockReward", "Exception thrown: " + e);
            }

            TotalContribFromRenown = (ulong)(Tier * 50);

            PlayerContributions.Clear();

            int arr;
            if (Constants.DoomsdaySwitch == 2)
            {
                arr = (int)pairing;
            }
            else
            {
                arr = Tier;
            }

            if (BattlefrontList.ActiveFronts[arr - 1] == this)
            {
                BattlefrontList.ActiveFronts[arr - 1] = null;
            }

            if (Constants.DoomsdaySwitch == 2)
            {
                foreach (Battlefront b in BattlefrontList.Battlefronts[Tier - 1])
                {
                    if (b != this && !b.PairingLocked && b.pairing == pairing)
                    {
                        b.EvtInterface.AddEvent(b.SupplyLineReset, 1, 1);
                    }
                }
            }
            else
            {
                foreach (Battlefront b in BattlefrontList.Battlefronts[Tier - 1])
                {
                    if (b != this && !b.PairingLocked)
                    {
                        b.EvtInterface.AddEvent(b.SupplyLineReset, 1, 1);
                    }
                }
            }
        }