void Inventory::addItem(PItem item) { itemsCache.push_back(item.get()); for (ItemIndex ind : ENUM_ALL(ItemIndex)) if (indexes[ind] && getIndexPredicate(ind)(item.get())) indexes[ind]->push_back(item.get()); items.push_back(std::move(item)); }
void RangedWeapon::fire(Creature* c, PItem ammo, Vec2 dir) { int toHitVariance = 10; int attackVariance = 15; int toHit = Random.get(-toHitVariance, toHitVariance) + c->getModifier(ModifierType::FIRED_ACCURACY) + ammo->getModifier(ModifierType::FIRED_ACCURACY) + getModifier(ModifierType::FIRED_ACCURACY); int damage = Random.get(-attackVariance, attackVariance) + c->getModifier(ModifierType::FIRED_DAMAGE) + ammo->getModifier(ModifierType::FIRED_DAMAGE) + getModifier(ModifierType::FIRED_DAMAGE); Attack attack(c, Random.choose({AttackLevel::LOW, AttackLevel::MIDDLE, AttackLevel::HIGH}), AttackType::SHOOT, toHit, damage, false, none); c->getPosition().throwItem(std::move(ammo), attack, 20, dir, c->getVision()); }
PItem Inventory::removeItem(Item* itemRef) { int ind = -1; for (int i : All(items)) if (items[i].get() == itemRef) { ind = i; break; } CHECK(ind > -1) << "Tried to remove unknown item."; PItem item = std::move(items[ind]); items.erase(items.begin() + ind); removeElement(itemsCache, itemRef); for (ItemIndex ind : ENUM_ALL(ItemIndex)) if (indexes[ind] && getIndexPredicate(ind)(item.get())) removeElement(*indexes[ind], itemRef); return item; }
void CPropItem::Activate() { Game::CProperty::Activate(); PItem Item = ItemMgr->GetItemTpl(GetEntity()->Get<CStrID>(Attr::ItemTplID))->GetTemplateItem(); int InstID = GetEntity()->Get<int>(Attr::ItemInstID); if (InstID > -1) { Item = Item->Clone(); //!!!Item->LoadFromDB(InstID);! } Items.SetItem(Item); Items.SetCount((WORD)GetEntity()->Get<int>(Attr::ItemCount)); PROP_SUBSCRIBE_PEVENT(OnSave, CPropItem, OnSave); PROP_SUBSCRIBE_PEVENT(OnPropsActivated, CPropItem, OnPropsActivated); PROP_SUBSCRIBE_PEVENT(PickItem, CPropItem, OnPickItem); }
WorkshopItem WorkshopItemCfg::get() const { // for some reason removing this line causes a linker error, probably a compiler bug auto t = tech; PItem elem = item.get(); return { item, elem->getName(), elem->getName(true), elem->getViewObject().id(), cost, elem->getDescription(), batchSize, work, tech, tutorialHighlight, elem->getAppliedUpgradeType(), elem->getMaxUpgrades() }; }
void Inventory::addItem(PItem item) { itemsCache.push_back(item.get()); items.push_back(move(item)); }
virtual void onInterceptFlyingItem(PItem it, const Attack& a, int remainingDist, Vec2 dir) { level->globalMessage(position, it->getTheName() + " disappears in the portal."); other->level->throwItem(std::move(it), a, remainingDist, other->position, dir); }