double CScript::ChangeAttr(const char* CmdStr, char* retStr)
{
	OBJECT_TYPE type;
	CGUID id;
	double value  = 0;
	double ret = INVILID_VALUE;

	int param = GetIntParam(CmdStr, 0);
	if(param != ERROR_CODE && param != INVILID_VALUE)
	{
		type = (OBJECT_TYPE)param;

		char* pIdName = GetStringParam(CmdStr, 1);
		if(NULL == pIdName) return ret;
		id = GetVariableList()->GetGuidValue(pIdName);
		if(id == NULL_GUID)
			id = GetGeneralVariableList()->GetGuidValue(pIdName);
		if(id == NULL_GUID)
			id = ((CPlayer*)p_SrcShape)->GetVariableList()->GetGuidValue(pIdName);

		CMoveShape* shape = GetGame()->FindShape(type, id);

		char* name = GetStringParam(CmdStr, 2);
		if(name)
		{
			value = GetIntParam(CmdStr, 3);
			if(value != ERROR_CODE && value != INVILID_VALUE)
			{

				if(NULL == shape) // 默认id=0时,直接调用SrcShape的SetAttr接口
				{
					CShape* cShape = GetSrcShape();
					if(cShape)
					{
						((CMoveShape*)cShape)->ChangeAttribute(string(name), value);
						((CMoveShape*)cShape)->UpdateAttribute();
						ret = 1;
					}
				}
				else
				{
					shape->ChangeAttribute(string(name), value);
					shape->UpdateAttribute();
					ret = 1;
				}
			}
		}

		M_FREE( pIdName, sizeof(char)*MAX_VAR_LEN );
		M_FREE( name, sizeof(char)*MAX_VAR_LEN );
	}
	else // 参数是字符串
	{
		AddErrorLogText(CStringReading::LoadString(IDS_GS_FUNCTION, STR_GS_FUNCTION_CHANGEATTRFIRSTVARISSTRING));
	}

	return ret;
}
double CScript::SetAttrInt(const char* CmdStr, char* retStr)
{
	OBJECT_TYPE type;
	CGUID id;
	double value   = 0;

	if(!GetSrcShape()) return -1.0f;

	int param = GetIntParam(CmdStr, 0);
	if(param != ERROR_CODE && param != INVILID_VALUE)
	{
		type = (OBJECT_TYPE)param;

		char* pIdName = GetStringParam(CmdStr, 1);
		if(!pIdName) return -1.0f;

		id = GetScriptGuidValue((CMoveShape*)GetSrcShape(), pIdName);

		CMoveShape* shape = NULL;

		char* name = GetStringParam(CmdStr, 2);

		if(!name)
		{
			M_FREE( pIdName, sizeof(char)*MAX_VAR_LEN );
			return -1.0f;
		}

		value = GetIntParam(CmdStr, 3);
		if(value == ERROR_CODE || value == INVILID_VALUE)
		{
			M_FREE( pIdName, sizeof(char)*MAX_VAR_LEN );
			M_FREE( name, sizeof(char)*MAX_VAR_LEN );
			return -1.0f;
		}

		if(NULL_GUID == id) // 默认id=0时,直接调用SrcShape的SetAttr接口
		{
			shape = (CMoveShape*)GetSrcShape();
		}
		else
		{
			shape = GetGame()->FindShape(type, id);
		}

		if(shape)
		{
			if(CVariableList::VAR_NOT_FOUND == SetScriptVarValue(shape, name, 0, value))
			{
				shape->SetAttribute(name, value);
				shape->UpdateAttribute();
			}
		}
	
		M_FREE( pIdName, sizeof(char)*MAX_VAR_LEN );
		M_FREE( name, sizeof(char)*MAX_VAR_LEN );
	}
	else // 参数是字符串
	{
		AddErrorLogText(CStringReading::LoadString(IDS_GS_FUNCTION, STR_GS_FUNCTION_SETATTRFIRSTVARISSTRING));
	}

	return -1.0f;
}
Example #3
0
void CPKSys::SetPKValue(CMoveShape *pAttacker,CMoveShape *pBeenAttacker,int nAddSub)
{
	//主动攻击(包含使用减益技能)本国白名玩家,每次攻击将增加20点PK值,因此方法获得的PK值上限为20,若PK值已经达到或超过20,则不会再因此方法而增加。	

	if (pAttacker==NULL || pBeenAttacker==NULL)
	{
		return;
	}
	if (pAttacker->GetType()==TYPE_MONSTER)
	{
		return;		
	}
	if (pBeenAttacker->GetType()==TYPE_MONSTER)
	{
		if (((CMonster*)pBeenAttacker)->GetNpcType()!=NT_Guard)
		{
			return;
		}	
	}

	CMoveShape* pAtker = pAttacker;
	CMoveShape* pDefer = pBeenAttacker;
	if( TYPE_PET == pAtker->GetType() )
	{
		pAtker = pAtker->GetHost();
	}

	if( TYPE_PET == pDefer->GetType() )
	{
		pDefer = pDefer->GetHost();
	}

	if( NULL == pAtker || NULL == pDefer )
	{
		//PutoutLog("Pet", LT_ERROR, "...");
		return;
	}

	// [8/24/2009 chenxianj]
	//////////////////////////////////////////////////////////////////////////
	//竞技区域不进行pk值设定
	CServerRegion* pRegion = dynamic_cast<CServerRegion*>( pAttacker->GetFather() );
	if( !pRegion ) 
	{
		return;
	}

	CRegion::eSecurity eSecurityType = pRegion->GetSecurity(pAttacker->GetTileX(),pAttacker->GetTileY());

	if (eSecurityType==CRegion::SECURTIY_FIGHT)
	{
		return;
	}
	//////////////////////////////////////////////////////////////////////////




	long lNum = pAtker->GetPkValue() + GlobalSetup::GetSetup()->dwPkCountPerAttack;

	//攻击本阵营PK值为0的角色(白名角色)/攻击本国或本阵营PK值大于0小于等于20的角色(紫名角色)
	if (nAddSub==2				&&
		IsSameCamp(pAtker,pDefer)&&
		(pDefer->GetPkValue()>=0 && pDefer->GetPkValue()<=20 )&&
		(pAtker->GetPkValue()<20))
	{
		if (lNum>20)
		{
			lNum = 20;
		}
		pAtker->SetPkValue(lNum);		
	}
	//对紫名、红名玩家释放增益技能,每次使用增益技能将增加20点PK值,因此方法获得的PK值上限为20,若PK值已经达到或超过20,则PK值不会再因此方法增加
	else if (nAddSub==1 && (pDefer->GetPkValue()>0) && (pAtker->GetPkValue()<20) && pAtker!=pDefer)
	{
		if (lNum>20)
		{
			lNum = 20;
		}		
		pAtker->SetPkValue(lNum);
	}
	else if (nAddSub==2 && !IsSameCamp(pAtker,pDefer) && pDefer->GetPVPValue()==0 && pDefer->GetPkValue()<=20 && pAtker->GetPVPValue()<20)
	{
		if(pRegion->GetStrongPointFlag()==false) // 未开启据点战标志
		{
			//攻击非本阵营恶名值为0且PK值小于等于20的角色
			long lNum = pAtker->GetPVPValue() + GlobalSetup::GetSetup()->dwPkCountPerAttack;
			if( lNum > (long) GlobalSetup::GetSetup()->dwPkCountPerAttack)
			{
				lNum = GlobalSetup::GetSetup()->dwPkCountPerAttack;
			}
			pAtker->SetAttribute("PVPValue",lNum);
			pAtker->UpdateAttribute();
		}
	}
	else if (nAddSub==1  && pDefer->GetPVPValue()>0 && pAtker->GetPVPValue()<20 && pAtker!=pDefer)
	{
		if(pRegion->GetStrongPointFlag()==false) // 未开启据点战标志
		{
			//对已有恶名值的角色使用增益技能&& !IsSameCamp(pAtker,pDefer)
			long lNum = pAtker->GetPVPValue() + GlobalSetup::GetSetup()->dwPkCountPerAttack;
			if (lNum>20)
			{
				lNum = 20;
			}
			pAtker->SetAttribute("PVPValue",lNum);	
			pAtker->UpdateAttribute();
		}
	}



}