Ultralight/game/logic.go

53 lines
973 B
Go

package game
import (
"strings"
"math/rand/v2"
)
func (p *Player) AdjustStats(which string, newvalue int) *Player {
switch strings.ToLower(which) {
case "strength","str":
p.Stats.strength.value = newvalue
case "endurance","end":
p.Stats.endurance.value = newvalue
p.Stats.health.value = 5 + (5*newvalue)
p.Stats.health.current = 5 + (5*newvalue)
case "wisdom","wis":
p.Stats.wisdom.value = newvalue
case "intelligence","int":
p.Stats.intelligence.value = newvalue
case "dexterity","dex":
p.Stats.dexterity.value = newvalue
}
return p
}
func (p *Player) AdjustMoney(adjustment int) *Player {
p.Money += adjustment
return p
}
func (i Item) GetAmount() int {
chance := rand.IntN(100)+1
if chance <= i.drop {
return 2
} else {
return 1
}
}
func CreateItem(thisName string, rate int) Item {
return Item{
name: thisName,
drop: rate,
}
}
func (i Item) CreateSlot(number int) Slot {
return Slot {
amount: number,
content: i,
}
}