当前位置: 首页>>代码示例>>C++>>正文


C++ MathVar类代码示例

本文整理汇总了C++中MathVar的典型用法代码示例。如果您正苦于以下问题:C++ MathVar类的具体用法?C++ MathVar怎么用?C++ MathVar使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MathVar类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CS_ASSERT

int EntityManager::CalculateFamiliarAffinity( psCharacter * chardata, size_t type, size_t lifecycle, size_t attacktool, size_t attacktype )
{
    static MathScript *msAffinity;
    int affinityValue = 0;

    if (!msAffinity)
    {
        msAffinity = psserver->GetMathScriptEngine()->FindScript("CalculateFamiliarAffinity");
        CS_ASSERT(msAffinity != NULL);
    }

    // Determine Familiar Type using Affinity Values
    if ( msAffinity )
    {
        MathEnvironment env;
        env.Define("Actor",      chardata);
        env.Define("Type",       type);
        env.Define("Lifecycle",  lifecycle);
        env.Define("AttackTool", attacktool);
        env.Define("AttackType", attacktype);
        msAffinity->Evaluate(&env);
        MathVar *affinity = env.Lookup("Affinity");
        affinityValue = affinity->GetRoundValue();
    }

    return affinityValue;

}
开发者ID:garinh,项目名称:planeshift,代码行数:28,代码来源:entitymanager.cpp

示例2: TEST

TEST(MathScriptTest, StringAssignment)
{
    Foo foo;
    MathScript *script = MathScript::Create("StringAssignment", "Skill = 'Sword'; Rank = Quux:GetSkillRank(Skill);");
    MathEnvironment env;
    ASSERT_NE(script, NULL);
    env.Define("Quux", &foo);
    script->Evaluate(&env);
    MathVar *rank = env.Lookup("Rank");
    EXPECT_EQ(33, rank->GetValue());
};
开发者ID:diana-coman,项目名称:Eulora-client,代码行数:11,代码来源:mathscript_unittest.cpp

示例3: CalcModifierCostCap

float LootRandomizer::CalcModifierCostCap(psCharacter* chr)
{
    float result = 1000.0;

    if(modifierCostCalc)
    {
        // Use the mob's attributes to calculate modifier cost cap
        MathEnvironment env;
        env.Define("Actor",   chr);
        env.Define("MaxHP",   chr->GetMaxHP().Current());
        env.Define("MaxMana", chr->GetMaxMana().Current());

        (void) modifierCostCalc->Evaluate(&env);
        MathVar* modcap = env.Lookup("ModCap");
        result = modcap->GetValue();
    }
    Debug2(LOG_LOOT,0,"DEBUG: Calculated cost cap %f\n", result);
    return result;
}
开发者ID:huigou,项目名称:planeshift,代码行数:19,代码来源:lootrandomizer.cpp

示例4: randomgentest

void randomgentest(int limit)
{
   csString scriptstr;
    if (limit<0)
    {
       scriptstr = "Roll = rnd();";
       limit=1;
    }
    else    
    {
       scriptstr.Format("Roll = rnd(%d);",limit);
    }
    MathScript *script = MathScript::Create("randomgen test", scriptstr.GetData());
    MathEnvironment env;
    ASSERT_NE(script, NULL) << scriptstr.GetData() << " did not create script";
    bool above1=false, abovehalflimit=false;
    for (int i=0; i<100; i++) //try 100 times, since this is random
    {
       script->Evaluate(&env);
       MathVar *roll = env.Lookup("Roll");
       EXPECT_GE(roll->GetValue(), 0); 
       EXPECT_LE(roll->GetValue(), limit);
       if (roll->GetValue()>1)
       {
          above1 = true;
       }
       if (2*roll->GetValue()>limit)
       {
          abovehalflimit = true;
       }
    }
    if (limit>1)
    {
       EXPECT_TRUE(above1) << scriptstr << "never exceeds 1"; 
    }
    if (limit>0)
    {
       EXPECT_TRUE(abovehalflimit) << scriptstr << "never exceeds half of limit"; 
    }
    delete script;
}
开发者ID:diana-coman,项目名称:Eulora-client,代码行数:41,代码来源:mathscript_unittest.cpp

示例5: DebugOutput

