コード例 #1
0
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++;
            }
        }
    }
}
コード例 #2
0
void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& BoneAttachmentComponent, double dt)
{


    if(!entity.HasComponent("Transform")) {
        return;
    }

    auto parent = entity.FirstParentWithComponent("Model");

    if(!parent.Valid()) {
        return;
    }


    Model* model;
    try {
        model = ResourceManager::Load<::Model, true>(parent["Model"]["Resource"]);
    } catch (const std::exception&) {
        return;
    }

    if (!model->IsSkinned()) {
        return;
    }

    Skeleton* skeleton = model->m_Skeleton;

    if(skeleton == nullptr) {
        return;
    }

    int id = skeleton->GetBoneID(entity["BoneAttachment"]["BoneName"]);

    if (id == -1) {
        return;
    }

    if (skeleton->BlendTrees.find(parent) != skeleton->BlendTrees.end()) {


        glm::mat4 boneTransform = skeleton->BlendTrees.at(parent)->GetBoneTransform(id);

        glm::vec3 scale;
        glm::quat rotation;
        glm::vec3 translation;
        glm::vec3 skew;
        glm::vec4 perspective;
        glm::decompose(boneTransform, scale, rotation, translation, skew, perspective);

        rotation = glm::quat((glm::vec3)entity["BoneAttachment"]["OrientationOffset"]) * rotation;
        rotation = glm::inverse(rotation);
        glm::vec3 angles = glm::eulerAngles(rotation);
        
        if ((bool)entity["BoneAttachment"]["InheritPosition"]) {
            entity["Transform"]["Position"] = translation + (glm::vec3)entity["BoneAttachment"]["PositionOffset"];
        }
        if ((bool)entity["BoneAttachment"]["InheritOrientation"]) {
            entity["Transform"]["Orientation"] = angles;
        }
        if ((bool)entity["BoneAttachment"]["InheritScale"]) {
            entity["Transform"]["Scale"] = scale  * (glm::vec3)entity["BoneAttachment"]["ScaleOffset"];
        }
    }

}
コード例 #3
0
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;
                            }
                        }
                    }
                }
            }
        }
    }
}