Skip to content

Commit

Permalink
feat(reward): 重构奖励系统
Browse files Browse the repository at this point in the history
  • Loading branch information
Encaik committed Dec 10, 2024
1 parent b9c6f21 commit f422c2c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export class RewardItemViewComponent implements OnInit {
getItemLevelClass = getItemLevelClass;

ngOnInit() {
this.rewardItems = this.reward.map(item => ItemMap[item]);
this.rewardItems = this.reward.map(item => ItemMap[item.id]);
}
}
28 changes: 26 additions & 2 deletions src/app/models/reward.model.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
export type RewardPool = string[];
export type RewardPool = RewardPoolItem[];

export interface RewardPoolItem {
id: string;
times: number;
probability: number;
}

export interface RewardItem {
id: string;
count: number;
}

export class RewardPoolMap {
static Challenge1: RewardPool = ['1'];
static Battle: RewardPool = [
{
id: '1',
times: 1,
probability: 1
},
{
id: '40000',
times: 10,
probability: 0.5
}
];
static Challenge1: RewardPool = [
{
id: '1',
times: 1,
probability: 1
}
];
}
21 changes: 10 additions & 11 deletions src/app/pages/home/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, inject, OnInit } from '@angular/core';
import { LogType, LogLevel, BattleCharacter, CharacterEventOperate, EventType, EventRes } from '@models';
import { LogType, LogLevel, BattleCharacter, CharacterEventOperate, EventType, EventRes, RewardPoolMap } from '@models';
import { CharacterService, LogService, RuntimeService, BattleService, EnvService, BackpackService, EventService } from '@services';
import { GenerateService } from '@shared';
import { Generate } from '@utils/generate';
Expand Down Expand Up @@ -122,16 +122,15 @@ export class HomeComponent implements OnInit {
});
this.enemys = this.enemys.filter(item => item.id !== enemy.id);
this.enemys.push(...Generate.enemys(1, this.characterSrv.levelInfo.level));
this.backpackSrv.addRewardItems([
{
id: '40000',
count: 1
},
{
id: '1',
count: Math.round(Math.random() * 100)
}
]);
this.backpackSrv.addRewardItems(
RewardPoolMap.Battle.map(reward => ({
id: reward.id,
count: Array.from({ length: reward.times }, () => (Math.random() <= reward.probability ? 1 : 0)).reduce(
(a: number, b: number) => a + b,
0
)
}))
);
} else {
this.enemys.forEach(item => {
item.statusInfo.hp = item.attrInfo.hp;
Expand Down

1 comment on commit f422c2c

@vercel
Copy link

@vercel vercel bot commented on f422c2c Dec 10, 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-git-main-encaiks-projects.vercel.app
wanjie-encaiks-projects.vercel.app

Please sign in to comment.