diff options
author | Jesusaves <cpntb1@ymail.com> | 2021-08-10 23:36:21 -0300 |
---|---|---|
committer | Jesusaves <cpntb1@ymail.com> | 2021-08-10 23:36:21 -0300 |
commit | 217abb0dd2acc08e0f4f3b7c50c458fb5470cd35 (patch) | |
tree | b260b8d42385c92fd17ada57dd29c57cbeea19ea | |
parent | 54a5c6cf49962495786bbc7f9fee880a82773f0c (diff) | |
download | server-217abb0dd2acc08e0f4f3b7c50c458fb5470cd35.tar.gz server-217abb0dd2acc08e0f4f3b7c50c458fb5470cd35.tar.bz2 server-217abb0dd2acc08e0f4f3b7c50c458fb5470cd35.tar.xz server-217abb0dd2acc08e0f4f3b7c50c458fb5470cd35.zip |
Isolate battle action code
-rw-r--r-- | battle/main.py | 39 |
1 files 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) |