⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 procedures.cpp

📁 MudMaster 2000 的C++源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
		}
		return(FALSE);
	}
	int nNum = atoi(strNum);
	if (nNum < 1)
	{
		if (_config.bDebugMessages)
		{
			CString strTemp;
			strTemp.Format("@Left(%s,%d): Number of characters is invalid.",
				(const char *)strText,nNum);
			PrintMessage(strTemp,TRUE,TRUE);
			_debugStack.DumpStack(_config.nDebugDepth);
		}
		return(FALSE);
	}
	if (nNum > strText.GetLength())
		nNum = strText.GetLength();
	strResult = strText.Left(nNum);
	return(TRUE);
}

BOOL Len(CString &strParams, CString &strResult)
{
	CString strText;
	FindParam(strParams,strText);
	ReplaceVariables(strText);
	strResult.Format("%d",strText.GetLength());
	return(TRUE);
}

BOOL Lower(CString &strParams, CString &strResult)
{
	FindParam(strParams,strResult);
	ReplaceVariables(strResult);
	strResult.MakeLower();
	return(TRUE);
}

BOOL LTrim(CString &strParams, CString &strResult)
{
	FindParam(strParams, strResult);
	ReplaceVariables(strResult);
	strResult.TrimLeft();
	return(TRUE);
}

BOOL Math(CString &strParams, CString &strResult)
{
	CString strMath;
	FindParam(strParams,strMath);
	ReplaceVariables(strMath);
	if (strMath.IsEmpty())
	{
		if (_config.bDebugMessages)
		{
			PrintMessage("@Math() : Formula is empty.",TRUE,TRUE);
			_debugStack.DumpStack(_config.nDebugDepth);
		}
		return(FALSE);
	}

	long lResult;
	if (CalculateMath(strMath,lResult))
	{
		strResult.Format("%ld",lResult);
		return(TRUE);
	}
	return(FALSE);
}

BOOL Mid(CString &strParams, CString &strResult)
{
	CString strText;
	CString strStart, strNum;
	FindParam(strParams,strText);
	FindParam(strParams,strStart);
	FindParam(strParams,strNum);
	ReplaceVariables(strText);
	ReplaceVariables(strStart);
	ReplaceVariables(strNum);
	if (strText.IsEmpty())
	{
		if (_config.bDebugMessages)
		{
			CString strTemp;
			strTemp.Format("@Mid(,%s,%s): Text is empty.",
				(const char *)strStart,
				(const char *)strNum);
			PrintMessage(strTemp,TRUE,TRUE);
			_debugStack.DumpStack(_config.nDebugDepth);
		}
		return(FALSE);
	}
	if (strStart.IsEmpty())
	{
		if (_config.bDebugMessages)
		{
			CString strTemp;
			strTemp.Format("@Mid(%s,,%s): Start index is empty.",
				(const char *)strText,
				(const char *)strNum);
			PrintMessage(strTemp,TRUE,TRUE);
			_debugStack.DumpStack(_config.nDebugDepth);
		}
		return(FALSE);
	}
	if (strNum.IsEmpty())
	{
		if (_config.bDebugMessages)
		{
			CString strTemp;
			strTemp.Format("@Mid(%s,%s,): Number of characters is empty.",
				(const char *)strText,
				(const char *)strStart);
			PrintMessage(strTemp,TRUE,TRUE);
			_debugStack.DumpStack(_config.nDebugDepth);
		}
		return(FALSE);
	}
	int nLen = strText.GetLength();
	int nStart = atoi(strStart);
	if (nStart < 0 || nStart >= nLen)
	{
		if (_config.bDebugMessages)
		{
			CString strTemp;
			strTemp.Format("@Mid(%s,%d,%s): Invalid start index.",
				(const char *)strText,
				nStart,
				(const char *)strNum);
			PrintMessage(strTemp,TRUE,TRUE);
			_debugStack.DumpStack(_config.nDebugDepth);
		}
		return(FALSE);
	}
	int nNum = atoi(strNum);
	if (nStart + nNum > nLen)
	{
		if (_config.bDebugMessages)
		{
			CString strTemp;
			strTemp.Format("@Mid(%s,%d,%d): Invalid number of characters.",
				(const char *)strText,
				nStart,
				nNum);
			PrintMessage(strTemp,TRUE,TRUE);
			_debugStack.DumpStack(_config.nDebugDepth);
		}
		return(FALSE);
	}
	strResult = strText.Mid(nStart,nNum);
	return(TRUE);
}

BOOL Minute(CString &strParams, CString &strResult)
{
	CTime tNow = CTime::GetCurrentTime();
	strResult.Format("%d",tNow.GetMinute());
	return(TRUE);
}

BOOL Month(CString &strParams, CString &strResult)
{
	CTime tNow = CTime::GetCurrentTime();
	strResult.Format("%d",tNow.GetMonth());
	return(TRUE);
}

