예제 #1
0
	bool ActorInventory::equip(int id, int count) {
		DASSERT(isValidId(id) && count > 0);

		Item item = m_entries[id].item;
		ItemType::Type type = item.type();
		if((type != ItemType::weapon && type != ItemType::armour && type != ItemType::ammo) || !count)
			return false;
		if(type == ItemType::ammo && m_weapon.proto().ammo_class_id != Ammo(item).classId())
			return false;

		Entry old_ammo = m_ammo;
		unequip(type);

		if(type == ItemType::ammo) {
			if(old_ammo.item == item)
				count += old_ammo.count;
			count = min(count, m_weapon.maxAmmo());
		}
		else
			count = min(count, 1);
		count = min(count, m_entries[id].count);

		remove(id, count);

		if(type == ItemType::weapon)
			m_weapon = item;
		else if(type == ItemType::armour)
			m_armour = item;
		else if(type == ItemType::ammo) {
			m_ammo.item = item;
			m_ammo.count = count;
		}

		return true;
	}
예제 #2
0
파일: inventory.cpp 프로젝트: nadult/FreeFT
	void HudItemDesc::onDraw(Renderer2D &out) const {
		HudLayer::onDraw(out);
		FRect rect = this->rect();

		if(!m_item.isDummy()) {
			float ypos = topOffset() + rect.y();

			FRect uv_rect;
			auto texture = m_item.guiImage(false, uv_rect);
			float2 size(texture->width() * uv_rect.width(), texture->height() * uv_rect.height());

			float2 pos = (float2)(int2)(float2(rect.center().x - size.x * 0.5f, ypos));
			out.addFilledRect(FRect(pos, pos + size), uv_rect, {texture, mulAlpha(ColorId::white, alpha())});

			ypos += size.y + 10.0f;
			FRect desc_rect(rect.x() + 5.0f, ypos, rect.ex() - 5.0f, rect.ey() - 5.0f);
			// TODO: fix drawing of text that does not fit
		
			string params_desc;
			if(m_item.type() == ItemType::weapon)
				params_desc = Weapon(m_item).paramDesc();
			else if(m_item.type() == ItemType::ammo)
				params_desc = Ammo(m_item).paramDesc();
			else if(m_item.type() == ItemType::armour)
				params_desc = Armour(m_item).paramDesc();

			m_font->draw(out, float2(rect.x() + 5.0f, ypos), {titleColor(), titleShadowColor()}, params_desc);
		}
	}
예제 #3
0
	bool Weapon::canUseAmmo(const Item &item) const {
		return needAmmo() && item.type() == ItemType::ammo && Ammo(item).classId() == proto().ammo_class_id;
	}