Advertisement
Guest User

Game::internalGetThing

a guest
May 20th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.79 KB | None | 0 0
  1. Thing* Game::internalGetThing(Player* player, const Position& pos, int32_t index,
  2.     uint32_t spriteId /*= 0*/, stackPosType_t type /*= STACKPOS_NORMAL*/)
  3. {
  4.     if(pos.x != 0xFFFF){
  5.         Tile* tile = getTile(pos.x, pos.y, pos.z);
  6.  
  7.         if(tile){
  8.             /*look at*/
  9.             if(type == STACKPOS_LOOK){
  10.                 return tile->getTopVisibleThing(player);
  11.             }
  12.  
  13.             Thing* thing = NULL;
  14.  
  15.             /*for move operations*/
  16.             if(type == STACKPOS_MOVE){
  17.                 Item* item = tile->getTopDownItem();
  18.                 if(item && !item->isNotMoveable())
  19.                     thing = item;
  20.                 else
  21.                     thing = tile->getTopVisibleCreature(player);
  22.             }
  23.             /*use item*/
  24.             else if(type == STACKPOS_USE){
  25.                 thing = tile->getTopDownItem();
  26.             }
  27.             else if(type == STACKPOS_USEITEM){
  28.                 //the first down item is usually the right item unless there is topOrder items with scripts
  29.                 Item* downItem = tile->getTopDownItem();
  30.  
  31.                 //check items with topOrder 2 (ladders, signs, splashes)
  32.                 Item* topOrderItem =  tile->getItemByTopOrder(2);
  33.                 if(topOrderItem && g_actions->hasAction(topOrderItem) ){
  34.                     const ItemType& it = Item::items[topOrderItem->getID()];
  35.                     //if the top order item has a height or allows pickupable items we use the first down item instead
  36.                     if(!(downItem && (it.hasHeight || it.allowPickupable))){
  37.                         thing = topOrderItem;
  38.                     }
  39.                 }
  40.  
  41.                 if(thing == NULL){
  42.                     //first down item
  43.                     thing = downItem;
  44.                 }
  45.  
  46.                 if(thing == NULL){
  47.                     //then items with topOrder 3 (doors etc)
  48.                     thing = tile->getTopTopItem();
  49.                 }
  50.  
  51.                 if(thing == NULL){
  52.                     //and finally the ground
  53.                     thing = tile->ground;
  54.                 }
  55.             }
  56.             else{
  57.                 thing = tile->__getThing(index);
  58.             }
  59.  
  60.             if(player){
  61.                 //do extra checks here if the thing is accessable
  62.                 if(thing && thing->getItem()){
  63.                     if(tile->hasProperty(ISVERTICAL)){
  64.                         if(player->getPosition().x + 1 == tile->getPosition().x){
  65.                             thing = NULL;
  66.                         }
  67.                     }
  68.                     else if(tile->hasProperty(ISHORIZONTAL)){
  69.                         if(player->getPosition().y + 1 == tile->getPosition().y){
  70.                             thing = NULL;
  71.                         }
  72.                     }
  73.                 }
  74.             }
  75.  
  76.             return thing;
  77.         }
  78.     }
  79.     else{
  80.         //container
  81.         if(pos.y & 0x40){
  82.             uint8_t fromCid = pos.y & 0x0F;
  83.             uint8_t slot = pos.z;
  84.  
  85.             Container* parentcontainer = player->getContainer(fromCid);
  86.             if(!parentcontainer)
  87.                 return NULL;
  88.  
  89.             return parentcontainer->getItem(slot);
  90.         }
  91.         else if(pos.y == 0 && pos.z == 0){
  92.             const ItemType& it = Item::items.getItemIdByClientId(spriteId);
  93.             if(it.id == 0){
  94.                 return NULL;
  95.             }
  96.  
  97.             int32_t subType = -1;
  98.             if(it.isFluidContainer()){
  99.                 subType = index;
  100.             }
  101.  
  102.             return findItemOfType(player, it.id, true, subType);
  103.         }
  104.         //inventory
  105.         else{
  106.             slots_t slot = (slots_t)static_cast<unsigned char>(pos.y);
  107.             return player->getInventoryItem(slot);
  108.         }
  109.     }
  110.  
  111.     return NULL;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement