2025-09-22 17:22:08 +00:00
|
|
|
|
package model
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"blazing/cool"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// 资源采集计数表名
|
2025-09-23 15:22:41 +00:00
|
|
|
|
const TableNameResourceCollection = "talk"
|
2025-09-22 17:22:08 +00:00
|
|
|
|
|
2025-09-23 15:22:41 +00:00
|
|
|
|
func NewTalk() *Talk {
|
|
|
|
|
|
return &Talk{
|
2025-09-22 17:22:08 +00:00
|
|
|
|
Model: cool.NewModel(),
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ResourceCollection 记录玩家每种资源的采集计数
|
2025-09-23 15:22:41 +00:00
|
|
|
|
type Talk struct {
|
2025-09-22 17:22:08 +00:00
|
|
|
|
*cool.Model
|
|
|
|
|
|
PlayerID uint64 `gorm:"not null;index:idx_player_resource;comment:'所属玩家ID'" json:"player_id"`
|
2025-12-09 00:09:51 +08:00
|
|
|
|
TalkID uint32 `gorm:"not null;comment:'资源ID'" json:"talk_id"`
|
2025-12-08 19:50:54 +08:00
|
|
|
|
Count uint32 `gorm:"not null;comment:'采集计数'" json:"count"`
|
2025-09-22 17:22:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TableName 资源采集表名
|
2025-09-23 15:22:41 +00:00
|
|
|
|
func (*Talk) TableName() string {
|
2025-09-22 17:22:08 +00:00
|
|
|
|
return TableNameResourceCollection
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GroupName 资源采集表分组
|
2025-09-23 15:22:41 +00:00
|
|
|
|
func (*Talk) GroupName() string {
|
2025-09-22 17:22:08 +00:00
|
|
|
|
return "default"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// // 检查是否可以采集(未超过每日上限)
|
|
|
|
|
|
// func (rc *ResourceCollection) CanCollect(maxDaily uint32) bool {
|
|
|
|
|
|
// // 先检查是否需要重置计数
|
|
|
|
|
|
// rc.checkAndReset()
|
|
|
|
|
|
// return rc.CollectCnt < maxDaily
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// // 增加采集计数,返回是否成功
|
|
|
|
|
|
// func (rc *ResourceCollection) AddCollectCount(maxDaily uint32) bool {
|
|
|
|
|
|
// if !rc.CanCollect(maxDaily) {
|
|
|
|
|
|
// return false
|
|
|
|
|
|
// }
|
|
|
|
|
|
// rc.CollectCnt++
|
|
|
|
|
|
// return true
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// // 检查并重置每日计数
|
|
|
|
|
|
// func (rc *ResourceCollection) checkAndReset() {
|
|
|
|
|
|
// now := time.Now()
|
|
|
|
|
|
// if now.After(rc.DailyReset) {
|
|
|
|
|
|
// rc.CollectCnt = 0
|
|
|
|
|
|
// // 重置为明天24点
|
|
|
|
|
|
// rc.DailyReset = now.Truncate(24 * time.Hour).Add(24 * time.Hour)
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
2025-12-08 21:11:12 +08:00
|
|
|
|
// // ResourceConfig 资源配置信息(对应XML中的配置)
|
|
|
|
|
|
// type ResourceConfig struct {
|
|
|
|
|
|
// Type uint32 `json:"type"` // 资源类型ID
|
|
|
|
|
|
// MapID uint32 `json:"map_id"` // 所在地图ID
|
|
|
|
|
|
// Name string `json:"name"` // 资源名称
|
|
|
|
|
|
// CollectType string `json:"collect_type"` // 采集类型
|
|
|
|
|
|
// MaxDailyCnt uint32 `json:"max_daily_cnt"` // 每日最大采集次数
|
|
|
|
|
|
// Unit string `json:"unit"` // 单位
|
|
|
|
|
|
// Dir uint32 `json:"dir"` // 方向
|
|
|
|
|
|
// }
|
2025-09-22 17:22:08 +00:00
|
|
|
|
|
|
|
|
|
|
// 初始化创建表
|
|
|
|
|
|
func init() {
|
2025-09-23 15:22:41 +00:00
|
|
|
|
cool.CreateTable(&Talk{})
|
2025-09-22 17:22:08 +00:00
|
|
|
|
// 可以在这里加载资源配置
|
|
|
|
|
|
// LoadResourceConfigsFromXML()
|
|
|
|
|
|
}
|