Пример #1
0
WorldItem ItemCreator::makeItem(int depth, int item_num, int worldTick) {
    RandomMachine random;
    random.setSeed(item_num + worldTick);

    int quality = getQualityFromDepth(depth, random);
    if(quality == 0) quality = 1;

    int major_type = random.getInt() & 15;

    switch(major_type) {
        case Inventory::AMULET_SLOT:
            return createAmulet(quality, random);
        case Inventory::ARMS_SLOT:
            return createArmsArmor(quality, random);
        case Inventory::BELT_SLOT:
            return createBeltArmor(quality, random);
        case Inventory::HEAD_SLOT:
            return createHeadArmor(quality, random);
        case Inventory::LEGS_SLOT:
            return createLegArmor(quality, random);
        case Inventory::TORSO_SLOT:
            return createTorsoArmor(quality, random);
        case Inventory::WEAPON_SLOT1:
            return createWeapon(quality, random);
        default:
            return createSmallItem(quality, random);
    }
}
Пример #2
0
void Hero::loadGate_1()
{
    hp = 100;
    atk = 5;
    this->setPosition(Vec2(playerPos));
    auto idleAnimation = this->createAnimation("Gate_1_Idle_%d.png", 2, 4);  // 空闲动画只有两帧  每秒4帧
    this->setIdleAction(RepeatForever::create(Animate::create(idleAnimation)));

    auto walkAnimation = this->createAnimation("Gate_1_Walk_%d.png", 3, 6);  // 行走动画只有7帧  每秒14帧
    this->setWalkAction(Sequence::create(Animate::create(walkAnimation), BaseSprite::createIdleCallbackFunc(), NULL));

    auto attackAnimation = this->createAnimation("Gate_1_Attack_%d.png", 2, 4);  // 攻击动画只有7帧  每秒14帧
    this->setAttackAction(Sequence::create(Animate::create(attackAnimation), BaseSprite::createIdleCallbackFunc(), NULL));  // 攻击之后立马变为空闲状态

    auto hurtAnimation = this->createAnimation("Gate_1_Hurt_%d.png", 2, 4);  // 受伤动画只有两帧  每秒4帧
    this->setHurtAction(Sequence::create(Animate::create(hurtAnimation), BaseSprite::createIdleCallbackFunc(), NULL));  // 受伤之后立马变为空闲状态

    auto deadAnimation = this->createAnimation("Gate_1_Dead_%d.png", 2, 4);  // 死亡动画只有两帧  每秒4帧
    this->setDeadAction(Sequence::create(Animate::create(deadAnimation), Blink::create(3, 9), NULL));  // 死亡之后立马闪烁

    createWeapon(1);
}
Пример #3
0
std::shared_ptr<Weapon> ObjectFactory::createWeapon(std::string id, std::string rarity){
	return createWeapon(engine::objectLibrary.weaponTemplates[id], *engine::raritySystem.getRarityType(rarity));
}
Пример #4
0
std::shared_ptr<Creature> ObjectFactory::createCreature(TemplateCreaturePreset &presetTemplate, RarityType &rarityType){
	TemplateCreatureBase &templateCreatureBase = engine::objectLibrary.creatureBaseTemplates[presetTemplate.creatureBaseId];

	int health =
		(int)(engine::healthMax *
		presetTemplate.healthFromMax *
		rarityType.improvementMultiplier *
		engine::random.variationMultiplier(engine::statisticVariation));

	int stamina =
		(int)(engine::staminaMax *
		presetTemplate.healthFromMax *
		rarityType.improvementMultiplier *
		engine::random.variationMultiplier(engine::statisticVariation));

	int magic =
		(int)(engine::magicMax *
		presetTemplate.magicFromMax *
		rarityType.improvementMultiplier *
		engine::random.variationMultiplier(engine::statisticVariation));
	
	double lootDropsFromMax = 
		0.30;

	std::shared_ptr<Creature> creature = std::shared_ptr<Creature>(new Creature(
		presetTemplate.id,
		RarityMod(rarityType), //engine::raritySystem.getCreatureMod(rarityType)
		DynamicObject(GameObject(
		presetTemplate.name,
		Creature::CREATURE,
		presetTemplate.glyph),
		health,
		templateCreatureBase.visualEffectOnTakeDamage),
		stamina,
		magic,
		engine::objectLibrary.ais[presetTemplate.aiId]->copy(),
		templateCreatureBase.limbs,
		lootDropsFromMax
		));
	//equip weapons
	for (auto &weaponId : presetTemplate.weaponIds){
		auto &weapon = createWeapon(engine::objectLibrary.weaponTemplates[weaponId], rarityType);
		creature->inventory.items.add(weapon);
		creature->inventory.equip(weapon);
	}
	//equip armors
	for (auto &armorId : presetTemplate.armorIds){
		auto &armor = createArmor(engine::objectLibrary.armorTemplates[armorId], rarityType);
		creature->inventory.items.add(armor);
		creature->inventory.equip(armor);
	}
	//equip accessories
	for (auto &accessoryId : presetTemplate.accessoryIds){
		auto &accessory = createAccessory(engine::objectLibrary.accessoryTemplates[accessoryId], rarityType);
		creature->inventory.items.add(accessory);
		creature->inventory.equip(accessory);
	}
	//regen stats
	creature->healthHit(-9999);
	creature->staminaHit(-9999);
	creature->magicHit(-9999);
	return creature;
}
Пример #5
0
/* returns 1 if shop successfully created, 0 o/w */
int
shMapLevel::makeShop (int sx, int sy, int ex, int ey, int kind)
{
    int x, y;
    int dx = -1, gx = -1;
    int dy = -1, gy = -1;
    shFeature *f;
    shFeature *door = NULL;
    shMonster *clerk;
    int roomid = mSquares[sx][sy].mRoomId;

    /* Find the door (we only make shops in rooms with exactly one door). */
    for (x = sx + 1; x < ex; x++) {
        f = getFeature (x, sy);
        if (f and f->isDoor ()) {
            if (door) return 0;
            door = f;
            dx = x;
            dy = sy;
        }
        f = getFeature (x, ey);
        if (f and f->isDoor ()) {
            if (door) return 0;
            door = f;
            dx = x;
            dy = ey;
        }
    }
    for (y = sy + 1; y < ey; y++) {
        f = getFeature (sx, y);
        if (f and f->isDoor ()) {
            if (door) return 0;
            door = f;
            dx = sx;
            dy = y;
        }
        f = getFeature (ex, y);
        if (f and f->isDoor ()) {
            if (door) return 0;
            door = f;
            dx = ex;
            dy = y;
        }
    }

    if (!door)  return 0;  /* What?! There are no doors to this room? */

    /* Make sure door is a normal automatic door. */
    door->mType = shFeature::kDoorClosed;
    door->mDoor.mFlags = shFeature::kAutomatic;

    /* First row or column from the door shall be empty. */
    if (dx == sx) {
        sx++; dx++; gx = sx;
    } else if (dx == ex) {
        ex--; dx--; gx = ex;
    }
    if (dy == sy) {
        sy++; dy++; gy = sy;
    } else if (dy == ey) {
        ey--; dy--; gy = ey;
    }

    if (-1 == kind) { /* Randomly determine kind of shop. */
        switch (RNG (20)) {
        case 0: case 1: case 2: case 3: case 4:
        case 5: case 6: case 7:
            kind = shRoom::kGeneralStore; break;
        case 8: case 9: case 10:
            kind = shRoom::kHardwareStore; break;
        case 11: case 12: case 13:
            kind = shRoom::kSoftwareStore; break;
        case 14: case 15:
            kind = shRoom::kArmorStore; break;
        case 16: case 17:
            kind = shRoom::kWeaponStore; break;
        case 18:
            kind = shRoom::kImplantStore; break;
        case 19:
            kind = shRoom::kCanisterStore; break;
        }
    }

    bool infested = !RNG (25); /* Full of cockroaches. */

    for (x = sx + 1; x < ex; x++) { /* Get us some stuff to sell. */
        for (y = sy + 1; y < ey; y++) {
            shObject *obj = NULL;

            switch (kind) {
            case shRoom::kGeneralStore:
                obj = generateObject (-1); break;
            case shRoom::kHardwareStore:
                obj = createTool (); break;
            case shRoom::kSoftwareStore:
                if (RNG (8)) {
                    obj = createFloppyDisk ();
                } else {
                    obj = pickFromCategory (kObjGenericComputer);
                } break;
            case shRoom::kArmorStore:
                obj = createArmor (); break;
            case shRoom::kWeaponStore:
                if (RNG (20)) {
                    obj = createWeapon ();
                } else {
                    obj = createRayGun ();
                } break;
            case shRoom::kImplantStore:
                obj = createImplant (); break;
            case shRoom::kCanisterStore:
                obj = createCanister (); break;
            }
            obj->setUnpaid ();
            putObject (obj, x, y);

            if (infested and /* Put one under every big enough item. */
                obj->myIlk ()->mSize > MonIlks[kMonGiantCockroach].mSize)
            {
                shCreature *cockroach = new shMonster (kMonGiantCockroach);
                putCreature (cockroach, x, y);
            }
        }
    }

    /* The shopkeeper droid. */
    clerk = new shMonster (kMonClerkbot);
    putCreature (clerk, dx, dy);
    clerk->mShopKeeper.mHomeX = dx;
    clerk->mShopKeeper.mHomeY = dy;
    clerk->mShopKeeper.mShopId = roomid;
    clerk->mShopKeeper.mBill = 0;

    /* Shops may have a guard. */
    bool guarded = false;
    if (mDLevel > 4 and (!RNG (3) or mDLevel > TOWNLEVEL) and !isTownLevel ()) {
        shMonster *guard = NULL;
        shMonId guardtype[3] = {kMonSecuritron, kMonWarbot, kMonGuardbot};
        guard = new shMonster (guardtype [RNG (3)]);
        if (guard) { /* Pick a nice warm spot in a corner. */
            if (gx == -1) {
                gx = (sx+1 == dx) ? ex-1 :
                     (ex-1 == dx) ? sx+1 :
                          RNG (2) ? sx+1 : ex-1;
            } else {
                gy = (sy+1 == dy) ? ey-1 :
                     (ey-1 == dy) ? sy+1 :
                          RNG (2) ? sy+1 : ey-1;
            }
            if (!putCreature (guard, gx, gy)) {
                guard->mStrategy = shMonster::kGuard;
                guard->mDisposition = shMonster::kIndifferent;
                guard->mGuard.mToll = -1;
                guarded = true;
            }
        }
    }

    mRooms[roomid].mType = (shRoom::Type) kind;
    mFlags |= kHasShop;
    debug.log ("made %s%sshop on level %d.",
        guarded ? "guarded " : "", infested ? "infested " : "", mDLevel);
    return 1;
}