Skip to content

Commit

Permalink
fix: Внёс правки в оценку, согласно новому api
Browse files Browse the repository at this point in the history
  • Loading branch information
ichirukyn committed Nov 26, 2023
1 parent 892bbf2 commit 1e5bbcd
Show file tree
Hide file tree
Showing 5 changed files with 2,835 additions and 2,906 deletions.
7 changes: 4 additions & 3 deletions src/pages/weasel/components/SubStatSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ function clearStats(stat: string) {
* 1. Был выбрана основная характеристика
* 2. Побочных характеристик не менее 1
*/
function weasel() {
async function weasel() {
if (store.chosen_art.main_stat.hasOwnProperty('name'))
if (store.chosen_art.sub_stats.length >= 1) {
if (!hero.$state.sortedCharactersStats.length) {
hero.get_hero();
/** Если список сортировки пуст, значит запуск происходит первый раз */
if (!hero.sortedCharactersStats.length) {
await hero.get_hero();
}
hero.weasel(store.chosen_art);
Expand Down
10 changes: 10 additions & 0 deletions src/scripts/enums/elements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export enum ElementsEnum {
ANEMO = "Anemo",
CRYO = "Cryo",
DENDRO = "Dendro",
ELECTRO = "Electro",
HYDRO = "Hydro",
GEO = "Geo",
PYRO = "Pyro",
PHYS = "Phys"
}
91 changes: 20 additions & 71 deletions src/scripts/models/weaselAppraiser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ElementsEnum } from "@/scripts/enums/elements";

export interface Data {
data: characterStats[];
data: CharacterStats[];
}

export interface Stat {
Expand All @@ -12,23 +14,23 @@ export interface Artifact {
stats: Stat[];
}

export interface characterStats {

export interface CharacterStats {
character_id: string,
name: string,
element: number,
element: ElementsEnum,
icon_url: string,
stats_profit: ArtStat[];
artifact_profits: ArtProfit;
}

// export interface StatsProfit {
// [key: number]: Flower,
//
// feather: Feather,
// sands: Sands,
// goblet: Goblet,
// circlet: Circlet,
// substats: ArtStat[];
// }
export interface ArtProfit {
circlet: AllStats,
flower: AllStats,
goblet: AllStats,
plume: AllStats,
sands: AllStats,
substats: AllStats;
}

export interface ArtStat {
slot: string,
Expand All @@ -47,47 +49,7 @@ export interface ArtStat {
ELEM?: number;
}

export interface Flower {
slot: string,
HP: number;
}

export interface Feather {
slot: string,
ATK: number;
}

export interface Sands {
slot: string,
ATK_P?: number,
HP_P?: number,
DEF_P?: number,
EM?: number,
ER?: number;
}

export interface Goblet {
slot: string,
ATK_P?: number,
HP_P?: number,
DEF_P?: number,
EM?: number,
PHYS?: number,
ELEM?: number;
}

export interface Circlet {
slot: string,
ATK_P?: number,
DEF_P?: number,
HP_P?: number,
EM?: number,
CR?: number,
CD?: number,
HEAL?: number;
}

export interface Substats {
export interface AllStats {
ATK?: number,
ATK_P?: number,
HP?: number,
Expand All @@ -97,23 +59,10 @@ export interface Substats {
EM?: number,
DEF?: number,
DEF_P?: number,
ER?: number;
}

export interface AllStats {
ATK: number | null,
ATK_P: number | null,
HP: number | null,
HP_P: number | null,
CD: number | null,
CR: number | null,
EM: number | null,
DEF: number | null,
DEF_P: number | null,
ER: number | null,
HEAL: number | null,
PHYS: number | null,
ELEM: number | null;
ER?: number,
ELEM?: number,
HEAL?: number,
PHYS?: number;
}

export interface Elements {
Expand Down
86 changes: 27 additions & 59 deletions src/stores/character.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { ArtStat, characterStats, Elements, Stat, Substats } from '@/scripts/models/weaselAppraiser';
import { AllStats, ArtProfit, CharacterStats, Stat } from '@/scripts/models/weaselAppraiser';
import { defineStore } from "pinia";
import { ref } from "vue";
import axios, { httpRoute } from "@/HttpConfig.js";
import { Logger } from "tslog";
import { test_data } from "@/stores/test";
import { ElementsEnum } from "@/scripts/enums/elements";

export const useCharacterStore = defineStore("character", () => {
const logger = new Logger({ name: "characterLogger", minLevel: import.meta.env.VITE_LOG_LEVEL });

const elements = ref<Elements[]>(['UndefinedElement', 'Pyro', 'Hydro', 'Geo', 'Anemo', 'Electro', 'Cryo', 'Dendro',])


interface ChosenArtifact {
slot: string,
main_stat: Stat,
Expand Down Expand Up @@ -38,26 +35,24 @@ export const useCharacterStore = defineStore("character", () => {

const sortedCharactersStats = ref<CharacterResult[][]>([]);

const charactersList = ref<characterStats[]>([]);
const charactersList = ref<CharacterStats[]>([]);

/** Помогает убрать превью, после нажатия "Оценки" */
const appraiser_start = ref(false);

/** Получает персонажей с сервера */
function get_hero() {
axios
.get(httpRoute.characters)
.then((res) => {
logger.trace('Fetching character stats');
charactersList.value = res.data;
})
.catch((error) => {
logger.error(error.message);
});

charactersList.value = test_data;
async function get_hero() {
try {
const res = await axios.get(httpRoute.characters)
logger.trace('Fetching character stats');
charactersList.value = res.data;
}
catch (error) {
logger.error(error);
}
}


/** Очищает все характеристики артефакта пользователя
* Todo: Понять почему, default_art ломается и перезаписывается.
* Сейчас временное решение
Expand Down Expand Up @@ -113,23 +108,16 @@ export const useCharacterStore = defineStore("character", () => {
*/
function weasel(chosenArtifact: ChosenArtifact) {
sort_default();

charactersList.value.filter((char) => {

/** substats всегда последний */
const substats = char.stats_profit.length - 1;
let selectSlot: ArtStat = { slot: '' };

/** Обнуляю main stat */
const newTableSub = { ...char.stats_profit[substats] };

newTableSub[chosenArtifact.main_stat.value as keyof Substats] = 0;
const newTableSub = { ...char.artifact_profits.substats, [chosenArtifact.main_stat.value]: 0 };

/** Пересобираю substats в массив, для удобной сортировки */
let subList: number[] = [];

for (let n in newTableSub) {
subList.push(<number>newTableSub[n as keyof Substats]);
subList.push(<number>newTableSub[n as keyof AllStats]);
}

/** Выбираю 4 наибольших substats */
Expand All @@ -140,62 +128,42 @@ export const useCharacterStore = defineStore("character", () => {

/** Нахожу вес лучшей основы */
let weight: number = 0;
let stats: ArtStat = selectSlot;


char.stats_profit.forEach((artSlot, index) => {
if (artSlot.slot === chosen_art.value.slot) {
selectSlot = artSlot;
stats = artSlot
}
})
let stats: AllStats = char.artifact_profits[chosen_art.value.slot as keyof ArtProfit];

weight = Object.entries(stats).reduce((prev, curr) => prev[1] > curr[1] ? prev : curr)[1]

/** Находим взешенный сабстаты */
let weightSub: AllStats = { ...char.artifact_profits.substats }

let weightSub: Substats = { ...char.stats_profit[substats] }
let subName

for (subName in char.stats_profit[substats]) {

if (subName !== 'slot') { // @ts-ignore
weightSub[subName] = (((400 - weight) / A) * char.stats_profit[substats][subName])
}
for (let subName in char.artifact_profits.substats) {
weightSub[subName as keyof AllStats] = (((400 - weight) / A) * <number>char.artifact_profits.substats[subName as keyof AllStats])
}


/** Оценка артефактов по выбранным сабстатам */
let sumWeightSub = 0;

chosen_art.value.sub_stats.map((value) => {
if (weightSub[value as keyof Substats])
// @ts-ignore
sumWeightSub += weightSub[value as keyof Substats];
if (weightSub[value as keyof AllStats])
sumWeightSub += weightSub[value as keyof AllStats] || 0;
else
sumWeightSub += 0
});


/** Сумма */
let score: number = 0
let main_stat_score = char.artifact_profits[chosen_art.value.slot as keyof ArtProfit][chosen_art.value.main_stat.value as keyof AllStats]


if (selectSlot[chosen_art.value.main_stat.value as keyof ArtStat])
// @ts-ignore
score = selectSlot[chosen_art.value.main_stat.value as keyof ArtStat] + sumWeightSub
if (main_stat_score)
score = main_stat_score + sumWeightSub
else
score = sumWeightSub

/** Проверка на элемент */
elements.value.forEach((value, index) => {
/** Проверка pyro === pyro && 1 === 1 */
if (value === chosen_art.value.main_stat.value && index === char.element) {
if (selectSlot.ELEM)
score = selectSlot.ELEM + sumWeightSub;
}
})

if (Object.values(ElementsEnum).includes(chosen_art.value.main_stat.value as ElementsEnum)) {
score = <number>char.artifact_profits.goblet.ELEM + sumWeightSub
}

let i = {
id: char.character_id,
Expand Down
Loading

0 comments on commit 1e5bbcd

Please sign in to comment.