public void CrossReferenceDefinitions() { m_CrossReference = new Dictionary <Type, List <Int32> >(); for (Int32 i = 0; i < m_TitleDefinitions.Count; i++) { TitleDefinition def = m_TitleDefinitions[i]; if (def != null) { foreach (Type t in def.CreatureRegistry) { if (m_CrossReference.ContainsKey(t)) { m_CrossReference[t].Add(i); } else { m_CrossReference[t] = new List <int>() { i } }; } } } }
public void ApplyButtonPressed(IGumpComponent sender, object param) { String titleName = GetTextEntry("Definition Name"); Boolean enabled = GetCheck("Definition Enabled"); if (DataIsValid) { List <Type> creatureRegistry = new List <Type>(); List <TitleEntry> titleRegistry = new List <TitleEntry>(); for (int i = 0; i < 20; i++) { string name = GetTextEntry(String.Format("Creature_{0}", i)); Type type = ScriptCompiler.FindTypeByName(name); if (type != null) { creatureRegistry.Add(type); } } for (int i = 0; i < 10; i++) { string title = GetTextEntry(String.Format("Title_{0}", i)); string count = GetTextEntry(String.Format("Count_{0}", i)); Int32 cnt = 0; Int32.TryParse(count, out cnt); if (title != "" && cnt > 0) { titleRegistry.Add(new TitleEntry(title, cnt)); } } if (_TitleIndex < _TitleDefinitions.Count) { _TitleDefinitions[_TitleIndex] = new TitleDefinition(titleName, enabled, creatureRegistry, titleRegistry); } else { _TitleDefinitions.Add(new TitleDefinition(titleName, enabled, creatureRegistry, titleRegistry)); } if (Address != null) { Address.SendGump(new SlayerTitleSetupGump(_CoreEnabled, _TitleDefinitions, (_TitleIndex / 10) * 10)); } } else { if (Address != null) { Address.SendGump(new TitleDefinitionGump(_CoreEnabled, _TitleDefinitions, _TitleIndex, titleName, enabled, _CreatureNames, _Titles, _Counts, true)); } } }
private void Setup() { Add(new CustomCoreGumpling(365, 335, 0x80E, "Slayer Title System", _CoreEnabled, CoreEnableChanged, SlayerTitleCore.Core.Version, SaveButtonPressed)); Add(new GumpLabel(94, 60, 0x3E, "Registered Title Definitions")); List <TitleDefinition> titles = new List <TitleDefinition>(); Boolean lastEntryBlank = false; for (int i = _TitleIndex; i < _TitleDefinitions.Count && i < _TitleIndex + 10; i++) { titles.Add(_TitleDefinitions[i]); if (_TitleDefinitions[i].DefinitionName == "") { lastEntryBlank = true; } } bool anotherPage = false; if (titles.Count == 10) { anotherPage = true; } else if (!lastEntryBlank) { titles.Add(new TitleDefinition("", false, new List <Type>(), new List <TitleEntry>())); } if (_TitleIndex > 0) { Add(new GreyLeftArrow(10, 63, PreviousPagePressed)); } if (anotherPage) { Add(new GreyRightArrow(277, 63, NextPagePressed)); } Int32 counter = _TitleIndex; for (int i = 0; i < titles.Count; i++) { TitleDefinition def = titles[i]; LabelAddRemoveGumpling g = new LabelAddRemoveGumpling(counter++, 10, 80 + (i * 22), 285, def.DefinitionName, (def.Enabled ? HUE_Enabled : HUE_Disabled)); g.OnEdit += EditDefinitionPressed; g.OnRemove += RemoveDefinitionPressed; Add(g); } }
private void EventSink_OnKilledBy(OnKilledByEventArgs e) { if (!this.Enabled) { return; } BaseCreature creature = null; PlayerMobile player = null; if (e.Killed is BaseCreature) { creature = (BaseCreature)e.Killed; } if (e.KilledBy is PlayerMobile) { player = (PlayerMobile)e.KilledBy; } SlayerModule module = player.GetModule(typeof(SlayerModule)) as SlayerModule; if (module == null) { module = new SlayerModule(player); } if (m_CrossReference.ContainsKey(creature.GetType())) { foreach (Int32 index in m_CrossReference[creature.GetType()]) { if (index < m_TitleDefinitions.Count && m_TitleDefinitions[index].CreatureRegistry.Contains(creature.GetType())) { TitleDefinition def = m_TitleDefinitions[index]; module.IncrementCounter(def.DefinitionName); Int32 value = module.GetSlayerCount(def.DefinitionName); TitleEntry titleToSet = null; foreach (TitleEntry entry in def.TitleRegistry) { if (entry.CountNeeded == value) { titleToSet = entry; } } if (titleToSet != null) { foreach (TitleEntry entry in def.TitleRegistry) { if (player.CollectionTitles.Contains(entry.Title) && entry != titleToSet) { player.CollectionTitles.Remove(entry.Title); } } player.AddCollectionTitle(titleToSet.Title); player.SendSound(0x3D); player.SendMessage(0xC8, String.Format("Your have been awarded the title of '{0}' for {1} kills.", titleToSet.Title, value)); if (TitleAwarded != null) { TitleAwarded(player, def.DefinitionName, titleToSet.Title); } if (IsMaxTitle(titleToSet.Title, def.TitleRegistry) && MaximumTitleAchieved != null) { MaximumTitleAchieved(player, def.DefinitionName, titleToSet.Title); } } } } } }
public TitleDefinitionGump(Boolean coreEnabled, List<TitleDefinition> titleDefinitions, Int32 titleIndex, String definitionName, Boolean definitionEnabled, List<String> creatureNames, List<String> titles, List<String> counts, Boolean validate) : base(50, 100) { _CoreEnabled = coreEnabled; _TitleDefinitions = titleDefinitions; _TitleIndex = titleIndex; _CreatureNames = creatureNames; _Titles = titles; _Counts = counts; TitleDefinition definition; if (_TitleIndex < _TitleDefinitions.Count) definition = _TitleDefinitions[_TitleIndex]; else definition = new TitleDefinition("", false, new List<Type>(), new List<TitleEntry>()); if (_CreatureNames == null) { _CreatureNames = new List<string>(); _Titles = new List<string>(); _Counts = new List<string>(); foreach (Type t in definition.CreatureRegistry) _CreatureNames.Add(t.Name); foreach (TitleEntry entry in definition.TitleRegistry) { _Titles.Add(entry.Title); _Counts.Add(entry.CountNeeded.ToString()); } } Add(new StoneyBackground(730, 470)); Add(new GumpLabel(10, 5, 0x4F1, "Title Definition Name")); Add(new EntryField(150, 4, 570, "Definition Name", 0x0, (definitionName == null ? definition.DefinitionName : definitionName))); if (validate && (definitionName == null ? definition.DefinitionName : definitionName) == "") Add(new GumpLabel(100, 30, HUE_InvalidEntry, "Title Definition Name must be entered")); Add(new GumpLabel(10, 30, 0x54F, "Enabled")); Add(new GreyCheckbox(63, 25, "Definition Enabled", (definitionName == null ? definition.Enabled : definitionEnabled))); Add(new GumpImageTiled(2, 55, 722, 4, 0x13ED)); Add(new GumpLabel(300, 60, 0x3E, "Creature Registry")); Type typeCheck = typeof(BaseCreature); Boolean creaturesValid = true; for (int col = 0; col < 2; col++) { for (int row = 0; row < 10; row++) { Int32 idx = row + (col * 10); String name = ""; if (idx < _CreatureNames.Count) name = _CreatureNames[idx]; Type type = ScriptCompiler.FindTypeByName(name); Boolean valid = type != null || name == ""; if (typeCheck != null && type != null) valid &= typeCheck.IsAssignableFrom(type); creaturesValid &= valid; Add(new EntryField(10 + (col * 360), 80 + (row * 22), 350, String.Format("Creature_{0}", idx), (valid ? HUE_ValidEntry : HUE_InvalidEntry), name)); } } if (!creaturesValid) Add(new GumpLabel(10, 60, HUE_InvalidEntry, "Invalid BaseCreature Type Specified")); Boolean titlesValid = true; Add(new GumpLabel(314, 305, 0x3E, "Title Registry")); for (int col = 0; col < 2; col++) { for (int row = 0; row < 5; row++) { Int32 idx = row + (col * 5); String title = ""; String count = ""; if (idx < _Titles.Count) title = _Titles[idx]; if (idx < _Counts.Count) count = _Counts[idx]; if (title != "" && count == "") count = "0"; Int32 test; Boolean countValid = Int32.TryParse(count, out test); if (title != "" && count == "0") countValid = false; if (test < 0) countValid = false; if (title == "" && count == "") countValid = true; titlesValid &= countValid; Add(new EntryField(10 + (col * 360), 325 + (row * 22), 295, String.Format("Title_{0}", idx), HUE_ValidEntry, title)); Add(new EntryField(310 + (col * 360), 325 + (row * 22), 50, String.Format("Count_{0}", idx), (countValid ? HUE_ValidEntry : HUE_InvalidEntry), count)); } } if (!titlesValid) Add(new GumpLabel(10, 305, HUE_InvalidEntry, "Invalid Count Value Specified")); Add(new ApplyCancelGumpling(560, 440, ApplyButtonPressed, CancelButtonPressed)); }
public void ApplyButtonPressed(IGumpComponent sender, object param) { String titleName = GetTextEntry("Definition Name"); Boolean enabled = GetCheck("Definition Enabled"); if (DataIsValid) { List<Type> creatureRegistry = new List<Type>(); List<TitleEntry> titleRegistry = new List<TitleEntry>(); for (int i = 0; i < 20; i++) { string name = GetTextEntry(String.Format("Creature_{0}", i)); Type type = ScriptCompiler.FindTypeByName(name); if (type != null) creatureRegistry.Add(type); } for (int i = 0; i < 10; i++) { string title = GetTextEntry(String.Format("Title_{0}", i)); string count = GetTextEntry(String.Format("Count_{0}", i)); Int32 cnt = 0; Int32.TryParse(count, out cnt); if (title != "" && cnt > 0) titleRegistry.Add(new TitleEntry(title, cnt)); } if (_TitleIndex < _TitleDefinitions.Count) _TitleDefinitions[_TitleIndex] = new TitleDefinition(titleName, enabled, creatureRegistry, titleRegistry); else _TitleDefinitions.Add(new TitleDefinition(titleName, enabled, creatureRegistry, titleRegistry)); if (Address != null) Address.SendGump(new SlayerTitleSetupGump(_CoreEnabled, _TitleDefinitions, (_TitleIndex / 10) * 10)); } else { if (Address != null) Address.SendGump(new TitleDefinitionGump(_CoreEnabled, _TitleDefinitions, _TitleIndex, titleName, enabled, _CreatureNames, _Titles, _Counts, true)); } }
public TitleDefinitionGump(Boolean coreEnabled, List <TitleDefinition> titleDefinitions, Int32 titleIndex, String definitionName, Boolean definitionEnabled, List <String> creatureNames, List <String> titles, List <String> counts, Boolean validate) : base(50, 100) { _CoreEnabled = coreEnabled; _TitleDefinitions = titleDefinitions; _TitleIndex = titleIndex; _CreatureNames = creatureNames; _Titles = titles; _Counts = counts; TitleDefinition definition; if (_TitleIndex < _TitleDefinitions.Count) { definition = _TitleDefinitions[_TitleIndex]; } else { definition = new TitleDefinition("", false, new List <Type>(), new List <TitleEntry>()); } if (_CreatureNames == null) { _CreatureNames = new List <string>(); _Titles = new List <string>(); _Counts = new List <string>(); foreach (Type t in definition.CreatureRegistry) { _CreatureNames.Add(t.Name); } foreach (TitleEntry entry in definition.TitleRegistry) { _Titles.Add(entry.Title); _Counts.Add(entry.CountNeeded.ToString()); } } Add(new StoneyBackground(730, 470)); Add(new GumpLabel(10, 5, 0x4F1, "Title Definition Name")); Add(new EntryField(150, 4, 570, "Definition Name", 0x0, (definitionName == null ? definition.DefinitionName : definitionName))); if (validate && (definitionName == null ? definition.DefinitionName : definitionName) == "") { Add(new GumpLabel(100, 30, HUE_InvalidEntry, "Title Definition Name must be entered")); } Add(new GumpLabel(10, 30, 0x54F, "Enabled")); Add(new GreyCheckbox(63, 25, "Definition Enabled", (definitionName == null ? definition.Enabled : definitionEnabled))); Add(new GumpImageTiled(2, 55, 722, 4, 0x13ED)); Add(new GumpLabel(300, 60, 0x3E, "Creature Registry")); Type typeCheck = typeof(BaseCreature); Boolean creaturesValid = true; for (int col = 0; col < 2; col++) { for (int row = 0; row < 10; row++) { Int32 idx = row + (col * 10); String name = ""; if (idx < _CreatureNames.Count) { name = _CreatureNames[idx]; } Type type = ScriptCompiler.FindTypeByName(name); Boolean valid = type != null || name == ""; if (typeCheck != null && type != null) { valid &= typeCheck.IsAssignableFrom(type); } creaturesValid &= valid; Add(new EntryField(10 + (col * 360), 80 + (row * 22), 350, String.Format("Creature_{0}", idx), (valid ? HUE_ValidEntry : HUE_InvalidEntry), name)); } } if (!creaturesValid) { Add(new GumpLabel(10, 60, HUE_InvalidEntry, "Invalid BaseCreature Type Specified")); } Boolean titlesValid = true; Add(new GumpLabel(314, 305, 0x3E, "Title Registry")); for (int col = 0; col < 2; col++) { for (int row = 0; row < 5; row++) { Int32 idx = row + (col * 5); String title = ""; String count = ""; if (idx < _Titles.Count) { title = _Titles[idx]; } if (idx < _Counts.Count) { count = _Counts[idx]; } if (title != "" && count == "") { count = "0"; } Int32 test; Boolean countValid = Int32.TryParse(count, out test); if (title != "" && count == "0") { countValid = false; } if (test < 0) { countValid = false; } if (title == "" && count == "") { countValid = true; } titlesValid &= countValid; Add(new EntryField(10 + (col * 360), 325 + (row * 22), 295, String.Format("Title_{0}", idx), HUE_ValidEntry, title)); Add(new EntryField(310 + (col * 360), 325 + (row * 22), 50, String.Format("Count_{0}", idx), (countValid ? HUE_ValidEntry : HUE_InvalidEntry), count)); } } if (!titlesValid) { Add(new GumpLabel(10, 305, HUE_InvalidEntry, "Invalid Count Value Specified")); } Add(new ApplyCancelGumpling(560, 440, ApplyButtonPressed, CancelButtonPressed)); }
public TitleDefinitionGump(Mobile from, Boolean coreEnabled, List<TitleDefinition> titleDefinitions, Int32 titleIndex, List<String> creatureNames, List<String> titles, List<String> counts, Boolean validate) : base(50, 100) { m_From = from; m_CoreEnabled = coreEnabled; m_TitleDefinitions = titleDefinitions; m_TitleIndex = titleIndex; m_CreatureNames = creatureNames; m_Titles = titles; m_Counts = counts; TitleDefinition definition; if (m_TitleIndex < m_TitleDefinitions.Count) definition = m_TitleDefinitions[m_TitleIndex]; else definition = new TitleDefinition("", false, new List<Type>(), new List<TitleEntry>()); if (m_CreatureNames == null) { m_CreatureNames = new List<string>(); m_Titles = new List<string>(); m_Counts = new List<string>(); foreach (Type t in definition.CreatureRegistry) m_CreatureNames.Add(t.Name); foreach (TitleEntry entry in definition.TitleRegistry) { m_Titles.Add(entry.Title); m_Counts.Add(entry.CountNeeded.ToString()); } } m_From.CloseGump(typeof(SlayerTitleSetupGump)); m_From.CloseGump(typeof(TitleDefinitionGump)); this.AddPage(0); this.AddBackground(0, 0, 730, 470, 5100); this.AddLabel(10, 5, 1265, "Title Definition Name"); this.AddImageTiled(150, 4, 570, 23, 2624); this.AddImageTiled(151, 5, 568, 21, 3004); this.AddTextEntry(154, 5, 565, 21, 0, ID_DefinitionName, definition.DefinitionName); if (validate && definition.DefinitionName == "") this.AddLabel(100, 30, HUE_InvalidEntry, "Title Definition Name must be entered"); this.AddLabel(10, 30, 1359, "Enabled"); this.AddCheck(63, 25, 9720, 9724, definition.Enabled, ID_DefinitionEnabled); this.AddImageTiled(2, 55, 722, 4, 5101); this.AddLabel(300, 60, 62, "Creature Registry"); Type typeCheck = typeof(BaseCreature); Boolean creaturesValid = true; for (int col = 0; col < 2; col++) { for (int row = 0; row < 10; row++) { Int32 idx = row + (col * 10); String name = ""; if (idx < m_CreatureNames.Count) name = m_CreatureNames[idx]; Type type = ScriptCompiler.FindTypeByName(name); Boolean valid = type != null || name == ""; if (typeCheck != null && type != null) valid &= typeCheck.IsAssignableFrom(type); creaturesValid &= valid; this.AddImageTiled(10 + (col * 360), 80 + (row * 22), 350, 23, 2624); this.AddImageTiled(11 + (col * 360), 81 + (row * 22), 348, 21, 3004); this.AddTextEntry(14 + (col * 360), 81 + (row * 22), 345, 21, (valid ? HUE_ValidEntry : HUE_InvalidEntry), ID_CreatureEntry + idx, name); } } if (!creaturesValid) this.AddLabel(10, 60, HUE_InvalidEntry, "Invalid BaseCreature Type Specified"); Boolean titlesValid = true; this.AddLabel(314, 305, 62, "Title Registry"); for (int col = 0; col < 2; col++) { for (int row = 0; row < 5; row++) { Int32 idx = row + (col * 5); String title = ""; String count = ""; if (idx < m_Titles.Count) title = m_Titles[idx]; if (idx < m_Counts.Count) count = m_Counts[idx]; if (title != "" && count == "") count = "0"; Int32 test; Boolean countValid = Int32.TryParse(count, out test); if (title != "" && count == "0") countValid = false; if (test < 0) countValid = false; if (title == "" && count == "") countValid = true; titlesValid &= countValid; this.AddImageTiled(10 + (col * 360), 325 + (row * 22), 295, 23, 2624); this.AddImageTiled(11 + (col * 360), 326 + (row * 22), 293, 21, 3004); this.AddTextEntry(14 + (col * 360), 326 + (row * 22), 290, 21, HUE_ValidEntry, ID_TitleEntry + idx, title); this.AddImageTiled(310 + (col * 360), 325 + (row * 22), 50, 23, 2624); this.AddImageTiled(311 + (col * 360), 326 + (row * 22), 48, 21, 3004); this.AddTextEntry(314 + (col * 360), 326 + (row * 22), 45, 21, (countValid ? HUE_ValidEntry : HUE_InvalidEntry), ID_CountNeededEntry + idx, count); } } if (!titlesValid) this.AddLabel(10, 305, HUE_InvalidEntry, "Invalid Count Value Specified"); this.AddButton(560, 440, 5204, 5205, ID_Apply_Button, GumpButtonType.Reply, 0); this.AddButton(645, 440, 5200, 5201, ID_Cancel_Button, GumpButtonType.Reply, 0); }
public override void OnResponse(Server.Network.NetState sender, RelayInfo info) { String titleName = info.GetTextEntry(ID_DefinitionName).Text.Trim(); Boolean enabled = info.IsSwitched(ID_DefinitionEnabled); switch (info.ButtonID) { case ID_Apply_Button: if (IsDataValid(sender, info)) { List<Type> creatureRegistry = new List<Type>(); List<TitleEntry> titleRegistry = new List<TitleEntry>(); for (int i = 0; i < 20; i++) { string name = info.GetTextEntry(ID_CreatureEntry + i).Text; Type type = ScriptCompiler.FindTypeByName(name); if (type != null) creatureRegistry.Add(type); } for (int i = 0; i < 10; i++) { string title = info.GetTextEntry(ID_TitleEntry + i).Text; string count = info.GetTextEntry(ID_CountNeededEntry + i).Text; Int32 cnt = 0; Int32.TryParse(count, out cnt); if (title != "" && cnt > 0) titleRegistry.Add(new TitleEntry(title, cnt)); } if (m_TitleIndex < m_TitleDefinitions.Count) m_TitleDefinitions[m_TitleIndex] = new TitleDefinition(titleName, enabled, creatureRegistry, titleRegistry); else m_TitleDefinitions.Add(new TitleDefinition(titleName, enabled, creatureRegistry, titleRegistry)); sender.Mobile.SendGump(new SlayerTitleSetupGump(sender.Mobile, m_CoreEnabled, m_TitleDefinitions, (m_TitleIndex / 10) * 10)); } else { if (m_TitleIndex < m_TitleDefinitions.Count) m_TitleDefinitions[m_TitleIndex] = new TitleDefinition(titleName, enabled, m_TitleDefinitions[m_TitleIndex].CreatureRegistry, m_TitleDefinitions[m_TitleIndex].TitleRegistry); else m_TitleDefinitions.Add(new TitleDefinition(titleName, enabled, new List<Type>(), new List<TitleEntry>())); sender.Mobile.SendGump(new TitleDefinitionGump(sender.Mobile, m_CoreEnabled, m_TitleDefinitions, m_TitleIndex, m_CreatureNames, m_Titles, m_Counts, true)); } break; default: sender.Mobile.SendGump(new SlayerTitleSetupGump(sender.Mobile, m_CoreEnabled, m_TitleDefinitions, (m_TitleIndex / 10) * 10)); break; } }