public ConquestState(PlayerMobile owner, Conquest conquest) { UID = new ConquestSerial(); Conquest = conquest; Owner = owner; EnsureDefaults(); }
public static Conquest Create(Type t) { Conquest c = null; if (t != null && t.IsConstructableFrom <Conquest>()) { Register(c = t.CreateInstanceSafe <Conquest>()); } return(c); }
public static void WriteConquest(GenericWriter writer, Conquest c) { if (c != null && !c.Deleted) { writer.Write(true); c.UID.Serialize(writer); } else { writer.Write(false); } }
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); } }
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); }
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); }
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); }
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()); }
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)); }
public static bool Validate(Conquest c, PlayerMobile pm) { return(c != null && !c.Deleted && c.Enabled && (pm == null || (!c.Young || pm.Young))); }
public bool ContainsState(Conquest c) { return(c != null && Registry.Exists(s => s.Conquest == c)); }
public bool RemoveState(Conquest c) { return(c != null && Registry.RemoveAll(s => s.Conquest == c) > 0); }
public bool TryGetState(Conquest c, out ConquestState state) { state = null; return(c != null && (state = Registry.FirstOrDefault(s => s.Conquest == c)) != null); }
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; }