完成度成就

This commit is contained in:
AncTe committed 2023-02-23 23:10:57 +08:00
1 parent 5dbe7654a4
commit 2ea95671a5
22 files changed
+279 -66

No files matched your search

+3 -3
View File
@@ -37,7 +37,7 @@
"text": [
"第一章完成度达到100%"
],
"progress": "100 / 100",
"progress": "${core.getChapterCompletion(1)} / 100",
"percent": true,
"point": 50
},
@@ -46,7 +46,7 @@
"text": [
"与山路上的若干个神秘木牌对话"
],
"progress": "5 / 5",
"progress": "${core.getLocalStorage('mountSign', 0)} / 5",
"hide": "该探索成就需要你自己探索如何达成",
"point": 25
},
@@ -55,7 +55,7 @@
"text": [
"第二章完成度达到100%"
],
"progress": "100 / 100",
"progress": "${core.getChapterCompletion(2)} / 100",
"percent": true,
"point": 50
},
+4 -1
View File
@@ -1,7 +1,10 @@
{
"fullscreen": {
"text": "全屏游戏",
"desc": ["是否全屏进行游戏"]
"desc": [
"是否全屏进行游戏,全屏后按ESC退出全屏,不能开启系统设置菜单,请按下方的按钮打开。",
"进入或退出全屏后请存读档一下,以解决一部分绘制问题。"
]
},
"transition": {
"text": "界面动画",
+12 -1
View File
@@ -13,6 +13,8 @@ import fixed from './plugin/ui/fixed';
import webglUtils from './plugin/webgl/utils';
import shadow from './plugin/shadow/shadow';
import gameShadow from './plugin/shadow/gameShadow';
import achievement from './plugin/ui/achievement';
import completion, { floors } from './plugin/completion';
function forward() {
const toForward: any[] = [
@@ -30,7 +32,9 @@ function forward() {
fixed(),
webglUtils(),
shadow(),
gameShadow()
gameShadow(),
achievement(),
completion()
];
// 初始化所有插件,并转发到core上
@@ -52,6 +56,13 @@ function forward() {
console.log('插件转发完成!');
})();
Object.values(floors).forEach((v, i) => {
const from = core.floorIds.indexOf(v[0]);
const to = core.floorIds.indexOf(v[1]);
const all = core.floorIds.slice(from, to + 1);
floors[i + 1] = all;
});
}
main.forward = forward;
+108
View File
@@ -0,0 +1,108 @@
import {
AchievementType,
completeAchievement,
hasCompletedAchievement
} from './ui/achievement';
import { changeLocalStorage } from './utils';
import list from '../data/achievement.json';
export default function init() {
return { getChapterCompletion, checkVisitedFloor };
}
export const floors: Record<number, FloorIds[]> = {
1: ['MT0', 'tower7']
};
const achis: Record<number, Record<AchievementType, number[]>> = {
1: {
normal: [0, 1],
challenge: [0],
explore: [1]
}
};
export const achiDict: Record<number, number> = {
1: 0
};
/**
* 检查所有到达过的楼层,用于成就的计算
*/
export function checkVisitedFloor() {
changeLocalStorage<Partial<Record<FloorIds, boolean>>>(
'visitedFloor',
data => {
let needUpdate = false;
core.floorIds.forEach(v => {
if (core.hasVisitedFloor(v)) {
data[v] = true;
needUpdate = true;
}
});
if (needUpdate) {
checkCompletionAchievement();
}
return data;
},
{}
);
}
/**
* 获取一个章节的完成度
* @param num 章节
*/
export function getChapterCompletion(num: number) {
if (!achis[num]) return 0;
let res = 0;
const all = floors[num];
const achiNum = Object.values(achis[num]).reduce(
(pre, cur) => pre + cur.length,
0
);
// 计算到达过的楼层
let visitedFloor = 0;
const visited = core.getLocalStorage<Partial<Record<FloorIds, boolean>>>(
'visitedFloor',
{}
);
all.forEach(v => {
if (visited[v]) visitedFloor++;
});
const floorRatio = all.length / (all.length + achiNum);
const floorPoint = (floorRatio * visitedFloor) / all.length;
let completedPoint = 0;
let totalPoint = 0;
// 计算成就,占比按成就点走
for (const [type, achi] of Object.entries(achis[num]) as [
AchievementType,
number[]
][]) {
achi.forEach(v => {
totalPoint += list[type][v].point;
if (hasCompletedAchievement(type, v)) {
completedPoint += list[type][v].point;
}
});
}
const achiPoint = (completedPoint / totalPoint) * (1 - floorRatio);
res = floorPoint + achiPoint;
return Math.floor(res * 100);
}
/**
* 检查完成度成就是否完成
*/
export function checkCompletionAchievement() {
[1].forEach(v => {
if (getChapterCompletion(v) >= 100) {
completeAchievement('explore', achiDict[v]);
}
});
}
+48 -9
View File
@@ -1,6 +1,7 @@
import { ref } from 'vue';
import list from '../../data/achievement.json';
import { has } from '../utils';
import { achiDict, checkCompletionAchievement } from '../completion';
import { changeLocalStorage, has } from '../utils';
type AchievementList = typeof list;
export type AchievementType = keyof AchievementList;
@@ -17,7 +18,7 @@ export interface Achievement {
}
export default function init() {
return {};
return { completeAchievement, hasCompletedAchievement, addMountSign };
}
export const showComplete = ref(false);
@@ -37,13 +38,22 @@ export const totalPoint = Object.values(list)
* @param index 成就索引
*/
export function completeAchievement(type: AchievementType, index: number) {
const now = core.getLocalStorage<AchievementData>('achievement', {
normal: [],
challenge: [],
explore: []
});
now[type][index] = true;
core.setLocalStorage('achievement', now);
if (flags.debug) return;
changeLocalStorage<AchievementData>(
'achievement',
data => {
data[type][index] = true;
return data;
},
{
normal: [],
challenge: [],
explore: []
}
);
if (type === 'explore' && !Object.values(achiDict).includes(index)) {
checkCompletionAchievement();
}
completeAchi.value = `${type},${index}`;
showComplete.value = true;
}
@@ -81,3 +91,32 @@ export function getNowPoint() {
}
return res;
}
// ----- 各个成就相关的函数
/**
* 山路木牌
* @param id 木牌id
*/
export function addMountSign(id: number) {
if (flags.debug) return;
if (
!core.getLocalStorage(`mountSign_${id}`, false) &&
!hasCompletedAchievement('explore', 1)
) {
changeLocalStorage(
'mountSign',
n => {
if (n + 1 >= 5) {
completeAchievement('explore', 1);
for (const i of [1, 2, 3, 4, 5]) {
core.removeLocalStorage(`mountSign_${i}`);
}
}
return n + 1;
},
0
);
core.setLocalStorage(`mountSign_${id}`, true);
}
}
+2 -1
View File
@@ -95,7 +95,8 @@ export default function init() {
shopOpened,
startOpened,
startAnimationEnded,
loaded
loaded,
achievementOpened
};
}
+17 -1
View File
@@ -15,7 +15,7 @@ type CanParseCss = keyof {
};
export default function init() {
return { has, getDamageColor, parseCss, tip };
return { has, getDamageColor, parseCss, tip, changeLocalStorage };
}
/**
@@ -212,3 +212,19 @@ export async function doByInterval(
}
}
}
/**
* 更改一个本地存储
* @param name 要更改的信息
* @param fn 更改时执行的函数
* @param defaultValue 如果不存在时获取的默认值
*/
export function changeLocalStorage<T>(
name: string,
fn: (data: T) => T,
defaultValue?: T
) {
const now = core.getLocalStorage(name, defaultValue);
const to = fn(now);
core.setLocalStorage(name, to);
}
+1
View File
@@ -569,6 +569,7 @@ interface IdToCls {
N639: 'npc48';
T640: 'terrains';
I641: 'items';
I642: 'items';
X20032: 'tileset';
X20033: 'tileset';
X20034: 'tileset';
+1
View File
@@ -186,4 +186,5 @@ interface ItemDeclaration {
I575: 'equips';
I589: 'equips';
I641: 'equips';
I642: 'constants';
}
+2
View File
@@ -569,6 +569,7 @@ interface IdToNumber {
N639: 639;
T640: 640;
I641: 641;
I642: 642;
X20032: 20032;
X20033: 20033;
X20034: 20034;
@@ -1221,6 +1222,7 @@ interface NumberToId {
639: 'N639';
640: 'T640';
641: 'I641';
642: 'I642';
20032: 'X20032';
20033: 'X20033';
20034: 'X20034';
+28 -1
View File
@@ -20,7 +20,8 @@ interface PluginDeclaration
PluginUse,
SkillTree,
MiniMap,
HeroRealStatus {
HeroRealStatus,
PluginAchievement {
/**
* 添加函数 例:添加弹出文字,像这个就可以使用core.addPop或core.plugin.addPop调用
* @param px 弹出的横坐标
@@ -389,6 +390,32 @@ interface HeroRealStatus {
): HeroStatus[K];
}
interface PluginAchievement {
/**
* 完成一个成就
* @param type 成就类型
* @param index 成就索引
*/
completeAchievement(type: AchievementType, index: number): void;
/**
* 是否完成了某个成就
* @param type 成就类型
* @param index 成就索引
*/
hasCompletedAchievement(type: AchievementType, index: number): boolean;
/**
* 获取当前成就点数
*/
getNowPoint(): number;
/**
* 检查所有到达过的楼层,用于成就的计算
*/
checkVisitedFloor(): void;
}
type Chapter = 'chapter1' | 'chapter2';
interface Skill {
+7 -2
View File
@@ -19,7 +19,7 @@
<div id="list">
<div id="achievement-list" :style="{ left: `-${offset}%` }">
<div v-for="t of column" class="achievement-one">
<Scroll class="list-scroll" :width="10">
<Scroll class="list-scroll" :width="isMobile ? 10 : 20">
<div class="list-div">
<div
v-for="a of getAllAchievements(t)"
@@ -107,6 +107,7 @@ import {
hasCompletedAchievement
} from '../plugin/ui/achievement';
import Scroll from '../components/scroll.vue';
import { isMobile } from '../plugin/use';
type AchievementList = typeof list;
type AchievementType = keyof AchievementList;
@@ -172,7 +173,11 @@ function getAllAchievements(type: AchievementType): ResolvedAchievement[] {
}
function exit() {
noClosePanel.value = true;
try {
core.closePanel();
} catch {
noClosePanel.value = true;
}
achievementOpened.value = false;
}
</script>
+3 -1
View File
@@ -112,7 +112,9 @@ type Settings = typeof settingInfo;
const core = window.core;
const selected = ref<keyof Settings>('transition');
const selected = ref<keyof Settings>('fullscreen');
fullscreen.value = !!document.fullscreenElement;
const descText = computed(() => {
return splitText(settingInfo[selected.value].desc);