void Theta_Star::updateVertex(PriorityQueue &fringe, Node current, Node &succ, Node *vertex) { if(current.parent != NULL && lineOfSight(*current.parent, succ)) { // Path 2 double g_current = g_val[current.parent->x+current.parent->y*(blocked->getCols()+1)]; double cost = sqrt( (succ.x-current.parent->x) * (succ.x-current.parent->x) + (succ.y-current.parent->y) * (succ.y-current.parent->y) ); if(cost + g_current < g_val[succ.x+succ.y*(blocked->getCols()+1)]) { g_val[succ.x+succ.y*(blocked->getCols()+1)] = cost + g_current; succ.h = h(succ.x,succ.y); succ.f = g_val[succ.x+succ.y*(blocked->getCols()+1)]+succ.h; f_val[succ.x+succ.y*(blocked->getCols()+1)] = succ.f; succ.parent = vertex->parent; // we didn't do this before either -> remove from fringe fringe.enqueue(succ); } } else { double g_current = g_val[current.x+current.y*(blocked->getCols()+1)]; double cost = sqrt( (succ.x-current.x) * (succ.x-current.x) + (succ.y-current.y) * (succ.y-current.y) ); if(g_current+cost < g_val[succ.x+succ.y*(blocked->getCols()+1)]) { g_val[succ.x+succ.y*(blocked->getCols()+1)] = g_current+cost; succ.h = h(succ.x,succ.y); succ.f = g_val[succ.x+succ.y*(blocked->getCols()+1)]+succ.h; succ.parent = vertex; //cout << succ.f << endl; if(succ.f < f_val[succ.x+succ.y*(blocked->getCols()+1)]) { fringe.enqueue(succ); //cout << "enqueued " << succ.x << " " << succ.y << endl; f_val[succ.x+succ.y*(blocked->getCols()+1)] = succ.f; } } } }
//--------------------------------------------------------------------------- bool Team::lineOfSight(Stuff::Vector3D position, Stuff::Vector3D targetPosition, int32_t teamId, float extRad, float startExtRad, bool checkVisibleBits) { int32_t posCellR, posCellC; int32_t tarCellR, tarCellC; land->worldToCell(position, posCellR, posCellC); land->worldToCell(targetPosition, tarCellR, tarCellC); float elev = land->getTerrainElevation(position); float localStart = position.z - elev; elev = land->getTerrainElevation(targetPosition); float localEnd = targetPosition.z - elev; return(lineOfSight(localStart, posCellR, posCellC, localEnd, tarCellR, tarCellC, teamId, extRad, startExtRad, checkVisibleBits)); }
void cDragItems::dropOnGround( cUOSocket *socket, P_ITEM pItem, const Coord_cl &pos ) { P_PLAYER pChar = socket->player(); // Check if the destination is in line of sight if( !lineOfSight( pChar->pos(), pos, WALLS_CHIMNEYS|DOORS|LAVA_WATER ) ) { socket->bounceItem( pItem, BR_OUT_OF_SIGHT ); return; } if( !pChar->canPickUp( pItem ) ) { socket->bounceItem( pItem, BR_CANNOT_PICK_THAT_UP ); return; } if( pItem->onDropOnGround( pos ) ) { // We're still dragging something if( socket->dragging() ) socket->bounceItem( socket->dragging(), BR_NO_REASON ); return; } pItem->removeFromCont(); pItem->moveTo( pos ); pItem->update(); if( pItem->priv() & 0x01 ) pItem->startDecay(); // Multi handling // Has it been dropped into a multi cMulti* pMulti = cMulti::findMulti( pos ); if( pMulti ) { pMulti->addItem( pItem ); } }
void cDragItems::dropOnChar( cUOSocket *socket, P_ITEM pItem, P_CHAR pOtherChar ) { // Three possibilities: // If we're dropping it on ourself: packintobackpack // If we're dropping it on some other player: trade-window // If we're dropping it on some NPC: checkBehaviours // If not handeled: Equip the item if the NPC is owned by us // To prevent bad effects remove it from the clients view first cUOTxRemoveObject rObject; rObject.setSerial( pItem->serial() ); socket->send( &rObject ); P_CHAR pChar = socket->player(); if( pItem->onDropOnChar( pOtherChar ) ) { // Still dragging? Bounce! if( socket->dragging() == pItem ) socket->bounceItem( pItem, BR_NO_REASON ); return; } if( pOtherChar->onDropOnChar( pItem ) ) { // Still dragging? Bounce! if( socket->dragging() == pItem ) socket->bounceItem( pItem, BR_NO_REASON ); return; } // Dropped on ourself if( pChar == pOtherChar ) { pItem->toBackpack( pChar ); return; } // Are we in range of our target if( !inrange1p( pChar, pOtherChar ) ) { socket->bounceItem( pItem, BR_OUT_OF_REACH ); return; } // Can wee see our target if( !lineOfSight( pChar->pos(), pOtherChar->pos(), TREES_BUSHES|WALLS_CHIMNEYS|DOORS|ROOFING_SLANTED|FLOORS_FLAT_ROOFING|LAVA_WATER ) ) { socket->bounceItem( pItem, BR_OUT_OF_SIGHT ); return; } // Open a secure trading window if( pOtherChar->objectType() == enPlayer && dynamic_cast<P_PLAYER>(pOtherChar)->socket() ) { // Check if we're already trading, // if not create a new window P_ITEM tradeWindow = pChar->atLayer( cBaseChar::TradeWindow ); //if( !tradeWindow ) // tradeWindow = Trade->tradestart( client->socket(), pOtherChar ); socket->bounceItem( pItem, BR_NO_REASON ); socket->sysMessage( "Trading is disabled" ); return; tradeWindow->addItem( pItem, false, false ); pItem->setPos( Coord_cl(rand() % 60, rand() % 60, 9) ); pItem->removeFromView( false ); pItem->update(); return; } // Dropping based on AI Type /*switch( pOtherChar->npcaitype() ) { case 4: dropOnGuard( client, pItem, pOtherChar ); break; case 5: dropOnBeggar( client, pItem, pOtherChar ); break; case 8: dropOnBanker( client, pItem, pOtherChar ); break; case 19: dropOnBroker( client, pItem, pOtherChar ); break; }; // Try to train - works for any NPC if( pOtherChar->cantrain() ) if( pChar->trainer() == pOtherChar->serial ) dropOnTrainer( client, pItem, pOtherChar ); else pOtherChar->talk( "You need to tell me what you want to learn first" );*/ // Finally lets check if it is simple food if( pItem->type() == 14 ) { dropFoodOnChar( socket, pItem, pOtherChar ); return; } socket->sysMessage( tr("The character does not seem to want the item.") ); socket->bounceItem( pItem, BR_NO_REASON ); return; }
bool Guards::CheckSight(Vector2 playerPos, int tileSize, double dt) { Vector2 lineOfSight(playerPos - this->pos); int numRows = 0; int numCols = 0; numCols = (int)lineOfSight.x / tileSize; numRows = (int)lineOfSight.y / tileSize; // player above guard if (numRows >= 0) { if (numCols >= 0) { // player is top right for (int i = 0; i <= numRows; ++i) { for (int j = 0; j <= numCols; ++j) { for (unsigned special = 0; special < currentRoom->specialTiles.size(); ++special) { if (currentRoom->specialTiles[special].TileName == "Wall" || currentRoom->specialTiles[special].TileName == "CellDoorClosed") { if (currentRoom->roomLayout[TileMap::TYPE_COLLISION].screenMap[currentRoom->roomLayout[TileMap::TYPE_COLLISION].getNumTilesHeight() - (int)pos.y / tileSize - i][(int) pos.x / tileSize + j] == currentRoom->specialTiles[special].TileID) { return false; } } } } } } else { // player is top left for (int i = 0; i <= numRows; ++i) { for (int j = 0; j >= numCols; --j) { for (unsigned special = 0; special < currentRoom->specialTiles.size(); ++special) { if (currentRoom->specialTiles[special].TileName == "Wall" || currentRoom->specialTiles[special].TileName == "CellDoorClosed") { if (currentRoom->roomLayout[TileMap::TYPE_COLLISION].screenMap[currentRoom->roomLayout[TileMap::TYPE_COLLISION].getNumTilesHeight() - (int)pos.y / tileSize - i][(int) pos.x / tileSize + j] == currentRoom->specialTiles[special].TileID) { return false; } } } } } } } else { // bottom right if (numCols >= 0) { for (int i = 0; i >= numRows; --i) { for (int j = 0; j <= numCols; ++j) { for (unsigned special = 0; special < currentRoom->specialTiles.size(); ++special) { if (currentRoom->specialTiles[special].TileName == "Wall" || currentRoom->specialTiles[special].TileName == "CellDoorClosed") { if (currentRoom->roomLayout[TileMap::TYPE_COLLISION].screenMap[currentRoom->roomLayout[TileMap::TYPE_COLLISION].getNumTilesHeight() - (int)pos.y / tileSize + i][(int) pos.x / tileSize + j] == currentRoom->specialTiles[special].TileID) { return false; } } } } } } else { // bottom left for (int i = 0; i >= numRows; --i) { for (int j = 0; j >= numCols; --j) { for (unsigned special = 0; special < currentRoom->specialTiles.size(); ++special) { if (currentRoom->specialTiles[special].TileName == "Wall" || currentRoom->specialTiles[special].TileName == "CellDoorClosed") { if (currentRoom->roomLayout[TileMap::TYPE_COLLISION].screenMap[currentRoom->roomLayout[TileMap::TYPE_COLLISION].getNumTilesHeight() - (int)pos.y / tileSize + i][(int) pos.x / tileSize + j] == currentRoom->specialTiles[special].TileID) { return false; } } } } } } } return true; }
/*! \brief Double click \author Ripper, rewrite by Endymion \param ps client of player dbclick \note Completely redone by Morrolan 20-07-99 \warning I use a define CASE for make more readable the code, if you change name of P_ITEM pi chage also the macro \todo los */ void doubleclick(NXWCLIENT ps) { if(ps==NULL) return; P_CHAR pc = ps->currChar(); VALIDATEPC( pc ); NXWSOCKET s = ps->toInt(); // the 0x80 bit in the first byte is used later for "keyboard" and should be ignored SERIAL serial = LongFromCharPtr(buffer[s] +1) & 0x7FFFFFFF; if (isCharSerial(serial)) { P_CHAR pd=pointers::findCharBySerial(serial); if(ISVALIDPC(pd)) dbl_click_character(ps, pd); return; } P_ITEM pi = pointers::findItemBySerial(serial); VALIDATEPI(pi); if (pi->amxevents[EVENT_IONDBLCLICK]!=NULL) { g_bByPass = false; pi->amxevents[EVENT_IONDBLCLICK]->Call( pi->getSerial32(), pc->getSerial32() ); if (g_bByPass==true) return; } /* g_bByPass = false; pi->runAmxEvent( EVENT_IONDBLCLICK, pi->getSerial32(), s ); if (g_bByPass==true) return; */ if (!checkItemUsability(pc , pi, ITEM_USE_DBLCLICK)) return; Location charpos= pc->getPosition(); if (pc->IsHiddenBySpell()) return; //Luxor: cannot use items if under invisible spell if ( !pc->IsGM() && pc->objectdelay >= uiCurrentTime ) { pc->sysmsg(TRANSLATE("You must wait to perform another action.")); return; } else pc->objectdelay = SrvParms->objectdelay * MY_CLOCKS_PER_SEC + uiCurrentTime; ///MODIFY, CANT CLICK ITEM AT DISTANCE >2////////////// if ( (pc->distFrom(pi)>2) && !pc->IsGM() && !(pc->nxwflags[0] & cChar::flagSpellTelekinesys) ) //Luxor: let's check also for the telekinesys spell { pc->sysmsg( TRANSLATE("Must be closer to use this!")); pc->objectdelay=0; return; } //<Anthalir> VARIAIBLI tile_st item; P_ITEM pack= pc->getBackpack(); VALIDATEPI( pack ); data::seekTile( pi->getId(), item ); //////FINEVARIABILI if ( ServerScp::g_nEquipOnDclick ) { // equip the item only if it is in the backpack of the player if ((pi->getContSerial() == pack->getSerial32()) && (item.quality != 0) && (item.quality != LAYER_BACKPACK) && (item.quality != LAYER_MOUNT)) { int drop[2]= {-1, -1}; // list of items to drop, there no reason for it to be larger int curindex= 0; NxwItemWrapper wea; wea.fillItemWeared( pc, true, true, true ); for( wea.rewind(); !wea.isEmpty(); wea++ ) { P_ITEM pj=wea.getItem(); if(!ISVALIDPI(pj)) continue; if ((item.quality == LAYER_1HANDWEAPON) || (item.quality == LAYER_2HANDWEAPON))// weapons { if (pi->itmhand == 2) // two handed weapons or shield { if (pj->itmhand == 2) drop[curindex++]= DEREF_P_ITEM(pj); if ( (pj->itmhand == 1) || (pj->itmhand == 3) ) drop[curindex++]= DEREF_P_ITEM(pj); } if (pi->itmhand == 3) { if ((pj->itmhand == 2) || pj->itmhand == 3) drop[curindex++]= DEREF_P_ITEM(pj); } if ((pi->itmhand == 1) && ((pj->itmhand == 2) || (pj->itmhand == 1))) drop[curindex++]= DEREF_P_ITEM(pj); } else // not a weapon { if (pj->layer == item.quality) drop[curindex++]= DEREF_P_ITEM(pj); } } if (ServerScp::g_nUnequipOnReequip) { if (drop[0] > -1) // there is at least one item to drop { for (int i= 0; i< 2; i++) { if (drop[i] > -1) { P_ITEM p_drop=MAKE_ITEM_REF(drop[i]); if(ISVALIDPI(p_drop)) pc->UnEquip( p_drop ); } } } pc->playSFX( itemsfx(pi->getId()) ); pc->Equip( pi ); } else { if (drop[0] == -1) { pc->playSFX( itemsfx(pi->getId()) ); pc->Equip( pi ); } } return; } } // </Anthalir> //<Luxor>: Circle of transparency bug fix P_ITEM pCont; Location dst; pCont = pi->getOutMostCont(); if(pCont->isInWorld()) { dst = pCont->getPosition(); } else { P_CHAR pg_dst = pointers::findCharBySerial( pCont->getContSerial() ); VALIDATEPC(pg_dst); dst = pg_dst->getPosition(); } Location charPos = pc->getPosition(); charPos.z = dst.z; charPos.dispz = dst.dispz; if ( !pc->IsGM() && !lineOfSight( charPos, dst ) && !(pc->nxwflags[0] & cChar::flagSpellTelekinesys) ) { pc->sysmsg( TRANSLATE( "You cannot reach the item" ) ); return; } //</Luxor> P_CHAR itmowner = pi->getPackOwner(); if(!pi->isInWorld()) { if (isItemSerial(pi->getContSerial()) && pi->type != ITYPE_CONTAINER) {// Cant use stuff that isn't in your pack. if ( ISVALIDPC(itmowner) && (itmowner->getSerial32()!=pc->getSerial32()) ) return; } else if (isCharSerial(pi->getContSerial()) && pi->type!=(UI32)INVALID) {// in a character. P_CHAR wearedby = pointers::findCharBySerial(pi->getContSerial()); if (ISVALIDPC(wearedby)) if (wearedby->getSerial32()!=pc->getSerial32() && pi->layer!=LAYER_UNUSED_BP && pi->type!=ITYPE_CONTAINER) return; } } if ((pi->magic==4) && (pi->secureIt==1)) { if (!pc->isOwnerOf(pi) || !pc->IsGMorCounselor()) { pc->sysmsg( TRANSLATE("That is a secured chest!")); return; } } if (pi->magic == 4) { pc->sysmsg( TRANSLATE("That item is locked down.")); return; } if (pc->dead && pi->type!=ITYPE_RESURRECT) // if you are dead and it's not an ankh, FORGET IT! { pc->sysmsg(TRANSLATE("You may not do that as a ghost.")); return; } else if (!pc->IsGMorCounselor() && pi->layer!=0 && !pc->IsWearing(pi)) {// can't use other people's things! if (!(pi->layer==LAYER_BACKPACK && SrvParms->rogue==1)) // bugfix for snooping not working, LB { pc->sysmsg(TRANSLATE("You cannot use items equipped by other players.")); return; } } // Begin checking objects that we force an object delay for (std objects) // start trigger stuff if (pi->trigger > 0) { if (pi->trigtype == 0) { if ( TIMEOUT( pi->disabled ) ) // changed by Magius(CHE) § { triggerItem(s, pi, TRIGTYPE_DBLCLICK); // if players uses trigger return; } else { if ( pi->disabledmsg!=NULL ) pc->sysmsg("%s", pi->disabledmsg->c_str()); else pc->sysmsg(TRANSLATE("That doesnt seem to work right now.")); return; } } else { pc->sysmsg( TRANSLATE("You are not close enough to use that.")); return; } } // check this on trigger in the event that the .trigger property is not set on the item // trigger code. Check to see if item is envokable by id else if (checkenvoke( pi->getId() )) { pc->envokeitem = pi->getSerial32(); pc->envokeid = pi->getId(); P_TARGET targ = clientInfo[s]->newTarget( new cObjectTarget() ); targ->code_callback=target_envoke; targ->send( ps ); ps->sysmsg( TRANSLATE("What will you use this on?")); return; } // end trigger stuff // BEGIN Check items by type int los = 0; BYTE map1[20] = "\x90\x40\x01\x02\x03\x13\x9D\x00\x00\x00\x00\x13\xFF\x0F\xFF\x01\x90\x01\x90"; BYTE map2[12] = "\x56\x40\x01\x02\x03\x05\x00\x00\x00\x00\x00"; // By Polygon: This one is needed to show the location on treasure maps BYTE map3[12] = "\x56\x40\x01\x02\x03\x01\x00\x00\x00\x00\x00"; P_TARGET targ = NULL; switch (pi->type) { case ITYPE_RESURRECT: // Check for 'resurrect item type' this is the ONLY type one can use if dead. if (pc->dead) { pc->resurrect(); pc->sysmsg(TRANSLATE("You have been resurrected.")); return; } else { pc->sysmsg(TRANSLATE("You are already living!")); return; } case ITYPE_BOATS:// backpacks - snooping a la Zippy - add check for SrvParms->rogue later- Morrolan if (pi->type2 == 3) { switch( pi->getId() & 0xFF ) { case 0x84: case 0xD5: case 0xD4: case 0x89: Boats->PlankStuff(pc, pi); break; default: pc->sysmsg( TRANSLATE("That is locked.")); break; } return; } case ITYPE_CONTAINER: // bugfix for snooping not working, lb case ITYPE_UNLOCKED_CONTAINER: // Wintermute: GMs or Counselors should be able to open trapped containers always if (pi->moreb1 > 0 && !pc->IsGMorCounselor()) { magic::castAreaAttackSpell(pi->getPosition("x"), pi->getPosition("y"), magic::SPELL_EXPLOSION); pi->moreb1--; } //Magic->MagicTrap(currchar[s], pi); // added by AntiChrist // only 1 and 63 can be trapped, so pleaz leave it here :) - Anti case ITYPE_NODECAY_ITEM_SPAWNER: // nodecay item spawner..Ripper case ITYPE_DECAYING_ITEM_SPAWNER: // decaying item spawner..Ripper if (pi->isInWorld() || (pc->IsGMorCounselor()) || // Backpack in world - free access to everyone ( isCharSerial(pi->getContSerial()) && pi->getContSerial()==pc->getSerial32())) // primary pack { pc->showContainer(pi); pc->objectdelay=0; return; } else if( isItemSerial(pi->getContSerial()) ) { P_ITEM pio = pi->getOutMostCont(); if (pio->getContSerial()==pc->getSerial32() || pio->isInWorld() ) { pc->showContainer(pi); pc->objectdelay=0; return; } } if(ISVALIDPC(itmowner)) snooping(pc, pi ); return; case ITYPE_TELEPORTRUNE: targ = clientInfo[s]->newTarget( new cLocationTarget() ); targ->code_callback = target_tele; targ->send( ps ); ps->sysmsg( TRANSLATE("Select teleport target.")); return; case ITYPE_KEY: targ = clientInfo[s]->newTarget( new cItemTarget() ); targ->code_callback = target_key; targ->buffer[0]= pi->more1; targ->buffer[1]= pi->more2; targ->buffer[2]= pi->more3; targ->buffer[3]= pi->more4; targ->send( ps ); ps->sysmsg( TRANSLATE("Select item to use the key on.")); return; case ITYPE_LOCKED_ITEM_SPAWNER: case ITYPE_LOCKED_CONTAINER: // Added traps effects by AntiChrist // Wintermute: GMs or Counselors should be able to open locked containers always if ( !pc->IsGMorCounselor() ) { if (pi->moreb1 > 0 ) { magic::castAreaAttackSpell(pi->getPosition().x, pi->getPosition().y, magic::SPELL_EXPLOSION); pi->moreb1--; } pc->sysmsg(TRANSLATE("This item is locked.")); return; } else { pc->showContainer(pi); return; } case ITYPE_SPELLBOOK: if (ISVALIDPI(pack)) // morrolan if(pi->getContSerial()==pack->getSerial32() || pc->IsWearing(pi)) ps->sendSpellBook(pi); else pc->sysmsg(TRANSLATE("If you wish to open a spellbook, it must be equipped or in your main backpack.")); return; case ITYPE_MAP: LongToCharPtr(pi->getSerial32(), map1 +1); map2[1] = map1[1]; map2[2] = map1[2]; map2[3] = map1[3]; map2[4] = map1[4]; /* By Polygon: Assign areas and map size before sending */ map1[7] = pi->more1; // Assign topleft x map1[8] = pi->more2; map1[9] = pi->more3; // Assign topleft y map1[10] = pi->more4; map1[11] = pi->moreb1; // Assign lowright x map1[12] = pi->moreb2; map1[13] = pi->moreb3; // Assign lowright y map1[14] = pi->moreb4; int width, height; // Tempoary storage for w and h; width = 134 + (134 * pi->morez); // Calculate new w and h height = 134 + (134 * pi->morez); ShortToCharPtr(width, map1 +15); ShortToCharPtr(height, map1 +17); // END OF: By Polygon Xsend(s, map1, 19); //AoS/ Network->FlushBuffer(s); Xsend(s, map2, 11); //AoS/ Network->FlushBuffer(s); return; case ITYPE_BOOK: Books::DoubleClickBook(s, pi); return; case ITYPE_DOOR: dooruse(s, pi); return; case ITYPE_LOCKED_DOOR: // Wintermute: GMs or Counselors should be able to open locked doors always if ( pc->IsGMorCounselor()) { dooruse(s, pi); return; } if (ISVALIDPI(pack)) { NxwItemWrapper si; si.fillItemsInContainer( pack ); for( si.rewind(); !si.isEmpty(); si++ ) { P_ITEM pj = si.getItem(); if (ISVALIDPI(pj) && pj->type==ITYPE_KEY) if (((pj->more1 == pi->more1) && (pj->more2 == pi->more2) && (pj->more3 == pi->more3) && (pj->more4 == pi->more4)) ) { pc->sysmsg(TRANSLATE("You quickly unlock, use, and then relock the door.")); dooruse(s, pi); return; } } } pc->sysmsg(TRANSLATE("This door is locked.")); return; case ITYPE_FOOD: if (pc->hunger >= 6) { pc->sysmsg( TRANSLATE("You are simply too full to eat any more!")); return; } else { switch (RandomNum(0, 2)) { case 0: pc->playSFX(0x3A); break; case 1: pc->playSFX(0x3B); break; case 2: pc->playSFX(0x3C); break; } switch (pc->hunger) { case 0: pc->sysmsg( TRANSLATE("You eat the food, but are still extremely hungry.")); break; case 1: pc->sysmsg( TRANSLATE("You eat the food, but are still extremely hungry.")); break; case 2: pc->sysmsg( TRANSLATE("After eating the food, you feel much less hungry.")); break; case 3: pc->sysmsg( TRANSLATE("You eat the food, and begin to feel more satiated.")); break; case 4: pc->sysmsg( TRANSLATE("You feel quite full after consuming the food.")); break; case 5: pc->sysmsg( TRANSLATE("You are nearly stuffed, but manage to eat the food.")); break; default: pc->sysmsg( TRANSLATE("You are simply too full to eat any more!")); break; } if (pi->poisoned) { pc->sysmsg(TRANSLATE("The food was poisoned!")); pc->applyPoison(PoisonType(pi->poisoned)); } pi->ReduceAmount(1); pc->hunger++; } return; case ITYPE_WAND: // -Fraz- Modified and tuned up, Wands must now be equipped or in pack case ITYPE_MANAREQ_WAND: // magic items requiring mana (xan) if (ISVALIDPI(pack)) { if (pi->getContSerial() == pack->getSerial32() || pc->IsWearing(pi)) { if (pi->morez != 0) { pi->morez--; if (magic::beginCasting( static_cast<magic::SpellId>((8*(pi->morex - 1)) + pi->morey - 1), ps, (pi->type==ITYPE_WAND) ? magic::CASTINGTYPE_ITEM : magic::CASTINGTYPE_NOMANAITEM)) { if (pi->morez == 0) { pi->type = pi->type2; pi->morex = 0; pi->morey = 0; pi->offspell = 0; } } } } else { pc->sysmsg(TRANSLATE("If you wish to use this, it must be equipped or in your backpack.")); } } return; // case 15 (magic items) /*////////////////////REMOVE///////////////////////////////////// case 18: // crystal ball? switch (RandomNum(0, 9)) { case 0: itemmessage(s, TRANSLATE("Seek out the mystic llama herder."), pi->getSerial32()); break; case 1: itemmessage(s, TRANSLATE("Wherever you go, there you are."), pi->getSerial32()); break; case 4: itemmessage(s, TRANSLATE("The message appears to be too cloudy to make anything out of it."), pi->getSerial32()); break; case 5: itemmessage(s, TRANSLATE("You have just lost five strength.. not!"), pi->getSerial32()); break; case 6: itemmessage(s, TRANSLATE("You're really playing a game you know"), pi->getSerial32()); break; case 7: itemmessage(s, TRANSLATE("You will be successful in all you do."), pi->getSerial32()); break; case 8: itemmessage(s, TRANSLATE("You are a person of culture."), pi->getSerial32()); break; default: itemmessage(s, TRANSLATE("Give me a break! How much good fortune do you expect!"), pi->getSerial32()); break; }// switch soundeffect2(pc_currchar, 0x01EC); return;// case 18 (crystal ball?) */////////////////////ENDREMOVE///////////////////////////////////// case ITYPE_POTION: // potions if (pi->morey != 3) pc->drink(pi); //Luxor: delayed potions drinking else //explosion potion usepotion(pc, pi); return; case ITYPE_RUNE: if (pi->morex==0 && pi->morey==0 && pi->morez==0) { pc->sysmsg( TRANSLATE("That rune is not yet marked!")); } else { pc->runeserial = pi->getSerial32(); pc->sysmsg( TRANSLATE("Enter new rune name.")); } return; case ITYPE_SMOKE: pc->smoketimer = pi->morex*MY_CLOCKS_PER_SEC + getclock(); pi->ReduceAmount(1); return; case ITYPE_RENAME_DEED: pc->namedeedserial = pi->getSerial32(); pc->sysmsg( TRANSLATE("Enter your new name.")); pi->ReduceAmount(1); return; case ITYPE_POLYMORPH: pc->setId( pi->morex ); pc->teleport(); pi->type = ITYPE_POLYMORPH_BACK; return; case ITYPE_POLYMORPH_BACK: pc->setId( pc->getOldId() ); pc->teleport(); pi->type = ITYPE_POLYMORPH; return; case ITYPE_ARMY_ENLIST: enlist(s, pi->morex); pi->Delete(); return; case ITYPE_TELEPORT: pc->MoveTo( pi->morex,pi->morey,pi->morez ); pc->teleport(); return; case ITYPE_DRINK: switch (rand()%2) { case 0: pc->playSFX(0x0031); break; case 1: pc->playSFX(0x0030); break; } pi->ReduceAmount(1); pc->sysmsg( TRANSLATE("Gulp !")); return; case ITYPE_GUILDSTONE: if ( pi->getId() == 0x14F0 || pi->getId() == 0x1869 ) // Check for Deed/Teleporter + Guild Type { pc->fx1 = DEREF_P_ITEM(pi); Guilds->StonePlacement(s); return; } else if (pi->getId() == 0x0ED5) // Check for Guildstone + Guild Type { pc->fx1 = DEREF_P_ITEM(pi); Guilds->Menu(s, 1); return; } else WarnOut("Unhandled guild item type named: %s with ID of: %X\n", pi->getCurrentNameC(), pi->getId()); return; case ITYPE_PLAYER_VENDOR_DEED: // PlayerVendors deed { P_CHAR vendor = npcs::AddNPCxyz(-1, 2117, charpos.x, charpos.y, charpos.z); if ( !ISVALIDPC(vendor) ) { WarnOut("npc-script couldnt find vendor !\n"); return; } los = 0; vendor->npcaitype = NPCAI_PLAYERVENDOR; vendor->MakeInvulnerable(); vendor->unHide(); vendor->stealth=INVALID; vendor->dir = pc->dir; vendor->npcWander = WANDER_NOMOVE; vendor->SetInnocent(); vendor->setOwnerSerial32( pc->getSerial32() ); vendor->tamed = false; pi->Delete(); vendor->teleport(); char temp[TEMP_STR_SIZE]; //xan -> this overrides the global temp var sprintf( temp, TRANSLATE("Hello sir! My name is %s and i will be working for you."), vendor->getCurrentNameC()); vendor->talk(s, temp, 0); return; } case ITYPE_TREASURE_MAP: Skills::Decipher(pi, s); return; case ITYPE_DECIPHERED_MAP: map1[ 1] = map2[1] = map3[1] = pi->getSerial().ser1; map1[ 2] = map2[2] = map3[2] = pi->getSerial().ser2; map1[ 3] = map2[3] = map3[3] = pi->getSerial().ser3; map1[ 4] = map2[4] = map3[4] = pi->getSerial().ser4; map1[ 7] = pi->more1; // Assign topleft x map1[ 8] = pi->more2; map1[ 9] = pi->more3; // Assign topleft y map1[10] = pi->more4; map1[11] = pi->moreb1; // Assign lowright x map1[12] = pi->moreb2; map1[13] = pi->moreb3; // Assign lowright y map1[14] = pi->moreb4; ShortToCharPtr(0x0100, map1 +15); // Let width and height be 256 ShortToCharPtr(0x0100, map1 +17); Xsend(s, map1, 19); //AoS/ Network->FlushBuffer(s); Xsend(s, map2, 11); //AoS/ Network->FlushBuffer(s); // Generate message to add a map point SI16 posx, posy; // tempoary storage for map point SI16 tlx, tly, lrx, lry; // tempoary storage for map extends tlx = (pi->more1 << 8) | pi->more2; tly = (pi->more3 << 8) | pi->more4; lrx = (pi->moreb1 << 8) | pi->moreb2; lry = (pi->moreb3 << 8) | pi->moreb4; posx = (256 * (pi->morex - tlx)) / (lrx - tlx); // Generate location for point posy = (256 * (pi->morey - tly)) / (lry - tly); ShortToCharPtr(posx, map3 +7); // Store the point position ShortToCharPtr(posy, map3 +9); Xsend(s, map3, 11); // Fire data to client :D //AoS/ Network->FlushBuffer(s); return; default: break; } ///END IDENTIFICATION BY TYPE /////////////////READ UP :D//////////////////////////////// ///BEGIN IDENTIFICATION BY ID if (pi->IsSpellScroll()) { if (ISVALIDPI(pack)) if( pi->getContSerial()==pack->getSerial32()) { magic::SpellId spn = magic::spellNumberFromScrollId(pi->getId()); // avoid reactive armor glitch if ((spn>=0)&&(magic::beginCasting(spn, ps, magic::CASTINGTYPE_SCROLL))) pi->ReduceAmount(1); // remove scroll if successful } else pc->sysmsg(TRANSLATE("The scroll must be in your backpack to envoke its magic.")); } CASE(IsAnvil) { targ = clientInfo[s]->newTarget( new cItemTarget() ); targ->code_callback=Skills::target_repair; targ->send( ps ); ps->sysmsg( TRANSLATE("Select item to be repaired.")); } CASE(IsAxe) { targ = clientInfo[s]->newTarget( new cTarget() ); targ->code_callback=target_axe; targ->buffer[0]=pi->getSerial32(); targ->send( ps ); ps->sysmsg( TRANSLATE("What would you like to use that on ?")); } CASEOR(IsFeather, IsShaft) { targ = clientInfo[s]->newTarget( new cItemTarget() ); targ->buffer[0]= pi->getSerial32(); targ->code_callback=Skills::target_fletching; targ->send( ps ); ps->sysmsg( TRANSLATE("What would you like to use this with?")); }
bool Coord_cl::lineOfSight( const Coord_cl &target, bool touch ) { return lineOfSight( target, 0, touch ); }
bool cNewMagic::checkTarget( P_CHAR pCaster, stNewSpell *sInfo, cUORxTarget *target ) { cUOSocket *socket; if( pCaster->objectType() == enPlayer ) socket = dynamic_cast<P_PLAYER>(pCaster)->socket(); P_CHAR pChar = FindCharBySerial( target->serial() ); P_ITEM pItem = FindItemBySerial( target->serial() ); if( sInfo->targets & (TARGET_CHAR|TARGET_ITEM) && !pItem && !pChar ) { socket->sysMessage( tr( "Please target an object" ) ); return false; } if( sInfo->targets & TARGET_CHAR && !pChar ) { socket->sysMessage( tr( "Please target a living creature." ) ); return false; } if( sInfo->targets & TARGET_ITEM && !pItem ) { socket->sysMessage( tr( "Please target an item." ) ); return false; } // Several checks (Get the correct position of the target and do NOT trust the position transmitted by the client) Coord_cl pos = socket->player()->pos(); if( pChar ) pos = pChar->pos(); else if( pItem ) pos = pItem->pos(); else { pos.x = target->x(); pos.y = target->y(); pos.z = target->z(); } if( pItem && !pItem->isInWorld() ) { P_CHAR pOut = pItem->getOutmostChar(); if( pOut == socket->player() ) return true; else { socket->clilocMessage( 0x7A258, "", 0x3b2 ); // You cannot reach that return false; } } else { // Distance check (VisRange + 5 for macros) if( pos.distance( socket->player()->pos() ) > ( socket->player()->visualRange() + 5 ) ) { socket->sysMessage( tr( "You can't see the target." ) ); return false; } // Line of Sight check if( !lineOfSight( pos, socket->player()->pos()+Coord_cl( 0, 0, 13 ), WALLS_CHIMNEYS|TREES_BUSHES|ROOFING_SLANTED|LAVA_WATER|DOORS ) ) { socket->sysMessage( tr( "You can't see the target." ) ); return false; } } // Visibility check (Chars) if( pChar && pChar->isHidden() && !socket->player()->isGM() ) { socket->sysMessage( tr( "You can't see this character." ) ); return false; } // Visibility check (Items) if( pItem && ( ( pItem->visible() == 1 && !socket->player()->Owns( pItem ) ) || pItem->visible() == 2 ) && !socket->player()->isGM() ) { socket->sysMessage( tr( "You can't see this item." ) ); return false; } return true; }
//--------------------------------------------------------------------------- bool Team::teamLineOfSight(Stuff::Vector3D tPos, float extRad) { //----------------------------------------------------------- // For each member of the team, check LOS to point provided. for(size_t i = 0; i < rosterSize; i++) { MoverPtr obj = (MoverPtr)ObjectManager->getByWatchID(roster[i]); if(!obj->isDisabled() && !obj->isDestroyed() && (obj->getStatus() != OBJECT_STATUS_SHUTDOWN)) { Stuff::Vector3D distance; distance.Subtract(tPos, obj->getPosition()); float dist = distance.GetApproximateLength(); //Figure out altitude above minimum terrain altitude and look up in table. float baseElevation = MapData::waterDepth; if(MapData::waterDepth < Terrain::userMin) baseElevation = Terrain::userMin; float altitude = obj->getPosition().z - baseElevation; float altitudeIntegerRange = (Terrain::userMax - baseElevation) * 0.00390625f; int32_t altLevel = 0; if(altitudeIntegerRange > Stuff::SMALL) altLevel = altitude / altitudeIntegerRange; if(altLevel < 0) altLevel = 0; if(altLevel > 255) altLevel = 255; float radius = visualRangeTable[altLevel]; //Scouting specialty skill. if(obj->isMover()) { MoverPtr mover = (MoverPtr)obj; if(mover->pilot && mover->pilot->isScout()) radius += (radius * 0.2f); radius *= mover->getLOSFactor(); } if(dist <= (radius * 25.0f * worldUnitsPerMeter)) { if(lineOfSight(obj->getLOSPosition(), tPos, id, extRad, 0.0f, false)) return true; } } } //------------------------------------------------------------------------- // Check the lookout towers now. You can find them in special Buildings!! for(size_t spBuilding = 0; spBuilding < ObjectManager->numSpecialBuildings; spBuilding++) { if(ObjectManager->specialBuildings[spBuilding] && ObjectManager->specialBuildings[spBuilding]->getExists() && ObjectManager->specialBuildings[spBuilding]->isLookoutTower() && (ObjectManager->specialBuildings[spBuilding]->getTeamId() == id)) { GameObjectPtr obj = ObjectManager->specialBuildings[spBuilding]; if(!obj->isDisabled() && !obj->isDestroyed() && (obj->getStatus() != OBJECT_STATUS_SHUTDOWN)) { Stuff::Vector3D distance; distance.Subtract(tPos, obj->getPosition()); float dist = distance.GetApproximateLength(); //Figure out altitude above minimum terrain altitude and look up in table. float baseElevation = MapData::waterDepth; if(MapData::waterDepth < Terrain::userMin) baseElevation = Terrain::userMin; float altitude = obj->getPosition().z - baseElevation; float altitudeIntegerRange = (Terrain::userMax - baseElevation) * 0.00390625f; int32_t altLevel = 0; if(altitudeIntegerRange > Stuff::SMALL) altLevel = altitude / altitudeIntegerRange; if(altLevel < 0) altLevel = 0; if(altLevel > 255) altLevel = 255; float radius = visualRangeTable[altLevel]; //Scouting specialty skill. if(obj->isMover()) { MoverPtr mover = (MoverPtr)obj; if(mover->pilot && mover->pilot->isScout()) radius += (radius * 0.2f); radius *= mover->getLOSFactor(); } if(dist <= (radius * 25.0f * worldUnitsPerMeter)) { if(lineOfSight(obj->getLOSPosition(), tPos, id, 0.0f, obj->getAppearRadius(), false)) return true; } } } } return false; }
void dump_item(NXWCLIENT ps, PKGx08 *pp) // Item is dropped on ground or a character { if (ps == NULL) return; tile_st tile; NXWSOCKET s=ps->toInt(); P_CHAR pc=ps->currChar(); VALIDATEPC(pc); P_ITEM pi=pointers::findItemBySerial(pp->Iserial); if (!ISVALIDPI(pi)) { LogError("client sent bad itemserial %d",pp->Iserial); return; } if ( isCharSerial(pi->getContSerial()) && pi->getContSerial() != pc->getSerial32() ) { P_CHAR pc_i = pointers::findCharBySerial(pi->getContSerial()); if (ISVALIDPC(pc_i)) pc_i->sysmsg("Warning, backpack disappearing bug located!"); if (ps->isDragging()) { ps->resetDragging(); UpdateStatusWindow(s,pi); } pi->setContSerial( pi->getContSerial(true) ); pi->setPosition( pi->getOldPosition() ); pi->layer = pi->oldlayer; pi->Refresh(); } if (pi->magic == 2) { //Luxor -- not movable objects if (ps->isDragging()) { ps->resetDragging(); UpdateStatusWindow(s,pi); } pi->setContSerial( pi->getContSerial(true) ); pi->MoveTo( pi->getOldPosition() ); pi->layer = pi->oldlayer; pi->Refresh(); return; } if(pi!=NULL) { weights::NewCalc(pc); statwindow(pc,pc); } //Ripper...so order/chaos shields disappear when on ground. if( pi->getId()==0x1BC3 || pi->getId()==0x1BC4 ) { pc->playSFX( 0x01FE); staticeffect(DEREF_P_CHAR(pc), 0x37, 0x2A, 0x09, 0x06); pi->Delete(); return; } //test UOP blocking Tauriel 1-12-99 if (!pi->isInWorld()) { item_bounce6(ps,pi); return; } data::seekTile(pi->getId(), tile); if (!pc->IsGM() && ((pi->magic==2 || (tile.weight==255 && pi->magic!=1))&&!pc->canAllMove()) || ( (pi->magic==3 || pi->magic==4) && !(pi->getOwnerSerial32()==pc->getSerial32()))) { item_bounce6(ps,pi); return; } if (buffer[s][5]!=(unsigned char)'\xFF') { if (pi->amxevents[EVENT_IDROPINLAND]!=NULL) { g_bByPass = false; pi->MoveTo(pp->TxLoc,pp->TyLoc,pp->TzLoc); pi->amxevents[EVENT_IDROPINLAND]->Call( pi->getSerial32(), pc->getSerial32() ); if (g_bByPass) { pi->Refresh(); return; } } /* //<Luxor> g_bByPass = false; pi->runAmxEvent( EVENT_IDROPINLAND, pi->getSerial32(), pc->getSerial32() ); if (g_bByPass) { pi->Refresh(); return; } //</Luxor> */ NxwSocketWrapper sw; sw.fillOnline( pi ); for( sw.rewind(); !sw.isEmpty(); sw++ ) { SendDeleteObjectPkt( sw.getSocket(), pi->getSerial32() ); } pi->MoveTo(pp->TxLoc,pp->TyLoc,pp->TzLoc); pi->setContSerial(-1); P_ITEM p_boat = Boats->GetBoat(pi->getPosition()); if(ISVALIDPI(p_boat)) { pi->SetMultiSerial(p_boat->getSerial32()); } pi->Refresh(); } else { if ( !ItemDroppedOnChar(ps, pp, pi) ) { //<Luxor>: Line of sight check //This part avoids the circle of transparency walls bug //----- if ( !lineOfSight( pc->getPosition(), Loc( pp->TxLoc, pp->TyLoc, pp->TzLoc ) ) ) { ps->sysmsg(TRANSLATE("You cannot place an item there!")); Sndbounce5(s); if (ps->isDragging()) { ps->resetDragging(); UpdateStatusWindow(s,pi); } pi->setContSerial( pi->getContSerial(true) ); pi->setPosition( pi->getOldPosition() ); pi->layer = pi->oldlayer; pi->Refresh(); return; } //</Luxor> //<Luxor> Items count check if (!pc->IsGM()) { NxwItemWrapper si; si.fillItemsAtXY( pp->TxLoc, pp->TyLoc ); if (si.size() >= 2) { //Only 2 items permitted ps->sysmsg(TRANSLATE("There is not enough space there!")); Sndbounce5(s); if (ps->isDragging()) { ps->resetDragging(); UpdateStatusWindow(s,pi); } if (ISVALIDPI(pc->getBackpack())) { pi->setCont(pc->getBackpack()); pi->SetRandPosInCont(pc->getBackpack()); } else { pi->setContSerial( pi->getContSerial(true) ); pi->setPosition( pi->getOldPosition() ); } pi->layer = pi->oldlayer; pi->Refresh(); return; } } //</Luxor> } weights::NewCalc(pc); // Ison 2-20-99 statwindow(pc,pc); pc->playSFX( itemsfx(pi->getId()) ); //Boats ! if (pc->getMultiSerial32() > 0) //How can they put an item in a multi if they aren't in one themselves Cut lag by not checking everytime something is put down { P_ITEM multi = pointers::findItemBySerial( pc->getMultiSerial32() ); if (ISVALIDPI(multi)) { //setserial(DEREF_P_ITEM(pi),DEREF_P_ITEM(multi),7); pi->SetMultiSerial(multi->getSerial32()); } } //End Boats } }