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);
}
Example #2
0
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;
		}
	}
}