Skip to content

Commit

Permalink
feat: getPowerupInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
pa001024 committed Jan 25, 2021
1 parent 7c78aac commit 05902ce
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"i18n-ally.sourceLanguage": "zh-Hans",
"i18n-ally.keystyle": "nested",
"i18n-ally.languageTagSystem": "bcp47",
"commentTranslate.targetLanguage": "zh-CN"
"commentTranslate.targetLanguage": "en"
}
2 changes: 1 addition & 1 deletion api/db/models/artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class Artifact implements IArtifact {
@prop({ ref: () => User, index: true })
public owner!: string;

/** 部位 */
/** 类型id */
@prop({ type: Number, required: true })
public typeId!: number;

Expand Down
2 changes: 1 addition & 1 deletion assets/global.less
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
--shadow: rgba(255, 255, 255, 0.23);
}

.nolink {
.nolink.nolink {
color: unset;
text-decoration: none;
}
2 changes: 1 addition & 1 deletion components/Rarity.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="rarity" :class="{ fixed: fixed }">
<div class="rarity" :class="{ fixed }">
<GsIcon v-for="i in star" :key="i" type="star" />
</div>
</template>
Expand Down
120 changes: 117 additions & 3 deletions modules/core/Artifact.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { IArtifactType, IAttr } from "./interface";
import { IArtifact, ARTIFACT } from ".";

const data: IArtifactType[] = require("~/content/en/relic/relic");
const dataMap = data.reduce<{ [x: number]: IArtifactType }>((r, v) => (r[v.id] = v) && r, {});
// move to component created()
// const data: IArtifactType[] = require("~/content/en/relic/relic");
// const dataMap = data.reduce<{ [x: number]: IArtifactType }>((r, v) => (r[v.id] = v) && r, {});

export class Artifact {
static relicMap: { [x: number]: IArtifactType };

/** 静态数据 */
data: IArtifact;
type: IArtifactType;
constructor(artifact: IArtifact) {
this.data = artifact;
this.type = dataMap[artifact.typeId];
this.type = Artifact.relicMap[artifact.typeId];
}

lazy = false;
Expand Down Expand Up @@ -44,4 +47,115 @@ export class Artifact {
};
return [mainAttr, ...this.data.attrs];
}

private _attrPowerUpInfo = [];
public get attrPowerUpInfo() {
return this._attrPowerUpInfo;
}

/**
* 回溯副属性强化情况 (高开销)
*/
getPowerupInfo() {
const pmap = new Map(ARTIFACT.SUB_PROPERTY[this.type.rarity - 1]);
const maxN = ARTIFACT.MAX_POWERUP_PROPS[this.type.rarity - 1];
return this.attrs.map(attr => {
const probs = pmap.get(attr.type)!;
// TODO: 考虑缓存
const rainbow = getNRainbow(probs, maxN);
const params = rainbow.get(attr.value)! || [0, 0, 0, 0];
return {
...attr,
params,
// 分解后数值
values: [].concat(probs.map((v, i) => Array(params[i]).fill(v)) as any),
} as IAttrPowerUpInfo;
});
}

/**
* 生成随机圣遗物
*
* @static
* @param atype 类型
* @param [level=0] 等级
*/
static random(atype: IArtifactType | string | number, level = 0) {
if (typeof atype === "string") atype = Artifact.relicMap[+atype];
else if (typeof atype === "number") atype = Artifact.relicMap[atype];

// 随机主属性
const mainWeights = ARTIFACT.MAIN_PROPERTY_WEIGHT[atype.type];
let total = mainWeights.reduce((r, [, w]) => r + w, 0) * Math.random();
const main = mainWeights.find(([, w]) => (total -= w) < 0)![0];

// 随机副属性
const subCount = ARTIFACT.MAX_SUB_PROPS[atype.rarity] - ~~(Math.random() + 0.5);
const subs: IAttr[] = [];
for (let i = 0; i < subCount; i++) {
const used = [main, ...subs.map(v => v.type)];
const subWeights = ARTIFACT.SUB_PROPERTY_WEIGHT.filter(v => !used.includes(v[0]));
total = subWeights.reduce((r, [, w]) => r + w, 0) * Math.random();
const sub = subWeights.find(([, w]) => (total -= w) < 0)![0];
const valueRange = ARTIFACT.SUB_PROPERTY[atype.rarity].find(v => v[0] === sub)![1];
const value = valueRange[~~(Math.random() * valueRange.length)];
subs.push({ type: sub, value });
}

return new Artifact({
typeId: atype.id,
level,
main,
attrs: subs,
});
}
}

