Пример #1
0
    def test_sub_with_damage(self):
        """ __sub__ works by adding the phys/magic damage and removing the other from it"""
        dmg_1 = Damage(phys_dmg=5, magic_dmg=5)
        dmg_2 = Damage(phys_dmg=2, magic_dmg=2)
        expected_result = (5 + 5) - (2 + 2)

        self.assertEqual(dmg_1 - dmg_2, expected_result)
Пример #2
0
    def test_iadd_damage(self):
        dmg_1 = Damage(phys_dmg=10, magic_dmg=10)
        dmg_2 = Damage(phys_dmg=5, magic_dmg=6)
        expected_result = Damage(phys_dmg=15, magic_dmg=16)

        dmg_1 += dmg_2
        self.assertEqual(dmg_1, expected_result)
Пример #3
0
    def test_isub_tuple(self):
        dmg_1 = Damage(phys_dmg=10, magic_dmg=10)
        dmg_2 = (5, 5)
        expected_result = Damage(phys_dmg=5, magic_dmg=5)

        dmg_1 -= dmg_2
        self.assertEqual(dmg_1, expected_result)
Пример #4
0
    def test_str_only_phys_dmg_with_absorbed(self):
        expected_phys = 10.10
        expected_absorbed = 10
        dmg = Damage(phys_dmg=10.111)
        dmg.phys_absorbed = expected_absorbed
        expected_str = f'{expected_phys:.2f} physical damage ({expected_absorbed:.2f} absorbed)'

        self.assertEqual(str(dmg), expected_str)
Пример #5
0
    def test_str_only_mag_dmg_with_absorbed(self):
        expected_magic = 10.10
        expected_absorbed = 10
        dmg = Damage(magic_dmg=10.111)
        dmg.magic_absorbed = expected_absorbed
        expected_str = f'{expected_magic:.2f} magical damage ({expected_absorbed:.2f} absorbed)'

        self.assertEqual(str(dmg), expected_str)
Пример #6
0
    def test_str_with_magic_dmg_phys_absorbed(self):
        expected_magic = 10.2
        expected_phys_absorbed = 5.5
        dmg = Damage(magic_dmg=10.199)
        dmg.phys_absorbed = expected_phys_absorbed
        expected_str = f'0.00 physical damage ({expected_phys_absorbed:.2f} absorbed) and {expected_magic:.2f} magical damage'

        self.assertEqual(str(dmg), expected_str)
Пример #7
0
    def test_str_only_phys_dmg_with_absorbed(self):
        expected_phys = 10.10
        expected_absorbed = 10
        dmg = Damage(phys_dmg=10.111)
        dmg.phys_absorbed = expected_absorbed
        expected_str = f'{expected_phys:.2f} physical damage ({expected_absorbed:.2f} absorbed)'

        self.assertEqual(str(dmg), expected_str)
Пример #8
0
    def test_str_only_mag_dmg_with_absorbed(self):
        expected_magic = 10.10
        expected_absorbed = 10
        dmg = Damage(magic_dmg=10.111)
        dmg.magic_absorbed = expected_absorbed
        expected_str = f'{expected_magic:.2f} magical damage ({expected_absorbed:.2f} absorbed)'

        self.assertEqual(str(dmg), expected_str)
Пример #9
0
    def test_str_with_magic_dmg_phys_absorbed(self):
        expected_magic = 10.2
        expected_phys_absorbed = 5.5
        dmg = Damage(magic_dmg=10.199)
        dmg.phys_absorbed = expected_phys_absorbed
        expected_str = f'0.00 physical damage ({expected_phys_absorbed:.2f} absorbed) and {expected_magic:.2f} magical damage'

        self.assertEqual(str(dmg), expected_str)
Пример #10
0
	def respons(self,other):
		self.unit.causeDamage(other.no,Damage.MAGIC_DAMAGE(),15)
		for pair in other.LastSortList:
			if pair.value <= 3+pair.key.radiu:
				if not  self.unit.manager.getUnit(pair.key.id)==None and not self.unit.manager.getUnit(pair.key.id).ownerid == self.unit.ownerid:
					self.unit.causeDamage(pair.key.id,Damage.MAGIC_DAMAGE(),15)
			else:
				break
