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)); }
public static ConquestProfile EnsureProfile(PlayerMobile pm) { ConquestProfile p; var account = pm.Account as Account; if (account == null) { Console.WriteLine("NULL ACCOUNT?!"); return(null); } if (!Profiles.TryGetValue(pm, out p)) { foreach (PlayerMobile mobile in account.Mobiles.OfType <PlayerMobile>()) { if (Profiles.TryGetValue(mobile, out p)) { break; } } if (p == null) { Profiles.Add(pm, p = new ConquestProfile(pm)); } } else if (p == null) { Profiles[pm] = p = new ConquestProfile(pm); } return(p); }
private static bool DeserializeProfiles(GenericReader reader) { int version = reader.GetVersion(); switch (version) { case 1: { ConquestProfile[] list = reader.ReadBlockArray(() => new ConquestProfile(reader)); foreach (ConquestProfile p in list) { Profiles.AddOrReplace(p.Owner, p); } } break; case 0: { reader.ReadBlockDictionary( () => { var p = new ConquestProfile(reader); PlayerMobile s = p.Owner; return(new KeyValuePair <PlayerMobile, ConquestProfile>(s, p)); }, Profiles); } break; } return(true); }
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)); }
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; }
public static void CheckProgress <TCon>(PlayerMobile pm, object args, params object[] argsN) where TCon : Conquest { if (!CMOptions.ModuleEnabled || pm == null) { return; } ConquestProfile p = EnsureProfile(pm); if (p == null) { return; } if (argsN != null && argsN.Length > 0) { args = new[] { args }.Merge(argsN); } bool refresh = false; foreach (var c in FindConquests <TCon>(c => Validate(c, pm))) { var state = p.EnsureState(c); if (state == null || state.Conquest != c || state.Owner.Account != pm.Account || state.Completed) { continue; } state.User = pm; int progress = c.GetProgress(state, args); if (progress != 0) { refresh = true; } state.Progress += progress; } if (refresh) { RefreshGumps(pm); } }
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; }
public static void SendConquestsGump(PlayerMobile source, PlayerMobile target) { if (source == null) { if (target == null) { return; } source = target; } if (target == null) { target = source; } if (source.Deleted || target.Deleted || (!CMOptions.ModuleEnabled && source.AccessLevel < Access)) { return; } ConquestProfile p = EnsureProfile(target); if (p == null) { return; } p.Sync(); if (CMOptions.UseCategories) { new ConquestStatesGump(source, null, p).Send(); } else { new ConquestStateListGump(source, null, p).Send(); } }
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); } }
/*private static void CMConfig() * { * SetEvents(); * } * * private static void CMEnabled() * { * SetEvents(); * } * * private static void CMDisabled() * { * UnsetEvents(); * }*/ private static void CMInvoke() { CommandUtility.Register( "Conquests", AccessLevel.Player, e => { if (!CMOptions.ModuleEnabled && e.Mobile.AccessLevel < Access) { e.Mobile.SendMessage(0x22, "Conquests are currently unavailable."); return; } if (e.Mobile is PlayerMobile) { SendConquestsGump((PlayerMobile)e.Mobile); } }); CommandUtility.Register( "ConsolidateConquests", AccessLevel.Developer, e => { if (!CMOptions.ModuleEnabled && e.Mobile.AccessLevel < Access) { e.Mobile.SendMessage(0x22, "Conquests are currently unavailable."); return; } if (e.Mobile is PlayerMobile) { ConsolidateConquests(); } }); CommandUtility.Register( "CheckAccountsConquests", AccessLevel.Developer, e => { if (!(e.Mobile is PlayerMobile)) { return; } foreach (PlayerMobile player in Profiles.Keys) { IAccount account = player.Account; foreach (PlayerMobile checkplayer in Profiles.Keys) { if (player != checkplayer) { IAccount checkaccount = checkplayer.Account; if (account == checkaccount) { e.Mobile.SendMessage(54, "THIS SHOULDN'T HAPPEN"); } } } } }); CommandUtility.Register( "PruneConquests", AccessLevel.Developer, e => { if (!(e.Mobile is PlayerMobile)) { return; } PruneConquestProfiles(); }); //Removed until we can get VNC lists to handle large amounts of entries /* * CommandUtility.Register( * "ConquestProfiles", * Access, * e => * { * if (!CMOptions.ModuleEnabled && e.Mobile.AccessLevel < Access) * { * e.Mobile.SendMessage(0x22, "Conquests are currently unavailable."); * return; * } * * if (e.Mobile is PlayerMobile) * { * SendConquestProfilesGump((PlayerMobile)e.Mobile); * } * }); */ CommandUtility.Register( "ConquestAdmin", Access, e => { if (e.Mobile is PlayerMobile) { SendConquestAdminGump((PlayerMobile)e.Mobile); } }); CommandUtility.Register( "IncreaseConquestState", AccessLevel.Developer, e => { if (!(e.Mobile is PlayerMobile)) { return; } if (e.Arguments.Length < 2) { e.Mobile.SendMessage(0x22, "Format: <PlayerName> <ConquestName> <Amount>"); return; } string name = e.Arguments[0]; string conquest = e.Arguments[1]; int value; if (!Int32.TryParse(e.Arguments[2], out value)) { e.Mobile.SendMessage(0x22, "Format: <PlayerName> <ConquestName> <Amount>"); return; } if (e.Arguments.Length > 3) { e.Mobile.SendMessage(0x22, "Format: <PlayerName> <ConquestName> <Amount>"); return; } Mobile mobile = World.Mobiles.Values.FirstOrDefault(x => x.RawName == name && x is PlayerMobile); if (mobile is PlayerMobile) { ConquestProfile profile = EnsureProfile(mobile as PlayerMobile); ConquestState state; if (profile.TryGetState(ConquestRegistry.Values.FirstOrDefault(x => x.Name == conquest), out state)) { state.Progress += value; } } }); }
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); }