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; } }
public LogicArrayList <LogicVector2> CreatePatrolPath() { int parentWidth = this.m_parent.GetWidthInTiles() << 8; int parentHeight = this.m_parent.GetHeightInTiles() << 8; int patrolRadius = this.m_hero.GetPatrolRadius(); if (patrolRadius * patrolRadius >= parentWidth * parentWidth + parentHeight * parentHeight) { LogicVector2 tmp1 = new LogicVector2(); LogicVector2 tmp2 = new LogicVector2(); LogicVector2 tmp3 = new LogicVector2(); LogicVector2 tmp4 = new LogicVector2(); int parentMidX = this.m_parent.GetMidX(); int parentMidY = this.m_parent.GetMidY(); tmp2.Set(parentMidX, parentMidY); LogicArrayList <LogicVector2> wayPoints = new LogicArrayList <LogicVector2>(LogicHeroBaseComponent.PATROL_PATHS); for (int i = 0, j = 22; i < LogicHeroBaseComponent.PATROL_PATHS; i++, j += 45) { tmp1.Set(parentMidX + LogicMath.Cos(j, patrolRadius), parentMidY + LogicMath.Sin(j, patrolRadius)); LogicHeroBaseComponent.FindPoint(this.m_parent.GetLevel().GetTileMap(), tmp3, tmp2, tmp1, tmp4); wayPoints.Add(new LogicVector2(tmp4.m_x, tmp4.m_y)); } tmp1.Destruct(); tmp2.Destruct(); tmp3.Destruct(); tmp4.Destruct(); return(wayPoints); } else { int startX = this.m_parent.GetX() + (this.m_parent.GetWidthInTiles() << 9) - 128; int startY = this.m_parent.GetY() + (this.m_parent.GetWidthInTiles() << 9) - 128; int endX = this.m_parent.GetX() + 128; int endY = this.m_parent.GetY() + 128; LogicArrayList <LogicVector2> wayPoints = new LogicArrayList <LogicVector2>(4); wayPoints.Add(new LogicVector2(startX, startY)); wayPoints.Add(new LogicVector2(endX, startY)); wayPoints.Add(new LogicVector2(endX, endY)); wayPoints.Add(new LogicVector2(startX, endY)); return(wayPoints); } }
public void SpawnUnit(int count) { LogicTrapData data = this.GetTrapData(); LogicCharacterData spawnData = this.m_useAirMode[this.m_level.GetActiveLayout(this.m_villageType)] ? data.GetSpawnedCharAir() : data.GetSpawnedCharGround(); if (spawnData != null) { LogicVector2 position = new LogicVector2(); for (int i = 0, j = 59, k = 0, l = 0; i < count; i++, j += 59, k += 128, l += 360) { int random = l / data.GetNumSpawns(this.m_upgLevel) + j * this.m_numSpawns % 360; int randomX = (byte)(k & 0x80) ^ 0x180; int posX = this.GetMidX() + LogicMath.GetRotatedX(randomX, 0, random); int posY = this.GetMidY() + LogicMath.GetRotatedY(randomX, 0, random); if (spawnData.IsFlying()) { position.m_x = posX; position.m_y = posY; } else { if (!this.m_level.GetTileMap().GetNearestPassablePosition(posX, posY, position, 1536)) { continue; } } LogicCharacter character = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(spawnData, this.m_level, this.m_villageType); character.GetHitpointComponent().SetTeam(1); character.GetMovementComponent().EnableJump(3600000); character.SetInitialPosition(position.m_x, position.m_y); character.SetSpawnTime(200); this.GetGameObjectManager().AddGameObject(character, -1); } position.Destruct(); } }
public void ClearPatrolArea() { if (this.m_wayPoints != null) { while (this.m_wayPoints.Size() > 0) { LogicVector2 wayPoint = this.m_wayPoints[this.m_wayPoints.Size() - 1]; if (wayPoint == null) { Debugger.Error("LogicMovementSystem::calculatePatrolArea: removed waypoint is NULL"); } wayPoint.Destruct(); this.m_wayPoints.Remove(this.m_wayPoints.Size() - 1); } } this.m_wayPoints = null; }
public void CheckSpawning(LogicCharacterData spawnCharacterData, int spawnCount, int spawnUpgradeLevel, int invulnerabilityTime) { LogicCharacterData data = this.GetCharacterData(); if (spawnCharacterData == null) { spawnCharacterData = data.GetSecondaryTroop(); if (spawnCharacterData == null) { spawnCharacterData = data.GetAttackerItemData(this.m_upgradeLevel).GetSummonTroop(); if (spawnCharacterData == null) { return; } } } if (spawnCharacterData.IsSecondaryTroop() || this.IsHero()) { int totalSpawnCount = spawnCount; int upgLevel = this.m_upgradeLevel; if (upgLevel >= spawnCharacterData.GetUpgradeLevelCount()) { upgLevel = spawnCharacterData.GetUpgradeLevelCount() - 1; } if (this.IsHero()) { if (this.m_summonSpawnCount >= spawnCount) { return; } upgLevel = spawnUpgradeLevel; totalSpawnCount = LogicMath.Max(0, LogicMath.Min(3, spawnCount - this.m_summonSpawnCount)); } else { if (data.GetSecondaryTroopCount(this.m_upgradeLevel) != 0) { totalSpawnCount = data.GetSecondaryTroopCount(this.m_upgradeLevel); } else if (spawnCount == 0) { totalSpawnCount = data.GetAttackerItemData(this.m_upgradeLevel).GetSummonTroopCount(); if (this.m_summonTroops.Size() + totalSpawnCount > data.GetAttackerItemData(this.m_upgradeLevel).GetSummonLimit()) { totalSpawnCount = data.GetAttackerItemData(this.m_upgradeLevel).GetSummonLimit() - this.m_summonTroops.Size(); } } } if (totalSpawnCount > 0) { LogicVector2 position = new LogicVector2(); LogicRandom random = new LogicRandom(this.m_globalId); int team = this.GetHitpointComponent().GetTeam(); bool randomizeSecSpawnDist = this.GetCharacterData().GetRandomizeSecSpawnDist(); for (int i = 0, j = 0, k = 0; i < totalSpawnCount; i++, j += 360, k += 100) { int seed = j / totalSpawnCount; if (this.IsHero()) { seed = 360 * (i + this.m_summonSpawnCount) / LogicMath.Max(1, LogicMath.Min(6, spawnCount)); } int rnd = 59 * this.m_globalId % 360 + seed; if (spawnCharacterData.IsFlying()) { LogicCharacterData parentData = this.GetCharacterData(); position.Set(this.GetX() + LogicMath.GetRotatedX(parentData.GetSecondarySpawnOffset(), 0, rnd), this.GetY() + LogicMath.GetRotatedY(parentData.GetSecondarySpawnOffset(), 0, rnd)); } else if (spawnCharacterData.GetSpeed() == 0) { position.Set(this.GetX(), this.GetY()); } else { if (!this.m_level.GetTileMap().GetNearestPassablePosition(this.GetX(), this.GetY(), position, 1536)) { continue; } } LogicCharacter spawnGameObject = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(spawnCharacterData, this.m_level, this.m_villageType); if (this.GetCharacterData().GetAttackerItemData(this.m_upgradeLevel).GetSummonTroop() != null || this.IsHero()) { this.m_summonTroops.Add(spawnGameObject); } spawnGameObject.GetHitpointComponent().SetTeam(team); spawnGameObject.SetUpgradeLevel(upgLevel); spawnGameObject.SetInitialPosition(position.m_x, position.m_y); if (this.m_duplicate) { spawnGameObject.m_duplicateLifeTime = this.m_duplicateLifeTime; spawnGameObject.m_duplicate = true; } if (!this.IsHero()) { spawnGameObject.m_summoner = (LogicCharacterData)this.m_data; } if (invulnerabilityTime > 0) { spawnGameObject.GetHitpointComponent().SetInvulnerabilityTime(invulnerabilityTime); } int secondarySpawnDistance = this.IsHero() ? 768 : this.GetCharacterData().GetSecondarySpawnDistance(); if (secondarySpawnDistance > 0) { if (randomizeSecSpawnDist) { secondarySpawnDistance = (int)(random.Rand(secondarySpawnDistance) + ((uint)secondarySpawnDistance >> 1)); } position.Set(LogicMath.Cos(rnd, secondarySpawnDistance), LogicMath.Sin(rnd, secondarySpawnDistance)); int pushBackSpeed = spawnGameObject.GetCharacterData().GetPushbackSpeed(); if (pushBackSpeed <= 0) { pushBackSpeed = 1; } int pushBackTime = 2 * secondarySpawnDistance / (3 * pushBackSpeed); if (this.GetHitpointComponent().GetHitpoints() > 0) { if (this.GetAttackerItemData().GetSummonTroop() != null) { spawnGameObject.SetSpawnTime(pushBackTime); } else if (this.IsHero()) { spawnGameObject.SetSpawnTime(pushBackTime + k); } } spawnGameObject.GetMovementComponent().GetMovementSystem().PushTrap(position, pushBackTime, 0, false, false); } if (team == 1 || spawnGameObject.GetCharacterData().IsJumper()) { spawnGameObject.GetMovementComponent().EnableJump(3600000); spawnGameObject.GetCombatComponent().RefreshTarget(true); } if (team == 1) { if (LogicDataTables.GetGlobals().AllianceTroopsPatrol()) { spawnGameObject.GetCombatComponent().SetSearchRadius(LogicDataTables.GetGlobals().GetClanCastleRadius() >> 9); if (this.GetMovementComponent().GetBaseBuilding() != null) { spawnGameObject.GetMovementComponent().SetBaseBuilding(this.GetMovementComponent().GetBaseBuilding()); } } } this.GetGameObjectManager().AddGameObject(spawnGameObject, -1); if (this.IsHero()) { ++this.m_summonSpawnCount; } } position.Destruct(); } } else { Debugger.Warning("checkSpawning: trying to spawn normal troops!"); } }
public void TargetReached(int damagePercent) { this.m_damageTime = this.GetProjectileData().GetDamageDelay(); this.UpdateDamage(damagePercent); this.m_targetReached = true; if (!this.m_dummy) { if (this.m_hitEffect != null) { if (this.m_target != null) { LogicHitpointComponent hitpointComponent = this.m_target.GetHitpointComponent(); if (hitpointComponent != null) { if (!this.m_bounceProjectile) { // Listener. } } } else if (!this.m_penetrating && this.m_shockwavePushStrength == 0) { // Listener. } } if (this.m_hitEffect2 != null) { if (this.m_target != null) { LogicHitpointComponent hitpointComponent = this.m_target.GetHitpointComponent(); if (hitpointComponent != null) { if (!this.m_bounceProjectile) { // Listener. } } } else if (!this.m_penetrating && this.m_shockwavePushStrength == 0) { // Listener. } } if (this.m_target != null) { if (this.m_bounceCount > 0) { this.m_bounceTargets[this.m_bounceCount - 1] = this.m_target; this.UpdateBounces(); } } LogicSpellData hitSpell = this.GetProjectileData().GetHitSpell(); if (hitSpell != null) { LogicSpell spell = (LogicSpell)LogicGameObjectFactory.CreateGameObject(hitSpell, this.m_level, this.m_villageType); spell.SetUpgradeLevel(this.GetProjectileData().GetHitSpellLevel()); spell.SetInitialPosition(this.GetMidX(), this.GetMidY()); spell.SetTeam(1); this.GetGameObjectManager().AddGameObject(spell, -1); } if (this.m_bounceProjectile) { int idx = -1; for (int i = 0; i < LogicProjectile.MAX_BOUNCES; i++) { if (this.m_bouncePositions[i] != null) { idx = i; break; } } if (idx != -1) { LogicVector2 bouncePosition = this.m_bouncePositions[idx]; this.m_bouncePositions[idx] = null; this.m_target = null; LogicEffectData bounceEffect = this.GetProjectileData().GetBounceEffect(); if (bounceEffect != null) { this.m_listener.PlayEffect(bounceEffect); } this.m_targetPosition.m_x = 8 * bouncePosition.m_x; this.m_targetPosition.m_y = 8 * bouncePosition.m_y; this.m_randomHitRange = this.m_flyingTarget ? 1000 : 0; // Listener. this.m_targetReached = false; this.m_travelTime = 0; bouncePosition.Destruct(); } else { this.m_target = null; } } if (this.m_targetReached) { LogicEffectData destroyedEffect = this.GetProjectileData().GetDestroyedEffect(); if (destroyedEffect != null) { // Listener. } } } }
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 bool ManualPushBack(LogicVector2 position, int speed, int time, int id) { if (speed > 0) { if (this.m_parent != null && this.m_parent.GetJump() <= 0) { if (id != 0) { int idx = -1; for (int k = 0; k < 3; k++) { if (this.m_preventsPushId[k] == id) { return(false); } if (this.m_preventsPushTime[k] == 0) { idx = k; } } if (idx == -1) { return(false); } this.m_preventsPushId[idx] = id; this.m_preventsPushTime[idx] = 1500; } LogicGameObject parent = this.m_parent.GetParent(); int rndX = parent.Rand(100) & 0x7F; int rndY = parent.Rand(200) & 0x7F; int pushBackX = rndX + position.m_x - 0x3F; int pushBackY = rndY + position.m_y - 0x3F; LogicVector2 pushForce = new LogicVector2((2 * speed * pushBackX) >> 8, (2 * speed * pushBackY) >> 8); int prevPushBackTime = this.m_pushTime; if (prevPushBackTime <= 0) { this.m_pushTime = time - 16; this.m_pushInitTime = time; this.m_ignorePush = false; this.m_pushBackStartPosition.m_x = this.m_position.m_x; this.m_pushBackStartPosition.m_y = this.m_position.m_y; this.m_pushBackEndPosition.m_x = this.m_position.m_x + pushForce.m_x; this.m_pushBackEndPosition.m_y = this.m_position.m_y + pushForce.m_y; } else { LogicVector2 prevPushForce = new LogicVector2(this.m_pushBackEndPosition.m_x - this.m_position.m_x, this.m_pushBackEndPosition.m_y - this.m_position.m_y); this.m_pushTime = prevPushBackTime + time - 16; this.m_pushInitTime = prevPushBackTime + time; this.m_ignorePush = false; pushForce.Add(prevPushForce); this.m_pushBackStartPosition.m_x = this.m_position.m_x; this.m_pushBackStartPosition.m_y = this.m_position.m_y; this.m_pushBackEndPosition.m_x = this.m_position.m_x + pushForce.m_x; this.m_pushBackEndPosition.m_y = this.m_position.m_y + pushForce.m_y; prevPushForce.Destruct(); } return(true); } } return(false); }
public bool MoveTo(int x, int y, LogicTileMap tileMap, bool defaultEndPoint) { this.ClearPath(); if (this.m_parent != null) { if (this.m_parent.GetParent().IsFrozen()) { return(false); } } this.m_wall = null; this.m_wallCount = 0; this.m_pathStartPosition.m_x = this.m_position.m_x >> 8; this.m_pathStartPosition.m_y = this.m_position.m_y >> 8; this.m_pathEndPosition.m_x = x >> 8; this.m_pathEndPosition.m_y = y >> 8; this.m_pathStartPosition.m_x = LogicMath.Clamp(this.m_pathStartPosition.m_x, 0, 99); this.m_pathStartPosition.m_y = LogicMath.Clamp(this.m_pathStartPosition.m_y, 0, 99); this.m_pathEndPosition.m_x = LogicMath.Clamp(this.m_pathEndPosition.m_x, 0, 99); this.m_pathEndPosition.m_y = LogicMath.Clamp(this.m_pathEndPosition.m_y, 0, 99); LogicPathFinder pathFinder; if (this.m_parent == null) { pathFinder = this.m_pathFinder; pathFinder.ResetCostStrategyToDefault(); } else { bool resetStrategyCost = true; int strategyCost = 256; LogicGameObject parent = this.m_parent.GetParent(); LogicHitpointComponent hitpointComponent = parent.GetHitpointComponent(); if (hitpointComponent != null) { if (hitpointComponent.GetTeam() == 1) { resetStrategyCost = false; strategyCost = 768; } } if (this.m_parent.CanJumpWall()) { resetStrategyCost = false; strategyCost = 16; } if (parent.GetGameObjectType() == LogicGameObjectType.CHARACTER) { LogicCharacter character = (LogicCharacter)parent; if (character.IsWallBreaker()) { resetStrategyCost = false; strategyCost = 128; } } pathFinder = tileMap.GetPathFinder(); if (resetStrategyCost) { pathFinder.ResetCostStrategyToDefault(); } else { pathFinder.SetCostStrategy(true, strategyCost); } pathFinder.FindPath(this.m_pathStartPosition, this.m_pathEndPosition, true); pathFinder.GetPathLength(); int pathLength = pathFinder.GetPathLength(); this.m_path.EnsureCapacity(pathLength + 1); if (pathLength != 0 && defaultEndPoint) { LogicVector2 pathPoint = new LogicVector2(x, y); this.CheckWall(pathPoint); this.m_path.Add(pathPoint); } if (LogicDataTables.GetGlobals().UseNewPathFinder()) { LogicTileMap pathFinderTileMap = pathFinder.GetTileMap(); int width = 2 * pathFinderTileMap.GetSizeX(); int height = 2 * pathFinderTileMap.GetSizeY(); int startTileIdx = this.m_pathStartPosition.m_x + width * this.m_pathStartPosition.m_y; int endTileIdx = this.m_pathEndPosition.m_x + width * this.m_pathEndPosition.m_y; if (!defaultEndPoint) { LogicVector2 pathPoint = new LogicVector2((endTileIdx % width) << 8, (endTileIdx / height) << 8); this.CheckWall(pathPoint); this.m_path.Add(pathPoint); } if (pathLength > 0 && !pathFinder.IsLineOfSightClear()) { int iterationCount = 0; while (endTileIdx != startTileIdx && endTileIdx != -1) { endTileIdx = pathFinder.GetParent(endTileIdx); if (endTileIdx != startTileIdx && endTileIdx != -1) { LogicVector2 pathPoint = new LogicVector2((endTileIdx % width) << 8, (endTileIdx / height) << 8); pathPoint.m_x += 128; pathPoint.m_y += 128; this.CheckWall(pathPoint); this.m_path.Add(pathPoint); if (iterationCount >= 100000) { Debugger.Warning("LMSystem: iteration count > 100000"); break; } } iterationCount += 1; } } } else { for (int i = -pathLength, j = 0; j + i != 0; j++) { LogicVector2 pathPoint = new LogicVector2(); pathFinder.GetPathPoint(pathPoint, i + j); if (i + j == -1 && this.m_pathStartPosition.Equals(pathPoint)) { pathPoint.Destruct(); pathPoint = null; } else { if (j != 0 || !this.m_pathStartPosition.Equals(pathPoint)) { pathPoint.m_x = (pathPoint.m_x << 8) | 128; pathPoint.m_y = (pathPoint.m_y << 8) | 128; } else { pathPoint.m_x = x; pathPoint.m_y = y; } this.CheckWall(pathPoint); this.m_path.Add(pathPoint); } } } } this.CalculatePathLength(); if (this.m_path.Size() > 0) { this.CalculateDirection(this.m_pathDistance); return(true); } return(false); }
public void CreatePatrolArea(LogicGameObject patrolPost, LogicLevel level, bool unk, int idx) { LogicArrayList <LogicVector2> wayPoints = new LogicArrayList <LogicVector2>(8); if (this.m_patrolPost == null) { this.m_patrolPost = patrolPost; } int startX = 0; int startY = 0; int endX = 0; int endY = 0; int midX = 0; int midY = 0; int width = 0; int height = 0; int radius = 0; if (patrolPost != null) { startX = patrolPost.GetX() - 128; startY = patrolPost.GetY() - 128; endX = patrolPost.GetX() + (patrolPost.GetWidthInTiles() << 9) + 128; endY = patrolPost.GetY() + (patrolPost.GetHeightInTiles() << 9) + 128; midX = patrolPost.GetMidX(); midY = patrolPost.GetMidY(); width = patrolPost.GetWidthInTiles() << 8; height = patrolPost.GetHeightInTiles() << 8; radius = 1536; } if (radius * radius >= (uint)(width * width + height * height)) { LogicVector2 tmp1 = new LogicVector2(); LogicVector2 tmp2 = new LogicVector2(); LogicVector2 tmp3 = new LogicVector2(); LogicVector2 tmp4 = new LogicVector2(); tmp2.Set(midX, midY); int rnd = patrolPost.GetLevel().GetLogicTime().GetTick() + idx; midX = midX + 127 * rnd % 1024 - 512; midY = midY + 271 * rnd % 1024 - 512; for (int i = 0, j = 45; i < 4; i++, j += 90) { tmp1.Set(midX + LogicMath.Cos(j, radius), midY + LogicMath.Sin(j, radius)); LogicHeroBaseComponent.FindPoint(patrolPost.GetLevel().GetTileMap(), tmp3, tmp2, tmp1, tmp4); wayPoints.Add(new LogicVector2(tmp4.m_x, tmp4.m_y)); } tmp1.Destruct(); tmp2.Destruct(); tmp3.Destruct(); tmp4.Destruct(); } else { wayPoints.Add(new LogicVector2(endX, endY)); wayPoints.Add(new LogicVector2(startX, endY)); wayPoints.Add(new LogicVector2(startX, startY)); wayPoints.Add(new LogicVector2(endX, startY)); } this.ClearPatrolArea(); this.m_wayPoints = wayPoints; this.m_patrolAreaCounter = 0; if (this.m_wayPoints.Size() > 1) { int closestLength = 0x7FFFFFFF; for (int i = 1, size = this.m_wayPoints.Size(); i < size; i++) { LogicVector2 wayPoint = this.m_wayPoints[i]; int length = (wayPoint.m_x - (this.m_position.m_x >> 16)) * (wayPoint.m_x - (this.m_position.m_x >> 16)) + (wayPoint.m_y - (this.m_position.m_y >> 16)) * (wayPoint.m_y - (this.m_position.m_y >> 16)); if (length < closestLength) { this.m_patrolAreaCounter = i; closestLength = length; } } } this.MoveTo(this.m_wayPoints[this.m_patrolAreaCounter].m_x, this.m_wayPoints[this.m_patrolAreaCounter].m_y, level.GetTileMap(), true); }