2024-02-11 00:27:08 +00:00
|
|
|
package fortnite
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"slices"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/ectrc/snow/aid"
|
|
|
|
"github.com/ectrc/snow/storage"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2024-02-19 04:07:40 +00:00
|
|
|
DataClient *dataClient
|
2024-02-11 00:27:08 +00:00
|
|
|
)
|
|
|
|
|
2024-02-19 04:07:40 +00:00
|
|
|
type dataClient struct {
|
2024-02-11 00:27:08 +00:00
|
|
|
h *http.Client
|
2024-03-10 18:16:42 +00:00
|
|
|
FortniteSets map[string]*APISetDefinition `json:"sets"`
|
|
|
|
FortniteItems map[string]*APICosmeticDefinition `json:"items"`
|
|
|
|
FortniteItemsWithDisplayAssets map[string]*APICosmeticDefinition `json:"-"`
|
|
|
|
FortniteItemsWithFeaturedImage []*APICosmeticDefinition `json:"-"`
|
|
|
|
TypedFortniteItems map[string][]*APICosmeticDefinition `json:"-"`
|
|
|
|
TypedFortniteItemsWithDisplayAssets map[string][]*APICosmeticDefinition `json:"-"`
|
2024-02-19 01:49:14 +00:00
|
|
|
SnowVariantTokens map[string]*FortniteVariantToken `json:"variants"`
|
2024-02-19 04:07:40 +00:00
|
|
|
StorefrontCosmeticOfferPriceLookup map[string]map[string]int `json:"-"`
|
|
|
|
StorefrontDailyItemCountLookup []struct{Season int;Items int} `json:"-"`
|
|
|
|
StorefrontWeeklySetCountLookup []struct{Season int;Sets int} `json:"-"`
|
|
|
|
StorefrontCurrencyOfferPriceLookup map[string]map[int]int `json:"-"`
|
2024-02-19 16:08:37 +00:00
|
|
|
StorefrontCurrencyMultiplier map[string]float64 `json:"-"`
|
2024-03-10 18:16:42 +00:00
|
|
|
SnowSeason *SnowSeasonDefinition `json:"season"`
|
2024-02-11 00:27:08 +00:00
|
|
|
}
|
|
|
|
|
2024-02-19 04:07:40 +00:00
|
|
|
func NewDataClient() *dataClient {
|
|
|
|
return &dataClient{
|
2024-02-11 00:27:08 +00:00
|
|
|
h: &http.Client{},
|
2024-03-10 18:16:42 +00:00
|
|
|
FortniteItems: make(map[string]*APICosmeticDefinition),
|
|
|
|
FortniteSets: make(map[string]*APISetDefinition),
|
|
|
|
FortniteItemsWithDisplayAssets: make(map[string]*APICosmeticDefinition),
|
|
|
|
FortniteItemsWithFeaturedImage: []*APICosmeticDefinition{},
|
|
|
|
TypedFortniteItems: make(map[string][]*APICosmeticDefinition),
|
|
|
|
TypedFortniteItemsWithDisplayAssets: make(map[string][]*APICosmeticDefinition),
|
2024-02-19 01:49:14 +00:00
|
|
|
SnowVariantTokens: make(map[string]*FortniteVariantToken),
|
2024-02-19 04:07:40 +00:00
|
|
|
StorefrontDailyItemCountLookup: []struct{Season int;Items int}{
|
|
|
|
{2, 4},
|
|
|
|
{4, 6},
|
|
|
|
{13, 10},
|
|
|
|
},
|
|
|
|
StorefrontWeeklySetCountLookup: []struct{Season int;Sets int}{
|
|
|
|
{2, 2},
|
|
|
|
{4, 3},
|
|
|
|
{13, 5},
|
|
|
|
},
|
|
|
|
StorefrontCosmeticOfferPriceLookup: map[string]map[string]int{
|
|
|
|
"EFortRarity::Legendary": {
|
|
|
|
"AthenaCharacter": 2000,
|
2024-03-10 18:16:42 +00:00
|
|
|
"AthenaBackpack": 300,
|
2024-02-19 04:07:40 +00:00
|
|
|
"AthenaPickaxe": 1500,
|
|
|
|
"AthenaGlider": 1800,
|
|
|
|
"AthenaDance": 500,
|
|
|
|
"AthenaItemWrap": 800,
|
|
|
|
},
|
|
|
|
"EFortRarity::Epic": {
|
|
|
|
"AthenaCharacter": 1500,
|
2024-03-10 18:16:42 +00:00
|
|
|
"AthenaBackpack": 250,
|
2024-02-19 04:07:40 +00:00
|
|
|
"AthenaPickaxe": 1200,
|
|
|
|
"AthenaGlider": 1500,
|
|
|
|
"AthenaDance": 800,
|
|
|
|
"AthenaItemWrap": 800,
|
|
|
|
},
|
|
|
|
"EFortRarity::Rare": {
|
|
|
|
"AthenaCharacter": 1200,
|
2024-03-10 18:16:42 +00:00
|
|
|
"AthenaBackpack": 200,
|
2024-02-19 04:07:40 +00:00
|
|
|
"AthenaPickaxe": 800,
|
|
|
|
"AthenaGlider": 800,
|
|
|
|
"AthenaDance": 500,
|
|
|
|
"AthenaItemWrap": 600,
|
|
|
|
},
|
|
|
|
"EFortRarity::Uncommon": {
|
|
|
|
"AthenaCharacter": 800,
|
|
|
|
"AthenaBackpack": 200,
|
|
|
|
"AthenaPickaxe": 500,
|
|
|
|
"AthenaGlider": 500,
|
|
|
|
"AthenaDance": 200,
|
|
|
|
"AthenaItemWrap": 300,
|
|
|
|
},
|
|
|
|
"EFortRarity::Common": {
|
|
|
|
"AthenaCharacter": 500,
|
|
|
|
"AthenaBackpack": 200,
|
|
|
|
"AthenaPickaxe": 500,
|
|
|
|
"AthenaGlider": 500,
|
|
|
|
"AthenaDance": 200,
|
|
|
|
"AthenaItemWrap": 300,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
StorefrontCurrencyOfferPriceLookup: map[string]map[int]int{
|
|
|
|
"USD": {
|
|
|
|
1000: 999,
|
|
|
|
2800: 2499,
|
|
|
|
5000: 3999,
|
2024-02-19 16:08:37 +00:00
|
|
|
7500: 5999,
|
2024-02-19 04:07:40 +00:00
|
|
|
13500: 9999,
|
|
|
|
},
|
|
|
|
"GBP": {
|
|
|
|
1000: 799,
|
|
|
|
2800: 1999,
|
|
|
|
5000: 3499,
|
2024-02-19 16:08:37 +00:00
|
|
|
7500: 4999,
|
2024-02-19 04:07:40 +00:00
|
|
|
13500: 7999,
|
|
|
|
},
|
|
|
|
},
|
2024-02-19 16:08:37 +00:00
|
|
|
StorefrontCurrencyMultiplier: map[string]float64{
|
|
|
|
"USD": 1.2503128911,
|
|
|
|
"GBP": 1.0,
|
|
|
|
},
|
2024-02-11 00:27:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-19 04:07:40 +00:00
|
|
|
func (c *dataClient) LoadExternalData() {
|
2024-02-11 00:27:08 +00:00
|
|
|
req, err := http.NewRequest("GET", "https://fortnite-api.com/v2/cosmetics/br", nil)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := c.h.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
bodyBytes, err := io.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-03-10 18:16:42 +00:00
|
|
|
content := &APICosmeticsResponse{}
|
2024-02-11 00:27:08 +00:00
|
|
|
err = json.Unmarshal(bodyBytes, content)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, item := range content.Data {
|
2024-03-10 18:16:42 +00:00
|
|
|
c.LoadItemDefinition(&item)
|
2024-02-11 00:27:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, item := range c.TypedFortniteItems["AthenaBackpack"] {
|
|
|
|
c.AddBackpackToItem(item)
|
|
|
|
}
|
|
|
|
|
2024-02-19 01:49:14 +00:00
|
|
|
displayAssets := storage.HttpAsset[[]string]("assets.snow.json")
|
2024-02-11 00:27:08 +00:00
|
|
|
if displayAssets == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, displayAsset := range *displayAssets {
|
|
|
|
c.AddDisplayAssetToItem(displayAsset)
|
|
|
|
}
|
|
|
|
|
2024-03-10 18:16:42 +00:00
|
|
|
variantTokens := storage.HttpAsset[map[string]SnowCosmeticVariantDefinition]("variants.snow.json")
|
2024-02-11 00:27:08 +00:00
|
|
|
if variantTokens == nil {
|
|
|
|
return
|
|
|
|
}
|
2024-02-19 01:49:14 +00:00
|
|
|
|
|
|
|
for k, v := range *variantTokens {
|
|
|
|
item := c.FortniteItems[v.Item]
|
|
|
|
if item == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
c.SnowVariantTokens[k] = &FortniteVariantToken{
|
|
|
|
Grants: v.Grants,
|
|
|
|
Item: item,
|
|
|
|
Name: v.Name,
|
|
|
|
Gift: v.Gift,
|
|
|
|
Equip: v.Equip,
|
|
|
|
Unseen: v.Unseen,
|
|
|
|
}
|
|
|
|
}
|
2024-02-11 00:27:08 +00:00
|
|
|
|
|
|
|
addNumericStylesToSets := []string{"Soccer", "Football", "ScaryBall"}
|
|
|
|
for _, setValue := range addNumericStylesToSets {
|
|
|
|
set, found := c.FortniteSets[setValue]
|
|
|
|
if !found {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, item := range set.Items {
|
|
|
|
c.AddNumericStylesToItem(item)
|
|
|
|
}
|
|
|
|
}
|
2024-03-10 18:16:42 +00:00
|
|
|
|
|
|
|
athenaSeasonObj := storage.HttpAsset[[]UnrealEngineObject[UnrealSeasonProperties, UnrealNoRows]]("season.snow.json")
|
|
|
|
if athenaSeasonObj == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
levelProgressionObj := storage.HttpAsset[[]UnrealEngineObject[UnrealProgressionProperties, UnrealProgressionRows]]("progression.levels.snow.json")
|
|
|
|
if levelProgressionObj == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
bookProgressionObj := storage.HttpAsset[[]UnrealEngineObject[UnrealProgressionProperties, UnrealProgressionRows]]("progression.book.snow.json")
|
|
|
|
if bookProgressionObj == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
c.SnowSeason = NewSeasonDefinition()
|
|
|
|
|
|
|
|
for index, tier := range (*athenaSeasonObj)[0].Properties.BookXpSchedulePaid.Levels {
|
|
|
|
c.SnowSeason.TierRewardsPremium[index] = []*ItemGrant{}
|
|
|
|
for _, reward := range tier.Rewards {
|
|
|
|
templateId := aid.Ternary[string](reward.ItemDefinition.AssetPathName != "None", convertAssetPathToTemplateId(reward.ItemDefinition.AssetPathName), reward.TemplateID)
|
|
|
|
c.SnowSeason.TierRewardsPremium[index] = append(c.SnowSeason.TierRewardsPremium[index], NewItemGrant(templateId, reward.Quantity))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.SnowSeason.TierRewardsPremium[0] = []*ItemGrant{}
|
|
|
|
|
|
|
|
for index, tier := range (*athenaSeasonObj)[0].Properties.BookXpScheduleFree.Levels {
|
|
|
|
c.SnowSeason.TierRewardsFree[index] = []*ItemGrant{}
|
|
|
|
for _, reward := range tier.Rewards {
|
|
|
|
templateId := aid.Ternary[string](reward.ItemDefinition.AssetPathName != "None", convertAssetPathToTemplateId(reward.ItemDefinition.AssetPathName), reward.TemplateID)
|
|
|
|
c.SnowSeason.TierRewardsFree[index] = append(c.SnowSeason.TierRewardsFree[index], NewItemGrant(templateId, reward.Quantity))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.SnowSeason.TierRewardsFree[0] = []*ItemGrant{}
|
|
|
|
|
|
|
|
for index, level := range (*athenaSeasonObj)[0].Properties.SeasonXpScheduleFree.Levels {
|
|
|
|
c.SnowSeason.LevelRewards[index] = []*ItemGrant{}
|
|
|
|
for _, reward := range level.Rewards {
|
|
|
|
templateId := aid.Ternary[string](reward.ItemDefinition.AssetPathName != "None", convertAssetPathToTemplateId(reward.ItemDefinition.AssetPathName), reward.TemplateID)
|
|
|
|
c.SnowSeason.LevelRewards[index] = append(c.SnowSeason.LevelRewards[index], NewItemGrant(templateId, reward.Quantity))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.SnowSeason.LevelRewards[0] = []*ItemGrant{}
|
|
|
|
|
|
|
|
for _, token := range (*athenaSeasonObj)[0].Properties.TokensToRemoveAtSeasonEnd {
|
|
|
|
c.SnowSeason.SeasonTokenRemoval = append(c.SnowSeason.SeasonTokenRemoval, NewItemGrant(convertAssetPathToTemplateId(token.AssetPathName), 1))
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, reward := range (*athenaSeasonObj)[0].Properties.SeasonFirstWinRewards.Rewards {
|
|
|
|
templateId := aid.Ternary[string](reward.ItemDefinition.AssetPathName != "None", convertAssetPathToTemplateId(reward.ItemDefinition.AssetPathName), reward.TemplateID)
|
|
|
|
c.SnowSeason.VictoryRewards = append(c.SnowSeason.VictoryRewards, NewItemGrant(templateId, reward.Quantity))
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, token := range (*athenaSeasonObj)[0].Properties.ExpiringRewardTypes {
|
|
|
|
c.SnowSeason.SeasonTokenRemoval = append(c.SnowSeason.SeasonTokenRemoval, NewItemGrant(convertAssetPathToTemplateId(token.AssetPathName), 1))
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, reward := range (*athenaSeasonObj)[0].Properties.SeasonGrantsToEveryone.Rewards {
|
|
|
|
templateId := aid.Ternary[string](reward.ItemDefinition.AssetPathName != "None", convertAssetPathToTemplateId(reward.ItemDefinition.AssetPathName), reward.TemplateID)
|
|
|
|
c.SnowSeason.TierRewardsFree[0] = append(c.SnowSeason.TierRewardsFree[0], NewItemGrant(templateId, reward.Quantity))
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, replacement := range (*athenaSeasonObj)[0].Properties.BattleStarSubstitutionReward.Rewards {
|
|
|
|
templateId := aid.Ternary[string](replacement.ItemDefinition.AssetPathName != "None", convertAssetPathToTemplateId(replacement.ItemDefinition.AssetPathName), replacement.TemplateID)
|
|
|
|
c.SnowSeason.BookXPReplacements = append(c.SnowSeason.BookXPReplacements, NewItemGrant(templateId, replacement.Quantity))
|
|
|
|
}
|
|
|
|
|
|
|
|
for indexString, row := range *(*levelProgressionObj)[0].Rows {
|
|
|
|
index := aid.ToInt(indexString)
|
|
|
|
c.SnowSeason.LevelProgression[index] = &row
|
|
|
|
}
|
|
|
|
c.SnowSeason.LevelProgression[0] = &UnrealProgressionRows{
|
|
|
|
Level: 0,
|
|
|
|
XpToNextLevel: 0,
|
|
|
|
XpTotal: 0,
|
|
|
|
}
|
|
|
|
c.SnowSeason.LevelProgression[100] = &UnrealProgressionRows{
|
|
|
|
Level: 100,
|
|
|
|
XpToNextLevel: 0,
|
|
|
|
XpTotal: c.SnowSeason.LevelProgression[99].XpTotal + c.SnowSeason.LevelProgression[99].XpToNextLevel,
|
|
|
|
}
|
|
|
|
|
|
|
|
for indexString, row := range *(*bookProgressionObj)[0].Rows {
|
|
|
|
index := aid.ToInt(indexString)
|
|
|
|
c.SnowSeason.BookProgression[index] = &row
|
|
|
|
}
|
|
|
|
c.SnowSeason.BookProgression[0] = &UnrealProgressionRows{
|
|
|
|
Level: 0,
|
|
|
|
XpToNextLevel: 0,
|
|
|
|
XpTotal: 0,
|
|
|
|
}
|
|
|
|
c.SnowSeason.BookProgression[100] = &UnrealProgressionRows{
|
|
|
|
Level: 100,
|
|
|
|
XpToNextLevel: 0,
|
|
|
|
XpTotal: c.SnowSeason.BookProgression[99].XpTotal + c.SnowSeason.BookProgression[99].XpToNextLevel,
|
|
|
|
}
|
|
|
|
|
|
|
|
c.SnowSeason.DefaultOfferID = (*athenaSeasonObj)[0].Properties.BattlePassOfferId
|
|
|
|
c.SnowSeason.BundleOfferID = (*athenaSeasonObj)[0].Properties.BattlePassBundleOfferId
|
|
|
|
c.SnowSeason.TierOfferID = (*athenaSeasonObj)[0].Properties.BattlePassLevelOfferID
|
2024-02-11 00:27:08 +00:00
|
|
|
}
|
|
|
|
|
2024-03-10 18:16:42 +00:00
|
|
|
func (c *dataClient) LoadItemDefinition(item *APICosmeticDefinition) {
|
2024-02-11 00:27:08 +00:00
|
|
|
if item.Introduction.BackendValue > aid.Config.Fortnite.Season || item.Introduction.BackendValue == 0 {
|
|
|
|
return
|
|
|
|
}
|
2024-03-10 18:16:42 +00:00
|
|
|
|
|
|
|
typeLookup := map[string]string{
|
|
|
|
"AthenaCharacter": "AthenaCharacter",
|
|
|
|
"AthenaBackpack": "AthenaBackpack",
|
|
|
|
"AthenaPickaxe": "AthenaPickaxe",
|
|
|
|
"AthenaGlider": "AthenaGlider",
|
|
|
|
"AthenaDance": "AthenaDance",
|
|
|
|
"AthenaToy": "AthenaDance",
|
|
|
|
"AthenaEmoji": "AthenaEmoji",
|
|
|
|
"AthenaItemWrap": "AthenaItemWrap",
|
|
|
|
"AthenaMusicPack": "AthenaMusicPack",
|
|
|
|
"AthenaPet": "AthenaBackpack",
|
|
|
|
"AthenaPetCarrier": "AthenaBackpack",
|
|
|
|
"AthenaLoadingScreen": "AthenaLoadingScreen",
|
|
|
|
"AthenaSkyDiveContrail": "AthenaSkyDiveContrail",
|
|
|
|
}
|
|
|
|
|
|
|
|
item.Type.BackendValue = aid.Ternary[string](typeLookup[item.Type.BackendValue] != "", typeLookup[item.Type.BackendValue], item.Type.BackendValue)
|
2024-02-11 00:27:08 +00:00
|
|
|
|
|
|
|
if c.FortniteSets[item.Set.BackendValue] == nil {
|
2024-03-10 18:16:42 +00:00
|
|
|
c.FortniteSets[item.Set.BackendValue] = &APISetDefinition{
|
2024-02-11 00:27:08 +00:00
|
|
|
BackendName: item.Set.Value,
|
|
|
|
DisplayName: item.Set.Text,
|
2024-03-10 18:16:42 +00:00
|
|
|
Items: []*APICosmeticDefinition{},
|
2024-02-11 00:27:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.TypedFortniteItems[item.Type.BackendValue] == nil {
|
2024-03-10 18:16:42 +00:00
|
|
|
c.TypedFortniteItems[item.Type.BackendValue] = []*APICosmeticDefinition{}
|
2024-02-11 00:27:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
c.FortniteItems[item.ID] = item
|
|
|
|
c.FortniteSets[item.Set.BackendValue].Items = append(c.FortniteSets[item.Set.BackendValue].Items, item)
|
|
|
|
c.TypedFortniteItems[item.Type.BackendValue] = append(c.TypedFortniteItems[item.Type.BackendValue], item)
|
|
|
|
|
|
|
|
if item.Type.BackendValue != "AthenaCharacter" || item.Images.Featured == "" || slices.Contains[[]string]([]string{
|
|
|
|
"Soccer",
|
|
|
|
"Football",
|
|
|
|
"Waypoint",
|
|
|
|
}, item.Set.BackendValue) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tag := range item.GameplayTags {
|
|
|
|
if strings.Contains(tag, "StarterPack") {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
c.FortniteItemsWithFeaturedImage = append(c.FortniteItemsWithFeaturedImage, item)
|
|
|
|
}
|
|
|
|
|
2024-03-10 18:16:42 +00:00
|
|
|
func (c *dataClient) AddBackpackToItem(backpack *APICosmeticDefinition) {
|
2024-02-11 00:27:08 +00:00
|
|
|
if backpack.ItemPreviewHeroPath == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
splitter := strings.Split(backpack.ItemPreviewHeroPath, "/")
|
|
|
|
character, found := c.FortniteItems[splitter[len(splitter) - 1]]
|
|
|
|
if !found {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-03-10 18:16:42 +00:00
|
|
|
character.BackpackDefinition = backpack
|
2024-02-11 00:27:08 +00:00
|
|
|
}
|
|
|
|
|
2024-02-19 04:07:40 +00:00
|
|
|
func (c *dataClient) AddDisplayAssetToItem(displayAsset string) {
|
2024-02-11 00:27:08 +00:00
|
|
|
split := strings.Split(displayAsset, "_")[1:]
|
|
|
|
found := c.FortniteItems[strings.Join(split[:], "_")]
|
|
|
|
|
|
|
|
if found == nil && split[0] == "CID" {
|
|
|
|
r := aid.Regex(strings.Join(split[:], "_"), `(?:CID_)(\d+|A_\d+)(?:_.+)`)
|
|
|
|
if r != nil {
|
2024-02-18 00:09:02 +00:00
|
|
|
found = GetItemByShallowID(*r)
|
2024-02-11 00:27:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if found == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-03-10 18:16:42 +00:00
|
|
|
found.NewDisplayAssetPath = displayAsset
|
2024-02-11 00:27:08 +00:00
|
|
|
c.FortniteItemsWithDisplayAssets[found.ID] = found
|
|
|
|
c.TypedFortniteItemsWithDisplayAssets[found.Type.BackendValue] = append(c.TypedFortniteItemsWithDisplayAssets[found.Type.BackendValue], found)
|
|
|
|
}
|
|
|
|
|
2024-03-10 18:16:42 +00:00
|
|
|
func (c *dataClient) AddNumericStylesToItem(item *APICosmeticDefinition) {
|
|
|
|
ownedStyles := []APICosmeticDefinitionVariant{}
|
2024-02-11 00:27:08 +00:00
|
|
|
for i := 0; i < 100; i++ {
|
2024-03-10 18:16:42 +00:00
|
|
|
ownedStyles = append(ownedStyles, APICosmeticDefinitionVariant{
|
2024-02-11 00:27:08 +00:00
|
|
|
Tag: fmt.Sprint(i),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-03-10 18:16:42 +00:00
|
|
|
item.Variants = append(item.Variants, APICosmeticDefinitionVariantChannel{
|
2024-02-11 00:27:08 +00:00
|
|
|
Channel: "Numeric",
|
|
|
|
Type: "int",
|
|
|
|
Options: ownedStyles,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-02-19 04:07:40 +00:00
|
|
|
func (c *dataClient) GetStorefrontDailyItemCount(season int) int {
|
|
|
|
currentValue := 4
|
|
|
|
for _, item := range c.StorefrontDailyItemCountLookup {
|
|
|
|
if item.Season > season {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
currentValue = item.Items
|
|
|
|
}
|
|
|
|
return currentValue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *dataClient) GetStorefrontWeeklySetCount(season int) int {
|
|
|
|
currentValue := 2
|
2024-03-10 18:16:42 +00:00
|
|
|
// for _, item := range c.StorefrontWeeklySetCountLookup {
|
|
|
|
// if item.Season > season {
|
|
|
|
// continue
|
|
|
|
// }
|
|
|
|
// currentValue = item.Sets
|
|
|
|
// }
|
2024-02-19 04:07:40 +00:00
|
|
|
return currentValue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *dataClient) GetStorefrontCosmeticOfferPrice(rarity string, type_ string) int {
|
|
|
|
return c.StorefrontCosmeticOfferPriceLookup[rarity][type_]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *dataClient) GetStorefrontCurrencyOfferPrice(currency string, amount int) int {
|
|
|
|
return c.StorefrontCurrencyOfferPriceLookup[currency][amount]
|
|
|
|
}
|
|
|
|
|
2024-03-10 18:16:42 +00:00
|
|
|
func (c *dataClient) GetStorefrontLocalizedOfferPrice(currency string, amount int) int {
|
2024-02-19 16:08:37 +00:00
|
|
|
return int(float64(amount) * c.StorefrontCurrencyMultiplier[currency])
|
|
|
|
}
|
|
|
|
|
2024-02-11 00:27:08 +00:00
|
|
|
func PreloadCosmetics() error {
|
2024-02-19 04:07:40 +00:00
|
|
|
DataClient = NewDataClient()
|
|
|
|
DataClient.LoadExternalData()
|
2024-02-11 00:27:08 +00:00
|
|
|
|
2024-02-19 04:07:40 +00:00
|
|
|
aid.Print("(snow) " + fmt.Sprint(len(DataClient.FortniteItems)) + " cosmetics loaded from fortnite-api.com")
|
2024-02-11 00:27:08 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-03-10 18:16:42 +00:00
|
|
|
func GetItemByShallowID(shallowID string) *APICosmeticDefinition {
|
2024-02-19 04:07:40 +00:00
|
|
|
for _, item := range DataClient.TypedFortniteItems["AthenaCharacter"] {
|
2024-02-11 00:27:08 +00:00
|
|
|
if strings.Contains(item.ID, shallowID) {
|
|
|
|
return item
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-03-10 18:16:42 +00:00
|
|
|
func GetRandomItemWithDisplayAsset() *APICosmeticDefinition {
|
2024-02-19 04:07:40 +00:00
|
|
|
items := DataClient.FortniteItemsWithDisplayAssets
|
2024-02-11 00:27:08 +00:00
|
|
|
if len(items) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-03-10 18:16:42 +00:00
|
|
|
flat := []APICosmeticDefinition{}
|
2024-02-18 00:09:02 +00:00
|
|
|
for _, item := range items {
|
|
|
|
flat = append(flat, *item)
|
|
|
|
}
|
|
|
|
|
2024-03-10 18:16:42 +00:00
|
|
|
slices.SortFunc[[]APICosmeticDefinition](flat, func(a, b APICosmeticDefinition) int {
|
2024-02-18 00:09:02 +00:00
|
|
|
return strings.Compare(a.ID, b.ID)
|
|
|
|
})
|
2024-02-11 00:27:08 +00:00
|
|
|
|
2024-02-18 00:09:02 +00:00
|
|
|
return &flat[aid.RandomInt(0, len(flat))]
|
|
|
|
}
|
2024-02-11 00:27:08 +00:00
|
|
|
|
2024-03-10 18:16:42 +00:00
|
|
|
func GetRandomItemWithDisplayAssetOfNotType(notType string) *APICosmeticDefinition {
|
|
|
|
flat := []APICosmeticDefinition{}
|
2024-02-18 00:09:02 +00:00
|
|
|
|
2024-02-19 04:07:40 +00:00
|
|
|
for t, items := range DataClient.TypedFortniteItemsWithDisplayAssets {
|
2024-02-18 00:09:02 +00:00
|
|
|
if t == notType {
|
2024-02-11 00:27:08 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-02-18 00:09:02 +00:00
|
|
|
for _, item := range items {
|
|
|
|
flat = append(flat, *item)
|
|
|
|
}
|
2024-02-11 00:27:08 +00:00
|
|
|
}
|
|
|
|
|
2024-03-10 18:16:42 +00:00
|
|
|
slices.SortFunc[[]APICosmeticDefinition](flat, func(a, b APICosmeticDefinition) int {
|
2024-02-18 00:09:02 +00:00
|
|
|
return strings.Compare(a.ID, b.ID)
|
|
|
|
})
|
2024-02-11 00:27:08 +00:00
|
|
|
|
2024-02-18 00:09:02 +00:00
|
|
|
return &flat[aid.RandomInt(0, len(flat))]
|
2024-02-11 00:27:08 +00:00
|
|
|
}
|
|
|
|
|
2024-03-10 18:16:42 +00:00
|
|
|
func GetRandomSet() *APISetDefinition {
|
|
|
|
sets := []APISetDefinition{}
|
2024-02-19 04:07:40 +00:00
|
|
|
for _, set := range DataClient.FortniteSets {
|
|
|
|
if set.BackendName == "" {
|
|
|
|
continue
|
|
|
|
}
|
2024-02-18 00:09:02 +00:00
|
|
|
sets = append(sets, *set)
|
2024-02-11 00:27:08 +00:00
|
|
|
}
|
|
|
|
|
2024-03-10 18:16:42 +00:00
|
|
|
slices.SortFunc[[]APISetDefinition](sets, func(a, b APISetDefinition) int {
|
2024-02-18 00:09:02 +00:00
|
|
|
return strings.Compare(a.BackendName, b.BackendName)
|
|
|
|
})
|
|
|
|
|
|
|
|
return &sets[aid.RandomInt(0, len(sets))]
|
2024-02-11 00:27:08 +00:00
|
|
|
}
|