/**
* 获取w阶n次组合矩阵
* 如2阶3次结果为
* [3,0]
* [2,1]
* [1,2]
* [0,3]
*
* @param w 宽度
* @param n 深度
*/
function wnMatrix(w: number, n: number) {
if (w === 1) return [[n]];
const m: number[][] = [];
for (let i = 0; i <= n; i++) {
for (const rest of wnMatrix(w - 1, n - i)) {
m.push([...rest, i]);
}
}
return m;
}

/**
* 获取特定值彩虹表
*
* @param values 取值范围
* @param maxN 最大强化次数
*/
function getNRainbow(values: number[], maxN: number) {
const all: number[][] = [].concat(
...(Array(maxN)
.fill(0)
.map((_, n) => wnMatrix(values.length, n + 1)) as any)
);

const vm = new Map(
all.map(m => {
const val = values.reduce((r, v, i) => r + v * m[i], 0);
return [+val.toFixed(1), m];
})
);

return vm;
}
interface IAttrPowerUpInfo extends IAttr {
params: number[];
values: number[];
}
188 changes: 104 additions & 84 deletions modules/core/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,105 +284,125 @@ export namespace ARTIFACT {
];

/** 各部位主属性权重 */
export const MAIN_PROPERTY_WEIGHT: { [x: number]: number }[] = [
{ [BuffType.HPDelta]: 1000 },
{ [BuffType.ATKDelta]: 1000 },
{
[BuffType.HPRatio]: 1334,
[BuffType.ATKRatio]: 1333,
[BuffType.DEFRatio]: 1333,
[BuffType.EnergyRecharge]: 500,
[BuffType.ElementalMastery]: 500,
},
{
[BuffType.HPRatio]: 850,
[BuffType.ATKRatio]: 850,
[BuffType.DEFRatio]: 800,
[BuffType.ElementalMastery]: 100,
[BuffType.PyroDMG]: 200,
[BuffType.ElectroDMG]: 200,
[BuffType.HydroDMG]: 200,
[BuffType.AnemoDMG]: 200,
[BuffType.GeoDMG]: 200,
[BuffType.CryoDMG]: 200,
[BuffType.PhysicalDMG]: 200,
},
{
[BuffType.HPRatio]: 1100,
[BuffType.ATKRatio]: 1100,
[BuffType.DEFRatio]: 1100,
[BuffType.CRITRate]: 500,
[BuffType.CRITDMG]: 500,
[BuffType.Heal]: 500,
[BuffType.ElementalMastery]: 200,
},
export const MAIN_PROPERTY_WEIGHT: [BuffType, number][][] = [
[[BuffType.HPDelta, 1000]],
[[BuffType.ATKDelta, 1000]],
[
[BuffType.HPRatio, 1334],
[BuffType.ATKRatio, 1333],
[BuffType.DEFRatio, 1333],
[BuffType.EnergyRecharge, 500],
[BuffType.ElementalMastery, 500],
],
[
[BuffType.HPRatio, 850],
[BuffType.ATKRatio, 850],
[BuffType.DEFRatio, 800],
[BuffType.ElementalMastery, 100],
[BuffType.PyroDMG, 200],
[BuffType.ElectroDMG, 200],
[BuffType.HydroDMG, 200],
[BuffType.AnemoDMG, 200],
[BuffType.GeoDMG, 200],
[BuffType.CryoDMG, 200],
[BuffType.PhysicalDMG, 200],
],
[
[BuffType.HPRatio, 1100],
[BuffType.ATKRatio, 1100],
[BuffType.DEFRatio, 1100],
[BuffType.CRITRate, 500],
[BuffType.CRITDMG, 500],
[BuffType.Heal, 500],
[BuffType.ElementalMastery, 200],
],
];

/** 最大强化等级 */
export const MAX_POWERUP_LEVEL: number[] = [4, 4, 12, 16, 20];

/** 最大初始词条 */
export const MAX_SUB_PROPS: number[] = [0, 1, 2, 3, 4];

/** 最大强化次数 */
export const MAX_POWERUP_PROPS: number[] = [1, 1, 2, 3, 6]; // 0 4 8 12 16 20

/** 副词条取值 */
export const SUB_PROPERTY: number[][][] = [
export const SUB_PROPERTY: [BuffType, number[]][][] = [
[
[23.9, 29.88],
[0.0117, 0.0146],
[1.56, 1.95],
[0.0117, 0.0146],
[1.85, 2.31],
[0.0146, 0.0182],
[0.013, 0.0162],
[4.66, 5.83],
[0.0078, 0.0097],
[0.0155, 0.0194],
[BuffType.HPDelta, [23.9, 29.88]],
[BuffType.HPRatio, [0.0117, 0.0146]],
[BuffType.ATKDelta, [1.56, 1.95]],
[BuffType.ATKRatio, [0.0117, 0.0146]],
[BuffType.DEFDelta, [1.85, 2.31]],
[BuffType.DEFRatio, [0.0146, 0.0182]],
[BuffType.EnergyRecharge, [0.013, 0.0162]],
[BuffType.ElementalMastery, [4.66, 5.83]],
[BuffType.CRITRate, [0.0078, 0.0097]],
[BuffType.CRITDMG, [0.0155, 0.0194]],
],
[
[50.19, 60.95, 71.7],
[0.0163, 0.0198, 0.0233],
[3.27, 3.97, 4.67],
[0.0163, 0.0198, 0.0233],
[3.89, 4.72, 5.56],
[0.0204, 0.0248, 0.0291],
[0.0181, 0.022, 0.0259],
[6.53, 7.93, 9.33],
[0.0109, 0.0132, 0.0155],
[0.0218, 0.0264, 0.0311],
[BuffType.HPDelta, [50.19, 60.95, 71.7]],
[BuffType.HPRatio, [0.0163, 0.0198, 0.0233]],
[BuffType.ATKDelta, [3.27, 3.97, 4.67]],
[BuffType.ATKRatio, [0.0163, 0.0198, 0.0233]],
[BuffType.DEFDelta, [3.89, 4.72, 5.56]],
[BuffType.DEFRatio, [0.0204, 0.0248, 0.0291]],
[BuffType.EnergyRecharge, [0.0181, 0.022, 0.0259]],
[BuffType.ElementalMastery, [6.53, 7.93, 9.33]],
[BuffType.CRITRate, [0.0109, 0.0132, 0.0155]],
[BuffType.CRITDMG, [0.0218, 0.0264, 0.0311]],
],
[
[100.38, 114.72, 129.06, 143.4],
[0.0245, 0.028, 0.0315, 0.035],
[6.54, 7.47, 8.4, 9.34],
[0.0245, 0.028, 0.0315, 0.035],
[7.78, 8.89, 10, 11.11],
[0.0306, 0.035, 0.0393, 0.0437],
[0.0272, 0.0311, 0.035, 0.0389],
[9.79, 11.19, 12.59, 13.99],
[0.0163, 0.0186, 0.021, 0.0233],
[0.0326, 0.0373, 0.042, 0.0466],
[BuffType.HPDelta, [100.38, 114.72, 129.06, 143.4]],
[BuffType.HPRatio, [0.0245, 0.028, 0.0315, 0.035]],
[BuffType.ATKDelta, [6.54, 7.47, 8.4, 9.34]],
[BuffType.ATKRatio, [0.0245, 0.028, 0.0315, 0.035]],
[BuffType.DEFDelta, [7.78, 8.89, 10, 11.11]],
[BuffType.DEFRatio, [0.0306, 0.035, 0.0393, 0.0437]],
[BuffType.EnergyRecharge, [0.0272, 0.0311, 0.035, 0.0389]],
[BuffType.ElementalMastery, [9.79, 11.19, 12.59, 13.99]],
[BuffType.CRITRate, [0.0163, 0.0186, 0.021, 0.0233]],
[BuffType.CRITDMG, [0.0326, 0.0373, 0.042, 0.0466]],
],
[
[167.3, 191.2, 215.1, 239],
[0.0326, 0.0373, 0.042, 0.0466],
[10.89, 12.45, 14, 15.56],
[0.0326, 0.0373, 0.042, 0.0466],
[12.96, 14.82, 16.67, 18.52],
[0.0408, 0.0466, 0.0525, 0.0583],
[0.0363, 0.0414, 0.0466, 0.0518],
[13.06, 14.92, 16.79, 18.65],
[0.0218, 0.0249, 0.028, 0.0311],
[0.0435, 0.0497, 0.056, 0.0622],
[BuffType.HPDelta, [167.3, 191.2, 215.1, 239]],
[BuffType.HPRatio, [0.0326, 0.0373, 0.042, 0.0466]],
[BuffType.ATKDelta, [10.89, 12.45, 14, 15.56]],
[BuffType.ATKRatio, [0.0326, 0.0373, 0.042, 0.0466]],
[BuffType.DEFDelta, [12.96, 14.82, 16.67, 18.52]],
[BuffType.DEFRatio, [0.0408, 0.0466, 0.0525, 0.0583]],
[BuffType.EnergyRecharge, [0.0363, 0.0414, 0.0466, 0.0518]],
[BuffType.ElementalMastery, [13.06, 14.92, 16.79, 18.65]],
[BuffType.CRITRate, [0.0218, 0.0249, 0.028, 0.0311]],
[BuffType.CRITDMG, [0.0435, 0.0497, 0.056, 0.0622]],
],
[
[209.13, 239, 268.88, 298.75],
[0.0408, 0.0466, 0.0525, 0.0583],
[13.62, 15.56, 17.51, 19.45],
[0.0408, 0.0466, 0.0525, 0.0583],
[16.2, 18.52, 20.83, 23.15],
[0.051, 0.0583, 0.0656, 0.0729],
[0.0453, 0.0518, 0.0583, 0.0648],
[16.32, 18.65, 20.98, 23.31],
[0.0272, 0.0311, 0.035, 0.0389],
[0.0544, 0.0622, 0.0699, 0.0777],
[BuffType.HPDelta, [209.13, 239, 268.88, 298.75]],
[BuffType.HPRatio, [0.0408, 0.0466, 0.0525, 0.0583]],
[BuffType.ATKDelta, [13.62, 15.56, 17.51, 19.45]],
[BuffType.ATKRatio, [0.0408, 0.0466, 0.0525, 0.0583]],
[BuffType.DEFDelta, [16.2, 18.52, 20.83, 23.15]],
[BuffType.DEFRatio, [0.051, 0.0583, 0.0656, 0.0729]],
[BuffType.EnergyRecharge, [0.0453, 0.0518, 0.0583, 0.0648]],
[BuffType.ElementalMastery, [16.32, 18.65, 20.98, 23.31]],
[BuffType.CRITRate, [0.0272, 0.0311, 0.035, 0.0389]],
[BuffType.CRITDMG, [0.0544, 0.0622, 0.0699, 0.0777]],
],
];

export const SUB_PROPERTY_WEIGHT = [150, 100, 150, 100, 150, 100, 100, 100, 75, 75];
export const SUB_PROPERTY_WEIGHT: [BuffType, number][] = [
[BuffType.HPDelta, 150],
[BuffType.HPRatio, 100],
[BuffType.ATKDelta, 150],
[BuffType.ATKRatio, 100],
[BuffType.DEFDelta, 150],
[BuffType.DEFRatio, 100],
[BuffType.EnergyRecharge, 100],
[BuffType.ElementalMastery, 100],
[BuffType.CRITRate, 75],
[BuffType.CRITDMG, 75],
];
}

export namespace ENEMY {
Expand Down
2 changes: 1 addition & 1 deletion nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default {
ignore: ["**/*.test.*", "**/*.spec.*", "cli/**"],

// Global CSS (https://go.nuxtjs.dev/config-css)
css: [],
css: ["~/assets/global.less"],

// Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)
plugins: [
Expand Down
Loading

0 comments on commit 05902ce

Please sign in to comment.