Пример #11
0
    def test_str_with_phys_and_magic_phys_absorb(self):
        expected_phys = 10.2
        expected_magic = 10.10
        expected_phys_absorbed = 5.5
        dmg = Damage(phys_dmg=10.199, magic_dmg=10.111)
        dmg.phys_absorbed = expected_phys_absorbed
        expected_str = f'{expected_phys:.2f} physical damage ({expected_phys_absorbed:.2f} absorbed) and {expected_magic:.2f} magical damage'

        self.assertEqual(str(dmg), expected_str)
Пример #12
0
    def test_str_with_phys_dmg_magic_absorbed(self):
        expected_phys = 10.2
        expected_magic = 0
        expected_magic_absorbed = 5.5
        dmg = Damage(phys_dmg=10.199)
        dmg.magic_absorbed = expected_magic_absorbed
        expected_str = f'{expected_phys:.2f} physical damage and {expected_magic:.2f} magical damage ({expected_magic_absorbed:.2f} absorbed)'

        self.assertEqual(str(dmg), expected_str)
Пример #13
0
    def test_str_with_phys_and_magic_phys_absorb(self):
        expected_phys = 10.2
        expected_magic = 10.10
        expected_phys_absorbed = 5.5
        dmg = Damage(phys_dmg=10.199, magic_dmg=10.111)
        dmg.phys_absorbed = expected_phys_absorbed
        expected_str = f'{expected_phys:.2f} physical damage ({expected_phys_absorbed:.2f} absorbed) and {expected_magic:.2f} magical damage'

        self.assertEqual(str(dmg), expected_str)
Пример #14
0
    def test_str_with_phys_dmg_magic_absorbed(self):
        expected_phys = 10.2
        expected_magic = 0
        expected_magic_absorbed = 5.5
        dmg = Damage(phys_dmg=10.199)
        dmg.magic_absorbed = expected_magic_absorbed
        expected_str = f'{expected_phys:.2f} physical damage and {expected_magic:.2f} magical damage ({expected_magic_absorbed:.2f} absorbed)'

        self.assertEqual(str(dmg), expected_str)
Пример #15
0
    def test_isub_negative_damage(self):
        """ It should reset the damage to 0, rather than making it negative"""
        dmg_1 = Damage(phys_dmg=10, magic_dmg=10)
        dmg_2 = Damage(phys_dmg=15, magic_dmg=117)
        expected_result = Damage(phys_dmg=0, magic_dmg=0)

        dmg_1 -= dmg_2

        self.assertEqual(dmg_1, expected_result)
Пример #16
0
    def test_str_with_absorbed_only(self):
        expected_magic_absorbed = 5.5
        expected_phys_absorbed = 5.4
        dmg = Damage()
        dmg.magic_absorbed = expected_magic_absorbed
        dmg.phys_absorbed = expected_phys_absorbed

        expected_str = f'0.00 physical damage ({expected_phys_absorbed:.2f} absorbed) and 0.00 magical damage ({expected_magic_absorbed:.2f} absorbed)'

        self.assertEqual(str(dmg), expected_str)
Пример #17
0
    def test_str_with_absorbed_only(self):
        expected_magic_absorbed = 5.5
        expected_phys_absorbed = 5.4
        dmg = Damage()
        dmg.magic_absorbed = expected_magic_absorbed
        dmg.phys_absorbed = expected_phys_absorbed

        expected_str = f'0.00 physical damage ({expected_phys_absorbed:.2f} absorbed) and 0.00 magical damage ({expected_magic_absorbed:.2f} absorbed)'

        self.assertEqual(str(dmg), expected_str)
Пример #18
0
 def test_eq(self):
     """ Two Damage classes should be equal if their magic/phys dmg and absorbed are equal"""
     dmg_1 = Damage(1, 1)
     dmg_2 = Damage(1, 1)
     self.assertEqual(dmg_1, dmg_2)
     dmg_1.phys_absorbed += 0.1
     self.assertNotEqual(dmg_1, dmg_2)
     dmg_1.phys_absorbed = dmg_2.phys_absorbed
     self.assertEqual(dmg_1, dmg_2)
     dmg_1.magic_dmg += 1
     self.assertNotEqual(dmg_1, dmg_2)
