dp-s_doc/Start/Example/17.md

69 lines
2.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 史诗药剂 (贡献者: 倾泪寒 && 南瓜)
> 首先我们先在dp_s文件夹中建立一个项目文件夹 MyProject 方便管理
![Alt text](../../image/6.png)
> 然后我们建立一个新文件 史诗药剂.nut 用于编写我们的代码
> 然后我们在史诗药剂.nut中写入以下代码
```
/*
文件名:史诗药剂.nut
路径:MyProject/史诗药剂.nut
创建日期:2025-03-28 10:21
文件用途:史诗药剂
*/
//➢SS药剂的ID
EpicPotionID <- 2600006;
//➢默认的药剂增加倍率
EpicPotionOdds <- 0.1;
//➢指定玩家增加深渊爆率
EpicPotionlist <- {};
//角色ID增加个人深渊爆率
EpicPotionlist[1] <- 1;
Cb_GetItemRarity_Enter_Func["史诗药剂_逻辑"] <- function(args) {
local Addr = NativePointer(args[0]);
local VectorSize = (Addr.add(4).readU32() - Addr.readU32()) / 4;
// 遍历队伍成员,找到使用了史诗药剂的玩家
local userWithPotion = null;
for (local i = 0; i< VectorSize; i++) {
local elementAddr = NativePointer(Addr.readPointer()).add(i * 4);
local user = elementAddr.readPointer();
if (user && Sq_CallFunc(S_Ptr("0x865E994"), "int", ["pointer", "int", ], user, EpicPotionID) ) {
userWithPotion = User(user);
break;
}
}
if (userWithPotion && Haker.NextReturnAddress == "0x853583a") {
local partyobj = userWithPotion.GetParty();
// 检查是否单人
if (Sq_CallFunc(S_Ptr("0x0859A16A"), "int", ["pointer", ], partyobj.C_Object) == 1) {
local MaxRoll = NativePointer(args[1]).add(16).readU32();
local odds = EpicPotionOdds; // 默认药剂的增加几率
// 检查是否VIP玩家
local charac_no = userWithPotion.GetCID();
if (EpicPotionlist.rawin(charac_no)) {
odds = EpicPotionlist[charac_no];
}
// 计算新的roll值
args[2] = MathClass.getMin(args[2] + args[2] * odds, MaxRoll);
}
}
return args;
}
```
> 最后我们回到dp_s文件夹中打开Main.nut 加载我们刚才编写的逻辑 如果你已经开启过数据库连接池则不需要初始化数据库连接池的代码
```
sq_RunScript("MyProject/史诗药剂.nut");
```
> 至此一个简单的史诗药剂的逻辑就写完了