63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package player
|
||
|
||
import (
|
||
"blazing/common/utils"
|
||
"blazing/logic/service/common"
|
||
"blazing/logic/service/fight/info"
|
||
"blazing/modules/blazing/model"
|
||
"math/rand"
|
||
"time"
|
||
|
||
"github.com/gogf/gf/v2/util/grand"
|
||
)
|
||
|
||
type baseplayer struct {
|
||
Info *model.PlayerInfo
|
||
//canFight uint32
|
||
FightC common.FightI //绑定战斗标识 替代本身的是否战斗标记 //IsFighting bool
|
||
*info.PlayerCaptureContext
|
||
}
|
||
|
||
// NewPlayerCaptureContext 创建用户捕捉上下文(每次登录调用)
|
||
func newbaseplayer() baseplayer {
|
||
rng := rand.New(rand.NewSource(time.Now().UnixNano() + int64(grand.Intn(1000000))))
|
||
ret := baseplayer{}
|
||
ret.PlayerCaptureContext = &info.PlayerCaptureContext{
|
||
rng,
|
||
1000,
|
||
0.10, // 15%衰减率
|
||
1,
|
||
make(map[int]int),
|
||
}
|
||
return ret
|
||
}
|
||
func (p *baseplayer) GetInfo() *model.PlayerInfo {
|
||
|
||
return p.Info
|
||
}
|
||
func (f *baseplayer) SetFightC(ff common.FightI) {
|
||
|
||
f.FightC = ff
|
||
}
|
||
|
||
func (f *baseplayer) GetPlayerCaptureContext() *info.PlayerCaptureContext {
|
||
return f.PlayerCaptureContext
|
||
}
|
||
|
||
func (f *baseplayer) FindPet(CatchTime uint32) (int, *model.PetInfo, bool) {
|
||
|
||
return utils.FindWithIndex(f.Info.PetList, func(item model.PetInfo) bool {
|
||
return item.CatchTime == CatchTime
|
||
})
|
||
}
|
||
|
||
// // 计算整数的二进制1的个数(Integer.bitCount)
|
||
// func bitsCount(n int) int {
|
||
// count := 0
|
||
// for n > 0 {
|
||
// count += n & 1
|
||
// n >>= 1
|
||
// }
|
||
// return count
|
||
// }
|