MergeBagItem Client Event: Merging Items in Game Backpacks
"[ClientEvent("MergeBagItem")]\n""public static void MergeBagItem(IPlayer player, int currentId, int targetId)\n"{\n""\tif (!player.HasData("id")) return;\n""\tplayer.GetData("id", out int id);\n""\tUser user = UserDao.FindUserById(id);\n""\tif (user == null) return;\n""\tBag currentBag = BagUtil.GetBagItemByBag(BagDao.FindBagById(currentId));\n""\tBag targetBag = BagUtil.GetBagItemByBag(BagDao.FindBagById(targetId));\n""\tif (currentBag == null || targetBag == null)\n""\t{\n"""\t\tNotifyEvent.SendNotify(player, "错误", "物品数据出现错误,请重试或联系管理员处理!", "error");\n"""\t\tOnPlayerOpenBag(player);\n"""\t\treturn;\n""\t}\n""\tif (!currentBag.Hash.Equals(targetBag.Hash))\n""\t{\n"""\t\tNotifyEvent.SendNotify(player, "错误", "物品数据出现错误,请重试或联系管理员处理!", "error");\n"""\t\tOnPlayerOpenBag(player);\n"""\t\treturn;\n""\t}\n""\tint checkId = 0;\n""\tif (currentBag.UserId != 0) checkId = currentBag.UserId;\n""\telse if (currentBag.HouseId != 0) checkId = currentBag.House.OwnerId;\n""\telse if (currentBag.VehicleId != 0) checkId = currentBag.Vehicle.UserId;\n""\tif (checkId != 0 && checkId != ServerUtil.GetPlayerId(player))\n""\t{\n"""\t\tNotifyEvent.SendNotify(player, "错误", "物品数据出现错误,请重试或联系管理员处理!", "error");\n"""\t\tOnPlayerOpenBag(player);\n"""\t\treturn;\n""\t}\n""\tif (targetBag.UserId != 0) checkId = targetBag.UserId;\n""\telse if (targetBag.HouseId != 0) checkId = targetBag.House.OwnerId;\n""\telse if (targetBag.VehicleId != 0) checkId = targetBag.Vehicle.UserId;\n""\tif (checkId != 0 && checkId != ServerUtil.GetPlayerId(player))\n""\t{\n"""\t\tNotifyEvent.SendNotify(player, "错误", "物品数据出现错误,请重试或联系管理员处理!", "error");\n"""\t\tOnPlayerOpenBag(player);\n"""\t\treturn;\n""\t}\n""\tint num = currentBag.Count;\n""\tif (currentBag.UserId != 0) checkId = currentBag.UserId;\n""\telse if (currentBag.HouseId != 0) checkId = currentBag.HouseId;\n""\telse if (currentBag.VehicleId != 0) checkId = currentBag.VehicleId;\n""\tbool canPut = BagUtil.checkCanPutInBag(targetBag.ColumnName, checkId, num * currentBag.Weight);\n""\tif (!canPut)\n""\t{\n"""\t\tNotifyEvent.SendNotify(player, "错误", "无法放置进入,您的背包太重或没有空槽!", "error");\n"""\t\tOnPlayerOpenBag(player);\n""\t}\n""\tif (currentBag.ColumnName.Equals(Const.GroundItems)) BagUtil.RemoveGroundItem(currentBag.Id);\n""\tBagDao.DeleteBagItem(currentBag);\n""\ttargetBag.Count += num;\n""\tBagDao.ModifyBag(targetBag);\n""\tif (targetBag.ColumnName.Equals(Const.GroundItems)) BagUtil.UpdateGroundItem(player, targetBag.Id);\n""\tOnPlayerOpenBag(player);\n""}}\n""This code snippet describes a client-side event called MergeBagItem which facilitates merging items within a game's backpack system. It ensures proper item validation, user authorization, and updates the inventory accordingly.
原文地址: https://www.cveoy.top/t/topic/pHwy 著作权归作者所有。请勿转载和采集!