public static bool DISBANDGROUP(TriggerObject trigObject, XmlGroup group)
			{
				return group != null && DISBANDGROUP(trigObject, group, false);
			}
			public static bool DISBANDGROUP(TriggerObject trigObject, XmlGroup group, bool forceDisband)
			{
				if (group == null || (group.Locked && !forceDisband))
				{
					return false;
				}

				// the only way to find the correct account tag to remove is going a round-about way
				foreach (Mobile mob in group.Members)
				{
					Account account = GETACCOUNT(trigObject, mob);

					if (account == null || account.GetTag(group.EventName) == null)
					{
						continue;
					}

					account.RemoveTag(group.EventName);
				}

				group.Delete();
				return true;
			}
			public static bool ADDTOGROUP(TriggerObject trigObject, Mobile mob, string eventName, XmlGroup grp)
			{
				if (mob == null || eventName == null || grp == null)
				{
					return false;
				}

				Account account = GETACCOUNT(trigObject, mob);

				if (account == null)
				{
					return false;
				}

				if (account.GetTag(eventName) != null)
				{
					return false; // already has that tag, can't add another one
				}

				if (grp.Members.Count >= grp.MaxMembers)
				{
					return false; // too many members
				}

				account.AddTag(eventName, (grp.AttachedTo).Serial.Value + "");

				// track the group tracking entity in the account tab
				grp.Members.Add(mob);

				return true;
			}
			public static XmlGroup CREATEGROUP(
				TriggerObject trigObject, Mobile captain, string eventName, IEntity groupTrackingObject)
			{
				if (captain == null)
				{
					throw new UberScriptException("CREATEGROUP: Cannot create group because captain was null!");
				}

				if (groupTrackingObject == null)
				{
					throw new UberScriptException("CREATEGROUP: Cannot create group because groupTrackingObject was null!");
				}

				if (eventName == null)
				{
					throw new UberScriptException("CREATEGROUP: Cannot create group because eventName was null!");
				}

				Account account = GETACCOUNT(trigObject, captain);

				if (account == null)
				{
					return null;
				}

				string tagValue = account.GetTag(eventName);

				if (tagValue != null)
				{
					// they are already in a group of that type
					return null;
				}

				XmlGroup newGroup = new XmlGroup(captain.RawName, eventName)
				{
					Captain = captain
				}; // RawNames are unique across the server

				XmlAttach.AttachTo(groupTrackingObject, newGroup);
				ADDTOGROUP(trigObject, captain, eventName, newGroup);

				return newGroup;
			}
			public static bool TRYCREATEGROUPPARTY(TriggerObject trigObject, XmlGroup grp, Type mobType)
			{
				return grp != null && TRYCREATEGROUPPARTY(trigObject, grp, mobType, true);
			}
			public static bool TRYCREATEGROUPPARTY(TriggerObject trigObject, XmlGroup grp, Type mobType, bool participantsOnly)
			{
				if (grp == null)
				{
					return false;
				}

				var mobsToParty = new List<Mobile>();
				var accountsToAdd = new List<Account>();

				if (participantsOnly)
				{
					if (grp.Participants.Count < 2)
					{
						return false;
					}

					accountsToAdd.AddRange(
						grp.Participants.Cast<Mobile>().Where(mob => mob.Account is Account).Select(mob => (Account)mob.Account));
				}
				else
				{
					if (grp.Members.Count < 2)
					{
						return false;
					}

					accountsToAdd.AddRange(
						grp.Members.Cast<Mobile>().Where(mob => mob.Account is Account).Select(mob => (Account)mob.Account));
				}

				foreach (NetState state in NetState.Instances.Where(ns => ns.Account is Account))
				{
					Account account = (Account)state.Account;

					if (!accountsToAdd.Contains(account))
					{
						continue;
					}

					if (mobType != null)
					{
						if (IS(null, state.Mobile, mobType))
						{
							mobsToParty.Add(state.Mobile);
						}
					}
					else
					{
						mobsToParty.Add(state.Mobile);
					}
				}

				if (mobsToParty.Count < 2)
				{
					return false;
				}

				// we need to bring them all into one party, so grab the first party available
				Party existingParty = null;
				var mobsToAddToExistingParty = new List<Mobile>();

				foreach (Mobile mobToParty in mobsToParty)
				{
					if (mobToParty.Party is Party)
					{
						if (existingParty == null)
						{
							existingParty = (Party)mobToParty.Party;
							continue;
						}

						if (mobToParty.Party == existingParty)
						{
							continue; // already in the party
						}

						try // get them out of the party they were in
						{
							((Party)mobToParty.Party).Remove(mobToParty);
							mobsToAddToExistingParty.Add(mobToParty);
						}
						catch
						{ }
					}
					else
					{
						// not in a party yet
						mobsToAddToExistingParty.Add(mobToParty);
					}
				}

				if (existingParty == null)
				{
					// create a new party and add them in
					Party newParty = new Party(mobsToParty[0]);

					mobsToParty[0].Party = newParty;

					for (int i = 1; i < mobsToParty.Count; i++)
					{
						newParty.Add(mobsToParty[i]);
					}
				}
				else
				{
					// add the mobs that weren't in the party into the existing one
					foreach (Mobile mob in mobsToAddToExistingParty)
					{
						existingParty.Add(mob);
					}
				}

				return true;
			}
			public static void GROUPMESSAGE(TriggerObject trigObject, XmlGroup grp, string message)
			{
				if (grp != null && !String.IsNullOrWhiteSpace(message))
				{
					GROUPMESSAGE(trigObject, grp, message, 0x3b2);
				}
			}
			public static void GROUPMESSAGE(TriggerObject trigObject, XmlGroup grp, string message, int hue)
			{
				if (grp == null || String.IsNullOrWhiteSpace(message))
				{
					return;
				}

				var accountList =
					grp.Members.Cast<Mobile>().Where(mob => mob.Account is Account).Select(mob => (Account)mob.Account).ToList();

				foreach (NetState state in
					NetState.Instances.Where(ns => ns.Mobile != null && ns.Account is Account && accountList.Contains(ns.Account)))
				{
					state.Mobile.SendMessage(hue, message);
				}
			}
			public static void SORTGROUPMEMBERS(TriggerObject trigObject, XmlGroup grp, string xmlValueName)
			{
				if (grp == null)
				{
					return;
				}

				ArrayList output = new ArrayList(grp.Members.Count);
				ArrayList scores = new ArrayList(grp.Members.Count); // parallel scores list--get the scores first
				Type xmlvalueType = typeof(XmlValue);

				foreach (XmlValue value in
					grp.Members.Cast<Mobile>().Select(member => GETATTACHMENT(null, member, xmlvalueType, xmlValueName) as XmlValue))
				{
					// @null: pretty sure they will be the worst score at -2 billion
					scores.Add(value == null ? Int32.MinValue : value.Value);
				}

				var tempScores = new List<int>(grp.Members.Count);

				for (int i = 0; i < grp.Members.Count; i++)
				{
					bool added = false;
					// scores is in the same ordder as group.Members
					Mobile thisMember = (Mobile)grp.Members[i];
					int thisMemberScore = (int)scores[i];

					for (int j = 0; j < output.Count; j++)
					{
						if (thisMemberScore <= tempScores[j])
						{
							continue;
						}

						output.Insert(j, thisMember);
						tempScores.Insert(j, thisMemberScore);
						added = true;
						break;
					}

					if (added)
					{
						continue;
					}

					// add to end of list
					output.Add(thisMember);
					tempScores.Add(thisMemberScore);
				}

				grp.Members = output;
			}
