Example #1
0
        public virtual void GivePowerScrolls()
        {
            if (ChampSpawn == null && !AlwaysDropScrolls)
            {
                return;
            }

            var scores = new Dictionary<Mobile, double>(Scores);

            var toReceiveScroll = new List<Mobile>();


            // first find all eligible receivers
            var eligibleMobs = new List<Mobile>();
            var eligibleMobScores = new List<double>();

            var eligibleFactionMobs = new List<Mobile>();
            var eligibleFactionMobScores = new List<double>();


            double totalScores = 0.0;
            double totalFactionScores = 0.0;

            var sb = new StringBuilder();

            sb.Append("========== " + DateTime.Now + " Champion " + GetType() + " Report ==============\r\n");
            sb.Append(
                "Score\tEligible\tName\tAccount\tAddress\tStr\tInt\tDex\tTaming\tProvocation\tMagery\tArchery\tMace\tFencing\tSwords\tLumberjack\tWrestling\tAnatomy\r\n");

            foreach (KeyValuePair<Mobile, double> pair in scores)
            {
                Mobile mob = pair.Key;

                if (mob == null)
                {
                    continue;
                }

                bool eligible = IsEligible(mob);

                sb.Append(
                    pair.Value + "\t" + eligible + "\t" + mob + "\t" + mob.Account + "\t" + mob.Address + "\t" + mob.Str +
                    "\t" +
                    mob.Int + "\t" + mob.Dex + "\t" + mob.Skills.AnimalTaming.Value + "\t" +
                    mob.Skills.Provocation.Value + "\t" +
                    mob.Skills.Magery.Value + "\t" + mob.Skills.Archery.Value + "\t" + mob.Skills.Macing.Value + "\t" +
                    mob.Skills.Fencing.Value + "\t" + mob.Skills.Swords.Value + "\t" + mob.Skills.Lumberjacking.Value +
                    "\t" +
                    mob.Skills.Wrestling.Value + "\t" + mob.Skills.Anatomy.Value + "\r\n");

                if (!eligible)
                {
                    continue;
                }

                eligibleMobs.Add(mob);
                eligibleMobScores.Add(pair.Value);

                if (mob is PlayerMobile && ((PlayerMobile) mob).FactionName != null)
                {
                    eligibleFactionMobs.Add(mob);
                    eligibleFactionMobScores.Add(pair.Value);
                    totalFactionScores += pair.Value;
                }

                totalScores += pair.Value;
            }

            if (0.1 > Utility.RandomDouble())
            {
                GiveRecipe(eligibleMobs, eligibleMobScores, totalScores);
            }

            if (0.1 > Utility.RandomDouble())
            {
                GiveRelic(eligibleMobs, eligibleMobScores, totalScores);
            }

            GiveSpecialItems(eligibleMobs, eligibleMobScores, totalScores);

            //determine faction PS winner


            for (int powerScrollIndex = 0;
                powerScrollIndex < FactionPSToGive;
                powerScrollIndex++)
            {
                double currentTestValue = 0.0;
                double roll = Utility.RandomDouble() * totalFactionScores;

                for (int i = 0; i < eligibleFactionMobScores.Count; i++)
                {
                    currentTestValue += eligibleFactionMobScores[i];

                    if (roll > currentTestValue)
                    {
                        continue;
                    }

                    toReceiveScroll.Add(eligibleFactionMobs[i]);

                    totalScores -= eligibleFactionMobScores[i];

                    // remove them from eligible list now
                    eligibleFactionMobs.RemoveAt(i);
                    eligibleFactionMobScores.RemoveAt(i);
                    break;
                }
            }

            for (int powerScrollIndex = 0;
                powerScrollIndex < PSToGive;
                powerScrollIndex++)
            {
                double currentTestValue = 0.0;
                double roll = Utility.RandomDouble() * totalScores;

                for (int i = 0; i < eligibleMobScores.Count; i++)
                {
                    currentTestValue += eligibleMobScores[i];

                    if (roll > currentTestValue)
                    {
                        continue;
                    }

                    toReceiveScroll.Add(eligibleMobs[i]);

                    totalScores -= eligibleMobScores[i];

                    // remove them from eligible list now
                    eligibleMobs.RemoveAt(i);
                    eligibleMobScores.RemoveAt(i);
                    break;
                }
            }

            if (Portal == null && Invasion == null)
            {
                foreach (PlayerMobile mobile in scores.Keys.OfType<PlayerMobile>())
                {
                    PlayerMobile mobile1 = mobile;
                    Timer.DelayCall(
                        TimeSpan.FromMinutes(1),
                        () =>
                        {
                            var scrollgump = new PlayerScoresScrollGump(mobile1, onAccept: x =>
                            {
                                var scoreboard = new PlayerScoreResultsGump(mobile1, this, scores, toReceiveScroll).
                                    Send<PlayerScoreResultsGump>();
                            }).Send<PlayerScoresScrollGump>();
                        });
                }
            }

            foreach (Mobile luckyPlayer in toReceiveScroll)
            {
                PowerScroll ps = CreateRandomPowerScroll(Expansion);

                if (ps == null)
                {
                    continue;
                }

                GivePowerScrollTo(luckyPlayer, ps);
                sb.Append(luckyPlayer + " received powerScoll " + ps.Skill + " " + ps.Value + "\r\n");
            }

            LoggingCustom.Log("ChampionScores/" + IOUtility.GetSafeFileName(GetType().FullName) + ".log", sb.ToString());
        }
