actor_genpool.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package genPool
  2. import (
  3. "f1-game/internal/code"
  4. "f1-game/internal/data"
  5. nameRemote "f1-game/internal/name/remote"
  6. "f1-game/internal/pb"
  7. ctime "github.com/cherry-game/cherry/extend/time"
  8. "github.com/cherry-game/cherry/net/parser/pomelo"
  9. )
  10. type actorGenPool struct {
  11. pomelo.ActorBase
  12. genPoolID int32 // 当前产出池ID
  13. }
  14. func newActorGenPool(genPoolID int32) actorGenPool {
  15. return actorGenPool{
  16. genPoolID: genPoolID,
  17. }
  18. }
  19. func (p *actorGenPool) OnInit() {
  20. p.Remote().Register(nameRemote.GenPoolConfrim, p.genPoolConfrim)
  21. }
  22. // 产出确认,返回实际可以产出的道具数量
  23. func (p *actorGenPool) genPoolConfrim(req *pb.AssetList) (*pb.AssetList, int32) {
  24. var (
  25. rsp = &pb.AssetList{}
  26. new = ctime.Now()
  27. )
  28. for _, asset := range req.List {
  29. // 不是产出池里面的稀有物品,则直接跳过
  30. if !data.GenPool.ContainIDItemID(p.genPoolID, asset.Id) {
  31. rsp.List = append(rsp.List, &pb.Asset{
  32. Id: asset.Id,
  33. Num: asset.Num,
  34. })
  35. continue
  36. }
  37. item, found := GetGenPoolItemCache(p.genPoolID, asset.Id)
  38. if !found {
  39. item = NewGenPoolItem(p.genPoolID, asset.Id)
  40. item.PeriodEndTime = item.CalcPeriodEndTime(new)
  41. SetGenPoolItemCache(item)
  42. } else {
  43. // 存在,检查是否可以重置
  44. if item.CheckReset(new) {
  45. item.ResetCount(new)
  46. }
  47. }
  48. // 有可获取数量
  49. if canCount := item.GetCanCount(asset.Num); canCount > 0 {
  50. item.AddCount(canCount)
  51. rsp.List = append(rsp.List, &pb.Asset{
  52. Id: item.ItemID,
  53. Num: canCount,
  54. })
  55. }
  56. }
  57. return rsp, code.OK
  58. }