BOOL NumActions(CString &strParams, CString &strResult)
{
	strResult.Format("%d",_actions.GetCount());
	return(TRUE);
}

BOOL NumAliases(CString &strParams, CString &strResult)
{
	strResult.Format("%d",_aliases.GetCount());
	return(TRUE);
}

BOOL NumArrays(CString &strParams, CString &strResult)
{
	strResult.Format("%d",_arrays.GetCount());
	return(TRUE);
}

BOOL NumBarItems(CString &strParams, CString &strResult)
{
	strResult.Format("%d",_statusBar.GetCount());
	return(TRUE);
}

BOOL NumEvents(CString &strParams, CString &strResult)
{
	strResult.Format("%d",_events.GetCount());
	return(TRUE);
}

BOOL NumGags(CString &strParams, CString &strResult)
{
	strResult.Format("%d",_gags.GetCount());
	return(TRUE);
}

BOOL NumHighlights(CString &strParams, CString &strResult)
{
	strResult.Format("%d",_highlights.GetCount());
	return(TRUE);
}

BOOL NumLists(CString &strParams, CString &strResult)
{
	strResult.Format("%d",_lists.GetCount());
	return(TRUE);
}

BOOL NumMacros(CString &strParams, CString &strResult)
{
	strResult.Format("%d",_macros.GetCount());
	return(TRUE);
}

BOOL NumSubstitutes(CString &strParams, CString &strResult)
{
	strResult.Format("%d",_subs.GetCount());
	return(TRUE);
}

BOOL NumTabList(CString &strParams, CString &strResult)
{
	strResult.Format("%d",_tabList.GetCount());
	return(TRUE);
}

BOOL NumVariables(CString &strParams, CString &strResult)
{
	strResult.Format("%d",_mapVars.GetCount());
	return(TRUE);
}

BOOL PadLeft(CString &strParams, CString &strResult)
{
	CString strText, strChar, strNum;
	FindParam(strParams,strText);
	FindParam(strParams,strChar);
	FindParam(strParams,strNum);

	ReplaceVariables(strText);
	ReplaceVariables(strChar);
	ReplaceVariables(strNum);

	if (strChar.IsEmpty())
	{
		if (_config.bDebugMessages)
		{
			CString strTemp;
			strTemp.Format("@PadLeft(%s,,%s): Character to pad is empty.",
				(const char *)strText,
				(const char *)strNum);
			PrintMessage(strTemp,TRUE,TRUE);
			_debugStack.DumpStack(_config.nDebugDepth);
		}
		return(FALSE);
	}
	if (strNum.IsEmpty())
	{
		if (_config.bDebugMessages)
		{
			CString strTemp;
			strTemp.Format("@PadLeft(%s,%s,): Number of characters to pad is empty.",
				(const char *)strText,
				(const char *)strChar);
			PrintMessage(strTemp,TRUE,TRUE);
			_debugStack.DumpStack(_config.nDebugDepth);
		}
		return(FALSE);
	}

	int nNum = atoi(strNum);
	if (nNum < 0 || nNum > 200)
	{
		if (_config.bDebugMessages)
		{
			CString strTemp;
			strTemp.Format("@PadLeft(%s,%s,%d): Number to pad must be between 0 and 200.",
				(const char *)strText,
				(const char *)strChar,
				nNum);
			PrintMessage(strTemp,TRUE,TRUE);
			_debugStack.DumpStack(_config.nDebugDepth);
		}
		return(FALSE);
	}

	CString strPad(strChar.GetAt(0),nNum);
	strResult = strPad + strText;
	return(TRUE);
}

BOOL PadRight(CString &strParams, CString &strResult)
{
	CString strText, strChar, strNum;
	FindParam(strParams,strText);
	FindParam(strParams,strChar);
	FindParam(strParams,strNum);

	ReplaceVariables(strText);
	ReplaceVariables(strChar);
	ReplaceVariables(strNum);

	if (strChar.IsEmpty())
	{
		if (_config.bDebugMessages)
		{
			CString strTemp;
			strTemp.Format("@PadRight(%s,,%s): Character to pad is empty.",
				(const char *)strText,
				(const char *)strNum);
			PrintMessage(strTemp,TRUE,TRUE);
			_debugStack.DumpStack(_config.nDebugDepth);
		}
		return(FALSE);
	}
	if (strNum.IsEmpty())
	{
		if (_config.bDebugMessages)
		{
			CString strTemp;
			strTemp.Format("@PadRight(%s,%s,): Number of characters to pad is empty.",
				(const char *)strText,
				(const char *)strChar);
			PrintMessage(strTemp,TRUE,TRUE);
			_debugStack.DumpStack(_config.nDebugDepth);
		}
		return(FALSE);
	}

	int nNum = atoi(strNum);
	if (nNum < 0 || nNum > 200)
	{
		if (_config.bDebugMessages)
		{
			CString strTemp;
			strTemp.Format("@PadRight(%s,%s,%d): Number to pad must be between 0 and 200.",
				(const char *)strText,
				(const char *)strChar,
				nNum);
			PrintMessage(strTemp,TRUE,TRUE);
			_debugStack.DumpStack(_config.nDebugDepth);
		}
		return(FALSE);
	}

	CString strPad(strChar.GetAt(0),nNum);
	strResult = strText + strPad;
	return(TRUE);
}

