예제 #1
0
bool CStoneMember::r_Verb( CScript & s, CTextConsole * pSrc ) // Execute command from script
{
	ADDTOCALLSTACK("CStoneMember::r_Verb");
	EXC_TRY("Verb");

	ASSERT(pSrc);
	
	LPCTSTR pszKey = s.GetKey();
	int index = FindTableSorted( pszKey, sm_szVerbKeys, COUNTOF(sm_szVerbKeys)-1 );
	if ( index < 0 )
	{
		if ( r_LoadVal(s) ) // if it's successful all ok, else go on verb.
		{
			return true;
		}
	}

	if ( GetLinkUID().IsChar() )
	{
		CScriptObj *pRef = GetLinkUID().CharFind();
		return pRef->r_Verb( s, pSrc );
	}
	else if ( GetLinkUID().IsItem() )
	{
		CScriptObj *pRef = GetLinkUID().ItemFind();
		return pRef->r_Verb( s, pSrc );
	}

	return true;
	EXC_CATCH;

	EXC_DEBUG_START;
	EXC_ADD_SCRIPTSRC;
	EXC_DEBUG_END;
	return false;
}
예제 #2
0
bool CPartyDef::r_Verb( CScript &s, CTextConsole *pSrc )
{
	ADDTOCALLSTACK("CPartyDef::r_Verb");
	EXC_TRY("Verb");
	ASSERT(pSrc);

	LPCTSTR pszKey = s.GetKey();
	CScriptObj *pRef;
	if ( r_GetRef(pszKey, pRef) )
	{
		if ( pszKey[0] )
		{
			if ( !pRef )
				return true;
			CScript script(pszKey, s.GetArgStr());
			return pRef->r_Verb(script, pSrc);
		}
	}

	int iIndex = FindTableSorted(pszKey, sm_szVerbKeys, COUNTOF(sm_szVerbKeys) - 1);
	switch ( iIndex )
	{
		case PDV_ADDMEMBER:
		case PDV_ADDMEMBERFORCED:
		{
			bool bForced = (iIndex == PDV_ADDMEMBERFORCED);
			CGrayUID toAdd = static_cast<CGrayUID>(s.GetArgVal());
			CChar *pCharAdd = toAdd.CharFind();
			CChar *pCharMaster = GetMaster().CharFind();
			if ( !pCharAdd || IsInParty(pCharAdd) )
				return false;

			if ( pCharMaster && !bForced )
				pCharMaster->SetKeyNum("PARTY_LASTINVITE", (long long)toAdd);
			
			return CPartyDef::AcceptEvent(pCharAdd, GetMaster(), bForced);
		} break;

		case PDV_CLEARTAGS:
		{
			LPCTSTR pszArg = s.GetArgStr();
			SKIP_SEPARATORS(pszArg);
			m_TagDefs.ClearKeys(pszArg);
		} break;

		case PDV_CREATE:
			return true;

		case PDV_DISBAND:
			return Disband(GetMaster());

		case PDV_MESSAGE:
			break;

		case PDV_REMOVEMEMBER:
		{
			CGrayUID toRemove;
			LPCTSTR pszArg = s.GetArgStr();
			if ( *pszArg == '@' )
			{
				pszArg++;
				size_t nMember = Exp_GetVal(pszArg);
				if ( !m_Chars.IsValidIndex(nMember) )
					return false;

				toRemove = m_Chars.GetChar(nMember);
			}
			else
				toRemove = static_cast<CGrayUID>(s.GetArgVal());

			if ( toRemove )
				return RemoveMember(toRemove, GetMaster());

			return false;
		} break;

		case PDV_SETMASTER:
		{
			CGrayUID newMaster;
			LPCTSTR pszArg = s.GetArgStr();
			if ( *pszArg == '@' )
			{
				pszArg++;
				size_t nMember = Exp_GetVal(pszArg);
				if ( nMember == 0 || !m_Chars.IsValidIndex(nMember) )
					return false;

				newMaster = m_Chars.GetChar(nMember);
			}
			else
				newMaster = static_cast<CGrayUID>(s.GetArgVal());

			if ( newMaster )
				return SetMaster(newMaster.CharFind());

			return false;
		} break;

		case PDV_SYSMESSAGE:
		{
			CGrayUID toSysmessage;
			LPCTSTR pszArg = s.GetArgStr();
			TCHAR *pUid = Str_GetTemp();
			size_t x = 0;

			if ( *pszArg == '@' )
			{
				pszArg++;
				if ( *pszArg != '@' )
				{
					LPCTSTR __pszArg = pszArg;
					while ( *pszArg != ' ' )
					{
						pszArg++;
						x++;
					}
					strcpylen(pUid, __pszArg, ++x);

					size_t nMember = Exp_GetVal(pUid);
					if ( !m_Chars.IsValidIndex(nMember) )
						return false;

					toSysmessage = m_Chars.GetChar(nMember);
				}
			}
			else
			{
				LPCTSTR __pszArg = pszArg;
				while ( *pszArg != ' ' )
				{
					pszArg++;
					x++;
				}
				strcpylen(pUid, __pszArg, ++x);

				toSysmessage = static_cast<CGrayUID>(Exp_GetVal(pUid));
			}

			SKIP_SEPARATORS(pszArg);

			if ( toSysmessage )
			{
				CChar *pSend = toSysmessage.CharFind();
				pSend->SysMessage(pszArg);
			}
			else
				SysMessageAll(pszArg);
		} break;

		case PDV_TAGLIST:
			m_TagDefs.DumpKeys(pSrc, "TAG.");
			break;

		default:
			return false;
	}
	return true;
	EXC_CATCH;

	EXC_DEBUG_START;
	EXC_ADD_SCRIPTSRC;
	EXC_DEBUG_END;
	return false;
}
예제 #3
0
bool CScriptObj::r_Verb( CScript & s, CTextConsole * pSrc ) // Execute command from script
{
	LOCKDATA;
	EXC_TRY(("r_Verb('%s %s',%x)", s.GetKey(), s.GetArgStr(), pSrc));
	int	index;
	LPCTSTR pszKey = s.GetKey();

	ASSERT( pSrc );
	CScriptObj * pRef;

	if ( r_GetRef( pszKey, pRef ))
	{
		if ( pszKey[0] )
		{
			if ( !pRef ) return true;
			CScript script( pszKey, s.GetArgStr());
			return pRef->r_Verb( script, pSrc );
		}
		// else just fall through. as they seem to be setting the pointer !?
	}

	if ( s.IsKeyHead( "SRC.", 4 ))
	{
		pszKey += 4;
		pRef = dynamic_cast <CScriptObj*> (pSrc->GetChar());	// if it can be converted .
		if ( ! pRef )
		{
			pRef = dynamic_cast <CScriptObj*> (pSrc);
			if ( ! pRef )
				return( false );
		}
		CScript script( pszKey, s.GetArgStr());
		return pRef->r_Verb( script, pSrc );
	}

	index = FindTableSorted( s.GetKey(), sm_szVerbKeys, COUNTOF( sm_szVerbKeys )-1 );
	switch (index)
	{
	case SSV_OBJ:
		g_World.m_uidObj = s.GetArgVal();
		if ( !g_World.m_uidObj.ObjFind() ) g_World.m_uidObj = 0;
		return( true );
	case SSV_NEW:
		g_World.m_uidNew = s.GetArgVal();
		if ( !g_World.m_uidNew.ObjFind() ) g_World.m_uidNew = 0;
		return( true );
	case SSV_DUMPKEYS:
		r_DumpLoadKeys( pSrc );
		return( true );
	case SSV_DUMPVERBS:
		r_DumpVerbKeys( pSrc );
		return( true );
	case SSV_SHOW:
		{
			CGString sVal;
			if ( ! r_WriteVal( s.GetArgStr(), sVal, pSrc ))
				return( false );
			TCHAR *pszMsg = Str_GetTemp();
			sprintf(pszMsg, "'%s' for '%s' is '%s'\n", (LPCTSTR) s.GetArgStr(), (LPCTSTR) GetName(), (LPCTSTR) sVal );
			pSrc->SysMessage(pszMsg);
		}
		return( true );
	case SSV_TRIGGER:
		{
		// This is effectively a goto to an alternate trigger. (for this same object)
		TCHAR * pszVals[2];
		// CScriptTriggerArgs * pArgs = NULL ?
		if ( Str_ParseCmds( s.GetArgStr(), pszVals, COUNTOF(pszVals)))
		{
			TRIGRET_TYPE tRet = OnTrigger( pszVals[0], pSrc, NULL );
			return( true );
		}
		}
		return( false );
	}
	return r_LoadVal( s );	// default to loading values.
	EXC_CATCH("CScriptObj");
	return false;
}