Пример #1
0
Weapon * WeaponsList::GetRandomWeaponToDrop()
{
  std::list<Weapon*>::iterator it;
  Double probability_sum = 0;
  for (it = m_weapons_list.begin(); it != m_weapons_list.end(); ++it) {
    probability_sum += (*it)->GetDropProbability();
  }
  ASSERT(probability_sum > 0);

  MSG_DEBUG("random.get", "WeaponList::GetRandomWeaponToDrop()");
  Double num = RandomSync().GetDouble(0, probability_sum);
  Double total_bf_weapon = 0;
  Double total_after_weapon = 0;

  for (it = m_weapons_list.begin(); it != m_weapons_list.end(); it++) {
    Weapon * weapon = *it;
    total_after_weapon = total_bf_weapon + weapon->GetDropProbability();
    if (total_bf_weapon < num && num <= total_after_weapon) {
      MSG_DEBUG("bonus","Weapon choosed: %s", weapon->GetName().c_str());
      return weapon;
    }
    total_bf_weapon = total_after_weapon;
  }
  ASSERT(false);
  return NULL;
}
Пример #2
0
void Dragon::ExtraOutput() {
	Weapon weapon = WeaponFactory::makeWeapon(number);
	morale = (float) head->GetRemain() / (float) this->lifeUnit;
	char buf[20];
	sprintf(buf, "%.2f", morale);
	cout << "It has a " << weapon.GetName() << ",and it's morale is " << buf << endl;
}
Пример #3
0
void Iceman::ExtraOutput()
{
	Weapon weapon = WeaponFactory::makeWeapon(number);
	cout << "It has a " << weapon.GetName() << endl;
}
Пример #4
0
void EquipWeapon(Hero* aHero) {
//    cout << aHero->GetName() << endl;
    // Inventory empty?
    if (aHero->Inventory.Items() == 0) {
        cout << "Empty inventory. Must buy some weapons first." << endl;
        return;
    }

    // Weapons on inventory?
    if (aHero->Inventory.Weapons() == 0) {
        cout << "You are not carring any weapons." << endl;
        return;
    }

    // Holding 2 weapons or 2 hand weapon?
    Weapon *left, *right;
    left = aHero->GetLeftHandWeapon();
    right = aHero->GetRightHandWeapon();
    if (left != 0 && right != 0)
        if (left->bothHands) {
            cout << "You don't have free hand. You must unequip first." << endl;
            return;
        }

    int choise;
    while (true) { // Choose weapon from inventory loop
        // Display inventory to choose
        cout << aHero->GetName() << endl;
        aHero->Inventory.DisplayWeapons();
        cout << "Give the item position of weapon to use (0 to exit): ";
        cin >> choise;
        cin.ignore(); // Ignore new line character
        if (choise == 0)
            return; // Exit function

        // Our list of weapons isn't in continues numbers,
        // so we examine if the choise is realy a weapon
        if (aHero->Inventory.GetItemType(choise) != Item::Weapon)
            cout << "Bad choise. Try again." << endl;
        else
            break; // Choise made
    }

    Weapon* choosedWeapon = (Weapon*) aHero->Inventory.Remove(choise);
    // If choosed weapon uses both hands and user hands aren't empty, must unequip first.
    if (choosedWeapon->bothHands && (right != 0 || left != 0)) { // Holding one weapon
        cout << "You choosed both hands weapon but your hands aren't free. Uneqiup first." << endl;
        // Put weapon back to inventory
        aHero->Inventory.Add(choosedWeapon);
        delete choosedWeapon;
        return;
    }

    // Choosed weapon uses both hands and both hands are free
    if (choosedWeapon->bothHands) {
        cout << "Holding: " << choosedWeapon->GetName();
        aHero->SetLeftHandWeapon(choosedWeapon);
        aHero->SetRightHandWeapon(choosedWeapon);
        delete choosedWeapon; // Set*Weapon copies argument
        return;
    }

    // Find an empty hand to put on.
    if (right == 0) {
        aHero->SetRightHandWeapon(choosedWeapon);
        cout << "Right hand: " << choosedWeapon->GetName() << endl;
    } else {
        aHero->SetLeftHandWeapon(choosedWeapon);
        cout << "Left hand: " << choosedWeapon->GetName() << endl;
    }
}