From 22e2ecd4c9b0a5ce20cb184f821454140ccd8c6f Mon Sep 17 00:00:00 2001 From: Hecht Date: Mon, 8 Sep 2025 20:58:52 +0200 Subject: [PATCH 1/3] Added conversion from object oriented fight to array-of-rounds --- scenes/Global/API.gd | 8 +- scenes/Global/FightLib.gd | 199 +++++++++++++++++++++++---------- scenes/Main/FightSetup.tscn | 6 + scenes/Main/fight_setup.gd | 7 ++ scenes/Main/fight_setup.gd.uid | 1 + 5 files changed, 162 insertions(+), 59 deletions(-) create mode 100644 scenes/Main/FightSetup.tscn create mode 100644 scenes/Main/fight_setup.gd create mode 100644 scenes/Main/fight_setup.gd.uid diff --git a/scenes/Global/API.gd b/scenes/Global/API.gd index 5afdd38..0c5c350 100644 --- a/scenes/Global/API.gd +++ b/scenes/Global/API.gd @@ -20,9 +20,7 @@ var _all_characters: Dictionary = {} var _techniques: Dictionary = {} var _techniques_array : Array = [] - -# Called when the node enters the scene tree for the first time. -func _ready(): +func initialize_api(): _http_request.base_address = "http://localhost:8000" _http_request.auth_token = "_sGFrChRV6ML0eWZC2qSUZzEGNLPbAhP4dwmnWhQ5bQ9xIi2pwHWQ1CzybFPDLeK8dTNx6GgWdR-Jcz-Z9_aC0hlY2h0fDIwMjQtMDYtMTNUMTk6MTU6MzkrMDA6MDA=" @@ -44,6 +42,10 @@ func _ready(): user_name = chunks.slice(64).get_string_from_utf8().split('|')[0] +# Called when the node enters the scene tree for the first time. +func _ready(): + initialize_api() + # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(_delta): pass diff --git a/scenes/Global/FightLib.gd b/scenes/Global/FightLib.gd index 0e6de71..f82715b 100644 --- a/scenes/Global/FightLib.gd +++ b/scenes/Global/FightLib.gd @@ -1,78 +1,165 @@ extends Node -class Motion: - pass +class Someone extends Object: + var name : String + + func _init(name : String) -> void: + self.name = name + +class Motion extends Object: + var originator : Someone + var animation : String + var stamina_change : float + + func _init(originator : Someone, animation : String, stamina_change : float = 0) -> void: + self.originator = originator + self.animation = animation + self.stamina_change = stamina_change class Recover extends Motion: ''' Animation ''' pass -class Action extends Motion: - pass +class Reaction extends Motion: + var hp_change : float -class ActionOnSelf extends Action: - pass + func _init(originator : Someone, animation: String, stamina_costs: float, hp_change : float): + super._init(originator, animation, -stamina_costs) + self.hp_change = hp_change -class Wait extends ActionOnSelf: - ''' Animation ''' - pass +class Counter extends Reaction: + var damage : float -class Buff extends ActionOnSelf: - ''' Animation ''' - pass + func _init(originator : Someone, animation: String, stamina_costs: float, damage : float): + super._init(originator, animation, -stamina_costs, 0) + self.damage = damage -class ActionOnOpponent extends Action: - pass +class Defense extends Reaction: + var successful : bool -class Attack extends ActionOnOpponent: - ''' Animation ''' - func get_damage() -> int: - return 0 + func _init(originator : Someone, animation: String, stamina_costs: float, hp_change : float): + super._init(originator, animation, -stamina_costs, hp_change) + self.successful = hp_change == 0.0 -class Debuff extends ActionOnOpponent: - ''' Animation ''' - pass +class Block extends Defense: + func _init(originator : Someone, animation : String, stamina_costs: float, hp_change : float): + super._init(originator, animation, stamina_costs, hp_change) -class Reaction extends Motion: - pass +class Evade extends Defense: + ''' Successfully, evaded? ''' + + func _init(originator : Someone, animation : String, stamina_costs: float, hp_change : float): + super._init(originator, animation, stamina_costs, hp_change) -class Counter extends Reaction: - ''' Animation ''' - pass +class Absorb extends Reaction: + ''' Actually, accept being hit ''' + + func _init(originator : Someone, animation: String, stamina_costs: float, hp_change : float): + super._init(originator, animation, -stamina_costs, hp_change) -class Defense extends Reaction: - func was_successful() -> bool: - return true -class Block extends Defense: - ''' Animation ''' +class Action extends Motion: pass -class Evade extends Defense: - ''' Animation ''' +class ActionOnSelf extends Action: pass -class Round: - pass +class Wait extends ActionOnSelf: + func _init(originator : Someone, animation : String, stamina_gain : float): + super._init(originator, animation, stamina_gain) -var actions = ["Attack", "Block", "Evade"] - -var rounds : Array[Round] = [ - Round.new(), - Round.new(), - Round.new(), - Round.new(), - Round.new(), - Round.new(), - Round.new(), - Round.new(), - Round.new(), - Round.new(), - Round.new(), - Round.new(), - Round.new(), - Round.new(), - Round.new(), - Round.new(), - Round.new(), -] +class Buff extends ActionOnSelf: + func _init(originator : Someone, animation : String) -> void: + super._init(originator, animation, 1.0) + +class ActionOnOpponent extends Action: + var opponent : Someone + var reaction : Reaction + + func _init(originator : Someone, animation : String, opponent : Someone, stamina_costs : float, reaction : Reaction) -> void: + super._init(originator, animation, -stamina_costs) + self.opponent = opponent + self.reaction = reaction + +class Attack extends ActionOnOpponent: + var damage : float + + func _init(originator : Someone, animation : String, opponent : Someone, stamina_costs : float, reaction : Reaction) -> void: + super._init(originator, animation, opponent, stamina_costs, reaction) + +class Debuff extends ActionOnOpponent: + func _init(originator : Someone, animation : String, opponent : Someone, stamina_costs : float, reaction : Reaction) -> void: + super._init(originator, animation, opponent, stamina_costs, reaction) + +class PlayerAnimation extends Object: + var animation : String + var hp_change : float + var stamina_change : float + +class Round extends Object: + var action: int + var animations : Array[PlayerAnimation] + +func convertReaction2PlayerAnimation(reaction : Reaction) -> PlayerAnimation: + if reaction == null: + return null + var a = PlayerAnimation.new() + a.animation = reaction.animation + a.hp_change = -reaction.hp_change + return a + +func getReaction(motion : Motion) -> Reaction: + if motion is ActionOnOpponent: + return motion.reaction + + return null + +func convertMotion2PlayerAnimation(motion : Motion) -> PlayerAnimation: + var a = PlayerAnimation.new() + a.animation = motion.animation + a.stamina_change = motion.stamina_change + return a + +func convertMotion2Round(lhs : Someone, rhs : Someone, motion : Motion) -> Round: + var round = Round.new() + + round.action = 0 if motion.originator == lhs else 1 + round.animations.append(convertMotion2PlayerAnimation(motion)) + var reaction = getReaction(motion) + round.animations.append(convertReaction2PlayerAnimation(reaction)) + + if reaction is Counter: + round.animations[0].hp_change = -reaction.damage + + return round + +# TODO: breakdown to a simpler transferable class +func convert(lhs : Someone, rhs : Someone, motions : Array[Motion]) -> Array[Round]: + var rounds : Array[Round] = [] + for motion in motions: + rounds.push_back(convertMotion2Round(lhs, rhs, motion)) + + return rounds + +func _init() -> void: + var player1 : Someone = Someone.new("John") + var player2 : Someone = Someone.new("Joe") + + var rounds : Array[Motion] = [ + Attack.new(player1, "Kick", player2, 1.0, Absorb.new(player2, "Hit", 1, 12.0)), + Buff.new(player2, "SSJ"), + Attack.new(player1, "Punch", player2, 2.0, Block.new(player2, "Block", 1.0, true)), + Wait.new(player2, "Wait", 5.0) + ] + + var r2 = self.convert(player1, player2, rounds) + + for r in r2: + var activeIndex = r.action + var reactiveIndex = 0 if r.action == 1 else 0 + var orientation = "Left" if r.action == 1 else "Right" + + print("%s Player {'Animation': '%s', 'hp_change': %f, 'stamina_change': %f}" % [orientation, r.animations[0].animation, r.animations[0].hp_change, r.animations[0].stamina_change]) + if r.animations[1] != null: + print("Other Player {'Animation': '%s', 'hp_change': %f, 'stamina_change': %f}" % [r.animations[1].animation, r.animations[1].hp_change, r.animations[1].stamina_change]) + print() diff --git a/scenes/Main/FightSetup.tscn b/scenes/Main/FightSetup.tscn new file mode 100644 index 0000000..0df59a6 --- /dev/null +++ b/scenes/Main/FightSetup.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://bmid6fvrq22bj"] + +[ext_resource type="Script" uid="uid://bwchifcb7bh05" path="res://scenes/Main/fight_setup.gd" id="1_l4m47"] + +[node name="FightSetup" type="Node2D"] +script = ExtResource("1_l4m47") diff --git a/scenes/Main/fight_setup.gd b/scenes/Main/fight_setup.gd new file mode 100644 index 0000000..1871d5d --- /dev/null +++ b/scenes/Main/fight_setup.gd @@ -0,0 +1,7 @@ +extends Node2D + +const FightLib = preload("res://scenes/Global/FightLib.gd") + +# Called when the node enters the scene tree for the first time. +func _ready(): + FightLib.new() diff --git a/scenes/Main/fight_setup.gd.uid b/scenes/Main/fight_setup.gd.uid new file mode 100644 index 0000000..556f88c --- /dev/null +++ b/scenes/Main/fight_setup.gd.uid @@ -0,0 +1 @@ +uid://bwchifcb7bh05 -- 2.30.2 From fef8caec93bb9b705c2a44ce38f45e04dda14456 Mon Sep 17 00:00:00 2001 From: Hecht Date: Mon, 8 Sep 2025 21:02:22 +0200 Subject: [PATCH 2/3] Minor text changes --- scenes/Global/FightLib.gd | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scenes/Global/FightLib.gd b/scenes/Global/FightLib.gd index f82715b..23ed17c 100644 --- a/scenes/Global/FightLib.gd +++ b/scenes/Global/FightLib.gd @@ -145,21 +145,21 @@ func _init() -> void: var player1 : Someone = Someone.new("John") var player2 : Someone = Someone.new("Joe") - var rounds : Array[Motion] = [ + var motions : Array[Motion] = [ Attack.new(player1, "Kick", player2, 1.0, Absorb.new(player2, "Hit", 1, 12.0)), Buff.new(player2, "SSJ"), Attack.new(player1, "Punch", player2, 2.0, Block.new(player2, "Block", 1.0, true)), Wait.new(player2, "Wait", 5.0) ] - var r2 = self.convert(player1, player2, rounds) + var rounds = self.convert(player1, player2, motions) - for r in r2: - var activeIndex = r.action - var reactiveIndex = 0 if r.action == 1 else 0 - var orientation = "Left" if r.action == 1 else "Right" + for round in rounds: + var activeIndex = round.action + var reactiveIndex = 0 if round.action == 1 else 0 + var orientation = "Left" if round.action == 1 else "Right" - print("%s Player {'Animation': '%s', 'hp_change': %f, 'stamina_change': %f}" % [orientation, r.animations[0].animation, r.animations[0].hp_change, r.animations[0].stamina_change]) - if r.animations[1] != null: - print("Other Player {'Animation': '%s', 'hp_change': %f, 'stamina_change': %f}" % [r.animations[1].animation, r.animations[1].hp_change, r.animations[1].stamina_change]) + print("%s Player {'Animation': '%s', 'hp_change': %f, 'stamina_change': %f}" % [orientation, round.animations[0].animation, round.animations[0].hp_change, round.animations[0].stamina_change]) + if round.animations[1] != null: + print("Other Player {'Animation': '%s', 'hp_change': %f, 'stamina_change': %f}" % [round.animations[1].animation, round.animations[1].hp_change, round.animations[1].stamina_change]) print() -- 2.30.2 From 84cff2ebbfce5819a2906e8e9d8a89fb16abbab6 Mon Sep 17 00:00:00 2001 From: Hecht Date: Mon, 8 Sep 2025 22:11:16 +0200 Subject: [PATCH 3/3] Extracted the fight calculation --- project.godot | 2 +- scenes/Global/FightLib.gd | 169 ++++----------------------------- scenes/Global/FightLib.gd.uid | 2 +- scenes/Global/MotionLib.gd | 108 +++++++++++++++++++++ scenes/Global/MotionLib.gd.uid | 1 + scenes/Global/RenderLib.gd | 52 ++++++++++ scenes/Global/RenderLib.gd.uid | 1 + scenes/Main/fight_setup.gd | 18 +++- 8 files changed, 197 insertions(+), 156 deletions(-) create mode 100644 scenes/Global/MotionLib.gd create mode 100644 scenes/Global/MotionLib.gd.uid create mode 100644 scenes/Global/RenderLib.gd create mode 100644 scenes/Global/RenderLib.gd.uid diff --git a/project.godot b/project.godot index 21a378e..7d8b98f 100644 --- a/project.godot +++ b/project.godot @@ -17,7 +17,7 @@ config/icon="res://icon.svg" [autoload] -API="*res://scenes/Global/API.tscn" +API="res://scenes/Global/API.tscn" Dialogic="*res://addons/dialogic/Core/DialogicGameHandler.gd" [dialogic] diff --git a/scenes/Global/FightLib.gd b/scenes/Global/FightLib.gd index 23ed17c..77d18a5 100644 --- a/scenes/Global/FightLib.gd +++ b/scenes/Global/FightLib.gd @@ -1,165 +1,28 @@ extends Node -class Someone extends Object: - var name : String - - func _init(name : String) -> void: - self.name = name +const MotionLib = preload("res://scenes/Global/MotionLib.gd") -class Motion extends Object: - var originator : Someone - var animation : String - var stamina_change : float - - func _init(originator : Someone, animation : String, stamina_change : float = 0) -> void: - self.originator = originator - self.animation = animation - self.stamina_change = stamina_change - -class Recover extends Motion: - ''' Animation ''' +class Skill: pass -class Reaction extends Motion: - var hp_change : float - - func _init(originator : Someone, animation: String, stamina_costs: float, hp_change : float): - super._init(originator, animation, -stamina_costs) - self.hp_change = hp_change - -class Counter extends Reaction: - var damage : float - - func _init(originator : Someone, animation: String, stamina_costs: float, damage : float): - super._init(originator, animation, -stamina_costs, 0) - self.damage = damage - -class Defense extends Reaction: - var successful : bool - - func _init(originator : Someone, animation: String, stamina_costs: float, hp_change : float): - super._init(originator, animation, -stamina_costs, hp_change) - self.successful = hp_change == 0.0 - -class Block extends Defense: - func _init(originator : Someone, animation : String, stamina_costs: float, hp_change : float): - super._init(originator, animation, stamina_costs, hp_change) - -class Evade extends Defense: - ''' Successfully, evaded? ''' - - func _init(originator : Someone, animation : String, stamina_costs: float, hp_change : float): - super._init(originator, animation, stamina_costs, hp_change) - -class Absorb extends Reaction: - ''' Actually, accept being hit ''' - - func _init(originator : Someone, animation: String, stamina_costs: float, hp_change : float): - super._init(originator, animation, -stamina_costs, hp_change) - - -class Action extends Motion: +class Action extends Skill: pass -class ActionOnSelf extends Action: +class Reaction extends Skill: pass -class Wait extends ActionOnSelf: - func _init(originator : Someone, animation : String, stamina_gain : float): - super._init(originator, animation, stamina_gain) - -class Buff extends ActionOnSelf: - func _init(originator : Someone, animation : String) -> void: - super._init(originator, animation, 1.0) - -class ActionOnOpponent extends Action: - var opponent : Someone - var reaction : Reaction - - func _init(originator : Someone, animation : String, opponent : Someone, stamina_costs : float, reaction : Reaction) -> void: - super._init(originator, animation, -stamina_costs) - self.opponent = opponent - self.reaction = reaction - -class Attack extends ActionOnOpponent: - var damage : float - - func _init(originator : Someone, animation : String, opponent : Someone, stamina_costs : float, reaction : Reaction) -> void: - super._init(originator, animation, opponent, stamina_costs, reaction) - -class Debuff extends ActionOnOpponent: - func _init(originator : Someone, animation : String, opponent : Someone, stamina_costs : float, reaction : Reaction) -> void: - super._init(originator, animation, opponent, stamina_costs, reaction) - -class PlayerAnimation extends Object: - var animation : String - var hp_change : float - var stamina_change : float - -class Round extends Object: - var action: int - var animations : Array[PlayerAnimation] - -func convertReaction2PlayerAnimation(reaction : Reaction) -> PlayerAnimation: - if reaction == null: - return null - var a = PlayerAnimation.new() - a.animation = reaction.animation - a.hp_change = -reaction.hp_change - return a - -func getReaction(motion : Motion) -> Reaction: - if motion is ActionOnOpponent: - return motion.reaction - - return null - -func convertMotion2PlayerAnimation(motion : Motion) -> PlayerAnimation: - var a = PlayerAnimation.new() - a.animation = motion.animation - a.stamina_change = motion.stamina_change - return a - -func convertMotion2Round(lhs : Someone, rhs : Someone, motion : Motion) -> Round: - var round = Round.new() - - round.action = 0 if motion.originator == lhs else 1 - round.animations.append(convertMotion2PlayerAnimation(motion)) - var reaction = getReaction(motion) - round.animations.append(convertReaction2PlayerAnimation(reaction)) - - if reaction is Counter: - round.animations[0].hp_change = -reaction.damage - - return round - -# TODO: breakdown to a simpler transferable class -func convert(lhs : Someone, rhs : Someone, motions : Array[Motion]) -> Array[Round]: - var rounds : Array[Round] = [] - for motion in motions: - rounds.push_back(convertMotion2Round(lhs, rhs, motion)) - - return rounds +class Passive extends Skill: + pass -func _init() -> void: - var player1 : Someone = Someone.new("John") - var player2 : Someone = Someone.new("Joe") +class Stats: + var strength : int + var constituion : int + var agility : int + var chi : int - var motions : Array[Motion] = [ - Attack.new(player1, "Kick", player2, 1.0, Absorb.new(player2, "Hit", 1, 12.0)), - Buff.new(player2, "SSJ"), - Attack.new(player1, "Punch", player2, 2.0, Block.new(player2, "Block", 1.0, true)), - Wait.new(player2, "Wait", 5.0) - ] +class CharacterLineup: + var stats : Stats + var skills : Array[Skill] - var rounds = self.convert(player1, player2, motions) - - for round in rounds: - var activeIndex = round.action - var reactiveIndex = 0 if round.action == 1 else 0 - var orientation = "Left" if round.action == 1 else "Right" - - print("%s Player {'Animation': '%s', 'hp_change': %f, 'stamina_change': %f}" % [orientation, round.animations[0].animation, round.animations[0].hp_change, round.animations[0].stamina_change]) - if round.animations[1] != null: - print("Other Player {'Animation': '%s', 'hp_change': %f, 'stamina_change': %f}" % [round.animations[1].animation, round.animations[1].hp_change, round.animations[1].stamina_change]) - print() +func calculateFight(player1 : CharacterLineup, player2 : CharacterLineup) -> MotionLib.MotionReport: + return MotionLib.MotionReport.new() diff --git a/scenes/Global/FightLib.gd.uid b/scenes/Global/FightLib.gd.uid index 35debab..31ebb58 100644 --- a/scenes/Global/FightLib.gd.uid +++ b/scenes/Global/FightLib.gd.uid @@ -1 +1 @@ -uid://btq7nf3fo58d3 +uid://wkn5qvs3fw82 diff --git a/scenes/Global/MotionLib.gd b/scenes/Global/MotionLib.gd new file mode 100644 index 0000000..7cbd7d7 --- /dev/null +++ b/scenes/Global/MotionLib.gd @@ -0,0 +1,108 @@ +extends Node + + +class Someone extends Object: + var name : String + + func _init(name : String) -> void: + self.name = name + +class Motion extends Object: + var originator : Someone + var animation : String + var stamina_change : float + + func _init(originator : Someone, animation : String, stamina_change : float = 0) -> void: + self.originator = originator + self.animation = animation + self.stamina_change = stamina_change + +class Recover extends Motion: + ''' Animation ''' + pass + +class Reaction extends Motion: + var hp_change : float + + func _init(originator : Someone, animation: String, stamina_costs: float, hp_change : float): + super._init(originator, animation, -stamina_costs) + self.hp_change = hp_change + +class Counter extends Reaction: + var damage : float + + func _init(originator : Someone, animation: String, stamina_costs: float, damage : float): + super._init(originator, animation, -stamina_costs, 0) + self.damage = damage + +class Defense extends Reaction: + var successful : bool + + func _init(originator : Someone, animation: String, stamina_costs: float, hp_change : float): + super._init(originator, animation, -stamina_costs, hp_change) + self.successful = hp_change == 0.0 + +class Block extends Defense: + func _init(originator : Someone, animation : String, stamina_costs: float, hp_change : float): + super._init(originator, animation, stamina_costs, hp_change) + +class Evade extends Defense: + ''' Successfully, evaded? ''' + + func _init(originator : Someone, animation : String, stamina_costs: float, hp_change : float): + super._init(originator, animation, stamina_costs, hp_change) + +class Absorb extends Reaction: + ''' Actually, accept being hit ''' + + func _init(originator : Someone, animation: String, stamina_costs: float, hp_change : float): + super._init(originator, animation, -stamina_costs, hp_change) + + +class Action extends Motion: + pass + +class ActionOnSelf extends Action: + pass + +class Wait extends ActionOnSelf: + func _init(originator : Someone, animation : String, stamina_gain : float): + super._init(originator, animation, stamina_gain) + +class Buff extends ActionOnSelf: + func _init(originator : Someone, animation : String) -> void: + super._init(originator, animation, 1.0) + +class ActionOnOpponent extends Action: + var opponent : Someone + var reaction : Reaction + + func _init(originator : Someone, animation : String, opponent : Someone, stamina_costs : float, reaction : Reaction) -> void: + super._init(originator, animation, -stamina_costs) + self.opponent = opponent + self.reaction = reaction + +class Attack extends ActionOnOpponent: + var damage : float + + func _init(originator : Someone, animation : String, opponent : Someone, stamina_costs : float, reaction : Reaction) -> void: + super._init(originator, animation, opponent, stamina_costs, reaction) + +class Debuff extends ActionOnOpponent: + func _init(originator : Someone, animation : String, opponent : Someone, stamina_costs : float, reaction : Reaction) -> void: + super._init(originator, animation, opponent, stamina_costs, reaction) + +class MotionReport: + var player1 : Someone + var player2 : Someone + var motions : Array[Motion] + + func _init(): + self.player1 = Someone.new("John") + self.player2 = Someone.new("Joe") + self.motions = [ + Attack.new(player1, "Kick", player2, 1.0, Absorb.new(player2, "Hit", 1, 12.0)), + Buff.new(player2, "SSJ"), + Attack.new(player1, "Punch", player2, 2.0, Block.new(player2, "Block", 1.0, true)), + Wait.new(player2, "Wait", 5.0) + ] diff --git a/scenes/Global/MotionLib.gd.uid b/scenes/Global/MotionLib.gd.uid new file mode 100644 index 0000000..35debab --- /dev/null +++ b/scenes/Global/MotionLib.gd.uid @@ -0,0 +1 @@ +uid://btq7nf3fo58d3 diff --git a/scenes/Global/RenderLib.gd b/scenes/Global/RenderLib.gd new file mode 100644 index 0000000..8382611 --- /dev/null +++ b/scenes/Global/RenderLib.gd @@ -0,0 +1,52 @@ +extends Node + +const MotionLib = preload("res://scenes/Global/MotionLib.gd") + +class PlayerAnimation extends Object: + var animation : String + var hp_change : float + var stamina_change : float + +class Round extends Object: + var action: int + var animations : Array[PlayerAnimation] + +class RenderReport: + var rounds: Array[Round] + + func _init(report : MotionLib.MotionReport): + self.rounds = [] + for motion in report.motions: + self.rounds.push_back(self.convertMotion2Round(report.player1, report.player2, motion)) + + func convertReaction2PlayerAnimation(reaction : MotionLib.Reaction) -> PlayerAnimation: + if reaction == null: + return null + var a = PlayerAnimation.new() + a.animation = reaction.animation + a.hp_change = -reaction.hp_change + return a + + func getReaction(motion : MotionLib.Motion) -> MotionLib.Reaction: + if motion is MotionLib.ActionOnOpponent: + return motion.reaction + return null + + func convertMotion2PlayerAnimation(motion : MotionLib.Motion) -> PlayerAnimation: + var a = PlayerAnimation.new() + a.animation = motion.animation + a.stamina_change = motion.stamina_change + return a + + func convertMotion2Round(lhs : MotionLib.Someone, rhs : MotionLib.Someone, motion : MotionLib.Motion) -> Round: + var round = Round.new() + + round.action = 0 if motion.originator == lhs else 1 + round.animations.append(self.convertMotion2PlayerAnimation(motion)) + var reaction = self.getReaction(motion) + round.animations.append(self.convertReaction2PlayerAnimation(reaction)) + + if reaction is MotionLib.Counter: + round.animations[0].hp_change = -reaction.damage + + return round diff --git a/scenes/Global/RenderLib.gd.uid b/scenes/Global/RenderLib.gd.uid new file mode 100644 index 0000000..4860d5a --- /dev/null +++ b/scenes/Global/RenderLib.gd.uid @@ -0,0 +1 @@ +uid://dad5bt8oak0ii diff --git a/scenes/Main/fight_setup.gd b/scenes/Main/fight_setup.gd index 1871d5d..43e4f74 100644 --- a/scenes/Main/fight_setup.gd +++ b/scenes/Main/fight_setup.gd @@ -1,7 +1,23 @@ extends Node2D +const MotionLib = preload("res://scenes/Global/MotionLib.gd") +const RenderLib = preload("res://scenes/Global/RenderLib.gd") const FightLib = preload("res://scenes/Global/FightLib.gd") # Called when the node enters the scene tree for the first time. func _ready(): - FightLib.new() + var player1 = FightLib.CharacterLineup.new() + var player2 = FightLib.CharacterLineup.new() + + var m : MotionLib.MotionReport = FightLib.new().calculateFight(player1, player2) + var r : RenderLib.RenderReport = RenderLib.RenderReport.new(m) + + for round in r.rounds: + var activeIndex = round.action + var reactiveIndex = 0 if round.action == 1 else 0 + var orientation = "Left" if round.action == 1 else "Right" + + print("%s Player {'Animation': '%s', 'hp_change': %f, 'stamina_change': %f}" % [orientation, round.animations[0].animation, round.animations[0].hp_change, round.animations[0].stamina_change]) + if round.animations[1] != null: + print("Other Player {'Animation': '%s', 'hp_change': %f, 'stamina_change': %f}" % [round.animations[1].animation, round.animations[1].hp_change, round.animations[1].stamina_change]) + print() -- 2.30.2