1
0
Fork 0

init: mvp

This commit is contained in:
Arthur Khachaturov 2024-08-17 01:20:24 +03:00
commit e307989b9f
No known key found for this signature in database
GPG key ID: CAC2B7EB6DF45D55
20 changed files with 835 additions and 0 deletions

View file

@ -0,0 +1,68 @@
package upgrades
import (
"encoding/json"
)
type Type string
const (
byUpgrade Type = "ByUpgrade"
referralCount Type = "ReferralCount"
moreReferralCount Type = "MoreReferralsCount"
subscribeTelegramChannel Type = "SubscribeTelegramChannel"
)
type Condition struct {
Type Type
ByUpgrade *ByUpgrade
ReferralCount *ReferralCount
MoreReferralCount *MoreReferralCount
SubscribeTelegramChannel *SubscribeTelegramChannel
}
type ByUpgrade struct {
Level int
UpgradeID string
}
type ReferralCount struct {
ReferralCount int
}
type MoreReferralCount struct {
MoreReferralCount int
}
type SubscribeTelegramChannel struct {
ChannelID int
Link string
}
func (c *Condition) UnmarshalJSON(d []byte) error {
type tmpStruct struct {
Type Type `json:"_type"`
ByUpgrade
ReferralCount
MoreReferralCount
SubscribeTelegramChannel
}
var tmp = new(tmpStruct)
if err := json.Unmarshal(d, tmp); err != nil {
return err
}
c.Type = tmp.Type
switch tmp.Type {
case byUpgrade:
c.ByUpgrade = &tmp.ByUpgrade
case referralCount:
c.ReferralCount = &tmp.ReferralCount
case moreReferralCount:
c.MoreReferralCount = &tmp.MoreReferralCount
case subscribeTelegramChannel:
c.SubscribeTelegramChannel = &tmp.SubscribeTelegramChannel
}
return nil
}

View file

@ -0,0 +1,37 @@
package upgrades
import (
"encoding/json"
)
func (u *Upgrades) RecurseUnavailable(item *Item) []*Item {
if item.IsAvailable || (item.Condition == nil || item.Condition.ByUpgrade == nil) {
return []*Item{item}
}
return append(u.RecurseUnavailable((*u)[item.Condition.ByUpgrade.UpgradeID]), item)
}
func (r *Response) UnmarshalJSON(data []byte) error {
type tempType Response
var temp *tempType = (*tempType)(r)
err := json.Unmarshal(data, temp)
if err != nil {
return err
}
r.Upgrades = make(Upgrades)
for _, i := range r.UpgradesArray {
r.Upgrades[i.ID] = i
}
return nil
}
func (r *Response) Tick() {
for _, e := range r.UpgradesArray {
e.Tick()
}
}

View file

@ -0,0 +1,76 @@
package upgrades
import "time"
type Item struct {
ID string `json:"id"`
Name string `json:"name"`
Price int `json:"price"`
ProfitPerHour int `json:"profitPerHour"`
Condition *Condition `json:"condition,omitempty"`
Section string `json:"section"`
Level int `json:"level"`
CurrentProfit int `json:"currentProfitPerHour"`
ProfitDelta int `json:"profitPerHourDelta"`
IsAvailable bool `json:"isAvailable"`
IsExpired bool `json:"isExpired"`
Cooldown *int `json:"cooldownSeconds"`
TotalCooldown *int `json:"totalCooldownSeconds"`
ReleaseAt *string `json:"releaseAt"`
ExpiresAt *string `json:"expiresAt"`
MaxLevel *int `json:"maxLevel"`
}
func (i *Item) Tick() {
if i.ExpiresAt != nil && !i.IsExpired && *i.ExpiresAt != "" {
expire_time, _ := time.Parse(time.RFC3339, *i.ExpiresAt)
if expire_time.Sub(time.Now()) < 0 {
i.IsExpired = true
}
}
if i.Cooldown != nil && *i.Cooldown > 0 {
(*i.Cooldown)--
}
}
type Section struct {
Name string `json:"section"`
IsAvailable bool `json:"isAvailable"`
}
type DailyCombo struct {
UpgradeIDs []string `json:"upgradeIds"`
BonusCoins int `json:"bonusCoins"`
IsClaimed bool `json:"isClaimed"`
RemainingSeconds int `json:"remainSeconds"`
}
type Upgrades map[string]*Item
type Response struct {
UpgradesArray []*Item `json:"upgradesForBuy"`
Upgrades Upgrades `json:"-"`
Sections []Section `json:"sections"`
DailyCombo DailyCombo `json:"dailyCombo"`
}
func (i *Item) PriceByLevel(level int) int {
return 0
}
func (i *Item) ProfitDeltaByLevel(level int) int {
return 0
}
func (i *Item) CooldownByLevel(level int) int {
return 0
}
// def profit_delta_by_level(self, level: int) -> int:
// return round(self.profit_per_hour_delta * 1.07 ** level)
//
// def price_by_level(self, level: int) -> int:
// return round(self.price * 1.05 ** ((level + 3) * level / 2))
//
// def cooldown_by_level(self, level: int) -> int:
// return self.cooldown_seconds * 2 ** level if self.cooldown_seconds else 0