Skip to content

Commit

Permalink
fix(niu): jj (#66)
Browse files Browse the repository at this point in the history
* Add files via upload

* 修改jj函数
  • Loading branch information
xyy0411 authored Jan 12, 2025
1 parent 290ddf3 commit 7402d87
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
40 changes: 23 additions & 17 deletions niu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
18 changes: 8 additions & 10 deletions niu/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit 7402d87

Please sign in to comment.