game_sync/gamesrv/slotspkg/assemble/datatocli.go

112 lines
3.7 KiB
Go

package assemble
import (
"mongo.games.com/game/gamesrv/slotspkg/internal/module/shared"
"mongo.games.com/game/gamesrv/slotspkg/slots/types/cli"
"sort"
)
var CoinRate float64 = 10000
func DataToCli(response any) interface{} {
switch Response := response.(type) {
case *cli.SlotsEnterResponse:
tableInfo := TableInfo{}
var BetSizes []float64
for _, size := range Response.BetSizes {
BetSizes = append(BetSizes, float64(size)/10000)
}
sort.Slice(Response.BetChangeList, func(i, j int) bool { return Response.BetChangeList[i] < Response.BetChangeList[j] })
sort.Slice(Response.BetLevels, func(i, j int) bool { return Response.BetLevels[i] < Response.BetLevels[j] })
sort.Slice(BetSizes, func(i, j int) bool { return BetSizes[i] < BetSizes[j] })
tableInfo.BetConfig = BetConfig{
BetChangeList: Response.BetChangeList,
BetSize: BetSizes,
BetLevel: Response.BetLevels,
BetLines: Response.BetLines,
BetType: 1,
BetSizeIndex: Response.BetSizeIndex,
BetLevelIndex: Response.BetLevelIndex,
BetLineIndex: Response.BetLineIndex,
}
tableInfo.Coin = float64(Response.Coin) / CoinRate
//////////////////////////////////////////////////////////////
res := response2NodeTree(Response.NodeTree)
ress := []*shared.Result{res}
gameEnd := shared.GameEndDto{
Results: ress,
RoundReward: Response.NodeTree.Nodes[0].ChildrenTotalWin,
TotalBet: Response.NodeTree.BetCoin.GetCoin(),
//BetBeforeCoin: Response.Coin - Response.ActualWin + Response.ActualBet,
//BetAfterCoin: Response.Coin - Response.ActualWin,
FinalCoin: Response.Coin,
ActualBet: Response.NodeTree.Nodes[0].Bet,
ActualWin: Response.Coin,
}
tableInfo.SpinResult = SpinRes2Dto(gameEnd)
return tableInfo
case *cli.SlotsPlayResponse:
res := response2NodeTree(Response.NodeTree)
ress := []*shared.Result{res}
GameEnd := shared.GameEndDto{
Results: ress,
RoundReward: Response.NodeTree.Nodes[0].ChildrenTotalWin,
TotalBet: Response.NodeTree.BetCoin.GetCoin(),
BetBeforeCoin: Response.Coin - Response.ActualWin + Response.ActualBet,
BetAfterCoin: Response.Coin - Response.ActualWin,
FinalCoin: Response.Coin,
ActualBet: Response.ActualBet,
ActualWin: Response.ActualWin,
}
//a, _ := json.Marshal(GameEnd)
//logx.Error("GameEnd:", string(a))
return GameEnd
default:
}
return nil
}
func response2NodeTree(NodeTree *shared.LiteNodeTree) *shared.Result {
Special, customFortune, featureTotalWin := getDataByTheme(NodeTree)
var ass []*shared.ArrSpins
for _, formation := range NodeTree.Formations {
item := formation.DisplaySymbols
spinType := formation.NodeType
indexs := formation.RandPositions
//win := formation.Win
items := cli.ToItems(formation.MatrixForm, item)
var lineReward float64
for _, info := range formation.RewardInfo {
lineReward += info.Reward
}
if formation.NewNodeType != "" {
spinType = formation.NewNodeType
}
spin := &shared.ArrSpins{
GearID: spinType,
Items: items,
Index: indexs,
Reward: float64(featureTotalWin) + lineReward, ///total_win
LineReward: lineReward, ///line_win
RewardInfo: formation.RewardInfo,
FinalSymbols: cli.ToItems(formation.MatrixForm, formation.GetFinalSymbols()),
}
if Special[formation.NodeID] != nil {
spin.Special = Special[formation.NodeID]
}
ass = append(ass, spin)
}
res := &shared.Result{
ArrSpins: ass,
}
res.TotalRewardBase = ass[0].LineReward ///line_win
res.TotalReward = ass[0].Reward ///total_win
res.FreeNumTrigger = customFortune.FreeNumTrigger
res.FreeNumMax = customFortune.FreeNumMax
res.FreeNum = customFortune.FreeSpinNum
return res
}