feat(sell): add hamster selling method

This commit is contained in:
2021-08-23 23:33:15 +02:00
parent 57e6f051f4
commit 5bae616ed2
2 changed files with 67 additions and 1 deletions

View File

@@ -3,9 +3,10 @@ package model
import (
"errors"
"fmt"
uuid "github.com/satori/go.uuid"
"hamster-tycoon/randomizer"
"time"
uuid "github.com/satori/go.uuid"
)
const (
@@ -58,6 +59,71 @@ func (h *Hamster) Die() {
h.Alive = false
}
func (h *Hamster) DeterminatePrice() int {
if h.Age >= 600 {
return 0
}
var price = 50
if h.Age >= 60 && h.Age <= 300 {
var diffAge, quotient int
diffAge = 300 - h.Age
quotient = diffAge / 25
price += quotient * 5
}
if h.Sexe == FEMALE {
price += 20
} else {
price -= 20
}
if h.Gestation {
if h.Age >= 500 {
price += 5
} else {
price += 20
}
}
if h.Age > 300 {
var diffAge, quotient int
diffAge = h.Age - 300
quotient = diffAge / 100
price += quotient * 10
}
switch h.ThirstLevel {
case Empty:
price -= 20
case AlmostEmpty:
price -= 10
case AlmostFull:
price += 10
case Full:
price += 20
}
switch h.HungerLevel {
case Empty:
price -= 20
case AlmostEmpty:
price -= 10
case AlmostFull:
price += 10
case Full:
price += 20
}
switch {
case h.GestationCooldown > 0 && h.GestationCooldown <= 7:
price -= 10
case h.GestationCooldown >= 8 && h.GestationCooldown <= 14:
price -= 5
case h.GestationCooldown > 15:
price -= 2
}
return price
}
func (h *Hamster) Grow() {
if h.Age >= MaxAge {
if randNumber(h.Age-MaxAge, 365) > 364 {