Example #2
0
        public override void GivePowerScrolls()
        {
            if (ChampSpawn == null && !AlwaysDropScrolls)
            {
                return;
            }

            var scores = new Dictionary<Mobile, double>(Scores);

            var toReceiveScroll = new List<Mobile>();

            // first find all eligible receivers
            var eligibleMobs = new List<Mobile>();
            var eligibleMobScores = new List<double>();

            List<KeyValuePair<Mobile, double>> orderedscores = scores.ToList();

            orderedscores.Sort((firstPair, nextPair) => firstPair.Value.CompareTo(nextPair.Value));
            orderedscores.Reverse();

            double totalScores = 0.0;
            var sb = new StringBuilder();

            sb.Append("========== " + DateTime.Now + " Champion " + GetType() + " Report ==============\r\n");
            sb.Append(
                "Score\tEligible\tName\tAccount\tAddress\tStr\tInt\tDex\tTaming\tProvocation\tMagery\tArchery\tMace\tFencing\tSwords\tLumberjack\tWrestling\tAnatomy\r\n");

            foreach (KeyValuePair<Mobile, double> pair in scores)
            {
                Mobile mob = pair.Key;

                if (mob == null)
                {
                    continue;
                }

                bool eligible = IsEligible(mob);

                sb.Append(
                    pair.Value + "\t" + eligible + "\t" + mob + "\t" + mob.Account + "\t" + mob.Address + "\t" + mob.Str +
                    "\t" +
                    mob.Int + "\t" + mob.Dex + "\t" + mob.Skills.AnimalTaming.Value + "\t" +
                    mob.Skills.Provocation.Value + "\t" +
                    mob.Skills.Magery.Value + "\t" + mob.Skills.Archery.Value + "\t" + mob.Skills.Macing.Value + "\t" +
                    mob.Skills.Fencing.Value + "\t" + mob.Skills.Swords.Value + "\t" + mob.Skills.Lumberjacking.Value +
                    "\t" +
                    mob.Skills.Wrestling.Value + "\t" + mob.Skills.Anatomy.Value + "\r\n");

                if (!eligible)
                {
                    continue;
                }

                eligibleMobs.Add(mob);
                eligibleMobScores.Add(pair.Value);

                totalScores += pair.Value;
            }

            for (int powerScrollIndex = 0;
                powerScrollIndex < ChampionGlobals.CSOptions.PowerScrollsToGive;
                powerScrollIndex++)
            {
                double currentTestValue = 0.0;
                double roll = Utility.RandomDouble() * totalScores;

                for (int i = 0; i < eligibleMobScores.Count; i++)
                {
                    currentTestValue += eligibleMobScores[i];

                    if (roll > currentTestValue)
                    {
                        continue;
                    }

                    toReceiveScroll.Add(eligibleMobs[i]);

                    totalScores -= eligibleMobScores[i];

                    // remove them from eligible list now
                    eligibleMobs.RemoveAt(i);
                    eligibleMobScores.RemoveAt(i);
                    break;
                }
            }


            foreach (PlayerMobile mobile in scores.Keys.OfType<PlayerMobile>())
            {
                PlayerMobile mobile1 = mobile;
                Timer.DelayCall(
                    TimeSpan.FromMinutes(1),
                    () =>
                    {
                        var scrollgump = new PlayerScoresScrollGump(mobile1, onAccept: x =>
                        {
                            var scoreboard = new PlayerScoreResultsGump(mobile1, this, scores, toReceiveScroll).
                                Send<PlayerScoreResultsGump>();
                        }).Send<PlayerScoresScrollGump>();
                    });
            }

            foreach (Mobile luckyPlayer in toReceiveScroll)
            {
                PowerScroll ps = CreateRandomPowerScroll(Expansion);

                if (ps == null)
                {
                    continue;
                }

                GivePowerScrollTo(luckyPlayer, ps);
                sb.Append(luckyPlayer + " received powerScoll " + ps.Skill + " " + ps.Value + "\r\n");
            }

            foreach (PlayerMobile pm in orderedscores.Select(kvp => kvp.Key as PlayerMobile))
            {
                TitleHue titlehue;

                CustomTitles.TryGetHue(1196, out titlehue);

                TitleProfile p = CustomTitles.EnsureProfile(pm);

                if (pm != null && titlehue != null && p != null && !p.Contains(titlehue))
                {
                    p.Add(titlehue);
                    pm.SendMessage(titlehue.Hue, "You have been granted the title hue: " + titlehue.Hue);
                    sb.Append(pm + " received titlehue " + titlehue.Hue + "\r\n");
                    break;
                }
            }

            LoggingCustom.Log("ChampionScores/" + IOUtility.GetSafeFileName(GetType().FullName) + ".log", sb.ToString());
        }