public void ApplyDamagePermil(int x, int y, int unk1, int team, int unk2, int targetType, int damageType, int unk3, bool healing) { LogicSpellData spellData = this.GetSpellData(); int radius = spellData.GetRadius(this.m_upgradeLevel); int troopDamagePermil = spellData.GetTroopDamagePermil(this.m_upgradeLevel); int buildingDamagePermil = spellData.GetBuildingDamagePermil(this.m_upgradeLevel); int executeHealthPermil = spellData.GetExecuteHealthPermil(this.m_upgradeLevel); int damagePermilMin = spellData.GetDamagePermilMin(this.m_upgradeLevel); int preferredTargetDamageMod = spellData.GetPreferredTargetDamageMod(); int preferredDamagePermilMin = spellData.GetPreferredDamagePermilMin(this.m_upgradeLevel); LogicData preferredTarget = spellData.GetPreferredTarget(); LogicVector2 pushBackPosition = new LogicVector2(); LogicArrayList <LogicComponent> components = this.GetComponentManager().GetComponents(LogicComponentType.HITPOINT); int tmp = troopDamagePermil + 2 * buildingDamagePermil; for (int i = 0; i < components.Size(); i++) { LogicHitpointComponent hitpointComponent = (LogicHitpointComponent)components[i]; LogicGameObject parent = hitpointComponent.GetParent(); if (!parent.IsHidden() && hitpointComponent.GetHitpoints() != 0) { if (hitpointComponent.GetTeam() == team) { if (tmp > 0 || tmp < 0 && parent.IsPreventsHealing()) { continue; } } else if (tmp < 0) { continue; } if (damageType == 2 && parent.GetGameObjectType() != LogicGameObjectType.CHARACTER) { continue; } int parentX; int parentY; LogicMovementComponent movementComponent = parent.GetMovementComponent(); if (movementComponent != null || parent.IsFlying()) { if (parent.IsFlying()) { if (targetType == 1) { continue; } } else if (targetType == 0) { continue; } parentX = parent.GetMidX(); parentY = parent.GetMidY(); } else { int posX = parent.GetX(); int posY = parent.GetY(); parentX = LogicMath.Clamp(x, posX, posX + (parent.GetWidthInTiles() << 9)); parentY = LogicMath.Clamp(y, posY, posY + (parent.GetHeightInTiles() << 9)); } int distanceX = x - parentX; int distanceY = y - parentY; if (LogicMath.Abs(distanceX) <= radius && LogicMath.Abs(distanceY) <= radius && distanceX * distanceX + distanceY * distanceY < (uint)(radius * radius)) { if (damageType == 1 && parent.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)parent; if (building.GetResourceStorageComponentComponent() != null && !building.GetBuildingData().IsTownHall() && !building.GetBuildingData().IsTownHallVillage2()) { parent.SetDamageTime(10); continue; } } if (parent.GetGameObjectType() == LogicGameObjectType.BUILDING || parent.GetGameObjectType() == LogicGameObjectType.CHARACTER) { int dataDamagePermil = parent.GetGameObjectType() == LogicGameObjectType.BUILDING ? buildingDamagePermil : troopDamagePermil; if (dataDamagePermil != 0) { int permil = 10 * hitpointComponent.GetMaxHitpoints() * dataDamagePermil / 10000; if (10 * hitpointComponent.GetMaxHitpoints() * dataDamagePermil <= -10000) { if (parent.IsHero()) { permil = LogicDataTables.GetGlobals().GetHeroHealMultiplier() * permil / 100; } } bool isPreferredTarget = LogicCombatComponent.IsPreferredTarget(preferredTarget, parent); int numberOfHits = spellData.GetNumberOfHits(this.m_upgradeLevel); int completePermil = hitpointComponent.GetDamagePermilCount() / spellData.GetNumberOfHits(this.m_upgradeLevel); int calculateDamage = isPreferredTarget ? permil / (completePermil + 1) + preferredTargetDamageMod * hitpointComponent.GetMaxHitpoints() / (100 * numberOfHits) * completePermil * completePermil : permil / (2 * completePermil + 1); int permilMin = isPreferredTarget ? preferredDamagePermilMin : damagePermilMin; int damage = hitpointComponent.GetMaxHitpoints() * permilMin / 10000; if (calculateDamage >= damage) { damage = calculateDamage; } if (executeHealthPermil > 0 && 1000 * (hitpointComponent.GetHitpoints() - damage) <= executeHealthPermil) { damage = hitpointComponent.GetHitpoints(); } hitpointComponent.CauseDamagePermil(damage); if (healing) { // Listener. } if ((distanceX | distanceX) == 0) { distanceX = 1; } pushBackPosition.m_x = -distanceX; pushBackPosition.m_y = -distanceY; pushBackPosition.Normalize(512); if (unk3 > 0 && movementComponent != null) { movementComponent.GetMovementSystem().PushBack(pushBackPosition, damage, unk3, 0, false, true); } } } } } } }