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); } } } } } } }
public void UpdatePenetrating(int damageMultiplier) { LogicVector2 pos1 = new LogicVector2((this.m_targetPosition.m_x >> 3) - this.m_unk248.m_x, (this.m_targetPosition.m_y >> 3) - this.m_unk248.m_y); pos1.Normalize(512); LogicVector2 pos2 = new LogicVector2(-pos1.m_y, pos1.m_x); int distance = ((200 - this.m_areaShieldDelay) * (8 * this.GetSpeed() - 8 * this.m_areaShieldSpeed) / 200 + 8 * this.m_areaShieldSpeed) >> 3; LogicArrayList <LogicComponent> components = this.GetComponentManager().GetComponents(LogicComponentType.MOVEMENT); for (int i = 0, damage = damageMultiplier * this.m_damage / 100; i < components.Size(); i++) { LogicMovementComponent component = (LogicMovementComponent)components[i]; LogicGameObject parent = component.GetParent(); LogicHitpointComponent hitpointComponent = parent.GetHitpointComponent(); if (!parent.IsHidden() && hitpointComponent.GetTeam() != this.m_myTeam && hitpointComponent.GetHitpoints() > 0) { int distanceX = parent.GetMidX() - this.GetMidX(); int distanceY = parent.GetMidY() - this.GetMidY(); if (parent.GetGameObjectType() == LogicGameObjectType.CHARACTER) { distanceX += parent.GetWidthInTiles() << 8; distanceY += parent.GetHeightInTiles() << 8; } if ((!component.IsFlying() || this.m_flyingTarget) && LogicMath.Abs(distanceX) <= this.m_penetratingRadius && LogicMath.Abs(distanceY) <= this.m_penetratingRadius && distanceX * distanceX + distanceY * distanceY <= (uint)(this.m_penetratingRadius * this.m_penetratingRadius)) { LogicVector2 position = new LogicVector2(); if (parent.GetGameObjectType() == LogicGameObjectType.CHARACTER && hitpointComponent.GetMaxHitpoints() <= damage) { int rnd = (byte)this.Rand(parent.GetGlobalID()); if (rnd > 170u) { position.Set((pos1.m_x >> 2) + pos2.m_x, (pos1.m_y >> 2) + pos2.m_y); } else { if (rnd > 85) { position.Set(pos1.m_x, pos1.m_y); } else { position.Set((pos1.m_x >> 2) - pos2.m_x, (pos1.m_y >> 2) - pos2.m_y); } } if (hitpointComponent.GetInvulnerabilityTime() <= 0) { ((LogicCharacter)parent).Eject(position); } position.Destruct(); } else { position.Set(pos1.m_x, pos1.m_y); position.Normalize(distance); if (parent.GetMovementComponent().GetMovementSystem().ManualPushTrap(position, 150, this.m_globalId) || parent.IsHero()) { this.UpdateTargetDamage(parent, damage); } } } } } pos1.Destruct(); pos2.Destruct(); }
public override void SubTick() { base.SubTick(); this.m_areaShieldSpeed = 0; bool isInAreaShield = false; int damagePercentage = 100; if (this.m_myTeam == 1) { LogicVector2 areaShield = new LogicVector2(); if (this.m_level.GetAreaShield(this.GetMidX(), this.GetMidY(), areaShield)) { this.m_areaShieldSpeed = areaShield.m_x; isInAreaShield = true; damagePercentage = 0; } } if (this.m_targetReached) { if (this.m_damageTime > 0) { this.UpdateDamage(damagePercentage); } } else { if (this.m_targetGroups) { if (this.m_target != null && this.m_groups != null) { LogicCombatComponent combatComponent = this.m_groups.GetCombatComponent(); if (combatComponent != null && !combatComponent.IsInRange(this.m_target)) { this.m_target = null; } } } if (isInAreaShield) { this.m_areaShieldDelay = LogicMath.Min(this.m_areaShieldDelay + 16, 200); } else if (this.m_areaShieldDelay > 0) { this.m_areaShieldDelay = LogicMath.Max(this.m_areaShieldDelay - 4, 0); } if (this.m_areaShieldDelay == 0) { if (this.m_target != null && this.m_target.GetMovementComponent() != null) { this.m_targetPosition.Set(this.m_target.GetMidX() * 8, this.m_target.GetMidY() * 8); this.m_targetPosition.Add(this.m_unk168); } } else if (this.m_target != null && this.m_target.GetMovementComponent() != null) { int x = this.m_unk168.m_x + this.m_target.GetMidX() * 8; int y = this.m_unk168.m_y + this.m_target.GetMidY() * 8; LogicVector2 tmp1 = new LogicVector2(x - this.m_unk276.m_x, y - this.m_unk276.m_y); LogicVector2 tmp2 = new LogicVector2(this.m_unk152.m_x, this.m_unk152.m_y); int length1 = tmp1.Normalize(512); int length2 = tmp2.Normalize(512); int angle1 = tmp1.GetAngle(); int angle2 = tmp2.GetAngle(); if (LogicMath.Abs(LogicMath.NormalizeAngle180(angle1 - angle2)) <= 30) { this.m_targetPosition.m_x += LogicMath.Clamp(x - this.m_targetPosition.m_x, length1 / -500, length1 / 500); this.m_targetPosition.m_y += LogicMath.Clamp(y - this.m_targetPosition.m_y, length1 / -500, length1 / 500); } else { this.m_target = null; } } this.m_unk144.m_x = this.m_targetPosition.m_x - this.m_unk276.m_x; this.m_unk144.m_y = this.m_targetPosition.m_y - this.m_unk276.m_y; int distance = (200 - this.m_areaShieldDelay) * (8 * this.GetSpeed() - 8 * this.m_areaShieldSpeed) / 200 + 8 * this.m_areaShieldSpeed; if (distance * distance >= this.m_unk144.GetDistanceSquaredTo(0, 0)) { this.TargetReached(damagePercentage); } else { this.m_unk152.m_x = this.m_unk144.m_x; this.m_unk152.m_y = this.m_unk144.m_y; this.m_unk144.Normalize(distance); this.m_unk276.m_x += this.m_unk144.m_x; this.m_unk276.m_y += this.m_unk144.m_y; this.SetPositionXY(this.m_unk276.m_x >> 3, this.m_unk276.m_y >> 3); this.m_unk160.m_x = this.m_unk144.m_x >> 3; this.m_unk160.m_y = this.m_unk144.m_y >> 3; } if (this.m_shockwavePushStrength > 0) { this.UpdateShockwavePush(this.m_myTeam, this.m_flyingTarget ? 0 : 1); } if (this.m_penetrating) { this.UpdatePenetrating(damagePercentage); } this.m_travelTime += 16; } }
public void UpdateShockwavePush(int team, int targetType) { LogicVector2 position = new LogicVector2(this.GetMidX() - this.m_unk248.m_x, this.GetMidY() - this.m_unk248.m_y); int length = position.GetLength(); if (length >= this.m_minAttackRange) { int maxRangeDistance = length - this.m_maxAttackRange; int maxRadius = length; int minRadius = length - 512; if (minRadius < this.m_minAttackRange) { minRadius = this.m_minAttackRange; } uint minRadiusSquared = (uint)(minRadius * minRadius); uint maxRadiusSquared = (uint)(maxRadius * maxRadius); int boostSpeed = this.m_speedMod * maxRangeDistance / this.m_maxAttackRange; int boostTime = this.m_statusEffectTime * maxRangeDistance / (16 * this.m_maxAttackRange); int shockwaveArcLength = this.GetShockwaveArcLength(); LogicArrayList <LogicComponent> components = this.GetComponentManager().GetComponents(LogicComponentType.MOVEMENT); LogicVector2 pushBackPosition = new LogicVector2(); for (int i = 0; i < components.Size(); i++) { LogicMovementComponent movementComponent = (LogicMovementComponent)components[i]; LogicGameObject parent = movementComponent.GetParent(); LogicHitpointComponent hitpointComponent = parent.GetHitpointComponent(); if (!parent.IsHidden()) { if (hitpointComponent == null || hitpointComponent.GetTeam() != team) { if (hitpointComponent != null && hitpointComponent.GetParent().IsFlying()) { if (targetType == 1) { continue; } } else if (targetType == 0) { continue; } int distanceX = parent.GetMidX() - this.m_unk248.m_x; int distanceY = parent.GetMidY() - this.m_unk248.m_y; if (LogicMath.Abs(distanceX) <= maxRadius && LogicMath.Abs(distanceY) <= maxRadius) { int distance = distanceX * distanceX + distanceY * distanceY; if (distance <= maxRadiusSquared && distance >= minRadiusSquared) { if ((distanceX | distanceY) == 0) { distanceX = 1; } pushBackPosition.Set(distanceX, distanceY); int pushBackLength = pushBackPosition.Normalize(512); int angle = LogicMath.Abs(LogicMath.NormalizeAngle180(LogicMath.NormalizeAngle180(pushBackPosition.GetAngle()) - LogicMath.NormalizeAngle180(this.m_shockwaveAngle))); if (angle < shockwaveArcLength / 2) { int pushBack = 100 * (this.m_maxAttackRange + 256 - pushBackLength) / 512; if (pushBack > this.m_shockwavePushStrength) { pushBack = this.m_shockwavePushStrength; } movementComponent.GetMovementSystem().ManualPushBack(pushBackPosition, pushBack, 750, this.m_globalId); if (boostSpeed != 0) { movementComponent.GetMovementSystem().Boost(boostSpeed, boostTime); } } } } } } } } }