From 7402d875de2c85fc7f26f8aa56b49406bca7bb7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=7E?= <158024940+xyy0411@users.noreply.github.com> Date: Sun, 12 Jan 2025 15:13:12 +0800 Subject: [PATCH] fix(niu): jj (#66) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add files via upload * 修改jj函数 --- niu/main.go | 40 +++++++++++++++++++++++----------------- niu/models.go | 18 ++++++++---------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/niu/main.go b/niu/main.go index c348061..ec5c7a6 100644 --- a/niu/main.go +++ b/niu/main.go @@ -170,7 +170,7 @@ func HitGlue(gid, uid int64, prop string) (string, error) { return "", ErrNoNiuNiuTwo } - messages, err := niuniu.processNiuNiuAction(prop) + messages, err := niuniu.processDaJiao(prop) if err != nil { return "", err } @@ -213,7 +213,7 @@ func JJ(gid, uid, adduser int64, prop string) (message string, adduserLength flo return "", 0, ErrCannotFight } - message, err = myniuniu.processJJuAction(adduserniuniu, prop) + message, err = myniuniu.processJJ(adduserniuniu, prop) if err != nil { return "", 0, err } @@ -227,6 +227,11 @@ func JJ(gid, uid, adduser int64, prop string) (message string, adduserLength flo } adduserLength = adduserniuniu.Length + + if err = db.setWordNiuNiu(gid, adduserniuniu); err != nil { + return "", 0, err + } + return } @@ -327,39 +332,40 @@ func ShowAuction(gid int64) ([]AuctionInfo, error) { // Auction 购买牛牛 func Auction(gid, uid int64, i int) (string, error) { - auction, err := db.getAllNiuNiuAuction(gid) + infos, err := db.getAllNiuNiuAuction(gid) if err != nil { return "", ErrNoNiuNiuINAuction } - err = wallet.InsertWalletOf(uid, -auction[i].Money) - if err != nil { + index := i - 1 + if err := wallet.InsertWalletOf(uid, -infos[index].Money); err != nil { return "", ErrNoMoney } niu, err := db.getWordNiuNiu(gid, uid) + if err != nil { - niu = &userInfo{ - UID: uid, - } + niu.UID = uid } - niu.Length = auction[i].Length - if auction[i].Money > 500 { + niu.Length = infos[index].Length + + if infos[index].Money >= 500 { niu.WeiGe += 2 - niu.Artifact += 2 + niu.Philter += 2 } - if err = db.setWordNiuNiu(gid, niu); err != nil { + if err = db.deleteNiuNiuAuction(gid, uint(index)); err != nil { return "", err } - err = db.deleteNiuNiuAuction(gid, auction[i].ID) - if err != nil { + + if err = db.setWordNiuNiu(gid, niu); err != nil { return "", err } - if auction[i].Money > 500 { - return fmt.Sprintf("恭喜你购买成功,当前长度为%.2fcm,此次购买将赠送你2个伟哥,2个媚药", - niu.Length), nil + + if infos[index].Money >= 500 { + return fmt.Sprintf("恭喜你购买成功,当前长度为%.2fcm,此次购买将赠送你2个伟哥,2个媚药", niu.Length), nil } + return fmt.Sprintf("恭喜你购买成功,当前长度为%.2fcm", niu.Length), nil } diff --git a/niu/models.go b/niu/models.go index b8f8daa..87db7dc 100644 --- a/niu/models.go +++ b/niu/models.go @@ -268,7 +268,7 @@ func (u *userInfo) purchaseItem(n int) (int, error) { return money, err } -func (u *userInfo) processNiuNiuAction(props string) (string, error) { +func (u *userInfo) processDaJiao(props string) (string, error) { var ( messages string info userInfo @@ -301,7 +301,7 @@ func (u *userInfo) processNiuNiuAction(props string) (string, error) { return messages, err } -func (u *userInfo) processJJuAction(adduserniuniu *userInfo, props string) (string, error) { +func (u *userInfo) processJJ(adduserniuniu *userInfo, props string) (string, error) { var ( fencingResult string f float64 @@ -378,7 +378,8 @@ func (db *model) getAllNiuNiuOfGroup(gid int64) (users, error) { var useras users err := db.sql.FindFor(fmt.Sprintf("%d", gid), &user, "", func() error { - useras = append(useras, &user) + newUser := user + useras = append(useras, &newUser) return nil }) return useras, err @@ -388,25 +389,22 @@ func (db *model) setNiuNiuAuction(gid int64, u *AuctionInfo) error { db.Lock() defer db.Unlock() num, err := db.sql.Count(fmt.Sprintf("auction_%d", gid)) - if err != nil { - num = 1 - } - u.ID = uint(num) - err = db.sql.Insert(fmt.Sprintf("auction_%d", gid), u) if err != nil { err = db.sql.Create(fmt.Sprintf("auction_%d", gid), &AuctionInfo{}) if err != nil { return err } - err = db.sql.Insert(fmt.Sprintf("auction_%d", gid), u) + num = -1 } + u.ID = uint(num + 1) + err = db.sql.Insert(fmt.Sprintf("auction_%d", gid), u) return err } func (db *model) deleteNiuNiuAuction(gid int64, id uint) error { db.Lock() defer db.Unlock() - return db.sql.Del(strconv.FormatInt(gid, 10), "WHERE ID = ?", id) + return db.sql.Del(fmt.Sprintf("auction_%d", gid), "WHERE id = ?", id) } func (db *model) getAllNiuNiuAuction(gid int64) ([]AuctionInfo, error) {