Example #1
0
bool CChar::CheckCorpseCrime( const CItemCorpse *pCorpse, bool fLooting, bool fTest )
{
	ADDTOCALLSTACK("CChar::CheckCorpseCrime");
	// fLooting = looting as apposed to carving.
	// RETURN: true = criminal act !

	if ( !pCorpse || !g_Cfg.m_fLootingIsACrime )
		return false;

	CChar *pCharGhost = pCorpse->m_uidLink.CharFind();
	if ( !pCharGhost || pCharGhost == this )
		return false;

	if ( pCharGhost->Noto_GetFlag(this) == NOTO_GOOD )
	{
		if ( !fTest )
		{
			// Anyone saw me doing this?
			CheckCrimeSeen(SKILL_NONE, pCharGhost, pCorpse, fLooting ? g_Cfg.GetDefaultMsg(DEFMSG_LOOTING_CRIME) : NULL);
			Noto_Criminal();
		}
		return true;
	}
	return false;
}
Example #2
0
bool clearTradesFunctor( CBaseObject *a, UI32 &b, void *extraData )
{
	bool retVal = true;
	if( ValidateObject( a ) && a->CanBeObjType( OT_ITEM ) )
	{
		// Body of the functor goes here
		CItem *i = static_cast< CItem * >(a);
		if( ValidateObject( i ) )
		{
			if( i->GetType() == IT_TRADEWINDOW )
			{
				CChar *k = FindItemOwner( i );
				if( ValidateObject( k ) )
				{
					CItem *p = k->GetPackItem();
					if( ValidateObject( p ) )
					{
						CDataList< CItem * > *iCont = i->GetContainsList();
						for( CItem *j = iCont->First(); !iCont->Finished(); j = iCont->Next() )
						{
							if( ValidateObject( j ) )
								j->SetCont( p );
						}
					}
				}
				i->Delete();
				++b;	// let's track how many we cleared
			}
		}
	}
	return retVal;
}
Example #3
0
//o--------------------------------------------------------------------------o
//|	Function		-	Cleanup( void )
//|	Date			-	26th September, 2001
//|	Programmer		-	Abaddon
//|	Modified		-
//o--------------------------------------------------------------------------o
//|	Purpose			-	Makes sure that any items and chars inside the multi
//|						are removed
//o--------------------------------------------------------------------------o
void CMultiObj::Cleanup( void )
{
	for( CItem *iRemove = itemInMulti.First(); !itemInMulti.Finished(); iRemove = itemInMulti.Next() )
	{
		if( ValidateObject( iRemove ) )
		{
			ItemTypes iType = iRemove->GetType();
			if( iType == IT_DOOR || iType == IT_LOCKEDDOOR || iType == IT_HOUSESIGN )
				iRemove->Delete();
			else
			{
				if( iRemove->IsLockedDown() )
					iRemove->SetMovable( 1 );
				iRemove->SetMulti( INVALIDSERIAL );
				iRemove->SetZ( GetZ() );
			}
		}
	}
	for( CChar *cRemove = charInMulti.First(); !charInMulti.Finished(); cRemove = charInMulti.Next() )
	{
		if( ValidateObject( cRemove ) )
		{
			cRemove->SetMulti( INVALIDSERIAL );
			cRemove->SetZ( GetZ() );
		}
	}
	CItem::Cleanup();
}
Example #4
0
bool CSector::v_AllClients( CScript & s, CTextConsole * pSrc )
{
	ADDTOCALLSTACK("CSector::v_AllClients");
	CScript script(s.GetArgStr());
	CChar * pChar = NULL;
	bool fRet = false;

	// Loop through all the characters in m_Chars_Active.
	// We should start at the end incase some are removed during the loop.
	size_t i = m_Chars_Active.GetCount();
	while ( i > 0 )
	{
		pChar = STATIC_CAST <CChar*>(m_Chars_Active.GetAt(--i));

		// Check that a character was returned and keep looking if not.
		if (pChar == NULL)
			continue;

		// Check that the character is a client (we only want to affect
		// clients with this)
		if ( ! pChar->IsClient())
			continue;

		// Execute the verb on the client
		fRet |= pChar->r_Verb(script, pSrc);
	}
	return fRet;
}
Example #5
0
//o---------------------------------------------------------------------------o
//|   Function   : void restockNPC(CChar *i, bool stockAll)
//|   Date       : Unknown
//|   Programmer : UOX3 DevTeam
//o---------------------------------------------------------------------------o
//|   Purpose    : Restock NPC Vendors
//o---------------------------------------------------------------------------o
void restockNPC(CChar& i, bool stockAll)
{
    if (!i.IsShop())
        return; // if we aren't a shopkeeper, why bother?

    CItem *ci = i.GetItemAtLayer(IL_SELLCONTAINER);
    if (ValidateObject(ci))
    {
        CDataList< CItem * > *ciCont = ci->GetContainsList();
        for (CItem *c = ciCont->First(); !ciCont->Finished(); c = ciCont->Next())
            if (ValidateObject(c))
            {
                if (stockAll)
                {
                    c->IncAmount(c->GetRestock());
                    c->SetRestock(0);
                }
                else if (c->GetRestock())
                {
                    UI16 stockAmt = UOX_MIN(c->GetRestock(), static_cast<UI16>((c->GetRestock() / 2) + 1));
                    c->IncAmount(stockAmt);
                    c->SetRestock(c->GetRestock() - stockAmt);
                }

                if (cwmWorldState->ServerData()->TradeSystemStatus()) 
                {
                    CTownRegion *tReg = calcRegionFromXY(i.GetX(), i.GetY(), i.WorldNumber());
                    Items->StoreItemRandomValue(c, tReg);
                }
            }
    }
}
Example #6
0
int CItemMemory::FixWeirdness()
{
	ADDTOCALLSTACK("CItemMemory::FixWeirdness");
	int iResultCode = CItem::FixWeirdness();
	if ( iResultCode )
		return iResultCode;

	if ( !IsItemEquipped() || (GetEquipLayer() != LAYER_SPECIAL) || !GetMemoryTypes() )	// has to be a memory of some sort.
		return 0x4222;	// get rid of it.

	CChar *pChar = dynamic_cast<CChar *>(GetParent());
	if ( !pChar )
		return 0x4223;	// get rid of it.

	// Make sure guild/town memories are linked correctly
	if ( IsMemoryTypes(MEMORY_GUILD|MEMORY_TOWN) )
	{
		const CItemStone *pStone = pChar->Guild_Find(static_cast<MEMORY_TYPE>(GetMemoryTypes()));
		if ( !pStone || pStone->GetUID() != m_uidLink )
			return 0x4224;	// get rid of it.
		if ( !pStone->GetMember(pChar) )
			return 0x4225;	// get rid of it.
	}

	// Make sure guard memories are linked correctly (this is not an ERROR, just make the item decay on next tick)
	if ( IsMemoryTypes(MEMORY_GUARD) && !m_uidLink.ObjFind() )
	{
		SetAttr(ATTR_DECAY);
		SetTimeout(0);
	}
	return 0;
}
Example #7
0
// ---------------------------------------------------------
bool CPartyDef::DeclineEvent( CChar * pCharDecline, CGrayUID uidInviter )	// static
{
	ADDTOCALLSTACK("CPartyDef::DeclineEvent");
	// This should happen after a timeout as well.
	// " You notify %s that you do not wish to join the party"

	CChar * pCharInviter = uidInviter.CharFind();
	if ( !pCharInviter || !pCharDecline )
		return( false );
	if ( uidInviter == pCharDecline->GetUID() )
		return( false );

	CVarDefCont * sTempVal = pCharInviter->GetTagDefs()->GetKey("PARTY_LASTINVITE");
	if ( !sTempVal )
		return( false );
	if ((DWORD)sTempVal->GetValNum() != (DWORD)pCharDecline->GetUID())
		return( false );

	// Remove the key
	pCharInviter->DeleteKey("PARTY_LASTINVITE");

	TCHAR * sTemp = Str_GetTemp();
	sprintf(sTemp, g_Cfg.GetDefaultMsg(DEFMSG_PARTY_DECLINE_2), static_cast<LPCTSTR>(pCharInviter->GetName()));
	pCharDecline->SysMessage( sTemp );
	sTemp = Str_GetTemp();
	sprintf(sTemp, g_Cfg.GetDefaultMsg(DEFMSG_PARTY_DECLINE_1), static_cast<LPCTSTR>(pCharDecline->GetName()));
	pCharInviter->SysMessage( sTemp );

	return( true );
}
Example #8
0
void CSector::SetLightNow( bool fFlash )
{
	ADDTOCALLSTACK("CSector::SetLightNow");
	// Set the light level for all the CClients here.

	CChar * pChar = static_cast<CChar *>( m_Chars_Active.GetHead());
	for ( ; pChar != NULL; pChar = pChar->GetNext())
	{
		if ( pChar->IsStatFlag( STATF_DEAD | STATF_NightSight ))
			continue;

		if ( pChar->m_pClient )
		{
			if ( fFlash )	// This does not seem to work predicably !
			{
				BYTE bPrvLight = m_Env.m_Light;
				m_Env.m_Light = LIGHT_BRIGHT;	// full bright.
				pChar->m_pClient->addLight();
				m_Env.m_Light = bPrvLight;	// back to previous.
			}
			pChar->m_pClient->addLight();
		}

		// don't fire trigger when server is loading or light is flashing
		if (( ! g_Serv.IsLoading() && fFlash == false ) && ( IsTrigUsed(TRIGGER_ENVIRONCHANGE) ))
		{
			pChar->OnTrigger( CTRIG_EnvironChange, pChar );
		}
	}
}
Example #9
0
bool CSector::v_AllClients( CScript & s, CTextConsole * pSrc )
{
	ADDTOCALLSTACK("CSector::v_AllClients");
	CScript script(s.GetArgStr());
	script.m_iResourceFileIndex = s.m_iResourceFileIndex;	// Index in g_Cfg.m_ResourceFiles of the CResourceScript (script file) where the CScript originated
	script.m_iLineNum = s.m_iLineNum;						// Line in the script file where Key/Arg were read
	CChar * pChar = nullptr;
	bool fRet = false;

	// Loop through all the characters in m_Chars_Active.
	// We should start at the end incase some are removed during the loop.
	size_t i = m_Chars_Active.GetCount();
	while ( i > 0 )
	{
		pChar = static_cast <CChar*>(m_Chars_Active.GetAt(--i));

		// Check that a character was returned and keep looking if not.
		if (pChar == nullptr)
			continue;

		// Check that the character is a client (we only want to affect clients with this)
		if ( ! pChar->IsClient())
			continue;

		// Execute the verb on the client
		fRet |= pChar->r_Verb(script, pSrc);
	}
	return fRet;
}
Example #10
0
void CSector::GoSleep()
{
    ADDTOCALLSTACK("CSector::Sleep");
    ProfileTask charactersTask(PROFILE_TIMERS);
    CTimedObject::GoSleep();

    CChar * pCharNext = nullptr;
    CChar * pChar = static_cast <CChar*>(m_Chars_Active.GetHead());
    for (; pChar != nullptr; pChar = pCharNext)
    {
		pCharNext = pChar->GetNext();
        if (!pChar->IsSleeping())
            pChar->GoSleep();
    }

    CItem * pItemNext = nullptr;
    CItem * pItem = static_cast <CItem*>(m_Items_Timer.GetHead());
    for (; pItem != nullptr; pItem = pItemNext)
    {
		pItemNext = pItem->GetNext();
        if (!pItem->IsSleeping())
			pItem->GoSleep();
    }
    pItemNext = nullptr;
    pItem = static_cast <CItem*>(m_Items_Inert.GetHead());
    for (; pItem != nullptr; pItem = pItemNext)
    {
        pItemNext = pItem->GetNext();
		if (!pItem->IsSleeping())
	        pItem->GoSleep();
    }
}
Example #11
0
// Create an NPC from script.
void CChar::NPC_LoadScript( bool fRestock )
{
	ADDTOCALLSTACK("CChar::NPC_LoadScript");
	if ( m_pNPC == NULL )
		// Set a default brian type til we get the real one from scripts.
		SetNPCBrain(GetNPCBrain(false));	// should have a default brain. watch out for override vendor.

	CCharBase * pCharDef = Char_GetDef();

	// 1) CHARDEF trigger
	if ( m_pPlayer == NULL ) //	CHARDEF triggers (based on body type)
	{
		CChar * pChar = this->GetChar();
		if ( pChar != NULL )
		{
			CUID uidOldAct = pChar->m_Act_Targ;
			pChar->m_Act_Targ = GetUID();
			pChar->ReadScriptTrig(pCharDef, CTRIG_Create);
			pChar->m_Act_Targ = uidOldAct;
		}
	}
	//This remains untouched but moved after the chardef's section
	if (( fRestock ) && ( IsTrigUsed(TRIGGER_NPCRESTOCK) ))
		ReadScriptTrig(pCharDef, CTRIG_NPCRestock);

	CreateNewCharCheck();	//This one is giving stats, etc to the char, so we can read/set them in the next triggers.
}
Example #12
0
void CItem::Spawn_KillChildren()
{
	// kill all creatures spawned from this !
	DEBUG_CHECK( IsType(IT_SPAWN_CHAR));
	int iCurrent = m_itSpawnChar.m_current;

	for ( int j = 0; j < 256; j++ )	// loop through all maps
	{
		if ( !g_MapList.m_maps[j] ) continue;		// skip unsupported maps

		for ( int i = 0; i < g_MapList.GetSectorQty(j); i++ )
		{
			CSector * pSector = g_World.GetSector(j, i);
			ASSERT(pSector);
			CChar * pCharNext;
			CChar * pChar = STATIC_CAST <CChar*>( pSector->m_Chars_Active.GetHead());
			for ( ; pChar!=NULL; pChar = pCharNext )
			{
				pCharNext = pChar->GetNext();
				if ( pChar->NPC_IsSpawnedBy( this ))
				{
					pChar->Delete();
					iCurrent --;
				}
			}
		}
	}
	if (iCurrent && ! g_Serv.IsLoading())
	{
		DEBUG_CHECK(iCurrent==0);
	}
	m_itSpawnChar.m_current = 0;	// Should not be necessary
	Spawn_OnTick( false );
}
CStoneMember::~CStoneMember()
{
	CItemStone * pStone = GetParentStone();
	if ( ! pStone )
		return;

	RemoveSelf();

	if ( m_iPriv == STONEPRIV_ENEMY )
	{
		// same as declaring peace.
		CItemStone * pStoneEnemy = dynamic_cast <CItemStone *>( GetLinkUID().ItemFind());
		if ( pStoneEnemy != NULL )
		{
			pStoneEnemy->TheyDeclarePeace( pStone, true );
		}
	}
	else if ( pStone->GetMemoryType())
	{
		// If we remove a char with good loyalty we may have changed the vote count.
		pStone->ElectMaster();

		CChar * pChar = GetLinkUID().CharFind();
		if ( pChar )
		{
			pChar->Memory_ClearTypes(static_cast<WORD>(pStone->GetMemoryType())); 	// Make them forget they were ever in this guild
		}
	}
}
Example #14
0
void CSector::Restock()
{
    ADDTOCALLSTACK("CSector::Restock");
    // ARGS: iTime = time in seconds
    // set restock time of all vendors in Sector.
    // set the respawn time of all spawns in Sector.

    CChar * pCharNext;
    CChar * pChar = dynamic_cast <CChar*>(m_Chars_Active.GetHead());
    for (; pChar; pChar = pCharNext)
    {
        pCharNext = pChar->GetNext();
        if (pChar->m_pNPC)
        {
            pChar->NPC_Vendor_Restock(true);
        }
    }

    CItem * pItemNext;
    CItem * pItem = dynamic_cast <CItem*>(m_Items_Timer.GetHead());
    for (; pItem; pItem = pItemNext)
    {
        pItemNext = pItem->GetNext();
        if (pItem->IsType(IT_SPAWN_ITEM) || pItem->IsType(IT_SPAWN_CHAR) || pItem->IsType(IT_SPAWN_CHAMPION))
        {
            CCSpawn *pSpawn = pItem->GetSpawn();
            if (pSpawn)
            {
                pSpawn->OnTickComponent();
            }
        }
    }
}
Example #15
0
void CItemSpawn::AddObj(CGrayUID uid)
{
	ADDTOCALLSTACK("CitemSpawn:AddObj");
	// NOTE: This function is also called when loading spawn items
	// on server startup. In this case, some objs UID still invalid
	// (not loaded yet) so just proceed without any checks.

	bool bIsSpawnChar = IsType(IT_SPAWN_CHAR);
	if ( !g_Serv.IsLoading() )
	{
		if ( !uid.IsValidUID() )
			return;

		if ( bIsSpawnChar )				// IT_SPAWN_CHAR can only spawn NPCs
		{
			CChar *pChar = uid.CharFind();
			if ( !pChar || !pChar->m_pNPC )
				return;
		}
		else if ( !uid.ItemFind() )		// IT_SPAWN_ITEM can only spawn items
			return;

		CItemSpawn *pPrevSpawn = static_cast<CItemSpawn*>(uid.ObjFind()->m_uidSpawnItem.ItemFind());
		if ( pPrevSpawn )
		{
			if ( pPrevSpawn == this )		// obj already linked to this spawn
				return;
			pPrevSpawn->DelObj(uid);		// obj linked to other spawn, remove the link before proceed
		}
	}

	BYTE iMax = maximum(GetAmount(), 1);
	for (BYTE i = 0; i < iMax; i++ )
	{
		if ( !m_obj[i].IsValidUID() )
		{
			m_obj[i] = uid;
			m_currentSpawned++;

			// objects are linked to the spawn at each server start
			if ( !g_Serv.IsLoading() )
			{
				uid.ObjFind()->m_uidSpawnItem = GetUID();
				if ( bIsSpawnChar )
				{
					CChar *pChar = uid.CharFind();
					ASSERT(pChar->m_pNPC);
					pChar->StatFlag_Set(STATF_Spawned);
					pChar->m_ptHome = GetTopPoint();
					pChar->m_pNPC->m_Home_Dist_Wander = static_cast<WORD>(m_itSpawnChar.m_DistMax);
				}
			}
			break;
		}
	}
	if ( !g_Serv.IsLoading() )
		ResendTooltip();
}
Example #16
0
bool CRegionBase::r_Verb( CScript & s, CTextConsole * pSrc ) // Execute command from script
{
	ADDTOCALLSTACK("CRegionBase::r_Verb");
	EXC_TRY("Verb");
	LPCTSTR pszKey = s.GetKey();

	if ( !strnicmp(pszKey, "CLEARTAGS", 9) )
	{
		pszKey = s.GetArgStr();
		SKIP_SEPARATORS(pszKey);
		m_TagDefs.ClearKeys(pszKey);
		return true;
	}	

	int index = FindTableSorted(pszKey, sm_szVerbKeys, COUNTOF(sm_szVerbKeys) - 1);
	if ( index < 0 )
	{
		index = FindTableSorted(s.GetKey(), CSector::sm_szVerbKeys, SEV_QTY);
		if ( index >= 0 )
			return SendSectorsVerb(s.GetKey(), s.GetArgRaw(), pSrc);
	}

	switch ( static_cast<RV_TYPE>(index) )
	{
		case RV_ALLCLIENTS:
		{
			ClientIterator it;
			for (CClient* pClient = it.next(); pClient != NULL; pClient = it.next())
			{
				CChar * pChar = pClient->GetChar();
				if ( !pChar || (pChar->m_pArea != this) )
					continue;

				CScript script( s.GetArgStr() );
				pChar->r_Verb(script, pSrc);
			}
			return true;
		}
		case RV_TAGLIST:
		{
			m_TagDefs.DumpKeys( pSrc, "TAG." );
			return true;
		}

		default:
			break;
	}

	return CScriptObj::r_Verb(s, pSrc);
	EXC_CATCH;

	EXC_DEBUG_START;
	g_Log.EventDebug("command '%s' args '%s' [%p]\n", s.GetKey(), s.GetArgRaw(), static_cast<void *>(pSrc));
	EXC_DEBUG_END;
	return false;
}
Example #17
0
CChar * CChar::CreateNPC( CREID_TYPE baseID )	// static
{
	ADDTOCALLSTACK("CChar::CreateNPC");
	CChar * pChar = CreateBasic(baseID);
	ASSERT(pChar);
	pChar->NPC_LoadScript(true);
	pChar->NPC_CreateTrigger();

	return pChar;
}
Example #18
0
int CItemMulti::Ship_ListObjs( CObjBase ** ppObjList )
{
	// List all the objects in the structure.
	// Move the ship and everything on the deck
	// If too much stuff. then some will fall overboard. hehe.

	if ( ! IsTopLevel())
		return 0;

	int iMaxDist = Multi_GetMaxDist();

	// always list myself first. All other items must see my new region !
	int iCount = 0;
	ppObjList[iCount++] = this;

	CWorldSearch AreaChar( GetTopPoint(), iMaxDist );
	while ( iCount < MAX_MULTI_LIST_OBJS )
	{
		CChar * pChar = AreaChar.GetChar();
		if ( pChar == NULL )
			break;
		if ( pChar->IsClient())
		{
			pChar->GetClient()->addPause();	// get rid of flicker. for anyone even seeing this.
		}
		if ( ! m_pRegion->IsInside2d( pChar->GetTopPoint()))
			continue;
		int zdiff = pChar->GetTopZ() - GetTopZ();
		if ( abs( zdiff ) > 3 )
			continue;
		ppObjList[iCount++] = pChar;
	}

	CWorldSearch AreaItem( GetTopPoint(), iMaxDist );
	while ( iCount < MAX_MULTI_LIST_OBJS )
	{
		CItem * pItem = AreaItem.GetItem();
		if ( pItem == NULL )
			break;
		if ( pItem == this )	// already listed.
			continue;
		if ( ! Multi_IsPartOf( pItem ))
		{
			if ( ! m_pRegion->IsInside2d( pItem->GetTopPoint()))
				continue;
			if ( ! pItem->IsMovable())
				continue;
			int zdiff = pItem->GetTopZ() - GetTopZ();
			if ( abs( zdiff ) > 3 )
				continue;
		}
		ppObjList[iCount++] = pItem;
	}
	return( iCount );
}
Example #19
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;
}
Example #20
0
// ---------------------------------------------------------
void CPartyDef::SysMessageAll( LPCTSTR pText )
{
	ADDTOCALLSTACK("CPartyDef::SysMessageAll");
	// SysMessage to all members of the party.
	size_t iQty = m_Chars.GetCharCount();
	for ( size_t i = 0; i < iQty; i++ )
	{
		CChar * pChar = m_Chars.GetChar(i).CharFind();
		pChar->SysMessage( pText );
	}
}
Example #21
0
bool CClient::r_GetRef( LPCTSTR & pszKey, CScriptObj * & pRef )
{
	ADDTOCALLSTACK("CClient::r_GetRef");
	int i = FindTableHeadSorted( pszKey, sm_szRefKeys, COUNTOF(sm_szRefKeys)-1 );
	if ( i >= 0 )
	{
		pszKey += strlen( sm_szRefKeys[i] );
		SKIP_SEPARATORS(pszKey);
		switch (i)
		{
			case CLIR_ACCOUNT:
				if ( pszKey[-1] != '.' )	// only used as a ref !
					break;
				pRef = GetAccount();
				return( true );
			case CLIR_GMPAGEP:
				pRef = m_pGMPage;
				return( true );
			case CLIR_HOUSEDESIGN:
				pRef = m_pHouseDesign;
				return( true );
			case CLIR_PARTY:
				if ( !this->m_pChar->m_pParty )
				{
					LPCTSTR oldKey = pszKey;
					if ( !strnicmp(pszKey, ".CREATE", 7) )
						pszKey +=7;

					CChar * pChar = static_cast<CChar*>(static_cast<CGrayUID>(Exp_GetSingle(pszKey)).CharFind());
					if ( !pChar )
						return false;
					if ( !pChar->IsClient() )
						return false;
					CPartyDef::AcceptEvent( pChar , this->GetChar()->GetUID(), true);
					if ( !this->m_pChar->m_pParty )
						return false;
					pszKey = oldKey;	// Restoring back to real pszKey, so we don't get errors for giving an uid instead of PDV_CREATE.
				}
				pRef = this->m_pChar->m_pParty;
				return true;
			case CLIR_TARG:
				pRef = m_Targ_UID.ObjFind();
				return( true );
			case CLIR_TARGPRV:
				pRef = m_Targ_PrvUID.ObjFind();
				return( true );
			case CLIR_TARGPROP:
				pRef = m_Prop_UID.ObjFind();
				return( true );
		}
	}
	return( CScriptObj::r_GetRef( pszKey, pRef ));
}
Example #22
0
void CItem::Spawn_GenerateChar( CResourceDef * pDef )
{
	if ( ! IsTopLevel())
		return;	// creatures can only be top level.
	if ( m_itSpawnChar.m_current >= GetAmount())
		return;
	int iComplexity = GetTopSector()->GetCharComplexity();
	if ( iComplexity > g_Cfg.m_iMaxCharComplexity )
	{
		DEBUG_MSG(( "Spawn uid=0%lx too complex (%d>%d)\n", GetUID(), iComplexity, g_Cfg.m_iMaxCharComplexity ));
		return;
	}

	int iDistMax = m_itSpawnChar.m_DistMax;
	RESOURCE_ID_BASE rid = pDef->GetResourceID();
	if ( rid.GetResType() == RES_SPAWN )
	{
		const CRandGroupDef * pSpawnGroup = STATIC_CAST <const CRandGroupDef *>(pDef);
		ASSERT(pSpawnGroup);
		int i = pSpawnGroup->GetRandMemberIndex();
		if ( i >= 0 )
		{
			rid = pSpawnGroup->GetMemberID(i);
		}
	}
	
	CREID_TYPE id;
	if ( rid.GetResType() == RES_CHARDEF || 
		rid.GetResType() == RES_UNKNOWN )
	{
		id = (CREID_TYPE) rid.GetResIndex();
	}
	else
	{
		return;
	}

	CChar * pChar = CChar::CreateNPC( id );
	if ( pChar == NULL )
		return;
	ASSERT(pChar->m_pNPC);

	m_itSpawnChar.m_current ++;
	pChar->Memory_AddObjTypes( this, MEMORY_ISPAWNED );
	// Move to spot "near" the spawn item.
	pChar->MoveNearObj( this, iDistMax );
	if ( iDistMax )
	{
		pChar->m_ptHome = GetTopPoint();
		pChar->m_pNPC->m_Home_Dist_Wander = iDistMax;
	}
	pChar->Update();
}
Example #23
0
void CCharRefArray::DeleteChars()
{
	ADDTOCALLSTACK("CCharRefArray::DeleteChars");
	size_t iQty = m_uidCharArray.GetCount();
	while ( iQty > 0 )
	{
		CChar *pChar = m_uidCharArray[--iQty].CharFind();
		if ( pChar )
			pChar->Delete();
	}
	m_uidCharArray.RemoveAll();
}
Example #24
0
void CChatChannel::WhoIs(LPCTSTR pszBy, LPCTSTR pszMember)
{
	ADDTOCALLSTACK("CChatChannel::WhoIs");
	CChatMember *pMemberBy = FindMember(pszBy);
	CChatMember *pMemberTarg = FindMember(pszMember);
	CChar *pCharTarg = (pMemberTarg && pMemberTarg->GetClient()) ? pMemberTarg->GetClient()->GetChar() : NULL;

	if ( !pCharTarg )
		pMemberBy->SendChatMsg(CHATMSG_NoPlayer, pszMember);
	else if ( pMemberTarg->m_bAllowWhoIs )
		pMemberBy->SendChatMsg(CHATMSG_PlayerKnownAs, pszMember, pCharTarg->GetName());
	else
		pMemberBy->SendChatMsg(CHATMSG_PlayerIsAnonymous, pszMember);
}
bool CItemStone::CheckValidMember( CStoneMember * pMember )
{
	ADDTOCALLSTACK("CItemStone::CheckValidMember");
	ASSERT(pMember);
	ASSERT( pMember->GetParent() == this );

	if ( GetAmount()==0 || g_Serv.m_iExitFlag )	// no reason to elect new if the stone is dead.
		return( true );	// we are deleting anyhow.

	switch ( pMember->GetPriv())
	{
		case STONEPRIV_MASTER:
		case STONEPRIV_MEMBER:
		case STONEPRIV_CANDIDATE:
		case STONEPRIV_ACCEPTED:
			if ( GetMemoryType())
			{
				// Make sure the member has a memory that links them back here.
				CChar * pChar = pMember->GetLinkUID().CharFind();
				if ( pChar == NULL )
					break;
				if ( pChar->Guild_Find( GetMemoryType()) != this )
					break;
			}
			return( true );
		case STONEPRIV_ENEMY:
			{
				CItemStone * pEnemyStone = dynamic_cast <CItemStone *>( pMember->GetLinkUID().ItemFind());
				if ( pEnemyStone == NULL )
					break;
				CStoneMember * pEnemyMember = pEnemyStone->GetMember(this);
				if ( pEnemyMember == NULL )
					break;
				if ( pMember->GetWeDeclared() && ! pEnemyMember->GetTheyDeclared())
					break;
				if ( pMember->GetTheyDeclared() && ! pEnemyMember->GetWeDeclared())
					break;
			}
			return( true );

		default:
			break;
	}

	// just delete this member. (it is mislinked)
	DEBUG_ERR(( "Stone UID=0%lx has mislinked member uid=0%lx\n", 
		(DWORD) GetUID(), (DWORD) pMember->GetLinkUID()));
	return( false );
}
Example #26
0
void CItemSpawn::GenerateChar(CResourceDef *pDef)
{
	ADDTOCALLSTACK("CitemSpawn:GenerateChar");

	RESOURCE_ID_BASE rid = pDef->GetResourceID();
	if ( rid.GetResType() == RES_SPAWN )
	{
		const CRandGroupDef *pSpawnGroup = static_cast<const CRandGroupDef *>(pDef);
		ASSERT(pSpawnGroup);
		size_t i = pSpawnGroup->GetRandMemberIndex();
		if ( i != pSpawnGroup->BadMemberIndex() )
			rid = pSpawnGroup->GetMemberID(i);
	}

	if ( (rid.GetResType() != RES_CHARDEF) && (rid.GetResType() != RES_UNKNOWN) )
		return;

	CPointMap pt = GetTopPoint();
	CRegionBase *pRegion = pt.GetRegion(REGION_TYPE_AREA);
	if ( !pRegion )
		return;

	CChar *pChar = CChar::CreateBasic(static_cast<CREID_TYPE>(rid.GetResIndex()));
	if ( !pChar )
		return;

	pChar->NPC_LoadScript(true);
	pChar->StatFlag_Set(STATF_Spawned);

	// Try placing the char near the spawn
	if ( !pChar->MoveNearObj(this, m_itSpawnChar.m_DistMax) || !pChar->CanSeeLOS(pt) )
	{
		// If this fails, try placing the char over the spawn
		if ( !pChar->MoveTo(pt) )
		{
			DEBUG_ERR(("Spawn UID:0%lx is unable to place a character inside the world.\n", static_cast<DWORD>(GetUID())));
			pChar->Delete();
			return;
		}
	}

	AddObj(pChar->GetUID());
	pChar->NPC_CreateTrigger();		// removed from NPC_LoadScript() and triggered after char placement and attachment to the spawnitem
	pChar->Update();

	size_t iCount = GetTopSector()->GetCharComplexity();
	if ( iCount > g_Cfg.m_iMaxCharComplexity )
		g_Log.Event(LOGL_WARN, "%" FMTSIZE_T " chars at %s. Sector too complex!\n", iCount, GetTopSector()->GetBasePoint().WriteUsed());
}
Example #27
0
LPCTSTR CChatMember::GetChatName()
{
	ADDTOCALLSTACK("CChatMember::GetChatName");
	CClient *pClient = GetClient();
	if ( pClient )
	{
		if ( !pClient->m_UseNewChatSystem && (g_Cfg.m_iChatFlags & CHATF_CUSTOMNAMES) )
			return pClient->m_pAccount->m_sChatName;

		CChar *pChar = pClient->GetChar();
		if ( pChar )
			return pChar->GetName();
	}
	return "<NA>";
}
Example #28
0
int CContainer::ResourceConsume( const CResourceQtyArray * pResources, int iReplicationQty, bool fTest, DWORD dwArg )
{
	ADDTOCALLSTACK("CContainer::ResourceConsume");
	// Consume or test all the required resources.
	// ARGS:
	//	pResources = the resources i need to make 1 replication of this end product.
	// RETURN:
	//  how many whole objects can be made. <= iReplicationQty

	if ( iReplicationQty <= 0 )
		iReplicationQty = 1;
	if ( ! fTest && iReplicationQty > 1 )
	{
		// Test what the max number we can really make is first !
		// All resources must be consumed with the same number.
		iReplicationQty = ResourceConsume( pResources, iReplicationQty, true, dwArg );
	}

	int iQtyMin = INT_MAX;
	for ( size_t i = 0; i < pResources->GetCount(); i++ )
	{
		int iResQty = static_cast<int>(pResources->GetAt(i).GetResQty());
		if (iResQty <= 0) // not sure why this would be true
			continue;

		int iQtyTotal = ( iResQty * iReplicationQty );
		RESOURCE_ID rid = pResources->GetAt(i).GetResourceID();
		if ( rid.GetResType() == RES_SKILL )
		{
			CChar *	pChar	= dynamic_cast <CChar *> (this);
			if ( !pChar )
				continue;
			if ( pChar->Skill_GetBase(static_cast<SKILL_TYPE>(rid.GetResIndex())) < iResQty )
				return 0;
			continue;
		}

		int iQtyCur = iQtyTotal - ContentConsume( rid, iQtyTotal, fTest, dwArg );
		iQtyCur /= iResQty;
		if ( iQtyCur < iQtyMin )
			iQtyMin = iQtyCur;
	}

	if ( iQtyMin == INT_MAX )	// it has no resources ? So i guess we can make it from nothing ?
		return( iReplicationQty );

	return( iQtyMin );
}
Example #29
0
// ---------------------------------------------------------
void CPartyDef::StatsUpdateAll( CChar *pCharSrc, PacketSend *pPacket )
{
	ADDTOCALLSTACK("CPartyDef::StatsUpdateAll");
	size_t iQty = m_Chars.GetCharCount();
	if ( iQty <= 0 )
		return;

	CChar *pChar = NULL;
	for ( size_t i = 0; i < iQty; i++ )
	{
		pChar = m_Chars.GetChar(i).CharFind();
		if ( !pChar || !pChar->m_pClient || (pChar == pCharSrc) || !pChar->CanSee(pCharSrc) )
			continue;
		pPacket->send(pChar->m_pClient);
	}
}
Example #30
0
// ---------------------------------------------------------
bool CPartyDef::MessageEvent( CGrayUID uidDst, CGrayUID uidSrc, const NCHAR * pText, int ilenmsg )
{
	ADDTOCALLSTACK("CPartyDef::MessageEvent");
	UNREFERENCED_PARAMETER(ilenmsg);
	if ( pText == NULL )
		return( false );

	if ( uidDst && !IsInParty( uidDst.CharFind() ) )
		return( false );

	CChar * pFrom = uidSrc.CharFind();
	CChar * pTo = NULL;
	if ( uidDst != (DWORD) 0 )
		pTo = uidDst.CharFind();

	TCHAR * szText = Str_GetTemp();
	CvtNUNICODEToSystem( szText, MAX_TALK_BUFFER, pText, MAX_TALK_BUFFER );

	if ( ! m_pSpeechFunction.IsEmpty() )
	{
		TRIGRET_TYPE tr = TRIGRET_RET_FALSE;
		CScriptTriggerArgs Args;
		Args.m_iN1 = uidSrc;
		Args.m_iN2 = uidDst;
		Args.m_s1 = szText;
		Args.m_s1_raw = szText;

		if ( r_Call(m_pSpeechFunction, &g_Serv, &Args, NULL, &tr) )
		{
			if ( tr == TRIGRET_RET_TRUE )
				return( false );
		}
	}

	if ( g_Log.IsLoggedMask( LOGM_PLAYER_SPEAK ))
		g_Log.Event( LOGM_PLAYER_SPEAK, "%lx:'%s' Says '%s' in party to '%s'\n", pFrom->GetClient()->GetSocketID(), pFrom->GetName(), szText, pTo ? pTo->GetName() : "all" );

	sprintf(szText, g_Cfg.GetDefaultMsg( DEFMSG_PARTY_MSG ), pText);
	PacketPartyChat cmd(pFrom, pText);

	if ( pTo != NULL )
		SendMemberMsg(pTo, &cmd);
	else
		SendAll(&cmd);

	return( true );
}