public void CreateProjectile(LogicProjectileData data) { LogicTrapData trapData = this.GetTrapData(); LogicVector2 position = new LogicVector2(); LogicArrayList <LogicGameObject> characters = this.GetGameObjectManager().GetGameObjects(LogicGameObjectType.CHARACTER); LogicGameObject closestGameObject = null; for (int i = 0, minDistance = 0; i < characters.Size(); i++) { LogicCharacter character = (LogicCharacter)characters[i]; LogicHitpointComponent hitpointComponent = character.GetHitpointComponent(); if (hitpointComponent != null && hitpointComponent.GetTeam() == 0) { if (character.IsFlying() && character.IsAlive()) { int housingSpace = character.GetCharacterData().GetHousingSpace(); if (housingSpace >= trapData.GetMinTriggerHousingLimit() && character.GetChildTroops() == null) { if (trapData.GetHealerTrigger() || character.GetCombatComponent() == null || !character.GetCombatComponent().IsHealer()) { position.m_x = character.GetPosition().m_x - this.GetMidX(); position.m_y = character.GetPosition().m_y - this.GetMidY(); int lengthSquared = position.GetLengthSquared(); if (minDistance == 0 || lengthSquared < minDistance) { minDistance = lengthSquared; closestGameObject = character; } } } } } } position.Destruct(); if (closestGameObject != null) { LogicProjectile projectile = (LogicProjectile)LogicGameObjectFactory.CreateGameObject(data, this.m_level, this.m_villageType); projectile.SetInitialPosition(null, this.GetMidX(), this.GetMidY()); projectile.SetTarget(this.GetMidX(), this.GetMidY(), 0, closestGameObject, data.GetRandomHitPosition()); projectile.SetDamage(trapData.GetDamage(this.m_upgLevel)); projectile.SetDamageRadius(trapData.GetDamageRadius(this.m_upgLevel)); projectile.SetPushBack(trapData.GetPushback(), !trapData.GetDoNotScalePushByDamage()); projectile.SetMyTeam(1); projectile.SetHitEffect(trapData.GetDamageEffect(), null); this.GetGameObjectManager().AddGameObject(projectile, -1); } }
public void SetTarget(int x, int y, int randomHitRange, LogicGameObject target, bool randomHitPosition) { this.m_target = target; this.m_targetPosition.m_x = target.GetMidX() * 8; this.m_targetPosition.m_y = target.GetMidY() * 8; if (target.GetGameObjectType() == LogicGameObjectType.CHARACTER) { LogicCharacter character = (LogicCharacter)target; if (character.IsFlying()) { LogicCombatComponent combatComponent = target.GetCombatComponent(); this.m_randomHitRange = combatComponent != null && combatComponent.IsHealer() ? 200 : 1000; this.m_flyingTarget = true; } if (randomHitPosition) { LogicVector2 pos = new LogicVector2(this.m_targetPosition.m_x >> 3, this.m_targetPosition.m_y >> 3); int distance = pos.GetDistance(this.GetPosition()); this.m_unk168.m_x = this.m_targetPosition.m_x - 8 * this.GetMidX(); this.m_unk168.m_y = this.m_targetPosition.m_y - 8 * this.GetMidY(); this.m_unk168.Rotate(90); this.m_unk168.Normalize(64); int rnd = ((distance / 10) & this.Rand(randomHitRange)) - distance / 20; this.m_unk168.m_x = this.m_unk168.m_x * rnd / 64; this.m_unk168.m_y = this.m_unk168.m_y * rnd / 64; pos.Destruct(); } } else { int range = target.IsWall() ? 1016 : 2040; this.m_unk168.m_x = 8 * x - this.m_targetPosition.m_x; this.m_unk168.m_y = 8 * y - this.m_targetPosition.m_y; this.m_unk168.Normalize(((target.GetWidthInTiles() - target.PassableSubtilesAtEdge()) << 12) / 3); this.m_unk168.m_x += (range & this.Rand(randomHitRange)) * (2 * (this.Rand(randomHitRange + 1) & 1) - 1); this.m_unk168.m_y += (range & this.Rand(randomHitRange + 2)) * (2 * (this.Rand(randomHitRange + 3) & 1) - 1); this.m_targetPosition.Add(this.m_unk168); this.m_randomHitRange = 150; } }