Compare commits

..

2 Commits

Author SHA1 Message Date
97d7b969da Movement modifier tweaks. Almost there. 2025-04-30 23:48:49 -07:00
2c7a8e64f2 Tired state added to test movement. 2025-04-30 23:39:33 -07:00
4 changed files with 37 additions and 3 deletions

View File

@ -47,6 +47,8 @@ func _ready():
request_state_change = funcref(get_node(callable_state_machine), 'change_to_known_state') request_state_change = funcref(get_node(callable_state_machine), 'change_to_known_state')
## Connect signal to get alerted of state change ## Connect signal to get alerted of state change
get_node(callable_state_machine).connect("state_changed", self,"_on_state_change") get_node(callable_state_machine).connect("state_changed", self,"_on_state_change")
## Get notified when modifiers updated
get_node(callable_state_machine).connect("modifiers_updated",self,"_on_modifiers_updated")
## A reference to the current state machine state ## A reference to the current state machine state
current_state = get_node(callable_state_machine).current_state current_state = get_node(callable_state_machine).current_state
## A reference to the state machine merged modifiers ## A reference to the state machine merged modifiers
@ -136,6 +138,14 @@ func _on_state_change(old_state_name:String, new_state :State):
push_warning("Received non animated Actor state.") push_warning("Received non animated Actor state.")
#current_state = new_state #current_state = new_state
func _on_modifiers_updated(_modifier_type :int, _modifier_action :int, _merged_modifier :StateModifier):
## Get reference (subscribe) to the merged modifier for movement
if _merged_modifier is StateModifierMovement:
print("Registered Modifier Movement: ", _merged_modifier.horizontal_speed)
modifier = _merged_modifier
## Side effects for these variables ## Side effects for these variables
# velocity - doesn't change but uses it to set base calculations # velocity - doesn't change but uses it to set base calculations
# accepts the state to determine movement, the deltatime, and an optional direction # accepts the state to determine movement, the deltatime, and an optional direction

View File

@ -58,7 +58,7 @@ func _ready():
func merge_modifiers(): func merge_modifiers():
#merged_animation_state_modifiers.reset() #merged_animation_state_modifiers.reset()
for modgroup in merged_modifiers.keys(): for modgroup in merged_modifiers.keys():
merged_modifiers["StateModifierAnimatedActor"].reset() merged_modifiers[modgroup].reset()
for m in state_modifiers: for m in state_modifiers:
if m is StateModifierAnimatedActor: if m is StateModifierAnimatedActor:
if merged_modifiers.has("StateModifierAnimatedActor") == false: if merged_modifiers.has("StateModifierAnimatedActor") == false:
@ -68,6 +68,13 @@ func merge_modifiers():
if m.is_active: if m.is_active:
#merged_animation_state_modifiers.merge(m) #merged_animation_state_modifiers.merge(m)
this_mod_type.merge(m) this_mod_type.merge(m)
if m is StateModifierMovement:
if merged_modifiers.has("StateModifierMovement") == false:
merged_modifiers["StateModifierMovement"] = StateModifierMovement.new()
#print(m.name)
var this_mod_type :StateModifierMovement = merged_modifiers["StateModifierMovement"]
if m.is_active:
this_mod_type.merge(m)
# Change to the new state by first calling any exit logic on the current state. # Change to the new state by first calling any exit logic on the current state.
func change_state(new_state: State) -> void: func change_state(new_state: State) -> void:

View File

@ -34,6 +34,15 @@ const state_to_item_map :Dictionary = {
var player_info_index :int var player_info_index :int
var player_data :PlayerData var player_data :PlayerData
## Temp Modifier to test movement modifier (getting tired)
var tired_debuff_modifier = StateModifierMovement.new()
# attack_sword = StateModifierAnimatedActor.new()
# attack_sword.setup('sword_drawn',StateModifier.TYPE.ANIMATION_SUFFIX,2.0)
# add_child(attack_sword.timeout)
# #attack_sword.animation_name = 'PoopenStein'
# attack_sword.animation_suffix = 'attack-sword'
# add_state_modifier.call_func(attack_sword)
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
@ -59,6 +68,10 @@ func _ready():
player_inventory.select_primary(punch_item) player_inventory.select_primary(punch_item)
movement_component.state_stamina_cost = state_stamina_cost movement_component.state_stamina_cost = state_stamina_cost
tired_debuff_modifier.setup('so_tired', StateModifier.TYPE.NONE)
tired_debuff_modifier.horizontal_speed = -40
movement_state_machine.push_state_modifier(tired_debuff_modifier)
#var stamina_recovery :float = 0.0 #var stamina_recovery :float = 0.0
@ -86,7 +99,11 @@ func _process(delta):
hitbox_component.damage_amount = state_damage_amount[movement_state_machine.current_state.name] hitbox_component.damage_amount = state_damage_amount[movement_state_machine.current_state.name]
else: else:
hitbox_component.damage_amount = 10 hitbox_component.damage_amount = 10
if stamina_component.stamina < 20 and tired_debuff_modifier.is_active == false:
tired_debuff_modifier.activate()
if stamina_component.stamina > 20 and tired_debuff_modifier.is_active == true:
tired_debuff_modifier.deactivate()
func hit_Receiver(damage): func hit_Receiver(damage):

View File

@ -148,7 +148,7 @@ max_health = 100
[node name="Stamina_Component" parent="." index="9" instance=ExtResource( 29 )] [node name="Stamina_Component" parent="." index="9" instance=ExtResource( 29 )]
unique_name_in_owner = true unique_name_in_owner = true
max_stamina = 50 max_stamina = 50
recovery_rate = 12 recovery_rate = 2
[node name="Hurtbox_Component" parent="." index="10" instance=ExtResource( 16 )] [node name="Hurtbox_Component" parent="." index="10" instance=ExtResource( 16 )]
collision_layer = 16 collision_layer = 16