Пример #10
0
			public static Mobile GETGROUPMOB(TriggerObject trigObject, Mobile mob, XmlGroup grp)
			{
				if (mob == null || grp == null)
				{
					return null;
				}

				Account account = GETACCOUNT(trigObject, mob);

				return account == null ? null : grp.Members.Cast<Mobile>().FirstOrDefault(member => member.Account == account);
			}
Пример #11
0
			public static void AWARDGROUP(TriggerObject trigObject, XmlGroup grp, Item reward, int indexArg, string selector)
			{
				if (grp == null || reward == null)
				{
					return;
				}

				AwardGroupSelector awardGroupSelector;

				if (!Enum.TryParse(selector, out awardGroupSelector))
				{
					reward.Delete();
					throw new UberScriptException("Award selector invalid!");
				}

				DateTime now = DateTime.Now;

				switch (awardGroupSelector)
				{
					case AwardGroupSelector.Index:
						{
							if (grp.Members.Count > indexArg)
							{
								Mobile member = (Mobile)grp.Members[indexArg];

								LOCALMSG(
									null,
									member,
									"You received an award for your achievements in the " + grp.EventName +
									" event. It has been placed in your bankbox.");
								Item toAdd = DUPE(null, reward);

								if (toAdd != null)
								{
									member.BankBox.AddItem(toAdd);
									LoggingCustom.Log("UAwards.txt", now + "\t" + member + "\t" + toAdd);
								}
							}
						}
						break;
					case AwardGroupSelector.TopScorers:
						{
							for (int i = 0; i < grp.Members.Count; i++)
							{
								if (i >= indexArg)
								{
									break;
								}

								Mobile member = (Mobile)grp.Members[i];
								Item toAdd = DUPE(null, reward);

								if (toAdd == null)
								{
									continue;
								}

								member.BankBox.AddItem(toAdd);

								LoggingCustom.Log("UAwards.txt", now + "\t" + member + "\t" + toAdd);
								LOCALMSG(
									null,
									member,
									"You received an award for your achievements in the " + grp.EventName +
									" event. It has been placed in your bankbox.");
							}
						}
						break;
					case AwardGroupSelector.BottomScorers:
						{
							for (int i = grp.Members.Count - 1; i >= 0; i--)
							{
								if (i < grp.Members.Count - indexArg)
								{
									break;
								}

								Mobile member = (Mobile)grp.Members[i];
								Item toAdd = DUPE(null, reward);

								if (toAdd == null)
								{
									continue;
								}

								member.BankBox.AddItem(toAdd);

								LoggingCustom.Log("UAwards.txt", now + "\t" + member + "\t" + toAdd);
								LOCALMSG(
									null,
									member,
									"You received an award for your achievements in the " + grp.EventName +
									" event. It has been placed in your bankbox.");
							}
						}
						break;
				}

				// delete the original
				reward.Delete();
			}
