void KillFeedSystem::Update(double dt) { auto killFeeds = m_World->GetComponents("KillFeed"); if (killFeeds == nullptr) { return; } for (auto it = m_DeathQueue.begin(); it != m_DeathQueue.end(); it++) { (*it).TimeToLive -= dt; } for (auto& killFeedComponent : *killFeeds) { EntityWrapper entity = EntityWrapper(m_World, killFeedComponent.EntityID); for (int i = 1; i <= 3; i++) { EntityWrapper child = entity.FirstChildByName("KillFeed" + std::to_string(i)); if (child.HasComponent("Text")) { (Field<std::string>)child["Text"]["Content"] = ""; } } int feedIndex = 1; for (auto it = m_DeathQueue.begin(); it != m_DeathQueue.end(); ) { bool remove = false; EntityWrapper child = entity.FirstChildByName("KillFeed" + std::to_string(feedIndex)); if (child.HasComponent("Text")) { std::string str = ""; //Add killer to the start of string. str = (*it).KillerColor + "\\" + std::to_string((*it).KillerClass) + "\\CFFFFFF" + " " + (*it).KillerName + " "; //Add Weapon to middle of string. str += "\\" + std::to_string((*it).KillerClass+3) + " "; //Add victim to the end of string str += (*it).VictimColor + "\\" + std::to_string((*it).VictimClass) + "\\CFFFFFF" + " " + (*it).VictimName; (Field<std::string>)child["Text"]["Content"] = str; if ((*it).TimeToLive <= 0.f) { (Field<std::string>)child["Text"]["Content"] = ""; remove = true; } } feedIndex++; if(feedIndex > 3) { break; } if(remove) { it = m_DeathQueue.erase(it); } else { it++; } } } }
void DefenderWeaponBehaviour::CheckBoost(ComponentWrapper cWeapon, WeaponInfo& wi) { // Only check ammo client side if (!IsClient) { return; } // Only handle ammo check for the local player if (wi.Player != LocalPlayer) { return; } // Make sure the player isn't checking from the grave if (!wi.Player.Valid()) { return; } // 3D-pick middle of screen Rectangle viewport = m_Renderer->GetViewportSize(); glm::vec2 centerScreen(viewport.Width / 2, viewport.Height / 2); // TODO: Some horizontal spread PickData pickData = m_Renderer->Pick(centerScreen); EntityWrapper victim(m_World, pickData.Entity); if (!victim.Valid()) { return; } // Don't let us somehow shoot ourselves in the foot if (victim == LocalPlayer) { return; } // Only care about players being hit if (!victim.HasComponent("Player")) { victim = victim.FirstParentWithComponent("Player"); } if (!victim.Valid()) { return; } // If friendly fire, reduce damage to 0 (needed to make Boosts, Ammosharing work) if ((ComponentInfo::EnumType)victim["Team"]["Team"] == (ComponentInfo::EnumType)wi.Player["Team"]["Team"]) { EntityWrapper friendlyBoostHudSpawner = wi.FirstPersonPlayerModel.FirstChildByName("FriendlyBoostAttachment"); if (friendlyBoostHudSpawner.Valid()) { EntityWrapper assaultBoost = victim.FirstChildByName("BoostAssault"); EntityWrapper defenderBoost = victim.FirstChildByName("BoostDefender"); EntityWrapper sniperBoost = victim.FirstChildByName("BoostSniper"); auto children = m_World->GetDirectChildren(friendlyBoostHudSpawner.ID); if (children.first == children.second) { if (friendlyBoostHudSpawner.HasComponent("Spawner")) { EntityWrapper friendlyBoostHud = SpawnerSystem::Spawn(friendlyBoostHudSpawner, friendlyBoostHudSpawner); if (friendlyBoostHud.Valid()) { EntityWrapper assaultBoostEntity = friendlyBoostHud.FirstChildByName("AssaultBoost"); if (assaultBoostEntity.Valid()) { EntityWrapper active = assaultBoostEntity.FirstChildByName("Active"); if (active.HasComponent("Text")) { if (assaultBoost.Valid()) { (Field<bool>)active["Text"]["Visible"] = true; } else { (Field<bool>)active["Text"]["Visible"] = false; } } } EntityWrapper defenderBoostEntity = friendlyBoostHud.FirstChildByName("DefenderBoost"); if (defenderBoostEntity.Valid()) { EntityWrapper active = defenderBoostEntity.FirstChildByName("Active"); if (active.HasComponent("Text")) { if (defenderBoost.Valid()) { (Field<bool>)active["Text"]["Visible"] = true; } else { (Field<bool>)active["Text"]["Visible"] = false; } } } EntityWrapper sniperBoostEntity = friendlyBoostHud.FirstChildByName("SniperBoost"); if (sniperBoostEntity.Valid()) { EntityWrapper active = sniperBoostEntity.FirstChildByName("Active"); if (active.HasComponent("Text")) { if (sniperBoost.Valid()) { (Field<bool>)active["Text"]["Visible"] = true; } else { (Field<bool>)active["Text"]["Visible"] = false; } } } } } } else { EntityWrapper friendlyBoostHud = friendlyBoostHudSpawner.FirstChildByName("FriendlyBoostHUD"); if (friendlyBoostHud.Valid()) { if (friendlyBoostHud.HasComponent("Lifetime")) { (Field<double>)friendlyBoostHud["Lifetime"]["Lifetime"] = 0.5; } EntityWrapper assaultBoostEntity = friendlyBoostHud.FirstChildByName("AssaultBoost"); if (assaultBoostEntity.Valid()) { EntityWrapper active = assaultBoostEntity.FirstChildByName("Active"); if (active.HasComponent("Text")) { if (assaultBoost.Valid()) { (Field<bool>)active["Text"]["Visible"] = true; } else { (Field<bool>)active["Text"]["Visible"] = false; } } } EntityWrapper defenderBoostEntity = friendlyBoostHud.FirstChildByName("DefenderBoost"); if (defenderBoostEntity.Valid()) { EntityWrapper active = defenderBoostEntity.FirstChildByName("Active"); if (active.HasComponent("Text")) { if (defenderBoost.Valid()) { (Field<bool>)active["Text"]["Visible"] = true; } else { (Field<bool>)active["Text"]["Visible"] = false; } } } EntityWrapper sniperBoostEntity = friendlyBoostHud.FirstChildByName("SniperBoost"); if (sniperBoostEntity.Valid()) { EntityWrapper active = sniperBoostEntity.FirstChildByName("Active"); if (active.HasComponent("Text")) { if (sniperBoost.Valid()) { (Field<bool>)active["Text"]["Visible"] = true; } else { (Field<bool>)active["Text"]["Visible"] = false; } } } } } } } }
void PlayerSpawnSystem::Update(double dt) { // If there are no CapturePointGameMode components we will just spawn immediately. // Should be able to support older maps with this. // TODO: In the future we might want to return instead, to avoid spawning in the menu for instance. auto pool = m_World->GetComponents("CapturePointGameMode"); if (pool != nullptr && pool->size() > 0) { // Take the first CapturePointGameMode component found. ComponentWrapper& modeComponent = *pool->begin(); // Increase timer. Field<double> timer = modeComponent["RespawnTime"]; timer += dt; if (m_DbgConfigForceRespawn) { (Field<double>)modeComponent["MaxRespawnTime"] = m_ForcedRespawnTime; } double maxRespawnTime = (double)modeComponent["MaxRespawnTime"]; EntityWrapper spectatorCam = m_World->GetFirstEntityByName("SpectatorCamera"); if (spectatorCam.Valid()) { EntityWrapper HUD = spectatorCam.FirstChildByName("SpectatorHUD"); if (HUD.Valid()) { EntityWrapper respawnTimer = spectatorCam.FirstChildByName("RespawnTimer"); if (respawnTimer.Valid()) { //Update respawn time in the HUD element. respawnTimer["Text"]["Content"] = std::to_string(1 + (int)(maxRespawnTime - timer)); } } } if (timer < maxRespawnTime) { return; } // If respawn time has passed, we spawn all players that have requested to be spawned. timer = 0; } // If there are no spawn requests, return immediately, if we are client the SpawnRequests should always be empty. if (m_SpawnRequests.size() == 0) { return; } auto playerSpawns = m_World->GetComponents("PlayerSpawn"); if (playerSpawns == nullptr) { return; } int numSpawnedPlayers = 0; int playersSpectating = 0; const int numRequestsToHandle = (int)m_SpawnRequests.size(); for (auto it = m_SpawnRequests.begin(); it != m_SpawnRequests.end(); ++it) { // It is valid if they didn't pick class yet // but don't spawn anything, goto next spawnrequest. if (it->Class == PlayerClass::None) { ++playersSpectating; continue; } for (auto& cPlayerSpawn : *playerSpawns) { EntityWrapper spawner(m_World, cPlayerSpawn.EntityID); if (!spawner.HasComponent("Spawner")) { continue; } // If the spawner has a team affiliation, check it if (spawner.HasComponent("Team")) { auto cSpawnerTeam = spawner["Team"]; if ((int)cSpawnerTeam["Team"] != it->Team) { // If they somehow has a valid class as spectator, don't spawn them. if (it->Team == cSpawnerTeam["Team"].Enum("Spectator")) { ++playersSpectating; break; } else { continue; } } } // TODO: Choose a different spawner depending on class picked? std::string playerEntityFile; if (it->Class == PlayerClass::Assault) { playerEntityFile = (const std::string&)cPlayerSpawn["AssaultFile"]; } else if (it->Class == PlayerClass::Defender) { playerEntityFile = (const std::string&)cPlayerSpawn["DefenderFile"]; } else if (it->Class == PlayerClass::Sniper) { playerEntityFile = (const std::string&)cPlayerSpawn["SniperFile"]; } // Spawn the player! EntityWrapper player = SpawnerSystem::SpawnEntityFile(playerEntityFile, spawner, EntityWrapper::Invalid, "Player"); // Set the player team affiliation player["Team"]["Team"] = it->Team; // Publish a PlayerSpawned event Events::PlayerSpawned e; e.PlayerID = it->PlayerID; e.Player = player; e.Spawner = spawner; m_EventBroker->Publish(e); ++numSpawnedPlayers; it = m_SpawnRequests.erase(it); break; } if (it == m_SpawnRequests.end()) { break; } } if (numSpawnedPlayers != numRequestsToHandle - playersSpectating) { LOG_DEBUG("%i players were supposed to be spawned, but only %i was successfully.", numRequestsToHandle - playersSpectating, numSpawnedPlayers); } else { std::string dbg = numSpawnedPlayers != 0 ? std::to_string(numSpawnedPlayers) + " players were spawned. " : ""; dbg += playersSpectating != 0 ? std::to_string(playersSpectating) + " players are spectating/picking class. " : ""; LOG_DEBUG(dbg.c_str()); } }
bool DefenderWeaponBehaviour::OnInputCommand(ComponentWrapper cWeapon, WeaponInfo& wi, const Events::InputCommand& e) { if (e.Command == "SpecialAbility") { EntityWrapper attachment = wi.Player.FirstChildByName("ShieldAttachment"); if (attachment.Valid()) { if (e.Value > 0) { if(wi.Player.Valid()) { if(wi.Player.HasComponent("ShieldAbility")) { (Field<bool>)wi.Player["ShieldAbility"]["Active"] = true; } } if (IsServer) { SpawnerSystem::Spawn(attachment, attachment); } EntityWrapper backAttachment = attachment.FirstChildByName("Back"); if (backAttachment.Valid()) { Events::AutoAnimationBlend eDeployShieldAttachement; eDeployShieldAttachement.RootNode = backAttachment; eDeployShieldAttachement.NodeName = "Deploy"; eDeployShieldAttachement.Restart = true; eDeployShieldAttachement.Start = true; m_EventBroker->Publish(eDeployShieldAttachement); } EntityWrapper frontAttachment = attachment.FirstChildByName("Front"); if (frontAttachment.Valid()) { Events::AutoAnimationBlend eDeployShieldAttachement; eDeployShieldAttachement.RootNode = frontAttachment; eDeployShieldAttachement.NodeName = "Deploy"; eDeployShieldAttachement.Restart = true; eDeployShieldAttachement.Start = true; m_EventBroker->Publish(eDeployShieldAttachement); } if (IsClient) { EntityWrapper root = wi.FirstPersonEntity; if (root.Valid()) { EntityWrapper animationNode = root.FirstChildByName("Shield"); if (animationNode.Valid()) { Events::AutoAnimationBlend eShieldBlend; eShieldBlend.RootNode = root; eShieldBlend.NodeName = "Shield"; eShieldBlend.Restart = true; eShieldBlend.Start = true; m_EventBroker->Publish(eShieldBlend); } } } else { // server only EntityWrapper root = wi.ThirdPersonPlayerModel; if (root.Valid()) { Events::AutoAnimationBlend eShieldActivateBlend; eShieldActivateBlend.RootNode = root; eShieldActivateBlend.NodeName = "ActivateShield"; eShieldActivateBlend.Restart = true; eShieldActivateBlend.Start = true; m_EventBroker->Publish(eShieldActivateBlend); EntityWrapper animationNode = root.FirstChildByName("ActivateShield"); if (animationNode.Valid()) { Events::AutoAnimationBlend eShieldIdleBlend; eShieldIdleBlend.RootNode = root; eShieldIdleBlend.NodeName = "ShieldFront"; eShieldIdleBlend.Restart = true; eShieldIdleBlend.Start = true; eShieldIdleBlend.AnimationEntity = animationNode; m_EventBroker->Publish(eShieldIdleBlend); } } } } else { attachment.DeleteChildren(); if (wi.Player.Valid()) { if (wi.Player.HasComponent("ShieldAbility")) { (Field<bool>)wi.Player["ShieldAbility"]["Active"] = false; } } if (IsClient) { EntityWrapper root = wi.FirstPersonEntity; if (root.Valid()) { EntityWrapper animationNode = root.FirstChildByName("ActionBlend"); if (animationNode.Valid()) { Events::AutoAnimationBlend eFireBlend; eFireBlend.RootNode = root; eFireBlend.NodeName = "ActionBlend"; eFireBlend.Restart = true; eFireBlend.Start = true; m_EventBroker->Publish(eFireBlend); } } } else { // server only EntityWrapper root = wi.ThirdPersonPlayerModel; if (root.Valid()) { Events::AutoAnimationBlend eShieldDeactivateBlend; eShieldDeactivateBlend.RootNode = root; eShieldDeactivateBlend.NodeName = "ActivateShield"; eShieldDeactivateBlend.Restart = true; eShieldDeactivateBlend.Start = true; eShieldDeactivateBlend.Reverse = true; m_EventBroker->Publish(eShieldDeactivateBlend); EntityWrapper animationNode = root.FirstChildByName("ActivateShield"); if (animationNode.Valid()) { Events::AutoAnimationBlend eActionBlend; eActionBlend.RootNode = root; eActionBlend.NodeName = "ActionBlend"; eActionBlend.AnimationEntity = animationNode; m_EventBroker->Publish(eActionBlend); } } } } } } return false; }