Skip to content

Commit

Permalink
feat(): 添加敌人生成等级
Browse files Browse the repository at this point in the history
  • Loading branch information
Encaik committed Sep 20, 2024
1 parent 4ce7e51 commit 5b9ec04
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/app/components/battle-modal/battle-modal.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { CommonModule } from '@angular/common';
import { Component, Input, OnInit } from '@angular/core';
import { Component, inject, Input, OnInit } from '@angular/core';
import { NzDescriptionsModule } from 'ng-zorro-antd/descriptions';
import { interval, Subscription, takeWhile } from 'rxjs';

import { BattleCharacter, BattleInfo, BattleStatusInfo } from '../../models';
import { EnvService } from '../../services/env.service';
import { ProgressViewComponent } from '../progress-view/progress-view.component';

@Component({
Expand All @@ -13,6 +14,8 @@ import { ProgressViewComponent } from '../progress-view/progress-view.component'
templateUrl: './battle-modal.component.html'
})
export class BattleModalComponent implements OnInit {
private envSrv = inject(EnvService);

@Input() leftCharacters: BattleCharacter[] = [];
@Input() rightCharacters: BattleCharacter[] = [];

Expand Down Expand Up @@ -89,7 +92,7 @@ export class BattleModalComponent implements OnInit {

battle(currentCharacter: BattleCharacter, targetCharacter: BattleCharacter) {
this.battleLogs.push(
`${this.getName(currentCharacter)} 攻击 ${this.getName(targetCharacter)}, 造成 ${currentCharacter!.attrInfo.attack} 点伤害`
`${this.getName(currentCharacter)}(${this.envSrv.levelMap[currentCharacter.levelInfo.level]}) 攻击 ${this.getName(targetCharacter)}(${this.envSrv.levelMap[targetCharacter.levelInfo.level]}), 造成 ${currentCharacter!.attrInfo.attack} 点伤害`
);
targetCharacter!.statusInfo.hp -= currentCharacter!.attrInfo.attack;
if (targetCharacter!.statusInfo.hp <= 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ export class HomeComponent {
});
const instance = modal.getContentComponent();
instance.leftCharacters = [this.characterSrv.getCharacter()];
instance.rightCharacters = Generate.enemys(1);
instance.rightCharacters = Generate.enemys(1, this.characterSrv.levelInfo.level);
}
}
17 changes: 12 additions & 5 deletions src/app/utils/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,21 @@ export class Generate {
}));
}

static enemys(length: number): BattleCharacter[] {
static enemys(length: number, level: number = 0): BattleCharacter[] {
return Array.from({ length }, (_, i) => {
const attrInfo = {
const skillInfo = {
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),
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,
critRate: Math.round(Math.random() * 5) + 2,
critDamage: Math.round(Math.random() * 20) + 10
};
Expand All @@ -70,8 +77,8 @@ export class Generate {
buffs: []
},
levelInfo: {
energy: Math.round(Math.random() * 1000),
level: 0
energy: level * 100,
level
},
attrInfo
};
Expand Down

1 comment on commit 5b9ec04

@vercel
Copy link

@vercel vercel bot commented on 5b9ec04 Sep 20, 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.vercel.app
wanjie-encaiks-projects.vercel.app
wanjie-git-main-encaiks-projects.vercel.app

Please sign in to comment.