Пример #19
0
 def test_eq(self):
     """ Two Damage classes should be equal if their magic/phys dmg and absorbed are equal"""
     dmg_1 = Damage(1, 1)
     dmg_2 = Damage(1, 1)
     self.assertEqual(dmg_1, dmg_2)
     dmg_1.phys_absorbed += 0.1
     self.assertNotEqual(dmg_1, dmg_2)
     dmg_1.phys_absorbed = dmg_2.phys_absorbed
     self.assertEqual(dmg_1, dmg_2)
     dmg_1.magic_dmg += 1
     self.assertNotEqual(dmg_1, dmg_2)
Пример #20
0
    def test_handle_absorption(self):
        """ The handle_absorption function subtracts the absorbed damage from the damage.
            Magical damage always gets absorbed first """
        absorption_shield = 5
        dmg = Damage(phys_dmg=10, magic_dmg=6)
        dmg.handle_absorption(absorption_shield)

        expected_dmg = Damage(phys_dmg=10, magic_dmg=1)
        expected_dmg.magic_absorbed = 5

        self.assertEqual(dmg, expected_dmg)
Пример #21
0
    def test_handle_absorption_bigger_than_both_dmg(self):
        absorption_shield = 17
        dmg = Damage(phys_dmg=10, magic_dmg=6)
        left_shield = dmg.handle_absorption(absorption_shield)

        expected_dmg = Damage(phys_dmg=0, magic_dmg=0)
        expected_dmg.magic_absorbed = 6
        expected_dmg.phys_absorbed = 10
        expected_shield = 1

        self.assertEqual(dmg, expected_dmg)
        self.assertEqual(left_shield, expected_shield)
Пример #22
0
 def redetonate(self, time):
     self.creater.causeDamage(self.unit.no, Damage.MAGIC_DAMAGE(), 20)
     for pair in self.unit.LastSortList:
         if pair.value <= self.range + pair.key.radiu:
             traget = self.unit.manager.getUnit(pair.key.id)
             if not traget == None and not traget.ownerid == self.creater.ownerid and not traget == self.unit:
                 self.creater.causeDamage(traget.no, Damage.MAGIC_DAMAGE(),
                                          20)
                 distant = (traget.circle.center -
                            self.unit.circle.center).normalized
                 traget.repel.begin(distant, 0.2, None, None)
         else:
             break
     print("_______redetonate")
     self.timeLeft = time
Пример #23
0
    def _apply_damage_absorption(self, damage: Damage, to_print=False) -> Damage:
        """
        This method subtracts the absorption (if any) from the damage
        :param to_print: A boolean indicating if we want to actually subtract the damage from the shield. If it's true,
        we're getting the damage for the sole reason to print it only, therefore we should not modify anything
        :return Damage
        """

        if self.absorption_shield:  # if there is anything to absorb
            # lowers the damage and returns our shield
            if not to_print:  # we want to modify the shield
                self.absorption_shield = damage.handle_absorption(self.absorption_shield)
            else:
                damage.handle_absorption(self.absorption_shield) # only modify the specific damage in order to print it

        return damage
Пример #24
0
    def test_str_with_phys_and_magic_dmg(self):
        expected_phys = 10.2
        expected_magic = 10.10
        dmg = Damage(phys_dmg=10.199, magic_dmg=10.111)
        expected_str = f'{expected_phys:.2f} physical damage and {expected_magic:.2f} magical damage'

        self.assertEqual(str(dmg), expected_str)
Пример #25
0
	def __init__(self,radiu,unit,index):
		super().__init__(radiu,unit,index)
		self.coolDown=1.0#技能冷却时间
		self.cdLeft=1.0#当前技能的剩余冷却时间
		self.damageKind=Damage.NORMAL_DAMAGE()
		self.damageNum=10
		self.timeBefore=0.2
Пример #26
0
	def __init__(self,radiu,unit,index):
		super().__init__(radiu,unit,index)
		self.coolDown=1.0#技能冷却时间
		self.cdLeft=1.0#当前技能的剩余冷却时间
		self.damageKind=Damage.PENETRATION_DAMAGE()
		self.damageNum=10
		self.missileSpeed=10
