Example #1
0
        public void SetUpgradeLevel(int upgLevel)
        {
            this.m_upgradeLevel = upgLevel;

            LogicCharacterData     data = this.GetCharacterData();
            LogicHitpointComponent hitpointComponent = this.GetHitpointComponent();
            LogicCombatComponent   combatComponent   = this.GetCombatComponent();

            int hp = data.GetHitpoints(upgLevel);
            int damagePercentage = 100;

            if (data.GetScaleByTH())
            {
                LogicAvatar avatar = this.m_level.GetHomeOwnerAvatar();

                if (hitpointComponent != null && hitpointComponent.GetTeam() == 0)
                {
                    avatar = this.m_level.GetVisitorAvatar();
                }

                int tmp1 = 700 * avatar.GetTownHallLevel() / (LogicDataTables.GetTownHallLevelCount() - 1);

                damagePercentage = tmp1 / 10 + 30;
                hp = damagePercentage * hp / 100;

                if (damagePercentage * hp < 200)
                {
                    hp = 1;
                }

                if (tmp1 < -289)
                {
                    damagePercentage = 1;
                }
            }

            hitpointComponent.SetMaxHitpoints(hp);
            hitpointComponent.SetHitpoints(data.GetHitpoints(upgLevel));
            hitpointComponent.SetDieEffect(data.GetDieEffect(upgLevel), data.GetDieEffect2(upgLevel));

            if (combatComponent != null)
            {
                combatComponent.SetAttackValues(data.GetAttackerItemData(upgLevel), damagePercentage);
            }

            if (this.m_childrens != null)
            {
                for (int i = 0; i < this.m_childrens.Size(); i++)
                {
                    this.m_childrens[i].SetUpgradeLevel(upgLevel);
                }
            }

            if (this.IsHero())
            {
                LogicHeroData heroData = (LogicHeroData)this.m_data;
                LogicAvatar   avatar   = this.m_level.GetHomeOwnerAvatar();

                if (hitpointComponent.GetTeam() == 0)
                {
                    avatar = this.m_level.GetVisitorAvatar();
                }

                this.m_flying = heroData.IsFlying(avatar.GetHeroMode(heroData));
                this.GetMovementComponent().SetFlying(this.m_flying);
            }

            if (data.GetAutoMergeDistance() > 0)
            {
                this.m_autoMergeTime = 2000;
            }

            int speed = data.GetSpeed();

            if (data.GetSpecialAbilityLevel(this.m_upgradeLevel) > 0 &&
                data.GetSpecialAbilityType() == LogicCharacterData.SPECIAL_ABILITY_TYPE_SPEED_BOOST)
            {
                speed = speed * data.GetSpecialAbilityAttribute(this.m_upgradeLevel) / 100;
            }

            this.GetMovementComponent().SetSpeed(speed);
        }