Ejemplo n.º 1
0
        public void UpdateBounces()
        {
            LogicArrayList <LogicGameObject> gameObjects = this.GetGameObjectManager().GetGameObjects(LogicGameObjectType.BUILDING);

            int closestBuildingDistance = 0x7FFFFFFF;
            int closestWallDistance     = 0x7FFFFFFF;

            LogicBuilding closestBuilding = null;
            LogicBuilding closestWall     = null;

            for (int i = 0; i < gameObjects.Size(); i++)
            {
                LogicBuilding building = (LogicBuilding)gameObjects[i];

                if (building != this.m_target && building.IsAlive())
                {
                    LogicHitpointComponent hitpointComponent = building.GetHitpointComponent();

                    if (hitpointComponent != null && hitpointComponent.IsEnemyForTeam(this.m_myTeam) && !building.IsHidden() && !building.IsWall())
                    {
                        int distanceSquared = this.GetDistanceSquaredTo(building);

                        if (distanceSquared <= 26214400 && distanceSquared < (building.IsWall() ? closestWallDistance : closestBuildingDistance))
                        {
                            int idx = -1;

                            for (int j = this.m_bounceCount; j < LogicProjectile.MAX_BOUNCES; j++)
                            {
                                if (this.m_bounceTargets[j] == building)
                                {
                                    idx = j;
                                    break;
                                }
                            }

                            if (idx == -1)
                            {
                                if (this.m_level.GetTileMap().GetWallInPassableLine(this.GetMidX(), this.GetMidY(), building.GetMidX(), building.GetMidY(), new LogicVector2()))
                                {
                                    if (building.IsWall())
                                    {
                                        closestWallDistance = distanceSquared;
                                        closestWall         = building;
                                    }
                                    else
                                    {
                                        closestBuildingDistance = distanceSquared;
                                        closestBuilding         = building;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            LogicBuilding nextTarget = closestBuilding ?? closestWall;

            if (nextTarget != null)
            {
                this.m_bounceCount  -= 1;
                this.m_targetReached = false;
                this.m_damage       /= 2;

                this.SetTarget(this.GetMidX(), this.GetMidY(), this.m_bounceCount, nextTarget, false);
                this.SetInitialPosition(this.m_groups, this.GetMidX(), this.GetMidY());
            }
        }