//--------------------------------------------
void CLaser::TurnOnLaser(bool manual /*= false*/)
{
	CWeapon* pParentWeapon = GetWeapon();
	if(pParentWeapon == NULL)
		return;

	m_laserHelperFP.clear();
	const SAccessoryParams *params = GetWeapon()->GetAccessoryParams(GetEntity()->GetClass());
	if (params)
		m_laserHelperFP = params->attach_helper;

	int slot = pParentWeapon->IsOwnerFP() ? eIGS_FirstPerson: eIGS_ThirdPerson;

	CActor* pOwner = pParentWeapon->GetOwnerActor();
	GetGameObject()->EnableUpdateSlot(this, eIUS_General);
	if (pOwner && pOwner->IsPlayer())
		pParentWeapon->SetFiringLocator(this);
	m_laserBeam.TurnOnLaser();

	//Turn off crosshair
	if (pParentWeapon->IsOwnerClient())
	{
		pParentWeapon->SetCrosshairMode(CWeapon::eWeaponCrossHair_ForceOff);
		pParentWeapon->FadeCrosshair(0.0f, g_pGame->GetUI()->GetCVars()->hud_Crosshair_laser_fadeOutTime);
	}
}
示例#2
0
	void execute(CItem *_this)
	{
		CActor *pActor = weapon->GetOwnerActor();

		if(pActor)
		{
			CItem			*pMain = weapon->GetActorItem(pActor);

			if(pMain)
				pMain->PlayAction(g_pItemStrings->idle, 0, false, CItem::eIPAF_Default|CItem::eIPAF_NoBlend);
		}
	}
