LearnCost migriert
This commit is contained in:
@@ -669,7 +669,7 @@ type LearnSpellRequest struct {
|
||||
}
|
||||
|
||||
// calculateMultiLevelCosts berechnet die Kosten für mehrere Level-Verbesserungen mit gsmaster.GetLernCostNextLevel
|
||||
func calculateMultiLevelCosts(character *Char, skillName string, currentLevel int, levelsToLearn []int, rewardType string, usePP, useGold int) (*gsmaster.LearnCost, error) {
|
||||
func calculateMultiLevelCosts(character *Char, skillName string, currentLevel int, levelsToLearn []int, rewardType string, usePP, useGold int) (*models.LearnCost, error) {
|
||||
if len(levelsToLearn) == 0 {
|
||||
return nil, fmt.Errorf("keine Level zum Lernen angegeben")
|
||||
}
|
||||
@@ -703,7 +703,7 @@ func calculateMultiLevelCosts(character *Char, skillName string, currentLevel in
|
||||
Reward: rewardTypePtr,
|
||||
}
|
||||
|
||||
totalCost := &gsmaster.LearnCost{
|
||||
totalCost := &models.LearnCost{
|
||||
Stufe: sortedLevels[len(sortedLevels)-1],
|
||||
LE: 0,
|
||||
Ep: 0,
|
||||
|
||||
@@ -31,7 +31,7 @@ type RewardOptions struct {
|
||||
}
|
||||
|
||||
type SkillCostResponse struct {
|
||||
*gsmaster.LearnCost
|
||||
*models.LearnCost
|
||||
SkillName string `json:"skill_name"`
|
||||
SkillType string `json:"skill_type"`
|
||||
Action string `json:"action"`
|
||||
@@ -46,13 +46,13 @@ type SkillCostResponse struct {
|
||||
PPAvailable int `json:"pp_available,omitempty"` // Verfügbare Praxispunkte für diese Kategorie
|
||||
|
||||
// Belohnungsdetails
|
||||
RewardApplied string `json:"reward_applied,omitempty"` // Art der angewendeten Belohnung
|
||||
OriginalCostStruct *gsmaster.LearnCost `json:"original_cost_struct,omitempty"` // Ursprüngliche Kosten ohne Belohnung
|
||||
Savings *gsmaster.LearnCost `json:"savings,omitempty"` // Ersparnisse durch Belohnung
|
||||
GoldUsedForEP int `json:"gold_used_for_ep,omitempty"` // Gold das für EP verwendet wurde
|
||||
PPReduction int `json:"pp_reduction,omitempty"` // Reduktion der Kosten durch PP
|
||||
OriginalCost int `json:"original_cost,omitempty"` // Ursprüngliche Kosten (vor PP-Reduktion)
|
||||
FinalCost int `json:"final_cost,omitempty"` // Endgültige Kosten (nach PP-Reduktion)
|
||||
RewardApplied string `json:"reward_applied,omitempty"` // Art der angewendeten Belohnung
|
||||
OriginalCostStruct *models.LearnCost `json:"original_cost_struct,omitempty"` // Ursprüngliche Kosten ohne Belohnung
|
||||
Savings *models.LearnCost `json:"savings,omitempty"` // Ersparnisse durch Belohnung
|
||||
GoldUsedForEP int `json:"gold_used_for_ep,omitempty"` // Gold das für EP verwendet wurde
|
||||
PPReduction int `json:"pp_reduction,omitempty"` // Reduktion der Kosten durch PP
|
||||
OriginalCost int `json:"original_cost,omitempty"` // Ursprüngliche Kosten (vor PP-Reduktion)
|
||||
FinalCost int `json:"final_cost,omitempty"` // Endgültige Kosten (nach PP-Reduktion)
|
||||
}
|
||||
|
||||
type MultiLevelCostResponse struct {
|
||||
@@ -62,7 +62,7 @@ type MultiLevelCostResponse struct {
|
||||
CurrentLevel int `json:"current_level"`
|
||||
TargetLevel int `json:"target_level"`
|
||||
LevelCosts []SkillCostResponse `json:"level_costs"`
|
||||
TotalCost *gsmaster.LearnCost `json:"total_cost"`
|
||||
TotalCost *models.LearnCost `json:"total_cost"`
|
||||
CanAffordTotal bool `json:"can_afford_total"`
|
||||
}
|
||||
|
||||
@@ -212,14 +212,14 @@ func GetSkillCost(c *gin.Context) {
|
||||
|
||||
// Belohnungsinformationen berechnen
|
||||
var rewardApplied string
|
||||
var savings *gsmaster.LearnCost
|
||||
var savings *models.LearnCost
|
||||
var goldUsedForEP int
|
||||
|
||||
if request.Reward != nil && request.Reward.Type != "" {
|
||||
rewardApplied = request.Reward.Type
|
||||
|
||||
// Ersparnisse berechnen
|
||||
savings = &gsmaster.LearnCost{
|
||||
savings = &models.LearnCost{
|
||||
Ep: originalCost.Ep - cost.Ep,
|
||||
LE: originalCost.LE - cost.LE,
|
||||
Money: originalCost.Money - cost.Money,
|
||||
@@ -281,8 +281,8 @@ func getCurrentSkillLevel(character *Char, skillName, skillType string) int {
|
||||
}
|
||||
|
||||
// Helper function to calculate single cost
|
||||
func calculateSingleCost(character *Char, request *SkillCostRequest) (*gsmaster.LearnCost, *gsmaster.LearnCost, *skillInfo, error) {
|
||||
var cost *gsmaster.LearnCost
|
||||
func calculateSingleCost(character *Char, request *SkillCostRequest) (*models.LearnCost, *models.LearnCost, *skillInfo, error) {
|
||||
var cost *models.LearnCost
|
||||
var err error
|
||||
var info skillInfo
|
||||
|
||||
@@ -331,7 +331,7 @@ func calculateSingleCost(character *Char, request *SkillCostRequest) (*gsmaster.
|
||||
finalEP, finalLE, _ := applyPPReduction(request, cost, availablePP)
|
||||
|
||||
// Erstelle eine neue LearnCost mit den reduzierten Werten
|
||||
cost = &gsmaster.LearnCost{
|
||||
cost = &models.LearnCost{
|
||||
Stufe: cost.Stufe,
|
||||
LE: finalLE,
|
||||
Ep: finalEP,
|
||||
@@ -343,7 +343,7 @@ func calculateSingleCost(character *Char, request *SkillCostRequest) (*gsmaster.
|
||||
}
|
||||
|
||||
// applyReward wendet Belohnungen auf die Kosten an
|
||||
func applyReward(cost *gsmaster.LearnCost, request *SkillCostRequest) *gsmaster.LearnCost {
|
||||
func applyReward(cost *models.LearnCost, request *SkillCostRequest) *models.LearnCost {
|
||||
if request.Reward == nil || request.Reward.Type == "" {
|
||||
return cost
|
||||
}
|
||||
@@ -440,14 +440,14 @@ func calculateMultiLevelCost(character *Char, request *SkillCostRequest) *MultiL
|
||||
|
||||
// Belohnungsinformationen für Level berechnen
|
||||
var rewardApplied string
|
||||
var savings *gsmaster.LearnCost
|
||||
var savings *models.LearnCost
|
||||
var goldUsedForEP int
|
||||
|
||||
if tempRequest.Reward != nil && tempRequest.Reward.Type != "" {
|
||||
rewardApplied = tempRequest.Reward.Type
|
||||
|
||||
// Ersparnisse berechnen
|
||||
savings = &gsmaster.LearnCost{
|
||||
savings = &models.LearnCost{
|
||||
Ep: originalCost.Ep - cost.Ep,
|
||||
LE: originalCost.LE - cost.LE,
|
||||
Money: originalCost.Money - cost.Money,
|
||||
@@ -486,7 +486,7 @@ func calculateMultiLevelCost(character *Char, request *SkillCostRequest) *MultiL
|
||||
totalMoney += cost.Money
|
||||
}
|
||||
|
||||
totalCost := &gsmaster.LearnCost{
|
||||
totalCost := &models.LearnCost{
|
||||
Stufe: request.TargetLevel,
|
||||
LE: 0,
|
||||
Ep: totalEP,
|
||||
@@ -542,7 +542,7 @@ func getSpellInfo(spellName string) skillInfo {
|
||||
return skillInfo{Category: spell.Category, Difficulty: strconv.Itoa(spell.Stufe)}
|
||||
}
|
||||
|
||||
func canCharacterAfford(character *Char, cost *gsmaster.LearnCost) bool {
|
||||
func canCharacterAfford(character *Char, cost *models.LearnCost) bool {
|
||||
// Check if character has enough EP
|
||||
if character.Erfahrungsschatz.EP < cost.Ep {
|
||||
return false
|
||||
@@ -554,7 +554,7 @@ func canCharacterAfford(character *Char, cost *gsmaster.LearnCost) bool {
|
||||
return totalMoney >= cost.Money
|
||||
}
|
||||
|
||||
func generateNotes(character *Char, request *SkillCostRequest, cost *gsmaster.LearnCost) string {
|
||||
func generateNotes(character *Char, request *SkillCostRequest, cost *models.LearnCost) string {
|
||||
var notes []string
|
||||
|
||||
if request.Action == "learn" {
|
||||
@@ -595,7 +595,7 @@ func getPPForSkill(character *Char, skillName string) int {
|
||||
}
|
||||
|
||||
// applyPPReduction reduziert die Kosten entsprechend der verwendeten Praxispunkte
|
||||
func applyPPReduction(request *SkillCostRequest, cost *gsmaster.LearnCost, availablePP int) (int, int, int) {
|
||||
func applyPPReduction(request *SkillCostRequest, cost *models.LearnCost, availablePP int) (int, int, int) {
|
||||
if request.UsePP <= 0 {
|
||||
return cost.Ep, cost.LE, 0
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package character
|
||||
|
||||
import (
|
||||
"bamort/gsmaster"
|
||||
"bamort/models"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -92,14 +93,14 @@ func TestSkillLearningDialogWorkflow(t *testing.T) {
|
||||
assert.Equal(t, 10, parsedRequest.Stufe)
|
||||
|
||||
// Teste erwartete Response-Struktur (ohne DB-Aufruf)
|
||||
expectedResponse := []gsmaster.LearnCost{
|
||||
expectedResponse := []models.LearnCost{
|
||||
{Stufe: 11, Ep: 120, Money: 60, LE: 2},
|
||||
{Stufe: 12, Ep: 140, Money: 70, LE: 2},
|
||||
}
|
||||
|
||||
// Überprüfe Response-Format wie das Frontend es erwartet
|
||||
responseBody, _ := json.Marshal(expectedResponse)
|
||||
var response []gsmaster.LearnCost
|
||||
var response []models.LearnCost
|
||||
err = json.Unmarshal(responseBody, &response)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -114,7 +115,7 @@ func TestSkillLearningDialogWorkflow(t *testing.T) {
|
||||
|
||||
t.Run("Frontend Conversion Logic Test", func(t *testing.T) {
|
||||
// Simuliere die Konvertierung wie sie das Frontend durchführt
|
||||
mockApiResponse := []gsmaster.LearnCost{
|
||||
mockApiResponse := []models.LearnCost{
|
||||
{Stufe: 11, Ep: 120, Money: 60, LE: 2},
|
||||
{Stufe: 12, Ep: 140, Money: 70, LE: 2},
|
||||
{Stufe: 13, Ep: 160, Money: 80, LE: 3},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package gsmaster
|
||||
|
||||
import (
|
||||
"bamort/models"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
@@ -437,7 +438,7 @@ type SkillCostResultNew struct {
|
||||
}
|
||||
|
||||
// CalculateDetailedSkillLearningCost berechnet die Kosten für das Lernen einer Fertigkeit mit Details
|
||||
func CalculateDetailedSkillLearningCost(skillName, characterClass string) (*LearnCost, error) {
|
||||
func CalculateDetailedSkillLearningCost(skillName, characterClass string) (*models.LearnCost, error) {
|
||||
// Fallback-Werte für Skills ohne definierte Kategorie/Schwierigkeit
|
||||
category := GetDefaultCategory(skillName)
|
||||
difficulty := GetDefaultDifficulty(skillName)
|
||||
@@ -448,7 +449,7 @@ func CalculateDetailedSkillLearningCost(skillName, characterClass string) (*Lear
|
||||
}
|
||||
|
||||
// Konvertiere SkillCostResult zu LearnCost
|
||||
return &LearnCost{
|
||||
return &models.LearnCost{
|
||||
Stufe: 0, // Lernen startet bei Stufe 0
|
||||
LE: result.LE,
|
||||
Ep: result.EP,
|
||||
@@ -457,7 +458,7 @@ func CalculateDetailedSkillLearningCost(skillName, characterClass string) (*Lear
|
||||
}
|
||||
|
||||
// CalculateDetailedSkillImprovementCost berechnet die Kosten für die Verbesserung einer Fertigkeit
|
||||
func CalculateDetailedSkillImprovementCost(skillName, characterClass string, currentLevel int) (*LearnCost, error) {
|
||||
func CalculateDetailedSkillImprovementCost(skillName, characterClass string, currentLevel int) (*models.LearnCost, error) {
|
||||
// Fallback-Werte für Skills ohne definierte Kategorie/Schwierigkeit
|
||||
category := GetDefaultCategory(skillName)
|
||||
difficulty := GetDefaultDifficulty(skillName)
|
||||
@@ -480,7 +481,7 @@ func CalculateDetailedSkillImprovementCost(skillName, characterClass string, cur
|
||||
improvedEP := int(float64(baseCost.EP) * improvementFactor)
|
||||
|
||||
// Konvertiere zu LearnCost
|
||||
return &LearnCost{
|
||||
return &models.LearnCost{
|
||||
Stufe: currentLevel + 1, // Ziel-Stufe
|
||||
LE: 1, // TE für Verbesserung (meist 1)
|
||||
Ep: improvedEP,
|
||||
@@ -489,7 +490,7 @@ func CalculateDetailedSkillImprovementCost(skillName, characterClass string, cur
|
||||
}
|
||||
|
||||
// CalculateDetailedSpellLearningCost berechnet die Kosten für das Lernen eines Zaubers
|
||||
func CalculateDetailedSpellLearningCost(spellName, characterClass string) (*LearnCost, error) {
|
||||
func CalculateDetailedSpellLearningCost(spellName, characterClass string) (*models.LearnCost, error) {
|
||||
// Standard-Zauberschule bestimmen
|
||||
spellSchool := getDefaultSpellSchool(spellName)
|
||||
|
||||
@@ -502,7 +503,7 @@ func CalculateDetailedSpellLearningCost(spellName, characterClass string) (*Lear
|
||||
}
|
||||
|
||||
// Konvertiere SkillCostResult zu LearnCost
|
||||
return &LearnCost{
|
||||
return &models.LearnCost{
|
||||
Stufe: 0, // Lernen startet bei Stufe 0
|
||||
LE: result.LE,
|
||||
Ep: result.EP,
|
||||
|
||||
@@ -164,17 +164,17 @@ func CalculateSkillLearnCost(skill string, class string) (int, error) {
|
||||
}
|
||||
|
||||
// CalculateImprovementCost: Kosten zum Steigern von +X auf +X+1
|
||||
func CalculateSkillImprovementCost(skill string, class string, currentSkillLevel int) (*LearnCost, error) {
|
||||
func CalculateSkillImprovementCost(skill string, class string, currentSkillLevel int) (*models.LearnCost, error) {
|
||||
return CalculateImprovementCost(skill, class, currentSkillLevel)
|
||||
}
|
||||
|
||||
func CalculateImprovementCost(skill string, class string, currentSkillLevel int) (*LearnCost, error) {
|
||||
func CalculateImprovementCost(skill string, class string, currentSkillLevel int) (*models.LearnCost, error) {
|
||||
/*
|
||||
if !Config.AllowedGroups[class][skill.Group] {
|
||||
return 0, fmt.Errorf("die Klasse %s darf %s nicht lernen", class, skill.Group)
|
||||
}
|
||||
*/
|
||||
lCost := LearnCost{}
|
||||
lCost := models.LearnCost{}
|
||||
var skl models.Skill
|
||||
if err := skl.First(skill); err != nil {
|
||||
return nil, errors.New("unbekannte Fertigkeit")
|
||||
|
||||
@@ -10,15 +10,6 @@ import (
|
||||
|
||||
var dbPrefix = "gsm"
|
||||
|
||||
type LearnCost struct {
|
||||
Stufe int `json:"stufe"`
|
||||
LE int `json:"le"`
|
||||
TE int `json:"te"`
|
||||
Ep int `json:"ep"`
|
||||
Money int `json:"money"`
|
||||
PP int `json:"pp"`
|
||||
}
|
||||
|
||||
type WeaponSkill struct {
|
||||
models.Skill
|
||||
}
|
||||
|
||||
@@ -31,6 +31,15 @@ type LookupList struct {
|
||||
Quelle string `json:"quelle"`
|
||||
}
|
||||
|
||||
type LearnCost struct {
|
||||
Stufe int `json:"stufe"`
|
||||
LE int `json:"le"`
|
||||
TE int `json:"te"`
|
||||
Ep int `json:"ep"`
|
||||
Money int `json:"money"`
|
||||
PP int `json:"pp"`
|
||||
}
|
||||
|
||||
type Skill struct {
|
||||
LookupList
|
||||
Initialwert int `gorm:"default:5" json:"initialwert"`
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package skills
|
||||
|
||||
import (
|
||||
"bamort/gsmaster"
|
||||
"bamort/models"
|
||||
)
|
||||
|
||||
@@ -9,14 +8,14 @@ var dbPrefix = "skill"
|
||||
|
||||
type Fertigkeit struct {
|
||||
models.BamortCharTrait
|
||||
Beschreibung string `json:"beschreibung"`
|
||||
Fertigkeitswert int `json:"fertigkeitswert"`
|
||||
Bonus int `json:"bonus,omitempty"`
|
||||
Pp int `json:"pp,omitempty"` //Praxispunkte
|
||||
Bemerkung string `json:"bemerkung"`
|
||||
Improvable bool `json:"improvable"`
|
||||
Category string `json:"category"`
|
||||
LearningCost gsmaster.LearnCost `gorm:"-" json:"learncost"`
|
||||
Beschreibung string `json:"beschreibung"`
|
||||
Fertigkeitswert int `json:"fertigkeitswert"`
|
||||
Bonus int `json:"bonus,omitempty"`
|
||||
Pp int `json:"pp,omitempty"` //Praxispunkte
|
||||
Bemerkung string `json:"bemerkung"`
|
||||
Improvable bool `json:"improvable"`
|
||||
Category string `json:"category"`
|
||||
LearningCost models.LearnCost `gorm:"-" json:"learncost"`
|
||||
}
|
||||
|
||||
type Waffenfertigkeit struct {
|
||||
|
||||
@@ -12,7 +12,7 @@ curl -X GET http://localhost:8180/api/characters/20/improve/skill \
|
||||
}'
|
||||
|
||||
echo -e "\n\nNote: This is a GET request with JSON body (unusual API design)"
|
||||
echo "The endpoint returns an array of gsmaster.LearnCost objects with fields:"
|
||||
echo "The endpoint returns an array of models.LearnCost objects with fields:"
|
||||
echo "- stufe: target level"
|
||||
echo "- ep: experience points cost"
|
||||
echo "- money: money cost"
|
||||
|
||||
Reference in New Issue
Block a user