Пример #1
0
/*virtual*/ void WBCompOwner::HandleEvent( const WBEvent& Event )
{
	XTRACE_FUNCTION;

	Super::HandleEvent( Event );

	// Bit of a hack; OnEquipped is sent from Eldritch code and this lives in Workbench.
	STATIC_HASHED_STRING( OnEquipped );
	STATIC_HASHED_STRING( SetOwner );

	const HashedString EventName = Event.GetEventName();
	if( EventName == sOnEquipped )
	{
		STATIC_HASHED_STRING( Owner );
		WBEntity* const pOwner = Event.GetEntity( sOwner );
		SetOwner( pOwner );
	}
	else if( EventName == sSetOwner )
	{
		STATIC_HASHED_STRING( NewOwner );
		WBEntity* const pNewOwner = Event.GetEntity( sNewOwner );

		SetOwner( pNewOwner );
	}
}
Пример #2
0
/*virtual*/ void WBCompEldSleeper::HandleEvent(const WBEvent& Event) {
  XTRACE_FUNCTION;

  Super::HandleEvent(Event);

  STATIC_HASHED_STRING(OnDamaged);
  STATIC_HASHED_STRING(OnAINoise);

  const HashedString EventName = Event.GetEventName();
  if (EventName == sOnDamaged) {
    Wake();
  } else if (EventName == sOnAINoise) {
    STATIC_HASHED_STRING(EventOwner);
    WBEntity* const pEventOwner = Event.GetEntity(sEventOwner);
    ASSERT(pEventOwner);

    if (pEventOwner == GetEntity()) {
      // Ignore AI noises from self (see SensorHearing for more details).
    } else {
      STATIC_HASHED_STRING(NoiseLocation);
      const Vector NoiseLocation = Event.GetVector(sNoiseLocation);

      STATIC_HASHED_STRING(NoiseRadius);
      const float NoiseRadius = Event.GetFloat(sNoiseRadius);

      HandleNoise(NoiseLocation, NoiseRadius);
    }
  }
}
Пример #3
0
/*virtual*/ void WBCompEldPickup::HandleEvent( const WBEvent& Event )
{
	XTRACE_FUNCTION;

	Super::HandleEvent( Event );

	STATIC_HASHED_STRING( OnFrobbed );
	STATIC_HASHED_STRING( OnPurchaseBuy );
	STATIC_HASHED_STRING( OnPurchaseSteal );
	STATIC_HASHED_STRING( OnShopkeeperDied );

	const HashedString EventName = Event.GetEventName();
	if( EventName == sOnShopkeeperDied )
	{
		m_Price = 0;
	}
	else if( EventName == sOnFrobbed )
	{
		STATIC_HASHED_STRING( Frobber );
		WBEntity* const pFrobber = Event.GetEntity( sFrobber );
		ASSERT( pFrobber );

		if( m_Price > 0 )
		{
			SellItemTo( pFrobber );
		}
		else
		{
			GiveItemTo( pFrobber );
		}
	}
	else if( EventName == sOnPurchaseBuy )
	{
		if( this == sm_PurchasePickup )
		{
			ASSERT( sm_Purchaser );
			AcceptPaymentFrom( sm_Purchaser );
			NotifyPurchasedBy( sm_Purchaser );
			GiveItemTo( sm_Purchaser );
		}
	}
	else if( EventName == sOnPurchaseSteal )
	{
		if( this == sm_PurchasePickup )
		{
			ASSERT( sm_Purchaser );
			NotifyTheftBy( sm_Purchaser );
			GiveItemTo( sm_Purchaser );
		}
	}
}
Пример #4
0
/*virtual*/ void WBCompEldSensorTheft::HandleEvent(const WBEvent& Event) {
  XTRACE_FUNCTION;

  Super::HandleEvent(Event);

  STATIC_HASHED_STRING(OnTheft);

  const HashedString EventName = Event.GetEventName();
  if (EventName == sOnTheft) {
    STATIC_HASHED_STRING(Thief);
    WBEntity* const pThief = Event.GetEntity(sThief);

    HandleTheft(pThief);

    // Also, forward event to this entity for scripting to handle.
    {
      WB_MAKE_EVENT(OnTheftSensed, GetEntity());
      WB_SET_AUTO(OnTheftSensed, Entity, Thief, pThief);
      WB_DISPATCH_EVENT(GetEventManager(), OnTheftSensed, GetEntity());
    }
  }
}
Пример #5
0
/*virtual*/ void WBCompEldMesh::HandleEvent(const WBEvent& Event) {
  XTRACE_FUNCTION;

  Super::HandleEvent(Event);

  STATIC_HASHED_STRING(OnInitialized);
  STATIC_HASHED_STRING(OnSpawnedQueued);
  STATIC_HASHED_STRING(OnLoaded);
  STATIC_HASHED_STRING(OnBecameFrobTarget);
  STATIC_HASHED_STRING(Hide);
  STATIC_HASHED_STRING(Show);
  STATIC_HASHED_STRING(HideMesh);
  STATIC_HASHED_STRING(ShowMesh);
  STATIC_HASHED_STRING(PlayAnim);
  STATIC_HASHED_STRING(SetAnim);
  STATIC_HASHED_STRING(CopyAnimations);
  STATIC_HASHED_STRING(SetMesh);
  STATIC_HASHED_STRING(SetTexture);

  const HashedString EventName = Event.GetEventName();
  if (EventName == sOnInitialized) {
    SetSendUpdatedEvent();
  } else if (EventName == sOnSpawnedQueued ||
             EventName == sOnLoaded)  // Need to have a valid transform
  {
    ImmediateUpdateBlendedIrradiance();
  } else if (EventName == sOnBecameFrobTarget) {
    STATIC_HASHED_STRING(IsFrobTarget);
    const bool IsFrobTarget = Event.GetBool(sIsFrobTarget);

    if (IsFrobTarget) {
      STATIC_HASHED_STRING(Highlight);
      m_CurrentHighlight = Event.GetVector(sHighlight);
    } else {
      m_CurrentHighlight.Zero();
    }
  } else if (EventName == sHide || EventName == sHideMesh) {
    m_Hidden = true;
  } else if (EventName == sShow || EventName == sShowMesh) {
    m_Hidden = false;
  } else if (EventName == sPlayAnim) {
    STATIC_HASHED_STRING(AnimationName);
    const HashedString AnimationName = Event.GetHash(sAnimationName);

    STATIC_HASHED_STRING(Loop);
    const bool Loop = Event.GetBool(sLoop);

    STATIC_HASHED_STRING(IgnoreIfAlreadyPlaying);
    const bool IgnoreIfAlreadyPlaying = Event.GetBool(sIgnoreIfAlreadyPlaying);

    STATIC_HASHED_STRING(PlayRate);
    const float PlayRate = Event.GetFloat(sPlayRate);

    PlayAnimation(AnimationName, Loop, IgnoreIfAlreadyPlaying, PlayRate);
  } else if (EventName == sSetAnim) {
    STATIC_HASHED_STRING(AnimationIndex);
    const int AnimationIndex = Event.GetInt(sAnimationIndex);

    STATIC_HASHED_STRING(AnimationTime);
    const float AnimationTime = Event.GetFloat(sAnimationTime);

    STATIC_HASHED_STRING(AnimationEndBehavior);
    const int AnimationEndBehavior = Event.GetInt(sAnimationEndBehavior);

    STATIC_HASHED_STRING(AnimationPlayRate);
    const float AnimationPlayRate = Event.GetFloat(sAnimationPlayRate);

    AnimationState::SPlayAnimationParams PlayParams;
    PlayParams.m_EndBehavior =
        static_cast<AnimationState::EAnimationEndBehavior>(
            AnimationEndBehavior);

    m_Mesh->SetAnimation(AnimationIndex, PlayParams);
    m_Mesh->SetAnimationTime(AnimationTime);
    m_Mesh->SetAnimationPlayRate(AnimationPlayRate > 0.0f ? AnimationPlayRate
                                                          : 1.0f);
  } else if (EventName == sCopyAnimations) {
    STATIC_HASHED_STRING(SourceEntity);
    WBEntity* const pSourceEntity = Event.GetEntity(sSourceEntity);

    STATIC_HASHED_STRING(SuppressAnimEvents);
    const bool SuppressAnimEvents = Event.GetBool(sSuppressAnimEvents);

    CopyAnimationsFrom(pSourceEntity, SuppressAnimEvents);
  } else if (EventName == sSetMesh) {
    STATIC_HASHED_STRING(Mesh);
    const SimpleString Mesh = Event.GetString(sMesh);

    STATIC_HASHED_STRING(Texture);
    const SimpleString Texture = Event.GetString(sTexture);

    SetMesh(Mesh);
    SetTexture(Texture);
    UpdateMesh(0.0f);
  } else if (EventName == sSetTexture) {
    STATIC_HASHED_STRING(Texture);
    const SimpleString Texture = Event.GetString(sTexture);

    SetTexture(Texture);
  }
}
Пример #6
0
/*virtual*/ void WBCompEldFrobbable::HandleEvent(const WBEvent& Event) {
  XTRACE_FUNCTION;

  Super::HandleEvent(Event);

  STATIC_HASHED_STRING(MarshalFrob);
  STATIC_HASHED_STRING(OnInitialized);
  STATIC_HASHED_STRING(OnDestroyed);
  STATIC_HASHED_STRING(OnMeshUpdated);
  STATIC_HASHED_STRING(SetIsFrobbable);
  STATIC_HASHED_STRING(BecomeFrobbable);
  STATIC_HASHED_STRING(BecomeNonFrobbable);
  STATIC_HASHED_STRING(SetHoldReleaseMode);
  STATIC_HASHED_STRING(SetFriendlyName);
  STATIC_HASHED_STRING(SetFrobVerb);
  STATIC_HASHED_STRING(SetBoundExtents);
  STATIC_HASHED_STRING(SetBoundOffsetZ);

  const HashedString EventName = Event.GetEventName();

  if (EventName == sMarshalFrob) {
    STATIC_HASHED_STRING(Frobber);
    WBEntity* const pFrobber = Event.GetEntity(sFrobber);

    STATIC_HASHED_STRING(InputEdge);
    const int InputEdge = Event.GetInt(sInputEdge);

    MarshalFrob(pFrobber, InputEdge);
  } else if (EventName == sOnInitialized) {
    if (m_UseCollisionExtents) {
      WBCompEldCollision* const pCollision =
          GET_WBCOMP(GetEntity(), EldCollision);
      if (pCollision) {
        m_BoundExtents =
            pCollision->GetExtents() +
            Vector(m_ExtentsFatten, m_ExtentsFatten, m_ExtentsFatten);
      }
    }
  } else if (EventName == sOnDestroyed) {
    if (m_IsProbableFrobbable) {
      SetHUDHidden(true);
    }
  } else if (EventName == sOnMeshUpdated) {
    ASSERT(m_UseMeshExtents);

    WBCompEldTransform* const pTransform =
        GetEntity()->GetTransformComponent<WBCompEldTransform>();
    DEVASSERT(pTransform);

    WBCompEldMesh* const pMeshComponent = GET_WBCOMP(GetEntity(), EldMesh);
    ASSERT(pMeshComponent);

    EldritchMesh* const pMesh = pMeshComponent->GetMesh();
    ASSERT(pMesh);

    m_BoundExtents = pMesh->m_AABB.GetExtents() +
                     Vector(m_ExtentsFatten, m_ExtentsFatten, m_ExtentsFatten);
    m_BoundOffset = pMesh->m_AABB.GetCenter() - pTransform->GetLocation();
  } else if (EventName == sSetIsFrobbable) {
    STATIC_HASHED_STRING(IsFrobbable);
    m_IsFrobbable = Event.GetBool(sIsFrobbable);
  } else if (EventName == sBecomeFrobbable) {
    m_IsFrobbable = true;
  } else if (EventName == sBecomeNonFrobbable) {
    m_IsFrobbable = false;
  } else if (EventName == sSetHoldReleaseMode) {
    const bool WasHoldReleaseMode = m_HoldReleaseMode;

    STATIC_HASHED_STRING(HoldReleaseMode);
    m_HoldReleaseMode = Event.GetBool(sHoldReleaseMode);

    if (m_HoldReleaseMode && !WasHoldReleaseMode) {
      m_HandleHoldRelease = false;
    }

    if (GetIsFrobTarget()) {
      PublishToHUD();
    }
  } else if (EventName == sSetFriendlyName) {
    STATIC_HASHED_STRING(FriendlyName);
    m_FriendlyName = Event.GetString(sFriendlyName);

    if (GetIsFrobTarget()) {
      PublishToHUD();
    }
  } else if (EventName == sSetFrobVerb) {
    STATIC_HASHED_STRING(FrobVerb);
    m_FrobVerb = Event.GetString(sFrobVerb);

    if (GetIsFrobTarget()) {
      PublishToHUD();
    }
  } else if (EventName == sSetBoundExtents) {
    STATIC_HASHED_STRING(BoundExtents);
    m_BoundExtents = Event.GetVector(sBoundExtents);
  } else if (EventName == sSetBoundOffsetZ) {
    STATIC_HASHED_STRING(BoundOffsetZ);
    m_BoundOffset.z = Event.GetFloat(sBoundOffsetZ);
  }
}
Пример #7
0
/*virtual*/ void WBCompEldHands::HandleEvent( const WBEvent& Event )
{
	XTRACE_FUNCTION;

	Super::HandleEvent( Event );

	STATIC_HASHED_STRING( OnWorldLoaded );
	STATIC_HASHED_STRING( OnItemEquipped );
	STATIC_HASHED_STRING( OnItemUnequipped );
	STATIC_HASHED_STRING( OnItemsSwapped );
	STATIC_HASHED_STRING( UseRightHand );
	STATIC_HASHED_STRING( UseLeftHand );
	STATIC_HASHED_STRING( ShowHands );
	STATIC_HASHED_STRING( HideHands );
	STATIC_HASHED_STRING( PlayHandAnim );
	STATIC_HASHED_STRING( SetHandMeshes );

	const HashedString EventName = Event.GetEventName();
	if( EventName == sOnWorldLoaded )
	{
		if( GetItemInRightHand() == GetWeapon() )
		{
			WB_MAKE_EVENT( OnWeaponEquipped, GetEntity() );
			WB_SET_AUTO( OnWeaponEquipped, Entity, Weapon, GetWeapon() );
			WB_DISPATCH_EVENT( GetEventManager(), OnWeaponEquipped, GetEntity() );
		}

		RestoreHandAnimations();

		UpdateWeaponHUD();
	}
	else if( EventName == sOnItemEquipped )
	{
		STATIC_HASHED_STRING( Item );
		WBEntity* const pItem = Event.GetEntity( sItem );
		ASSERT( pItem );

		// Hide fists and show ammo when we equip a weapon
		if( pItem == GetWeapon() )
		{
			WB_MAKE_EVENT( Hide, GetEntity() );
			WB_DISPATCH_EVENT( GetEventManager(), Hide, GetFists() );

			WB_MAKE_EVENT( OnWeaponEquipped, GetEntity() );
			WB_SET_AUTO( OnWeaponEquipped, Entity, Weapon, pItem );
			WB_DISPATCH_EVENT( GetEventManager(), OnWeaponEquipped, GetEntity() );

			ShowWeaponHUD();
		}
		
		if( pItem == GetItemInRightHand() ||
			pItem == GetItemInLeftHand() )
		{
			AddAnimationsToHand( pItem );
		}

		if( pItem == GetWeaponAlt() )
		{
			// When traveling to a new world and spawning an item in the alt slot, immediately hide it
			WB_MAKE_EVENT( Hide, GetEntity() );
			WB_DISPATCH_EVENT( GetEventManager(), Hide, GetWeaponAlt() );

			ShowWeaponAltHUD();
		}
	}
	else if( EventName == sOnItemUnequipped )
	{
		// Show fists when we unequip a weapon
		STATIC_HASHED_STRING( Item );
		WBEntity* const pItem = Event.GetEntity( sItem );
		if( pItem == GetWeapon() )
		{
			WB_MAKE_EVENT( Show, GetEntity() );
			WB_DISPATCH_EVENT( GetEventManager(), Show, GetFists() );

			WB_MAKE_EVENT( OnWeaponUnequipped, GetEntity() );
			WB_DISPATCH_EVENT( GetEventManager(), OnWeaponUnequipped, GetEntity() );

			// Revert to the fists animations
			AddAnimationsToHand( GetFists(), EH_Right );

			// HACK: Play the idle animation. I could add an event for "restored equip focus"
			// or whatever and hook this up in data, but eh. That somehow feels worse.
			STATIC_HASHED_STRING( Idle );
			PlayAnimation( GetFists(), sIdle, EH_Right );

			HideWeaponHUD();
		}
	}
	else if( EventName == sOnItemsSwapped )
	{
		// HACK, since the only things we swap (currently) are Weapon/WeaponAlt

		// Hide the alt weapon, show the right hand item
		WB_MAKE_EVENT( Hide, GetEntity() );
		WB_DISPATCH_EVENT( GetEventManager(), Hide, GetWeaponAlt() );

		WB_MAKE_EVENT( Show, GetEntity() );
		WB_DISPATCH_EVENT( GetEventManager(), Show, GetItemInRightHand() );

		AddAnimationsToHand( GetItemInRightHand() );

		STATIC_HASHED_STRING( Idle );
		PlayAnimation( GetItemInRightHand(), sIdle, EH_Right );

		UpdateWeaponHUD();

		WB_MAKE_EVENT( OnWeaponEquipped, GetEntity() );
		WB_SET_AUTO( OnWeaponEquipped, Entity, Weapon, GetItemInRightHand() );
		WB_DISPATCH_EVENT( GetEventManager(), OnWeaponEquipped, GetEntity() );
	}
	else if( EventName == sUseRightHand )
	{
		WBEntity* const pWeapon = GetItemInRightHand();
		if( pWeapon )
		{
			STATIC_HASHED_STRING( InputEdge );
			const int InputEdge = Event.GetInt( sInputEdge );

			{
				WB_MAKE_EVENT( Use, GetEntity() );
				WB_SET_AUTO( Use, Int, InputEdge, InputEdge );
				WB_DISPATCH_EVENT( GetEventManager(), Use, pWeapon );
			}
		}
	}
	else if( EventName == sUseLeftHand )
	{
		WBEntity* const pPower = GetItemInLeftHand();
		if( pPower )
		{
			STATIC_HASHED_STRING( InputEdge );
			const int InputEdge = Event.GetInt( sInputEdge );

			{
				WB_MAKE_EVENT( Use, GetEntity() );
				WB_SET_AUTO( Use, Int, InputEdge, InputEdge );
				WB_DISPATCH_EVENT( GetEventManager(), Use, pPower );
			}
		}
	}
	else if( EventName == sShowHands )
	{
		DecrementHideHandsRefs();
	}
	else if( EventName == sHideHands )
	{
		IncrementHideHandsRefs();
	}
	else if( EventName == sPlayHandAnim )
	{
		STATIC_HASHED_STRING( AnimatingEntity );
		WBEntity* const pAnimatingEntity = Event.GetEntity( sAnimatingEntity );

		STATIC_HASHED_STRING( AnimationName );
		const HashedString AnimationName = Event.GetHash( sAnimationName );

		// Don't play hand anim if we're restoring the alternate weapon
		if( pAnimatingEntity == GetItemInRightHand() || pAnimatingEntity == GetItemInLeftHand() )
		{
			const EHand Hand = GetHandEnum( pAnimatingEntity );
			PlayAnimation( pAnimatingEntity, AnimationName, Hand );
		}
	}
	else if( EventName == sSetHandMeshes )
	{
		STATIC_HASHED_STRING( LeftHandMesh );
		const SimpleString LeftHandMesh = Event.GetString( sLeftHandMesh );

		STATIC_HASHED_STRING( LeftHandTexture );
		const SimpleString LeftHandTexture = Event.GetString( sLeftHandTexture );

		STATIC_HASHED_STRING( RightHandMesh );
		const SimpleString RightHandMesh = Event.GetString( sRightHandMesh );

		STATIC_HASHED_STRING( RightHandTexture );
		const SimpleString RightHandTexture = Event.GetString( sRightHandTexture );

		SetHandMeshes( LeftHandMesh, LeftHandTexture, RightHandMesh, RightHandTexture );
		RestoreHandAnimations();
	}
}