I'm working on a combat system and the last thing I need to polish the structure is the buff and debuffing system, for example, poison effects.
So far it works neatly, except for the fact that if two characters got the same debuff at different turns, the duration will be shared, to explain better:
poison duration = 3 turns
character 1 got poisoned in turn 1
character 2 got poisoned in turn 2
in turn 2, both of them have a shared duration of 2 turns of poison
I figure it's because I'm changing the "remaining turn attribute" of the debuff, and it's not an independ, so my question is if there's a way to have duplicates that can be changed separately, or if there's a better way to manage these.
To avoid walls of code I'll summarize how the basics work. Characters have an attribute, dot, which contains a list with the buffs and debuffs applied to them, and the code below is aiming to them.
Here are the pieces of code regarding this part:
Debuff class
Code: Select all
class DoT(object):
def __init__(self, name, img, desc, turns, damage, heal, prot, type, damagetotal=0, healtotal=0, prottotal=0):
self.name = name
self.img = img
self.desc = desc
self.turns = turns
self.damage = damage
self.heal = heal
self.prot = prot
self.type = type
self.damagetotal = damagetotal
Code: Select all
def DotEffect(self):
global party # Your team
global enemy_list # Enemy team
for member in party:
if member.dot != []:
for item in member.dot:
if item.turns < 0 and item.prot == 0:
member.dot.remove(item)
if item.turns > 0 and item.prot == 0: ## Protection buffs last til the character is hit
item.turns -= 1 ##<------- Here's where I modify the turns
self.healingraw = member.max_hp*item.heal
self.healingdone = int(self.healingraw)
member.addHP(self.healingdone)
self.damageraw = member.max_hp*item.damage
self.damagedone = int(self.damageraw)
member.reduceHP(self.damagedone)
if item.turns == 0 and item.prot == 0:
item.turns -= 1
self.healingraw = member.max_hp*item.heal
self.healingdone = int(self.healingraw)
member.addHP(self.healingdone)
self.damageraw = member.max_hp*item.damage
self.damagedone = int(self.damageraw)
member.reduceHP(self.damagedone)
member.dot.remove(item)