240 lines
7.1 KiB
Go
240 lines
7.1 KiB
Go
package gatesofolympus
|
||
|
||
import (
|
||
"fmt"
|
||
"github.com/mohae/deepcopy"
|
||
"github.com/tomas-qstarrs/boost/mathx"
|
||
"mongo.games.com/game/gamesrv/slotspkg/internal/generic/key"
|
||
"mongo.games.com/game/gamesrv/slotspkg/internal/module/shared"
|
||
"mongo.games.com/game/gamesrv/slotspkg/slots/intf"
|
||
"mongo.games.com/game/gamesrv/slotspkg/slots/plugin/generic"
|
||
)
|
||
|
||
type PluginEliminate struct {
|
||
generic.PluginBase
|
||
}
|
||
|
||
type CustomEliminate struct {
|
||
LinkPositions []*shared.LinkPositions `json:"LinkPositions,omitempty"` //消除的位置
|
||
AppendSymbols [][]int64 `json:"AppendSymbols,omitempty"` //新增
|
||
FormattedSymbols [][]int64 `json:"FormattedSymbols,omitempty"` //最终的结果
|
||
LinePays []float64 `json:"LinePays,omitempty"` //赔付
|
||
WinCoins []float64 `json:"WinCoins,omitempty"` //输赢
|
||
MultiStr string `json:"multi_str,omitempty"`
|
||
SymbolsAbove []int64 `json:"symbols_above,omitempty"`
|
||
SymbolsBelow []int64 `json:"symbols_below,omitempty"`
|
||
}
|
||
|
||
type CustomMulti struct {
|
||
Multi int64
|
||
MultiStr string
|
||
MultiStrVal string
|
||
}
|
||
|
||
type CustomPay struct {
|
||
Pay float64
|
||
}
|
||
|
||
func (p *PluginEliminate) Theme() string {
|
||
return key.GatesOfOlympus
|
||
}
|
||
|
||
func (p *PluginEliminate) Customs() []interface{} {
|
||
return []interface{}{
|
||
&CustomEliminate{},
|
||
&CustomMulti{},
|
||
&CustomPay{},
|
||
&CustomFortune{},
|
||
}
|
||
}
|
||
|
||
func (p *PluginEliminate) OnInit(m intf.Master) {
|
||
if len(m.RootCustoms(&CustomMulti{})) == 0 {
|
||
m.AddRootFeature(&CustomMulti{})
|
||
}
|
||
}
|
||
|
||
func (p *PluginEliminate) OnEnterNode(m intf.Master) {
|
||
if m.Cursor().GetType() == key.BaseSpin {
|
||
m.RootCustom(&CustomMulti{}).(*CustomMulti).Multi = 0
|
||
}
|
||
}
|
||
|
||
func (p *PluginEliminate) BeforeSpin(m intf.Master) {
|
||
m.AddCursorFeature(&CustomPay{}).SetLifetime(1)
|
||
}
|
||
|
||
func (p *PluginEliminate) AfterSpin(m intf.Master) {
|
||
cursorFormation := m.CursorFormation()
|
||
formattedSymbols := cursorFormation.GetReelFormattedDisplaySymbols()
|
||
|
||
//f := getCustomFortune(m)
|
||
//if f.FreeSpinNum == 13 {
|
||
// formattedSymbols[0][0] = 1
|
||
// formattedSymbols[0][1] = 1
|
||
// formattedSymbols[0][2] = 1
|
||
//}
|
||
|
||
appendFormattedSymbols := deepcopy.Copy(formattedSymbols).([][]int64)
|
||
randPositions := cursorFormation.GetRandPositions()
|
||
|
||
// 清空基础赢钱
|
||
m.CursorFormation().SetWin(0)
|
||
|
||
// 获取custom
|
||
customMulti := m.RootCustom(&CustomMulti{}).(*CustomMulti)
|
||
customPay := m.CursorCustom(&CustomPay{}).(*CustomPay)
|
||
|
||
// 根据赔付计算multi type
|
||
linkPositions, _, linePays := m.TryLinkMatrixSymbols(1, formattedSymbols)
|
||
|
||
var multiType int64
|
||
if mathx.Sum(linePays) == 0 {
|
||
multiType = MultiplierNoWin
|
||
} else if m.Cursor().GetType() == key.BaseSpin {
|
||
multiType = MultiplierBaseSpin
|
||
} else {
|
||
multiType = MultiplierFreeSpin
|
||
}
|
||
|
||
// 替换Formation元素
|
||
for colIdx, symbols := range formattedSymbols {
|
||
for rowIdx, symbol := range symbols {
|
||
if symbol == SymbolMultiplier {
|
||
multiSymbol := Descx(m).RandMultiplier(multiType)
|
||
formattedSymbols[int64(colIdx)][5-int64(len(symbols))+int64(rowIdx)] = multiSymbol
|
||
}
|
||
}
|
||
}
|
||
|
||
// 存储 Formation元素
|
||
cursorFormation.SetFormattedDisplaySymbols(formattedSymbols)
|
||
defer cursorFormation.SetFormattedFinalSymbols(formattedSymbols)
|
||
|
||
// 有消除
|
||
for mathx.Sum(linePays) > 0 {
|
||
// 计算连线赢钱
|
||
lineNum := len(linePays)
|
||
winCoins := make([]float64, lineNum)
|
||
for lineIdx, pay := range linePays {
|
||
winCoins[lineIdx] = float64(m.Cursor().GetSingleBet()) * float64(pay)
|
||
}
|
||
|
||
// 标记消除的元素
|
||
for _, link := range linkPositions {
|
||
for _, pos := range link.Positions {
|
||
row, col := cursorFormation.PositionToCoords(pos)
|
||
formattedSymbols[col][row] = -1
|
||
}
|
||
}
|
||
// 删除消除的元素
|
||
for colIndex := range formattedSymbols {
|
||
for rowIndex := 0; rowIndex < len(formattedSymbols[colIndex]); rowIndex++ {
|
||
if formattedSymbols[colIndex][rowIndex] == -1 {
|
||
formattedSymbols[colIndex] = append(formattedSymbols[colIndex][:rowIndex], formattedSymbols[colIndex][rowIndex+1:]...)
|
||
rowIndex--
|
||
}
|
||
}
|
||
}
|
||
|
||
var symbolsAbove []int64
|
||
// 获取新得元素
|
||
for colIdx, symbols := range formattedSymbols {
|
||
// 获取后续(向前)元素
|
||
appendFormattedSymbols[colIdx] = cursorFormation.GetReelSymbols(int64(colIdx),
|
||
randPositions[colIdx]-int64(5-len(symbols)), int64(5-len(symbols)))
|
||
|
||
symbolsAbove = append(symbolsAbove, cursorFormation.GetReelSymbols(int64(colIdx),
|
||
randPositions[colIdx]-int64(5-len(symbols))-1, 1)...)
|
||
|
||
for rowIdx, symbol := range appendFormattedSymbols[colIdx] {
|
||
if symbol == SymbolMultiplier {
|
||
multiSymbol := Descx(m).RandMultiplier(multiType)
|
||
appendFormattedSymbols[colIdx][rowIdx] = multiSymbol
|
||
}
|
||
}
|
||
|
||
// 拼接剩余元素和后续(向前)元素
|
||
formattedSymbols[colIdx] = deepcopy.Copy(appendFormattedSymbols[colIdx]).([]int64)
|
||
formattedSymbols[colIdx] = append(formattedSymbols[colIdx], symbols...)
|
||
|
||
// randPosition 向前移动
|
||
randPositions[colIdx] -= int64(len(appendFormattedSymbols[colIdx]))
|
||
}
|
||
|
||
// 添加后续feature,这里是消除
|
||
m.AddCursorFeature(&CustomEliminate{
|
||
LinkPositions: linkPositions,
|
||
AppendSymbols: appendFormattedSymbols,
|
||
FormattedSymbols: formattedSymbols,
|
||
LinePays: linePays,
|
||
WinCoins: winCoins,
|
||
MultiStr: Descx(m).GetMultiStr(),
|
||
SymbolsAbove: symbolsAbove,
|
||
SymbolsBelow: m.CursorFormation().GetSymbolsBelow(),
|
||
}).SetLifetime(1)
|
||
|
||
// 累加pay
|
||
customPay.Pay += mathx.Sum(linePays)
|
||
|
||
// 连线
|
||
linkPositions, _, linePays = m.TryLinkMatrixSymbols(1, formattedSymbols)
|
||
}
|
||
|
||
// 增加multi
|
||
var multiSum int64
|
||
maxColCount := 0
|
||
|
||
// 找到最长的列数
|
||
for _, row := range formattedSymbols {
|
||
if len(row) > maxColCount {
|
||
maxColCount = len(row)
|
||
}
|
||
}
|
||
|
||
flatIndex := 0 // 当前符号在一维数组中的索引
|
||
|
||
customMulti.MultiStr = ""
|
||
customMulti.MultiStrVal = ""
|
||
|
||
// 遍历列优先的索引
|
||
for col := 0; col < maxColCount; col++ {
|
||
for row := 0; row < len(formattedSymbols); row++ {
|
||
rowSymbols := formattedSymbols[row] // 当前行的符号
|
||
if col < len(rowSymbols) { // 确保当前列存在
|
||
symbol := rowSymbols[col]
|
||
multi := Descx(m).GetMultiBySymbol(symbol)
|
||
multiSum += multi
|
||
|
||
// 打印 Symbol 和其一维索引
|
||
//fmt.Printf("Symbol: %s, Position in one-dimensional array: %d\n", symbol, flatIndex)
|
||
if multi > 0 {
|
||
if len(customMulti.MultiStr) > 0 {
|
||
customMulti.MultiStr += ";"
|
||
customMulti.MultiStrVal += ","
|
||
}
|
||
customMulti.MultiStr += fmt.Sprintf("%v~%v~%v", 12, flatIndex, multi)
|
||
customMulti.MultiStrVal += fmt.Sprintf("%v", multi)
|
||
}
|
||
flatIndex++ // 索引递增
|
||
}
|
||
}
|
||
}
|
||
|
||
if customPay.Pay > 0 {
|
||
if multiSum == 0 {
|
||
win := int64(customPay.Pay * float64(m.Cursor().GetSingleBet()))
|
||
m.CursorFeature(&CustomPay{}).SetWin(win)
|
||
} else {
|
||
customMulti.Multi += multiSum
|
||
var win int64
|
||
if customMulti.Multi == 0 {
|
||
win = int64(customPay.Pay * float64(m.Cursor().GetSingleBet()))
|
||
} else {
|
||
win = int64(customPay.Pay * float64(m.Cursor().GetSingleBet()) * float64(customMulti.Multi))
|
||
}
|
||
m.CursorFeature(&CustomPay{}).SetWin(win)
|
||
}
|
||
}
|
||
}
|