//-------------------------------------------
void CLaser::Update(SEntityUpdateContext& ctx, int slot)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	if((slot == eIUS_General) && m_laserBeam.IsLaserActivated())
	{
		RequireUpdate(eIUS_General);

		CWeapon* pParentWeapon = GetWeapon();
		if (pParentWeapon)
		{
			CActor* pOwnerActor = pParentWeapon->GetOwnerActor();
			Vec3 laserPos, laserDir;
			GetLaserPositionAndDirection(pParentWeapon, laserPos, laserDir);

			CLaserBeam::SLaserUpdateDesc laserUpdateDesc(laserPos, laserDir, ctx.fFrameTime, pParentWeapon->GetEntity()->IsHidden());
			laserUpdateDesc.m_weaponZoomed = pParentWeapon->IsZoomed() || pParentWeapon->IsZoomingInOrOut();

			m_laserBeam.UpdateLaser(laserUpdateDesc);
		}
	}
}
示例#4
0
int CScriptBind_Weapon::AttachAccessoryPlaceHolder(IFunctionHandler *pH, SmartScriptTable accessory, bool attach)
{
	CWeapon *pWeapon = GetWeapon(pH);
	if (!pWeapon)
		return pH->EndFunction();

	const char *accessoryName;
	accessory->GetValue("class", accessoryName);
	ScriptHandle id;
	accessory->GetValue("id", id);
	
	EntityId entId = (EntityId)id.n;
	//CryLogAlways("id = %d", entId);
	IEntity *attachment = gEnv->pEntitySystem->GetEntity(entId);
	

	if (accessoryName)
	{
		//CryLogAlways("got name: %s", accessoryName);
		if (pWeapon->GetAccessoryPlaceHolder(accessoryName))
		{
			//CryLogAlways("found accessory place holder");
			pWeapon->AttachAccessoryPlaceHolder(accessoryName, attach);
		}
		else
		{
			//CryLogAlways("accessory place holder not found");
			CActor *pActor = pWeapon->GetOwnerActor();
			IEntity *wep = pWeapon->GetEntity();
			//IGameObject *pGameObject = pWeapon->GetOwnerActor()->GetGameObject();
			IInventory *pInventory = pActor->GetInventory();
			if (pInventory)
			{
				//CryLogAlways("found inventory");
				if (attachment)
				{
					if (pInventory->FindItem(entId) != -1)
					{
						//CryLogAlways("found attachment in inventory already...");
					}
					else
					{
						//CryLogAlways("attachment not found in inventory, adding...");
					}
					//CryLogAlways("found attachment");
					
					
					//attachment->DetachThis(0);
					//attachment->SetParentId(0);
					//CItem *t = (CItem *)attachment;
					//t->SetParentId(0);
					//pWeapon->GetEntity()->AttachChild(attachment, false)
					pInventory->AddItem(attachment->GetId());
					//for (int i = 0; i < wep->GetChildCount(); i++)
					//{
					//	IEntity *cur = wep->GetChild(i);
					//	CryLogAlways("none of these should be %s", attachment->GetName());
					//	CryLogAlways(" %s", cur->GetName());
					//}
					pWeapon->AttachAccessoryPlaceHolder(accessoryName, attach);
					pInventory->RemoveItem(attachment->GetId());
					
				}
				else
				{
					//CryLogAlways("!attachment");
				}
			}
		}
		
	}
	return pH->EndFunction();
}
示例#5
0
//------------------------------------------------------------------------
bool CFireModePlugin_Overheat::Update(float frameTime, uint32 frameId)
{
	CWeapon* pWeapon = m_pOwnerFiremode->GetWeapon();

	CRY_ASSERT(pWeapon);

	CActor *pActor = pWeapon->GetOwnerActor();
	bool isOwnerAIControlled = pActor ? !pActor->IsPlayer() : false;

	if(isOwnerAIControlled)
		return false;

	float oldheat = m_heat;

	if (m_overheat > 0.0f)
	{
		m_overheat -= frameTime;
		if (m_overheat <= 0.0f)
		{
			m_overheat = 0.0f;
			FragmentID fragment = pWeapon->GetFragmentID(m_pParams->cooldown.c_str());
			pWeapon->PlayAction(fragment);				
		}
	}
	else
	{
		float add=0.0f;
		float sub=0.0f;

		if (m_firedThisFrame)
		{
			add = m_pParams->attack;

			if(pActor && pActor->GetLinkedVehicle())
			{
				const static float k_VehicleCombatMode_ScaleOverheat = 0.5f;
				add = m_pParams->attack * k_VehicleCombatMode_ScaleOverheat;	
			}

		}
		else if (m_pOwnerFiremode->GetNextShotTime()<=0.0001f && !m_pOwnerFiremode->IsFiring())
		{
			sub=frameTime / m_pParams->decay;
		}

		m_heat = clamp_tpl(m_heat + (add-sub), 0.0f, 1.0f);

		if (m_heat >= 0.999f && oldheat<0.999f)
		{
			m_overheat = m_pParams->duration;
			m_isCoolingDown = true;

			m_pOwnerFiremode->StopFire();
			FragmentID fragment = pWeapon->GetFragmentID(m_pParams->overheating.c_str());
			pWeapon->PlayAction(fragment);

			int slot = pWeapon->GetStats().fp ? eIGS_FirstPerson : eIGS_ThirdPerson;
			if (!m_pParams->effect[slot].empty())
			{
				if (m_heatEffectId)
				{
					pWeapon->DetachEffect(m_heatEffectId);
					m_heatEffectId = 0;
				}

				m_heatEffectId = pWeapon->AttachEffect(slot, false, m_pParams->effect[slot].c_str(), m_pParams->helper[slot].c_str());
			}
		}
		else if(m_heat <= m_pParams->refire_heat)
		{
			m_isCoolingDown = false;
		}
	}

	m_firedThisFrame = false;

	return (m_heat > 0.0001f);
}
示例#6
0
void CFlashLight::EnableLight(bool enable)
{
	CWeapon* pWeapon = GetWeapon();

	if (!pWeapon || !m_sharedparams->pFlashLightParams || (m_lightEnabled && enable) || (!m_lightEnabled && !enable))
	{
		return;
	}

	CActor* pOwner = pWeapon->GetOwnerActor();
	bool ownerIsFP = pWeapon->IsOwnerFP();
	int slot = ownerIsFP ? eIGS_FirstPerson : eIGS_ThirdPerson;

	if (enable)
	{
		const char* attachHelper = "light_term";
		const Vec3 direction = Vec3(-1.0f, 0.0f, 0.0f);

		IRenderNode* pCasterException = NULL;

		if (pOwner)
		{
			IComponentRender* pRenderProxy = static_cast<IComponentRender*>(pOwner->GetEntity()->GetComponent<IComponentRender>().get());

			if (pRenderProxy)
			{
				pCasterException = pRenderProxy->GetRenderNode();
			}
		}

		EntityEffects::SLightAttachParams lightParams;

		lightParams.pCasterException = pCasterException;
		lightParams.color = m_sharedparams->pFlashLightParams->color * m_sharedparams->pFlashLightParams->diffuseMult;
		lightParams.direction = direction;
		lightParams.radius = m_sharedparams->pFlashLightParams->distance;
		lightParams.specularMultiplier = m_sharedparams->pFlashLightParams->specularMult;
		lightParams.projectFov = m_sharedparams->pFlashLightParams->fov;
		lightParams.hdrDynamic = m_sharedparams->pFlashLightParams->HDRDynamic;
		lightParams.projectTexture = m_sharedparams->pFlashLightParams->lightCookie.c_str();
		lightParams.style = m_sharedparams->pFlashLightParams->style;
		lightParams.animSpeed = m_sharedparams->pFlashLightParams->animSpeed;
		lightParams.castShadows = g_pGameCVars->i_flashlight_has_shadows != 0;
		lightParams.firstSafeSlot = eIGS_Last;

		m_lightId = pWeapon->AttachLight(slot, attachHelper, lightParams);

		EnableFogVolume(pWeapon, slot, true);
	}
	else
	{
		if (m_lightId)
		{
			pWeapon->DetachEffect(m_lightId);
		}

		m_lightId = 0;
		EnableFogVolume(pWeapon, slot, false);
	}

	m_lightEnabled = enable;
}