示例#1
0
        public void EnsureDefaults()
        {
            _Initializing = true;

            Tier      = 0;
            _Progress = 0;

            if (WorldFirst)
            {
                ConquestState s = Conquests.FindReplacementWorldFirst(Conquest);

                WorldFirst = false;

                if (s != null)
                {
                    s.WorldFirst = true;
                    s.Conquest.OnWorldFirst(s);
                }
            }

            LastProgress  = DateTime.MinValue;
            CompletedDate = DateTime.MinValue;

            _Initializing = false;
        }
        protected override int GetProgress(ConquestState state, ConquestTierCompletedContainer args)
        {
            if (state.User == null)
            {
                return(0);
            }

            int progress = base.GetProgress(state, args);

            if (progress <= 0)
            {
                return(progress);
            }

            int count = args.Tier >= TierReq ? 1 : 0;

            ConquestProfile p = Conquests.EnsureProfile(state.User);

            if (p != null)
            {
                count += p.Count(s => s != state && Include(s));
            }

            return(Math.Max(0, count - state.Progress));
        }
示例#3
0
        public override void Serialize(GenericWriter writer)
        {
            base.Serialize(writer);

            int version = writer.SetVersion(0);

            UID.Serialize(writer);

            Conquests.WriteConquest(writer, Conquest);

            writer.Write(Owner);

            switch (version)
            {
            case 0:
            {
                writer.Write(LastProgress);
                writer.Write(CompletedDate);

                writer.Write(WorldFirst);

                writer.Write(Tier);
                writer.Write(_Progress);
            }
            break;
            }
        }
示例#4
0
        public void AccountPropagate()
        {
            var acc = Owner.Account as Account;

            if (acc == null)
            {
                return;
            }

            foreach (var p in
                     acc.Mobiles.Where(m => m != null && !m.Deleted && m != Owner)
                     .OfType <PlayerMobile>()
                     .Select(Conquests.EnsureProfile)
                     .Where(p => p != null && Conquests.Validate(Conquest, p.Owner)))
            {
                ConquestState s = p.EnsureState(Conquest);

                if (s == null || s == this)
                {
                    continue;
                }

                int d = _Progress - s._Progress;

                if (_Progress > s._Progress || CompletedDate < s.CompletedDate || WorldFirst)
                {
                    s.CopyState(this);
                }
            }
        }
示例#5
0
        protected override int GetProgress(ConquestState state, ConquestProgressContainer args)
        {
            if (state.User == null)
            {
                return(0);
            }

            int progress = base.GetProgress(state, args);

            if (progress <= 0)
            {
                return(progress);
            }

            int total = args.State.Progress + args.Offset;

            ConquestProfile p = Conquests.EnsureProfile(state.User);

            if (p != null)
            {
                total += p.Sum(s => s != state && Include(s) ? s.Progress : 0);
            }

            return(Math.Max(0, total - state.Progress));
        }
示例#6
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.GetVersion();

            UID = new ConquestSerial(reader);

            Conquest = Conquests.ReadConquest(reader);

            Owner = reader.ReadMobile <PlayerMobile>();

            _Initializing = true;

            switch (version)
            {
            case 0:
            {
                LastProgress  = reader.ReadDateTime();
                CompletedDate = reader.ReadDateTime();

                WorldFirst = reader.ReadBool();

                Tier      = reader.ReadInt();
                _Progress = reader.ReadInt();
            }
            break;
            }

            _Initializing = false;
        }
示例#7
0
        protected override void CompileMenuOptions(MenuGumpOptions list)
        {
            if (User.AccessLevel >= Conquests.Access)
            {
                list.AppendEntry(new ListGumpEntry("System Options", OpenConfig, HighlightHue));
                list.AppendEntry(new ListGumpEntry("Add Conquest", AddConquest, HighlightHue));

                list.AppendEntry(
                    new ListGumpEntry(
                        "Delete All",
                        button => Send(
                            new ConfirmDialogGump(User, this)
                {
                    Title = "Delete All Conquests?",
                    Html  =
                        "All conquests in the database will be deleted, erasing all data associated with them.\nThis action can not be reversed.\n\nDo you want to continue?",
                    AcceptHandler = subButton =>
                    {
                        Conquest[] conquests = Conquests.ConquestRegistry.Values.Where(c => c != null && !c.Deleted).ToArray();

                        conquests.ForEach(c => c.Delete());

                        Conquests.ConquestRegistry.Clear();

                        Refresh(true);
                    }
                }),
                        ErrorHue));

                list.AppendEntry(
                    new ListGumpEntry(
                        "Disable All Conquests",
                        button => Send(
                            new ConfirmDialogGump(User, this)
                {
                    Title = "Disable All Conquests?",
                    Html  =
                        "All conquests in the database will be disabled, which will also reset their states.\n\nDo you want to continue?",
                    AcceptHandler = subButton =>
                    {
                        Conquest[] conquests = Conquests.ConquestRegistry.Values.Where(c => c != null && !c.Deleted).ToArray();

                        conquests.ForEach(c => c.Enabled = !c.Enabled);

                        Refresh(true);
                    }
                }),
                        ErrorHue));

                list.AppendEntry(new ListGumpEntry("Import XML", b => Conquests.ImportXML(User)));
                list.AppendEntry(new ListGumpEntry("Export XML", b => Conquests.ExportXML(User)));
            }

            //list.AppendEntry(new ListGumpEntry("View Profiles", ShowProfiles));
            list.AppendEntry(new ListGumpEntry("Help", ShowHelp));

            base.CompileMenuOptions(list);
        }
示例#8
0
 protected virtual void OnDisabled()
 {
     foreach (
         ConquestProfile p in
         Conquests.Profiles.Values.AsParallel().Where(p => p != null && !Conquests.Validate(this, p.Owner)))
     {
         p.RemoveState(this);
     }
 }
示例#9
0
        protected override void Compile()
        {
            if (Profile != null)
            {
                Title = "Conquests for " + Profile.Owner.RawName + " (" + Profile.Registry.Count(s => s.Completed) + "/" +
                        Conquests.FindConquests <Conquest>(c => Conquests.Validate(c, Profile.Owner)).Length + ")";
            }

            base.Compile();
        }
示例#10
0
        public ConquestStateListGump(
            PlayerMobile user,
            Gump parent             = null,
            ConquestProfile profile = null,
            string category         = "All")
            : base(user, parent, emptyText: "There are no conquests to display.", title: "Conquests")
        {
            Profile = profile ?? Conquests.EnsureProfile(User);

            Category = category.ToUpperWords() ?? "All";

            ForceRecompile = true;
            AutoRefresh    = true;

            Sorted = true;
        }
示例#11
0
        protected virtual void OnEnabled()
        {
            foreach (
                ConquestProfile p in
                Conquests.Profiles.Values.AsParallel().Where(p => p != null && Conquests.Validate(this, p.Owner)))
            {
                p.EnsureState(this);

                foreach (
                    var s in
                    p.Where(
                        s =>
                        s.Completed && this is ConquestCompletedConquest &&
                        Insensitive.Contains(s.Conquest.Category, (((ConquestCompletedConquest)this).CategoryReq))))
                {
                    Conquests.CheckProgress <ConquestCompletedConquest>(p.Owner, new ConquestCompletedContainer(s));
                }
                //until lee implements his changes, handle it like I originally was doing
                //Conquests.InvalidateRecursiveConquests(p.Owner);
            }
        }
示例#12
0
        public ConquestStatesGump(
            PlayerMobile user, Gump parent = null, ConquestProfile profile = null, ConquestCategory category = null)
            : base(user, parent)
        {
            Title        = "Conquests";
            RootCategory = String.Empty;

            Profile = profile ?? Conquests.EnsureProfile(user);

            Category = category ?? String.Empty;

            Categories = new List <ConquestCategory>();

            ForceRecompile = true;

            CanMove = true;

            Sorted = true;

            EntriesPerPage = 4;
        }
示例#13
0
        public virtual void OnTierComplete(ConquestState s)
        {
            if (!Enabled || Deleted || s == null || s.Conquest != this || s.User == null)
            {
                return;
            }

            ConquestProfile p = Conquests.EnsureProfile(s.User);

            if (p != null)
            {
                p.Credit += Points;
            }

            if (s.TiersComplete || RewardTierComplete)
            {
                GiveRewards(s);
            }

            if (SoundOnComplete > 0)
            {
                s.User.PlaySound(SoundOnComplete);
            }

            if (!CentralGump.CentralGump.EnsureProfile(s.User).IgnoreConquests)
            {
                ConquestCompletedGump g = ConquestCompletedGump.Acquire(s);

                if (g != null)
                {
                    g.Send();
                }
            }

            if (Conquests.CMOptions.ModuleDebug)
            {
                Conquests.CMOptions.ToConsole("{0} tier complete: {1} ({2})", Name, s.User, s.Tier);
            }
        }
示例#14
0
        private void OnAddConquest(Type t)
        {
            Selected = Conquests.Create(t);

            Refresh(true);
        }
示例#15
0
 private void OnMyProfile()
 {
     Hide(true);
     Conquests.SendConquestsGump(User);
 }
