示例#1
0
文件: feats.cpp 项目: wroy/dndBuilder
void Feats::on_btnNext_clicked()
{
    Equipment* s = new Equipment();
    _main->setCentralWidget(s);
    s->show();
    s->setMainWindow(_main);
}
示例#2
0
void MainWindow::on_actionEquipment_triggered()
{
    Equipment* ar = new Equipment();
    this->setCentralWidget(ar);
    ar->show();
    ar->setMainWindow(this);
}
/**
 * @brief OknoBazaru::kupDuzaMiksture	Przeprowadza kupno dużej mikstury zdrowia.
 */
void MarketWindow::buyLargePotion()
{
	Equipment *equipment = player_->equipment();
	equipment->setLargePotions(equipment->largePotions() + 1);
	player_->setGold(player_->gold() - CENA_DUZEJ_MIKSTURY);

	playerWindow_->update();
	smallPotionCountLabel->setText(QString::number(player_->equipment()->largePotions()));

	largePotionButton->setEnabled(player_->gold() >= CENA_DUZEJ_MIKSTURY);
	smallPotionButton->setEnabled(player_->gold() >= CENA_MALEJ_MIKSTURY);
}
示例#4
0
void EquipmentEditor::newEquipment()
{
   QString name = QInputDialog::getText(this, tr("Equipment name"),
                                          tr("Equipment name:"));
   if( name.isEmpty() )
      return;

   Equipment* e = Database::instance().newEquipment();
   e->setName( name );

   setEquipment(e);
   show();
}
bool ModelValidator::isValid(const Equipment& equipment, bool allowDefaults/* = false*/)
{
	RETURN_IF_STR_EMPTY(equipment.GetManufacturerName(), "Equipment Manufacturer Name");
	RETURN_IF_STR_EMPTY(equipment.GetManufacturerModelName(), "Equipment Manufacturer Model");

	if (!allowDefaults)
	{
		RETURN_IF_STR_EMPTY(equipment.GetManufacturerModelName(), "Manafacturer Model Name");
		RETURN_IF_STR_EMPTY(equipment.GetSoftwareVersion(), "Software Version");
	}

	return true;
}
示例#6
0
void dummy() {
/*
*/
Equipment* component;
InventoryVisitor visitor;

component->Accept(visitor);
cout << "Inventory "
     << component->Name()
     << visitor.GetInventory();
/*
*/
}
bool QEquipmentView::fromXML(QDomDocument & dom)
{
    //supprime le contenu en cours
    this->reset();

    //charge le contenu
    QDomElement el = dom.documentElement().firstChildElement();
    while(!el.isNull()){
        Equipment equip;
        equip.boundXML(el);
        this->addEquipment(equip);
        el = el.nextSiblingElement();
    }
    return QRESULT_OK();
}
示例#8
0
/*
* Equips the item specified by itemToEquip
* returns true if the item was equiped
*/
bool Character::equipItem(Equipment itemToEquip) {
	int tempSlot = itemToEquip.getSlot();
	if (equipedItems[tempSlot] == 0) {
		*equipedItems[tempSlot] = itemToEquip;
		return true;
	}
	return false;
};
示例#9
0
bool Inventory::addEntityInventoryItem(int i, Entity* ii)
{
	if (slotList.size() < maxSlotListCount)
	{
		if (!hasEntityInventoryItem(i))
		{
			if (ii->getInventoryItem()->getType() == "INVENTORYEQUIPMENT")
			{//is equipment
				Equipment* eq = (Equipment*)ii->getInventoryItem()->getItem();
				if (eq->occupiesBody())
				{//is body armor
					if (getSlotBody() == nullptr || getSlotBody()->getInventoryItem()->getCost() < ii->getInventoryItem()->getCost())
					{//if new armor is better (more expensive)
						slot_body = i;
					}
				}
				else if (eq->occupiesHand())
				{
					if (eq->occupiesOffhand())
					{//normal weapon
						if (getSlotHand() == nullptr || getSlotHand()->getInventoryItem()->getCost() < ii->getInventoryItem()->getCost())
						{//if new weapon is better (more expensive)
							slot_hand = i;
						}
					}
				}
				else
				{//shield
					if (getSlotOffHand() == nullptr || getSlotOffHand()->getInventoryItem()->getCost() < ii->getInventoryItem()->getCost())
					{//if new shield is better (more expensive)
						slot_offhand = i;
					}
				}
			}
			int row = i / inventoryColumns + 1;
			int col = i % inventoryColumns + 1;
			ii->setX(xDrawPosition + col*ii->getInventoryItem()->getItem()->getSpriteWidth() + magicPadding);
			ii->setY(yDrawPosition + row*ii->getInventoryItem()->getItem()->getSpriteHeight() + magicPadding);
			slotList[i] = ii;
			return true;
		}
	}
	return false;
}
示例#10
0
void LogIntoLayer::clickLogInto(CCObject* pSender)
{
	map<string,string> post;
	post["api"] = "login";
	post["username"]=usernameText->getString();
	post["password"]=passwordText->getString();
	std::string jsonStr = POST(post);
	JsonBox::Value data;
	CCLOG(jsonStr.c_str());
	data.loadFromString(jsonStr);
	if(data["result"].getString()=="OK"){
		CCLOG("Login Successfully!");
		USER->setUserID(atoi(data["0"]["user_id"].getString().c_str()));
		USER->setUsername(data["0"]["username"].getString());
		USER->setPassword(data["0"]["password"].getString());
		USER->setLevel(atoi(data["0"]["level"].getString().c_str()));
		USER->setExp(atoi(data["0"]["exp"].getString().c_str()));
		USER->setBasicAGI(atoi(data["0"]["basic_agi"].getString().c_str()));
		USER->setBasicSTR(atoi(data["0"]["basic_str"].getString().c_str()));
		USER->setBasicDEF(atoi(data["0"]["basic_def"].getString().c_str()));
		Equipment* equipment = new Equipment();
		equipment->setWeapon(Weapon(atoi(data["0"]["current_weapon"].getString().c_str())));
		equipment->setBase(Base(atoi(data["0"]["current_base"].getString().c_str())));
		equipment->setPlate(Plate(atoi(data["0"]["current_plate"].getString().c_str())));//
		USER->setOpenChaptersNumber(atoi(data["0"]["open_chapters_number"].getString().c_str()));
		USER->setWinOnlineGamesNumber(atoi(data["0"]["win_online_game_number"].getString().c_str()));
		USER->setPlayOnlineGamesNumber(atoi(data["0"]["play_online_game_number"].getString().c_str()));
		USER->setMoney(atoi(data["0"]["money"].getString().c_str()));
		CCLOG(data["0"]["money"].getString().c_str());
		USER->setHonor(atoi(data["0"]["honor"].getString().c_str()));
		USER->setHasSignin(true);
		USER->setIsBeginner(false);
		USER->flush();
		CCNode* parent = this->getParent();
		this->removeFromParentAndCleanup();
		INFORMATION_BOX("Login successfully!",parent);
	}
	else{
		PopWindowsLayer::createInfomationBox("Login failed!",this);
	}
}
示例#11
0
void ItemFactory::LoadItem(Item::ItemType type, int id, Item* item)
{
    if(item->GetItemType() == Item::ItemTypeEquipment)
    {
        Equipment* equipment = (Equipment*)item;
        LoadEquipment(equipment->GetEquipmentPosition(), id, equipment);
    }
    else
    {
        switch(id)
        {
            //TODO: Init Item with Id itemId

        default:
            std::string msg("Invalid ItemId ");
            msg.append(std::to_string(id));
            msg.append(" given in LoadItem.");
            throw GenericException(msg);
        }
    }
}
/**
 * @brief zdejmijPrzedmiot	W miarę możliwości zdejmuje dany przedmiot z gracza.
 * @param rzecz		Przedmiot do zdjęcia
 * @param gracz		gracz, który zdjejmuje przedmiot
 */
void unequipItem(const Item *item, Player *player)
{
	if (!isEquipped(item, player) || item == nullptr)
		return;

	Equipment *equipment = player->equipment();

	switch (item->type()) {
	case bronDwureczna:
	case bronJednoreczna:
		equipment->setRightHand(nullptr);
		break;
	case tarcza:
		equipment->setLeftHand(nullptr);
		break;
	case pancerz:
		equipment->setTorso(nullptr);
		break;
	case helm:
		equipment->setHead(nullptr);
		break;
	case artefakt:
		equipment->removeArtifact(item);
		break;
	default:
		qDebug() << QString::fromUtf8("Próbowano założyć nierozpoznany rodzaj ekwipunku.");
	}

	deactivateBonus(item, player);
}
/**
 * @brief OknoBazaru::kup	Kupuje lub sprzedaje aktualnie zaznaczony przedmiot z listy przedmiotów na					bazarze.
 */
void MarketWindow::buy()
{
	Equipment *equipment = player_->equipment();
	if (buyButton->text() == sellText) {
		const Item *item = equipment->backpack().at(playerItemList->currentRow());
		unequipItem(item, player_);

		equipment->removeItem(item);
		wares_.push_back(item);
		player_->setGold(player_->gold() + item->value() / 2);
	} else {
		const Item *item = wares_.at(wareList->currentRow());
		if (player_->gold() < item->value())
			return;
		equipment->addItem(item);

		wares_.removeAt(wares_.indexOf(item));
		player_->setGold(player_->gold() - item->value());
	}
	populateListWidgets();
	playerWindow_->update();
	largePotionButton->setEnabled(player_->gold() >= CENA_DUZEJ_MIKSTURY);
	smallPotionButton->setEnabled(player_->gold() >= CENA_MALEJ_MIKSTURY);
}
示例#14
0
void EquipmentEditor::showChanges()
{
   Equipment *e = obsEquip;
   if( e == 0 )
   {
      clear();
      return;
   }

   // Get weight and volume units for grain absorption.
   Unit* weightUnit = 0;
   Unit* volumeUnit = 0;
   Brewtarget::getThicknessUnits( &volumeUnit, &weightUnit );
   label_absorption->setText(tr("Grain absorption (%1/%2)").arg(volumeUnit->getUnitName()).arg(weightUnit->getUnitName()));

   //equipmentComboBox->setIndexByEquipment(e);

   lineEdit_name->setText(e->name());
   lineEdit_name->setCursorPosition(0);
   lineEdit_boilSize->setText(e);
   checkBox_calcBoilVolume->blockSignals(true); // Keep next line from emitting a signal and changing e.
   checkBox_calcBoilVolume->setCheckState( (e->calcBoilVolume())? Qt::Checked : Qt::Unchecked );
   checkBox_calcBoilVolume->blockSignals(false);
   lineEdit_batchSize->setText(e);

   lineEdit_tunVolume->setText(e);
   lineEdit_tunWeight->setText(e);
   lineEdit_tunSpecificHeat->setText(e);

   lineEdit_boilTime->setText(e);
   lineEdit_evaporationRate->setText(e);
   lineEdit_topUpKettle->setText(e);
   lineEdit_topUpWater->setText(e);

   lineEdit_trubChillerLoss->setText(e);
   lineEdit_lauterDeadspace->setText(e);

   textEdit_notes->setText( e->notes() );

   double gaCustomUnits = e->grainAbsorption_LKg() * volumeUnit->fromSI(1.0) * weightUnit->toSI(1.0);
   lineEdit_grainAbsorption->setText(gaCustomUnits);

   lineEdit_boilingPoint->setText(e);

   lineEdit_hopUtilization->setText(e);
   checkBox_defaultEquipment->blockSignals(true);
   if ( Brewtarget::option("defaultEquipmentKey",-1) == e->key() )
      checkBox_defaultEquipment->setCheckState(Qt::Checked);
   else
      checkBox_defaultEquipment->setCheckState(Qt::Unchecked);
   checkBox_defaultEquipment->blockSignals(false);
}
/**
 * @brief zalozPrzedmiot	W miarę możliwości zakłada dany przedmiot na gracza
 * @param rzecz		przedmiot do założenia
 * @param gracz		gracz, który zakłada przedmiot
 */
void equipItem(const Item *item, Player *player)
{
	Equipment *equipment = player->equipment();

	if (item == nullptr || isEquipped(item, player) || (item->type() == artefakt && equipment->usedArtifacts().size() >= Item::ArtifactLimit))
		return;

	switch (item->type()) {
	case bronDwureczna:
		unequipItem(equipment->rightHand(), player);
		unequipItem(equipment->leftHand(), player);
		equipment->setRightHand(item);
		break;
	case bronJednoreczna:
		unequipItem(equipment->rightHand(), player);
		equipment->setRightHand(item);
		break;
	case tarcza:
		if (equipment->rightHand()->type() == bronDwureczna)
			unequipItem(equipment->rightHand(), player);
		unequipItem(equipment->leftHand(), player);
		equipment->setLeftHand(item);
		break;
	case pancerz:
		unequipItem(equipment->torso(), player);
		equipment->setTorso(item);
		break;
	case helm:
		unequipItem(equipment->head(), player);
		equipment->setHead(item);
		break;
	case artefakt:
		if (equipment->usedArtifacts().size() < Item::ArtifactLimit)
			equipment->addArtifact(item);
	case mikstura:
		qDebug() << "Proba zalozenia mikstury";
	}

	activateBonus(item, player);
}
示例#16
0
void Player::initCommands() {
    std::function<void (std::vector<std::string> commandWords, std::function<bool(const std::vector<std::string> &)>)> addCommands = [this](std::vector<std::string> commandWords, std::function<bool(const std::vector<std::string> &)> operation){
        if(commandWords.size() < 1) {
            throw std::invalid_argument("You must at least have one word associated with the command");
        }
        uniqueCommands.push_back(commandWords.front());
        for(std::string word: commandWords){
            if(commands.find(word) != commands.end()) {
                throw std::invalid_argument("The word: " + word + " is associated with more than one command");
            }
            commands[word] = operation;
        }
        
    };
    
    std::function<bool (const std::vector<std::string> & commands, const std::string & helpText, const std::string & usageCommands)> isHelp = [](const std::vector<std::string> & commands, const std::string & helpText, const std::string & usageCommands){
        if(commands.size() != 2){ return false; };
        if(commands[1] != "help"){ return false; };
        
        std::cout << TEXT_DIVIDER << " HELP: " << commands[0] << " " << TEXT_DIVIDER << std::endl;
        if(helpText != "") {
            std::cout << helpText << std::endl;
        }
        std::cout << "Usage: " << commands[0] << " " << usageCommands << std::endl;
        return true;
    };
    
    addCommands({"go", "move", "goto"}, [this, isHelp](const std::vector<std::string> & commands) -> bool {
        if(isHelp(commands, "Used for navigating through the world.", "LOCATION")) { return false; }
            
        if(commands.size() != 2) {
            std::cout << "You forgot to write where you wanna go." << std::endl;
            return false;
        }
        
        
        int num = -1; 
        try {
            num = atoi(commands[1].c_str()) - 1;
        } catch(int) {
            std::cout << "That is not an option. Write one of the numbers given as option." << std::endl;
            return false;
        }
        
        auto dirs = getEnvironment()->getDirections();
        
        if(num >= dirs.size()) {
            std::cout << "That is not an option. Write one of the numbers given as option." << std::endl;
            return false;
        }
        
        if(!this->move(dirs[num])) {
                std::cout << "That is not an option. Write one of the numbers given as option." << std::endl;
                return false;
            }
        
        return true;
    });
    
    addCommands({"look"}, [this, isHelp](const std::vector<std::string> & commands) -> bool {
        if(isHelp(commands, "Look for example at different characters or on items to get more information. You can look at almost anything in the world.", "[CONTAINER] [OBJECT]")) { return false;}
        Environment * env = getEnvironment();
        if(commands.size() == 1) {
            printUpdateInfo();
        } else if(commands.size() == 2) {
            if(isCommandInventory(commands[1])) {
                std::cout << getInventory()->getDescription() << std::endl;
                return false;
            }
            if(isCommandEquipment(commands[1])) {
                std::cout << getEquipment()->getDescription() << std::endl;
                return false;
            }
            PhysicalObject * physicalObject = env->find(commands[1]);
            if(physicalObject == NULL) {
                std::cout << "Found no item named: " << commands[1] << std::endl;
            } else {
                std::cout << physicalObject->getDescription() << std::endl;
            }
            
            
        } else if(commands.size() == 3) {
            Item * item = NULL;
            if(isCommandInventory(commands[1])) {
                Inventory * inv = getInventory();
                item = inv->find(commands[2]);
                if(item == NULL) {
                    std::cout << "Found no item named: " << commands[2] << " in your inventory." << std::endl;
                    return false;
                }
            } else if(isCommandEquipment(commands[1])) {
                Equipment * eq = getEquipment();
                item = eq->find(commands[2]);
                if(item == NULL) {
                    std::cout << "Found no item named: " << commands[2] << " in your equipment." << std::endl;
                    return false;
                }
            } else {
                Container * con = env->find<Container>(OBJECT_TYPE_CONTAINER, commands[2]);
                if(con == NULL) {
                    std::cout << "Found no container named: " <<commands[1] << std::endl;
                    return false;
                } else {
                    item = con->find(commands[2]);
                    if(item == NULL) {
                        std::cout << "Found no item named: " << commands[2] << " in container: " << con->getName() << std::endl;
                        return false;
                    }
                }
            }
            std::cout << item->getDescription() << std::endl;
        }
        
        return false;
    });
    
    addCommands({"stats"}, [this, isHelp](const std::vector<std::string> & commands) -> bool {
        if(isHelp(commands,"Get information about you.",  "")) { return false;}
        std::cout << getDescription() << std::endl;
        return false;
    });
    
    addCommands({"inventory", "backpack", "inv"}, [this, isHelp](const std::vector<std::string> & commands) -> bool {
        if(isHelp(commands, "Get information about your inventory that contains items.", "")) { return false;}
        Inventory * inv = getInventory();
        std::cout << inv->getDescription() << std::endl;
        return false;
    });
    
    addCommands({"equipment"}, [this, isHelp](const std::vector<std::string> & commands) -> bool {
        if(isHelp(commands, "Get information about your current equipment.", "")) { return false;}
        Equipment * eq = getEquipment();
        std::cout << eq->getDescription() << std::endl;
        return false;
    });
    
    addCommands({"pick"}, [this, isHelp](const std::vector<std::string> & commands) -> bool {
        if(isHelp(commands,"Pick up items from the ground or from containers like for example Chests.", "[CONTAINER] ITEM")) { return false;}
        if(commands.size() < 2) {
            std::cout << "You forgot to write what you wanted to pick up." << std::endl;
            return false;
        }
        
        Environment * env = getEnvironment();
        if(commands.size() == 2) {
            Item * item = env->find<Item>(OBJECT_TYPE_ITEM, commands[1]);
            if(item == NULL) {
                std::cout << "Found no item named: " << commands[1] << std::endl;
                return false;
            }
            
            if(!pickItem(item)) {
                std::cout << "You can't pick up item: " << commands[1] << std::endl;
                return false;
            }
            
            std::cout << "You picked up item: " << commands[1] << std::endl;
            
            return false;
        } else if(commands.size() == 3) {
            Container * container = env->find<Container>(OBJECT_TYPE_CONTAINER, commands[1]);
            if(container == NULL) {
                std::cout << "Found no container named: " <<commands[1] << std::endl;
                return false;
            }
            
            Item * item = container->find<Item>(OBJECT_TYPE_ITEM, commands[2]);
            if(item == NULL) {
                std::cout << "Found no item named: " << commands[2] << " in container: " << commands[1] << std::endl;
                return false;
            }
            
            if(!pickItem(item, container)) {
                std::cout << "You can't pick up item: " << commands[2] << " in container: " << commands[1] << std::endl;
                return false;
            }

            std::cout << "You picked up item: " << commands[2] << " from container: " << commands[1]<< std::endl;
            
            return false;
        }
        
        std::cout << "Invalid command syntax. Usage: pick [CONTAINER] ITEM" << std::endl;
        return false;
    });
    
    addCommands({"drop", "put"}, [this, isHelp](const std::vector<std::string> & commands) -> bool {
        if(isHelp(commands, "Drop items on the ground or drop them into containers.", "[CONTAINER] ITEM")) { return false;}
        if(commands.size() < 2) {
            std::cout << "You forgot to write what you wanted to drop." << std::endl;
            return false;
        }
        
        Inventory * inv = getInventory();
        if(commands.size() == 2) {
            Item * item = inv->find(commands[1]);
            if(item == NULL) {
                std::cout << "Found no item named: " << commands[1] << " in your inventory." << std::endl;
                return false;
            }
            
            if(!dropItem(item)) {
                std::cout << "You can't drop item: " << commands[1] << " from your inventory. " << std::endl;
                return false;
            }
            
            std::cout << "You dropped item: " << commands[1] << " from your inventory. " << std::endl;
            return false;
            
        } else if(commands.size() == 3) {
            Environment * env = getEnvironment();
            Container * container = env->find<Container>(OBJECT_TYPE_CONTAINER, commands[1]);
            if(container == NULL) {
                std::cout << "Found no container named: " <<commands[1] << std::endl;
                return false;
            }
            
            Item * item = inv->find(commands[2]);
            if(item == NULL) {
                std::cout << "Found no item named: " << commands[2] << " in your inventory." << std::endl;
                return false;
            }
            
            if(!putItem(item, container)) {
                std::cout << "You can't put item: " << commands[2] << " in container: " << commands[1] << std::endl;
                return false;
            }
            
            std::cout << "You put item: " << commands[2] << " in container: " << commands[1] << std::endl;

            return false;
        }
        
        std::cout << "Invalid command syntax. Usage: drop [CONTAINER] ITEM" << std::endl;
        return false;
    });
    
    addCommands({"open"}, [this, isHelp](const std::vector<std::string> & commands) -> bool {
        if(isHelp(commands,"The same as 'look CONTAINER'.", "CONTAINER")) { return false;}
        if(commands.size() != 2) {
            std::cout << "You forgot to write what you wanted to open." << std::endl;
            return false;
        }
        
        Environment * env = getEnvironment();
        Container * container = env->find<Container>(OBJECT_TYPE_CONTAINER, commands[1]);
        if(container == NULL) {
            std::cout << "Found no container named: " <<commands[1] << std::endl;
            return false;
        }
        
        int takenSpace = container->getTakenSpace();
        std::string takenSpaceText = unsignedValToString(takenSpace);
        
        std::cout << container->getDescription() << std::endl;
        
        return false;
    });
    
    addCommands({"unlock"}, [this, isHelp](const std::vector<std::string> & commands) -> bool {
        if(isHelp(commands, "Unlock containers or items using this command.", "[CONTAINER] LOCKED_OBJECT KEY")) { return false;}
        Environment * env = getEnvironment();
        Inventory * inv = getInventory();
        if(commands.size() < 3 || commands.size() > 4) {
            std::cout << "Invalid command syntax. Usage: unlock [CONTAINER] LOCKED_OBJECT KEY" << std::endl;
            return false;
        }
        KeyLock * lock = NULL;
        std::string containerString;
        std::string lockString;
        std::string keyString;
        if(commands.size() == 4) {
            lockString = commands[2];
            keyString = commands[3];
            Container * con;
            if(isCommandInventory(commands[1])) {
                con = inv;
            } else {
                con = env->find<Container>(OBJECT_TYPE_CONTAINER, commands[1]);
            }
            if(con == NULL) {
                std::cout << "Found no container named: " << commands[1] << std::endl;
                return false;
            }
            lock = dynamic_cast<KeyLock *>(con->find(commands[1]));
            
            containerString = " in container named: " + con->getName();

        } else if(commands.size() == 3) {
            containerString = "";
            lockString = commands[1];
            keyString = commands[2];
            lock = dynamic_cast<KeyLock *>(env->find(commands[1]));
        }
        if(lock == NULL) {
            std::cout << "Found no lockable object named: " << lockString << containerString << std::endl;
            return false;
        }
        Key * key = inv->find<Key>(OBJECT_TYPE_ITEM, ITEM_TYPE_KEY, keyString);
        if(key == NULL) {
            std::cout << "Found no key named: " << keyString  << " in your inventory."<< std::endl;
            return false;
        }
        std::string keyName = key->getName();
        PhysicalObject * test = dynamic_cast<PhysicalObject*>(lock); // Needed because not strictly
        if(test == nullptr) {
            throw std::runtime_error("The lockable item was not a PhysicalObject. Should not be possible.");
        }
        std::string lockName = test->getName();
        if(lock->unlock(key, *inv)) {
            std::cout << "You unlocked: " << lockName << containerString << " using key: " << keyName << std::endl;
            return false;
        } else {
            std::cout << "You can't unlock: " << lockName << containerString << " using key: " << keyName << std::endl;
            return false;
        }
    });
    
    addCommands({"eat", "drink"}, [this, isHelp](const std::vector<std::string> & commands) -> bool {
        if(isHelp(commands,"Use this command to consume items. Tip: Write 'drink' so you don't accidentally chew liquids.", "ITEM")) { return false;}
        if(commands.size() != 2) {
            std::cout << "Invalid command syntax. Usage: eat FOOD" << std::endl;
            return false;
        }
        
        Consumable * cItem = getInventory()->find<Consumable>(OBJECT_TYPE_ITEM, ITEM_TYPE_CONSUMABLE, commands[1]);
        if(cItem == NULL) {
            std::cout << "Found no consumable item named: " << commands[1]  << " in your inventory."<< std::endl;
            return false;
        }
        
        std::string consumableName = cItem->getName();
        std::string response = cItem->consume(this);
        std::cout << "You digested " << consumableName  << " and " << response << std::endl;
        return false;
    });
    
    addCommands({"equip", "eq"}, [this, isHelp](const std::vector<std::string> & commands) -> bool {
        if(isHelp(commands, "Used for equipping items. You can only equip one of each type of equippable item.", "[ITEM]")) { return false;}
        if(commands.size() != 2) {
            std::cout << "Invalid command syntax. Usage: equip ITEM" << std::endl;
            return false;
        }
        
        Inventory * inv = getInventory();
        Item * item = inv->find(commands[1]);
        if(item == NULL) {
            std::cout << "Found no equipable item named: " << commands[1] << std::endl;
            return false;
        }
        
        BreakableItem * bItem = dynamic_cast<BreakableItem*>(item);
        if(bItem == nullptr) {
            std::cout << "The item: " << item->getName() << " is not equipable." << std::endl;
            return false;
        }
        
        if(equip(bItem)) {
            std::cout << "You equipeed item: " << bItem->getName() << std::endl;
            return false;
        } else {
            std::cout << "You failed to equip: " << bItem->getName() << std::endl;
            return false;
        }
    });
    
    addCommands({"unequip", "uneq", "ueq"}, [this, isHelp](const std::vector<std::string> & commands) -> bool {
        if(isHelp(commands,"Used for removing equipped items and putting them back to your inventory, if you have enough space.", "ITEM")) { return false;}
        if(commands.size() != 2) {
            std::cout << "Invalid command syntax. Usage: equip ITEM" << std::endl;
            return false;
        }
        
        Equipment * eq = getEquipment();
        BreakableItem * bItem = eq->find(commands[1]);
        if(bItem == NULL) {
            std::cout << "Found no equiped item named: " << commands[1] << std::endl;
            return false;
        }
        if(unEquip(bItem)) {
            std::cout << "You unequiped item: " << bItem->getName() << std::endl;
            return false;
        } else {
            std::cout << "You failed to unequip: " << bItem->getName() << std::endl;
            return false;
        }
    });
    
    addCommands({"attack", "att"}, [this, isHelp](const std::vector<std::string> & commands) -> bool {
        if(isHelp(commands, "KILL!", "CHARACTER")) { return false;}
        if(commands.size() != 2) {
            std::cout << "You forgot to write what you wanted to attack." << std::endl;
            return false;
        }
        
        Character * character = getEnvironment()->find<Character>(OBJECT_TYPE_CHARACTER, commands[1], {this});
        
        if(character == NULL) {
            std::cout << "There is no " + commands[1] << " in the area." << std::endl;
            return false;
        }
        
        if(!character->startInteraction(this)) {
            std::cout << "The " << character->getName() << " busy fighting already." << std::endl;
            return false;
        }
        
        std::cout << std::endl << "You are initiating a fight with " << character->getName() << "!" << std::endl;
        
        interact(character);
        
        character->endInteraction(this);
        endInteraction(character);
        
        
        return true;
    });
    
    addCommands({"pass", "wait", "skip"}, [isHelp](const std::vector<std::string> & commands) -> bool {
        if(isHelp(commands,"Wait a moment and let others take their turn.", "")) { return false;}
        return true;
    });
    
    addCommands({"exit"}, [this, isHelp](const std::vector<std::string> & commands) -> bool {
        if(isHelp(commands,"Exit the game. No turning back after this.", "")) { return false;}
        this->getEngine()->kill();
        return true;
    });
    
    addCommands({"help"}, [this, isHelp](const std::vector<std::string> & commands) -> bool {
        if(isHelp(commands,"Helpception?", "")) { return false;}
        std::cout << std::endl;
        std::cout << TEXT_DIVIDER << " HELP START " << TEXT_DIVIDER << std::endl;
        std::cout << "For more help on individual commands, write: COMMAND help" << std::endl;
        std::cout << "COMMANDS" << std::endl;
        std::cout << TEXT_DIVIDER << std::endl;
        
        for(auto command : getUniqueCommands()) {
            std::cout << command << std::endl;
        }
        
        std::cout << TEXT_DIVIDER << " HELP END " << TEXT_DIVIDER << std::endl;
        return false;
    });
}
示例#17
0
void Testing::postBoilLossOgTest()
{
   double const grain_kg = 5.0;
   Recipe* recNoLoss = Database::instance().newRecipe();
   Recipe* recLoss = Database::instance().newRecipe();
   Equipment* eNoLoss = equipFiveGalNoLoss;
   Equipment* eLoss = Database::instance().newEquipment(eNoLoss);

   // Only difference between the recipes:
   // - 2 L of post-boil loss
   // - 2 L extra of boil size (to hit the same batch size)
   eLoss->setTrubChillerLoss_l(2.0);
   eLoss->setBoilSize_l(eNoLoss->boilSize_l() + eLoss->trubChillerLoss_l());

   // Basic recipe parameters
   recNoLoss->setName("TestRecipe_noLoss");
   recNoLoss->setBatchSize_l(eNoLoss->batchSize_l());
   recNoLoss->setBoilSize_l(eNoLoss->boilSize_l());
   recNoLoss->setEfficiency_pct(70.0);

   recLoss->setName("TestRecipe_loss");
   recLoss->setBatchSize_l(eLoss->batchSize_l());
   recLoss->setBoilSize_l(eLoss->boilSize_l());
   recLoss->setEfficiency_pct(70.0);

   double mashWaterNoLoss_l = recNoLoss->boilSize_l()
      + eNoLoss->grainAbsorption_LKg() * grain_kg
   ;
   double mashWaterLoss_l = recLoss->boilSize_l()
      + eLoss->grainAbsorption_LKg() * grain_kg
   ;

   // Add equipment
   Database::instance().addToRecipe(recNoLoss, eNoLoss);
   Database::instance().addToRecipe(recLoss, eLoss);

   // Add grain
   twoRow->setAmount_kg(grain_kg);
   Database::instance().addToRecipe(recNoLoss, twoRow);
   Database::instance().addToRecipe(recLoss, twoRow);

   // Single conversion, no sparge
   Mash* singleConversion = Database::instance().newMash();
   singleConversion->setName("Single Conversion");
   singleConversion->setGrainTemp_c(20.0);
   singleConversion->setSpargeTemp_c(80.0);

   MashStep* singleConversion_convert = Database::instance().newMashStep(singleConversion);
   singleConversion_convert->setName("Conversion");
   singleConversion_convert->setType(MashStep::Infusion);

   // Infusion for recNoLoss
   singleConversion_convert->setInfuseAmount_l(mashWaterNoLoss_l);
   Database::instance().addToRecipe(recNoLoss, singleConversion);

   // Infusion for recLoss
   singleConversion_convert->setInfuseAmount_l(mashWaterLoss_l);
   Database::instance().addToRecipe(recLoss, singleConversion);

   // Verify we hit the right boil/final volumes (that the test is sane)
   QVERIFY2( fuzzyComp(recNoLoss->boilVolume_l(),  recNoLoss->boilSize_l(),  0.1),     "Wrong boil volume calculation (recNoLoss)" );
   QVERIFY2( fuzzyComp(recLoss->boilVolume_l(),    recLoss->boilSize_l(),    0.1),     "Wrong boil volume calculation (recLoss)" );
   QVERIFY2( fuzzyComp(recNoLoss->finalVolume_l(), recNoLoss->batchSize_l(), 0.1),     "Wrong final volume calculation (recNoLoss)" );
   QVERIFY2( fuzzyComp(recLoss->finalVolume_l(),   recLoss->batchSize_l(),   0.1),     "Wrong final volume calculation (recLoss)" );

   // The OG calc itself is verified in recipeCalcTest_*(), so just verify that
   // the two OGs are the same
   QVERIFY2( fuzzyComp(recLoss->og(), recNoLoss->og(), 0.002), "OG of recipe with post-boil loss is different from no-loss recipe" );
}
示例#18
0
int script::upgrade(lua_State *L)
{
	//charactersession, type(0=all), rate
	//returns true on success
	//TODO not sure how this one should work for final version
	const int n = lua_gettop(L);
	if (n != 3)
		return 0;
	Character *c = (Character *)lua_touserdata(L, 1);
	int type = (int)lua_tonumber(L, 2);
	int rate = (int)lua_tonumber(L, 3);

	std::uniform_int_distribution<int> dist(0, 99);
	
	if (rate < 100 && dist(generator()) >= rate) {
		return 0;
	}
	//here im assuming this is the upgrader's function, but what if it should work
	//for players too?
	Item *itm = c->getInventory()[0];
	if (!itm || itm->getType() != BaseItem::EQUIP)
		return 0;
	Equipment *eq = (Equipment*) itm;
	if (!eq->canModify() || (eq->getSlot() != Equipment::WEAPON && eq->getSlot() != Equipment::ARMOR)
			|| eq->getMod() > Equipment::GRAND) {
		return 0;
	}

	if (c->countItems(eq->getId(), eq->getMod()) < 3) {
		return 0;
	}

	//finally
	Equipment *neweq = (Equipment*) new Equipment(eq->getId(), eq->getQty(), eq->getMaxDur());
	neweq->setMod(eq->getMod() + 1);
	Item *r = c->getInventory().take(eq->getId(), 3, eq->getMod(), c);
	if (r) {
		c->getItem(neweq);
		delete r;
	}
	lua_pushboolean(L, true);
	return 1;
}
示例#19
0
void Testing::recipeCalcTest_allGrain()
{
   double const grain_kg = 5.0;
   double const conversion_l = grain_kg * 2.8; // 2.8 L/kg mash thickness
   Recipe* rec = Database::instance().newRecipe();
   Equipment* e = equipFiveGalNoLoss;

   // Basic recipe parameters
   rec->setName("TestRecipe");
   rec->setBatchSize_l(e->batchSize_l());
   rec->setBoilSize_l(e->boilSize_l());
   rec->setEfficiency_pct(70.0);

   // Single conversion, single sparge
   Mash* singleConversion = Database::instance().newMash();
   singleConversion->setName("Single Conversion");
   singleConversion->setGrainTemp_c(20.0);
   singleConversion->setSpargeTemp_c(80.0);
   MashStep* singleConversion_convert = Database::instance().newMashStep(singleConversion);
   singleConversion_convert->setName("Conversion");
   singleConversion_convert->setType(MashStep::Infusion);
   singleConversion_convert->setInfuseAmount_l(conversion_l);
   MashStep* singleConversion_sparge = Database::instance().newMashStep(singleConversion);
   singleConversion_sparge->setName("Sparge");
   singleConversion_sparge->setType(MashStep::Infusion);
   singleConversion_sparge->setInfuseAmount_l(
      rec->boilSize_l()
      + e->grainAbsorption_LKg() * grain_kg // Grain absorption
      - conversion_l // Water we already added
   );

   // Add equipment
   Database::instance().addToRecipe(rec, e);

   // Add hops (85g)
   cascade_4pct->setAmount_kg(0.085);
   Database::instance().addToRecipe(rec, cascade_4pct);

   // Add grain
   twoRow->setAmount_kg(grain_kg);
   Database::instance().addToRecipe(rec, twoRow);

   // Add mash
   Database::instance().addToRecipe(rec, singleConversion);

   // Malt color units
   double mcus =
      twoRow->color_srm()
      * (grain_kg * 2.205) // Grain in lb
      / (rec->batchSize_l() * 0.2642); // Batch size in gal

   // Morey formula
   double srm = 1.49 * pow(mcus, 0.686);

   // Initial og guess in kg/L.
   double og = 1.050;

   // Ground-truth plato (~12)
   double plato =
      grain_kg
      * twoRow->yield_pct()/100.0
      * rec->efficiency_pct()/100.0
      / (rec->batchSize_l() * og) // Total wort mass in kg (not L)
      * 100; // Convert to percent

   // Refine og estimate
   og = 259.0/(259.0-plato);

   // Ground-truth IBUs (mg/L of isomerized alpha acid)
   //   ~40 IBUs
   double ibus =
      cascade_4pct->amount_kg()*1e6     // Hops in mg
      * cascade_4pct->alpha_pct()/100.0 // AA ratio
      * 0.235 // Tinseth utilization (60 min @ 12 Plato)
      / rec->batchSize_l();

   // Verify calculated recipe parameters within some tolerance.
   QVERIFY2( fuzzyComp(rec->boilVolume_l(),  rec->boilSize_l(),  0.1),     "Wrong boil volume calculation" );
   QVERIFY2( fuzzyComp(rec->finalVolume_l(), rec->batchSize_l(), 0.1),     "Wrong final volume calculation" );
   QVERIFY2( fuzzyComp(rec->og(),            og,                 0.002),   "Wrong OG calculation" );
   QVERIFY2( fuzzyComp(rec->IBU(),           ibus,               5.0),     "Wrong IBU calculation" );
   QVERIFY2( fuzzyComp(rec->color_srm(),     srm,                srm*0.1), "Wrong color calculation" );
}
示例#20
0
Item* ItemFactory::GetEquipment(Equipment::EquipmentPosition pos, int itemId)
{
    Localization* localization = Localization::GetInstance();
    Equipment* retval = new Equipment(itemId,pos);
    LoadEquipment(pos, itemId, retval);
    SkillGenerator* gen = retval->GetSkillGenerator();

    MathHelper* mathHelper = MathHelper::GetInstance();
    switch(itemId)
    {
    case 1:
        retval->SetAttributeBuff(BattleEnums::AttributeStrength, mathHelper->GetRandomInt(6,3,true));
        retval->SetAttributeBuff(BattleEnums::AttributeDefense, mathHelper->GetRandomInt(3,0,true));
        retval->SetAttributeBuff(BattleEnums::AttributeSpeed, mathHelper->GetRandomInt(3,0,true));
        retval->SetAttributeBuff(BattleEnums::AttributeMaxHp, mathHelper->GetRandomInt(3,0,true));

        retval->AddSkillsToLearn(mathHelper->GetRandomInt(3,1,true));
        break;

    case 2:
        retval->SetAttributeBuff(BattleEnums::AttributeDefense, mathHelper->GetRandomInt(6,3,true));
        retval->SetAttributeBuff(BattleEnums::AttributeMagicDefense, mathHelper->GetRandomInt(6,3,true));
        retval->SetAttributeBuff(BattleEnums::AttributeMaxHp, mathHelper->GetRandomInt(6,3,true));

        retval->AddSkillsToLearn(mathHelper->GetRandomInt(3,1,true));
        break;

    case 3:
        retval->SetAttributeBuff(BattleEnums::AttributeDefense, mathHelper->GetRandomInt(3,0,true));
        retval->SetAttributeBuff(BattleEnums::AttributeMagicDefense, mathHelper->GetRandomInt(6,3,true));
        retval->SetAttributeBuff(BattleEnums::AttributeMaxHp, mathHelper->GetRandomInt(6,3,true));
        retval->SetAttributeBuff(BattleEnums::AttributeSpeed, mathHelper->GetRandomInt(6,3,true));

        retval->AddSkillsToLearn(mathHelper->GetRandomInt(3,1,true));
        break;

    case 4:
        retval->SetAttributeBuff(BattleEnums::AttributeMagicDefense, mathHelper->GetRandomInt(3,0,true));
        retval->SetAttributeBuff(BattleEnums::AttributeMaxMp, mathHelper->GetRandomInt(6,3,true));
        retval->SetAttributeBuff(BattleEnums::AttributeInt, mathHelper->GetRandomInt(6,3,true));
        retval->SetAttributeBuff(BattleEnums::AttributeSpeed, mathHelper->GetRandomInt(3,0,true));

        retval->AddSkillsToLearn(mathHelper->GetRandomInt(3,1,true));
        break;

    case 101:
        retval->SetAttributeBuff(BattleEnums::AttributeStrength, mathHelper->GetRandomInt(10,5,true));
        retval->SetAttributeBuff(BattleEnums::AttributeDefense, mathHelper->GetRandomInt(5,2,true));
        retval->SetAttributeBuff(BattleEnums::AttributeSpeed, mathHelper->GetRandomInt(5,2,true));
        retval->SetAttributeBuff(BattleEnums::AttributeMaxHp, mathHelper->GetRandomInt(5,2,true));

        retval->AddSkillsToLearn(mathHelper->GetRandomInt(4,2,true));
        break;

    case 102:
        retval->SetAttributeBuff(BattleEnums::AttributeDefense, mathHelper->GetRandomInt(10,5,true));
        retval->SetAttributeBuff(BattleEnums::AttributeMagicDefense, mathHelper->GetRandomInt(10,5,true));
        retval->SetAttributeBuff(BattleEnums::AttributeMaxHp, mathHelper->GetRandomInt(10,5,true));

        retval->AddSkillsToLearn(mathHelper->GetRandomInt(4,2,true));
        break;

    case 103:
        retval->SetAttributeBuff(BattleEnums::AttributeDefense, mathHelper->GetRandomInt(5,2,true));
        retval->SetAttributeBuff(BattleEnums::AttributeMagicDefense, mathHelper->GetRandomInt(10,5,true));
        retval->SetAttributeBuff(BattleEnums::AttributeMaxHp, mathHelper->GetRandomInt(10,5,true));
        retval->SetAttributeBuff(BattleEnums::AttributeSpeed, mathHelper->GetRandomInt(10,5,true));

        retval->AddSkillsToLearn(mathHelper->GetRandomInt(4,2,true));
        break;

    case 104:
        retval->SetAttributeBuff(BattleEnums::AttributeMagicDefense, mathHelper->GetRandomInt(5,2,true));
        retval->SetAttributeBuff(BattleEnums::AttributeMaxMp, mathHelper->GetRandomInt(10,5,true));
        retval->SetAttributeBuff(BattleEnums::AttributeInt, mathHelper->GetRandomInt(10,5,true));
        retval->SetAttributeBuff(BattleEnums::AttributeSpeed, mathHelper->GetRandomInt(5,2,true));

        retval->AddSkillsToLearn(mathHelper->GetRandomInt(4,2,true));
        break;

    case 1001:
        retval->SetAttributeBuff(BattleEnums::AttributeStrength, mathHelper->GetRandomInt(10,5,true));
        retval->SetAttributeBuff(BattleEnums::AttributeDefense, mathHelper->GetRandomInt(5,2,true));
        retval->SetAttributeBuff(BattleEnums::AttributeSpeed, mathHelper->GetRandomInt(5,2,true));
        retval->SetAttributeBuff(BattleEnums::AttributeMaxHp, mathHelper->GetRandomInt(5,2,true));

        retval->AddSkillsToLearn(mathHelper->GetRandomInt(5,2,true));
        break;

    case 1101:
        retval->SetAttributeBuff(BattleEnums::AttributeDefense, mathHelper->GetRandomInt(10,5,true));
        retval->SetAttributeBuff(BattleEnums::AttributeMagicDefense, mathHelper->GetRandomInt(10,5,true));
        retval->SetAttributeBuff(BattleEnums::AttributeMaxHp, mathHelper->GetRandomInt(10,5,true));

        retval->AddSkillsToLearn(mathHelper->GetRandomInt(5,2,true));
        break;

    case 1201:
        retval->SetAttributeBuff(BattleEnums::AttributeDefense, mathHelper->GetRandomInt(5,2,true));
        retval->SetAttributeBuff(BattleEnums::AttributeMagicDefense, mathHelper->GetRandomInt(10,5,true));
        retval->SetAttributeBuff(BattleEnums::AttributeMaxHp, mathHelper->GetRandomInt(10,5,true));
        retval->SetAttributeBuff(BattleEnums::AttributeSpeed, mathHelper->GetRandomInt(10,5,true));

        retval->AddSkillsToLearn(mathHelper->GetRandomInt(5,2,true));
        break;

    case 1301:
        retval->SetAttributeBuff(BattleEnums::AttributeMagicDefense, mathHelper->GetRandomInt(5,2,true));
        retval->SetAttributeBuff(BattleEnums::AttributeMaxMp, mathHelper->GetRandomInt(10,5,true));
        retval->SetAttributeBuff(BattleEnums::AttributeInt, mathHelper->GetRandomInt(10,5,true));
        retval->SetAttributeBuff(BattleEnums::AttributeSpeed, mathHelper->GetRandomInt(5,2,true));

        retval->AddSkillsToLearn(mathHelper->GetRandomInt(5,2,true));
        break;


        //TODO: Init Equipment with Id itemId
    default:
        std::string msg("Invalid ItemId ");
        msg.append(std::to_string(itemId));
        msg.append(" given in GetEquipment.");
        throw GenericException(msg);
    }
    return retval;
}
示例#21
0
// TODO: There are a LOT of assumptions and simplifications here. Need to change that.
void OgAdjuster::calculate()
{
   Equipment* equip;
   double sg = 0.0;
   double temp_c = 0.0;
   double plato = 0.0;
   double wort_l = 0.0;
   double hydroTemp_c = 0.0;

   double sugar_kg = 0.0;
   double water_kg = 0.0;
   double sg_15C = 0.0;
   double sg_20C = 0.0;
   double evapRate_lHr = 0.0;

   double finalPlato = 0.0;
   double finalVolume_l = 0.0;
   double finalWater_kg = 0.0;
   double finalUncorrectedSg_20C = 0.0;
   double waterToAdd_kg = 0.0;
   double waterToAdd_l = 0.0;

   bool gotSG = false;
   bool okPlato = true;

   // Get inputs.
   sg          = lineEdit_sg->toSI();
   plato       = lineEdit_plato->toDouble(&okPlato);
   temp_c      = lineEdit_temp->toSI();
   hydroTemp_c = lineEdit_calTemp->toSI();
   wort_l      = lineEdit_volume->toSI();

   // Make sure we got enough info.
   gotSG = sg != 0 && temp_c != 0 && hydroTemp_c != 0;

   if( wort_l == 0 )
      return;
   if( ! gotSG && ! okPlato )
      return;

   if( recObs == 0 || recObs->equipment() == 0 )
      return;

   equip = recObs->equipment();
   evapRate_lHr = equip->evapRate_lHr();

   // Calculate missing input parameters.
   if( gotSG )
   {
      sg_15C = sg * Algorithms::getWaterDensity_kgL(hydroTemp_c)/Algorithms::getWaterDensity_kgL(15) + Algorithms::hydrometer15CCorrection( temp_c );
      sg_20C = sg_15C * Algorithms::getWaterDensity_kgL(15)/Algorithms::getWaterDensity_kgL(20);

      plato = Algorithms::SG_20C20C_toPlato( sg_20C );
      lineEdit_plato->setText( sg_20C ); //Event if the display is in Plato, we must send it in default unit
   }
   else
   {
      sg_20C = Algorithms::PlatoToSG_20C20C( plato );
   }

   // Calculate intermediate parameters.
   sugar_kg = sg_20C * Algorithms::getWaterDensity_kgL(20) * wort_l * plato/(double)100;
   //std::cerr << "sugar_kg = " << sugar_kg << std::endl;
   water_kg = sg_20C * Algorithms::getWaterDensity_kgL(20) * wort_l * ((double)1 - plato/(double)100);
   //std::cerr << "water_kg = " << water_kg << std::endl;

   // Calculate OG w/o correction.
   finalVolume_l = equip->wortEndOfBoil_l(wort_l);
   finalWater_kg = water_kg - equip->boilTime_min()/(double)60 * evapRate_lHr * Algorithms::getWaterDensity_kgL(20);
   //std::cerr << "finalWater_kg = " << finalWater_kg << std::endl;
   //std::cerr << "boilTime = " << equip->getBoilTime_min() << std::endl;
   //std::cerr << "evapRate_lHr = " << evapRate_lHr << std::endl;
   //std::cerr << "waterDensity = " << Algorithms::getWaterDensity_kgL(20) << std::endl;
   finalPlato = (double)100 * sugar_kg / (sugar_kg + finalWater_kg);
   //std::cerr << "finalPlato = " << finalPlato << std::endl;
   finalUncorrectedSg_20C = Algorithms::PlatoToSG_20C20C( finalPlato );

   // Calculate volume to add to boil
   finalPlato = Algorithms::SG_20C20C_toPlato( recObs->og() ); // This is bad. This assumes the post-boil gravity = og. Need account for post-boil water additions.
   // postBoilWater_kg = batchSize - topUpWater;
   // postBoilSugar_kg = Algorithms::SG_20C20C_toPlato( recObs->getOG() ) / 100.0 * batchSize * recObs->getOG() * Algorithms::getWaterDensity_kgL(20);
   // finalPlato = 100 * postBoilSugar_kg / ( postBoilSugar_kg + postBoilWater_kg );
   waterToAdd_kg = (double)100 * sugar_kg / finalPlato - sugar_kg - finalWater_kg;
   waterToAdd_l = waterToAdd_kg / Algorithms::getWaterDensity_kgL(20);

   // Calculate final batch size.
   finalVolume_l += waterToAdd_l;

   // Display output.
   lineEdit_og->setText(finalUncorrectedSg_20C);
   lineEdit_add->setText(waterToAdd_l);
   lineEdit_batchSize->setText(finalVolume_l);
}
BaseSprite* MainLayerZhuangBeiBaseBody::getItemContentByIndex(unsigned int index)
{
    BaseSprite* bg = BaseSprite::create("mianban_zhuangbei_xiangxi.png");

    CCString tempStr;

    CCPoint picPos = ccp(75.0f, bg->getContentSize().height/2);

    {
        ImageData diWenData = ImageManager::getManager()->getImageData_DiWen_List(
                                  mEquipmentVec[index]->getEquipColor(),
                                  false,
                                  mEquipmentVec[index]->isPartOfSuit(),
                                  mEquipmentVec[index]->haveZhuanke());
        BaseSprite* diWen = BaseSprite::create(diWenData.getCurrentImageFile());
        diWen->setScale(diWenData.scale);
        diWen->setPosition(picPos);
        bg->addChild(diWen,0,TAG_BaseBody_TABLE_ITEM_DiWen);

        {
            BaseSprite *sprite = ImageManager::getManager()->getSpriteOfZhuangbei(mEquipmentVec[index],true,true);
            //sprite->setScale(data.scale);
            sprite->setScale(0.43f);
            sprite->setPosition(picPos);
            bg->addChild(sprite,0,TAG_BaseBody_TABLE_ITEM_Image);
        }

        //封印
        if (mEquipmentVec[index]->isInFengYin())
        {
            BaseSprite *fyImg = BaseSprite::create("shenbing_fengyin_suo.png");
            bg->addChild(fyImg, 0, TAG_BaseBody_TABLE_FengYin_Img);
            fyImg->setPosition(diWen->getPosition());
            fyImg->setScale(diWen->getContentSize().width*diWen->getScale() / fyImg->getContentSize().width);
        }

    }

    // 添加图片识别区
    {
        ImageData selecedData = ImageManager::getManager()->getImageData_DiWen_Selected(
                                    mEquipmentVec[index]->getEquipColor(),
                                    false,//mEquipmentVec[index]->isShenBing(),
                                    mEquipmentVec[index]->isPartOfSuit());
        BaseSprite* menuItemSel = BaseSprite::create(selecedData.getCurrentImageFile());
        menuItemSel->setScale(selecedData.scale);
        CCSprite* menuRect = CCSprite::createWithTexture(menuItemSel->getTexture());
        menuRect->setScale(0.0f);

        FXScrollMenu *menu = FXScrollMenu::create(
                                 mTableView->getParent()->convertToWorldSpace(mTableView->getPosition()), mTableView->getViewSize());
        bg->addChild(menu, 0, TAG_BaseBody_MENU);
        menu->setPosition(ccp(0,0));
        CCMenuItemSprite* t = CCMenuItemSprite::create(menuRect,menuItemSel,this,SEL_MenuHandler(&MainLayerZhuangBeiBaseBody::itemImageClicked));
        menu->addChild(t, 0, index);
        t->setPosition(picPos);
    }

    float left_x_start = 160 - 4;
    //名称
    {
        CCLabelTTF* label;
        char str[64];
        if (mEquipmentVec[index]->getEquipData().qianghua_data.qianghua_count != 0)
        {
            sprintf(str, "%s", mEquipmentVec[index]->getName().c_str());
        }
        else
        {
            sprintf(str, "%s", mEquipmentVec[index]->getName().c_str());
        }

        label = LF::lable(bg,str,ccp(left_x_start,190),24,fontStr_kaiti);
        label->setTag(TAG_BaseBody_LABLE_NAME);
        ccColor3B color = ImageManager::getManager()->getShowColor(mEquipmentVec[index]->getEquipColor(),false,mEquipmentVec[index]->isPartOfSuit());
        label->setColor(color);
    }

    //类型
    {
        std::string typeStr =
            CS::getZhuangbeiTypeName(mEquipmentVec[index]->getType(), mEquipmentVec[index]->getEquipColor());

        CCLabelTTF* label;
        label = LF::lable(bg,typeStr,ccp(left_x_start,165),18,fontStr_kaiti);
        label->setTag(TAG_BaseBody_LABLE_TYPE);
        label->setColor(fonColor_CiYao);
    }

    //白字
    {
        CCLabelTTF* label_baizhi = NULL;
        bool hasBaiZhi = false;
        {
            float baizi = 0;
            switch(mEquipmentVec[index]->getType())
            {
            case ZhuangbeiType_DanshouJian:
            case ZhuangbeiType_ShuangshouBishou:
            case ZhuangbeiType_ShuangshouFu:
            case ZhuangbeiType_DanshouFazhang:
            case ZhuangbeiType_ShuangshouFazhang:
            case ZhuangbeiType_Gong:
                hasBaiZhi = true;
                baizi = mEquipmentVec[index]->getGongjiLiAfterQianghua(false);
                break;
            case ZhuangbeiType_Dunpai:
            case ZhuangbeiType_KuijiaZhong:
            case ZhuangbeiType_KuijiaQin:
                hasBaiZhi = true;
                baizi = mEquipmentVec[index]->getHuJiaZhiAfterQianghua();
                break;
            default:
                break;
            }
            if (hasBaiZhi)
            {
                char str[64];
                sprintf(str, "%.1f", baizi);

                label_baizhi = LF::lable(bg,str,ccp(left_x_start,126),60,fontStr_BookAntiqua);
                label_baizhi->setTag(TAG_BaseBody_LABLE_BAIZI);
            }
            else
            {
                label_baizhi = LF::lable(bg,"",ccp(left_x_start,126),60,fontStr_BookAntiqua);
                label_baizhi->setTag(TAG_BaseBody_LABLE_BAIZI);
            }
        }
        //junshang
        CCLabelTTF* label_junshang = LF::lable(bg,LFStrings::getValue("junshang"),ccp(0,0),20,fontStr_kaiti);
        label_junshang->setAnchorPoint(ccp(0, 0.5));
        label_junshang->setPosition(
            ccp(label_baizhi->getPositionX()+label_baizhi->getContentSize().width+10, 116));
        label_junshang->setTag(TAG_BaseBody_LABLE_JUNSHANG_TXT);
        if(hasBaiZhi)
        {
            label_junshang->setVisible(true);
            if(mEquipmentVec[index]->getEquipType() == EquipType_FangJu)
                label_junshang->setString(LFStrings::getValue("huJia").c_str());
        }
        else
        {
            label_junshang->setVisible(false);
        }
    }

    //伤害详细
    if (mEquipmentVec[index]->getEquipType() == EquipType_WuQi)
    {
        CCLabelTTF* label;
        char str[64];
        sprintf(str, "%u-%u ", mEquipmentVec[index]->getEquipData().gongji_min
                , mEquipmentVec[index]->getEquipData().gongji_max);

        label = LF::lable(bg,str,ccp(left_x_start,87),20,fontStr_BookAntiqua);
        label->setTag(TAG_BaseBody_LABLE_SHANGHAIXIANGXI_NUM);
        label->setColor(fonColor_CiYao);
        CCLabelTTF* label2;
        label2 = LF::lable(bg,LFStrings::getValue("dianShangHai")
                           ,ccp(label->getPosition().x + label->getContentSize().width, label->getPositionY()),20,fontStr_kaiti);
        label2->setTag(TAG_BaseBody_LABLE_SHANGHAIXIANGXI_TXT);
        label2->setColor(fonColor_CiYao);
    }
    else
    {
        CCLabelTTF* label;
        label = LF::lable(bg,"",ccp(left_x_start,87),20,fontStr_kaiti);
        label->setTag(TAG_BaseBody_LABLE_SHANGHAIXIANGXI_NUM);
        CCLabelTTF* label2;
        label2 = LF::lable(bg,""
                           ,ccp(label->getPosition().x + label->getContentSize().width, label->getPositionY()),20,fontStr_kaiti);
        label2->setTag(TAG_BaseBody_LABLE_SHANGHAIXIANGXI_TXT);
    }

    //等级
    {
        CCLabelTTF* label;
        char str[64];
        sprintf(str, "%s %u ", LFStrings::getValue("dengji").c_str(), mEquipmentVec[index]->getEquipData().zhuangbei_level);
        label = LF::lable(bg,str,ccp(left_x_start,28),20,fontStr_kaiti);
        label->setColor(fonColor_FaGuang);
        label->setTag(TAG_BaseBody_LABLE_Level);
    }

    //人物
    {
        CCLabelTTF* label;
        int actorId = mEquipmentVec[index]->getActorId();
        if (actorId != INVALID_ID)
        {
            BaseActor* actor = MyselfManager::getManager()->getMyTeamActor(actorId);
            CCAssert(actor!=NULL,"");
            BaseActorProperty prop = actor->getCurrentProperty();
            label = LF::lable(bg,LF::getString("zhuangBeiYu")+prop.nameInChinese,ccp(0, 0),20,fontStr_kaiti);
        }
        else
        {
            label = LF::lable(bg,LF::getString("meiYouZhuangBei"),ccp(0, 0),20,fontStr_kaiti);
        }
        label->setColor(fonColor_FaGuang);
        label->setAnchorPoint(ccp(1, 0.5));
        label->setPosition(ccp( 590, 200));
        label->setTag(TAG_BaseBody_LABLE_OWNTO);
        if (actorId == INVALID_ID && mEquipmentVec[index]->getEquipData().profession_id != 0)
        {
            CCString temp;
            temp.initWithFormat("%s(%s)", LFStrings::getValue("ZhiYeXianZhi").c_str(),
                                BaseActorPropertyParser::getParser()->getExtraProerty((Profession)mEquipmentVec[index]->getEquipData().profession_id).nameInChinese.c_str());
            label->setString(temp.getCString());
            label->setColor(fonColor_JingGao);
        }
    }

    //魔法属性
    {
        int start_x = 400 + 38;
        Equipment* equip = mEquipmentVec[index];
        std::vector<std::string> vec = equip->getAllMofaShuxing(false);

        //大于5个  第五个就是 ......
        for(int i=0; i<vec.size(); ++i)
        {
            std::string txt = vec[i];

            BaseSprite* biaoji = BaseSprite::create("zhuangbei_xiangxi_biaoji.png");
            bg->addChild(biaoji, 0, TAG_BIAOJI+i);
            biaoji->setPosition(ccp(start_x, 170-i*28));
            //biaoji->setOpacity(80);

            CCLabelTTF* label;
            label = LF::lable(bg,txt,ccp(0,0),20,fontStr_kaiti);
            label->setColor(ImageManager::getManager()->getShowColor(ZhuangbeiColour_Fumo, false, false));
            label->setAnchorPoint(ccp(0, 0.5));
            label->setPosition(ccp(start_x+15, 170-i*28));
            label->setTag(i);

            if(vec.size()>6)
            {
                CCLog("Warrior:%s ---> equipment property > 6, current is [%d]", __FUNCTION__, vec.size());
                //	break;
            }
        }
        //洗练
        string xxx;
        CCSprite *diwen = (CCSprite*)bg->getChildByTag(TAG_BaseBody_TABLE_ITEM_DiWen);
        if (equip->canPurify(xxx,1) && diwen)
        {
            ZhuangbeiOptionLevel *layer = ZhuangbeiOptionLevel::createWithEquipment(equip);
            bg->addChild(layer,20);
            //layer->setScale(1/diwen->getScale());
            CCPoint pos = diwen->getPosition();
            pos.x -= diwen->getContentSize().width * diwen->getScaleX() / 2;
            pos.y -= diwen->getContentSize().height * diwen->getScaleY() / 2;

            int width = pos.x + layer->getContentSize().width / 2 + 12;
            int height = pos.y + layer->getContentSize().height / 2 + 4;
            layer->setPosition(ccp(width,height));
        }
    }

    bg->setPosition(ccp(bg->getContentSize().width/2,bg->getContentSize().height/2));
    return bg;
}