Lernkosten funktioniert
aber die Fertigkeiten sind nicht immer gleich teuer wenn sie in mehrerenKategorien vorhanden sind.
This commit is contained in:
@@ -74,7 +74,7 @@ type LernCostRequest struct {
|
||||
TargetLevel int `json:"target_level,omitempty"` // Zielwert (optional, für Kostenberechnung bis zu einem bestimmten Level)
|
||||
UsePP int `json:"use_pp,omitempty"` // Anzahl der zu verwendenden Praxispunkte
|
||||
// Belohnungsoptionen
|
||||
Reward *string `json:"reward" binding:"required,oneof=default noGold halveep"` // Belohnungsoptionen Lernen als Belohnung
|
||||
Reward *string `json:"reward" binding:"required,oneof=default noGold halveep halveepnoGold"` // Belohnungsoptionen Lernen als Belohnung
|
||||
// default
|
||||
// learn: ohne Gold
|
||||
// improve/spell: halbe EP kein Gold
|
||||
|
||||
@@ -430,6 +430,7 @@ type SkillCostResultNew struct {
|
||||
EP int `json:"ep"`
|
||||
LE int `json:"le"`
|
||||
GoldCost int `json:"gold_cost"`
|
||||
PPUsed int `json:"pp_used"`
|
||||
Details map[string]interface{} `json:"details"`
|
||||
}
|
||||
|
||||
|
||||
@@ -522,7 +522,11 @@ func CalcSkillLernCost(costResult *SkillCostResultNew, reward *string) error {
|
||||
// Berechne die Lernkosten basierend auf den aktuellen Werten im costResult
|
||||
// Hier sollte die Logik zur Berechnung der Lernkosten implementiert werden
|
||||
//Finde EP kosten für die Kategorie für die Charakterklasse aus learningCostsData.EPPerTE
|
||||
epPerTE, ok := learningCostsData.EPPerTE[costResult.CharacterClass][costResult.Category]
|
||||
// Konvertiere Vollnamen der Charakterklasse zu Abkürzungen falls nötig
|
||||
//classKey := getClassAbbreviation(costResult.CharacterClass)
|
||||
classKey := costResult.CharacterClass
|
||||
|
||||
epPerTE, ok := learningCostsData.EPPerTE[classKey][costResult.Category]
|
||||
if !ok {
|
||||
return fmt.Errorf("EP-Kosten für Kategorie '%s' und Klasse '%s' nicht gefunden", costResult.Category, costResult.CharacterClass)
|
||||
}
|
||||
@@ -546,9 +550,35 @@ func CalcSkillLernCost(costResult *SkillCostResultNew, reward *string) error {
|
||||
// CalcSkillImproveCost berechnet die Kosten für die Verbesserung einer Fertigkeit
|
||||
func CalcSkillImproveCost(costResult *SkillCostResultNew, currentLevel int, reward *string) error {
|
||||
// Für Skill-Verbesserung könnten die Kosten vom aktuellen Level abhängen
|
||||
// TODO: Implementiere spezifische Verbesserungslogik
|
||||
// Für jetzt verwenden wir die gleiche Logik wie für das Lernen
|
||||
return CalcSkillLernCost(costResult, reward)
|
||||
|
||||
//Finde EP kosten für die Kategorie für die Charakterklasse aus learningCostsData.EPPerTE
|
||||
//classKey := getClassAbbreviation(costResult.CharacterClass)
|
||||
classKey := costResult.CharacterClass
|
||||
|
||||
epPerTE, ok := learningCostsData.EPPerTE[classKey][costResult.Category]
|
||||
if !ok {
|
||||
return fmt.Errorf("EP-Kosten für Kategorie '%s' und Klasse '%s' nicht gefunden", costResult.Category, costResult.CharacterClass)
|
||||
}
|
||||
|
||||
diffData := learningCostsData.ImprovementCost[costResult.Category][costResult.Difficulty]
|
||||
trainCost := diffData.TrainCosts[currentLevel+1]
|
||||
if costResult.PPUsed > 0 {
|
||||
trainCost -= costResult.PPUsed // Wenn PP verwendet werden, setze die Kosten auf die PP
|
||||
}
|
||||
// Apply reward logic
|
||||
costResult.LE = trainCost
|
||||
costResult.EP = epPerTE * trainCost
|
||||
costResult.GoldCost = trainCost * 20 // Beispiel: 20 Gold pro TE
|
||||
|
||||
if reward != nil && *reward == "halveep" {
|
||||
costResult.EP = costResult.EP / 2 // Halbiere die EP-Kosten für diese Belohnung
|
||||
}
|
||||
if reward != nil && *reward == "halveepnoGold" {
|
||||
costResult.GoldCost = 0 // Keine Goldkosten für diese Belohnung
|
||||
costResult.EP = costResult.EP / 2 // Halbiere die EP-Kosten für diese Belohnung
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CalcSpellLernCost berechnet die Kosten für das Erlernen eines Zaubers
|
||||
|
||||
@@ -563,23 +563,91 @@ func TestCalcSpellLernCostWithRewards(t *testing.T) {
|
||||
*/
|
||||
|
||||
// TestCalcSkillImproveCostWithRewards tests the reward logic in CalcSkillImproveCost
|
||||
/*
|
||||
func TestCalcSkillImproveCostWithRewards(t *testing.T) {
|
||||
costResult := &SkillCostResultNew{
|
||||
CharacterClass: "Kr", // Use abbreviation
|
||||
SkillName: "Klettern",
|
||||
Category: GetSkillCategory("Klettern"),
|
||||
Difficulty: GetSkillDifficulty(GetSkillCategory("Klettern"), "Klettern"),
|
||||
tests := []struct {
|
||||
name string
|
||||
skillName string
|
||||
characterClass string
|
||||
currentLevel int
|
||||
ppUsed int
|
||||
reward *string
|
||||
expectedEP int
|
||||
expectedGold int
|
||||
}{
|
||||
{
|
||||
name: "Normal improvement to 13 without reward",
|
||||
skillName: "Klettern",
|
||||
characterClass: "Kr",
|
||||
currentLevel: 12,
|
||||
ppUsed: 0,
|
||||
reward: nil,
|
||||
expectedEP: 20, // Kr has 20 EP/TE for Körper, currentLevel 12->13 costs 0 TE, so 20*0=0
|
||||
expectedGold: 20, // No gold cost for improvements
|
||||
},
|
||||
{
|
||||
name: "Normal improvement to 14 without reward",
|
||||
skillName: "Klettern",
|
||||
characterClass: "Kr",
|
||||
currentLevel: 13,
|
||||
ppUsed: 0,
|
||||
reward: nil,
|
||||
expectedEP: 40, // Kr has 20 EP/TE for Körper, currentLevel 12->13 costs 0 TE, so 20*0=0
|
||||
expectedGold: 40, // No gold cost for improvements
|
||||
},
|
||||
{
|
||||
name: "Improvement with halveep reward",
|
||||
skillName: "Klettern",
|
||||
characterClass: "Kr",
|
||||
currentLevel: 13,
|
||||
ppUsed: 0,
|
||||
reward: stringPtr("halveep"),
|
||||
expectedEP: 20, // Kr has 20 EP/TE for Körper, level 13->14 costs 1 TE, so 20*1=20, halved = 10
|
||||
expectedGold: 40, // No gold cost for improvements
|
||||
},
|
||||
{
|
||||
name: "Improvement with PP used",
|
||||
skillName: "Klettern",
|
||||
characterClass: "Kr",
|
||||
currentLevel: 14,
|
||||
ppUsed: 1,
|
||||
reward: nil,
|
||||
expectedEP: 20, // Kr has 20 EP/TE for Körper, level 14->15 costs 2 TE, minus 1 PP = 1 TE, so 20*1=20
|
||||
expectedGold: 0, // No gold cost for improvements
|
||||
},
|
||||
{
|
||||
name: "Improvement with halveepnoGold reward",
|
||||
skillName: "Klettern",
|
||||
characterClass: "Kr",
|
||||
currentLevel: 15,
|
||||
ppUsed: 0,
|
||||
reward: stringPtr("halveepnoGold"),
|
||||
expectedEP: 50, // Kr has 20 EP/TE for Körper, level 15->16 costs 5 TE, so 20*5=100, halved = 50
|
||||
expectedGold: 0, // Should be 0 with halveepnoGold reward
|
||||
},
|
||||
}
|
||||
|
||||
// Test with halveep reward
|
||||
err := CalcSkillImproveCost(costResult, 5, stringPtr("halveep"))
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to calculate improvement costs: %v", err)
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
costResult := &SkillCostResultNew{
|
||||
CharacterClass: tt.characterClass,
|
||||
SkillName: tt.skillName,
|
||||
Category: GetSkillCategory(tt.skillName),
|
||||
Difficulty: GetSkillDifficulty(GetSkillCategory(tt.skillName), tt.skillName),
|
||||
PPUsed: tt.ppUsed,
|
||||
}
|
||||
|
||||
if costResult.GoldCost != 0 {
|
||||
t.Errorf("Expected gold cost 0 with halveep reward, got %d", costResult.GoldCost)
|
||||
err := CalcSkillImproveCost(costResult, tt.currentLevel, tt.reward)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to calculate improvement costs: %v", err)
|
||||
}
|
||||
|
||||
if costResult.EP != tt.expectedEP {
|
||||
t.Errorf("Expected EP %d, got %d", tt.expectedEP, costResult.EP)
|
||||
}
|
||||
|
||||
if costResult.GoldCost != tt.expectedGold {
|
||||
t.Errorf("Expected gold cost %d, got %d", tt.expectedGold, costResult.GoldCost)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user