第一步:
nums -> 强化等级 16 17 18 19 20
weights -> 权重 越小越难出
function randomNumber() {
var nums = [16, 17, 18, 19, 20];
var weights = [1, 0.2, 0.05, 0.03, 0.01];
var totalWeight = weights.reduce(function (a, b) {
return a + b;
}, 0);
var rnd = Math.random() * totalWeight;
var sum = 0;
var result = null;
for (var i = 0; i < nums.length; i++) {
sum += weights[i];
if (rnd < sum) {
result = nums[i];
break;
}
}
return result;
}
第二步:
/**
* 随机增幅
*
* @param user 用户
*/
function randomIncrease(user) {
var inven = CUserCharacInfo_getCurCharacInvenW(user);
var equ = CInventory_GetInvenRef(inven, INVENTORY_TYPE_ITEM, 9);
var itemId = Inven_Item_getKey(equ)
var inUpgrade_level = equ.add(6).readU8();
var append = equ.add(17).readU16();
var characName = api_CUserCharacInfo_getCurCharacName(user);
var equipmentName = api_CItem_GetItemName(itemId);
if (equ != null) {
if (append != null && append != 0) {
if (inUpgrade_level < 31) {
var now = randomNumber();
equ.add(6).writeU8(now);
CUser_SendUpdateItemList(user, 1, 0, 9);
api_CUser_SendNotiPacketMessage(user, "[" + [characName] + "] 增幅 +" + now + " " + [equipmentName] + "成功", 0);
} else {
api_CUser_SendNotiPacketMessage(user, "使用失败:当前装备增幅等级,已到最大限制!", 1);
}
} else {
api_CUser_SendNotiPacketMessage(user, "使用失败:此装备无异界气息!", 1);
}
}
}
第三步:
if ('20230726 ' == item_id) {
// 随机增幅 ok
randomIncrease(user)
}
注:这个道具是随机增幅的 所以它也会降级 比如你现在是 19 你可能一用 就 16了
暂无讨论,说说你的看法吧