For example, we could design a small level where there is a hallway that leads to a room. Right before the room, there is a door that is open by default. Inside the room exists a big bad boss and a door behind the boss that is initially closed. In this scenario, the entry door will want to subscribe to the bosses' ENTER_COMBAT and LEAVE_COMBAT events to trigger closing/opening the door. Similarly, the exit door will want to subscribe to a DEATH event triggered by the boss when he dies, so that the exit door will open under that condition.
In the above example, the exit door's DoorOpenTriggerComponent would have some code that resembles this:
Code: Select all
void CDoorOpenTriggerComponent::OnInitialize() {
EventSystem::getSingleton().addListener(EventSystem::E_DEATH, &CDoorOpenTriggerComponent::OnDeath);
}
void CDoorOpenTriggerComponent::OnDeath(GameEvent& evt) {
if(evt.senderEntityId == bossEntityId) { // how would we get boss' entity id???
m_doorState = OPEN_STATE;
}
}
Under the first scenario (despawn); the above open door trigger logic would still continue to work. However, under the second scenario, the logic would need to be a bit more complex because not only should the door open when the boss dies; but when the boss and all his spawned minions have been killed too.
How would that second scenario work? And how would others support one entity getting the entity information from another spawned entity that it cares about in the relationship of a fight scenario such as this? Would entities have a parent/child relationship such that the boss is the parent with the two doors and all spawned minions being children of the boss?