void CombatManager::DebugOutput(psCombatGameEvent *event, const MathEnvironment & env)
{
    MathVar *missed   = env.Lookup("Missed");      // Missed  = Attack missed the enemy
    MathVar *dodged   = env.Lookup("Dodged");      // Dodged  = Attack dodged  by enemy
    MathVar *blocked  = env.Lookup("Blocked");     // Blocked = Attack blocked by enemy
    MathVar *damage   = env.Lookup("FinalDamage"); // Actual damage done, if any

    psItem* item = event->GetAttackerData()->Inventory().GetEffectiveWeaponInSlot(event->GetWeaponSlot() );

    csString debug;
    debug.Append( "-----Debug Combat Summary--------\n");
    debug.AppendFmt( "%s attacks %s with slot %d , weapon %s, quality %1.2f, basedmg %1.2f/%1.2f/%1.2f\n",
      event->attacker->GetName(),event->target->GetName(), event->GetWeaponSlot(),item->GetName(),item->GetItemQuality(),
      item->GetDamage(PSITEMSTATS_DAMAGETYPE_SLASH),item->GetDamage(PSITEMSTATS_DAMAGETYPE_BLUNT),item->GetDamage(PSITEMSTATS_DAMAGETYPE_PIERCE));
    debug.AppendFmt( "Missed: %1.6f Dodged: %1.6f Blocked: %1.6f", missed->GetValue(), dodged->GetValue(), blocked->GetValue());
    debug.AppendFmt( "Damage: %1.1f\n", damage->GetValue());
    Debug2(LOG_COMBAT, event->attacker->GetClientID(), "%s", debug.GetData());
}
开发者ID:randomcoding,项目名称:PlaneShift-PSAI,代码行数:18,代码来源:combatmanager.cpp

示例6: Debug2

