<commit_before>#include <Runtime/MP1/World/CSpacePirate.hpp>
#include "CPatterned.hpp"
#include "Runtime/CStateManager.hpp"
#include "CPatternedInfo.hpp"
#include "TCastTo.hpp"
#include "CActorParameters.hpp"
#include "Character/CPASAnimParmData.hpp"
#include "GameGlobalObjects.hpp"
#include "CSimplePool.hpp"
#include "CPlayer.hpp"
#include "Weapon/CGameProjectile.hpp"
#include "Character/CAnimData.hpp"
#include "TCastTo.hpp"
#include "MP1/World/CSpacePirate.hpp"
#include "World/CStateMachine.hpp"

namespace urde
{

const zeus::CColor CPatterned::skDamageColor(0.5f, 0.f, 0.f);
CMaterialList gkPatternedGroundMaterialList(EMaterialTypes::Character, EMaterialTypes::Solid,
                                            EMaterialTypes::Orbit, EMaterialTypes::GroundCollider,
                                            EMaterialTypes::Target);
CMaterialList gkPatternedFlyerMaterialList(EMaterialTypes::Character, EMaterialTypes::Solid,
                                           EMaterialTypes::Orbit, EMaterialTypes::Target);

CPatterned::CPatterned(ECharacter character, TUniqueId uid, std::string_view name, CPatterned::EFlavorType flavor,
                       const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData,
                       const CPatternedInfo& pInfo, CPatterned::EMovementType moveType,
                       CPatterned::EColliderType colliderType, EBodyType bodyType, const CActorParameters& actorParms,
                       int variant)
: CAi(uid, pInfo.xf8_active, name, info, xf, std::move(mData),
      zeus::CAABox(pInfo.xcc_bodyOrigin - zeus::CVector3f{pInfo.xc4_halfExtent, pInfo.xc4_halfExtent, 0.f},
                   pInfo.xcc_bodyOrigin +
                       zeus::CVector3f{pInfo.xc4_halfExtent, pInfo.xc4_halfExtent, pInfo.xc8_height}),
      pInfo.x0_mass, pInfo.x54_healthInfo, pInfo.x5c_damageVulnerability,
      moveType == EMovementType::Flyer ? gkPatternedFlyerMaterialList : gkPatternedGroundMaterialList,
      pInfo.xfc_stateMachineId, actorParms, pInfo.xd8_stepUpHeight, 0.8f),
x2fc_minAttackRange(pInfo.x18_minAttackRange),
x300_maxAttackRange(pInfo.x1c_maxAttackRange),
x304_averageAttackTime(pInfo.x20_averageAttackTime),
x308_attackTimeVariation(pInfo.x24_attackTimeVariation),
x34c_character(character),
x388_anim(pInfo.GetAnimationParameters().GetInitialAnimation()),
x3b4_speed(pInfo.x4_speed),
x3b8_turnSpeed(pInfo.x8_turnSpeed),
x3bc_detectionRange(pInfo.xc_detectionRange),
x3c0_detectionHeightRange(pInfo.x10_detectionHeightRange),
x3c4_detectionAngle(std::cos(zeus::degToRad(pInfo.x14_dectectionAngle))),
x3c8_leashRadius(pInfo.x28_leashRadius),
x3cc_playerLeashRadius(pInfo.x2c_playerLeashRadius),
x3d0_playerLeashTime(pInfo.x30_playerLeashTime),
x3fc_flavor(flavor)
{
    x400_25_ = true;
    x400_31_ = moveType == CPatterned::EMovementType::Flyer;
    x402_29_ = true;
    x402_30_ = x402_31_ = actorParms.HasThermalHeat();
    x403_25_ = true;
    x403_26_ = true;
    x404_contactDamage = pInfo.x34_contactDamageInfo;
    x424_damageWaitTime = pInfo.x50_damageWaitTime;
    x454_deathSfx = pInfo.xe8_deathSfx;
    x458_iceShatterSfx = pInfo.x134_iceShatterSfx;
    x4f4_ = pInfo.x100_;
    x4f8_ = pInfo.x104_;
    x4fc_ = pInfo.x108_;
    x508_colliderType = colliderType;
    x50c_thermalMag = actorParms.GetThermalMag();
    x510_.reset(new CVertexMorphEffect);
    x514_ = pInfo.x110_particle1Scale;
    x540_ = pInfo.x124_particle2Scale;

    if (pInfo.x11c_particle1.IsValid())
        x520_ = { g_SimplePool->GetObj({FOURCC('PART'), pInfo.x11c_particle1})};

    if (pInfo.x120_electric.IsValid())
        x530_ = { g_SimplePool->GetObj({FOURCC('ELSC'), pInfo.x120_electric})};

    if (pInfo.x130_particle2.IsValid())
        x54c_ = { g_SimplePool->GetObj({FOURCC('PART'), pInfo.x130_particle2})};

    if (x404_contactDamage.GetRadius() > 0.f)
        x404_contactDamage.SetRadius(0.f);

    xe6_29_renderParticleDBInside = false;
    x402_27_ = x64_modelData->HasModel(CModelData::EWhichModel::XRay);
    BuildBodyController(bodyType);
}

void CPatterned::Accept(urde::IVisitor& visitor)
{
    visitor.Visit(this);
}

void CPatterned::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr)
{
    CAi::AcceptScriptMsg(msg, uid, mgr);

    switch(msg)
    {
    case EScriptObjectMessage::Registered:
    {
        if (x508_colliderType == EColliderType::Zero)
        {
            CMaterialList include = GetMaterialFilter().GetIncludeList();
            CMaterialList exclude = GetMaterialFilter().GetExcludeList();
            include.Remove(EMaterialTypes::Character);
            exclude.Add(EMaterialTypes::Character);
            SetMaterialFilter(CMaterialFilter::MakeIncludeExclude(include, exclude));
        }

        if (HasModelData() && GetModelData()->HasAnimData() && GetModelData()->GetAnimationData()->GetIceModel())
        {
            /* TODO Initialize CVertexMorphEffect located at 0x8007CC7C */
        }

        xf8_25_angularEnabled = true;
        x450_bodyController->Activate(mgr);
        break;
    }
    case EScriptObjectMessage::OnFloor:
    {
        if (!x328_25_)
        {
            x150_momentum = {};
            AddMaterial(EMaterialTypes::GroundCollider, mgr);
        }
        x328_27_onGround = true;
        break;
    }
    case EScriptObjectMessage::Falling:
    {
        if (!x328_25_)
        {
            if (x450_bodyController->GetPercentageFrozen() == 0.f)
            {
                x150_momentum = {0.f, 0.f, -GetWeight()};
                RemoveMaterial(EMaterialTypes::GroundCollider, mgr);
            }
        }<commit_msg>Remove debug function call<commit_after>#include <Runtime/MP1/World/CSpacePirate.hpp>
#include "CPatterned.hpp"
#include "Runtime/CStateManager.hpp"
#include "CPatternedInfo.hpp"
#include "TCastTo.hpp"
#include "CActorParameters.hpp"
#include "Character/CPASAnimParmData.hpp"
#include "GameGlobalObjects.hpp"
#include "CSimplePool.hpp"
#include "CPlayer.hpp"
#include "Weapon/CGameProjectile.hpp"
#include "Character/CAnimData.hpp"
#include "TCastTo.hpp"
#include "MP1/World/CSpacePirate.hpp"
#include "World/CStateMachine.hpp"

namespace urde
{

const zeus::CColor CPatterned::skDamageColor(0.5f, 0.f, 0.f);
CMaterialList gkPatternedGroundMaterialList(EMaterialTypes::Character, EMaterialTypes::Solid,
                                            EMaterialTypes::Orbit, EMaterialTypes::GroundCollider,
                                            EMaterialTypes::Target);
CMaterialList gkPatternedFlyerMaterialList(EMaterialTypes::Character, EMaterialTypes::Solid,
                                           EMaterialTypes::Orbit, EMaterialTypes::Target);

CPatterned::CPatterned(ECharacter character, TUniqueId uid, std::string_view name, CPatterned::EFlavorType flavor,
                       const CEntityInfo& info, const zeus::CTransform& xf, CModelData&& mData,
                       const CPatternedInfo& pInfo, CPatterned::EMovementType moveType,
                       CPatterned::EColliderType colliderType, EBodyType bodyType, const CActorParameters& actorParms,
                       int variant)
: CAi(uid, pInfo.xf8_active, name, info, xf, std::move(mData),
      zeus::CAABox(pInfo.xcc_bodyOrigin - zeus::CVector3f{pInfo.xc4_halfExtent, pInfo.xc4_halfExtent, 0.f},
                   pInfo.xcc_bodyOrigin +
                       zeus::CVector3f{pInfo.xc4_halfExtent, pInfo.xc4_halfExtent, pInfo.xc8_height}),
      pInfo.x0_mass, pInfo.x54_healthInfo, pInfo.x5c_damageVulnerability,
      moveType == EMovementType::Flyer ? gkPatternedFlyerMaterialList : gkPatternedGroundMaterialList,
      pInfo.xfc_stateMachineId, actorParms, pInfo.xd8_stepUpHeight, 0.8f),
x2fc_minAttackRange(pInfo.x18_minAttackRange),
x300_maxAttackRange(pInfo.x1c_maxAttackRange),
x304_averageAttackTime(pInfo.x20_averageAttackTime),
x308_attackTimeVariation(pInfo.x24_attackTimeVariation),
x34c_character(character),
x388_anim(pInfo.GetAnimationParameters().GetInitialAnimation()),
x3b4_speed(pInfo.x4_speed),
x3b8_turnSpeed(pInfo.x8_turnSpeed),
x3bc_detectionRange(pInfo.xc_detectionRange),
x3c0_detectionHeightRange(pInfo.x10_detectionHeightRange),
x3c4_detectionAngle(std::cos(zeus::degToRad(pInfo.x14_dectectionAngle))),
x3c8_leashRadius(pInfo.x28_leashRadius),
x3cc_playerLeashRadius(pInfo.x2c_playerLeashRadius),
x3d0_playerLeashTime(pInfo.x30_playerLeashTime),
x3fc_flavor(flavor)
{
    x400_25_ = true;
    x400_31_ = moveType == CPatterned::EMovementType::Flyer;
    x402_29_ = true;
    x402_30_ = x402_31_ = actorParms.HasThermalHeat();
    x403_25_ = true;
    x403_26_ = true;
    x404_contactDamage = pInfo.x34_contactDamageInfo;
    x424_damageWaitTime = pInfo.x50_damageWaitTime;
    x454_deathSfx = pInfo.xe8_deathSfx;
    x458_iceShatterSfx = pInfo.x134_iceShatterSfx;
    x4f4_ = pInfo.x100_;
    x4f8_ = pInfo.x104_;
    x4fc_ = pInfo.x108_;
    x508_colliderType = colliderType;
    x50c_thermalMag = actorParms.GetThermalMag();
    x510_.reset(new CVertexMorphEffect);
    x514_ = pInfo.x110_particle1Scale;
    x540_ = pInfo.x124_particle2Scale;

    if (pInfo.x11c_particle1.IsValid())
        x520_ = { g_SimplePool->GetObj({FOURCC('PART'), pInfo.x11c_particle1})};

    if (pInfo.x120_electric.IsValid())
        x530_ = { g_SimplePool->GetObj({FOURCC('ELSC'), pInfo.x120_electric})};

    if (pInfo.x130_particle2.IsValid())
        x54c_ = { g_SimplePool->GetObj({FOURCC('PART'), pInfo.x130_particle2})};

    if (x404_contactDamage.GetRadius() > 0.f)
        x404_contactDamage.SetRadius(0.f);

    xe6_29_renderParticleDBInside = false;
    x402_27_ = x64_modelData->HasModel(CModelData::EWhichModel::XRay);
    BuildBodyController(bodyType);
}

void CPatterned::Accept(urde::IVisitor& visitor)
{
    visitor.Visit(this);
}

void CPatterned::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr)
{
    CAi::AcceptScriptMsg(msg, uid, mgr);

    switch(msg)
    {
    case EScriptObjectMessage::Registered:
    {
        if (x508_colliderType == EColliderType::Zero)
        {
            CMaterialList include = GetMaterialFilter().GetIncludeList();
            CMaterialList exclude = GetMaterialFilter().GetExcludeList();
            include.Remove(EMaterialTypes::Character);
            exclude.Add(EMaterialTypes::Character);
            SetMaterialFilter(CMaterialFilter::MakeIncludeExclude(include, exclude));
        }

        if (HasModelData() && GetModelData()->HasAnimData() && GetModelData()->GetAnimationData()->GetIceModel())
        {
            /* TODO Initialize CVertexMorphEffect located at 0x8007CC7C */
        }

        xf8_25_angularEnabled = true;
        break;
    }
    case EScriptObjectMessage::OnFloor:
    {
        if (!x328_25_)
        {
            x150_momentum = {};
            AddMaterial(EMaterialTypes::GroundCollider, mgr);
        }
        x328_27_onGround = true;
        break;
    }
    case EScriptObjectMessage::Falling:
    {
        if (!x328_25_)
        {
            if (x450_bodyController->GetPercentageFrozen() == 0.f)
            {
                x150_momentum = {0.f, 0.f, -GetWeight()};
                RemoveMaterial(EMaterialTypes::GroundCollider, mgr);
            }
        }
{'fraction_non_alphanumeric': 0.10877130364950477, 'fraction_numerical': 0.044168823057017935, 'mean_word_length': 3.681704260651629, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1048583', 'n_tokens_mistral': 4183, 'n_tokens_neox': 3840, 'n_words': 496}