laneya2

cave exploration game
git clone https://git.ce9e.org/laneya2.git

commit
c944e64295bfd86157f95ad9f660e61dbd8229a9
parent
680489b93400fa5fffc8c522d593e39c2b8c846b
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2024-09-29 10:19
refactor RemoveItem

Diffstat

M player.go 20 ++++++++++----------

1 files changed, 10 insertions, 10 deletions


diff --git a/player.go b/player.go

@@ -77,18 +77,18 @@ func (player *Player) AddItem(item string, amount uint) {
   77    77 	})
   78    78 }
   79    79 
   80    -1 func (player *Player) RemoveItem(item string, amount uint) bool {
   -1    80 func (player *Player) RemoveItem(item string) bool {
   81    81 	value, ok := player.Inventory[item]
   82    -1 	success := false
   -1    82 	success := true
   83    83 	if !ok {
   84    84 		value = 0
   85    -1 	} else if value <= amount {
   86    -1 		delete(player.Inventory, item)
   87    -1 		value = 0
   88    -1 	} else {
   89    -1 		value -= amount
   -1    85 		success = false
   -1    86 	} else if value > 1 {
   -1    87 		value -= 1
   90    88 		player.Inventory[item] = value
   91    -1 		success = true
   -1    89 	} else {
   -1    90 		value = 0
   -1    91 		delete(player.Inventory, item)
   92    92 	}
   93    93 
   94    94 	player.Enqueue(Message{
@@ -134,7 +134,7 @@ func (player *Player) PickupItems() {
  134   134 }
  135   135 
  136   136 func (player *Player) DropItem(item string) {
  137    -1 	if player.RemoveItem(item, 1) {
   -1   137 	if player.RemoveItem(item) {
  138   138 		player.Game.addToPile(player.Pos, item, 1)
  139   139 	}
  140   140 }
@@ -142,7 +142,7 @@ func (player *Player) DropItem(item string) {
  142   142 func (player *Player) UseItem(item string) {
  143   143 	if item == "potion" {
  144   144 		if player.Health < player.HealthTotal {
  145    -1 			if player.RemoveItem(item, 1) {
   -1   145 			if player.RemoveItem(item) {
  146   146 				player.Heal(10)
  147   147 			}
  148   148 		}