| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package genPool
- import (
- "f1-game/internal/code"
- "f1-game/internal/data"
- nameRemote "f1-game/internal/name/remote"
- "f1-game/internal/pb"
- ctime "github.com/cherry-game/cherry/extend/time"
- "github.com/cherry-game/cherry/net/parser/pomelo"
- )
- type actorGenPool struct {
- pomelo.ActorBase
- genPoolID int32 // 当前产出池ID
- }
- func newActorGenPool(genPoolID int32) actorGenPool {
- return actorGenPool{
- genPoolID: genPoolID,
- }
- }
- func (p *actorGenPool) OnInit() {
- p.Remote().Register(nameRemote.GenPoolConfrim, p.genPoolConfrim)
- }
- // 产出确认,返回实际可以产出的道具数量
- func (p *actorGenPool) genPoolConfrim(req *pb.AssetList) (*pb.AssetList, int32) {
- var (
- rsp = &pb.AssetList{}
- new = ctime.Now()
- )
- for _, asset := range req.List {
- // 不是产出池里面的稀有物品,则直接跳过
- if !data.GenPool.ContainIDItemID(p.genPoolID, asset.Id) {
- rsp.List = append(rsp.List, &pb.Asset{
- Id: asset.Id,
- Num: asset.Num,
- })
- continue
- }
- item, found := GetGenPoolItemCache(p.genPoolID, asset.Id)
- if !found {
- item = NewGenPoolItem(p.genPoolID, asset.Id)
- item.PeriodEndTime = item.CalcPeriodEndTime(new)
- SetGenPoolItemCache(item)
- } else {
- // 存在,检查是否可以重置
- if item.CheckReset(new) {
- item.ResetCount(new)
- }
- }
- // 有可获取数量
- if canCount := item.GetCanCount(asset.Num); canCount > 0 {
- item.AddCount(canCount)
- rsp.List = append(rsp.List, &pb.Asset{
- Id: item.ItemID,
- Num: canCount,
- })
- }
- }
- return rsp, code.OK
- }
|