修复圣遗物替换的小问题并优化

This commit is contained in:
UnKownOwO
2023-02-15 21:02:46 +08:00
parent 76b417f3f4
commit 555463f669
8 changed files with 97 additions and 90 deletions
+3 -22
View File
@@ -11,6 +11,7 @@ type Item struct {
func (p *Player) InitAllItem() {
for itemId, item := range p.ItemMap {
item.Guid = p.GetNextGameObjectGuid()
p.GameObjectGuidMap[item.Guid] = GameObject(item)
p.ItemMap[itemId] = item
}
}
@@ -23,28 +24,6 @@ func (p *Player) GetItemGuid(itemId uint32) uint64 {
return itemInfo.Guid
}
func (p *Player) GetItemIdByGuid(itemGuid uint64) uint32 {
for _, item := range p.ItemMap {
if item.Guid == itemGuid {
return item.ItemId
}
}
return 0
}
func (p *Player) GetItemIdByItemAndWeaponGuid(guid uint64) uint32 {
for _, item := range p.ItemMap {
if item.Guid == guid {
return item.ItemId
}
}
for _, weapon := range p.WeaponMap {
if weapon.Guid == guid {
return weapon.ItemId
}
}
return 0
}
func (p *Player) GetItemCount(itemId uint32) uint32 {
prop, ok := constant.VIRTUAL_ITEM_PROP[itemId]
if ok {
@@ -72,6 +51,7 @@ func (p *Player) AddItem(itemId uint32, count uint32) {
Count: 0,
Guid: p.GetNextGameObjectGuid(),
}
p.GameObjectGuidMap[itemInfo.Guid] = GameObject(itemInfo)
}
itemInfo.Count += count
p.ItemMap[itemId] = itemInfo
@@ -89,6 +69,7 @@ func (p *Player) CostItem(itemId uint32, count uint32) {
}
if itemInfo.Count == 0 {
delete(p.ItemMap, itemId)
delete(p.GameObjectGuidMap, itemInfo.Guid)
} else {
p.ItemMap[itemId] = itemInfo
}