How to implement RPG weapons and magic affects on various types of enemies.

Discussion in 'Programming' started by evildead9000, May 30, 2019.

  1. evildead9000

    evildead9000 Member

    Joined:
    Nov 20, 2017
    Posts:
    62
    I'm in the somewhat early stages of developing a game. I have a decent system for enemy AI as well as various weapons, and magic for the player.

    However, I am not sure how to implement a manageable system for weapon/magic affects on different types of enemies. For example, what is the easiest way to manage the effectiveness of 10 different attacks of magic and weaponry to 10 different types of enemies?

    To clarify: If an ice blast collided with an enemy, I would like to quickly determine the affect on the enemy. Obviously, I don't want to have numerous "if" statements. Is the enemy vulnerable to ice attacks? (-10 HP or so) Or immune (-0 HP)? Or is it slightly effective (-2 HP)?

    I think it may be a combo of ds_maps, and switches, but I'm really lost as to how to begin coding something efficient.

    (I think I butchered the usage of "affect" and "effect" Lol!!)

    I would greatly appreciate some guidance/info on best practices.
     
  2. Rob

    Rob Member

    Joined:
    Jul 12, 2016
    Posts:
    681
    If you have an array for the weapons and the damage/type of damage they do, have a similar array for the enemies that sets how much resistance the enemies have against that particular type of weapon.

    You can then just check which type of weapon is being used when an enemy is hit and work out damage based on that particular entry in its array
     
    evildead9000 and woods like this.
  3. woods

    woods Member

    Joined:
    Jun 21, 2016
    Posts:
    223
    the more involved the system, the more hairy the code gets ;o)

    example:
    enemy stats:
    hp = 100
    armor = 50
    melee resist= 10
    magic resist = 10
    fire resist =10
    ice resist = 0

    weapon attack stats:
    damage = 15
    type_fire = +10%
    type_ice = +0%

    maybe something along these lines...
    psudo code
    Code:
    with (weapon_flame_sword)
    { 
        total dam = (weapon.damage + weapon.type_fire + weapon.type_ice) - (enemy.armor + enemy.melee.resist + enemy.fire_resist))
    }
    
     
    evildead9000 likes this.
  4. evildead9000

    evildead9000 Member

    Joined:
    Nov 20, 2017
    Posts:
    62
    Thank you for the responses. Indeed "the more involved the system, the more hairy the code gets"!!!

    I started implementing your suggestions. I only have 2 weapons at the moment and they are working as planned. However, moving forward, as I add more weapons and magic it will get a bit dicey! :)
     
  5. Rob

    Rob Member

    Joined:
    Jul 12, 2016
    Posts:
    681
    That's why coding and planning using arrays or data structures will benefit you. If you get it right for 2 weapons, it should work for 100.
     
    evildead9000, Ferrettomato and woods like this.
  6. Paskaler

    Paskaler Member

    Joined:
    Jul 4, 2016
    Posts:
    315
    Another way you could implement this is: have the enemies store all their resistance values in an array or ds map. Then make all weapons have a customized script that runs whenever they're supposed to deal damage. So, for example, a "fire sword" type weapon could check in its script resistance to fire and ice and modify how much damage it deals. Bonus, since weapons have their own scripts, you could make the fire sword inflict a "burn" effect to the enemy making it take damage for N number of seconds, or other fun stuff such as this
     
    evildead9000 likes this.
  7. jackquake

    jackquake Member

    Joined:
    Aug 17, 2016
    Posts:
    81
    As mentioned earlier, map this out in a spreadsheet, do significant testing of the model there first. Then put it to code. If not, you will rewrite lots of code to get it right in the end.
     
    evildead9000 likes this.
  8. JackTurbo

    JackTurbo Member

    Joined:
    Oct 19, 2016
    Posts:
    824
    Another approach to dealing damage with effects, elements and resistances is to decouple the attack and the resolving of damage.

    That's something I do in my game. If the player attacks an enemy it passes the attack damage and any element or status effect to the enemy. In the end step event the enemy checks if it has damage waiting to be applied and resolves it checking it's own resistance/weaknesses etc.
     
    woods and evildead9000 like this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice