Exemplo n.º 1
0
bool Actions::UseItemEx(Player* player, const Position &from_pos,
	const unsigned char from_stack,const Position &to_pos,
	const unsigned char to_stack,const unsigned short itemid)
{
	if(canUse(player,from_pos) == TOO_FAR){
		player->sendCancel("Too far away.");
		return false;
	}

	Item *item = dynamic_cast<Item*>(game->getThing(from_pos,from_stack,player));
	if(!item)
		return false;

	if(item->getID() != itemid)
		return false;

	if(!item->isUseable())
		return false;

	Action *action = getAction(item);

	if(action){
		if(action->allowFarUse() == false){
			if(canUse(player,to_pos) == TOO_FAR){
				player->sendCancel("Too far away.");
				return false;
			}
		}
		else if(canUseFar(player, to_pos, action->blockWalls()) == TOO_FAR){
			player->sendCancel("Too far away.");
			return false;
		}
		else if(canUseFar(player, to_pos, action->blockWalls()) == CAN_NOT_THTOW){
			player->sendCancel("You cannot throw there.");
			return false;
		}

		Position itempos = game->getThingMapPos(player, from_pos);
		game->autoCloseTrade(item);
		PositionEx posFromEx(from_pos,from_stack);
		PositionEx posToEx(to_pos,to_stack);
    	if(action->executeUse(player,item,posFromEx,posToEx))
    		return true;
	}

	//not found
	player->sendCancel("You can not use this object.");
	return false;
}
Exemplo n.º 2
0
 int jump(int A[], int n) {
     // Start typing your C/C++ solution below
     // DO NOT write int main() function
     if(n<=1) return 0;
     vector<int> ret(n, n+1);
     vector<bool> canUse(n, true);
     ret[0] = 0;
     int maxReachIndex = 0;
     for(int i=0; i< n && i<= maxReachIndex; i++)
     {
         int oldMax = maxReachIndex;
         if(i+A[i] < maxReachIndex) continue;
         else
         {
             maxReachIndex = i+A[i];
         }
         
         if(!canUse[i]) continue;
         for(int j=oldMax+1; j <n && j<=maxReachIndex; j++)
         {
             if(!canUse[j]) continue;
             ret[j] = ret[j] < ret[i] + 1 ? ret[j] : ret[i] +1;
             if(ret[j] > ret[n-1]) canUse[j] = false;
            
         }
     }
     if(maxReachIndex < n-1) return -1;
     return ret[n-1];
 }
Exemplo n.º 3
0
int Actions::canUseFar(const Player *player,const Position &to_pos, const bool blockWalls) const
{
	if(to_pos.x == 0xFFFF){
		return CAN_USE;
	}
	if(std::abs(player->pos.x - to_pos.x) > 7 || std::abs(player->pos.y - to_pos.y) > 5 || player->pos.z != to_pos.z){
		return TOO_FAR;
	}

	if(canUse(player,to_pos) == TOO_FAR){
		if(blockWalls && (game->map->canThrowObjectTo(player->pos, to_pos, BLOCK_PROJECTILE) != RET_NOERROR)){
			return CAN_NOT_THTOW;
		}
	}

	return CAN_USE;
}
Exemplo n.º 4
0
void backtrack(int column){
	int row;

	if (column > size){
		if (remaining){
			printAnswer();
			remaining--;
		}
		answer++;
		return;
	}

	for (row = 0; row < size; row++){
		if (canUse(row,column)){
			used[row] = column;
			backtrack(column+1);
			used[row] = 0;
		}
	}
}
Exemplo n.º 5
0
bool VerbUseStructure::canAttach( Noun * pNoun )
{
	return canUse( WidgetCast<NounStructure>( pNoun ), m_pUser );
}
Exemplo n.º 6
0
PUBLIC int httpConnect(HttpStream *stream, cchar *method, cchar *url, MprSsl *ssl)
{
    HttpNet     *net;
    HttpTx      *tx;
    HttpUri     *uri;
    cchar       *ip, *protocol;
    int         port;

    assert(stream);
    assert(method && *method);
    assert(url && *url);

    net = stream->net;
    if (httpServerStream(stream)) {
        mprLog("client error", 0, "Cannot call httpConnect() in a server");
        return MPR_ERR_BAD_STATE;
    }
    if (net->protocol <= 0) {
        mprLog("client error", 0, "HTTP protocol to use has not been defined");
        return MPR_ERR_BAD_STATE;
    }
    if (stream->tx == 0 || stream->state != HTTP_STATE_BEGIN) {
        httpResetClientStream(stream, 0);
    }
    tx = stream->tx;
    tx->method = supper(method);
    stream->authRequested = 0;
    stream->startMark = mprGetHiResTicks();

    if ((uri = tx->parsedUri = httpCreateUri(url, HTTP_COMPLETE_URI_PATH)) == 0) {
        return MPR_ERR_BAD_ARGS;
    }
    ssl = uri->secure ? (ssl ? ssl : mprCreateSsl(0)) : 0;
    httpGetUriAddress(uri, &ip, &port);

    if (net->sock) {
        if (net->error) {
            mprCloseSocket(net->sock, 0);
            net->sock = 0;

        } else if (canUse(net, stream, uri, ssl, ip, port)) {
            httpLog(net->trace, "client.connection.reuse", "context", "reuse:%d", stream->keepAliveCount);

        } else {
            if (net->protocol >= 2) {
                if (mprGetListLength(net->streams) > 1) {
                    httpError(stream, HTTP_CODE_COMMS_ERROR, "Cannot use network for %s due to other existing requests", ip);
                    return MPR_ERR_CANT_FIND;
                }
            } else {
                mprCloseSocket(net->sock, 0);
                net->sock = 0;
            }
        }
    }
    if (!net->sock) {
        if (httpConnectNet(net, ip, port, ssl) < 0) {
            return MPR_ERR_CANT_CONNECT;
        }
        stream->net = net;
        stream->sock = net->sock;
        stream->ip = net->ip;
        stream->port = net->port;
        stream->keepAliveCount = (net->protocol >= 2) ? 0 : stream->limits->keepAliveMax;

#if ME_HTTP_WEB_SOCKETS
        if (net->protocol == 1 && uri->webSockets && httpUpgradeWebSocket(stream) < 0) {
            stream->errorMsg = net->errorMsg = net->sock->errorMsg;
            return 0;
        }
#endif
    }
    httpCreatePipeline(stream);
    setDefaultHeaders(stream);
    httpSetState(stream, HTTP_STATE_CONNECTED);
    protocol = net->protocol < 2 ? "HTTP/1.1" : "HTTP/2";
    httpLog(net->trace, "client.request", "request", "method='%s', url='%s', protocol='%s'", tx->method, url, protocol);
    return 0;
}
Exemplo n.º 7
0
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;
}