Exemplo n.º 1
0
        public ConquestState(PlayerMobile owner, Conquest conquest)
        {
            UID = new ConquestSerial();

            Conquest = conquest;
            Owner    = owner;

            EnsureDefaults();
        }
Exemplo n.º 2
0
        public static Conquest Create(Type t)
        {
            Conquest c = null;

            if (t != null && t.IsConstructableFrom <Conquest>())
            {
                Register(c = t.CreateInstanceSafe <Conquest>());
            }

            return(c);
        }
Exemplo n.º 3
0
        public static void WriteConquest(GenericWriter writer, Conquest c)
        {
            if (c != null && !c.Deleted)
            {
                writer.Write(true);

                c.UID.Serialize(writer);
            }
            else
            {
                writer.Write(false);
            }
        }
Exemplo n.º 4
0
        public static void Register(Conquest c)
        {
            if (c == null || c.Deleted)
            {
                return;
            }

            if (ConquestRegistry.ContainsKey(c.UID))
            {
                ConquestRegistry[c.UID] = c;
            }
            else
            {
                ConquestRegistry.Add(c.UID, c);
            }
        }
Exemplo n.º 5
0
        public static ConquestState FindWorldFirst(Conquest c)
        {
            if (c == null || c.Deleted)
            {
                return(null);
            }

            ConquestState state = null;

            if (Profiles.Values.Any(p => p != null && p.Owner != null && p.TryGetState(c, out state) && state.WorldFirst))
            {
                return(state);
            }

            return(null);
        }
Exemplo n.º 6
0
        public ConquestState EnsureState(Conquest c)
        {
            if (Owner == null || c == null)
            {
                return(null);
            }

            ConquestState state;

            if (!TryGetState(c, out state))
            {
                Registry.Add(state = new ConquestState(Owner, c));
            }

            return(state);
        }
Exemplo n.º 7
0
        public static ConquestRewardInfo EnsureInfo(Conquest c, Type t)
        {
            if (t == null)
            {
                return(null);
            }

            Dictionary <Type, ConquestRewardInfo> list;

            if (!RewardCache.TryGetValue(c, out list))
            {
                RewardCache.Add(c, list = new Dictionary <Type, ConquestRewardInfo>());
            }
            else if (list == null)
            {
                RewardCache[c] = list = new Dictionary <Type, ConquestRewardInfo>();
            }

            ConquestRewardInfo info;

            if (!list.TryGetValue(t, out info))
            {
                info = CreateInstance(t);

                if (info != null)
                {
                    list.Add(t, info);
                }
            }
            else if (info == null)
            {
                info = CreateInstance(t);

                if (info != null)
                {
                    list[t] = info;
                }
                else
                {
                    list.Remove(t);
                }
            }

            return(info);
        }
Exemplo n.º 8
0
        public static ConquestState FindReplacementWorldFirst(Conquest c)
        {
            if (c == null || c.Deleted || !c.Enabled)
            {
                return(null);
            }

            List <ConquestState> states = new List <ConquestState>();

            foreach (var p in Profiles.Values.Where(p => p != null && p.Owner != null))
            {
                ConquestState state;

                if (p.TryGetState(c, out state) && state.Completed && !state.WorldFirst)
                {
                    states.Add(state);
                }
            }

            return(states.OrderBy(s => s.CompletedDate.Ticks).FirstOrDefault());
        }
Exemplo n.º 9
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));
        }
Exemplo n.º 10
0
 public static bool Validate(Conquest c, PlayerMobile pm)
 {
     return(c != null && !c.Deleted && c.Enabled && (pm == null || (!c.Young || pm.Young)));
 }
Exemplo n.º 11
0
 public bool ContainsState(Conquest c)
 {
     return(c != null && Registry.Exists(s => s.Conquest == c));
 }
Exemplo n.º 12
0
 public bool RemoveState(Conquest c)
 {
     return(c != null && Registry.RemoveAll(s => s.Conquest == c) > 0);
 }
Exemplo n.º 13
0
        public bool TryGetState(Conquest c, out ConquestState state)
        {
            state = null;

            return(c != null && (state = Registry.FirstOrDefault(s => s.Conquest == c)) != null);
        }
Exemplo n.º 14
0
 public RewardTypesGump(PlayerMobile user, Conquest c, Gump parent = null)
     : base(user, parent, list: c.Rewards, title: c.Name + " Rewards List", emptyText: "No rewards to display.")
 {
     Conquest = c;
 }