Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(headhunt): add April Fools' Day special function #19

Merged
merged 3 commits into from
Apr 1, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions src/core/web/headhunt.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"strconv"
"strings"
"time"
)

func Headhunt(r *gin.Engine) {
Expand All @@ -31,18 +32,8 @@ func Headhunt(r *gin.Engine) {
var operator utils.Operator
name := ""
autoProb(&r6prob, &r5prob, &r4prob, &r3prob, &times)
allPro := r6prob + r5prob + r4prob + r3prob
rankRand := float64(getRandomInt(1, int64(allPro)))
if rankRand <= r6prob {
name = randChar(6)
reProb(&r6prob, &r5prob, &r4prob, &r3prob, &times)
} else if rankRand <= r6prob+r5prob {
name = randChar(5)
} else if rankRand <= r6prob+r5prob+r4prob {
name = randChar(4)
} else if rankRand <= r6prob+r5prob+r4prob+r3prob {
name = randChar(3)
}
name = genOpeName(&r6prob, &r5prob, &r4prob, &r3prob)

char := utils.GetOperatorByName(name)
operator.Profession = char.Profession
operator.Rarity = char.Rarity
Expand All @@ -56,6 +47,31 @@ func Headhunt(r *gin.Engine) {
})
}

// 生成干员
func genOpeName(r6prob *float64, r5prob *float64, r4prob *float64, r3prob *float64) string {
name := ""
// 愚人节应设定为全3星
now := time.Now()
_, month, day := now.Date()
if month == time.April && day == 1 {
name = randChar(3)
return name
}
allPro := *r6prob + *r5prob + *r4prob + *r3prob
rankRand := float64(getRandomInt(1, int64(allPro)))
if rankRand <= *r6prob {
name = randChar(6)
reProb(r6prob, r5prob, r4prob, r3prob, times)
cworld1 marked this conversation as resolved.
Show resolved Hide resolved
} else if rankRand <= *r6prob+*r5prob {
name = randChar(5)
} else if rankRand <= *r6prob+*r5prob+*r4prob {
name = randChar(4)
} else {
name = randChar(3)
}
return name
}

// 自动调整6星概率
func autoProb(r6prob, r5prob, r4prob, r3prob *float64, times *int) {
if *times > 50 {
Expand Down