void CHARACTER::AutoGiveItem(LPITEM item, bool longOwnerShip) { if (NULL == item) { sys_err("NULL point."); return; } if (item->GetOwner()) { sys_err("item %d 's owner exists!", item->GetID()); return; } int cell; if (item->IsDragonSoul()) cell = GetEmptyDragonSoulInventory(item); #ifdef ENABLE_SPECIAL_STORAGE else if (item->IsUpgradeItem()) cell = GetEmptyUpgradeInventory(item); else if (item->IsBook()) cell = GetEmptyBookInventory(item); else if (item->IsStone()) cell = GetEmptyStoneInventory(item); else if (item->IsFlower()) cell = GetEmptyFlowerInventory(item); else if (item->IsAttrItem()) cell = GetEmptyAttrInventory(item); else if (item->IsChest()) cell = GetEmptyChestInventory(item); #endif else cell = GetEmptyInventory(item->GetSize()); if (cell != -1) { if (item->IsDragonSoul()) item->AddToCharacter(this, TItemPos(DRAGON_SOUL_INVENTORY, cell)); #ifdef ENABLE_SPECIAL_STORAGE else if (item->IsUpgradeItem()) item->AddToCharacter(this, TItemPos(UPGRADE_INVENTORY, cell)); else if (item->IsBook()) item->AddToCharacter(this, TItemPos(BOOK_INVENTORY, cell)); else if (item->IsStone()) item->AddToCharacter(this, TItemPos(STONE_INVENTORY, cell)); else if (item->IsFlower()) item->AddToCharacter(this, TItemPos(FLOWER_INVENTORY, cell)); else if (item->IsAttrItem()) item->AddToCharacter(this, TItemPos(ATTR_INVENTORY, cell)); else if (item->IsChest()) item->AddToCharacter(this, TItemPos(CHEST_INVENTORY, cell)); #endif else item->AddToCharacter(this, TItemPos(INVENTORY, cell)); LogManager::instance().ItemLog(this, item, "SYSTEM", item->GetName()); if (item->GetType() == ITEM_USE && item->GetSubType() == USE_POTION) { TQuickslot* pSlot; if (GetQuickslot(0, &pSlot) && pSlot->type == QUICKSLOT_TYPE_NONE) { TQuickslot slot; slot.type = QUICKSLOT_TYPE_ITEM; slot.pos = cell; SetQuickslot(0, slot); } } } else { item->AddToGround(GetMapIndex(), GetXYZ()); #ifdef ENABLE_NEWSTUFF item->StartDestroyEvent(g_aiItemDestroyTime[ITEM_DESTROY_TIME_AUTOGIVE]); #else item->StartDestroyEvent(); #endif if (longOwnerShip) item->SetOwnership(this, 300); else item->SetOwnership(this, 60); LogManager::instance().ItemLog(this, item, "SYSTEM_DROP", item->GetName()); } } LPITEM CHARACTER::AutoGiveItem(DWORD dwItemVnum, BYTE bCount, int iRarePct, bool bMsg) { TItemTable* p = ITEM_MANAGER::instance().GetTable(dwItemVnum); if (!p) return NULL; #ifdef ENABLE_AUTOGIVEITEM_CELL_CHECK LPITEM itemCheck = ITEM_MANAGER::instance().CreateItem(dwItemVnum, bCount, 0, true, -1, true); if (itemCheck) { int iEmptyCell = -1; if (p->bType == ITEM_DS) iEmptyCell = GetEmptyDragonSoulInventory(itemCheck); #ifdef ENABLE_SPECIAL_STORAGE else if (IsUpgradeItem(dwItemVnum)) iEmptyCell = GetEmptyUpgradeInventory(itemCheck); else if (IsStoneSpecial(dwItemVnum, p->bType)) iEmptyCell = GetEmptyStoneInventory(itemCheck); else if (ITEM_SKILLBOOK == p->bType) iEmptyCell = GetEmptyBookInventory(itemCheck); else if (IsFlowerItem(dwItemVnum)) iEmptyCell = GetEmptyFlowerInventory(itemCheck); else if (IsAttrSpecial(dwItemVnum)) iEmptyCell = GetEmptyAttrInventory(itemCheck); else if (IsChestItem(dwItemVnum)) iEmptyCell = GetEmptyChestInventory(itemCheck); #endif else iEmptyCell = GetEmptyInventory(p->bSize); if (iEmptyCell == -1) { if (bMsg) ChatPacket(CHAT_TYPE_INFO, LC_TEXT("Envanterinde yer yok autogiveitem!")); return NULL; } } #endif DBManager::instance().SendMoneyLog(MONEY_LOG_DROP, dwItemVnum, bCount); if (p->dwFlags & ITEM_FLAG_STACKABLE && p->bType != ITEM_BLEND) { #ifdef ENABLE_SPECIAL_STORAGE if (IsUpgradeItem(dwItemVnum)) //upgrade item { for (int i = 0; i < SPECIAL_INVENTORY_MAX_NUM; ++i) { LPITEM item = GetUpgradeInventoryItem(i); if (!item) continue; if (item->GetVnum() == dwItemVnum && FN_check_item_socket(item)) { if (IS_SET(p->dwFlags, ITEM_FLAG_MAKECOUNT)) { if (bCount < p->alValues[1]) bCount = p->alValues[1]; } BYTE bCount2 = MIN(g_bItemCountLimit - item->GetCount(), bCount); bCount -= bCount2; if (bCount2 > 0) item->SetCount(item->GetCount() + bCount2); if (bCount == 0) { if (bMsg) ChatPacket(CHAT_TYPE_INFO, LC_TEXT("lCRELU Caµc: %s"), item->GetName()); return item; } } } } else if (IsStoneSpecial(dwItemVnum, p->bType)) //stone item { for (int i = 0; i < SPECIAL_INVENTORY_MAX_NUM; ++i) { LPITEM item = GetStoneInventoryItem(i); if (!item) continue; if (item->GetVnum() == dwItemVnum && FN_check_item_socket(item)) { if (IS_SET(p->dwFlags, ITEM_FLAG_MAKECOUNT)) { if (bCount < p->alValues[1]) bCount = p->alValues[1]; } BYTE bCount2 = MIN(g_bItemCountLimit - item->GetCount(), bCount); bCount -= bCount2; if (bCount2 > 0) item->SetCount(item->GetCount() + bCount2); if (bCount == 0) { if (bMsg) ChatPacket(CHAT_TYPE_INFO, LC_TEXT("lCRELU Caµc: %s"), item->GetName()); return item; } } } } else if (IsFlowerItem(dwItemVnum)) //flower item { for (int i = 0; i < SPECIAL_INVENTORY_MAX_NUM; ++i) { LPITEM item = GetFlowerInventoryItem(i); if (!item) continue; if (item->GetVnum() == dwItemVnum && FN_check_item_socket(item)) { if (IS_SET(p->dwFlags, ITEM_FLAG_MAKECOUNT)) { if (bCount < p->alValues[1]) bCount = p->alValues[1]; } BYTE bCount2 = MIN(g_bItemCountLimit - item->GetCount(), bCount); bCount -= bCount2; if (bCount2 > 0) item->SetCount(item->GetCount() + bCount2); if (bCount == 0) { if (bMsg) ChatPacket(CHAT_TYPE_INFO, LC_TEXT("lCRELU Caµc: %s"), item->GetName()); return item; } } } } else if (IsAttrSpecial(dwItemVnum)) //attr item { for (int i = 0; i < SPECIAL_INVENTORY_MAX_NUM; ++i) { LPITEM item = GetAttrInventoryItem(i); if (!item) continue; if (item->GetVnum() == dwItemVnum && FN_check_item_socket(item)) { if (IS_SET(p->dwFlags, ITEM_FLAG_MAKECOUNT)) { if (bCount < p->alValues[1]) bCount = p->alValues[1]; } BYTE bCount2 = MIN(g_bItemCountLimit - item->GetCount(), bCount); bCount -= bCount2; if (bCount2 > 0) item->SetCount(item->GetCount() + bCount2); if (bCount == 0) { if (bMsg) ChatPacket(CHAT_TYPE_INFO, LC_TEXT("lCRELU Caµc: %s"), item->GetName()); return item; } } } } else if (IsChestItem(dwItemVnum)) //chest item { for (int i = 0; i < SPECIAL_INVENTORY_MAX_NUM; ++i) { LPITEM item = GetChestInventoryItem(i); if (!item) continue; if (item->GetVnum() == dwItemVnum && FN_check_item_socket(item)) { if (IS_SET(p->dwFlags, ITEM_FLAG_MAKECOUNT)) { if (bCount < p->alValues[1]) bCount = p->alValues[1]; } BYTE bCount2 = MIN(g_bItemCountLimit - item->GetCount(), bCount); bCount -= bCount2; if (bCount2 > 0) item->SetCount(item->GetCount() + bCount2); if (bCount == 0) { if (bMsg) ChatPacket(CHAT_TYPE_INFO, LC_TEXT("lCRELU Caµc: %s"), item->GetName()); return item; } } } } else { for (int i = 0; i < INVENTORY_MAX_NUM; ++i) { LPITEM item = GetInventoryItem(i); if (!item) continue; if (item->GetVnum() == dwItemVnum && FN_check_item_socket(item)) { if (IS_SET(p->dwFlags, ITEM_FLAG_MAKECOUNT)) { if (bCount < p->alValues[1]) bCount = p->alValues[1]; } BYTE bCount2 = MIN(g_bItemCountLimit - item->GetCount(), bCount); bCount -= bCount2; if (bCount2 > 0) item->SetCount(item->GetCount() + bCount2); if (bCount == 0) { if (bMsg) ChatPacket(CHAT_TYPE_INFO, LC_TEXT("¾ÆÀÌÅÛ È¹µæ: %s"), item->GetName()); return item; } } } } #else for (int i = 0; i < INVENTORY_MAX_NUM; ++i) { LPITEM item = GetInventoryItem(i); if (!item) continue; if (item->GetVnum() == dwItemVnum && FN_check_item_socket(item)) { if (IS_SET(p->dwFlags, ITEM_FLAG_MAKECOUNT)) { if (bCount < p->alValues[1]) bCount = p->alValues[1]; } BYTE bCount2 = MIN(g_bItemCountLimit - item->GetCount(), bCount); bCount -= bCount2; if (bCount2 > 0) item->SetCount(item->GetCount() + bCount2); if (bCount == 0) { if (bMsg) ChatPacket(CHAT_TYPE_INFO, LC_TEXT("¾ÆÀÌÅÛ È¹µæ: %s"), item->GetName()); return item; } } } #endif } LPITEM item = ITEM_MANAGER::instance().CreateItem(dwItemVnum, bCount, 0, true); if (!item) { sys_err("cannot create item by vnum %u (name: %s)", dwItemVnum, GetName()); return NULL; } #ifdef ENABLE_SPECIAL_STORAGE if (item->IsBook()) { for (int i = 0; i < SPECIAL_INVENTORY_MAX_NUM; ++i) { LPITEM book = GetBookInventoryItem(i); if (!book) continue; if (book->GetVnum() == dwItemVnum && book->GetSocket(0) == item->GetSocket(0)) { if (IS_SET(p->dwFlags, ITEM_FLAG_MAKECOUNT)) { if (bCount < p->alValues[1]) bCount = p->alValues[1]; } BYTE bCount2 = MIN(g_bItemCountLimit - book->GetCount(), bCount); bCount -= bCount2; if (bCount2 > 0) book->SetCount(book->GetCount() + bCount2); if (bCount == 0) { if (bMsg) ChatPacket(CHAT_TYPE_INFO, LC_TEXT("lCRELU Caµc: %s"), book->GetName()); M2_DESTROY_ITEM(item); return book; } } } } #endif if (item->GetType() == ITEM_BLEND) { for (int i = 0; i < INVENTORY_MAX_NUM; i++) { LPITEM inv_item = GetInventoryItem(i); if (inv_item == NULL) continue; if (inv_item->GetType() == ITEM_BLEND) { if (inv_item->GetVnum() == item->GetVnum()) { if (inv_item->GetSocket(0) == item->GetSocket(0) && inv_item->GetSocket(1) == item->GetSocket(1) && inv_item->GetSocket(2) == item->GetSocket(2) && inv_item->GetCount() < g_bItemCountLimit) { inv_item->SetCount(inv_item->GetCount() + item->GetCount()); M2_DESTROY_ITEM(item);// @fixme173 return inv_item; } } } } } int iEmptyCell; if (item->IsDragonSoul()) iEmptyCell = GetEmptyDragonSoulInventory(item); #ifdef ENABLE_SPECIAL_STORAGE else if (item->IsUpgradeItem()) iEmptyCell = GetEmptyUpgradeInventory(item); else if (item->IsBook()) iEmptyCell = GetEmptyBookInventory(item); else if (item->IsStone()) iEmptyCell = GetEmptyStoneInventory(item); else if (item->IsFlower()) iEmptyCell = GetEmptyFlowerInventory(item); else if (item->IsAttrItem()) iEmptyCell = GetEmptyAttrInventory(item); else if (item->IsChest()) iEmptyCell = GetEmptyChestInventory(item); #endif else iEmptyCell = GetEmptyInventory(item->GetSize()); if (iEmptyCell != -1) { if (bMsg) ChatPacket(CHAT_TYPE_INFO, LC_TEXT("¾ÆÀÌÅÛ È¹µæ: %s"), item->GetName()); if (item->IsDragonSoul()) item->AddToCharacter(this, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyCell)); #ifdef ENABLE_SPECIAL_STORAGE else if (item->IsUpgradeItem()) item->AddToCharacter(this, TItemPos(UPGRADE_INVENTORY, iEmptyCell)); else if (item->IsBook()) item->AddToCharacter(this, TItemPos(BOOK_INVENTORY, iEmptyCell)); else if (item->IsStone()) item->AddToCharacter(this, TItemPos(STONE_INVENTORY, iEmptyCell)); else if (item->IsFlower()) item->AddToCharacter(this, TItemPos(FLOWER_INVENTORY, iEmptyCell)); else if (item->IsAttrItem()) item->AddToCharacter(this, TItemPos(ATTR_INVENTORY, iEmptyCell)); else if (item->IsChest()) item->AddToCharacter(this, TItemPos(CHEST_INVENTORY, iEmptyCell)); #endif else item->AddToCharacter(this, TItemPos(INVENTORY, iEmptyCell)); LogManager::instance().ItemLog(this, item, "SYSTEM", item->GetName()); if (item->GetType() == ITEM_USE && item->GetSubType() == USE_POTION) { TQuickslot* pSlot; if (GetQuickslot(0, &pSlot) && pSlot->type == QUICKSLOT_TYPE_NONE) { TQuickslot slot; slot.type = QUICKSLOT_TYPE_ITEM; slot.pos = iEmptyCell; SetQuickslot(0, slot); } } } else { item->AddToGround(GetMapIndex(), GetXYZ()); #ifdef ENABLE_NEWSTUFF item->StartDestroyEvent(g_aiItemDestroyTime[ITEM_DESTROY_TIME_AUTOGIVE]); #else item->StartDestroyEvent(); #endif if (IS_SET(item->GetAntiFlag(), ITEM_ANTIFLAG_DROP)) item->SetOwnership(this, 300); else item->SetOwnership(this, 60); LogManager::instance().ItemLog(this, item, "SYSTEM_DROP", item->GetName()); } sys_log(0, "7: %d %d", dwItemVnum, bCount); return item; }