public void UpdateHeroHealthToAvatar(int hitpoint)
        {
            LogicAvatar   avatar = this.m_team == 1 ? this.m_parent.GetLevel().GetHomeOwnerAvatar() : this.m_parent.GetLevel().GetVisitorAvatar();
            LogicHeroData data   = null;

            int upgLevel = 0;

            if (this.m_parent.IsHero())
            {
                LogicCharacter character = (LogicCharacter)this.m_parent;

                data     = (LogicHeroData)character.GetCharacterData();
                upgLevel = character.GetUpgradeLevel();
            }
            else if (this.m_parent.GetGameObjectType() == LogicGameObjectType.BUILDING)
            {
                LogicBuilding          building          = (LogicBuilding)this.m_parent;
                LogicHeroBaseComponent heroBaseComponent = building.GetHeroBaseComponent();

                if (heroBaseComponent == null)
                {
                    return;
                }

                LogicBuildingData buildingData = building.GetBuildingData();

                if (!buildingData.GetShareHeroCombatData())
                {
                    return;
                }

                LogicCombatComponent combatComponent = building.GetCombatComponent();

                if (combatComponent == null || !combatComponent.IsEnabled())
                {
                    return;
                }

                data     = buildingData.GetHeroData();
                upgLevel = avatar.GetUnitUpgradeLevel(data);
            }

            if (data != null)
            {
                int secs = LogicMath.Min(data.GetSecondsToFullHealth(hitpoint, upgLevel), data.GetFullRegenerationTimeSec(upgLevel));

                if (avatar != null)
                {
                    avatar.GetChangeListener().CommodityCountChanged(0, data, secs);
                    avatar.SetHeroHealth(data, secs);
                }
            }
        }
        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);
            }
        }
Пример #3
0
        public bool IsHeroUnlocked(LogicHeroData data)
        {
            LogicArrayList <LogicComponent> components = this.m_components[(int)LogicComponentType.HERO_BASE];

            for (int i = 0; i < components.Size(); i++)
            {
                LogicHeroBaseComponent component = (LogicHeroBaseComponent)components[i];

                if (component.GetHeroData() == data)
                {
                    LogicBuilding building = (LogicBuilding)component.GetParent();

                    if (!building.IsLocked())
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #4
0
        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);
        }