From 217abb0dd2acc08e0f4f3b7c50c458fb5470cd35 Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Tue, 10 Aug 2021 23:36:21 -0300 Subject: Isolate battle action code --- battle/main.py | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/battle/main.py b/battle/main.py index d104db8..34123fc 100644 --- a/battle/main.py +++ b/battle/main.py @@ -161,7 +161,28 @@ def begin_quest(args, token, client_side=True): return sjson +# Action +def _action(token, bat, bt, spheres): + global Battle + + # Will they use a sphere? + idx=Battle[token]["party"].index(bat) + stdout("Check index %d" % idx, 2) + if (bt["sphere"][idx] == ACT_SPHERE): + # Remove the sphere + spheres[idx]=SPH_NONE + sphere_attack(token, bat, Battle[token]["spheres"][idx], idx) + Battle[token]["bp"]+=2 + else: + sphere_attack(token, bat, SPH_NONE, idx) + Battle[token]["bp"]+=1 + stdout("Attack performed", 2) + + # If HP ends up broken + if (bat["hp"] > bat["max_hp"]): + bat["hp"]=0+bat["max_hp"] + return # Advance turn button. Main turn logic # Receives a list of units position, and if they'll use sphere: # { "unit": [uid1, uid2 ....], "sphere": [True/False array, in future will save skill as 2] } @@ -248,22 +269,8 @@ def battle(args, token): if (bat["hp"] <= 0): continue - # Will you use a sphere? - idx=Battle[token]["party"].index(bat) - stdout("Check index %d" % idx, 2) - if (bt["sphere"][idx] == ACT_SPHERE): - # Remove the sphere - spheres[idx]=SPH_NONE - sphere_attack(token, bat, Battle[token]["spheres"][idx], idx) - Battle[token]["bp"]+=2 - else: - sphere_attack(token, bat, SPH_NONE, idx) - Battle[token]["bp"]+=1 - stdout("Attack performed", 2) - - # If HP ends up broken - if (bat["hp"] > bat["max_hp"]): - bat["hp"]=0+bat["max_hp"] + # Execute whatever + _action(token, bat, bt, spheres) # HOLD THAT! Handle victory/defeat conditions check = conditions(token, spheres) -- cgit v1.2.3-70-g09d2