add support for multiple rolls

This commit is contained in:
wish
2023-02-15 00:13:43 +11:00
parent 9805991c95
commit 403b5f1c7f

View File

@@ -279,11 +279,25 @@ func handleMsgMhfPlayNormalGacha(s *Session, p mhfpacket.MHFPacket) {
return return
} }
switch entry.ItemType { switch entry.ItemType {
/*
valid types that need manual savedata manipulation:
- Ryoudan Points
- Bond Points
- Image Change Points
valid types that work (no additional code needed):
- Tore Points
- Festa Points
*/
case 17:
_ = addPointNetcafe(s, int(entry.ItemNumber)*-1)
case 19: case 19:
fallthrough fallthrough
case 20: case 20:
spendGachaCoin(s, entry.ItemNumber) spendGachaCoin(s, entry.ItemNumber)
case 21:
s.server.db.Exec("UPDATE users u SET frontier_points=frontier_points-$1 WHERE u.id=(SELECT c.user_id FROM characters c WHERE c.id=$2)", entry.ItemNumber, s.charID)
} }
rolls := int(entry.Rolls)
entries, err := s.server.db.Queryx(`SELECT id, weight, rarity FROM gacha_entries WHERE gacha_id = $1 AND entry_type = 100 ORDER BY weight DESC`, pkt.GachaID) entries, err := s.server.db.Queryx(`SELECT id, weight, rarity FROM gacha_entries WHERE gacha_id = $1 AND entry_type = 100 ORDER BY weight DESC`, pkt.GachaID)
if err != nil { if err != nil {
@@ -298,6 +312,7 @@ func handleMsgMhfPlayNormalGacha(s *Session, p mhfpacket.MHFPacket) {
result := rand.Float64() * totalWeight result := rand.Float64() * totalWeight
var rewardCount uint8 var rewardCount uint8
temp := byteframe.NewByteFrame() temp := byteframe.NewByteFrame()
for i := 0; i < rolls; i++ {
for _, entry := range gachaEntries { for _, entry := range gachaEntries {
result -= entry.Weight result -= entry.Weight
if result < 0 { if result < 0 {
@@ -318,11 +333,11 @@ func handleMsgMhfPlayNormalGacha(s *Session, p mhfpacket.MHFPacket) {
break break
} }
} }
}
bf.WriteUint8(rewardCount) bf.WriteUint8(rewardCount)
bf.WriteBytes(temp.Data()) bf.WriteBytes(temp.Data())
doAckBufSucceed(s, pkt.AckHandle, bf.Data()) doAckBufSucceed(s, pkt.AckHandle, bf.Data())
addGachaItem(s, rewards) addGachaItem(s, rewards)
// TODO: subtract gacha coins if spent
} }
func addGachaItem(s *Session, items []GachaItem) { func addGachaItem(s *Session, items []GachaItem) {