@rpg-engine/long-bow 0.8.82 → 0.8.83

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.82",
3
+ "version": "0.8.83",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -1,10 +1,11 @@
1
1
  import {
2
+ CharacterClass,
3
+ getLevelFromSP,
2
4
  getSPForLevel,
3
5
  getSPForLevelExponential,
4
6
  getSkillConstants,
5
- CharacterClass,
6
7
  } from '@rpg-engine/shared';
7
- import React, { useMemo } from 'react';
8
+ import React from 'react';
8
9
  import styled from 'styled-components';
9
10
  import { uiColors } from '../constants/uiColors';
10
11
  import { ErrorBoundary } from './Item/Inventory/ErrorBoundary';
@@ -34,7 +35,7 @@ export const SkillProgressBar: React.FC<ISkillProgressBarProps> = ({
34
35
  characterClass,
35
36
  level,
36
37
  skillPoints: currentSkillPoints,
37
- skillPointsToNextLevel,
38
+
38
39
  texturePath,
39
40
  showSkillPoints = true,
40
41
  atlasIMG,
@@ -42,26 +43,44 @@ export const SkillProgressBar: React.FC<ISkillProgressBarProps> = ({
42
43
 
43
44
  buffAndDebuff,
44
45
  }) => {
45
- // Skill points needed to start the current level
46
- const baseSkillPoints = useMemo(() => {
47
- if (skillKey && characterClass) {
48
- const { A, b, c } = getSkillConstants(skillKey, characterClass);
49
- return getSPForLevelExponential(level, A, b, c);
46
+ // Use CharacterClass.None as default if skillKey is provided but characterClass is not
47
+ const effectiveClass = characterClass ?? CharacterClass.None;
48
+
49
+ // Calculate the effective level based on actual SP (handles data inconsistencies)
50
+ const calculateEffectiveLevel = (): number => {
51
+ if (!skillKey) {
52
+ return level; // Fallback to stored level for general "Level" display
50
53
  }
51
- // Fallback to old formula for backwards compatibility
52
- return getSPForLevel(level);
53
- }, [level, skillKey, characterClass]);
54
+
55
+ const { A, b, c } = getSkillConstants(skillKey, effectiveClass);
56
+ const actualLevel = Math.floor(getLevelFromSP(currentSkillPoints, A, b, c));
57
+ return Math.max(c, actualLevel); // At least starting level
58
+ };
59
+
60
+ const effectiveLevel = calculateEffectiveLevel();
61
+
62
+ // Calculate progress based on actual SP position
54
63
  const calculateProgress = (): number => {
55
- const totalPointsForLevelUp = Math.max(
56
- 1,
57
- skillPointsToNextLevel - baseSkillPoints
58
- );
59
- const excessSkillPoints = Math.max(0, currentSkillPoints - baseSkillPoints);
60
-
61
- return Math.min(
62
- 100,
63
- Math.max(0, (excessSkillPoints / totalPointsForLevelUp) * 100)
64
- );
64
+ if (!skillKey) {
65
+ // Fallback for general "Level" display: simple ratio of current SP to next level
66
+ const spForCurrentLevel = getSPForLevel(level);
67
+ const spForNextLevel = getSPForLevel(level + 1);
68
+ const range = spForNextLevel - spForCurrentLevel;
69
+ const progress = currentSkillPoints - spForCurrentLevel;
70
+ return Math.min(100, Math.max(0, (progress / range) * 100));
71
+ }
72
+
73
+ const { A, b, c } = getSkillConstants(skillKey, effectiveClass);
74
+
75
+ // Calculate SP thresholds for current effective level
76
+ const spForEffectiveLevel = getSPForLevelExponential(effectiveLevel, A, b, c);
77
+ const spForNextLevel = getSPForLevelExponential(effectiveLevel + 1, A, b, c);
78
+
79
+ // Progress within current effective level
80
+ const range = spForNextLevel - spForEffectiveLevel;
81
+ const progressInLevel = currentSkillPoints - spForEffectiveLevel;
82
+
83
+ return Math.min(100, Math.max(0, (progressInLevel / Math.max(1, range)) * 100));
65
84
  };
66
85
 
67
86
  const progress = calculateProgress();
@@ -85,7 +104,7 @@ export const SkillProgressBar: React.FC<ISkillProgressBarProps> = ({
85
104
  <TitleNameContainer>
86
105
  <TitleNameBuff>{skillName}</TitleNameBuff>
87
106
  <TitleNameBuff>
88
- lv {level} ({skillsBuffsCalc(level, buffAndDebuff)})
107
+ lv {effectiveLevel} ({skillsBuffsCalc(effectiveLevel, buffAndDebuff)})
89
108
  </TitleNameBuff>
90
109
  </TitleNameContainer>
91
110
  <TitleNameBuffContainer>
@@ -99,7 +118,7 @@ export const SkillProgressBar: React.FC<ISkillProgressBarProps> = ({
99
118
  <TitleNameContainer>
100
119
  <TitleNameDebuff>{skillName}</TitleNameDebuff>
101
120
  <TitleNameDebuff>
102
- lv {level} ({skillsBuffsCalc(level, buffAndDebuff)})
121
+ lv {effectiveLevel} ({skillsBuffsCalc(effectiveLevel, buffAndDebuff)})
103
122
  </TitleNameDebuff>
104
123
  </TitleNameContainer>
105
124
  <div>
@@ -116,7 +135,7 @@ export const SkillProgressBar: React.FC<ISkillProgressBarProps> = ({
116
135
  {!buffAndDebuff && (
117
136
  <TitleNameContainer>
118
137
  <TitleName>{skillName}</TitleName>
119
- <ValueDisplay>lv {level}</ValueDisplay>
138
+ <ValueDisplay>lv {effectiveLevel}</ValueDisplay>
120
139
  </TitleNameContainer>
121
140
  )}
122
141
  </ProgressTitle>
@@ -1,3 +1,4 @@
1
+ import { CharacterClass } from '@rpg-engine/shared';
1
2
  import { Meta, Story } from '@storybook/react';
2
3
  import React from 'react';
3
4
  import { RPGUIRoot } from '../../../components/RPGUI/RPGUIRoot';
@@ -21,6 +22,7 @@ const Template: Story<ISkillContainerProps> = args => (
21
22
  <SkillsContainer
22
23
  {...args}
23
24
  skill={skillMock}
25
+ characterClass={CharacterClass.Warrior}
24
26
  onCloseButton={() => console.log('close skill container')}
25
27
  atlasIMG={atlasIMG}
26
28
  atlasJSON={atlasJSON}
@@ -32,4 +34,5 @@ export const Default = Template.bind([]);
32
34
 
33
35
  Default.args = {
34
36
  skill: skillMock,
37
+ characterClass: CharacterClass.Warrior,
35
38
  };