@rpg-engine/long-bow 0.8.51 → 0.8.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpg-engine/long-bow",
3
- "version": "0.8.51",
3
+ "version": "0.8.53",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -21,6 +21,7 @@ interface IDailyTaskItemProps {
21
21
  itemsAtlasIMG: string;
22
22
  iconAtlasJSON?: Record<string, any>;
23
23
  iconAtlasIMG?: string;
24
+ isRewardClaimed: boolean;
24
25
  }
25
26
 
26
27
  export const DailyTaskItem: React.FC<IDailyTaskItemProps> = ({
@@ -31,11 +32,12 @@ export const DailyTaskItem: React.FC<IDailyTaskItemProps> = ({
31
32
  itemsAtlasIMG,
32
33
  iconAtlasJSON,
33
34
  iconAtlasIMG,
35
+ isRewardClaimed,
34
36
  }) => {
35
37
  const isMobile = isMobileOrTablet();
36
38
 
37
39
  const isCompleted = task.status === TaskStatus.Completed;
38
- const isClaimed = task.claimed;
40
+ const isClaimed = task.claimed || isRewardClaimed;
39
41
 
40
42
  const handleClaimReward = () => {
41
43
  onClaimReward(task.key, task.type);
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  ICharacterDailyTask,
3
3
  ICollectGlobalRewardRequest,
4
- ITaskIdentifier,
4
+ ICollectRewardRequest,
5
5
  TaskType,
6
6
  } from '@rpg-engine/shared';
7
- import React from 'react';
7
+ import React, { useState } from 'react';
8
8
  import styled from 'styled-components';
9
9
  import { uiColors } from '../../constants/uiColors';
10
10
  import { useResponsiveSize } from '../CraftBook/hooks/useResponsiveSize';
@@ -16,7 +16,7 @@ import { getTaskIcon } from './utils/dailyTasks.utils';
16
16
 
17
17
  export interface IDailyTasksProps {
18
18
  tasks: ICharacterDailyTask[];
19
- onClaimReward: (task: ITaskIdentifier) => void;
19
+ onClaimReward: (task: ICollectRewardRequest) => void;
20
20
  onClaimGlobalReward: (tasks: ICollectGlobalRewardRequest) => void;
21
21
  onClose: () => void;
22
22
  scale?: number;
@@ -24,6 +24,7 @@ export interface IDailyTasksProps {
24
24
  itemsAtlasIMG: string;
25
25
  iconAtlasJSON?: Record<string, any>;
26
26
  iconAtlasIMG?: string;
27
+ globalRewardClaimed?: boolean;
27
28
  }
28
29
 
29
30
  export const DailyTasks: React.FC<IDailyTasksProps> = ({
@@ -36,19 +37,30 @@ export const DailyTasks: React.FC<IDailyTasksProps> = ({
36
37
  itemsAtlasIMG,
37
38
  iconAtlasJSON,
38
39
  iconAtlasIMG,
40
+ globalRewardClaimed = false,
39
41
  }): JSX.Element | null => {
40
42
  const [localTasks] = React.useState(tasks);
41
43
  const size = useResponsiveSize(scale);
44
+ const [claimedTasks, setClaimedTasks] = useState<string[]>([]);
45
+ const [globalRewardClaimedLocal, setGlobalRewardClaimedLocal] = useState(
46
+ false
47
+ );
42
48
 
43
- const handleClaimReward = (taskKey: string, type: TaskType) => {
49
+ const handleClaimReward = (taskKey: string, taskType: TaskType) => {
44
50
  onClaimReward({
45
- type,
46
51
  taskKey,
52
+ type: taskType,
47
53
  });
54
+ setClaimedTasks(prev => [...prev, taskKey]);
48
55
  };
49
56
 
50
57
  const handleClaimGlobalRewards = (tasks: ICollectGlobalRewardRequest) => {
51
58
  onClaimGlobalReward(tasks);
59
+ setGlobalRewardClaimedLocal(true);
60
+ };
61
+
62
+ const isTaskRewardClaimed = (taskKey: string): boolean => {
63
+ return claimedTasks.includes(taskKey);
52
64
  };
53
65
 
54
66
  if (!size) return null;
@@ -68,6 +80,9 @@ export const DailyTasks: React.FC<IDailyTasksProps> = ({
68
80
  <GlobalDailyProgress
69
81
  tasks={localTasks}
70
82
  onClaimAllRewards={handleClaimGlobalRewards}
83
+ globalRewardClaimed={
84
+ globalRewardClaimed || globalRewardClaimedLocal
85
+ }
71
86
  />
72
87
  {localTasks.map(task => (
73
88
  <DailyTaskItem
@@ -79,6 +94,7 @@ export const DailyTasks: React.FC<IDailyTasksProps> = ({
79
94
  itemsAtlasIMG={itemsAtlasIMG}
80
95
  iconAtlasJSON={iconAtlasJSON}
81
96
  iconAtlasIMG={iconAtlasIMG}
97
+ isRewardClaimed={task.claimed || isTaskRewardClaimed(task.key)}
82
98
  />
83
99
  ))}
84
100
  </TasksList>
@@ -144,3 +160,5 @@ const TaskTitle = styled.h2`
144
160
  font-size: 1.4rem !important;
145
161
  width: 100%;
146
162
  `;
163
+
164
+
@@ -11,26 +11,37 @@ import { Button, ButtonTypes } from '../Button';
11
11
  interface IGlobalTaskProgressProps {
12
12
  tasks: ICharacterDailyTask[];
13
13
  onClaimAllRewards: (tasks: ICollectGlobalRewardRequest) => void;
14
+ globalRewardClaimed: boolean;
14
15
  }
15
16
 
16
17
  export const GlobalDailyProgress: React.FC<IGlobalTaskProgressProps> = ({
17
18
  tasks,
18
19
  onClaimAllRewards,
20
+ globalRewardClaimed,
19
21
  }) => {
20
22
  const totalTasks = tasks.length;
21
23
  const completedTasks = tasks.filter(
22
24
  task => task.status === TaskStatus.Completed
23
25
  ).length;
24
26
 
25
- const claimedTasks = tasks.filter(task => task.claimed === true).length;
27
+ const allCompleted =
28
+ tasks.length > 0 &&
29
+ tasks.every(task => task.status === TaskStatus.Completed);
26
30
 
27
- const allCompleted = completedTasks === totalTasks;
28
- const allClaimed = claimedTasks === totalTasks;
29
- const [isClaimed, setIsClaimed] = React.useState(false);
31
+ const allClaimed =
32
+ tasks.length > 0 && tasks.every(task => task.claimed === true);
30
33
 
31
- const handleClaimAll = (tasks: ICollectGlobalRewardRequest) => {
32
- onClaimAllRewards(tasks);
33
- setIsClaimed(true);
34
+ const shouldShowGlobalButton =
35
+ allCompleted && allClaimed && !globalRewardClaimed;
36
+
37
+ const shouldShowClaimedMessage = globalRewardClaimed;
38
+
39
+ const handleClaimAll = () => {
40
+ const taskIdentifiers = tasks.map(task => ({
41
+ taskKey: task.key,
42
+ type: task.type,
43
+ }));
44
+ onClaimAllRewards({ tasks: taskIdentifiers });
34
45
  };
35
46
 
36
47
  return (
@@ -44,11 +55,9 @@ export const GlobalDailyProgress: React.FC<IGlobalTaskProgressProps> = ({
44
55
  <ProgressBar>
45
56
  <ProgressFill percentage={(completedTasks / totalTasks) * 100} />
46
57
  </ProgressBar>
47
- {totalTasks > 0 && allCompleted && (
58
+ {allCompleted && (
48
59
  <>
49
- {allClaimed || isClaimed ? (
50
- <ClaimedText>Global Rewards Claimed</ClaimedText>
51
- ) : (
60
+ {shouldShowGlobalButton && (
52
61
  <CollectWrapper>
53
62
  <Button
54
63
  buttonType={ButtonTypes.RPGUIButton}
@@ -58,6 +67,9 @@ export const GlobalDailyProgress: React.FC<IGlobalTaskProgressProps> = ({
58
67
  </Button>
59
68
  </CollectWrapper>
60
69
  )}
70
+ {shouldShowClaimedMessage && (
71
+ <ClaimedText>Global Rewards Claimed</ClaimedText>
72
+ )}
61
73
  </>
62
74
  )}
63
75
  </GlobalProgressContainer>