Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
fangliuyu authored Sep 2, 2023
1 parent bc23be8 commit 8730c7b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
12 changes: 9 additions & 3 deletions plugin/mcfish/fish.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ func init() {
msg = "(你的鱼竿耐久仅剩" + strconv.Itoa(equipInfo.Durable) + ")"
}
} else {
fishNmae, err := dbdata.pickFishFor(uid)
fishNmaes, err := dbdata.pickFishFor(uid, fishNumber)
if err != nil {
ctx.SendChain(message.Text("[ERROR at fish.go.5.1]:", err))
return
}
if fishNmae == "" {
if len(fishNmaes) == 0 {
equipInfo.Durable = 0
err = dbdata.updateUserEquip(equipInfo)
if err != nil {
Expand All @@ -127,7 +127,13 @@ func init() {
ctx.SendChain(message.Text("美西螈因为没吃到鱼,钓鱼时一直没回来,你失去了美西螈"))
return
}
msg = "(美西螈吃掉了一条" + fishNmae + ")"
msg = "(美西螈吃掉了"
fishNumber = 0
for name, number := range fishNmaes {
fishNumber += number
msg += strconv.Itoa(number) + name + "、"
}
msg += ")"
}
waitTime := 120 / (equipInfo.Induce + 1)
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("你开始去钓鱼了,请耐心等待鱼上钩(预计要", time.Second*time.Duration(waitTime), ")"))
Expand Down
23 changes: 19 additions & 4 deletions plugin/mcfish/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@ func (sql *fishdb) setEquipFor(uid int64) (err error) {
return sql.db.Insert("fishState", &userInfo)
}

func (sql *fishdb) pickFishFor(uid int64) (fishName string, err error) {
func (sql *fishdb) pickFishFor(uid int64, number int) (fishNames map[string]int, err error) {
fishNames = make(map[string]int, 6)
name := strconv.FormatInt(uid, 10) + "Pack"
sql.Lock()
defer sql.Unlock()
Expand Down Expand Up @@ -499,7 +500,21 @@ func (sql *fishdb) pickFishFor(uid int64) (fishName string, err error) {
if len(fishTypes) == 0 {
return
}
randNumber := rand.Intn(len(fishTypes))
fishTypes[randNumber].Number--
return fishTypes[randNumber].Name, sql.db.Insert(name, &fishTypes[randNumber])
max := 0
for _, info := range fishTypes {
max += info.Number
}
if max < number {
number = max
}
for i := number; i > 0; i-- {
randNumber := rand.Intn(len(fishTypes))
fishTypes[randNumber].Number--
err = sql.db.Insert(name, &fishTypes[randNumber])
if err != nil {
return
}
fishNames[fishTypes[randNumber].Name]++
}
return
}

0 comments on commit 8730c7b

Please sign in to comment.