void CombatManager::HandleCombatEvent(psCombatGameEvent *event)
{
    psCharacter *attacker_data,*target_data;
    int attack_result;
    bool skipThisRound = false;

    if (!event->GetAttacker() || !event->GetTarget()) // disconnected and deleted
    {
#ifdef COMBAT_DEBUG
        psserver->SendSystemError(event->AttackerCID, "Combat stopped as one participant logged of.");
#endif
        return;
    }

    gemActor *gemAttacker = dynamic_cast<gemActor*> ((gemObject *) event->attacker);
    gemActor *gemTarget   = dynamic_cast<gemActor*> ((gemObject *) event->target);

    attacker_data=event->GetAttackerData();
    target_data=event->GetTargetData();

    // If the attacker is no longer in attack mode abort.
    if (gemAttacker->GetMode() != PSCHARACTER_MODE_COMBAT)
    {
#ifdef COMBAT_DEBUG
        psserver->SendSystemError(event->AttackerCID,
                "Combat stopped as you left combat mode.");
#endif
        return;
    }

    // If target is dead, abort.
    if (!gemTarget->IsAlive() )
    {
#ifdef COMBAT_DEBUG
        psserver->SendSystemResult(event->AttackerCID, "Combat stopped as one participant logged of.");
#endif
        return;
    }

    // If the slot is no longer attackable, abort
    if (!attacker_data->Inventory().CanItemAttack(event->GetWeaponSlot()))
    {
#ifdef COMBAT_DEBUG
        psserver->SendSystemError(event->AttackerCID, "Combat stopped as you have no longer an attackable item equipped.");
#endif
        return;
    }
    
    if (attacker_data->Inventory().GetEquipmentObject(event->GetWeaponSlot()).eventId != event->id)
    {
#ifdef COMBAT_DEBUG
        psserver->SendSystemError(event->AttackerCID, "Ignored combat event as newer is in.");
#endif
        return;
    }
   
    psItem* weapon = attacker_data->Inventory().GetEffectiveWeaponInSlot(event->GetWeaponSlot());

    // weapon became unwieldable
    csString response;
    if(weapon!=NULL && !weapon->CheckRequirements(attacker_data,response))
    {
        Debug2(LOG_COMBAT, gemAttacker->GetClientID(),"%s has lost use of weapon", gemAttacker->GetName() );
        psserver->SendSystemError(event->AttackerCID, "You can't use your %s any more.", weapon->GetName() );
        return;
    }

    // If the weapon in the slot has been changed, skip a turn (latency for this slot may also have changed)
    if (event->WeaponID != weapon->GetUID())
    {
        Debug2(LOG_COMBAT, gemAttacker->GetClientID(),"%s has changed weapons mid battle", gemAttacker->GetName() );
#ifdef COMBAT_DEBUG
        psserver->SendSystemError(event->AttackerCID, "Weapon changed. Skipping");
#endif
        skipThisRound = true;
    }

    Client * attacker_client = psserver->GetNetManager()->GetClient(event->AttackerCID);
    if (attacker_client)
    {
        // Input the stamina data
        MathEnvironment env;
        env.Define("Actor",  event->GetAttacker());
        env.Define("Weapon", weapon);
        staminacombat->Evaluate(&env);
        MathVar *PhyDrain = env.Lookup("PhyDrain");
        MathVar *MntDrain = env.Lookup("MntDrain");

        if ( (attacker_client->GetCharacterData()->GetStamina(true) < PhyDrain->GetValue())
            || (attacker_client->GetCharacterData()->GetStamina(false) < MntDrain->GetValue()) )
        {
           StopAttack(attacker_data->GetActor());
           psserver->SendSystemError(event->AttackerCID, "You are too tired to attack.");
           return;
        }

        // If the target has become impervious, abort and give up attacking
        if (!attacker_client->IsAllowedToAttack(gemTarget))
        {
           StopAttack(attacker_data->GetActor());
//.........这里部分代码省略.........
开发者ID:randomcoding,项目名称:PlaneShift-PSAI,代码行数:101,代码来源:combatmanager.cpp

示例7: ApplyCombatEvent

void CombatManager::ApplyCombatEvent(psCombatGameEvent *event, int attack_result)
{
    psCharacter *attacker_data = event->GetAttackerData();
    psCharacter *target_data=event->GetTargetData();

    MathVar *weaponDecay = NULL;
    MathVar *blockDecay = NULL;
    MathVar *armorDecay = NULL;
    MathEnvironment env;

    psItem *weapon         = attacker_data->Inventory().GetEffectiveWeaponInSlot(event->GetWeaponSlot());
    psItem *blockingWeapon = target_data->Inventory().GetEffectiveWeaponInSlot(event->GetWeaponSlot(),true);
    psItem *struckArmor    = target_data->Inventory().GetEffectiveArmorInSlot(event->AttackLocation);

    // there may only be a decay if you actually hit your target by some means
    if(attack_result == ATTACK_DAMAGE || attack_result == ATTACK_BLOCKED)
    {
        // we are guaranteed some armor is present - real one, race one or base one
        CS_ASSERT(struckArmor);
        float ArmorVsWeapon = weapon->GetArmorVSWeaponResistance(struckArmor->GetBaseStats());

        // clamp value between 0 and 1
        ArmorVsWeapon = ArmorVsWeapon > 1.0F ? 1.0F : ArmorVsWeapon < 0.0F ? 0.0F : ArmorVsWeapon;

        env.Define("Weapon", weapon);                             // weapon that was used to attack
        env.Define("BlockingWeapon", blockingWeapon);             // weapon that blocked the attack
        env.Define("Armor", struckArmor);                         // armor hit
        env.Define("ArmorVsWeapon", ArmorVsWeapon);               // armor vs weapon effectiveness
        env.Define("Damage", event->FinalDamage);                 // actual damage dealt
        env.Define("Blocked", (attack_result == ATTACK_BLOCKED)); // identifies whether this attack was blocked

        calc_decay->Evaluate(&env);

        weaponDecay = env.Lookup("WeaponDecay");
        blockDecay  = env.Lookup("BlockingDecay");
        armorDecay  = env.Lookup("ArmorDecay");
    }

    gemActor *gemAttacker = dynamic_cast<gemActor*> ((gemObject *) event->attacker);
    gemActor *gemTarget   = dynamic_cast<gemActor*> ((gemObject *) event->target);

    switch (attack_result)
    {
        case ATTACK_DAMAGE:
        {
            bool isNearlyDead = false;
            if (target_data->GetMaxHP().Current() > 0.0 && target_data->GetHP()/target_data->GetMaxHP().Current() > 0.2)
            {
                if ((target_data->GetHP() - event->FinalDamage) / target_data->GetMaxHP().Current() <= 0.2)
                    isNearlyDead = true;
            }

            psCombatEventMessage ev(event->AttackerCID,
                isNearlyDead ? psCombatEventMessage::COMBAT_DAMAGE_NEARLY_DEAD : psCombatEventMessage::COMBAT_DAMAGE,
                gemAttacker->GetEID(),
                gemTarget->GetEID(),
                event->AttackLocation,
                event->FinalDamage,
                weapon->GetAttackAnimID(gemAttacker->GetCharacterData()),
                gemTarget->FindAnimIndex("hit"));

            ev.Multicast(gemTarget->GetMulticastClients(),0,MAX_COMBAT_EVENT_RANGE);

            // Apply final damage
            if (target_data!=NULL)
            {
                gemTarget->DoDamage(gemAttacker,event->FinalDamage);
                
                if (gemAttacker)
                {
                    gemAttacker->InvokeAttackScripts(gemTarget, weapon);
                }

                if (gemTarget)
                {
                    gemTarget->InvokeDefenseScripts(gemAttacker, weapon);
                    if(isNearlyDead)
                    {
                        gemTarget->InvokeNearlyDeadScripts(gemAttacker, weapon);
                    }
                }
            }

            // If the target wasn't in combat, it is now...
            // Note that other modes shouldn't be interrupted automatically
            if (gemTarget->GetMode() == PSCHARACTER_MODE_PEACE || gemTarget->GetMode() == PSCHARACTER_MODE_WORK)
            {
                if (gemTarget->GetClient())  // Set reciprocal target
                    gemTarget->GetClient()->SetTargetObject(gemAttacker,true);

                // The default stance is 'Fully Defensive'.
                Stance initialStance = GetStance(cacheManager, "FullyDefensive");
                AttackSomeone(gemTarget,gemAttacker,initialStance);
            }

            if (weapon)
            {
                weapon->AddDecay(weaponDecay->GetValue());
            }
            if (struckArmor)
//.........这里部分代码省略.........
开发者ID:randomcoding,项目名称:PlaneShift-PSAI,代码行数:101,代码来源:combatmanager.cpp


注:本文中的MathVar类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。