xKrazyx
Old School
- Joined
- Oct 23, 2012
- Messages
- 899
- Solutions
- 6
- Reaction score
- 677
Trying to replicate the 7.4 stack block for parcel and boxes but cant seem to find the code.. anyone know where that might be located in the old otserv distros? otserv.cpp??
EDIT: ive been searching.. is this it????
Heres some other code..
EDIT: ive been searching.. is this it????
Code:
void Game::internalGetPosition(Item* item, Position& pos, uint8_t& stackpos)
{
pos.x = 0;
pos.y = 0;
pos.z = 0;
stackpos = 0;
Cylinder* topParent = item->getTopParent();
if(topParent){
if(Player* player = dynamic_cast<Player*>(topParent)){
pos.x = 0xFFFF;
Container* container = dynamic_cast<Container*>(item->getParent());
if(container){
pos.y = ((uint16_t) ((uint16_t)0x40) | ((uint16_t)player->getContainerID(container)) );
pos.z = container->__getIndexOfThing(item);
stackpos = pos.z;
}
else{
pos.y = player->__getIndexOfThing(item);
stackpos = pos.y;
}
}
else if(Tile* tile = topParent->getTile()){
pos = tile->getPosition();
stackpos = tile->__getIndexOfThing(item);
}
}
}
Heres some other code..
Code:
Cylinder* Game::internalGetCylinder(Player* player, const Position& pos)
{
if(pos.x != 0xFFFF){
return getTile(pos.x, pos.y, pos.z);
}
else{
//container
if(pos.y & 0x40){
uint8_t from_cid = pos.y & 0x0F;
return player->getContainer(from_cid);
}
//inventory
else{
return player;
}
}
}
Thing* Game::internalGetThing(Player* player, const Position& pos, int32_t index,
uint32_t spriteId /*= 0*/, stackPosType_t type /*= STACKPOS_NORMAL*/)
{
if(pos.x != 0xFFFF){
Tile* tile = getTile(pos.x, pos.y, pos.z);
if(tile){
/*look at*/
if(type == STACKPOS_LOOK){
return tile->getTopVisibleThing(player);
}
Thing* thing = NULL;
/*for move operations*/
if(type == STACKPOS_MOVE){
Item* item = tile->getTopDownItem();
if(item && !item->isNotMoveable())
thing = item;
else
thing = tile->getTopVisibleCreature(player);
}
/*use item*/
else if(type == STACKPOS_USE){
thing = tile->getTopDownItem();
}
else if(type == STACKPOS_USEITEM){
//the first down item is usually the right item unless there is topOrder items with scripts
Item* downItem = tile->getTopDownItem();
//check items with topOrder 2 (ladders, signs, splashes)
Item* topOrderItem = tile->getItemByTopOrder(2);
if(topOrderItem && g_actions->hasAction(topOrderItem) ){
const ItemType& it = Item::items[topOrderItem->getID()];
//if the top order item has a height or allows pickupable items we use the first down item instead
if(!(downItem && (it.hasHeight || it.allowPickupable))){
thing = topOrderItem;
}
}
if(thing == NULL){
//first down item
thing = downItem;
}
if(thing == NULL){
//then items with topOrder 3 (doors etc)
thing = tile->getTopTopItem();
}
if(thing == NULL){
//and finally the ground
thing = tile->ground;
}
}
else{
thing = tile->__getThing(index);
}
if(player){
//do extra checks here if the thing is accessable
if(thing && thing->getItem()){
if(tile->hasProperty(ISVERTICAL)){
if(player->getPosition().x + 1 == tile->getPosition().x){
thing = NULL;
}
}
else if(tile->hasProperty(ISHORIZONTAL)){
if(player->getPosition().y + 1 == tile->getPosition().y){
thing = NULL;
}
}
}
}
return thing;
}
}
else{
//container
if(pos.y & 0x40){
uint8_t fromCid = pos.y & 0x0F;
uint8_t slot = pos.z;
Container* parentcontainer = player->getContainer(fromCid);
if(!parentcontainer)
return NULL;
return parentcontainer->getItem(slot);
}
else if(pos.y == 0 && pos.z == 0){
const ItemType& it = Item::items.getItemIdByClientId(spriteId);
if(it.id == 0){
return NULL;
}
int32_t subType = -1;
if(it.isFluidContainer()){
subType = index;
}
return findItemOfType(player, it.id, true, subType);
}
//inventory
else{
slots_t slot = (slots_t)static_cast<unsigned char>(pos.y);
return player->getInventoryItem(slot);
}
}
return NULL;
}
void Game::internalGetPosition(Item* item, Position& pos, uint8_t& stackpos)
{
pos.x = 0;
pos.y = 0;
pos.z = 0;
stackpos = 0;
Cylinder* topParent = item->getTopParent();
if(topParent){
if(Player* player = dynamic_cast<Player*>(topParent)){
pos.x = 0xFFFF;
Container* container = dynamic_cast<Container*>(item->getParent());
if(container){
pos.y = ((uint16_t) ((uint16_t)0x40) | ((uint16_t)player->getContainerID(container)) );
pos.z = container->__getIndexOfThing(item);
stackpos = pos.z;
}
else{
pos.y = player->__getIndexOfThing(item);
stackpos = pos.y;
}
}
else if(Tile* tile = topParent->getTile()){
pos = tile->getPosition();
stackpos = tile->__getIndexOfThing(item);
}
}
}
Last edited: