本文整理汇总了C++中Item::CanUse方法的典型用法代码示例。如果您正苦于以下问题:C++ Item::CanUse方法的具体用法?C++ Item::CanUse怎么用?C++ Item::CanUse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Item
的用法示例。
在下文中一共展示了Item::CanUse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Tick
void GameWorld::Tick(float timeStep)
{
for (GameObjectList::iterator iter = _objects.begin(); iter != _objects.end(); ++iter)
{
Item* object = *iter;
if (object->CanUse())
{
_characters[0]->GetController<Controller::CharacterController>(0)->SetUsableObject(object);
PlayScene::GetInstancePtr()->GetTooltipHeader()->SetText(static_cast<Potion*>(object)->GetDisplayName());
PlayScene::GetInstancePtr()->GetTooltipDescription()->SetText(static_cast<Potion*>(object)->GetDescription());
}
else
{
_characters[0]->GetController<Controller::CharacterController>(0)->SetUsableObject(nullptr);
}
object->Tick(timeStep);
}
_characters[0]->Tick(timeStep);
}
示例2: HandleItemSelection
void InventoryView::HandleItemSelection() {
Player* p = DataManager::Instance()->GetPlayer();
Inventory& inv = p->GetInventory();
if(m_inInventoryArea) {
if(inv.NumItems() > 0) {
Item* toUse = inv.ItemAtIndex(m_selectIdx);
Item* oldItem = NULL;
if(!toUse->CanUse()) {
stringstream s;
s << toUse->GetDisplayName() << " requires level " << toUse->GetRequiredLevel();
string toDisp = s.str();
DataManager::Instance()->AppendStatusString(toDisp);
return;
}
switch(toUse->GetClass()) {
case E_HELM:
inv.RemoveItem(toUse);
oldItem = p->GetHeadItem();
p->SetHeadItem((ArmorItem*)toUse);
if(oldItem) {
inv.AddItem(oldItem);
}
break;
case E_BODY:
inv.RemoveItem(toUse);
oldItem = p->GetBodyItem();
p->SetBodyItem((ArmorItem*)toUse);
if(oldItem) {
inv.AddItem(oldItem);
}
break;
case E_LEGS:
inv.RemoveItem(toUse);
oldItem = p->GetLegsItem();
p->SetLegsItem((ArmorItem*)toUse);
if(oldItem) {
inv.AddItem(oldItem);
}
break;
case E_WEAPON:
inv.RemoveItem(toUse);
oldItem = p->GetWeaponItem();
p->SetWeaponItem((Weapon*)toUse);
if(oldItem) {
inv.AddItem(oldItem);
}
break;
case E_IMPLANT:
inv.RemoveItem(toUse);
oldItem = p->GetImplantItem();
p->SetImplantItem((Implant*)toUse);
if(oldItem) {
inv.AddItem(oldItem);
}
break;
case E_CONSUMABLE:
if(toUse->CanStack()) {
Consumable* c = (Consumable*)toUse;
c->ApplyEffect();
if(toUse->GetStackSize() < 1) {
inv.RemoveItem(toUse);
}
}
break;
default:
break;
}
}
}
else {
switch(m_selectIdx) {
case 0:
p->ReturnHeadItemToInventory();
break;
case 1:
p->ReturnBodyItemToInventory();
break;
case 2:
p->ReturnLegsItemToInventory();
break;
case 3:
p->ReturnWeaponItemToInventory();
break;
case 4:
p->ReturnImplantItemToInventory();
break;
}
}
}