From ccdee2e05700297c12b8dc73f5e9ed93ba99d4cc Mon Sep 17 00:00:00 2001 From: tonydero Date: Sun, 20 Oct 2024 16:44:08 -0600 Subject: [PATCH] many renames, basic exp earning --- .gitignore | 3 ++- project.godot | 4 +++ scenes/enemy.tscn | 2 ++ scenes/testScrollScene.tscn | 10 +++++--- scripts/AbilityBase.gd | 14 +---------- scripts/AbilityPlayer.gd | 48 +++++++++++++++++++++++++++++++----- scripts/Globals.gd | 15 +++++++---- scripts/ItemGear.gd | 2 +- scripts/NPC.gd | 7 +++--- scripts/NPCEnemy.gd | 17 +++++++------ scripts/Player.cs | 8 ++++++ scripts/Player.gd | 46 ++++++++++++++++++++++++++++++++++ scripts/PlayerState.gd | 4 +-- scripts/Quest.gd | 18 +++++++++----- scripts/SignalBus.gd | 6 ++++- scripts/WorldArea.gd | 3 +-- scripts/WorldState.gd | 2 +- scripts/gearRand.gd | 2 +- scripts/test_scroll_scene.gd | 10 ++++---- 19 files changed, 164 insertions(+), 57 deletions(-) create mode 100644 scripts/Player.cs create mode 100644 scripts/Player.gd diff --git a/.gitignore b/.gitignore index 58c1eec..dc3b101 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,5 @@ export_presets.cfg data_*/ mono_crash.*.json - +# codium stuff +.VSCodeCounter diff --git a/project.godot b/project.godot index 60547f9..bf72253 100644 --- a/project.godot +++ b/project.godot @@ -34,3 +34,7 @@ project/assembly_name="Semi-Idle ARPG" [editor_plugins] enabled=PackedStringArray("res://addons/godot-vim/plugin.cfg") + +[physics] + +common/physics_ticks_per_second=120 diff --git a/scenes/enemy.tscn b/scenes/enemy.tscn index c625874..a715b92 100644 --- a/scenes/enemy.tscn +++ b/scenes/enemy.tscn @@ -6,6 +6,8 @@ [node name="NPCEnemy" type="CharacterBody2D"] script = ExtResource("1_ec4cy") +npcDifficulty = 2 +npcTier = 4 [node name="CollisionShape2D" type="CollisionPolygon2D" parent="."] position = Vector2(-100, -86) diff --git a/scenes/testScrollScene.tscn b/scenes/testScrollScene.tscn index ac6d18b..de0b8ce 100644 --- a/scenes/testScrollScene.tscn +++ b/scenes/testScrollScene.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=15 format=3 uid="uid://0h3dpe6fuhe8"] +[gd_scene load_steps=16 format=3 uid="uid://0h3dpe6fuhe8"] [ext_resource type="Script" path="res://scripts/test_scroll_scene.gd" id="1_gc1kb"] [ext_resource type="Theme" uid="uid://clhh3c3gxotjg" path="res://assets/healthbar.tres" id="2_2v2l0"] [ext_resource type="Script" path="res://scripts/WorldArea.gd" id="2_ccxbh"] [ext_resource type="PackedScene" uid="uid://dvwo26vsk46tl" path="res://scenes/ability_player.tscn" id="2_heria"] +[ext_resource type="Script" path="res://scripts/Player.gd" id="3_cjiwt"] [ext_resource type="Theme" uid="uid://cp82s71sduhcv" path="res://assets/expbar.tres" id="3_n8q4b"] [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_6qo1s"] @@ -92,6 +93,7 @@ theme_override_styles/panel = SubResource("StyleBoxEmpty_imvmd") unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 3 +script = ExtResource("3_cjiwt") [node name="PlayerLabel" type="HBoxContainer" parent="MarginContainer/UIBottom/PlayerContainer/PlayerInfo"] layout_mode = 2 @@ -198,14 +200,16 @@ alignment = 1 [node name="AbilityA1" parent="MarginContainer/UIBottom/UIBottomCenter/AbilityBar" instance=ExtResource("2_heria")] custom_minimum_size = Vector2(64, 64) layout_mode = 2 -attack_range = 600 +attack_range = 9999 +attack_damage = 999999 [node name="AbilityA2" parent="MarginContainer/UIBottom/UIBottomCenter/AbilityBar" instance=ExtResource("2_heria")] +visible = false custom_minimum_size = Vector2(64, 64) layout_mode = 2 size_flags_horizontal = 6 -attack_range = 200 target_type = 3 +attack_range = 200 attack_damage = 50 auto_speed = 5.0 diff --git a/scripts/AbilityBase.gd b/scripts/AbilityBase.gd index ce9b259..c6cdeb9 100644 --- a/scripts/AbilityBase.gd +++ b/scripts/AbilityBase.gd @@ -3,19 +3,7 @@ class_name AbilityBase extends TextureRect -enum TargTypes { - SINGLE, - CLEAVE, - CHAIN, - SWIPE, - WAVE, - AREA, - RAY, -} - - @export var attack_range := 0 -@export var target_type := TargTypes.SINGLE -@export var damage_type := Globals.Ability.PDmgTypes.SLICE +@export var damage_type := Globals.Ability.PDamageType.SLICE @export var attack_damage := 200 @export var auto_speed := 1.0 diff --git a/scripts/AbilityPlayer.gd b/scripts/AbilityPlayer.gd index 8d4cd6d..ac4b714 100644 --- a/scripts/AbilityPlayer.gd +++ b/scripts/AbilityPlayer.gd @@ -6,6 +6,19 @@ extends AbilityBase var middleX var playerPos +enum TargetType { + SINGLE, + CLEAVE, + CHAIN, + SWIPE, + WAVE, + AREA, + RAY, +} + + +@export var target_type := TargetType.SINGLE +@export var target_angle := 2*PI @export var base_cooldown := 0.0 func _ready() -> void: @@ -42,39 +55,62 @@ func _get_target(enemies) -> Node: # get list of distances by mapping distance to each node in enemies enemyDists = enemies.map(_get_distsq_to_player) # get closest enemy by finding first index with min dist - if enemyDists.min() <= self.attack_range**2: + if enemyDists.min() <= self.attack_range ** 2: closestEnemy = enemies[enemyDists.find(enemyDists.min())] return closestEnemy -func _get_targets(enemies) -> Array: +func _get_targets_in_range(enemies) -> Array: var enemyDists var enemiesInRange := [] # get list of distances by mapping distance to each node in enemies enemyDists = enemies.map(_get_distsq_to_player) # append enemies in range to enemiesInRange for i in range(enemies.size()): - if enemyDists[i] <= self.attack_range**2: + if enemyDists[i] <= self.attack_range ** 2: enemiesInRange.append(enemies[i]) return enemiesInRange +# func _get_targets_in_angle(enemies) -> Array: +# var enemyAngles +# var enemiesInAngle := [] +# # get list of angles by mapping distance to each node in enemies +# enemyAngles = enemies.map(_get_angle_to_player) +# # append enemies in range to enemiesInAngle +# for i in range(enemies.size()): +# if enemyAngles[i] <= self.attack_range ** 2: +# enemiesInAngle.append(enemies[i]) + +# return enemiesInAngle + + +# func _get_targets(enemies) -> Array: +# if self.attack_range > 0: +# var enemiesInRange = _get_targets_in_range(enemies) + + + +func _apply_status() -> void: + # TODO: Try passing damage and status type to target for mods, e.g. burning or stunned, and use with singleton stats to add thread to target for damage or do other things depending on the case + pass + + func _deal_idle_damage(enemiesList) -> void: match target_type: - TargTypes.SINGLE: + TargetType.SINGLE: var target = _get_target(enemiesList) if target: target.damageTaken += attack_damage _: - var targets = _get_targets(enemiesList) + var targets = _get_targets_in_range(enemiesList) if targets: for target in targets: target.damageTaken += attack_damage - func _on_idle_cooldown_timeout() -> void: var enemiesList = _get_enemies() if not enemiesList.is_empty() and self.visible: diff --git a/scripts/Globals.gd b/scripts/Globals.gd index eb037c7..86d7dac 100644 --- a/scripts/Globals.gd +++ b/scripts/Globals.gd @@ -2,26 +2,30 @@ extends Node class World: - enum Zones { + enum Zone { TUTORIAL, } - enum AreaTypes { + enum AreaType { PEACEFUL, URBAN, WILDS, DEEP_WILDS, DUNGEON, } + enum Faction { + CREATURE, + MONSTER, + } class Ability: - enum PDmgTypes { + enum PDamageType { SLICE, PUNCTURE, BASH, HACK, SHRED, } - enum MDmgTypes { + enum MDamageType { BURN, FREEZE, SHOCK, @@ -32,11 +36,12 @@ class Ability: ARCANE, FORCE } - enum SModTypes { + enum StatusModType { STUN, SLOW, ABSORB, SHIELD, + DOT, DOTB, DOTE } diff --git a/scripts/ItemGear.gd b/scripts/ItemGear.gd index dcf19a3..43ca33f 100644 --- a/scripts/ItemGear.gd +++ b/scripts/ItemGear.gd @@ -1,5 +1,5 @@ class_name Gear -extends "item.gd" +extends Item # the basic stats that occur on gear diff --git a/scripts/NPC.gd b/scripts/NPC.gd index b2c58b4..52c46ce 100644 --- a/scripts/NPC.gd +++ b/scripts/NPC.gd @@ -13,6 +13,7 @@ signal npc_died(npcTier: NPCTier) @export var damageTaken := 0 @export var npcDifficulty: NPCDifficulty @export var npcTier: NPCTier +@export var faction: Globals.World.Faction func _random_mod_health() -> void: randomize() @@ -37,9 +38,9 @@ func _random_mod_health() -> void: self.maxHealth *= 10 -func _init() -> void: - self.npcDifficulty = NPCDifficulty.NORMAL - self.npcTier = NPCTier.I +# func _init() -> void: +# self.npcDifficulty = NPCDifficulty.NORMAL +# self.npcTier = NPCTier.I func _ready() -> void: diff --git a/scripts/NPCEnemy.gd b/scripts/NPCEnemy.gd index 061fa12..5e7f854 100644 --- a/scripts/NPCEnemy.gd +++ b/scripts/NPCEnemy.gd @@ -3,22 +3,24 @@ class_name NPCEnemy extends NPC -@export var killType: WorldArea.Faction = WorldArea.Faction.CREATURE var target var speed := 200 var prevCollisions := 0 -func _init() -> void: - # TODO: randomize within area restrictions? or put this in area? - self.npcDifficulty = NPCDifficulty.NORMAL - self.npcTier = NPCTier.I +# func _init() -> void: +# # TODO: randomize within area restrictions? or put this in area? +# self.npcDifficulty = NPCDifficulty.NORMAL +# self.npcTier = NPCTier.I func _ready() -> void: # add to enemies add_to_group("enemies") + + # set faction + self.faction = Globals.World.Faction.CREATURE # set health _random_mod_health() @@ -33,12 +35,13 @@ func _process(_delta: float) -> void: if damageTaken >= maxHealth: # save vars to emit var enemyDifficulty = self.npcDifficulty - var enemyKillType = self.killType + var enemyFaction = self.faction + var enemyTier = self.npcTier # delete node self.remove_from_group("enemies") self.queue_free() # send signal that I died to be counted, etc. - SignalBus.enemy_died.emit(enemyDifficulty, enemyKillType) + SignalBus.enemy_died.emit(enemyDifficulty, enemyTier, enemyFaction) func _physics_process(_delta): diff --git a/scripts/Player.cs b/scripts/Player.cs new file mode 100644 index 0000000..c4f3aab --- /dev/null +++ b/scripts/Player.cs @@ -0,0 +1,8 @@ +// player class +using Godot; + +public class Player +{ + public int playerLevel; + public int playerExp; +} \ No newline at end of file diff --git a/scripts/Player.gd b/scripts/Player.gd new file mode 100644 index 0000000..96dea34 --- /dev/null +++ b/scripts/Player.gd @@ -0,0 +1,46 @@ +# player class +class_name Player +extends VBoxContainer + + +var area_exp := 0.0 + + +func _ready() -> void: + SignalBus.enemy_died.connect(_on_enemy_died) + SignalBus.quest_completed.connect(_on_quest_completed) + $PlayerExpBar.value = _get_level_progress_percent() + $PlayerLabel/PlayerLevel.text = str(floor(PlayerState.player_level)) + + +func _on_enemy_died(enemyDifficulty, enemyTier, _enemyFaction) -> void: + var kill_exp = pow(pow(enemyTier + 1, 3), enemyDifficulty) + area_exp += kill_exp + print("T: ", enemyTier, " D: ", enemyDifficulty) + print("K: ", kill_exp) + print("A: ",area_exp) + # TODO: maybe show earned exp on bar, separate from current + # use xp to next level and current level, subtract, figure out percentage per point exp, add to display? + + +func _calculate_player_level() -> float: + var current_exp = PlayerState.player_exp + return log((current_exp + 5)/5.0) + 1 + + +func _get_level_progress_percent() -> float: + var current_level = _calculate_player_level() + return fmod(current_level, 1) * 100.0 + + +func _on_quest_completed() -> void: + PlayerState.player_exp += area_exp + PlayerState.player_level = _calculate_player_level() + $PlayerExpBar.value = _get_level_progress_percent() + $PlayerLabel/PlayerLevel.text = str(floor(PlayerState.player_level)) + print("FA: ", area_exp) + print("L: ", PlayerState.player_level) + print("XP: ", PlayerState.player_exp) + print("CL: ", _calculate_player_level()) + print("LP: ", _get_level_progress_percent()) + Engine.time_scale = 0.0001 diff --git a/scripts/PlayerState.gd b/scripts/PlayerState.gd index 8c6ae88..c979551 100644 --- a/scripts/PlayerState.gd +++ b/scripts/PlayerState.gd @@ -3,7 +3,7 @@ extends Node @export var player_constitution := 1 -@export var player_exp := 0 -@export var player_level := 1 +@export var player_exp := 0.0 +@export var player_level := 1.0 @export var player_maxhealth := player_constitution * player_level * 100 @export var player_currenthealth := player_maxhealth \ No newline at end of file diff --git a/scripts/Quest.gd b/scripts/Quest.gd index 2126410..ef9cc88 100644 --- a/scripts/Quest.gd +++ b/scripts/Quest.gd @@ -1,9 +1,11 @@ +# quest class, impleeenting all quest functionality +# TODO: implement zone quests class_name Quest extends PanelContainer @export var goalType := WorldArea.GoalType.KILL -@export var faction := WorldArea.Faction.CREATURE +@export var faction := Globals.World.Faction.CREATURE @export var goalTotal := 1 @export var goalCurrent := 0 @@ -25,7 +27,7 @@ func _process(_delta: float) -> void: func _set_goal_text() -> void: var goalStr = WorldArea.GoalType.keys()[self.goalType].capitalize() - var factionStr = WorldArea.Faction.keys()[self.faction].capitalize() + var factionStr = Globals.World.Faction.keys()[self.faction].capitalize() $QuestProgress/GoalTypeVal.text = goalStr + " " + factionStr + "s" @@ -33,7 +35,7 @@ func _set_goal_val() -> void: $QuestProgress/GoalVal.text = str(self.goalTotal) -func _quest_goal_check(enemyKillType: WorldArea.Faction) -> void: +func _quest_goal_check(enemyKillType: Globals.World.Faction) -> void: if enemyKillType == self.faction: self.goalCurrent += 1 $QuestProgress/CompletedVal.text = str(self.goalCurrent) @@ -51,14 +53,18 @@ func _quest_complete_show() -> void: func _generate_random_quest() -> void: - # TODO: generate random quest + # TODO: generate acutally random quest self.goalType = WorldArea.GoalType.KILL - self.faction = WorldArea.Faction.CREATURE + self.faction = Globals.World.Faction.CREATURE self.goalTotal = randi_range(20, 50) # match self.goalType: # GoalTypes.KILLMANY: # self.faction = KillTypes.NATURAL -func _on_enemy_died(_enemyDifficulty: NPC.NPCDifficulty, enemyFaction: WorldArea.Faction): +func _on_enemy_died( + _enemyDifficulty: NPC.NPCDifficulty, + _enemyTier: NPC.NPCTier, + enemyFaction: Globals.World.Faction, +): _quest_goal_check(enemyFaction) diff --git a/scripts/SignalBus.gd b/scripts/SignalBus.gd index 3fb72f6..834572c 100644 --- a/scripts/SignalBus.gd +++ b/scripts/SignalBus.gd @@ -2,6 +2,10 @@ extends Node -signal enemy_died(npcDifficulty: NPC.NPCDifficulty, faction: WorldArea.Faction) +signal enemy_died( + npcDifficulty: NPC.NPCDifficulty, + npcTier: NPC.NPCTier, + faction: Globals.World.Faction, +) signal enemy_damaged_player signal quest_completed \ No newline at end of file diff --git a/scripts/WorldArea.gd b/scripts/WorldArea.gd index e09e3a0..bcd54e5 100644 --- a/scripts/WorldArea.gd +++ b/scripts/WorldArea.gd @@ -4,9 +4,8 @@ extends PanelContainer enum GoalType {KILL, FIND} -enum Faction {CREATURE, MONSTER} -@export var area_type := Globals.World.AreaTypes.WILDS +@export var area_type := Globals.World.AreaType.WILDS # instantiate Quest diff --git a/scripts/WorldState.gd b/scripts/WorldState.gd index 16a8a56..e22a531 100644 --- a/scripts/WorldState.gd +++ b/scripts/WorldState.gd @@ -2,5 +2,5 @@ extends Node -@export var current_zone: Globals.World.Zones +@export var current_zone: Globals.World.Zone @export var last_played: Dictionary \ No newline at end of file diff --git a/scripts/gearRand.gd b/scripts/gearRand.gd index c119176..638e75e 100644 --- a/scripts/gearRand.gd +++ b/scripts/gearRand.gd @@ -1,5 +1,5 @@ class_name GearRandom -extends "gear.gd" +extends Gear func _init(): diff --git a/scripts/test_scroll_scene.gd b/scripts/test_scroll_scene.gd index a432edc..00f35f4 100644 --- a/scripts/test_scroll_scene.gd +++ b/scripts/test_scroll_scene.gd @@ -3,7 +3,7 @@ extends Control @export var debug = false -@export var spawnTimerValue = 5.0 +@export var spawnTimerValue = 10.0 var deltaCount := 0 var enemyMoveSpeed := 5.0 @@ -17,7 +17,7 @@ var playerPos func _ready() -> void: if debug: %DebugMenu.show() - Engine.time_scale = 3.0 + Engine.time_scale = 10.0 SignalBus.quest_completed.connect(_on_quest_completed) SignalBus.enemy_damaged_player.connect(_on_enemy_damaged_player) @@ -30,7 +30,7 @@ func _ready() -> void: _set_player_display() $SpawnTimer.start(spawnTimerValue) - _spawn_enemies(1) + _spawn_enemies(randi_range(1, 5)) # _spawn_enemies(5) @@ -83,7 +83,7 @@ func _on_button_exit_pressed() -> void: func _on_spawn_timer_timeout() -> void: - _spawn_enemies(1) + _spawn_enemies(randi_range(1, 5)) func _get_player_current_health() -> void: @@ -91,7 +91,7 @@ func _get_player_current_health() -> void: %PlayerInfo/PlayerHealthBar/PlayerHealthCurrent.text = str(playerCurrHeath) %PlayerInfo/PlayerHealthBar.value = playerCurrHeath if playerCurrHeath <= 0: - get_tree().paused = true + Engine.time_scale = 0.0001 func _set_player_display() -> void: