Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- service.h:
- add:
- #define __PET_PICKUP
- PetSystem.h:
- search:
- void SetSummonItem (LPITEM pItem);
- add below:
- #ifdef __PET_PICKUP
- void PickUpItems(int range);
- void BringItem();
- void SetPickup(bool is_pickup) { m_is_pickup = is_pickup; }
- bool IsPickup(){ return m_is_pickup; }
- void SetPickupItem(LPITEM item) { m_pickup_item = item; }
- LPITEM GetPickupItem(){ return m_pickup_item; }
- #endif
- search:
- LPCHARACTER m_pkOwner;
- add below:
- #ifdef __PET_PICKUP
- bool m_is_pickup;
- LPITEM m_pickup_item;
- #endif
- char.h:
- search:
- bool PickupItem(DWORD vid);
- add below:
- #ifdef __PET_PICKUP
- bool PickupItemByPet(DWORD vid);
- #endif
- char_item.cpp:
- search:
- bool CHARACTER::PickupItem(DWORD dwVID)
- add above:
- #ifdef __PET_PICKUP
- bool CHARACTER::PickupItemByPet(DWORD dwVID)
- {
- LPITEM item = ITEM_MANAGER::instance().FindByVID(dwVID);
- if (IsObserverMode())
- return false;
- if (!item || !item->GetSectree())
- return false;
- if (item->IsOwnership(this))
- {
- if (item->GetType() == ITEM_ELK)
- {
- GiveGold(item->GetCount());
- item->RemoveFromGround();
- M2_DESTROY_ITEM(item);
- Save();
- }
- else
- {
- if (item->IsStackable() && !IS_SET(item->GetAntiFlag(), ITEM_ANTIFLAG_STACK))
- {
- BYTE bCount = item->GetCount();
- for (int i = 0; i < INVENTORY_MAX_NUM; ++i)
- {
- LPITEM item2 = GetInventoryItem(i);
- if (!item2)
- continue;
- if (item2->GetVnum() == item->GetVnum())
- {
- int j;
- for (j = 0; j < ITEM_SOCKET_MAX_NUM; ++j)
- if (item2->GetSocket(j) != item->GetSocket(j))
- break;
- if (j != ITEM_SOCKET_MAX_NUM)
- continue;
- BYTE bCount2 = MIN(200 - item2->GetCount(), bCount);
- bCount -= bCount2;
- item2->SetCount(item2->GetCount() + bCount2);
- if (bCount == 0)
- {
- ChatPacket(CHAT_TYPE_INFO, LC_TEXT("¾ÆÀÌÅÛ È¹µæ: %s"), item2->GetName());
- M2_DESTROY_ITEM(item);
- if (item2->GetType() == ITEM_QUEST)
- quest::CQuestManager::instance().PickupItem(GetPlayerID(), item2);
- return true;
- }
- }
- }
- item->SetCount(bCount);
- }
- int iEmptyCell;
- if (item->IsDragonSoul())
- {
- if ((iEmptyCell = GetEmptyDragonSoulInventory(item)) == -1)
- {
- sys_log(0, "No empty ds inventory pid %u size
- itemid %u", GetPlayerID(), item->GetSize(), item->GetID());
- ChatPacket(CHAT_TYPE_INFO, LC_TEXT("¼ÒÁöÇÏ°í ÀÖ´Â ¾ÆÀÌÅÛÀÌ ³Ê¹« ¸¹½À´Ï´Ù."));
- return false;
- }
- }
- else
- {
- if ((iEmptyCell = GetEmptyInventory(item->GetSize())) == -1)
- {
- sys_log(0, "No empty inventory pid %u size
- itemid %u", GetPlayerID(), item->GetSize(), item->GetID());
- ChatPacket(CHAT_TYPE_INFO, LC_TEXT("¼ÒÁöÇÏ°í ÀÖ´Â ¾ÆÀÌÅÛÀÌ ³Ê¹« ¸¹½À´Ï´Ù."));
- return false;
- }
- }
- item->RemoveFromGround();
- if (item->IsDragonSoul())
- item->AddToCharacter(this, TItemPos(DRAGON_SOUL_INVENTORY, iEmptyCell));
- else
- item->AddToCharacter(this, TItemPos(INVENTORY, iEmptyCell));
- char szHint[32 + 1];
- snprintf(szHint, sizeof(szHint), "%s %u %u", item->GetName(), item->GetCount(), item->GetOriginalVnum());
- LogManager::instance().ItemLog(this, item, "GET", szHint);
- ChatPacket(CHAT_TYPE_INFO, LC_TEXT("¾ÆÀÌÅÛ È¹µæ: %s"), item->GetName());
- if (item->GetType() == ITEM_QUEST)
- quest::CQuestManager::instance().PickupItem(GetPlayerID(), item);
- }
- //Motion(MOTION_PICKUP);
- return true;
- }
- return false;
- }
- #endif
- PetSystem.cpp:
- search:
- bool CPetActor::Follow(float fMinDistance)
- add above:
- #ifdef __PET_PICKUP
- struct PetPickUpItemStruct
- {
- CPetActor * pet;
- int range;
- PetPickUpItemStruct(CPetActor * p, int r){
- pet = p;
- range = r;
- }
- void operator()(LPENTITY pEnt)
- {
- if (!pet->GetOwner() || !pet->GetCharacter())
- return;
- if (pet->IsPickup())
- return;
- if (pEnt->IsType(ENTITY_ITEM) == true)
- {
- LPITEM item = (LPITEM)pEnt;
- LPCHARACTER player = pet->GetOwner();
- if (!item->GetSectree() || !item->IsOwnership(player))
- return;
- int iDist = DISTANCE_APPROX(item->GetX() - player->GetX(), player->GetY() - player->GetY());
- if (iDist > range)
- return;
- pet->SetPickup(true);
- pet->SetPickupItem(item);
- }
- }
- };
- void CPetActor::PickUpItems(int range){
- if (IsPickup())
- return;
- long map = m_pkChar->GetMapIndex();
- PIXEL_POSITION m = m_pkChar->GetXYZ();
- LPSECTREE tree = SECTREE_MANAGER::instance().Get(map, m.x, m.y);
- if (!tree)
- {
- sys_err("cannot find sectree by %dx%d", m.x, m.y);
- return;
- }
- PetPickUpItemStruct f(this, range);
- tree->ForEachAround(f);
- }
- void CPetActor::BringItem(){
- if (!IsPickup())
- return;
- LPITEM item = GetPickupItem();
- if (!m_pkOwner || !m_pkChar || !item || !item->GetSectree())
- return;
- float fMinDistance = 20.0;
- float fPetX = m_pkChar->GetX();
- float fPetY = m_pkChar->GetY();
- float itemX = item->GetX();
- float itemY = item->GetY();
- float fDist = DISTANCE_SQRT(itemX - fPetX, itemY - fPetY);
- if (fDist <= 250.0)
- {
- SetPickup(false);
- m_pkOwner->PickupItemByPet(item->GetVID());
- SetPickupItem(NULL);
- m_pkChar->SendMovePacket(FUNC_WAIT, 0, 0, 0, 0, 0);
- return;
- }
- m_pkChar->SetRotationToXY(itemX, itemY);
- float fx, fy;
- float fDistToGo = fDist - fMinDistance;
- GetDeltaByDegree(m_pkChar->GetRotation(), fDistToGo, &fx, &fy);
- if (!m_pkChar->Goto((int)(fPetX + fx + 0.5f), (int)(fPetY + fy + 0.5f)))
- return;
- m_pkChar->SendMovePacket(FUNC_WAIT, 0, 0, 0, 0, 0);
- }
- #endif
- search:
- if (this->IsSummoned() && HasOption(EPetOption_Followable))
- add above:
- #ifdef __PET_PICKUP
- if (this->IsSummoned()){
- this->BringItem();
- this->PickUpItems(900); // 900 = RANGE
- }
- #endif
- search:
- this->SetSummonItem(NULL);
- add below:
- #ifdef __PET_PICKUP
- this->SetPickupItem(NULL);
- this->SetPickup(false);
- #endif
- search:
- m_dwSummonItemVID = 0;
- m_dwSummonItemVnum = 0;
- add below:
- #ifdef __PET_PICKUP
- this->SetPickupItem(NULL);
- this->SetPickup(false);
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement