feat: starting skills

This commit is contained in:
2025-10-12 21:06:48 +02:00
parent 4213b6e85f
commit c2c75287a0
7 changed files with 77 additions and 13 deletions

View File

@@ -19,6 +19,7 @@ void USkillTreeComponent::BeginPlay()
void USkillTreeComponent::InitializeSkillTree()
{
AllSkills.Empty();
PurchasedSkills.Empty();
if (!SkillDataTable)
{
@@ -44,10 +45,33 @@ void USkillTreeComponent::InitializeSkillTree()
}
}
// Auto-purchase starting skills (these don't cost skill points)
for (auto& Pair : AllSkills)
{
const FName& SkillID = Pair.Key;
FSkillNodeRuntime& SkillNode = Pair.Value;
if (SkillNode.NodeData.bStartingSkill)
{
// Mark as purchased
SkillNode.CurrentState = ESkillNodeState::Purchased;
PurchasedSkills.Add(SkillID);
// Apply skill effects
ApplySkillEffects(SkillNode.NodeData);
// Broadcast purchase event
OnSkillPurchased.Broadcast(SkillID);
UE_LOG(LogTemp, Log, TEXT("SkillTreeComponent: Auto-purchased starting skill: %s"),
*SkillNode.NodeData.DisplayName.ToString());
}
}
UpdateSkillStates();
UE_LOG(LogTemp, Log, TEXT("SkillTreeComponent: Initialized with %d skills"),
AllSkills.Num());
UE_LOG(LogTemp, Log, TEXT("SkillTreeComponent: Initialized with %d skills (%d starting)"),
AllSkills.Num(), PurchasedSkills.Num());
}
void USkillTreeComponent::AddSkillPoints(int32 Amount)
@@ -414,14 +438,20 @@ float USkillTreeComponent::GetTotalSpeedBonusPercent() const
void USkillTreeComponent::ResetAllSkills()
{
// Refund all skill points
// Refund skill points (but not for starting skills)
int32 RefundAmount = 0;
for (const FName& SkillID : PurchasedSkills)
{
if (const FSkillNodeRuntime* SkillNode = AllSkills.Find(SkillID))
{
RefundAmount += SkillNode->NodeData.Cost;
// Remove skill effects for all purchased skills
RemoveSkillEffects(SkillNode->NodeData);
// Only refund cost for non-starting skills
if (!SkillNode->NodeData.bStartingSkill)
{
RefundAmount += SkillNode->NodeData.Cost;
}
}
}
@@ -437,13 +467,39 @@ void USkillTreeComponent::ResetAllSkills()
CurrentSelectionCost = 0;
// Add refunded points
AddSkillPoints(RefundAmount);
if (RefundAmount > 0)
{
AddSkillPoints(RefundAmount);
}
// Re-purchase starting skills
for (auto& Pair : AllSkills)
{
const FName& SkillID = Pair.Key;
FSkillNodeRuntime& SkillNode = Pair.Value;
if (SkillNode.NodeData.bStartingSkill)
{
// Mark as purchased
SkillNode.CurrentState = ESkillNodeState::Purchased;
PurchasedSkills.Add(SkillID);
// Apply skill effects
ApplySkillEffects(SkillNode.NodeData);
// Broadcast purchase event
OnSkillPurchased.Broadcast(SkillID);
}
}
// Update states
UpdateSkillStates();
// Broadcast events
OnSkillSelectionChanged.Broadcast(CurrentSelectionCost);
UE_LOG(LogTemp, Log, TEXT("SkillTreeComponent: Reset all skills. Refunded %d points. Re-purchased %d starting skills."),
RefundAmount, PurchasedSkills.Num());
}
void USkillTreeComponent::UpdateSkillStates()