change talent replace before property allocate

This commit is contained in:
Vick Scarlet
2021-12-14 18:47:05 +08:00
parent f4d7b3ae3c
commit a1e4232369
9 changed files with 48 additions and 27 deletions

View File

@@ -120,9 +120,14 @@ class App{
$ui.popup(UI.popups.ACHIEVEMENT, {achievement}); $ui.popup(UI.popups.ACHIEVEMENT, {achievement});
}) })
$$on('message', ([message, ...args]) => { $$on('message', ([message, ...args]) => {
$ui.popup(UI.popups.MESSAGE, {message: $_.format( if(Array.isArray(message)) {
$lang[message], ...args message = message.map(([m, ...a]) => $_.format($lang[m], ...a)) .join('\n');
) }); } else {
message = $_.format(
$lang[message], ...args
);
}
$ui.popup(UI.popups.MESSAGE, {message});
}) })
} }

View File

@@ -83,10 +83,17 @@ function deepMapSet(target, source) {
return target; return target;
} }
function deepGet(obj, path) {
for(const key of path.split('.')) {
if(!(key in obj)) return undefined;
obj = obj[key];
}
return obj;
}
function format(str, ...args) { function format(str, ...args) {
const replace = set => (match, key) => { const replace = set => (match, key) => {
const value = set[key]; const value = deepGet(set, key);
switch(typeof value) { switch(typeof value) {
case 'object': return JSON.stringify(value); case 'object': return JSON.stringify(value);
case 'boolean': case 'boolean':

View File

@@ -143,5 +143,6 @@ export default ({
F_TalentConflict: '与已选的「{0}」天赋冲突', F_TalentConflict: '与已选的「{0}」天赋冲突',
F_TalentSelectLimit: '只能选 {0} 个天赋', F_TalentSelectLimit: '只能选 {0} 个天赋',
F_TalentSelectNotComplect: '要选满{0}个天赋', F_TalentSelectNotComplect: '要选满{0}个天赋',
F_PropertyPointLeft: '你还有 {0} 属性点没有分配完' F_PropertyPointLeft: '你还有 {0} 属性点没有分配完',
F_TalentReplace: '天赋替换【{source.name}】->【{target.name}】',
}); });

View File

@@ -22,6 +22,7 @@ class Life {
#propertyAllocateLimit; #propertyAllocateLimit;
#defaultPropertys; #defaultPropertys;
#specialThanks; #specialThanks;
#initialData;
async initial(i18nLoad, commonLoad) { async initial(i18nLoad, commonLoad) {
const [age, talents, events, achievements, specialThanks] = await Promise.all([ const [age, talents, events, achievements, specialThanks] = await Promise.all([
@@ -58,25 +59,28 @@ class Life {
this.#property.config(propertyConfig); this.#property.config(propertyConfig);
} }
restart(allocation) { remake(talents) {
const propertys = clone(this.#defaultPropertys); this.#initialData = clone(this.#defaultPropertys);
for(const key in allocation) { this.#initialData.TLT = clone(talents);
propertys[key] = clone(allocation[key]);
}
this.#triggerTalents = {}; this.#triggerTalents = {};
const contents = this.talentReplace(propertys.TLT); return this.talentReplace(this.#initialData.TLT);
this.#property.restart(propertys); }
start(allocation) {
for(const key in allocation) {
this.#initialData[key] = clone(allocation[key]);
}
this.#property.restart(this.#initialData);
this.doTalent() this.doTalent()
this.#property.restartLastStep(); this.#property.restartLastStep();
this.#achievement.achieve( this.#achievement.achieve(
this.AchievementOpportunity.START, this.AchievementOpportunity.START,
this.#property this.#property
) );
return contents;
} }
getPropertyPoints(selectedTalentIds) { getPropertyPoints() {
return this.#defaultPropertyPoints + this.#talent.allocationAddition(selectedTalentIds); return this.#defaultPropertyPoints + this.#talent.allocationAddition(this.#initialData.TLT);
} }
getTalentCurrentTriggerCount(talentId) { getTalentCurrentTriggerCount(talentId) {

View File

@@ -41,9 +41,11 @@ export default class CyberProperty extends ui.view.CyberTheme.CyberPropertyUI {
init({talents}) { init({talents}) {
this.listSelectedTalents.array = talents; this.listSelectedTalents.array = talents;
const talentIds = talents.map(talent => talent.id); const replace = core.remake(talents.map(talent => talent.id));
// core.talentReplace(talentIds); if(replace.length > 0) {
this.#propertyPoints = core.getPropertyPoints(talentIds); $$event('message', [replace.map(v => ['F_TalentReplace', v])]);
}
this.#propertyPoints = core.getPropertyPoints();
this.#propertyAllocateLimit = core.propertyAllocateLimit; this.#propertyAllocateLimit = core.propertyAllocateLimit;
this.labLeftPropertyPoint.text = this.#propertyPoints; this.labLeftPropertyPoint.text = this.#propertyPoints;
this.#propertyAllocate = { this.#propertyAllocate = {
@@ -51,7 +53,6 @@ export default class CyberProperty extends ui.view.CyberTheme.CyberPropertyUI {
[this.#types.INT]: 0, [this.#types.INT]: 0,
[this.#types.STR]: 0, [this.#types.STR]: 0,
[this.#types.MNY]: 0, [this.#types.MNY]: 0,
[this.#types.TLT]: talentIds,
} }
this.updateAllocate(); this.updateAllocate();
} }

View File

@@ -74,7 +74,7 @@ export default class CyberTrajectory extends ui.view.CyberTheme.CyberTrajectoryU
this.#trajectoryItems = []; this.#trajectoryItems = [];
this.#isEnd = false; this.#isEnd = false;
this.#talents = talents; this.#talents = talents;
core.restart(propertyAllocate); core.start(propertyAllocate);
this.updateProperty(); this.updateProperty();
this.onNext(); this.onNext();
} }

View File

@@ -41,9 +41,11 @@ export default class Property extends ui.view.DefaultTheme.PropertyUI {
init({talents}) { init({talents}) {
this.listSelectedTalents.array = talents; this.listSelectedTalents.array = talents;
const talentIds = talents.map(talent => talent.id); const replace = core.remake(talents.map(talent => talent.id));
// core.talentReplace(talentIds); if(replace.length > 0) {
this.#propertyPoints = core.getPropertyPoints(talentIds); $$event('message', [replace.map(v => ['F_TalentReplace', v])]);
}
this.#propertyPoints = core.getPropertyPoints();
this.#propertyAllocateLimit = core.propertyAllocateLimit; this.#propertyAllocateLimit = core.propertyAllocateLimit;
this.labLeftPropertyPoint.text = this.#propertyPoints; this.labLeftPropertyPoint.text = this.#propertyPoints;
this.#propertyAllocate = { this.#propertyAllocate = {
@@ -51,7 +53,6 @@ export default class Property extends ui.view.DefaultTheme.PropertyUI {
[this.#types.INT]: 0, [this.#types.INT]: 0,
[this.#types.STR]: 0, [this.#types.STR]: 0,
[this.#types.MNY]: 0, [this.#types.MNY]: 0,
[this.#types.TLT]: talentIds,
} }
this.updateAllocate(); this.updateAllocate();
} }

View File

@@ -53,7 +53,7 @@ export default class Trajectory extends ui.view.DefaultTheme.TrajectoryUI {
this.#trajectoryItems = []; this.#trajectoryItems = [];
this.#isEnd = false; this.#isEnd = false;
this.#talents = talents; this.#talents = talents;
core.restart(propertyAllocate); core.start(propertyAllocate);
this.updateProperty(); this.updateProperty();
this.onNext(); this.onNext();
} }

View File

@@ -8,10 +8,12 @@ export default class MessagePopup extends ui.view.MessagePopupUI {
} }
async popup({message}, parent) { async popup({message}, parent) {
this.message.text = message;
this.message.commitMeasure();
this.height = this.message.height + this.boxBg.radius * 2 + this.message.fontSize;
Laya.Tween.clearAll(this); Laya.Tween.clearAll(this);
this.alpha = 0; this.alpha = 0;
this.y = - 2 * this.height; this.y = - 2 * this.height;
this.message.text = message;
await Laya.promises.Tween.to(this, { y: 0, alpha: 1 }, 300, Laya.Ease.backOut), await Laya.promises.Tween.to(this, { y: 0, alpha: 1 }, 300, Laya.Ease.backOut),
await Laya.promises.Tween.to(this, { alpha: 0}, 300, Laya.Ease.strongIn, 3000); await Laya.promises.Tween.to(this, { alpha: 0}, 300, Laya.Ease.strongIn, 3000);
} }