移除物品概念,不合理
This commit is contained in:
parent
da77329799
commit
eb31ec3982
|
@ -1,51 +0,0 @@
|
||||||
package builtin
|
|
||||||
|
|
||||||
import "github.com/kercylan98/minotaur/utils/huge"
|
|
||||||
|
|
||||||
func NewItem[ID comparable](id ID, options ...ItemOption[ID]) *Item[ID] {
|
|
||||||
item := &Item[ID]{
|
|
||||||
id: id,
|
|
||||||
}
|
|
||||||
for _, option := range options {
|
|
||||||
option(item)
|
|
||||||
}
|
|
||||||
return item
|
|
||||||
}
|
|
||||||
|
|
||||||
type Item[ID comparable] struct {
|
|
||||||
id ID
|
|
||||||
stackLimit *huge.Int
|
|
||||||
count *huge.Int
|
|
||||||
}
|
|
||||||
|
|
||||||
func (slf *Item[ID]) GetID() ID {
|
|
||||||
return slf.id
|
|
||||||
}
|
|
||||||
|
|
||||||
func (slf *Item[ID]) GetCount() *huge.Int {
|
|
||||||
return slf.count
|
|
||||||
}
|
|
||||||
|
|
||||||
func (slf *Item[ID]) GetStackLimit() *huge.Int {
|
|
||||||
return slf.stackLimit
|
|
||||||
}
|
|
||||||
|
|
||||||
func (slf *Item[ID]) SetCount(count *huge.Int) {
|
|
||||||
if count.LessThan(huge.IntZero) {
|
|
||||||
slf.count = huge.IntZero.Copy()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
slf.count = count.Copy()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (slf *Item[ID]) ChangeCount(count *huge.Int) error {
|
|
||||||
newCount := slf.count.Copy().Add(count)
|
|
||||||
if newCount.LessThan(huge.IntZero) {
|
|
||||||
return ErrItemInsufficientQuantityDeduction
|
|
||||||
}
|
|
||||||
if newCount.GreaterThan(slf.stackLimit) {
|
|
||||||
return ErrItemStackLimit
|
|
||||||
}
|
|
||||||
slf.count = newCount
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
package builtin
|
|
||||||
|
|
||||||
import "errors"
|
|
||||||
|
|
||||||
var (
|
|
||||||
ErrItemInsufficientQuantityDeduction = errors.New("insufficient quantity deduction")
|
|
||||||
ErrItemStackLimit = errors.New("the number of items reaches the stacking limit")
|
|
||||||
)
|
|
|
@ -1,16 +0,0 @@
|
||||||
package builtin
|
|
||||||
|
|
||||||
import "github.com/kercylan98/minotaur/utils/huge"
|
|
||||||
|
|
||||||
type ItemOption[ID comparable] func(item *Item[ID])
|
|
||||||
|
|
||||||
// WithItemStackLimit 通过特定堆叠上限创建物品
|
|
||||||
// - 默认无限制
|
|
||||||
func WithItemStackLimit[ID comparable](stackLimit *huge.Int) ItemOption[ID] {
|
|
||||||
return func(item *Item[ID]) {
|
|
||||||
if stackLimit == nil || stackLimit.LessThanOrEqualTo(huge.IntZero) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
item.stackLimit = stackLimit
|
|
||||||
}
|
|
||||||
}
|
|
17
game/item.go
17
game/item.go
|
@ -1,17 +0,0 @@
|
||||||
package game
|
|
||||||
|
|
||||||
import "github.com/kercylan98/minotaur/utils/huge"
|
|
||||||
|
|
||||||
// Item 物品
|
|
||||||
type Item[ID comparable] interface {
|
|
||||||
// GetID 获取物品id
|
|
||||||
GetID() ID
|
|
||||||
// GetCount 获取物品数量
|
|
||||||
GetCount() *huge.Int
|
|
||||||
// GetStackLimit 获取堆叠上限
|
|
||||||
GetStackLimit() *huge.Int
|
|
||||||
// SetCount 设置物品数量
|
|
||||||
SetCount(count *huge.Int)
|
|
||||||
// ChangeCount 改变物品数量
|
|
||||||
ChangeCount(count *huge.Int) error
|
|
||||||
}
|
|
Loading…
Reference in New Issue