Пример #27
0
	def trigger(self,damage):
			#print("in role{0} skill trigger:::::::::::::::::::::::::{0}".format(self.unit.no))
			if damage.kind==Damage.MAGIC_DAMAGE():
				if random.randint(1,100)<=65:#50%几率
					#print("is magic damage")
					self.unit.events.append(Event(self.unit.manager.useSkill,[self.index,self.unit.no]))
					damage.exist=False#无效
Пример #28
0
    def setUp(self):
        self.name = 'Audi'
        self.damage_tick = Damage(phys_dmg=3)
        self.duration = 5
        self.caster_level = 10

        self.dot_dummy = DoT(self.name, self.damage_tick, self.duration,
                             self.caster_level)
Пример #29
0
    def get_auto_attack_damage(self, target_level: int):
        # get the base auto attack damage
        damage_to_deal = random.randint(self.min_damage, self.max_damage)
        # factor in the level difference
        damage_to_deal = self._calculate_level_difference_damage(
            damage_to_deal, target_level)

        return Damage(phys_dmg=damage_to_deal)
Пример #30
0
 def update(self, time):
     self.timeLeft -= time
     self.actionTime -= time
     if self.actionTime <= 0:
         self.creater.causeDamage(self.unit.no, Damage.MAGIC_DAMAGE(), 3)
         self.actionTime = 1
     if self.timeLeft <= 0:
         self.unit.deleteBuff(self)
Пример #31
0
    def test_handle_absorption_bigger_than_magic(self):
        absorption_shield = 7
        dmg = Damage(phys_dmg=10, magic_dmg=6)
        dmg.handle_absorption(absorption_shield)

        expected_dmg = Damage(phys_dmg=9, magic_dmg=0)
        expected_dmg.magic_absorbed = 6
        expected_dmg.phys_absorbed = 1

        self.assertEqual(dmg, expected_dmg)
Пример #32
0
 def update(self, time):
     if not self.timing:
         inside = self.manager.space.castRadiuCircle(
             self.center, self.radiu)
         if len(inside) > 0:
             self.timing = True
             self.time = 0.4
             self.manager.createEffection(
                 [19, (self.center.x, self.center.y)])
     if self.timing:
         self.time -= time
         if self.time <= 0:
             tragets = self.manager.space.castCircle(
                 self.center, self.exp_radiu)
             for pair in tragets:
                 unit = self.manager.getUnit(pair.key.id)
                 newd = Damage(Damage.REAL_DAMAGE(), 20, None)
                 unit.takeDamage(newd)
             self.delSelf()
Пример #33
0
    def test_init(self):
        dmg = Damage(phys_dmg=1.34, magic_dmg=1.49391)
        expected_phys_dmg = 1.3
        expected_m_dmg = 1.5
        expected_absorbed = 0

        # it should round the magic/phys dmg to 1 point after the decimal
        self.assertEqual(dmg.phys_dmg, expected_phys_dmg)
        self.assertEqual(dmg.magic_dmg, expected_m_dmg)
        self.assertEqual(dmg.phys_absorbed, expected_absorbed)
        self.assertEqual(dmg.magic_absorbed, expected_absorbed)
Пример #34
0
    def convert_to_dot_object(self, caster_lvl) -> DoT:
        """
        Convert the Dot schema object to a DoT object
        """
        dot_name: str = self.name
        dot_damage_per_tick: int = self.damage_per_tick
        dot_damage_school: str = self.damage_school
        dot_duration: int = self.duration

        if dot_damage_school == "magic":
            dot_damage: Damage = Damage(magic_dmg=dot_damage_per_tick)
        elif dot_damage_school == "physical":
            dot_damage: Damage = Damage(phys_dmg=dot_damage_per_tick)
        else:
            raise Exception('Unsupported Damage type!')

        return DoT(name=dot_name,
                   damage_tick=dot_damage,
                   duration=dot_duration,
                   caster_lvl=caster_lvl)
