feat: add XP levels and progression points
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
extends GutTest
|
||||
|
||||
const ActorStateType = preload("res://scripts/domain/actor_state.gd")
|
||||
const AttributesType = preload("res://scripts/domain/entities/attributes.gd")
|
||||
const ExperienceType = preload("res://scripts/domain/progression/experience.gd")
|
||||
const SkillTreeType = preload("res://scripts/domain/progression/skill_tree.gd")
|
||||
|
||||
func test_experience_uses_cumulative_thresholds_and_awards_one_of_each_point_per_level() -> void:
|
||||
var experience := ExperienceType.new()
|
||||
|
||||
assert_eq(experience.xp_for_level(1), 0)
|
||||
assert_eq(experience.xp_for_level(2), 100)
|
||||
assert_eq(experience.xp_for_level(3), 300)
|
||||
# The E4 neutral companion event routes through the shared F1 split rule.
|
||||
assert_eq(ExperienceType.split_reward(9, true), {"player_xp": 5, "companion_xp": 4})
|
||||
assert_eq(ExperienceType.split_reward(9, false), {"player_xp": 9, "companion_xp": 0})
|
||||
assert_eq(experience.grant(99), {"xp_gained": 99, "levels_gained": 0})
|
||||
assert_eq(experience.level, 1)
|
||||
assert_eq(experience.grant(201), {"xp_gained": 201, "levels_gained": 2})
|
||||
assert_eq(experience.total_xp, 300)
|
||||
assert_eq(experience.level, 3)
|
||||
assert_eq(experience.attribute_points, 2)
|
||||
assert_eq(experience.skill_points, 2)
|
||||
|
||||
func test_skill_tree_spends_level_rewards_once_and_rejects_unknown_and_overspend_requests() -> void:
|
||||
var experience := ExperienceType.new()
|
||||
experience.grant(100)
|
||||
var attributes := AttributesType.new()
|
||||
var tree := SkillTreeType.new(experience, attributes)
|
||||
|
||||
assert_eq(tree.spend_attribute(&"str_"), {"accepted": true, "reason": &""})
|
||||
assert_eq(attributes.get_attribute(&"str_"), 5)
|
||||
assert_eq(experience.attribute_points, 0)
|
||||
assert_eq(tree.spend_attribute(&"str_"), {"accepted": false, "reason": &"insufficient_attribute_points"})
|
||||
assert_eq(tree.spend_attribute(&"not_an_attribute"), {"accepted": false, "reason": &"unknown_attribute"})
|
||||
assert_eq(tree.spend_skill(&"melee"), {"accepted": true, "reason": &""})
|
||||
assert_eq(tree.skill_value(&"melee"), 2)
|
||||
assert_eq(experience.skill_points, 0)
|
||||
assert_eq(tree.spend_skill(&"melee"), {"accepted": false, "reason": &"insufficient_skill_points"})
|
||||
assert_eq(tree.spend_skill(&"not_a_skill"), {"accepted": false, "reason": &"unknown_skill"})
|
||||
|
||||
func test_actor_xp_grants_progression_and_keeps_legacy_xp_ledger_in_sync() -> void:
|
||||
var actor := ActorStateType.new(&"player", Vector2i.ZERO, 12, 3, &"player", {"xp": 99})
|
||||
|
||||
assert_eq(actor.xp, 99)
|
||||
assert_eq(actor.progression.level, 1)
|
||||
assert_eq(actor.grant_xp(1), {"xp_gained": 1, "levels_gained": 1})
|
||||
assert_eq(actor.xp, 100)
|
||||
assert_eq(actor.progression.level, 2)
|
||||
assert_eq(actor.progression.attribute_points, 1)
|
||||
assert_eq(actor.progression.skill_points, 1)
|
||||
Reference in New Issue
Block a user