Skip to content

Commit

Permalink
Merge branch 'sealdice:master' into refactor_api
Browse files Browse the repository at this point in the history
  • Loading branch information
PaienNate authored Oct 26, 2024
2 parents a039480 + fc01987 commit 04b9ca5
Showing 1 changed file with 53 additions and 44 deletions.
97 changes: 53 additions & 44 deletions dice/ext_dnd5e.go
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,9 @@ func RegisterBuiltinExtDnd5e(self *Dice) {
text = strings.TrimPrefix(text, ",")
// 情况1,名字是自己
name = mctx.Player.Name
// replace any space or \n with _
name = strings.ReplaceAll(name, " ", "_")
name = strings.ReplaceAll(name, "\n", "_")
// 情况2,名字是自己,没有加值
if !exprExists {
val = int64(ds.Roll(nil, 20, 0))
Expand Down Expand Up @@ -1349,61 +1352,67 @@ func RegisterBuiltinExtDnd5e(self *Dice) {
setInitNextRoundVars(ctx, lst, round)
ReplyToSender(ctx, msg, DiceFormatTmpl(ctx, "DND:先攻_下一回合"))
case "del", "rm":
names := cmdArgs.Args[1:]
riList := (RIList{}).LoadByCurGroup(ctx)
newList := RIList{}
tryDeleteMembersInInitList := func(deleteNames []string, riList RIList) (newList RIList, textOut strings.Builder, ok bool) {
round, _ := VarGetValueInt64(ctx, "$g回合数")
round %= int64(len(riList))
toDeleted := map[string]bool{}
for _, i := range deleteNames {
toDeleted[i] = true
}

round, _ := VarGetValueInt64(ctx, "$g回合数")
round %= int64(len(riList))
delCounter := 0

toDeleted := map[string]bool{}
for _, i := range names {
toDeleted[i] = true
}
preCurrent := 0 // 每有一个在当前单位前面的单位被删除, 当前单位下标需要减 1
for index, i := range riList {
if !toDeleted[i.name] {
newList = append(newList, i)
} else {
delCounter++
textOut.WriteString(fmt.Sprintf("%2d. %s\n", delCounter, i.name))

textOut := strings.Builder{}
textOut.WriteString(DiceFormatTmpl(ctx, "DND:先攻_移除_前缀"))
delCounter := 0
if int64(index) < round {
preCurrent++
}
}
}
current := *riList[round]
currentDeleted := toDeleted[current.name]

preCurrent := 0 // 每有一个在当前单位前面的单位被删除, 当前单位下标需要减 1
for index, i := range riList {
if !toDeleted[i.name] {
newList = append(newList, i)
} else {
delCounter++
textOut.WriteString(fmt.Sprintf("%2d. %s\n", delCounter, i.name))
round -= int64(preCurrent)
if round >= int64(len(newList)) {
round = 0
}
VarSetValueInt64(ctx, "$g回合数", round)

if int64(index) < round {
preCurrent++
}
if delCounter == 0 {
textOut.WriteString("- 没有找到任何单位\n")
return newList, textOut, false
}
}
current := *riList[round]
currentDeleted := toDeleted[current.name]

round -= int64(preCurrent)
if round >= int64(len(newList)) {
round = 0
newList.SaveToGroup(ctx)
if currentDeleted {
if len(newList) == 0 {
textOut.WriteString(DiceFormatTmpl(ctx, "DND:先攻_清除列表"))
} else {
setInitNextRoundVars(ctx, newList, round)
// Note(Xiangze Li): 这是为了让回合结束的角色显示为被删除的角色,而不是当前角色的上一个
VarSetValueStr(ctx, "$t当前回合角色名", current.name)
VarSetValueStr(ctx, "$t当前回合at", AtBuild(current.uid))
textOut.WriteString(DiceFormatTmpl(ctx, "DND:先攻_下一回合"))
}
}
return newList, textOut, true
}
VarSetValueInt64(ctx, "$g回合数", round)

if delCounter == 0 {
textOut.WriteString("- 没有找到任何单位\n")
nameWithSpace, _ := cmdArgs.EatPrefixWith("del", "rm")
riList := (RIList{}).LoadByCurGroup(ctx)
_, textOut, ok := tryDeleteMembersInInitList([]string{nameWithSpace}, riList)
if !ok {
_, textOut, _ = tryDeleteMembersInInitList(cmdArgs.Args[1:], riList)
}
textToSend := DiceFormatTmpl(ctx, "DND:先攻_移除_前缀") + textOut.String()

newList.SaveToGroup(ctx)
if currentDeleted {
if len(newList) == 0 {
textOut.WriteString(DiceFormatTmpl(ctx, "DND:先攻_清除列表"))
} else {
setInitNextRoundVars(ctx, newList, round)
// Note(Xiangze Li): 这是为了让回合结束的角色显示为被删除的角色,而不是当前角色的上一个
VarSetValueStr(ctx, "$t当前回合角色名", current.name)
VarSetValueStr(ctx, "$t当前回合at", AtBuild(current.uid))
textOut.WriteString(DiceFormatTmpl(ctx, "DND:先攻_下一回合"))
}
}
ReplyToSender(ctx, msg, textOut.String())
ReplyToSender(ctx, msg, textToSend)
case "set":
name := cmdArgs.GetArgN(2)
exists := name != ""
Expand Down

0 comments on commit 04b9ca5

Please sign in to comment.