Attack subroutine

I wrote subroutines for attacking and defending.
Please poke holes in them. :smile:

*label attack_roll

*temp str_mod 0
*temp dam_roll 0
*temp dodge_roll 0
*temp weapon_roll 0
*temp attack_roll 0
*temp d6a 0
*temp d6b 0
*temp d6c 0
*temp d4a 0
*temp d4b 0
*temp d4c 0

*rand d6a 1 6
*rand d6b 1 6
*rand d6c 1 6
*rand d4a 1 4
*rand d4b 1 4
*rand d4c 1 4

*set attack_roll (((d6a + d6b + d6c) * 2) + round(attack_skill / 2) + attack_bonus)
*set enemy_dodge_roll ((((d4a + d4b + d4c) * 2) + 3) + enemy_dodge)
*if attack_roll > enemy_dodge_roll
    *set attack_hit true
    *set hit_count +1
*else 
    *set attack_hit false
    *return

*if attack_weapon none
    *rand weapon_roll 2 5
*if attack_weapon dagger
    *rand weapon_roll 2 5
*if attack_weapon rapier
    *rand weapon_roll 2 7
*if attack_weapon sword
    *rand weapon_roll 2 7
*if attack_weapon axe
    *rand weapon_roll 2 7
*if attack_weapon greatsword 
    *rand weapon_roll 4 9
*if attack_weapon greataxe
    *rand weapon_roll 4 9
*if attack_weapon shortbow
    *rand weapon_roll 2 5
*if attack_weapon longbow
    *rand weapon_roll 2 7

*set str_mod round(strength / 2)
*set dam_roll (weapon_roll + str_mod + damage_bonus)
*set attack_damage (dam_roll - enemy_armour)
*if attack_damage < 0
    *set attack_damage 0
*set damage_done + attack_damage

*if current_enemy_nr 1
    *set enemy_1_hp - attack_damage
*if current_enemy_nr 2
    *set enemy_2_hp - attack_damage
*if current_enemy_nr 3
    *set enemy_3_hp - attack_damage
*if current_enemy_nr 4
    *set enemy_4_hp - attack_damage
*if current_enemy_nr 5
    *set enemy_5_hp - attack_damage
*return

*label dodge_roll

*temp dodge_roll 0
*temp end_mod 0
*temp dam_roll 0
*temp weapon_roll 0
*temp attack_roll 0
*temp d6a 0
*temp d6b 0
*temp d6c 0
*temp d4a 0
*temp d4b 0
*temp d4c 0

*rand d6a 1 6
*rand d6b 1 6
*rand d6c 1 6
*rand d4a 1 4
*rand d4b 1 4
*rand d4c 1 4

*set attack_roll (((d6a + d6b + d6c) * 2) + enemy_attack)
*set dodge_roll ((((d4a + d4b + d4c) * 2) + 3) + round(dodge / 2))
*if attack_roll > dodge_roll
    *set attack_hit true
*else 
    *set attack_hit false
    *return

*set end_mod round(endurance / 3)

*set dam_roll enemy_damage
*set attack_damage (dam_roll - armour_rating - end_mod)
*if attack_damage < 0
    *set attack_damage 0
*set damage_taken + attack_damage
*set current_health - attack_damage
*return
2 Likes

It seems very math heavy. It might fit well in a game that focuses overtly on stats, but for games that focus on plots and characters more, this might be a bit too much to work with.

1 Like

Yes, it’s for a game that’s supposed to feel like playing pen and paper, or an oldschool rpg. :smile:

I wrote one similar years ago but in a story, heavy didn’t go well with the flow of the story I have a loop system that introduces story vignettes when you or enemy reaching certain heal levels or you do a certain critic or you are out I mana still make a combat in a story and not look bizarre is very difficult

Any reason why the variables are temp instead of created? Considering it’s for a pen and paper type game and how heavy it is, it seems like you would be using it for all the chapters.

I use temp too because is a gosub_scene that is same for all the story that way you gain a lot of code efficiency. and temp you can have all those variables in the scene so they are easier to track than in the startup at least for me

All the variables that might get used elsewhere are created. I just didn’t copy-paste that part. :blush:

As Mara says, it’s a subroutine, so they only have to be written this once.
I also especially want the dice to be temporary to the specific scene, to minimize mishaps.

2 Likes

tell me before the gosub_scene command the random scenes were a pain in the as to implement. When I started try to make dices to play tabletop was a mess lol. Now is far easier.

Alright, so I tried testing it out, and it looks like the program doesn’t like the way your parenthesis are positioned. I was able to circumvent this and get the code to read through it by adding an extra set so it looks like this: *set attack_roll (((d6a + d6b) + d6c) * 2) + (round(attack_skill / 2) + attack_bonus)
and this: *set enemy_dodge_roll (((((d4a + d4b) + d4c) * 2) + 3) + enemy_dodge)

I don’t know if you had problems with this particular portion when you tested it, that’s just what I could find after copy-pasting it.

1 Like

I really like this, have you thought about adding certain benefits to particular weapons when fighting against an enemy. For example, maybe if your enemy has a dagger and you have a long ranged weapon like a spear it could give you a bonus, or perhaps you always attack first if you have a lighter weapon or can attack more frequently than your opponent or vice versa. Perhaps using a bow against a sword user gives you a negative to defense since you can’t parry as easily. Maybe instead of a random dodge role, it is affected by the weapon you are using. Just a thought.

A question, if I may.

So what did damage_done do?