Better check in experience random algorithm

This commit is contained in:
2024-11-30 01:01:54 +08:00
parent 55b3a6f164
commit 312cf820ab
3 changed files with 9 additions and 7 deletions

View File

@ -99,7 +99,7 @@ func doCheckIn(c *fiber.Ctx) error {
if record, err := services.CheckIn(user); err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error())
} else {
services.AddEvent(user.ID, "dailySign", strconv.Itoa(int(record.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
services.AddEvent(user.ID, "checkIn", strconv.Itoa(int(record.ID)), c.IP(), c.Get(fiber.HeaderUserAgent))
return c.JSON(record)
}
}

View File

@ -6,7 +6,6 @@ import (
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
"git.solsynth.dev/hypernet/passport/pkg/internal/database"
"gorm.io/gorm"
"math"
"math/rand"
"time"
)
@ -38,9 +37,11 @@ const CheckInResultModifiersLength = 4
func CheckIn(user models.Account) (models.CheckInRecord, error) {
tier := rand.Intn(5)
expMax := 100 * (tier + 1)
expMin := 100
record := models.CheckInRecord{
ResultTier: tier,
ResultExperience: rand.Intn(int(math.Max(float64(tier), 1)*100)+1-100) + 100,
ResultExperience: rand.Intn(expMax-expMin) + expMin,
AccountID: user.ID,
}