|
楼主 |
发表于 2025-4-8 21:51:44
|
显示全部楼层
//获取角色仓库
var CUserCharacInfo_getCurCharacCargoW = new NativeFunction(ptr(0x008151A94), 'pointer', ['pointer'], {"abi":"sysv"});
//获取角色背包
var CUserCharacInfo_getCurCharacInvenW = new NativeFunction(ptr(0x80DA28E), 'pointer', ['pointer'], {"abi":"sysv"});
//获取背包槽中的道具
var CInventory_getInvenRef = new NativeFunction(ptr(0x84FC1DE), 'pointer', ['pointer', 'int', 'int'], {"abi":"sysv"});
//获取背包中道具item_id
var Inven_Item_getKey = new NativeFunction(ptr(0x850D14E), 'int', ['pointer'], {"abi":"sysv"});
//检查仓库是否存在物品
var CCargo_check_item_exist = new NativeFunction(ptr(0x0850BC14), 'int', ['pointer', 'int'], {"abi":"sysv"});
//获取道具附加信息
var Inven_Item_get_add_info = new NativeFunction(ptr(0x80F783A), 'int', ['pointer'], {"abi":"sysv"});
var Inven_Item_set_add_info = new NativeFunction(ptr(0x80CB884), 'int', ['pointer', 'int'], {"abi":"sysv"});
//检查物品堆叠上限
var checkStackableLimit = new NativeFunction(ptr(0x08501A79), 'int', ['int', 'int'], {"abi":"sysv"});
//将物品存入仓库
var CCargo_insert_item = new NativeFunction(ptr(0x0850B400), 'int', ['pointer', 'pointer'], {"abi":"sysv"});
//删除背包槽中的道具
var Inven_Item_reset = new NativeFunction(ptr(0x080CB7D8), 'int', ['pointer'], {"abi":"sysv"});
//通知客户端道具更新(客户端指针, 通知方式[仅客户端=1, 世界广播=0, 小队=2, war room=3], itemSpace[装备=0, 时装=1], 道具所在的背包槽)
var CUser_SendUpdateItemList = new NativeFunction(ptr(0x867C65A), 'int', ['pointer', 'int', 'int', 'int'], {"abi":"sysv"});
// 通知客户端更新背包栏
var CUser_send_itemspace = new NativeFunction(ptr(0x865DB6C), 'int', ['pointer', 'int'], {"abi":"sysv"});
// 一键入库
function moveToCargo(user) {
const cargo = CUserCharacInfo_getCurCharacCargoW(user);
const inven = CUserCharacInfo_getCurCharacInvenW(user);
// 物品槽范围: 57-152 (材料、消耗品栏)
const INVENTORY_SLOT_START = 57;
const INVENTORY_SLOT_END = 152;
for (var slot = INVENTORY_SLOT_START; slot <= INVENTORY_SLOT_END; slot++) {
const inventoryItem = CInventory_getInvenRef(inven, INVENTORY_TYPE_ITEM, slot);
const itemId = Inven_Item_getKey(inventoryItem); // 获取物品ID
// 如果物品ID无效,跳过当前循环
if (itemId <= 0) continue;
const itemExistsInCargo = CCargo_check_item_exist(cargo, itemId);
// 如果仓库中没有该物品,跳过
if (itemExistsInCargo == -1) continue;
// 获取仓库中对应物品的指针和数量
const cargoItemPointer = cargo.add(4).readPointer().add(61 * itemExistsInCargo);
const cargoItemId = cargo.add(4).readPointer().add(61 * itemExistsInCargo + 2).readU32();
const cargoItemCount = Inven_Item_get_add_info(cargoItemPointer);
const inventoryItemCount = Inven_Item_get_add_info(inventoryItem);
// 检查物品堆叠是否超过上限
const canStack = checkStackableLimit(cargoItemId, cargoItemCount + inventoryItemCount);
// 如果超过堆叠上限,提示并跳过
if (canStack == 0) {
const itemName = api_CItem_GetItemName(cargoItemId);
api_CUser_SendNotiPacketMessage(user, `${itemName} 超过堆叠上限,无法放入!`, 1);
continue;
}
// 将物品存入仓库
const insertResult = CCargo_insert_item(cargo, inventoryItem);
// 如果存入成功,更新背包和仓库
if (insertResult >= 0) {
Inven_Item_reset(inventoryItem); // 重置背包物品
CUser_SendUpdateItemList(user, 1, 0, slot); // 更新背包
CUser_send_itemspace(user, 2); // 更新仓库
}
}
} |
|