From eb31ec39827ff781e3b369a1900cefa7db58d2a0 Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Wed, 10 May 2023 10:34:13 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E7=89=A9=E5=93=81=E6=A6=82?= =?UTF-8?q?=E5=BF=B5=EF=BC=8C=E4=B8=8D=E5=90=88=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game/builtin/item.go | 51 ------------------------------------ game/builtin/item_errors.go | 8 ------ game/builtin/item_options.go | 16 ----------- game/item.go | 17 ------------ 4 files changed, 92 deletions(-) delete mode 100644 game/builtin/item.go delete mode 100644 game/builtin/item_errors.go delete mode 100644 game/builtin/item_options.go delete mode 100644 game/item.go 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 -}