Skip to content

Commit

Permalink
Merge pull request #19 from cworld1/refactor/bot
Browse files Browse the repository at this point in the history
feat(headhunt): add April Fools' Day special function
  • Loading branch information
singer233 authored Apr 1, 2024
2 parents 45e4987 + 5cad59c commit 369321a
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions src/core/web/headhunt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
"arknights_bot/utils"
"crypto/rand"
"fmt"
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
"math/big"
"net/http"
"strconv"
"strings"
"time"

"github.com/gin-gonic/gin"
"github.com/spf13/viper"
)

func Headhunt(r *gin.Engine) {
Expand All @@ -29,20 +31,7 @@ func Headhunt(r *gin.Engine) {
var operators []utils.Operator
for i := 0; i < 10; i++ {
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, &times)
char := utils.GetOperatorByName(name)
operator.Profession = char.Profession
operator.Rarity = char.Rarity
Expand All @@ -56,6 +45,32 @@ func Headhunt(r *gin.Engine) {
})
}

// 生成干员
func genOpeName(r6prob *float64, r5prob *float64, r4prob *float64, r3prob *float64, times *int) string {
name := ""
// 愚人节应设定为全3星
now := time.Now()
_, month, day := now.Date()
if month == time.April && day == 1 {
name = randChar(3)
return 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 {
name = randChar(3)
}
return name
}

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

0 comments on commit 369321a

Please sign in to comment.