BOOL PreTrans(CString &strParams, CString &strResult)
{
	strResult = strParams;
	ReplaceVariables(strResult);
	return(TRUE);
}

BOOL Random(CString &strParams, CString &strResult)
{
	CString strMax;
	FindParam(strParams,strMax);

	ReplaceVariables(strMax);

	if (strMax.IsEmpty())
	{
		if (_config.bDebugMessages)
		{
			PrintMessage("@Random(): No value given.",TRUE,TRUE);
			_debugStack.DumpStack(_config.nDebugDepth);
		}
		return(FALSE);
	}

	int nNum = atoi(strMax);
	if (!nNum || nNum > RAND_MAX)
	{
		if (_config.bDebugMessages)
		{
			CString strTemp;
			strTemp.Format("@Random(%d): Invalid value.",nNum);
			PrintMessage(strTemp,TRUE,TRUE);
			_debugStack.DumpStack(_config.nDebugDepth);
		}
		return(FALSE);
	}
	strResult.Format("%u",rand()%nNum+1);
	return(TRUE);
}

BOOL Right(CString &strParams, CString &strResult)
{
	CString strText;
	CString strNum;
	FindParam(strParams,strText);
	FindParam(strParams,strNum);
	ReplaceVariables(strText);
	ReplaceVariables(strNum);

	if (strText.IsEmpty())
	{
		if (_config.bDebugMessages)
		{
			CString strTemp;
			strTemp.Format("@Right(,%s): Text string is empty.",
				(const char *)strNum);
			PrintMessage(strTemp,TRUE,TRUE);
			_debugStack.DumpStack(_config.nDebugDepth);
		}
		return(FALSE);
	}
	if (strNum.IsEmpty())
	{
		if (_config.bDebugMessages)
		{
			CString strTemp;
			strTemp.Format("@Right(%s,): Number of characters is empty.",
				(const char *)strText);
			PrintMessage(strTemp,TRUE,TRUE);
			_debugStack.DumpStack(_config.nDebugDepth);
		}
		return(FALSE);
	}
	int nNum = atoi(strNum);
	if (nNum < 1)
	{
		if (_config.bDebugMessages)
		{
			CString strTemp;
			strTemp.Format("@Right(%s,%d): Number of characters is invalid.",
				(const char *)strText,nNum);
			PrintMessage(strTemp,TRUE,TRUE);
			_debugStack.DumpStack(_config.nDebugDepth);
		}
		return(FALSE);
	}	
	if (nNum > strText.GetLength())
		nNum = strText.GetLength();
	strResult = strText.Right(nNum);
	return(TRUE);
}

BOOL RTrim(CString &strParams, CString &strResult)
{
	FindParam(strParams, strResult);
	ReplaceVariables(strResult);
	strResult.TrimRight();
	return(TRUE);
}

BOOL Second(CString &strParams, CString &strResult)
{
	CTime tNow = CTime::GetCurrentTime();
	strResult.Format("%d",tNow.GetSecond());
	return(TRUE);
}

BOOL StripAnsi(CString &strParams, CString &strResult)
{
	ReplaceVariables(strParams);

	// Quick check to see if there are any codes.
	if (strParams.Find('\x1b') == -1)
	{
		strResult = strParams;
		return(TRUE);
	}

	strResult.Empty();
	BOOL bInAnsi = FALSE;
	int nIndex = 0;
	int nLen = strParams.GetLength();
	while(nIndex < nLen)
	{
		if (bInAnsi)
		{
			if (strParams.GetAt(nIndex) == 'm')
				bInAnsi = FALSE;
			nIndex++;
			continue;
		}

		if (strParams.GetAt(nIndex) == '\x1b' && nIndex < nLen-2 && strParams.GetAt(nIndex+1) == '[')
		{
			bInAnsi = TRUE;
			nIndex++;
			continue;
		}

		strResult += strParams.GetAt(nIndex);
		nIndex++;
	}

	return(TRUE);
}

BOOL StrStr(CString &strParams, CString &strResult)
{
	CString strSearchIn, strSearchFor;
	FindParam(strParams,strSearchIn);
	FindParam(strParams,strSearchFor);
	ReplaceVariables(strSearchIn);
	ReplaceVariables(strSearchFor);

	if (strSearchIn.IsEmpty())
	{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -