@rpg-engine/long-bow 0.6.49 → 0.6.51

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.6.49",
3
+ "version": "0.6.51",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -1,5 +1,5 @@
1
1
  import { getSPForLevel } from '@rpg-engine/shared';
2
- import React, { useEffect, useState } from 'react';
2
+ import React from 'react';
3
3
  import styled from 'styled-components';
4
4
  import { uiColors } from '../constants/uiColors';
5
5
  import { ErrorBoundary } from './Item/Inventory/ErrorBoundary';
@@ -22,46 +22,46 @@ export interface ISkillProgressBarProps {
22
22
  export const SkillProgressBar: React.FC<ISkillProgressBarProps> = ({
23
23
  bgColor,
24
24
  skillName,
25
- level: initialLevel,
26
- skillPoints: initialSkillPoints,
27
- skillPointsToNextLevel: initialSkillPointsToNextLevel,
25
+ level,
26
+ skillPoints: currentSkillPoints,
27
+
28
28
  texturePath,
29
29
  showSkillPoints = true,
30
30
  atlasIMG,
31
31
  atlasJSON,
32
32
  buffAndDebuff,
33
33
  }) => {
34
- const [level, setLevel] = useState(initialLevel);
35
- const [skillPoints, setSkillPoints] = useState(initialSkillPoints);
36
- const [skillPointsToNextLevel, setSkillPointsToNextLevel] = useState(
37
- initialSkillPointsToNextLevel || getSPForLevel(initialLevel + 1)
38
- );
39
-
40
- // Update skill points and level from props when they change
41
- useEffect(() => {
42
- setLevel(initialLevel);
43
- setSkillPoints(initialSkillPoints);
44
- setSkillPointsToNextLevel(
45
- initialSkillPointsToNextLevel || getSPForLevel(initialLevel + 1)
46
- );
47
- }, [initialLevel, initialSkillPoints, initialSkillPointsToNextLevel]);
48
-
49
- useEffect(() => {
50
- if (skillPoints >= skillPointsToNextLevel) {
51
- const excessSkillPoints = skillPoints - skillPointsToNextLevel;
52
- const newLevel = level + 1;
53
- setLevel(newLevel);
54
- setSkillPoints(excessSkillPoints);
55
- setSkillPointsToNextLevel(getSPForLevel(newLevel + 1));
56
- }
57
- }, [skillPoints, skillPointsToNextLevel, level]);
58
-
59
- // Calculate the ratio, ensuring it doesn't exceed 100%
60
- const ratio = Math.min((skillPoints / skillPointsToNextLevel) * 100, 100);
34
+ // Base skill points for the previous level (0 for level 1)
35
+ const baseSkillPointsPrevLevel = level > 1 ? getSPForLevel(level - 1) : 0;
36
+
37
+ // Total skill points needed for the next level
38
+ const nextLevelSkillPoints = getSPForLevel(level + 1);
39
+
40
+ // Calculate excess skill points above the previous level
41
+ const excessSkillPoints = currentSkillPoints - baseSkillPointsPrevLevel;
42
+
43
+ // Calculate progress percentage towards the next level
44
+ const progress =
45
+ nextLevelSkillPoints > baseSkillPointsPrevLevel
46
+ ? Math.max(
47
+ Math.min(
48
+ (excessSkillPoints /
49
+ (nextLevelSkillPoints - baseSkillPointsPrevLevel)) *
50
+ 100,
51
+ 100
52
+ ),
53
+ 0
54
+ )
55
+ : 0;
61
56
 
62
57
  const skillsBuffsCalc = (level: number, buffAndDebuff: number): string => {
63
58
  const result = level * (buffAndDebuff / 100);
64
- return result > 0 ? `+${result}` : `${result}`;
59
+
60
+ if (result > 0) {
61
+ return `+${result.toFixed(2)}`;
62
+ } else {
63
+ return `${result.toFixed(2)}`;
64
+ }
65
65
  };
66
66
 
67
67
  return (
@@ -127,14 +127,12 @@ export const SkillProgressBar: React.FC<ISkillProgressBarProps> = ({
127
127
  </ProgressIconContainer>
128
128
 
129
129
  <ProgressBarContainer>
130
- <SimpleProgressBar value={ratio} bgColor={bgColor} />
130
+ <SimpleProgressBar value={progress} bgColor={bgColor} />
131
131
  </ProgressBarContainer>
132
132
  </ProgressBody>
133
133
  {showSkillPoints && (
134
134
  <SkillDisplayContainer>
135
- <SkillPointsDisplay>
136
- {skillPoints} / {skillPointsToNextLevel} ({ratio.toFixed(2)}%)
137
- </SkillPointsDisplay>
135
+ <SkillPointsDisplay>{progress.toFixed(2)}%</SkillPointsDisplay>
138
136
  </SkillDisplayContainer>
139
137
  )}
140
138
  </>
@@ -1,18 +1,22 @@
1
1
  import { ISkill, SkillType, getSPForLevel } from '@rpg-engine/shared';
2
2
 
3
+ for (let level = 2; level <= 10; level++) {
4
+ console.log(`SP for level ${level}: ${getSPForLevel(level)}`);
5
+ }
6
+
3
7
  export const skillMock = {
4
8
  _id: '62aebda8785a9f0089a4f757',
5
9
  stamina: {
6
10
  type: SkillType.BasicAttributes,
7
- level: 2,
8
- skillPoints: 50.03,
11
+ level: 1,
12
+ skillPoints: 5,
9
13
  skillPointsToNextLevel: getSPForLevel(2),
10
14
  },
11
15
  magic: {
12
16
  type: SkillType.BasicAttributes,
13
- level: 2,
14
- skillPoints: 22,
15
- skillPointsToNextLevel: getSPForLevel(2.4),
17
+ level: 1,
18
+ skillPoints: 12,
19
+ skillPointsToNextLevel: getSPForLevel(2),
16
20
  buffAndDebuff: -10,
17
21
  },
18
22
  magicResistance: {