int Wing::handle_upgrade_wing(const Wing_Config &cfg, int is_auto_buy) { Money_Sub_Info money_sub_info(Money_Sub_Type(COPPER_ONLY), cfg.gold_cost, MONEY_SUB_UPGRADE_WING); int ret = player_self()->pack_try_sub_money(money_sub_info); if (0 != ret) return ret; int item_amount = player_self()->pack_calc_item(PACK_T_PACKAGE_INDEX, cfg.goods_cost.val_1); if (item_amount < cfg.goods_cost.val_2 && 0== is_auto_buy) { MSG_82100008 msg; msg.item_ids.push_back(cfg.goods_cost.val_1); THIS_SEND_TO_CLIENT(msg); return ERROR_ITEM_NOT_ENOUGH; } item_amount = item_amount > cfg.goods_cost.val_2 ? cfg.goods_cost.val_2 : item_amount; if (0 != item_amount) { Id_Amount pack_item(cfg.goods_cost.val_1, item_amount); ret = player_self()->pack_try_erase_item(PACK_T_PACKAGE_INDEX, pack_item); if (0 != ret) return ret; } if (item_amount < cfg.goods_cost.val_2) { int amount_need_to_buy = cfg.goods_cost.val_2 - item_amount; ret = player_self()->req_fast_buy_item_in_mall_tabs(cfg.goods_cost.val_1, amount_need_to_buy, 1); if (0 != ret) return ret; } if (item_amount > 0) { Id_Amount pack_item(cfg.goods_cost.val_1, item_amount); player_self()->pack_erase_item(PACK_T_PACKAGE_INDEX, pack_item, Lose_Item_DM_Info(ITEM_LOSE_UPGRADE_WING)); } player_self()->pack_sub_money(money_sub_info); int progress = wing_detail_->progress; int rate = wing_detail_->rate; if (handle_upgrade_wing(progress, rate, cfg)) { wing_detail_->lv += 1; wing_detail_->rate = 0; wing_detail_->progress = 0; wing_detail_->times = 0; } else { wing_detail_->rate = rate; wing_detail_->progress = progress; wing_detail_->times += 1; } wing_detail_->last_time = Time_Value::gettimeofday(); wing_detail_->detail_change(); if(item_amount) { player_self()->oper_activity_listen_type_common(OPER_ACTIVITY_ITEM_WING_USE_DAN, item_amount); } return 0; }
int msg_pack(message_t * msg, uint8_t * out, uint32_t * out_size) { uint32_t psize = 0; uint32_t outsize = 0; uint32_t left = 0; uint32_t i = 0; tlv_t * cur = NULL; message_t * cur_msg = NULL; if ((NULL == msg) || (NULL == out) || (NULL == out_size)) { printf("something is null\n"); return -1; } psize = msg_get_packed_size(msg); if (*out_size < psize) { return -1; } PUT32(out, htonl(MSG_MAGIC)); ADVANCE32(out); PUT32(out, htonl(msg->nitems)); ADVANCE32(out); left = (uint32_t) (*out_size - (sizeof(uint32_t) * 2)); for (i = 0; i < msg->nitems; i++) { cur = MSG_TLV(msg, i); PUT16(out, htons(cur->id)); ADVANCE16(out); PUT16(out, htons(cur->type)); ADVANCE16(out); if (TLV_TYPE_MSG == cur->type) { cur_msg = (message_t *)(cur->value); PUT16(out, htons((uint16_t)msg_get_packed_size(cur_msg))); ADVANCE16(out); } else { PUT16(out, htons(cur->length)); ADVANCE16(out); } left -= (sizeof(uint16_t) * 3); outsize = left; pack_item(cur, out, &outsize); out += outsize; left -= outsize; } *out_size = psize; return 0; }
void cDragdrop::drop_item(P_CLIENT ps) // Item is dropped { UOXSOCKET s=ps->GetSocket(); // CHARACTER cc=ps->GetCurrChar(); PKGx08 pkgbuf, *pp=&pkgbuf; pp->Iserial=LongFromCharPtr(buffer[s]+1); pp->TxLoc=ShortFromCharPtr(buffer[s]+5); pp->TyLoc=ShortFromCharPtr(buffer[s]+7); pp->TzLoc=buffer[s][9]; pp->Tserial=LongFromCharPtr(buffer[s]+10); //#define debug_dragg if (clientDimension[s]==3) { // UO:3D clients send SOMETIMES two dragg packets for a single dragg action. // sometimes we HAVE to swallow it, sometimes it has to be interpreted // if UO:3D specific item loss problems are reported, this is probably the code to blame :) // LB P_ITEM pi = FindItemBySerial(pp->Iserial); #ifdef debug_dragg if (i!=-1) { sprintf(temp, "%04x %02x %02x %01x %04x i-name: %s EVILDRAG-old: %i\n",pp->Iserial, pp->TxLoc, pp->TyLoc, pp->TzLoc, pp->Tserial, items[i].name, EVILDRAGG[s]); clConsole.send(temp); } else { sprintf(temp, "blocked: %04x %02x %02x %01x %04x i-name: invalid item EVILDRAG-old: %i\n",pp->Iserial, pp->TxLoc, pp->TyLoc, pp->TzLoc, pp->Tserial, EVILDRAGG[s]); clConsole.send(temp); } #endif if ( (pp->TxLoc==-1) && (pp->TyLoc==-1) && (pp->Tserial==0) && (EVILDRAGG[s]==1) ) { EVILDRAGG[s]=0; #ifdef debug_dragg clConsole.send("Swallow only\n"); #endif return; } // swallow! note: previous evildrag ! else if ( (pp->TxLoc==-1) && (pp->TyLoc==-1) && (pp->Tserial==0) && (EVILDRAGG[s]==0) ) { #ifdef debug_dragg clConsole.send("Bounce & Swallow\n"); #endif item_bounce6(ps, pi); return; } else if ( ( (pp->TxLoc!=-1) && (pp->TyLoc!=-1) && ( pp->Tserial!=-1)) || ( (isItemSerial(pp->Iserial)) && (isItemSerial(pp->Tserial)) ) ) EVILDRAGG[s]=1; // calc new evildrag value else EVILDRAGG[s]=0; } #ifdef debug_dragg else { ITEM i = calcItemFromSer( pp->Iserial ); if (i!=-1) { sprintf(temp, "blocked: %04x %02x %02x %01x %04x i-name: %s EVILDRAG-old: %i\n",pp->Iserial, pp->TxLoc, pp->TyLoc, pp->TzLoc, pp->Tserial, items[i].name, EVILDRAGG[s]); clConsole.send(temp); } } #endif if ( (buffer[s][10]>=0x40) && (buffer[s][10]!=0xff) ) pack_item(ps,pp); else dump_item(ps,pp); }
void drop_item(NXWCLIENT ps) // Item is dropped { if (ps == NULL) return; NXWSOCKET s=ps->toInt(); // CHARACTER cc=ps->currCharIdx(); PKGx08 pkgbuf, *pp=&pkgbuf; pp->Iserial=LongFromCharPtr(buffer[s]+1); pp->TxLoc=ShortFromCharPtr(buffer[s]+5); pp->TyLoc=ShortFromCharPtr(buffer[s]+7); pp->TzLoc=buffer[s][9]; pp->Tserial=LongFromCharPtr(buffer[s]+10); //#define debug_dragg if (clientDimension[s]==3) { // UO:3D clients send SOMETIMES two dragg packets for a single dragg action. // sometimes we HAVE to swallow it, sometimes it has to be interpreted // if UO:3D specific item loss problems are reported, this is probably the code to blame :) // LB P_ITEM pi = pointers::findItemBySerial(pp->Iserial); #ifdef debug_dragg if (ISVALIDPI(pi)) { sprintf(temp, "%04x %02x %02x %01x %04x i-name: %s EVILDRAG-old: %i\n",pp->Iserial, pp->TxLoc, pp->TyLoc, pp->TzLoc, pp->Tserial, pi->name, clientInfo[s]->evilDrag); ConOut(temp); } else { sprintf(temp, "blocked: %04x %02x %02x %01x %04x i-name: invalid item EVILDRAG-old: %i\n",pp->Iserial, pp->TxLoc, pp->TyLoc, pp->TzLoc, pp->Tserial, clientInfo[s]->evilDrag); ConOut(temp); } #endif if ( (pp->TxLoc==-1) && (pp->TyLoc==-1) && (pp->Tserial==0) && (clientInfo[s]->evilDrag) ) { clientInfo[s]->evilDrag=false; #ifdef debug_dragg ConOut("Swallow only\n"); #endif return; } // swallow! note: previous evildrag ! else if ( (pp->TxLoc==-1) && (pp->TyLoc==-1) && (pp->Tserial==0) && (!clientInfo[s]->evilDrag) ) { #ifdef debug_dragg ConOut("Bounce & Swallow\n"); #endif item_bounce6(ps, pi); return; } else if ( ( (pp->TxLoc!=-1) && (pp->TyLoc!=-1) && ( pp->Tserial!=-1)) || ( (pp->Iserial>=0x40000000) && (pp->Tserial>=0x40000000) ) ) clientInfo[s]->evilDrag=true; // calc new evildrag value else clientInfo[s]->evilDrag=false; } #ifdef debug_dragg else { P_ITEM pi = pointers::findItemBySerial(pp->Iserial); if (ISVALIDPI(pi)) { sprintf(temp, "blocked: %04x %02x %02x %01x %04x i-name: %s EVILDRAG-old: %i\n",pp->Iserial, pp->TxLoc, pp->TyLoc, pp->TzLoc, pp->Tserial, pi->name, clientInfo[s]->evilDrag); ConOut(temp); } } #endif // if ( (buffer[s][10]>=0x40) && (buffer[s][10]!=0xff) ) if ( isItemSerial(pp->Tserial) && (pp->Tserial != INVALID) ) // Invalid target => invalid container => put inWorld !!! pack_item(ps,pp); else dump_item(ps,pp); }