Beispiel #1
0
// ---------------------------------------------------------
bool CPartyDef::SendMemberMsg( CChar *pCharDest, PacketSend *pPacket )
{
	ADDTOCALLSTACK("CPartyDef::SendMemberMsg");
	if ( !pCharDest )
	{
		SendAll(pPacket);
		return true;
	}

	// Weirdness check.
	if ( pCharDest->m_pParty != this )
	{
		if ( DetachChar(pCharDest) != m_Chars.BadIndex() )	// this is bad!
			return false;
		return true;
	}
	if ( !m_Chars.IsCharIn(pCharDest) )
	{
		pCharDest->m_pParty = NULL;
		return true;
	}

	if ( pCharDest->m_pClient )
	{
		pPacket->send(pCharDest->m_pClient);
		if ( *pPacket->getData() == PARTYMSG_Remove )
			pCharDest->m_pClient->addReSync();
	}

	return true;
}
Beispiel #2
0
size_t CCharRefArray::DetachChar( const CChar *pChar )
{
	ADDTOCALLSTACK("CCharRefArray::DetachChar");
	size_t i = FindChar(pChar);
	if ( i != m_uidCharArray.BadIndex() )
		DetachChar(i);
	return i;
}
Beispiel #3
0
bool CPartyDef::RemoveMember( CGrayUID uidRemove, CGrayUID uidCommand )
{
	ADDTOCALLSTACK("CPartyDef::RemoveMember");
	// ARGS:
	//  uidRemove = Who is being removed.
	//  uidCommand = who removed this person (only the master or self can remove)
	//
	// NOTE: remove of the master will cause the party to disband.

	if ( m_Chars.GetCharCount() <= 0 )
		return false;

	CGrayUID uidMaster = GetMaster();
	if ( (uidRemove != uidCommand) && (uidCommand != uidMaster) )
		return false;

	CChar *pCharRemove = uidRemove.CharFind();
	if ( !pCharRemove )
		return false;
	if ( !IsInParty(pCharRemove) )
		return false;
	if ( uidRemove == uidMaster )
		return Disband(uidMaster);

	CChar *pSrc = uidCommand.CharFind();
	if ( pSrc && IsTrigUsed(TRIGGER_PARTYREMOVE) )
	{
		CScriptTriggerArgs args;
		if ( pCharRemove->OnTrigger(CTRIG_PartyRemove, pSrc, &args) == TRIGRET_RET_TRUE )
			return false;
	}
	if ( IsTrigUsed(TRIGGER_PARTYLEAVE) )
	{
		if ( pCharRemove->OnTrigger(CTRIG_PartyLeave, pCharRemove, 0) == TRIGRET_RET_TRUE )
			return false;
	}

	// Remove it from the party
	SendRemoveList(pCharRemove, true);
	DetachChar(pCharRemove);
	pCharRemove->SysMessageDefault(DEFMSG_PARTY_LEAVE_2);

	TCHAR *pszMsg = Str_GetTemp();
	sprintf(pszMsg, g_Cfg.GetDefaultMsg(DEFMSG_PARTY_LEAVE_1), pCharRemove->GetName());
	SysMessageAll(pszMsg);

	if ( m_Chars.GetCharCount() <= 1 )
	{
		// Disband the party
		SysMessageAll(g_Cfg.GetDefaultMsg(DEFMSG_PARTY_LEAVE_LAST_PERSON));
		return Disband(uidMaster);
	}

	return true;
}
Beispiel #4
0
bool CPartyDef::FixWeirdness( CChar * pChar )
{
	ADDTOCALLSTACK("CPartyDef::FixWeirdness");
	if ( !pChar )
		return( false );

	if ( pChar->m_pParty != this )
		return( DetachChar( pChar ) != m_Chars.BadIndex() ); // this is bad!
	else if ( ! m_Chars.IsCharIn( pChar ))
	{
		pChar->m_pParty = NULL;
		return( true );
	}

	return( false );
}
Beispiel #5
0
size_t CCharRefArray::InsertChar( const CChar *pChar, size_t i )
{
	ADDTOCALLSTACK("CCharRefArray::InsertChar");
	size_t currentIndex = FindChar(pChar);
	if ( currentIndex != m_uidCharArray.BadIndex() )
	{
		if ( currentIndex == i )	// already there
			return i;
		DetachChar(currentIndex);	// remove from list
	}

	if ( !IsValidIndex(i) )		// prevent from being inserted too high
		i = GetCharCount();

	m_uidCharArray.InsertAt(i, pChar->GetUID() );
	return i;
}
Beispiel #6
0
bool CPartyDef::Disband( CGrayUID uidMaster )
{
	ADDTOCALLSTACK("CPartyDef::Disband");
	// Make sure i am the master.
	if ( m_Chars.GetCharCount() <= 0 )
		return false;
	if ( GetMaster() != uidMaster )
		return false;

	CChar *pMaster = GetMaster().CharFind();
	if ( pMaster && IsTrigUsed(TRIGGER_PARTYDISBAND) )
	{
		CScriptTriggerArgs args;
		if ( pMaster->OnTrigger(CTRIG_PartyDisband, pMaster, &args) == TRIGRET_RET_TRUE )
			return false;
	}

	SysMessageAll(g_Cfg.GetDefaultMsg(DEFMSG_PARTY_DISBANDED));

	CChar *pSrc = uidMaster.CharFind();
	size_t iQty = m_Chars.GetCharCount();
	ASSERT(iQty > 0);
	CChar *pChar = NULL;
	for ( size_t i = 0; i < iQty; i++ )
	{
		pChar = m_Chars.GetChar(i).CharFind();
		if ( !pChar )
			continue;

		if ( IsTrigUsed(TRIGGER_PARTYREMOVE) )
		{
			CScriptTriggerArgs args;
			args.m_iN1 = 1;
			pChar->OnTrigger(CTRIG_PartyRemove, pSrc, &args);
		}

		SendRemoveList(pChar, true);
		DetachChar(pChar);
	}

	delete this;	// should remove itself from the world list.
	return true;
}