Added conversion from object oriented fight to array-of-rounds
							parent
							
								
									0c84f5fb29
								
							
						
					
					
						commit
						22e2ecd4c9
					
				| @ -1,78 +1,165 @@ | |||||||
| extends Node | extends Node | ||||||
| 
 | 
 | ||||||
| class Motion: | class Someone extends Object: | ||||||
| 	pass | 	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: | class Recover extends Motion: | ||||||
| 	''' Animation ''' | 	''' Animation ''' | ||||||
| 	pass | 	pass | ||||||
| 
 | 
 | ||||||
| class Action extends Motion: | class Reaction extends Motion: | ||||||
| 	pass | 	var hp_change : float | ||||||
| 
 | 
 | ||||||
| class ActionOnSelf extends Action: | 	func _init(originator : Someone, animation: String, stamina_costs: float, hp_change : float): | ||||||
| 	pass | 		super._init(originator, animation, -stamina_costs) | ||||||
|  | 		self.hp_change = hp_change | ||||||
| 
 | 
 | ||||||
| class Wait extends ActionOnSelf: | class Counter extends Reaction: | ||||||
| 	''' Animation ''' | 	var damage : float | ||||||
| 	pass |  | ||||||
| 
 | 
 | ||||||
| class Buff extends ActionOnSelf: | 	func _init(originator : Someone, animation: String, stamina_costs: float, damage : float): | ||||||
| 	''' Animation ''' | 		super._init(originator, animation, -stamina_costs, 0) | ||||||
| 	pass | 		self.damage = damage | ||||||
| 
 | 
 | ||||||
| class ActionOnOpponent extends Action: | class Defense extends Reaction: | ||||||
| 	pass | 	var successful : bool | ||||||
| 
 | 
 | ||||||
| class Attack extends ActionOnOpponent: | 	func _init(originator : Someone, animation: String, stamina_costs: float, hp_change : float): | ||||||
| 	''' Animation ''' | 		super._init(originator, animation, -stamina_costs, hp_change) | ||||||
| 	func get_damage() -> int: | 		self.successful = hp_change == 0.0 | ||||||
| 		return 0 |  | ||||||
| 
 | 
 | ||||||
| class Debuff extends ActionOnOpponent: | class Block extends Defense: | ||||||
| 	''' Animation ''' | 	func _init(originator : Someone, animation : String, stamina_costs: float, hp_change : float): | ||||||
| 	pass | 		super._init(originator, animation, stamina_costs, hp_change) | ||||||
| 
 | 
 | ||||||
| class Reaction extends Motion: | class Evade extends Defense: | ||||||
| 	pass | 	''' 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: | class Absorb extends Reaction: | ||||||
| 	''' Animation ''' | 	''' Actually, accept being hit ''' | ||||||
| 	pass | 		 | ||||||
|  | 	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: | class Action extends Motion: | ||||||
| 	''' Animation ''' |  | ||||||
| 	pass | 	pass | ||||||
| 
 | 
 | ||||||
| class Evade extends Defense: | class ActionOnSelf extends Action: | ||||||
| 	''' Animation ''' |  | ||||||
| 	pass | 	pass | ||||||
| 
 | 
 | ||||||
| class Round: | class Wait extends ActionOnSelf: | ||||||
| 	pass | 	func _init(originator : Someone, animation : String, stamina_gain : float): | ||||||
|  | 		super._init(originator, animation, stamina_gain) | ||||||
| 
 | 
 | ||||||
| var actions = ["Attack", "Block", "Evade"] | class Buff extends ActionOnSelf: | ||||||
| 
 | 	func _init(originator : Someone, animation : String) -> void: | ||||||
| var rounds : Array[Round] = [ | 		super._init(originator, animation, 1.0) | ||||||
| 	Round.new(), | 
 | ||||||
| 	Round.new(), | class ActionOnOpponent extends Action: | ||||||
| 	Round.new(), | 	var opponent : Someone | ||||||
| 	Round.new(), | 	var reaction : Reaction | ||||||
| 	Round.new(), | 
 | ||||||
| 	Round.new(), | 	func _init(originator : Someone, animation : String, opponent : Someone, stamina_costs : float, reaction : Reaction) -> void: | ||||||
| 	Round.new(), | 		super._init(originator, animation, -stamina_costs) | ||||||
| 	Round.new(), | 		self.opponent = opponent | ||||||
| 	Round.new(), | 		self.reaction = reaction | ||||||
| 	Round.new(), | 
 | ||||||
| 	Round.new(), | class Attack extends ActionOnOpponent: | ||||||
| 	Round.new(), | 	var damage : float | ||||||
| 	Round.new(), | 	 | ||||||
| 	Round.new(), | 	func _init(originator : Someone, animation : String, opponent : Someone, stamina_costs : float, reaction : Reaction) -> void: | ||||||
| 	Round.new(), | 		super._init(originator, animation, opponent, stamina_costs, reaction) | ||||||
| 	Round.new(), | 
 | ||||||
| 	Round.new(), | 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() | ||||||
|  | |||||||
| @ -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") | ||||||
| @ -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() | ||||||
| @ -0,0 +1 @@ | |||||||
|  | uid://bwchifcb7bh05 | ||||||
					Loading…
					
					
				
		Reference in New Issue