From f422c2c2a4a97a96f2b5907191b586c0f112fd66 Mon Sep 17 00:00:00 2001 From: shatong <843391622@qq.com> Date: Tue, 10 Dec 2024 15:22:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(reward):=20=E9=87=8D=E6=9E=84=E5=A5=96?= =?UTF-8?q?=E5=8A=B1=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reward-item-view.component.ts | 2 +- src/app/models/reward.model.ts | 28 +++++++++++++++++-- src/app/pages/home/home.component.ts | 21 +++++++------- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/app/components/reward-item-view/reward-item-view.component.ts b/src/app/components/reward-item-view/reward-item-view.component.ts index 3c60fda..e1cc67b 100644 --- a/src/app/components/reward-item-view/reward-item-view.component.ts +++ b/src/app/components/reward-item-view/reward-item-view.component.ts @@ -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]); } } diff --git a/src/app/models/reward.model.ts b/src/app/models/reward.model.ts index 0fe7099..54b3434 100644 --- a/src/app/models/reward.model.ts +++ b/src/app/models/reward.model.ts @@ -1,4 +1,10 @@ -export type RewardPool = string[]; +export type RewardPool = RewardPoolItem[]; + +export interface RewardPoolItem { + id: string; + times: number; + probability: number; +} export interface RewardItem { id: string; @@ -6,5 +12,23 @@ export interface RewardItem { } 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 + } + ]; } diff --git a/src/app/pages/home/home.component.ts b/src/app/pages/home/home.component.ts index 9a13102..656d86e 100644 --- a/src/app/pages/home/home.component.ts +++ b/src/app/pages/home/home.component.ts @@ -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'; @@ -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;