bool InventoryItem::Merge(InventoryItemRef to_merge, int32 qty, bool notify) { if(typeID() != to_merge->typeID()) { _log(ITEM__ERROR, "%s (%u): Asked to merge with %s (%u).", itemName().c_str(), itemID(), to_merge->itemName().c_str(), to_merge->itemID()); return false; } if(locationID() != to_merge->locationID() || flag() != to_merge->flag()) { _log(ITEM__ERROR, "%s (%u) in location %u, flag %u: Asked to merge with item %u in location %u, flag %u.", itemName().c_str(), itemID(), locationID(), flag(), to_merge->itemID(), to_merge->locationID(), to_merge->flag()); return false; } if(qty == 0) qty = to_merge->quantity(); if(qty <= 0) { _log(ITEM__ERROR, "%s (%u): Asked to merge with %d units of item %u.", itemName().c_str(), itemID(), qty, to_merge->itemID()); return false; } if(!AlterQuantity(qty, notify)) { _log(ITEM__ERROR, "%s (%u): Failed to add quantity %d.", itemName().c_str(), itemID(), qty); return false; } if(qty == to_merge->quantity()) { to_merge->Delete(); } else if(!to_merge->AlterQuantity(-qty, notify)) { _log(ITEM__ERROR, "%s (%u): Failed to remove quantity %d.", to_merge->itemName().c_str(), to_merge->itemID(), qty); return false; } return true; }
void InventoryItem::Move(uint32 new_location, EVEItemFlags new_flag, bool notify) { uint32 old_location = locationID(); EVEItemFlags old_flag = flag(); if( new_location == old_location && new_flag == old_flag ) return; //nothing to do... //first, take myself out of my old inventory, if its loaded. Inventory *old_inventory = m_factory.GetInventory( old_location, false ); if(old_inventory != NULL) old_inventory->RemoveItem( InventoryItemRef( this ) ); //releases its ref m_locationID = new_location; m_flag = new_flag; //then make sure that my new inventory is updated, if its loaded. Inventory *new_inventory = m_factory.GetInventory( new_location, false ); if( new_inventory != NULL ) new_inventory->AddItem( InventoryItemRef( this ) ); //makes a new ref SaveItem(); //notify about the changes. if( notify ) { std::map<int32, PyRep *> changes; if( new_location != old_location ) changes[ixLocationID] = new PyInt(old_location); if( new_flag != old_flag ) changes[ixFlag] = new PyInt(old_flag); SendItemChange( ownerID(), changes ); //changes is consumed } }
bool InventoryItem::Populate( Rsp_CommonGetInfo_Entry& result ) { //itemID: result.itemID = itemID(); //invItem: PySafeDecRef( result.invItem ); result.invItem = GetItemRow(); //hacky, but it doesn't really hurt anything. if( GetAttribute(AttrIsOnline).get_int() != 0 ) { //there is an effect that goes along with this. We should //probably be properly tracking the effect due to some // timer things, but for now, were hacking it. EntityEffectState es; es.env_itemID = itemID(); es.env_charID = ownerID(); //may not be quite right... es.env_shipID = locationID(); es.env_target = locationID(); //this is what they do. es.env_other = new PyNone; es.env_effectID = effectOnline; es.startTime = Win32TimeNow() - Win32Time_Hour; //act like it happened an hour ago es.duration = INT_MAX; es.repeat = 0; es.randomSeed = new PyNone; result.activeEffects[es.env_effectID] = es.Encode(); } //activeEffects: //result..activeEffects[id] = List[11]; //attributes: AttributeMap::AttrMapItr itr = mAttributeMap.begin(); AttributeMap::AttrMapItr itr_end = mAttributeMap.end(); for (; itr != itr_end; itr++) { result.attributes[(*itr).first] = (*itr).second.GetPyObject(); } //no idea what time this is supposed to be result.time = Win32TimeNow(); return true; }
bool InventoryItem::_Load() { // load attributes mAttributeMap.Load(); // update inventory Inventory *inventory = m_factory.GetInventory( locationID(), false ); if( inventory != NULL ) inventory->AddItem( InventoryItemRef( this ) ); return true; }
InventoryItemRef InventoryItem::Split(int32 qty_to_take, bool notify) { if(qty_to_take <= 0) { _log(ITEM__ERROR, "%s (%u): Asked to split into a chunk of %d", itemName().c_str(), itemID(), qty_to_take); return InventoryItemRef(); } if(!AlterQuantity(-qty_to_take, notify)) { _log(ITEM__ERROR, "%s (%u): Failed to remove quantity %d during split.", itemName().c_str(), itemID(), qty_to_take); return InventoryItemRef(); } ItemData idata( typeID(), ownerID(), (notify ? 1 : locationID()), //temp location to cause the spawn via update flag(), qty_to_take ); InventoryItemRef res = m_factory.SpawnItem(idata); if(notify) res->Move( locationID(), flag() ); return( res ); }
void InventoryItem::GetItemRow( PyPackedRow* into ) const { into->SetField( "itemID", new PyLong( itemID() ) ); into->SetField( "typeID", new PyInt( typeID() ) ); into->SetField( "ownerID", new PyInt( ownerID() ) ); into->SetField( "locationID", new PyLong( locationID() ) ); into->SetField( "flagID", new PyInt( flag() ) ); into->SetField( "quantity", new PyInt( singleton() ? -1 : quantity()) ); into->SetField( "groupID", new PyInt( groupID() ) ); into->SetField( "categoryID", new PyInt( categoryID() ) ); into->SetField( "customInfo", new PyString( customInfo() ) ); //into->SetField( "singleton", new PyBool( singleton() ) ); //into->SetField( "stacksize", new PyInt (quantity()) ); }
void InventoryItem::SaveItem() { //_log( ITEM__TRACE, "Saving item %u.", itemID() ); SaveAttributes(); m_factory.db().SaveItem( itemID(), ItemData( itemName().c_str(), typeID(), ownerID(), locationID(), flag(), contraband(), singleton(), quantity(), position(), customInfo().c_str() ) ); }