diff --git a/game/builtin/item.go b/game/builtin/item.go deleted file mode 100644 index d3f0775..0000000 --- a/game/builtin/item.go +++ /dev/null @@ -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 -} diff --git a/game/builtin/item_errors.go b/game/builtin/item_errors.go deleted file mode 100644 index 25e14bd..0000000 --- a/game/builtin/item_errors.go +++ /dev/null @@ -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") -) diff --git a/game/builtin/item_options.go b/game/builtin/item_options.go deleted file mode 100644 index 55d43c7..0000000 --- a/game/builtin/item_options.go +++ /dev/null @@ -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 - } -} diff --git a/game/item.go b/game/item.go deleted file mode 100644 index 73742c3..0000000 --- a/game/item.go +++ /dev/null @@ -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 -}