133 lines
3.8 KiB
GDScript
133 lines
3.8 KiB
GDScript
extends Node
|
|
|
|
@onready var xpPopupScene = preload("res://Skills/XpPopups/XpPopup.tscn")
|
|
|
|
var skills = {}
|
|
var levelCurve = [40, 80, 100, 30, 30, 200, 120, 80, 300,
|
|
220, 180, 130, 400, 410, 300, 500, 220, 2000, 90,
|
|
90, 200, 550, 620, 150, 160, 720, 710, 700, 2220,
|
|
450, 510, 550, 180, 900, 240, 160, 380, 100, 2500,
|
|
560, 770, 620, 850, 320, 250, 280, 2000, 450, 1110,
|
|
1010, 990, 880, 770, 660, 550, 440, 330, 220, 6660]
|
|
|
|
var xpPopups = []
|
|
|
|
func _init():
|
|
initialize_skills()
|
|
|
|
func hide_skills():
|
|
if skills["walking"].currentLevel < 20:
|
|
skills["fastWalking"].hidden = true
|
|
|
|
func _process(delta):
|
|
if skills["fastWalking"].hidden:
|
|
if skills["walking"].currentLevel >= 20:
|
|
unlock_skill("fastWalking")
|
|
|
|
func unlock_skill(skillName):
|
|
var skill = skills[skillName]
|
|
skill.hidden = false
|
|
|
|
if !SaveManager.get_save_value(skillName + "Unlocked", false):
|
|
MessageManager.secret_skill_popup(skill)
|
|
SaveManager.set_save_value(skillName + "Unlocked", true)
|
|
|
|
func add_XP(skillName, amount):
|
|
var multiplier = SaveManager.get_save_value("xpMult", 1)
|
|
amount = amount*multiplier
|
|
amount = roundi(amount)
|
|
|
|
var skill = get_skill(skillName)
|
|
skill.add_XP(amount)
|
|
|
|
spawn_XP_drop(skill, amount)
|
|
|
|
while skill.currentXP >= get_XP_to_next_level(skill.currentLevel):
|
|
skill.currentXP -= get_XP_to_next_level(skill.currentLevel)
|
|
skill.currentLevel += 1
|
|
MessageManager.levelup_popup(skill)
|
|
MessageManager.addMessage(skill.skillName + " level is now " + str(skill.currentLevel),
|
|
null, "System", Color.BLUE, true, false)
|
|
AchievementManager.skill_level_achievement_checks(skill)
|
|
|
|
AchievementManager.total_level_achievement_checks()
|
|
SaveManager.save_game()
|
|
|
|
func spawn_XP_drop(skill:Skill, amount):
|
|
var newXpPopup = xpPopupScene.instantiate()
|
|
newXpPopup.set_amount(amount)
|
|
newXpPopup.set_sprite(skill.get_icon())
|
|
|
|
newXpPopup.global_position = GameVariables.player.global_position + Vector2(-50, -100)
|
|
add_child(newXpPopup)
|
|
|
|
clean_up_xp_drops()
|
|
layout_xp_drops(newXpPopup.global_position)
|
|
xpPopups.push_front(newXpPopup)
|
|
|
|
func clean_up_xp_drops():
|
|
var xpPopupsSize = xpPopups.size()
|
|
for i in range(xpPopupsSize):
|
|
var currentIndex = xpPopupsSize - i - 1
|
|
var currentXpDrop = xpPopups[currentIndex]
|
|
if !is_instance_valid(currentXpDrop) or currentXpDrop == null:
|
|
xpPopups.remove_at(currentIndex)
|
|
|
|
func layout_xp_drops(newXpDropPos):
|
|
var lastPos = newXpDropPos
|
|
for i in range(xpPopups.size()):
|
|
var currentXpPopup = xpPopups[i]
|
|
|
|
var yDif = lastPos.y - currentXpPopup.global_position.y
|
|
if yDif <= 20:
|
|
currentXpPopup.global_position.y = lastPos.y - 20
|
|
|
|
lastPos = currentXpPopup.global_position
|
|
|
|
func get_XP_to_next_level(currentLevel:int):
|
|
if currentLevel > levelCurve.size():
|
|
return 99999900
|
|
|
|
return levelCurve[currentLevel - 1]
|
|
|
|
func get_total_level():
|
|
var totalLevel = 0
|
|
for skill in skills.values():
|
|
totalLevel += skill.currentLevel
|
|
|
|
return totalLevel
|
|
|
|
func skill_check(skillName, levelNeeded):
|
|
var overrideCheck = SaveManager.get_save_value("disableQuestLevelChecks", false)
|
|
if overrideCheck:
|
|
return true
|
|
|
|
if skills[skillName].currentLevel >= levelNeeded:
|
|
return true
|
|
return false
|
|
|
|
func get_skill(skillName):
|
|
return skills[skillName]
|
|
|
|
func get_all_skills():
|
|
return skills.values()
|
|
|
|
func add_all_xp(amount:int):
|
|
var skillNames = skills.keys()
|
|
for skill in skills:
|
|
add_XP(skill, amount)
|
|
|
|
func initialize_skills():
|
|
skills["arson"] = Arson.new()
|
|
skills["walking"] = Walking.new()
|
|
skills["juiceDrinking"] = JuiceDrinking.new()
|
|
skills["scavenging"] = Scavenging.new()
|
|
skills["basketWeaving"] = BasketWeaving.new()
|
|
skills["appreciating"] = Appreciating.new()
|
|
skills["gaming"] = Gaming.new()
|
|
skills["trampolining"] = Trampolining.new()
|
|
skills["gardening"] = Gardening.new()
|
|
skills["swimming"] = Swimming.new()
|
|
skills["building"] = Building.new()
|
|
skills["fastWalking"] = FastWalking.new()
|