Server.Engines.PartySystem.Party.Add C# (CSharp) Method

Add() public method

public Add ( Server.Mobile m ) : void
m Server.Mobile
return void
		public void Add( Mobile m )
		{
			PartyMemberInfo mi = this[m];

			if ( mi == null )
			{
				m_Members.Add( new PartyMemberInfo( m ) );
				m.Party = this;

				Packet memberList = Packet.Acquire( new PartyMemberList( this ) );
				Packet attrs = Packet.Acquire( new MobileAttributesN( m ) );

				for ( int i = 0; i < m_Members.Count; ++i )
				{
					Mobile f = ((PartyMemberInfo)m_Members[i]).Mobile;

					f.Send( memberList );

					if ( f != m )
					{
						f.Send( new MobileStatusCompact( m.CanBeRenamedBy( f ), m ) );
						f.Send( attrs );
						m.Send( new MobileStatusCompact( f.CanBeRenamedBy( m ), f ) );
						m.Send( new MobileAttributesN( f ) );
					}
				}

				Packet.Release( memberList );
				Packet.Release( attrs );
			}
		}

Usage Example

Ejemplo n.º 1
0
			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;
			}
All Usage Examples Of Server.Engines.PartySystem.Party::Add