示例#16
0
        public void UpdateProgress(int offset)
        {
            if (offset <= 0 || !ConquestExists)
            {
                return;
            }

            if (Completed)
            {
                _Progress = ProgressMax;
                return;
            }

            DateTime now = DateTime.Now;

            if (Conquest.TimeoutReset > TimeSpan.Zero && LastProgress + Conquest.TimeoutReset < now)
            {
                _Progress = 0;
                return;
            }

            LastProgress = now;

            var args = new ConquestProgressContainer(this, offset);

            Conquests.HandleProgress(args);

            offset = args.Offset;

            _Progress += offset;

            Conquest.OnProgress(this, offset);

            while (ProgressComplete && !Completed)
            {
                int pMax = ProgressMax;

                ++Tier;

                Conquest.OnTierComplete(this);

                Conquests.HandleTierCompleted(new ConquestTierCompletedContainer(this, Tier));

                if (TiersComplete)
                {
                    _Progress = pMax;
                    break;
                }

                _Progress -= pMax;
            }

            if (!Completed)
            {
                return;
            }

            _Progress = ProgressMax;

            CompletedDate = DateTime.Now;

            ConquestState wf = Conquests.FindWorldFirst(Conquest);

            if (wf == null && (Owner.AccessLevel == AccessLevel.Player || Owner.AccessLevel > AccessLevel.Player && Conquests.CMOptions.StaffWorldFirsts))
            {
                WorldFirst = true;

                Conquest.OnWorldFirst(this);
            }

            Conquests.HandleCompleted(new ConquestCompletedContainer(this));
        }
示例#17
0
        public virtual void GiveRewards(ConquestState s)
        {
            if (!Enabled || Deleted || s == null || s.Conquest != this || s.User == null)
            {
                return;
            }

            if (AccountBound)
            {
                var account = s.User.Account as Account;

                if (account == null)
                {
                    return;
                }

                string tag = account.GetTag(TagKey);

                if (!String.IsNullOrWhiteSpace(tag))
                {
                    return;
                }

                // Look for all players in the account that aren't the owner of the current conquest state.
                for (int i = 0; i < account.Length; i++)
                {
                    var pm = account[i] as PlayerMobile;

                    if (pm == null || pm == s.User)
                    {
                        continue;
                    }

                    ConquestProfile prof = Conquests.EnsureProfile(pm);

                    ConquestState state;

                    if (!prof.TryGetState(this, out state) || state == null || state == s || !state.Completed)
                    {
                        continue;
                    }

                    account.SetTag(TagKey, state.CompletedDate.ToSimpleString("t@h:m@ d-m-y"));
                    return;                     // get outta here, no rewards!
                }

                account.SetTag(TagKey, s.CompletedDate.ToSimpleString("t@h:m@ d-m-y"));
            }
            else
            {
                var account = s.User.Account as Account;

                if (account != null)
                {
                    account.RemoveTag(TagKey);                     // Remove the tag, just in case it was bound previously but isn't now.
                }
            }

            InvalidateRewardInfo();

            if (Rewards.Count == 0)
            {
                return;
            }

            var rewards     = new List <IEntity>();
            var attachments = new List <IXmlAttachment>();

            Rewards.ForEach(
                type =>
            {
                if (type == null)
                {
                    return;
                }

                int count = ScaleRewards ? s.Tier : 1;

                while (--count >= 0)
                {
                    var reward = type.CreateInstanceSafe <object>();

                    if (reward is Item)
                    {
                        var rewardItem = (Item)reward;

                        if (!OnBeforeGiveReward(s, rewardItem))
                        {
                            rewardItem.Delete();
                            return;
                        }

                        OnGiveReward(s, rewardItem);

                        if (!rewardItem.Deleted)
                        {
                            rewards.Add(rewardItem);
                        }
                    }
                    else if (reward is BaseCreature)
                    {
                        var rewardCreature = (BaseCreature)reward;

                        if (!OnBeforeGiveReward(s, rewardCreature))
                        {
                            rewardCreature.Delete();
                            return;
                        }

                        OnGiveReward(s, rewardCreature);

                        if (!rewardCreature.Deleted)
                        {
                            rewards.Add(rewardCreature);
                        }
                    }
                    else if (reward is Mobile)
                    {
                        var rewardMobile = (Mobile)reward;

                        if (!OnBeforeGiveReward(s, rewardMobile))
                        {
                            rewardMobile.Delete();
                            return;
                        }

                        OnGiveReward(s, rewardMobile);

                        if (!rewardMobile.Deleted)
                        {
                            rewards.Add(rewardMobile);
                        }
                    }
                    else if (reward is XmlAttachment)
                    {
                        var a = (XmlAttachment)reward;

                        if (!OnBeforeGiveReward(s, a))
                        {
                            a.Delete();
                            return;
                        }

                        OnGiveReward(s, a);

                        if (!a.Deleted)
                        {
                            attachments.Add(a);
                        }
                    }
                }
            });

            OnRewarded(s, rewards, attachments, true);
        }
示例#18
0
        public void Sync()
        {
            Registry.RemoveAll(s => s == null || !s.ConquestExists || !Conquests.Validate(s.Conquest, Owner));

            Conquests.ConquestRegistry.Values.Where(c => Conquests.Validate(c, Owner)).ForEach(c => EnsureState(c));
        }