コード例 #1
0
ファイル: weapon.cpp プロジェクト: Pandakls/MorphDataBase
Weapon Weapon::randomWeapon(){
    Weapon w = Weapon();
    int price = 0;
    w.setPrice(price);
    w.loadRandomType();
    w.addPower();
    for (int i=0; i< w.getPower() ; i++){
        w += w.loadRandomWeaponBuff();
    }
    w.setName(w.getName() + ", " + iTos(w.getDd1()) + "d" + iTos(w.getDd2()));
    w.setName(w.getName() + (w.getRange() != 1 ? + ", " + iTos(w.getRange()) + "m" : "") );
    return w;
}
コード例 #2
0
ファイル: basicmonster.cpp プロジェクト: Zwergesel/deadmeat
int BasicMonster::action()
{
	if ((usesMeleeWeapons() || usesRangedWeapons()) && inventory.size() > 0)
	{
		useBestWeapon();
	}
	int time;
	bool seen = seePlayer();
	if (shouldFlee())
	{
		time = doFlee();
		if (time > 0) return time;
	}
	if (attitude == ATTITUDE_HOSTILE && seen)
	{
		int sqdist = Point::sqlen(world.player->getCreature()->getPos() - position);
		Weapon* weapon = getMainWeapon();
		if (weapon == NULL) weapon = &baseWeapon;
		int range = weapon->getRange();

		// Ranged attack
		if (range > 1 && sqdist <= range*range)
		{
			time = doRangedAttack(weapon);
			if (time > 0) return time;
		}

		// Special attacks (e.g. dragon breath)
		time = doSpecialAttack();
		if (time > 0) return time;

		// Melee attack
		if (sqdist <= 2)
		{
			time = doMeleeAttack(weapon);
			if (time > 0) return time;
		}

		// Run towards player / tactical movement
		time = doChargePlayer();
		if (time > 0) return time;
	}

	// Random walk, search for items, etc.
	time = doWander();
	return time > 0 ? time : 10;
}
コード例 #3
0
ファイル: basicmonster.cpp プロジェクト: Zwergesel/deadmeat
void BasicMonster::useBestWeapon()
{
	bool melee = usesMeleeWeapons();
	bool ranged = usesRangedWeapons();
	int bestScore = -1;
	symbol bestWeapon = '\0';

	for (auto it = inventory.begin(); it != inventory.end(); it++)
	{
		if (it->second->getType() != ITEM_WEAPON) continue;
		Weapon* weapon = static_cast<Weapon*>(it->second);
		if (weapon->getRange() <= 1 && !melee) continue;
		if (weapon->getRange() > 1 && !ranged) continue;
		int score = scoreWeapon(weapon);
		if (score > bestScore)
		{
			bestScore = score;
			bestWeapon = it->first;
		}
	}

	mainWeapon = bestWeapon;
}