void Node::pyHandleCustomCtorArgs(py::tuple& args, py::dict& kw){ if(py::len(args)>0){ if(py::len(args)>2) throw std::runtime_error("Node: only takes 0, 1 or 2 non-keyword arguments ("+to_string(py::len(args))+" given)."); py::extract<Vector3r> posEx(args[0]); if(!posEx.check()) woo::TypeError("Node: first non-keyword argument must be Vector3 (pos)"); pos=posEx(); if(py::len(args)==2){ py::extract<Quaternionr> oriEx(args[1]); if(!oriEx.check()) woo::TypeError("Node: second non-keyword argument must be Quaternion (ori)"); ori=oriEx(); } args=py::tuple(); // clear args } for(const char* name:{"dem","gl","sparc","clDem"}){ if(!kw.has_key(name)) continue; auto& d=py::extract<shared_ptr<NodeData>>(kw[name])(); if(d->getterName()!=string(name)) throw std::runtime_error("Node: mismatch passing "+string(name)+"="+d->pyStr()+": shorthand for this type should be "+d->getterName()+" (not "+string(name)+")."); d->setDataOnNode(*this); py::api::delitem(kw,name); } }
ReturnValue Actions::internalUseItem(Player* player, const Position& pos, uint8_t index, Item* item, bool isHotkey) { if (Door* door = item->getDoor()) { if (!door->canUse(player)) { return RETURNVALUE_CANNOTUSETHISOBJECT; } } Action* action = getAction(item); if (action) { int32_t stack = item->getParent()->__getIndexOfThing(item); PositionEx posEx(pos, stack); if (action->isScripted()) { if (action->executeUse(player, item, posEx, posEx, false, 0, isHotkey)) { return RETURNVALUE_NOERROR; } } else if (action->function) { if (action->function(player, item, posEx, posEx, false, isHotkey)) { return RETURNVALUE_NOERROR; } } } if (BedItem* bed = item->getBed()) { if (!bed->canUse(player)) { return RETURNVALUE_CANNOTUSETHISOBJECT; } if (bed->trySleep(player)) { player->setBedItem(bed); g_game.sendOfflineTrainingDialog(player); } return RETURNVALUE_NOERROR; } if (Container* container = item->getContainer()) { Container* openContainer; //depot container if (DepotLocker* depot = container->getDepotLocker()) { DepotLocker* myDepotLocker = player->getDepotLocker(depot->getDepotId()); myDepotLocker->setParent(depot->getParent()->getTile()); openContainer = myDepotLocker; player->setLastDepotId(depot->getDepotId()); } else { openContainer = container; } uint32_t corpseOwner = container->getCorpseOwner(); if (corpseOwner != 0 && !player->canOpenCorpse(corpseOwner)) { return RETURNVALUE_YOUARENOTTHEOWNER; } //open/close container int32_t oldContainerId = player->getContainerID(openContainer); if (oldContainerId != -1) { player->onCloseContainer(openContainer); player->closeContainer(oldContainerId); } else { player->addContainer(index, openContainer); player->onSendContainer(openContainer); } return RETURNVALUE_NOERROR; } if (item->isReadable()) { if (item->canWriteText()) { player->setWriteItem(item, item->getMaxWriteLength()); player->sendTextWindow(item, item->getMaxWriteLength(), true); } else { player->setWriteItem(nullptr); player->sendTextWindow(item, 0, false); } return RETURNVALUE_NOERROR; } return RETURNVALUE_CANNOTUSETHISOBJECT; }
bool Actions::UseItem(Player* player, const Position &pos,const unsigned char stack, const unsigned short itemid, const unsigned char index) { if(canUse(player,pos)== TOO_FAR){ player->sendCancel("Too far away."); return false; } Item *item = dynamic_cast<Item*>(game->getThing(pos,stack,player)); if(!item){ #ifdef __DEBUG__ std::cout << "no item" << std::endl; #endif player->sendCancel("You can not use this object."); return false; } if(item->getID() != itemid){ #ifdef __DEBUG__ std::cout << "no id" << std::endl; #endif player->sendCancel("You can not use this object."); return false; } #ifdef TLM_HOUSE_SYSTEM if (Item::items[itemid].isDoor) { Tile* tile = game->getTile(pos); House* house = tile? tile->getHouse() : NULL; if (house && player->access < g_config.ACCESS_HOUSE && house->getPlayerRights(pos, player->getName()) <= HOUSE_GUEST) { player->sendCancel("You are not allowed to open this door."); return false; } } #endif //TLM_HOUSE_SYSTEM //look for the item in action maps Action *action = getAction(item); //if found execute it if(action){ Position itempos = game->getThingMapPos(player, pos); game->autoCloseTrade(item); PositionEx posEx(pos,stack); if(action->executeUse(player,item,posEx,posEx)){ return true; } } //if it is a container try to open it if(dynamic_cast<Container*>(item)){ if(openContainer(player,dynamic_cast<Container*>(item),index)) return true; } //we dont know what to do with this item player->sendCancel("You can not use this object."); return false; }