-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
137 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,54 @@ | ||
import { Component, inject, OnInit } from '@angular/core'; | ||
import { NzButtonModule } from 'ng-zorro-antd/button'; | ||
import { NzEmptyModule } from 'ng-zorro-antd/empty'; | ||
import { NzTypographyModule } from 'ng-zorro-antd/typography'; | ||
|
||
import { ItemMap, Task } from '../../../../models'; | ||
import { getItemLevelClass, ItemMap, LogLevel, LogType, Task } from '../../../../models'; | ||
import { BackpackService } from '../../../../services/backpack.service'; | ||
import { LogService } from '../../../../services/log.service'; | ||
import { StatisticsService } from '../../../../services/statistics.service'; | ||
import { TaskService } from '../../../../services/task.service'; | ||
|
||
@Component({ | ||
selector: 'app-task', | ||
standalone: true, | ||
imports: [NzTypographyModule, NzEmptyModule], | ||
imports: [NzTypographyModule, NzEmptyModule, NzButtonModule], | ||
templateUrl: './task.component.html' | ||
}) | ||
export class TaskComponent implements OnInit { | ||
private taskSrv = inject(TaskService); | ||
private statisticsService = inject(StatisticsService); | ||
private backpackSrv = inject(BackpackService); | ||
private logSrv = inject(LogService); | ||
currentTask: Task | undefined; | ||
|
||
ItemMap = ItemMap; | ||
|
||
ngOnInit(): void { | ||
this.taskSrv.task$.subscribe(task => (this.currentTask = task)); | ||
this.statisticsService.statistics$.subscribe(event => { | ||
if (!this.currentTask) return; | ||
this.currentTask.isCompleted = this.currentTask.conditions.every( | ||
condition => | ||
condition.type === event.type && | ||
condition.field === event.field && | ||
condition.count <= this.statisticsService.getValue(condition.type, condition.field) | ||
); | ||
}); | ||
} | ||
|
||
onGetRewardClick() { | ||
if (!this.currentTask) return; | ||
let msg: string = ''; | ||
this.currentTask.rewards.forEach(reward => { | ||
const item = ItemMap[reward.id]; | ||
this.backpackSrv.addItem(item, reward.count); | ||
msg += `<span class="${getItemLevelClass(item.level)}">${item.name}</span> * ${reward.count} `; | ||
}); | ||
this.logSrv.log({ | ||
msg: `完成任务,获得奖励:${msg}`, | ||
type: LogType.Item, | ||
level: LogLevel.Info | ||
}); | ||
this.currentTask && this.taskSrv.complatedTask(this.currentTask); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export interface CharacterStatistics { | ||
cultivationCount: number; | ||
} | ||
|
||
export interface StatisticsEvent { | ||
type: StatisticsEventType; | ||
field: string; | ||
count: number; | ||
} | ||
|
||
export enum StatisticsEventType { | ||
Character | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { StatisticsService } from './statistics.service'; | ||
|
||
describe('StatisticsService', () => { | ||
let service: StatisticsService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(StatisticsService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Injectable, OnInit } from '@angular/core'; | ||
import { Subject } from 'rxjs'; | ||
|
||
import { CharacterStatistics, StatisticsEvent, StatisticsEventType } from '../models'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class StatisticsService { | ||
characterStatistics: CharacterStatistics = { | ||
cultivationCount: 0 | ||
}; | ||
statistics: Subject<StatisticsEvent> = new Subject(); | ||
statistics$ = this.statistics.asObservable(); | ||
|
||
update(event: StatisticsEvent) { | ||
switch (event.type) { | ||
case StatisticsEventType.Character: | ||
(this.characterStatistics as any)[event.field] += event.count; | ||
break; | ||
} | ||
this.statistics.next(event); | ||
} | ||
|
||
getValue(type: StatisticsEventType, field: string) { | ||
switch (type) { | ||
case StatisticsEventType.Character: | ||
return (this.characterStatistics as any)[field]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0f5a7c2
There was a problem hiding this comment.
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