예제 #1
0
static void test_give_okay(CuTest * tc) {
    struct give env = { 0 };

    test_setup_ex(tc);
    env.f2 = env.f1 = test_create_faction(NULL);
    setup_give(&env);

    config_set("rules.give.flags", "0");
    CuAssertPtrEquals(tc, NULL, check_give(env.src, env.dst, NULL));
    test_teardown();
}
예제 #2
0
static void test_give_new_unit(CuTest * tc) {
    struct give env = { 0 };

    test_setup_ex(tc);
    env.f1 = test_create_faction(NULL);
    env.f2 = test_create_faction(NULL);
    setup_give(&env);
    env.dst->number = 0;
    fset(env.dst, UFL_ISNEW);
    CuAssertPtrEquals(tc, NULL, check_give(env.src, env.dst, NULL));
    test_teardown();
}
예제 #3
0
static void test_give_okay(CuTest * tc) {
    struct give env;
    struct race * rc;

    test_cleanup();
    rc = test_create_race("human");
    env.f2 = env.f1 = test_create_faction(rc);
    setup_give(&env);

    set_param(&global.parameters, "rules.give", "0");
    CuAssertPtrEquals(tc, 0, check_give(env.src, env.dst, 0));
    test_cleanup();
}
예제 #4
0
static void test_give_dead_unit(CuTest * tc) {
    struct give env = { 0 };
    struct message *msg;

    test_setup_ex(tc);
    env.f1 = test_create_faction(NULL);
    env.f2 = test_create_faction(NULL);
    setup_give(&env);
    env.dst->number = 0;
    freset(env.dst, UFL_ISNEW);
    CuAssertPtrNotNull(tc, msg = check_give(env.src, env.dst, NULL));
    msg_release(msg);
    test_teardown();
}
예제 #5
0
static void test_give_denied_by_rules(CuTest * tc) {
    struct give env = { 0 };
    struct message *msg;

    test_setup_ex(tc);
    env.f1 = test_create_faction(NULL);
    env.f2 = test_create_faction(NULL);
    setup_give(&env);

    config_set("rules.give.flags", "0");
    CuAssertPtrNotNull(tc, msg = check_give(env.src, env.dst, NULL));
    msg_release(msg);
    test_teardown();
}
예제 #6
0
static void test_give_denied_by_rules(CuTest * tc) {
    struct give env;
    struct race * rc;
    struct message *msg;

    test_cleanup();
    rc = test_create_race("human");
    env.f1 = test_create_faction(rc);
    env.f2 = test_create_faction(rc);
    setup_give(&env);

    set_param(&global.parameters, "rules.give", "0");
    CuAssertPtrNotNull(tc, msg=check_give(env.src, env.dst, 0));
    msg_release(msg);
    test_cleanup();
}
예제 #7
0
uint32 check_give( SUser* user, std::vector< S3UInt32 >& coins )
{
    std::vector< S3UInt32 > list = merge_coins( coins );

    int32 item_space_count = -1;
    for ( std::vector< S3UInt32 >::iterator i = list.begin();
        i != list.end();
        ++i )
    {
        uint32 ret = 0;

        switch ( i->cate )
        {
        case kCoinItem:
            {
                //初始化背包空格子
                if ( item_space_count < 0 )
                    item_space_count = (int32)item::GetItemSpace( user, kBagFuncCommon );

                //获取物品叠加量
                uint32 stackable = 1;
                {
                    CItemData::SData* pitem = theItemExt.Find( i->objid );
                    if ( pitem != NULL && pitem->stackable > 1 )
                        stackable = pitem->stackable;

                }

                //获取已存在物品可叠加数量
                uint32 item_stackable_count = 0;

                if ( stackable > 1 )
                    item_stackable_count = item::GetItemStackableCount( user, kBagFuncCommon, i->objid );

                //可叠加量足够直接返回
                if ( item_stackable_count >= i->val )
                    break;

                //扣取可叠加量
                i->val -= item_stackable_count;

                //计算剩余量需占用的空格子数
                uint32 space_value = i->val / stackable;
                if ( i->val % stackable )
                    space_value++;

                if ( item_space_count < (int32)space_value )
                    return i->cate;

                //扣取空格子
                item_space_count -= space_value;
            }
            break;
        }

        ret = check_give( user, *i );
        if ( ret != 0 )
            return ret;
    }

    return 0;
}