Skip to content

Commit

Permalink
refactor(功法、生成逻辑): 功法和属性名称变更及代码调整
Browse files Browse the repository at this point in the history
  • Loading branch information
Encaik committed Sep 28, 2024
1 parent b73c2f4 commit b01d871
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 51 deletions.
20 changes: 20 additions & 0 deletions src/app/assets/data/method-suit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"xianxia": ["逍遥诀", "乾坤大挪移", "九阳神功", "太乙真经", "玉女心经", "玄天剑法", "金刚不坏体", "九阴白骨爪", "紫霞神功", "北冥神功"],
"magic": ["幻影咒", "光明圣典", "黑暗秘法", "元素融合术", "灵魂束缚咒", "星辰召唤", "元素风暴", "禁咒之书", "魔力涌动", "时光逆流"],
"fantasy": ["精灵之歌", "龙语魔法", "亡灵召唤术", "元素之舞", "光之祈祷", "暗影潜行", "自然之怒", "梦境编织", "神谕降临", "时空裂缝"],
"technology": [
"量子跃迁",
"神经链接",
"反重力引擎",
"时间加速仪",
"能量护盾",
"纳米修复",
"智能矩阵",
"量子纠缠器",
"空间折叠技术",
"光速引擎"
],
"modern": ["格斗奥义", "枪械精通", "战术指挥", "黑客帝国", "狙击艺术", "特战突击", "信息战术", "潜行大师", "爆破专家", "心理战术"],
"imperial": ["帝王心术", "治国方略", "兵法六韬", "龙战于野", "一统江山", "九鼎之重", "天子剑意", "御龙在天", "天下布武", "皇极经世"],
"adventure": ["荒野求生", "宝藏探寻", "迷宫解谜", "勇者斗恶龙", "神秘遗迹", "航海日志", "大陆探险", "遗迹守护", "秘境追踪", "异界旅行"]
}
10 changes: 5 additions & 5 deletions src/app/components/init-modal/init-modal.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
<nz-tag>{{ item.name }}</nz-tag>
}
</nz-descriptions-item>
<nz-descriptions-item nzTitle="生命">{{ item.skillInfo.hp }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="灵力">{{ item.skillInfo.mp }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="攻击">{{ item.skillInfo.attack }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="防御">{{ item.skillInfo.defence }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="敏捷">{{ item.skillInfo.speed }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="生命">{{ item.innateInfo.hp }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="灵力">{{ item.innateInfo.mp }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="攻击">{{ item.innateInfo.attack }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="防御">{{ item.innateInfo.defence }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="敏捷">{{ item.innateInfo.speed }}</nz-descriptions-item>
</nz-descriptions>
</div>
}
Expand Down
10 changes: 5 additions & 5 deletions src/app/layouts/character/character.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ <h5 nz-typography class="underline decoration-sky-500">战斗属性</h5>
</nz-descriptions>
<h5 nz-typography class="underline decoration-sky-500">天资属性</h5>
<nz-descriptions nzSize="small" [nzColumn]="{ xxl: 2, xl: 2, lg: 2, md: 2, sm: 2, xs: 3 }">
<nz-descriptions-item nzTitle="生命">{{ character.skillInfo.hp }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="灵力">{{ character.skillInfo.mp }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="攻击">{{ character.skillInfo.attack }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="防御">{{ character.skillInfo.defence }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="敏捷">{{ character.skillInfo.speed }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="生命">{{ character.innateInfo.hp }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="灵力">{{ character.innateInfo.mp }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="攻击">{{ character.innateInfo.attack }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="防御">{{ character.innateInfo.defence }}</nz-descriptions-item>
<nz-descriptions-item nzTitle="敏捷">{{ character.innateInfo.speed }}</nz-descriptions-item>
</nz-descriptions>
</div>
2 changes: 1 addition & 1 deletion src/app/models/battle.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export interface BattleInfo {
round: number;
}

export type BattleCharacter = Omit<Character, 'skillInfo'> & { isEnemy?: boolean };
export type BattleCharacter = Omit<Character, 'innateInfo'> & { isEnemy?: boolean };
4 changes: 2 additions & 2 deletions src/app/models/character.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface Character {
id: string;
baseInfo: BaseInfo; // 基本信息
statusInfo: StatusInfo; // 状态信息
skillInfo: SkillInfo; // 技能点信息
innateInfo: InnateInfo; // 技能点信息
levelInfo: LevelInfo; // 等级信息
attrInfo: AttrInfo; // 属性信息
}
Expand All @@ -29,7 +29,7 @@ export interface StatusInfo {
buffs: Buff[]; // 当前获得的状态
}

export interface SkillInfo {
export interface InnateInfo {
hp: number; // 基础生命
mp: number; // 基础灵力
attack: number; // 攻击力
Expand Down
3 changes: 3 additions & 0 deletions src/app/models/env.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { MethodSuit } from './method.model';

export interface Env {
id: string;
name: string; // 环境名称
Expand All @@ -6,6 +8,7 @@ export interface Env {
maxExp: number; // 最大经验值
weight: number; // 权重
galaxiesId: string; // 所属星系id
methodSuits: MethodSuit[];
}

export enum EnvType {
Expand Down
1 change: 1 addition & 0 deletions src/app/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from './env.model'; // 环境
export * from './event.model'; // 事件
export * from './item.model'; // 物品
export * from './log.model'; // 日志
export * from './method.model'; // 功法
export * from './reward.model'; // 奖励池
export * from './runtime.model'; // 运行时
export * from './statistics.model'; // 统计
Expand Down
18 changes: 18 additions & 0 deletions src/app/models/method.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export interface MethodConfig {
methods: Map<number, MethodBook>;
}

export interface MethodBook {
id: string;
suit: MethodSuit; // 功法体系
level: number; // 当前残本对应体系等级
skill: MethodSkill; // 功法技能
}

export interface MethodSuit {
name: string; // 功法体系名称
}

export interface MethodSkill {
name: string; // 功法技能名称
}
8 changes: 7 additions & 1 deletion src/app/pages/method/method.component.html
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
<p>method works!</p>
@for (item of mothodConfig.methods; track $index) {
<nz-card>
<div class="flex flex-col gap-2">
{{ item }}
</div>
</nz-card>
}
14 changes: 11 additions & 3 deletions src/app/pages/method/method.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { MethodBook, MethodConfig } from '@models';
import { NzCardModule } from 'ng-zorro-antd/card';

@Component({
selector: 'app-method',
standalone: true,
imports: [],
imports: [NzCardModule],
templateUrl: './method.component.html',
styleUrl: './method.component.less'
})
export class MethodComponent {}
export class MethodComponent implements OnInit {
mothodConfig: MethodConfig = {
methods: new Map()
};

ngOnInit() {}
}
24 changes: 12 additions & 12 deletions src/app/services/character.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { inject, Injectable } from '@angular/core';
import { delay, Observable, of } from 'rxjs';

import { BaseInfo, Character, LogLevel, LogType, SkillInfo, StatusInfo, LevelInfo, AttrInfo } from '../models';
import { BaseInfo, Character, LogLevel, LogType, InnateInfo, StatusInfo, LevelInfo, AttrInfo } from '../models';
import { CharacterEventOperate, Event, EventRes } from '../models/event.model';
import { StatisticsService } from '../storages/statistics.service';
import { EnvService } from './env.service';
Expand Down Expand Up @@ -35,7 +35,7 @@ export class CharacterService {
power: 0,
level: 0
};
skillInfo: SkillInfo = {
innateInfo: InnateInfo = {
hp: 0,
mp: 0,
attack: 0,
Expand Down Expand Up @@ -112,16 +112,16 @@ export class CharacterService {
level: level + 1
});
this.logSrv.log({
msg: `恭喜你,获得了${this.skillInfo.hp}点生命,${this.skillInfo.mp}点灵力,${this.skillInfo.attack}点攻击,${this.skillInfo.defence}点防御和${this.skillInfo.speed}点敏捷\n`,
msg: `恭喜你,获得了${this.innateInfo.hp}点生命,${this.innateInfo.mp}点灵力,${this.innateInfo.attack}点攻击,${this.innateInfo.defence}点防御和${this.innateInfo.speed}点敏捷\n`,
type: LogType.Character,
level: LogLevel.Info
});
this.setAttrInfo({
hp: this.attrInfo.hp + this.skillInfo.hp,
mp: this.attrInfo.mp + this.skillInfo.mp,
attack: this.attrInfo.attack + this.skillInfo.attack,
defence: this.attrInfo.defence + this.skillInfo.defence,
speed: this.attrInfo.speed + this.skillInfo.speed
hp: this.attrInfo.hp + this.innateInfo.hp,
mp: this.attrInfo.mp + this.innateInfo.mp,
attack: this.attrInfo.attack + this.innateInfo.attack,
defence: this.attrInfo.defence + this.innateInfo.defence,
speed: this.attrInfo.speed + this.innateInfo.speed
});
this.canUpgrade = false;
}
Expand All @@ -142,7 +142,7 @@ export class CharacterService {
baseInfo: this.baseInfo,
statusInfo: this.statusInfo,
levelInfo: this.levelInfo,
skillInfo: this.skillInfo,
innateInfo: this.innateInfo,
attrInfo: this.attrInfo
};
}
Expand All @@ -151,7 +151,7 @@ export class CharacterService {
character.id && (this.id = character.id);
character.baseInfo && this.setBaseInfo(character.baseInfo);
character.statusInfo && this.setStatusInfo(character.statusInfo);
character.skillInfo && this.setSkillInfo(character.skillInfo);
character.innateInfo && this.setInnateInfo(character.innateInfo);
character.attrInfo && this.setAttrInfo(character.attrInfo);
character.levelInfo && this.setLevelInfo(character.levelInfo);
}
Expand Down Expand Up @@ -190,8 +190,8 @@ export class CharacterService {
this.levelInfo = { ...this.levelInfo, ...levelInfo };
}

setSkillInfo(skillInfo: Partial<SkillInfo>) {
this.skillInfo = { ...this.skillInfo, ...skillInfo };
setInnateInfo(innateInfo: Partial<InnateInfo>) {
this.innateInfo = { ...this.innateInfo, ...innateInfo };
this.updatePower();
}

Expand Down
10 changes: 5 additions & 5 deletions src/app/utils/generate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ describe('Util Generate', () => {
expect(character.baseInfo.gender).toMatch(/^(男|女)$/);
expect(character.baseInfo.age).toBeGreaterThanOrEqual(12);
expect(character.baseInfo.talent).toEqual(jasmine.any(Array));
expect(character.skillInfo.hp).toBeGreaterThanOrEqual(100);
expect(character.skillInfo.mp).toBeGreaterThanOrEqual(100);
expect(character.skillInfo.attack).toBeGreaterThanOrEqual(20);
expect(character.skillInfo.defence).toBeGreaterThanOrEqual(20);
expect(character.skillInfo.speed).toBeGreaterThanOrEqual(0);
expect(character.innateInfo.hp).toBeGreaterThanOrEqual(100);
expect(character.innateInfo.mp).toBeGreaterThanOrEqual(100);
expect(character.innateInfo.attack).toBeGreaterThanOrEqual(20);
expect(character.innateInfo.defence).toBeGreaterThanOrEqual(20);
expect(character.innateInfo.speed).toBeGreaterThanOrEqual(0);
});
});
});
Expand Down
46 changes: 29 additions & 17 deletions src/app/utils/generate.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import LEVELMAP from '@assets/data/level-map.json';
import METHODS_SUITS from '@assets/data/method-suit.json';
import NAMES from '@assets/data/names.json';
import SURNAMES from '@assets/data/surnames.json';
import TALENTS from '@assets/data/talents.json';
import WORLDS from '@assets/data/worlds.json';
import { BattleCharacter, CharacterTalent, Env, EnvType, InitCharacter, MethodSuit } from '@models';
import { v4 as uuidv4 } from 'uuid';

import LEVELMAP from '../assets/data/level-map.json';
import NAMES from '../assets/data/names.json';
import SURNAMES from '../assets/data/surnames.json';
import TALENTS from '../assets/data/talents.json';
import WORLDS from '../assets/data/worlds.json';
import { BattleCharacter, CharacterTalent, Env, EnvType, InitCharacter } from '../models';

const SURNAMES_LEN = SURNAMES.length;
const NAMES_LEN = NAMES.length;
const WORLDS_LEN = WORLDS.length;
const TALENTS_LEN = TALENTS.length;

/**
Expand All @@ -34,7 +33,7 @@ export class Generate {
age: Math.floor(Math.random() * 10) * 2 + 12,
talent: getCharacterTalent(1)
},
skillInfo: {
innateInfo: {
hp: Math.round(Math.random() * 40) + 100,
mp: Math.round(Math.random() * 40) + 100,
attack: Math.round(Math.random() * 40) + 20,
Expand All @@ -46,19 +45,19 @@ export class Generate {

static enemys(length: number, level: number = 0): BattleCharacter[] {
return Array.from({ length }, (_, i) => {
const skillInfo = {
const innateInfo = {
hp: Math.round(Math.random() * 40) + 100,
mp: Math.round(Math.random() * 40) + 100,
attack: Math.round(Math.random() * 40) + 20,
defence: Math.round(Math.random() * 40) + 20,
speed: Math.round(Math.random() * 40)
};
const attrInfo = {
hp: (1 + level) * skillInfo.hp,
mp: (1 + level) * skillInfo.mp,
attack: (1 + level) * skillInfo.attack,
defence: (1 + level) * skillInfo.defence,
speed: (1 + level) * skillInfo.speed,
hp: (1 + level) * innateInfo.hp,
mp: (1 + level) * innateInfo.mp,
attack: (1 + level) * innateInfo.attack,
defence: (1 + level) * innateInfo.defence,
speed: (1 + level) * innateInfo.speed,
critRate: Math.round(Math.random() * 5) + 2,
critDamage: Math.round(Math.random() * 20) + 10
};
Expand Down Expand Up @@ -107,20 +106,33 @@ export class Generate {
envs: Array.from({ length }, (_, i) => {
const weight: number = Number((Math.random() * 0.5 + 0.75).toFixed(2));
const type: EnvType = Object.values(EnvType)[Math.floor(Math.random() * Object.keys(EnvType).length)];
const WORLDS_NAMES = WORLDS[type];
const WORLDS_LEN = WORLDS_NAMES.length;
return {
id: `env-${uuidv4()}`,
name: WORLDS[Math.floor(Math.random() * WORLDS_LEN)],
name: WORLDS_NAMES[Math.floor(Math.random() * WORLDS_LEN)],
type,
galaxiesId,
levelMap: LEVELMAP[type][0],
weight,
// TODO: 测试用数据,调低了最大经验
maxExp: Math.round((Math.random() * 0.4 + 0.8) * weight * 10000)
maxExp: Math.round((Math.random() * 0.4 + 0.8) * weight * 10000),
methodSuits: this.methods(2, type)
};
}),
galaxiesId
};
}

static methods(length: number, type: EnvType): MethodSuit[] {
const METHODS_SUITS_NAMES = METHODS_SUITS[type];
const METHODS_SUITS_LEN = METHODS_SUITS_NAMES.length;
return Array.from({ length }, (_, i) => {
return {
name: METHODS_SUITS_NAMES[Math.floor(Math.random() * METHODS_SUITS_LEN)]
};
});
}
}

/**
Expand Down

1 comment on commit b01d871

@vercel
Copy link

@vercel vercel bot commented on b01d871 Sep 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

wanjie – ./

wanjie-git-main-encaiks-projects.vercel.app
wanjie.vercel.app
wanjie-encaiks-projects.vercel.app

Please sign in to comment.