damage.py (5100B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\behaviors\actions\damage.py 2 import logging 3 import math 4 from behaviors.tasks import Task 5 from behaviors.utility.ballparks import get_distance_between 6 from dogma.attributes import health 7 from dogma.const import attributeEmDamage, attributeKineticDamage, attributeThermalDamage, attributeExplosiveDamage 8 logger = logging.getLogger(__name__) 9 10 class SetArmorRatio(Task): 11 12 def OnEnter(self): 13 health.SetArmorRatio(self.context.dogmaLM, self.context.myItemId, self.attributes.armorRatio) 14 self.SetStatusToSuccess() 15 16 17 class SetShieldRatio(Task): 18 19 def OnEnter(self): 20 health.SetShieldRatio(self.context.dogmaLM, self.context.myItemId, self.attributes.shieldRatio) 21 self.SetStatusToSuccess() 22 23 24 class SetStructureRatio(Task): 25 26 def OnEnter(self): 27 health.SetStructureRatio(self.context.dogmaLM, self.context.myItemId, self.attributes.structureRatio) 28 self.SetStatusToSuccess() 29 30 31 class SetArmorRatioForItem(Task): 32 33 def OnEnter(self): 34 itemId = self.GetLastBlackboardValue(self.attributes.itemIdAddress) 35 if itemId: 36 health.SetArmorRatio(self.context.dogmaLM, itemId, self.attributes.armorRatio) 37 self.SetStatusToSuccess() 38 39 40 class SetShieldRatioForItem(Task): 41 42 def OnEnter(self): 43 itemId = self.GetLastBlackboardValue(self.attributes.itemIdAddress) 44 if itemId: 45 health.SetShieldRatio(self.context.dogmaLM, itemId, self.attributes.shieldRatio) 46 self.SetStatusToSuccess() 47 48 49 class SetStructureRatioForItem(Task): 50 51 def OnEnter(self): 52 itemId = self.GetLastBlackboardValue(self.attributes.itemIdAddress) 53 if itemId: 54 health.SetStructureRatio(self.context.dogmaLM, itemId, self.attributes.structureRatio) 55 self.SetStatusToSuccess() 56 57 58 class DealDamageOutsideOfArea(Task): 59 60 def OnEnter(self): 61 self.SetStatusToSuccess() 62 ships_in_bubble = self._get_ships_in_same_bubble() 63 self._deal_damage_to_ships_in_bubble(ships_in_bubble) 64 65 def _get_ships_in_same_bubble(self): 66 return self.context.ballpark.GetShipsInSameBubble(self.context.myItemId) 67 68 def _deal_damage_to_ships_in_bubble(self, ships_in_bubble): 69 ships_within_damage_distance = self._get_ships_within_damage_distance(ships_in_bubble) 70 for ship_id, distance in ships_within_damage_distance: 71 damage_multiplier = self._get_damage_based_on_distance(distance) 72 self._deal_damage_to_ship(ship_id, damage_multiplier) 73 self._show_damage_effect_on_ship(ship_id) 74 75 def _show_damage_effect_on_ship(self, ship_id): 76 self.context.ballpark.specialEffects.StartShipEffect(ship_id, 'effects.DrifterControlled', 5000, 0) 77 78 def _get_ships_within_damage_distance(self, ships_in_bubble): 79 ships_within_damage_distance = [] 80 for ship_id in ships_in_bubble: 81 distance = get_distance_between(self, self.context.myItemId, ship_id) 82 if self.attributes.minDamageDistance < distance: 83 ships_within_damage_distance.append((ship_id, distance)) 84 85 return ships_within_damage_distance 86 87 def _get_damage_based_on_distance(self, distance): 88 distance_from_min = distance - self.attributes.minDamageDistance 89 area_distance = self.attributes.maxDamageDistance - self.attributes.minDamageDistance 90 return math.pow(math.exp(distance_from_min / area_distance), self.attributes.areaDamageFactor) 91 92 def _deal_damage_to_ship(self, ship_id, damage_multiplier): 93 if self.context.ballpark.IsWarping(ship_id): 94 logger.debug('Behavior=%s did not deal area damage to item=%s - possibly still in warp', self.behaviorTree.GetBehaviorId(), ship_id) 95 return 96 damage_amount_by_damage_type = self._get_damage_amount_by_damage_type() 97 sm.GetService('dogma').ApplyDamage(None, self.context.myItemId, ship_id, damageMultiplier=damage_multiplier, indirectDogmaLM=self.context.dogmaLM, weaponDamages=damage_amount_by_damage_type) 98 logger.debug('Behavior=%s dealing area damage to item=%s with damage multiplier=%s and damage by type=%s', self.behaviorTree.GetBehaviorId(), ship_id, damage_multiplier, damage_amount_by_damage_type) 99 100 def _get_damage_amount_by_damage_type(self): 101 return {attributeEmDamage: self.attributes.emDamage, 102 attributeKineticDamage: self.attributes.explosiveDamage, 103 attributeThermalDamage: self.attributes.kineticDamage, 104 attributeExplosiveDamage: self.attributes.thermalDamage} 105 106 107 class DisplayCholesterolField(Task): 108 109 def OnEnter(self): 110 self.SetStatusToSuccess() 111 sm.GetService('machoNet').SinglecastBySolarSystemID(self.context.ballpark.solarsystemID, 'OnCholesterolFieldActivated', self.context.myItemId, self._get_distance()) 112 113 def _get_distance(self): 114 if getattr(self.attributes, 'distanceAddress', None): 115 return self.GetLastBlackboardValue(self.attributes.distanceAddress) 116 else: 117 return self.attributes.defaultDistance