package entity import ( "encoding/json" "mongo.games.com/game/gamesrv/slotspkg/internal/generic/errors" ) // CheatFormations replaces formation's symbols when its length is valid func (e *Entity) CheatFormations() { for _, originFormation := range e.OriginFormations { minLen := 0 if len(originFormation.Symbols) > len(originFormation.CheatSymbols) { minLen = len(originFormation.CheatSymbols) } else { minLen = len(originFormation.Symbols) } for symbolIdx := int64(0); symbolIdx < int64(minLen); symbolIdx++ { originFormation.Symbols[symbolIdx] = originFormation.CheatSymbols[symbolIdx] } } } // PrepareCheatFormations gets all cheat formations from data func (e *Entity) PrepareCheatFormations() { v, ok := e.Data[e.NodeDesc.NodeType] if !ok { return } result := v.(string) if result == "" { return } cheatSeqSymbols := make([][]int64, 0) err := json.Unmarshal([]byte(result), &cheatSeqSymbols) if err != nil { cheatSeqSymbols = make([][]int64, 0) symbols := make([]int64, 0) err = json.Unmarshal([]byte(result), &symbols) if err != nil { panic(errors.Error(err)) } cheatSeqSymbols = append(cheatSeqSymbols, symbols) } minLen := 0 if len(cheatSeqSymbols) > len(e.OriginFormations) { minLen = len(e.OriginFormations) } else { minLen = len(cheatSeqSymbols) } for formationIdx := int64(0); formationIdx < int64(minLen); formationIdx++ { cheatSymbols := cheatSeqSymbols[formationIdx] originFormation := e.OriginFormations[formationIdx] originFormation.CheatSymbols = make([]int64, len(cheatSymbols)) copy(originFormation.CheatSymbols, cheatSymbols) } }