Пример #12
0
			public static void AWARDGROUP(TriggerObject trigObject, XmlGroup grp, Item reward, int indexArg)
			{
				if (grp == null || reward == null)
				{
					AWARDGROUP(trigObject, grp, reward, indexArg, "TopScorers"); // give to all the team members
				}
			}
Пример #13
0
			/// <summary>
			///     Straight up award given to qualifying members of a group
			/// </summary>
			public static void AWARDGROUP(TriggerObject trigObject, XmlGroup grp, Item reward)
			{
				if (grp == null || reward == null)
				{
					AWARDGROUP(trigObject, grp, reward, 10000000); // give to all the team members
				}
			}
Пример #14
0
			public static int GETGROUPTOTALSCORE(TriggerObject trigObject, XmlGroup grp, string xmlValueName)
			{
				if (grp == null || xmlValueName == null)
				{
					return 0;
				}

				Type xmlvalueType = typeof(XmlValue);

				return
					grp.Members.Cast<Mobile>()
					   .Select(mob => GETATTACHMENT(null, mob, xmlvalueType, xmlValueName) as XmlValue)
					   .Where(value => value != null)
					   .Sum(value => value.Value);
			}
Пример #15
0
			public static XmlAttachment NEWATTACHMENT(TriggerObject trigObj, string attachmenttype, string name)
			{
				attachmenttype = attachmenttype.ToLower().Trim();

				XmlAttachment attachment = null;

				switch (attachmenttype)
				{
					case "xmlvalue":
						attachment = new XmlValue("", 0);
						break;
					case "xmllocalvariable":
						attachment = new XmlLocalVariable("");
						break;
					case "xmlscript":
						attachment = new XmlScript();
						break;
					case "xmlteam":
						attachment = new XmlTeam();
						break;
					case "xmldouble":
						attachment = new XmlDouble("", 0.0);
						break;
					case "xmlgroup":
						attachment = new XmlGroup();
						break;
					case "xmlslayer":
						attachment = new XmlSlayer("orcslaying", name);
						break;
					case "xmldate":
						attachment = new XmlDate("");
						break;
					case "xmlcorpseaction":
						attachment = new XmlCorpseAction();
						break;
					case "xmldeathaction":
						attachment = new XmlDeathAction();
						break;
					case "xmluse":
						attachment = new XmlUse();
						break;
					case "xmlonhit":
						attachment = new XmlOnHit();
						break;
					case "xmladdfame":
						attachment = new XmlAddFame(0);
						break;
					case "xmladdkarma":
						attachment = new XmlAddKarma(0);
						break;
					case "xmldex":
						attachment = new XmlDex();
						break;
					case "xmldialog":
						attachment = new XmlDialog();
						break;
					case "xmlenemymastery":
						attachment = new XmlEnemyMastery("");
						break;
					case "xmlfire":
						attachment = new XmlFire(1);
						break;
					case "xmlfreeze":
						attachment = new XmlFreeze();
						break;
					case "xmlhue":
						attachment = new XmlHue(0);
						break;
					case "xmllifedrain":
						attachment = new XmlLifeDrain(1);
						break;
					case "xmllightning":
						attachment = new XmlLightning(1);
						break;
					case "xmlmagicword":
						attachment = new XmlMagicWord();
						break;
					case "xmlmanadrain":
						attachment = new XmlManaDrain(1);
						break;
					case "xmlmessage":
						attachment = new XmlMessage("");
						break;
					case "xmlsaveitem":
						attachment = new XmlSaveItem();
						break;
					case "xmlskill":
						attachment = new XmlSkill("", "wrestling");
						break;
					case "xmlsound":
						attachment = new XmlSound();
						break;
					case "xmlstamdrain":
						attachment = new XmlStamDrain(1);
						break;
					case "xmlstr":
						attachment = new XmlStr();
						break;
					case "xmlint":
						attachment = new XmlInt();
						break;
				}

				if (attachment == null)
				{
					throw new UberScriptException("NEWATTACHMENT error: " + attachmenttype + " is not an available xmlattachment!");
				}

				if (attachment.Name == "" && name == null) // those attachments that require a name
				{
					return attachment;
				}

				attachment.Name = name;

				return attachment;
			}