@rpg-engine/long-bow 0.8.82 → 0.8.84

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.84",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -84,7 +84,7 @@
84
84
  "dependencies": {
85
85
  "@capacitor/core": "^6.1.0",
86
86
  "@rollup/plugin-image": "^2.1.1",
87
- "@rpg-engine/shared": "^0.10.32",
87
+ "@rpg-engine/shared": "^0.10.33",
88
88
  "dayjs": "^1.11.2",
89
89
  "font-awesome": "^4.7.0",
90
90
  "fs-extra": "^10.1.0",
@@ -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,48 @@ 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(1, actualLevel); // Minimum level is always 1 in our system
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
+ // Get the actual calculated level (might be 0 for magic)
76
+ const actualLevel = Math.floor(getLevelFromSP(currentSkillPoints, A, b, c));
77
+ const calcLevel = Math.max(c, actualLevel); // Use c as minimum for calculation
78
+
79
+ // Calculate SP thresholds based on actual position
80
+ const spForCalcLevel = getSPForLevelExponential(calcLevel, A, b, c);
81
+ const spForNextLevel = getSPForLevelExponential(calcLevel + 1, A, b, c);
82
+
83
+ // Progress within current level range
84
+ const range = spForNextLevel - spForCalcLevel;
85
+ const progressInLevel = currentSkillPoints - spForCalcLevel;
86
+
87
+ return Math.min(100, Math.max(0, (progressInLevel / Math.max(1, range)) * 100));
65
88
  };
66
89
 
67
90
  const progress = calculateProgress();
@@ -85,7 +108,7 @@ export const SkillProgressBar: React.FC<ISkillProgressBarProps> = ({
85
108
  <TitleNameContainer>
86
109
  <TitleNameBuff>{skillName}</TitleNameBuff>
87
110
  <TitleNameBuff>
88
- lv {level} ({skillsBuffsCalc(level, buffAndDebuff)})
111
+ lv {effectiveLevel} ({skillsBuffsCalc(effectiveLevel, buffAndDebuff)})
89
112
  </TitleNameBuff>
90
113
  </TitleNameContainer>
91
114
  <TitleNameBuffContainer>
@@ -99,7 +122,7 @@ export const SkillProgressBar: React.FC<ISkillProgressBarProps> = ({
99
122
  <TitleNameContainer>
100
123
  <TitleNameDebuff>{skillName}</TitleNameDebuff>
101
124
  <TitleNameDebuff>
102
- lv {level} ({skillsBuffsCalc(level, buffAndDebuff)})
125
+ lv {effectiveLevel} ({skillsBuffsCalc(effectiveLevel, buffAndDebuff)})
103
126
  </TitleNameDebuff>
104
127
  </TitleNameContainer>
105
128
  <div>
@@ -116,7 +139,7 @@ export const SkillProgressBar: React.FC<ISkillProgressBarProps> = ({
116
139
  {!buffAndDebuff && (
117
140
  <TitleNameContainer>
118
141
  <TitleName>{skillName}</TitleName>
119
- <ValueDisplay>lv {level}</ValueDisplay>
142
+ <ValueDisplay>lv {effectiveLevel}</ValueDisplay>
120
143
  </TitleNameContainer>
121
144
  )}
122
145
  </ProgressTitle>
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  ISkill,
3
3
  SkillType,
4
- getSPForLevel,
5
4
  getSPForLevelExponential,
6
5
  getSkillConstants,
7
6
  CharacterClass,
@@ -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
  };