Пример #35
0
	def respons(self,null):
		for pair in self.unit.LastSortList:
			if (not self.unit.manager.getUnit(pair.key.id).ownerid==self.unit.ownerid)and  pair.value <= self.range +pair.key.radiu:
				traget=self.unit.manager.getUnit(pair.key.id)
				#print("in skill no2 self id{0} traget id{1} dir{2}".format(self.unit.no,traget.no,self.unit.direct))
				#v1=self.unit.direct
				#v2=traget.circle.center-self.unit.circle.center
				#print("v1*v2:{0} m1*m2:{1} ans:{2}".format(v1*v2,v1.magnitude*v2.magnitude,(v1*v2)/(v1.magnitude*v2.magnitude)))
				if not traget==None and Vector2.angleBetween(self.unit.direct,traget.circle.center-self.unit.circle.center)<=math.pi*0.5:
					self.unit.causeDamage(traget.no,Damage.MAGIC_DAMAGE(),16)
					self.unit.AfterSkillTo(self,traget.no)
Пример #36
0
 def setUp(self):
     """
     Test that the values in the Schema are as expected
     And that the convert_to_paladin_spell_object function works
     """
     self.spell_entry = 4
     self.spell_name = 'Melting Strike'
     self.dot = DoT(name='Melting', damage_tick=Damage(magic_dmg=2), duration=2, caster_lvl=0)
     self.expected_spell = PaladinSpell(name=self.spell_name, rank=1, damage1=3, damage2=0, damage3=0,
                                        heal1=0, heal2=0, heal3=0, mana_cost=6, cooldown=3,
                                        beneficial_effect=None, harmful_effect=self.dot)
Пример #37
0
    def _apply_damage_absorption(self,
                                 damage: Damage,
                                 to_print=False) -> Damage:
        """
        This method subtracts the absorption (if any) from the damage
        :param to_print: A boolean indicating if we want to actually subtract the damage from the shield. If it's true,
        we're getting the damage for the sole reason to print it only, therefore we should not modify anything
        :return Damage
        """

        if self.absorption_shield:  # if there is anything to absorb
            # lowers the damage and returns our shield
            if not to_print:  # we want to modify the shield
                self.absorption_shield = damage.handle_absorption(
                    self.absorption_shield)
            else:
                damage.handle_absorption(
                    self.absorption_shield
                )  # only modify the specific damage in order to print it

        return damage
Пример #38
0
    def test_handle_absorption(self):
        """ The handle_absorption function subtracts the absorbed damage from the damage.
            Magical damage always gets absorbed first """
        absorption_shield = 5
        dmg = Damage(phys_dmg=10, magic_dmg=6)
        dmg.handle_absorption(absorption_shield)

        expected_dmg = Damage(phys_dmg=10, magic_dmg=1)
        expected_dmg.magic_absorbed = 5

        self.assertEqual(dmg, expected_dmg)
Пример #39
0
	def __init__(self,radiu,unit,index):
		#客制化属性
		self.coolDown=1.5#技能冷却时间
		self.cdLeft=1.5#当前技能的剩余冷却时间
		self.damageKind=Damage.MAGIC_DAMAGE()
		self.damageNum=10
		self.missileSpeed=5
		#固有代码
		self.kind=Skill.ACTIVE()
		self.attack=True#是否是角色的基本攻击
		self.range=unit.AI.FAR_RANGE(radiu)#攻击范围
		self.unit=unit
		self.index=index#技能在角色身上的欄位索引
Пример #40
0
	def __init__(self,radiu,unit,index):
		#子类别客制化属性
		self.coolDown=1.0#技能冷却时间
		self.cdLeft=1.0#当前技能的剩余冷却时间
		self.damageKind=Damage.NORMAL_DAMAGE()
		self.damageNum=10
		self.timeBefore=0.2
		#固有代码
		self.kind=Skill.ACTIVE()
		self.attack=True#是否是角色的基本攻击
		self.range=unit.AI.NEAR_RANGE(radiu)#攻击范围
		self.unit=unit
		self.index=index#技能在角色身上的欄位索引
Пример #41
0
    def test_handle_absorption_bigger_than_magic(self):
        absorption_shield = 7
        dmg = Damage(phys_dmg=10, magic_dmg=6)
        dmg.handle_absorption(absorption_shield)

        expected_dmg = Damage(phys_dmg=9, magic_dmg=0)
        expected_dmg.magic_absorbed = 6
        expected_dmg.phys_absorbed = 1

        self.assertEqual(dmg, expected_dmg)