Esempio n. 1
0
        public override int Execute(LogicLevel level)
        {
            LogicArrayList <LogicComponent> components = level.GetComponentManager().GetComponents(LogicComponentType.VILLAGE2_UNIT);
            int remainingSecs = 0;

            for (int i = 0; i < components.Size(); i++)
            {
                remainingSecs += ((LogicVillage2UnitComponent)components[i]).GetRemainingSecs();
            }

            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();
            int speedUpCost = LogicGamePlayUtil.GetSpeedUpCost(remainingSecs, 4, 1);

            if (!playerAvatar.HasEnoughDiamonds(speedUpCost, true, level))
            {
                return(-1);
            }

            playerAvatar.UseDiamonds(speedUpCost);

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

                if (component.GetCurrentlyTrainedUnit() != null && component.GetRemainingSecs() > 0)
                {
                    component.ProductionCompleted();
                }
            }

            playerAvatar.GetChangeListener().DiamondPurchaseMade(16, 0, 0, speedUpCost, 1);

            return(0);
        }
Esempio n. 2
0
        /// <summary>
        ///     Trains the unit with new training.
        /// </summary>
        public int NewTrainingUnit(LogicLevel level)
        {
            if (LogicDataTables.GetGlobals().UseNewTraining())
            {
                LogicUnitProduction unitProduction = this._spellProduction ? level.GetGameObjectManager().GetSpellProduction() : level.GetGameObjectManager().GetUnitProduction();
                LogicClientAvatar   playerAvatar   = level.GetPlayerAvatar();
                Int32 remainingSecs = unitProduction.GetTotalRemainingSeconds();
                Int32 speedUpCost   = LogicGamePlayUtil.GetSpeedUpCost(remainingSecs, this._spellProduction ? 1 : 4, level.GetVillageType());

                if (!level.GetMissionManager().IsTutorialFinished())
                {
                    if (speedUpCost > 0 && LogicDataTables.GetGlobals().GetTutorialTrainingSpeedUpCost() > 0)
                    {
                        speedUpCost = LogicDataTables.GetGlobals().GetTutorialTrainingSpeedUpCost();
                    }
                }

                if (playerAvatar.HasEnoughDiamonds(speedUpCost, true, level))
                {
                    playerAvatar.UseDiamonds(speedUpCost);
                    unitProduction.SpeedUp();

                    return(0);
                }

                return(-1);
            }

            return(-99);
        }
        public int SpeedUpNewTrainingUnit(LogicLevel level)
        {
            if (LogicDataTables.GetGlobals().UseNewTraining())
            {
                LogicUnitProduction unitProduction = this.m_spellProduction ? level.GetGameObjectManager().GetSpellProduction() : level.GetGameObjectManager().GetUnitProduction();
                LogicClientAvatar   playerAvatar   = level.GetPlayerAvatar();

                int remainingSecs = unitProduction.GetTotalRemainingSeconds();
                int speedUpCost   = LogicGamePlayUtil.GetSpeedUpCost(remainingSecs, this.m_spellProduction ? 1 : 4, level.GetVillageType());

                if (!level.GetMissionManager().IsTutorialFinished())
                {
                    if (speedUpCost > 0 && LogicDataTables.GetGlobals().GetTutorialTrainingSpeedUpCost() >= 0)
                    {
                        speedUpCost = LogicDataTables.GetGlobals().GetTutorialTrainingSpeedUpCost();
                    }
                }

                if (playerAvatar.HasEnoughDiamonds(speedUpCost, true, level))
                {
                    playerAvatar.UseDiamonds(speedUpCost);
                    unitProduction.SpeedUp();
                    playerAvatar.GetChangeListener().DiamondPurchaseMade(unitProduction.GetUnitProductionType() == LogicDataType.CHARACTER ? 2 : 7, 0, 0, speedUpCost, level.GetVillageType());

                    return(0);
                }

                return(-1);
            }

            return(-99);
        }
        public bool SpeedUp()
        {
            if (this.m_timer != null)
            {
                int remainingSecs = this.m_timer.GetRemainingSeconds(this.m_parent.GetLevel().GetLogicTime());
                int speedUpCost   = LogicGamePlayUtil.GetSpeedUpCost(remainingSecs, 0, this.m_parent.GetVillageType());

                LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();

                if (homeOwnerAvatar.IsClientAvatar())
                {
                    LogicClientAvatar clientAvatar = (LogicClientAvatar)homeOwnerAvatar;

                    if (clientAvatar.HasEnoughDiamonds(speedUpCost, true, this.m_parent.GetLevel()))
                    {
                        clientAvatar.UseDiamonds(speedUpCost);
                        clientAvatar.GetChangeListener().DiamondPurchaseMade(10, this.m_hero.GetGlobalID(), clientAvatar.GetUnitUpgradeLevel(this.m_hero) + 1, speedUpCost,
                                                                             this.m_parent.GetLevel().GetVillageType());
                        this.FinishUpgrading(true);

                        return(true);
                    }
                }
            }

            return(false);
        }
        internal override void Decode()
        {
            var cost = LogicGamePlayUtil.GetSpeedUpCost(this.Connection.Avatar.Sailing.Timer.RemainingSecs, LogicGamePlayUtil.GetSpeedUpCostMultiplier(4));

            Debugger.Debug(cost);

            this.ReadHeader();
        }
Esempio n. 6
0
        internal override void Execute()
        {
            var cost = LogicGamePlayUtil.GetSpeedUpCost(86400, LogicGamePlayUtil.GetSpeedUpCostMultiplier(1));

            Debugger.Debug(cost);

            this.Connection.Avatar.Diamonds -= cost;

            this.Connection.Avatar.ShipUpgrade.Finish();
        }
        internal override void Execute()
        {
            var cost = LogicGamePlayUtil.GetSpeedUpCost(this.Connection.Avatar.Sailing.Timer.RemainingSecs, LogicGamePlayUtil.GetSpeedUpCostMultiplier(4));

            Debugger.Debug(cost);

            this.Connection.Avatar.Diamonds -= cost;

            this.Connection.Avatar.Sailing.Finish();
            this.Connection.Avatar.Save();
        }
        internal override void Execute()
        {
            int speedUpCost = LogicGamePlayUtil.GetSpeedUpCost(this.Connection.Avatar.SpellTimer.Timer.RemainingSecs, LogicGamePlayUtil.GetSpeedUpCostMultiplier(2));

            if (this.Connection.Avatar.Diamonds >= speedUpCost)
            {
                this.Connection.Avatar.Diamonds -= speedUpCost;
                this.Connection.Avatar.SpellTimer.Finish();
            }

            this.Connection.Avatar.Save();
        }
        /// <summary>
        /// Finishes this instance.
        /// </summary>
        internal void Finish()
        {
            if (this.Upgrading)
            {
                this.Timer.StopTimer();

                int cost = LogicGamePlayUtil.GetSpeedUpCost(this.Timer.RemainingSecs, LogicGamePlayUtil.GetSpeedUpCostMultiplier(1));
                Debugger.Debug(cost);

                this.Avatar.Diamonds -= cost;

                this.Avatar.ShipLevel++;
                this.Avatar.Save();
            }
        }
Esempio n. 10
0
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (playerAvatar != null)
            {
                int lootLimitCooldown = playerAvatar.GetVariableByName("LootLimitCooldown");

                if (lootLimitCooldown == 1)
                {
                    LogicConfiguration configuration = level.GetGameMode().GetConfiguration();

                    if (configuration != null)
                    {
                        LogicCalendar calendar = level.GetGameMode().GetCalendar();

                        if (calendar != null)
                        {
                            int remainingSecs          = playerAvatar.GetRemainingLootLimitTime();
                            int totalSecs              = LogicCalendar.GetDuelLootLimitCooldownInMinutes(calendar, configuration) * 60;
                            int maxDiamondsCostPercent = LogicCalendar.GetDuelBonusMaxDiamondCostPercent(calendar, configuration);

                            int speedUpCost = LogicMath.Max(
                                LogicGamePlayUtil.GetLeagueVillage2(playerAvatar.GetDuelScore()).GetMaxDiamondCost() * maxDiamondsCostPercent * remainingSecs / totalSecs / 100, 1);

                            if (playerAvatar.HasEnoughDiamonds(speedUpCost, true, level))
                            {
                                playerAvatar.UseDiamonds(speedUpCost);
                                playerAvatar.GetChangeListener().DiamondPurchaseMade(18, 0, remainingSecs, speedUpCost, level.GetVillageType());
                                playerAvatar.FastForwardLootLimit(remainingSecs);

                                return(0);
                            }

                            return(-3);
                        }

                        return(-5);
                    }

                    return(-4);
                }

                return(-3);
            }

            return(-2);
        }
Esempio n. 11
0
        /// <summary>
        ///     Speeds up the clearing of the obstacle.
        /// </summary>
        public bool SpeedUpClearing()
        {
            if (this._clearTimer != null)
            {
                int speedUpCost = LogicGamePlayUtil.GetSpeedUpCost(this._clearTimer.GetRemainingSeconds(this._level.GetLogicTime()), 0, this._villageType);

                if (this._level.GetPlayerAvatar().HasEnoughDiamonds(speedUpCost, true, this._level))
                {
                    this._level.GetPlayerAvatar().UseDiamonds(speedUpCost);
                    this.ClearingFinished(false);
                    return(true);
                }
            }

            return(false);
        }
        private int CalculateSpeedUpCost()
        {
            double cost = LogicGamePlayUtil.GetSpeedUpCost(this.Connection.Avatar.Sailing.Timer.RemainingSecs, LogicGamePlayUtil.GetSpeedUpCostMultiplier(4));

            if (this.Connection.Avatar.Sailing.Heroes.Count == 2)
            {
                cost += (cost / 2);
            }
            else if (this.Connection.Avatar.Sailing.Heroes.Count == 3)
            {
                cost = (cost * 2) + 1;
            }

            Debugger.Debug(Math.Round(cost));

            return((int)Math.Round(cost));
        }
Esempio n. 13
0
        public override int Execute(LogicLevel level)
        {
            if (level.GetVillageType() == 0)
            {
                if (level.GetState() == 2 || level.GetState() == 1)
                {
                    if (this.m_buyResourceData != null)
                    {
                        if (this.m_buyResourceCount > 0 && !this.m_buyResourceData.IsPremiumCurrency())
                        {
                            int cost = LogicGamePlayUtil.GetResourceDiamondCost(this.m_buyResourceCount, this.m_buyResourceData);
                            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                            if (playerAvatar.GetUnusedResourceCap(this.m_buyResourceData) >= this.m_buyResourceCount)
                            {
                                if (playerAvatar.HasEnoughDiamonds(cost, true, level))
                                {
                                    playerAvatar.UseDiamonds(cost);
                                    playerAvatar.GetChangeListener()
                                    .DiamondPurchaseMade(5, this.m_buyResourceData.GetGlobalID(), this.m_buyResourceCount, cost, level.GetVillageType());
                                    playerAvatar.CommodityCountChangeHelper(0, this.m_buyResourceData, this.m_buyResourceCount);
                                }
                                else
                                {
                                    return(-2);
                                }
                            }
                            else
                            {
                                return(-1);
                            }
                        }
                    }

                    level.GetGameListener().MatchmakingCommandExecuted();

                    return(0);
                }

                return(-3);
            }

            return(-32);
        }
        public bool SpeedUpClearing()
        {
            if (this.m_clearTimer != null)
            {
                LogicClientAvatar playerAvatar = this.m_level.GetPlayerAvatar();
                int speedUpCost = LogicGamePlayUtil.GetSpeedUpCost(this.m_clearTimer.GetRemainingSeconds(this.m_level.GetLogicTime()), 0, this.m_villageType);

                if (playerAvatar.HasEnoughDiamonds(speedUpCost, true, this.m_level))
                {
                    playerAvatar.UseDiamonds(speedUpCost);
                    playerAvatar.GetChangeListener().DiamondPurchaseMade(3, this.m_data.GetGlobalID(), 0, speedUpCost, this.m_level.GetVillageType());

                    this.ClearingFinished(false);
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 15
0
        public override int Execute(LogicLevel level)
        {
            if (LogicDataTables.GetGlobals().UseTroopRequestSpeedUp())
            {
                LogicClientAvatar      playerAvatar      = level.GetPlayerAvatar();
                LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0);
                LogicBuilding          allianceCastle    = gameObjectManager.GetAllianceCastle();

                if (allianceCastle != null)
                {
                    LogicBunkerComponent bunkerComponent = allianceCastle.GetBunkerComponent();

                    if (bunkerComponent != null)
                    {
                        if (playerAvatar.GetAllianceCastleUsedCapacity() < playerAvatar.GetAllianceCastleTotalCapacity() ||
                            playerAvatar.GetAllianceCastleUsedSpellCapacity() < playerAvatar.GetAllianceCastleTotalSpellCapacity())
                        {
                            int speedUpCost = LogicGamePlayUtil.GetSpeedUpCost(bunkerComponent.GetRequestCooldownTime(), 3, 0);

                            if (playerAvatar.HasEnoughDiamonds(speedUpCost, true, level))
                            {
                                playerAvatar.UseDiamonds(speedUpCost);
                                playerAvatar.GetChangeListener().DiamondPurchaseMade(11, 0, 0, speedUpCost, level.GetVillageType());
                                bunkerComponent.StopRequestCooldownTime();

                                return(0);
                            }

                            return(-6);
                        }

                        return(-5);
                    }

                    return(-4);
                }

                return(-3);
            }

            return(-1);
        }
        public override int Execute(LogicLevel level)
        {
            if (level.GetVillageType() == 1)
            {
                if (level.IsUnitsTrainedVillage2())
                {
                    if (level.GetState() == 1)
                    {
                        if (this.m_buyResourceCount > 0)
                        {
                            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                            if (playerAvatar.GetUnusedResourceCap(LogicDataTables.GetGold2Data()) < this.m_buyResourceCount)
                            {
                                return(-1);
                            }

                            int buyResourceCost = LogicGamePlayUtil.GetResourceDiamondCost(this.m_buyResourceCount, LogicDataTables.GetGold2Data());

                            if (playerAvatar.HasEnoughDiamonds(buyResourceCost, true, level))
                            {
                                return(-2);
                            }

                            playerAvatar.UseDiamonds(buyResourceCost);
                            playerAvatar.GetChangeListener().DiamondPurchaseMade(5, LogicDataTables.GetGold2Data().GetGlobalID(), this.m_buyResourceCount, buyResourceCost,
                                                                                 level.GetVillageType());
                            playerAvatar.CommodityCountChangeHelper(0, LogicDataTables.GetGold2Data(), this.m_buyResourceCount);
                        }

                        level.GetGameListener().MatchmakingVillage2CommandExecuted();
                        return(0);
                    }

                    return(-3);
                }

                return(-24);
            }

            return(-32);
        }
Esempio n. 17
0
        /// <summary>
        ///     Speed up the trap construction.
        /// </summary>
        public bool SpeedUpConstruction()
        {
            if (this._constructionTimer != null)
            {
                int remainingSecs = this._constructionTimer.GetRemainingSeconds(this._level.GetLogicTime());
                int speedUpCost   = LogicGamePlayUtil.GetSpeedUpCost(remainingSecs, 0, this._villageType);

                if (this._level.GetPlayerAvatar().HasEnoughDiamonds(speedUpCost, true, this._level))
                {
                    Debugger.Print("LogicTrap::speedUpConstruction speedup cost: " + speedUpCost);

                    this._level.GetPlayerAvatar().UseDiamonds(speedUpCost);
                    this.FinishConstruction(false);

                    return(true);
                }
            }

            return(false);
        }
        public bool SpeedUpConstruction()
        {
            if (this.m_constructionTimer != null)
            {
                LogicClientAvatar playerAvatar = this.m_level.GetPlayerAvatar();

                int remainingSecs = this.m_constructionTimer.GetRemainingSeconds(this.m_level.GetLogicTime());
                int speedUpCost   = LogicGamePlayUtil.GetSpeedUpCost(remainingSecs, 0, this.m_villageType);

                if (playerAvatar.HasEnoughDiamonds(speedUpCost, true, this.m_level))
                {
                    playerAvatar.UseDiamonds(speedUpCost);
                    playerAvatar.GetChangeListener().DiamondPurchaseMade(4, this.m_data.GetGlobalID(), this.m_upgLevel + (this.m_upgrading ? 2 : 1), speedUpCost,
                                                                         this.m_level.GetVillageType());

                    this.FinishConstruction(false);

                    return(true);
                }
            }

            return(false);
        }
Esempio n. 19
0
        public bool DuplicateCharacter(LogicCharacterData data, int upgLevel)
        {
            if (data != null)
            {
                int tick   = this.m_level.GetLogicTime().GetTick();
                int offset = 75 * this.GetSpellData().GetRadius(this.m_upgradeLevel) / 100 * (tick % 100) / 100;

                int posX = this.GetX() + ((offset * LogicMath.Sin(tick * 21 + 7 * this.m_duplicateCharacterPositionOffset)) >> 10);
                int posY = this.GetY() + ((offset * LogicMath.Cos(tick * 21 + 7 * this.m_duplicateCharacterPositionOffset)) >> 10);

                bool posNotFound = false;

                if (!data.IsFlying())
                {
                    posNotFound = !LogicGamePlayUtil.FindGoodDuplicatePosAround(this.m_level, posX, posY, out int outputX, out int outputY, 10);

                    posX = outputX;
                    posY = outputY;
                }

                if (!posNotFound)
                {
                    if (this.m_duplicateHousingSpace >= data.GetHousingSpace())
                    {
                        this.m_duplicateHousingSpace -= data.GetHousingSpace();
                        this.m_duplicateCharacters.Add(this.CreateDuplicateCharacter(data, upgLevel, posX, posY));

                        ++this.m_duplicateCharacterOffset;
                        ++this.m_duplicateCharacterPositionOffset;

                        return(true);
                    }
                }
            }

            return(false);
        }
        public void ClearingFinished(bool ignoreState)
        {
            int state = this.m_level.GetState();

            if (state == 1 || !LogicDataTables.GetGlobals().CompleteConstructionOnlyHome() && ignoreState)
            {
                if (this.m_level.GetHomeOwnerAvatar().IsClientAvatar())
                {
                    LogicClientAvatar homeOwnerAvatar  = (LogicClientAvatar)this.m_level.GetHomeOwnerAvatar();
                    LogicObstacleData obstacleData     = this.GetObstacleData();
                    LogicResourceData lootResourceData = obstacleData.GetLootResourceData();

                    int lootCount = obstacleData.GetLootCount();

                    if (obstacleData.IsLootCart())
                    {
                        LogicLootCartComponent lootCartComponent = (LogicLootCartComponent)this.GetComponent(LogicComponentType.LOOT_CART);

                        if (lootCartComponent != null)
                        {
                            LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE);

                            bool empty = true;

                            for (int i = 0; i < resourceTable.GetItemCount(); i++)
                            {
                                LogicResourceData resourceData = (LogicResourceData)resourceTable.GetItemAt(i);

                                if (!resourceData.IsPremiumCurrency() && resourceData.GetWarResourceReferenceData() == null)
                                {
                                    int resourceCount  = lootCartComponent.GetResourceCount(i);
                                    int rewardCount    = LogicMath.Min(homeOwnerAvatar.GetUnusedResourceCap(resourceData), resourceCount);
                                    int remainingCount = resourceCount - rewardCount;

                                    if (rewardCount > 0)
                                    {
                                        homeOwnerAvatar.CommodityCountChangeHelper(0, resourceData, rewardCount);
                                        lootCartComponent.SetResourceCount(i, remainingCount);
                                    }

                                    if (remainingCount > 0)
                                    {
                                        empty = false;
                                    }
                                }
                            }

                            if (!empty)
                            {
                                return;
                            }
                        }
                    }

                    if (!obstacleData.IsTombstone() && !obstacleData.IsLootCart())
                    {
                        this.m_level.GetAchievementManager().ObstacleCleared();
                    }

                    this.m_level.GetWorkerManagerAt(this.m_villageType).DeallocateWorker(this);
                    this.XpGainHelper(LogicGamePlayUtil.TimeToExp(obstacleData.GetClearTime()), homeOwnerAvatar, ignoreState || state == 1);

                    if (lootResourceData != null && lootCount > 0)
                    {
                        if (homeOwnerAvatar != null)
                        {
                            if (lootResourceData.IsPremiumCurrency())
                            {
                                int lootMultipler = 1;

                                if (this.m_lootMultiplyVersion >= 2)
                                {
                                    lootMultipler = obstacleData.GetLootMultiplierVersion2();
                                }

                                int diamondsCount = obstacleData.GetName().Equals("Bonus Gembox")
                                    ? lootCount * lootMultipler
                                    : this.m_level.GetGameObjectManagerAt(this.m_villageType).IncreaseObstacleClearCounter(lootMultipler);

                                if (diamondsCount > 0)
                                {
                                    homeOwnerAvatar.SetDiamonds(homeOwnerAvatar.GetDiamonds() + diamondsCount);
                                    homeOwnerAvatar.SetFreeDiamonds(homeOwnerAvatar.GetFreeDiamonds() + diamondsCount);
                                    homeOwnerAvatar.GetChangeListener().FreeDiamondsAdded(diamondsCount, 6);
                                }
                            }
                            else
                            {
                                int gainCount = LogicMath.Min(homeOwnerAvatar.GetUnusedResourceCap(lootResourceData), lootCount);

                                if (gainCount > 0)
                                {
                                    homeOwnerAvatar.CommodityCountChangeHelper(0, lootResourceData, gainCount);
                                }
                            }
                        }
                        else
                        {
                            Debugger.Error("LogicObstacle::clearingFinished - Home owner avatar is NULL!");
                        }
                    }

                    if (obstacleData.IsEnabledInVillageType(this.m_level.GetVillageType()))
                    {
                        // ?
                    }

                    if (this.m_clearTimer != null)
                    {
                        this.m_clearTimer.Destruct();
                        this.m_clearTimer = null;
                    }

                    this.m_fadeTime = 1;
                }
            }
        }
Esempio n. 21
0
        public override void CreateReferences()
        {
            base.CreateReferences();

            this.m_width  = this.GetIntegerValue("Width", 0);
            this.m_height = this.GetIntegerValue("Height", 0);

            this.m_upgradeLevelCount = this.m_row.GetBiggestArraySize();

            this.m_buildCost         = new int[this.m_upgradeLevelCount];
            this.m_rearmCost         = new int[this.m_upgradeLevelCount];
            this.m_townHallLevel     = new int[this.m_upgradeLevelCount];
            this.m_strenghtWeight    = new int[this.m_upgradeLevelCount];
            this.m_damage            = new int[this.m_upgradeLevelCount];
            this.m_damageRadius      = new int[this.m_upgradeLevelCount];
            this.m_ejectHousingLimit = new int[this.m_upgradeLevelCount];
            this.m_numSpawns         = new int[this.m_upgradeLevelCount];
            this.m_constructionTimes = new int[this.m_upgradeLevelCount];

            this.m_projectileData = new LogicProjectileData[this.m_upgradeLevelCount];

            for (int i = 0; i < this.m_upgradeLevelCount; i++)
            {
                this.m_buildCost[i]         = this.GetClampedIntegerValue("BuildCost", i);
                this.m_rearmCost[i]         = this.GetClampedIntegerValue("RearmCost", i);
                this.m_townHallLevel[i]     = LogicMath.Max(this.GetClampedIntegerValue("TownHallLevel", i) - 1, 0);
                this.m_strenghtWeight[i]    = this.GetClampedIntegerValue("StrengthWeight", i);
                this.m_damage[i]            = LogicGamePlayUtil.DPSToSingleHit(this.GetClampedIntegerValue("Damage", i), 1000);
                this.m_damageRadius[i]      = (this.GetClampedIntegerValue("DamageRadius", i) << 9) / 100;
                this.m_ejectHousingLimit[i] = this.GetIntegerValue("EjectHousingLimit", i);
                this.m_numSpawns[i]         = this.GetClampedIntegerValue("NumSpawns", i);
                this.m_constructionTimes[i] = 86400 * this.GetClampedIntegerValue("BuildTimeD", i) +
                                              3600 * this.GetClampedIntegerValue("BuildTimeH", i) +
                                              60 * this.GetClampedIntegerValue("BuildTimeM", i) +
                                              this.GetClampedIntegerValue("BuildTimeS", i);
                this.m_projectileData[i] = LogicDataTables.GetProjectileByName(this.GetValue("Projectile", i), this);
            }

            this.m_preferredTargetData      = LogicDataTables.GetCharacterByName(this.GetValue("PreferredTarget", 0), this);
            this.m_preferredTargetDamageMod = this.GetIntegerValue("PreferredTargetDamageMod", 0);

            if (this.m_preferredTargetDamageMod == 0)
            {
                this.m_preferredTargetDamageMod = 100;
            }

            this.m_buildResourceData = LogicDataTables.GetResourceByName(this.GetValue("BuildResource", 0), this);

            if (this.m_buildResourceData == null)
            {
                Debugger.Error("build resource is not defined for trap: " + this.GetName());
            }

            this.m_ejectVictims               = this.GetBooleanValue("EjectVictims", 0);
            this.m_actionFrame                = 1000 * this.GetIntegerValue("ActionFrame", 0) / 24;
            this.m_pushback                   = this.GetIntegerValue("Pushback", 0);
            this.m_doNotScalePushByDamage     = this.GetBooleanValue("DoNotScalePushByDamage", 0);
            this.m_effectData                 = LogicDataTables.GetEffectByName(this.GetValue("Effect", 0), this);
            this.m_effect2Data                = LogicDataTables.GetEffectByName(this.GetValue("Effect2", 0), this);
            this.m_effectBrokenData           = LogicDataTables.GetEffectByName(this.GetValue("EffectBroken", 0), this);
            this.m_damageEffectData           = LogicDataTables.GetEffectByName(this.GetValue("DamageEffect", 0), this);
            this.m_pickUpEffectData           = LogicDataTables.GetEffectByName(this.GetValue("PickUpEffect", 0), this);
            this.m_placingEffectData          = LogicDataTables.GetEffectByName(this.GetValue("PlacingEffect", 0), this);
            this.m_appearEffectData           = LogicDataTables.GetEffectByName(this.GetValue("AppearEffect", 0), this);
            this.m_toggleAttackModeEffectData = LogicDataTables.GetEffectByName(this.GetValue("ToggleAttackModeEffect", 0), this);
            this.m_triggerRadius              = (this.GetIntegerValue("TriggerRadius", 0) << 9) / 100;
            this.m_directionCount             = this.GetIntegerValue("DirectionCount", 0);
            this.m_spell                  = LogicDataTables.GetSpellByName(this.GetValue("Spell", 0), this);
            this.m_airTrigger             = this.GetBooleanValue("AirTrigger", 0);
            this.m_groundTrigger          = this.GetBooleanValue("GroundTrigger", 0);
            this.m_healerTrigger          = this.GetBooleanValue("HealerTrigger", 0);
            this.m_speedMod               = this.GetIntegerValue("SpeedMod", 0);
            this.m_damageMod              = this.GetIntegerValue("DamageMod", 0);
            this.m_durationMS             = this.GetIntegerValue("DurationMS", 0);
            this.m_hitDelayMS             = this.GetIntegerValue("HitDelayMS", 0);
            this.m_hitCount               = this.GetIntegerValue("HitCnt", 0);
            this.m_minTriggerHousingLimit = this.GetIntegerValue("MinTriggerHousingLimit", 0);
            this.m_spawnedCharGroundData  = LogicDataTables.GetCharacterByName(this.GetValue("SpawnedCharGround", 0), this);
            this.m_spawnedCharAirData     = LogicDataTables.GetCharacterByName(this.GetValue("SpawnedCharAir", 0), this);
            this.m_timeBetweenSpawnsMS    = this.GetIntegerValue("TimeBetweenSpawnsMs", 0);
            this.m_spawnInitialDelayMS    = this.GetIntegerValue("SpawnInitialDelayMs", 0);
            this.m_throwDistance          = this.GetIntegerValue("ThrowDistance", 0);
            this.m_hasAltMode             = this.GetBooleanValue("HasAltMode", 0);
            this.m_enableByCalendar       = this.GetBooleanValue("EnabledByCalendar", 0);

            if (this.m_enableByCalendar)
            {
                if (this.m_upgradeLevelCount > 1)
                {
                    Debugger.Error("Temporary traps should not have upgrade levels!");
                }
            }
        }
        public void CreateReferences(CSVRow row, LogicData data, int idx)
        {
            this.m_row   = row;
            this.m_data  = data;
            this.m_index = idx;

            this.m_pushBack      = row.GetClampedIntegerValue("PushBack", idx);
            this.m_airTargets    = row.GetClampedBooleanValue("AirTargets", idx);
            this.m_groundTargets = row.GetClampedBooleanValue("GroundTargets", idx);
            this.m_altAttackMode = row.GetClampedBooleanValue("AltAttackMode", idx);
            this.m_damage        = 100 * row.GetClampedIntegerValue("Damage", idx);

            int dps            = row.GetClampedIntegerValue("DPS", idx);
            int attackSpeed    = row.GetClampedIntegerValue("AttackSpeed", idx);
            int altDps         = row.GetClampedIntegerValue("AltDPS", idx);
            int altAttackSpeed = row.GetClampedIntegerValue("AltAttackSpeed", idx);

            if (this.m_altAttackMode && altAttackSpeed == 0)
            {
                altAttackSpeed = attackSpeed;
            }

            int cooldownOverride = row.GetClampedIntegerValue("CoolDownOverride", idx);

            if (cooldownOverride == 0)
            {
                int tmp = (int)(((dps | this.m_damage) >> 31) & 0xFFFFFAEC) + 1500;

                if (attackSpeed > tmp)
                {
                    cooldownOverride = attackSpeed - tmp;
                }
            }

            this.m_prepareSpeed = row.GetClampedIntegerValue("PrepareSpeed", idx);

            this.m_attackSpeed      = attackSpeed - cooldownOverride;
            this.m_altAttackSpeed   = altAttackSpeed - cooldownOverride;
            this.m_cooldownOverride = cooldownOverride;

            this.m_damageMulti = 100 * row.GetClampedIntegerValue("DamageMulti", idx);
            this.m_damageLvl2  = 100 * row.GetClampedIntegerValue("DamageLv2", idx);
            this.m_damageLvl3  = 100 * row.GetClampedIntegerValue("DamageLv3", idx);

            this.m_altDamage = this.m_damage;

            if (dps != 0)
            {
                if (altDps == 0)
                {
                    altDps = dps;
                }

                this.m_damage      = LogicGamePlayUtil.DPSToSingleHit(dps, this.m_attackSpeed + this.m_cooldownOverride);
                this.m_altDamage   = LogicGamePlayUtil.DPSToSingleHit(altDps, this.m_altAttackSpeed + this.m_cooldownOverride);
                this.m_damageMulti = LogicGamePlayUtil.DPSToSingleHit(row.GetClampedIntegerValue("DPSMulti", idx), this.m_attackSpeed + this.m_cooldownOverride);
                this.m_damageLvl2  = LogicGamePlayUtil.DPSToSingleHit(row.GetClampedIntegerValue("DPSLv2", idx), this.m_attackSpeed + this.m_cooldownOverride);
                this.m_damageLvl3  = LogicGamePlayUtil.DPSToSingleHit(row.GetClampedIntegerValue("DPSLv3", idx), this.m_attackSpeed + this.m_cooldownOverride);
            }

            this.m_hitEffectData       = LogicDataTables.GetEffectByName(row.GetClampedValue("HitEffect", idx), data);
            this.m_hitEffect2Data      = LogicDataTables.GetEffectByName(row.GetClampedValue("HitEffect2", idx), data);
            this.m_hitEffectActiveData = LogicDataTables.GetEffectByName(row.GetClampedValue("HitEffectActive", idx), data);

            this.m_attackRange  = (row.GetClampedIntegerValue("AttackRange", idx) << 9) / 100;
            this.m_damageRadius = (row.GetClampedIntegerValue("DamageRadius", idx) << 9) / 100;

            this.m_attackEffectData        = LogicDataTables.GetEffectByName(row.GetClampedValue("AttackEffect", idx), data);
            this.m_altAttackEffectData     = LogicDataTables.GetEffectByName(row.GetClampedValue("AttackEffectAlt", idx), data);
            this.m_ammoCount               = row.GetClampedIntegerValue("AmmoCount", idx);
            this.m_attackEffect2Data       = LogicDataTables.GetEffectByName(row.GetClampedValue("AttackEffect2", idx), data);
            this.m_attackEffectLv2Data     = LogicDataTables.GetEffectByName(row.GetClampedValue("AttackEffectLv2", idx), data);
            this.m_attackEffectLv3Data     = LogicDataTables.GetEffectByName(row.GetClampedValue("AttackEffectLv3", idx), data);
            this.m_transitionEffectLv2Data = LogicDataTables.GetEffectByName(row.GetClampedValue("TransitionEffectLv2", idx), data);
            this.m_transitionEffectLv3Data = LogicDataTables.GetEffectByName(row.GetClampedValue("TransitionEffectLv3", idx), data);
            this.m_altNumMultiTargets      = row.GetClampedIntegerValue("AltNumMultiTargets", idx);
            this.m_switchTimeLv2           = row.GetClampedIntegerValue("Lv2SwitchTime", idx);
            this.m_switchTimeLv3           = row.GetClampedIntegerValue("Lv3SwitchTime", idx);
            this.m_statusEffectTime        = row.GetClampedIntegerValue("StatusEffectTime", idx);
            this.m_speedMod              = row.GetClampedIntegerValue("SpeedMod", idx);
            this.m_altAttackRange        = (row.GetClampedIntegerValue("AltAttackRange", idx) << 9) / 100;
            this.m_projectileData        = LogicDataTables.GetProjectileByName(row.GetClampedValue("Projectile", idx), data);
            this.m_altProjectileData     = LogicDataTables.GetProjectileByName(row.GetClampedValue("AltProjectile", idx), data);
            this.m_shockwavePushStrength = row.GetClampedIntegerValue("ShockwavePushStrength", idx);
            this.m_hitSpellData          = LogicDataTables.GetSpellByName(row.GetClampedValue("HitSpell", idx), data);
            this.m_hitSpellLevel         = row.GetClampedIntegerValue("HitSpellLevel", idx);
            this.m_damage2             = 100 * row.GetClampedIntegerValue("Damage2", idx);
            this.m_damage2Radius       = (row.GetClampedIntegerValue("Damage2Radius", idx) << 9) / 100;
            this.m_damage2Delay        = row.GetClampedIntegerValue("Damage2Delay", idx);
            this.m_damage2Min          = 100 * row.GetClampedIntegerValue("Damage2Min", idx);
            this.m_damage2FalloffStart = (row.GetClampedIntegerValue("Damage2FalloffStart", idx) << 9) / 100;
            this.m_damage2FalloffEnd   = (row.GetClampedIntegerValue("Damage2FalloffStart", idx) << 9) / 100;

            if (this.m_damage2FalloffEnd < this.m_damage2FalloffStart)
            {
                Debugger.Error("Building " + row.GetName() + " has falloff end less than falloff start!");
            }

            if (this.m_damage2FalloffEnd > this.m_damage2Radius)
            {
                Debugger.Error("Building " + row.GetName() + " has falloff end greater than the damage radius!");
            }

            this.m_preAttackEffectData         = LogicDataTables.GetEffectByName(row.GetClampedValue("PreAttackEffect", idx), data);
            this.m_becomesTargetableEffectData = LogicDataTables.GetEffectByName(row.GetClampedValue("BecomesTargetableEffect", idx), data);
            this.m_increasingDamage            = row.GetClampedBooleanValue("IncreasingDamage", idx);
            this.m_preventsHealing             = row.GetClampedBooleanValue("PreventsHealing", idx);
            this.m_alternatePickNewTargetDelay = row.GetClampedIntegerValue("AlternatePickNewTargetDelay", idx);
            this.m_shockwaveArcLength          = row.GetClampedIntegerValue("ShockwaveArcLength", idx);
            this.m_shockwaveExpandRadius       = row.GetClampedIntegerValue("ShockwaveExpandRadius", idx);
            this.m_targetingConeAngle          = row.GetClampedIntegerValue("TargetingConeAngle", idx);
            this.m_penetratingProjectile       = row.GetClampedBooleanValue("PenetratingProjectile", idx);
            this.m_penetratingRadius           = (row.GetClampedIntegerValue("PenetratingRadius", idx) << 9) / 100;
            this.m_penetratingExtraRange       = (row.GetClampedIntegerValue("PenetratingExtraRange", idx) << 9) / 100;
            this.m_targetGroups               = row.GetClampedBooleanValue("TargetGroups", idx);
            this.m_fightWithGroups            = row.GetClampedBooleanValue("FightWithGroups", idx);
            this.m_targetGroupsRadius         = (row.GetClampedIntegerValue("TargetGroupsRadius", idx) << 9) / 100;
            this.m_targetGroupsRange          = (row.GetClampedIntegerValue("TargetGroupsRange", idx) << 9) / 100;
            this.m_targetGroupsMinWeight      = row.GetClampedIntegerValue("TargetGroupsMinWeight", idx);
            this.m_wakeUpSpace                = row.GetClampedIntegerValue("WakeUpSpace", idx);
            this.m_wakeUpSpeed                = row.GetClampedIntegerValue("WakeUpSpeed", idx);
            this.m_preferredTargetData        = LogicDataTables.GetCharacterByName(row.GetClampedValue("PreferredTarget", idx), data);
            this.m_preferredTargetDamageMod   = row.GetClampedIntegerValue("PreferredTargetDamageMod", idx);
            this.m_preferredTargetNoTargeting = row.GetClampedBooleanValue("PreferredTargetNoTargeting", idx);
            this.m_altAirTargets              = row.GetClampedBooleanValue("AltAirTargets", idx);
            this.m_altGroundTargets           = row.GetClampedBooleanValue("AltGroundTargets", idx);
            this.m_altMultiTargets            = row.GetClampedBooleanValue("AltMultiTargets", idx);
            this.m_minAttackRange             = (row.GetClampedIntegerValue("MinAttackRange", idx) << 9) / 100;

            if (this.m_preferredTargetData == null)
            {
                this.m_preferredTargetData = LogicDataTables.GetBuildingClassByName(row.GetClampedValue("PreferedTargetBuildingClass", idx), data);

                if (this.m_preferredTargetData == null)
                {
                    this.m_preferredTargetData = LogicDataTables.GetBuildingByName(row.GetClampedValue("PreferedTargetBuilding", idx), data);
                }

                this.m_preferredTargetDamageMod = row.GetClampedIntegerValue("PreferedTargetDamageMod", idx);

                if (this.m_preferredTargetDamageMod == 0)
                {
                    this.m_preferredTargetDamageMod = 100;
                }
            }

            this.m_summonTroopCount   = row.GetClampedIntegerValue("SummonTroopCount", idx);
            this.m_summonCooldown     = row.GetClampedIntegerValue("SummonCooldown", idx);
            this.m_summonEffectData   = LogicDataTables.GetEffectByName(row.GetClampedValue("SummonEffect", idx), data);
            this.m_summonLimit        = row.GetClampedIntegerValue("SummonLimit", idx);
            this.m_summonTroopData    = LogicDataTables.GetCharacterByName(row.GetClampedValue("SummonTroop", idx), data);
            this.m_spawnOnAttack      = row.GetClampedBooleanValue("SpawnOnAttack", idx);
            this.m_hideEffectData     = LogicDataTables.GetEffectByName(row.GetClampedValue("HideEffect", idx), data);
            this.m_rageProjectileData = LogicDataTables.GetProjectileByName(row.GetClampedValue("RageProjectile", idx), data);
            this.m_projectileBounces  = row.GetClampedIntegerValue("ProjectileBounces", idx);
            this.m_selfAsAoeCenter    = row.GetClampedBooleanValue("SelfAsAoeCenter", idx);

            if (this.m_damage2Delay > this.m_cooldownOverride + this.m_attackSpeed)
            {
                Debugger.Error(row.GetName() + " has Damage2Delay greater than the attack speed!");
            }

            if (this.m_ammoCount > 0 && (this.m_attackSpeed & 63) != 0)
            {
                Debugger.Error(string.Format("Invalid attack speed {0} (must be multiple of 64)", this.m_attackSpeed));
            }

            this.m_burstCount             = row.GetClampedIntegerValue("BurstCount", idx);
            this.m_burstDelay             = row.GetClampedIntegerValue("BurstDelay", idx);
            this.m_altBurstCount          = row.GetClampedIntegerValue("AltBurstCount", idx);
            this.m_altBurstDelay          = row.GetClampedIntegerValue("AltBurstDelay", idx);
            this.m_dummyProjectileCount   = row.GetClampedIntegerValue("DummyProjectileCount", idx);
            this.m_attackEffectSharedData = LogicDataTables.GetEffectByName(row.GetClampedValue("AttackEffectShared", idx), data);
            this.m_chainAttackDistance    = row.GetClampedIntegerValue("ChainAttackDistance", idx);
            this.m_newTargetAttackDelay   = row.GetClampedIntegerValue("NewTargetAttackDelay", idx);

            if (this.m_newTargetAttackDelay > 0)
            {
                this.m_newTargetAttackDelay = LogicMath.Clamp(attackSpeed - this.m_newTargetAttackDelay, 0, attackSpeed);
            }
        }
Esempio n. 23
0
        /// <summary>
        ///     Called when the clearing of this <see cref="LogicObstacle"/> instance is finished.
        /// </summary>
        public void ClearingFinished(bool ignoreState)
        {
            int state = this._level.GetState();

            if (state == 1 || !LogicDataTables.GetGlobals().CompleteConstructionOnlyHome() && ignoreState)
            {
                if (this._level.GetHomeOwnerAvatar().IsClientAvatar())
                {
                    LogicClientAvatar homeOwnerAvatar  = (LogicClientAvatar)this._level.GetHomeOwnerAvatar();
                    LogicObstacleData obstacleData     = this.GetObstacleData();
                    LogicResourceData lootResourceData = obstacleData.GetLootResourceData();
                    int lootCount = obstacleData.GetLootCount();

                    if (obstacleData.IsLootCart())
                    {
                        LogicComponent component     = this.GetComponent(14);
                        LogicDataTable resourceTable = LogicDataTables.GetTable(2);

                        if (component != null && resourceTable.GetItemCount() > 0)
                        {
                            for (int i = 0; i < resourceTable.GetItemCount(); i++)
                            {
                                // TODO: Implement LootCart.
                            }
                        }
                    }

                    if (!obstacleData.IsTombstone && !obstacleData.IsLootCart())
                    {
                        this._level.GetAchievementManager().ObstacleCleared();
                    }

                    this._level.GetWorkerManagerAt(this._villageType).DeallocateWorker(this);
                    this.XpGainHelper(LogicGamePlayUtil.TimeToExp(obstacleData.GetClearTime()), homeOwnerAvatar, ignoreState || state == 1);

                    if (lootResourceData != null && lootCount > 0)
                    {
                        if (homeOwnerAvatar != null)
                        {
                            if (lootResourceData.PremiumCurrency)
                            {
                                int lootMultipler = 1;

                                if (this._lootMultiplyVersion >= 2)
                                {
                                    lootMultipler = obstacleData.GetLootMultiplierVersion2();
                                }

                                int diamondsCount = obstacleData.GetName().Equals("Bonus Gembox")
                                    ? lootCount * lootMultipler
                                    : this._level.GetGameObjectManagerAt(this._villageType).IncreaseObstacleClearCounter(lootMultipler);

                                if (diamondsCount > 0)
                                {
                                    Debugger.Print("LogicObstacle::clearingFinished diamonds reward: " + diamondsCount);

                                    homeOwnerAvatar.SetDiamonds(homeOwnerAvatar.GetDiamonds() + diamondsCount);
                                    homeOwnerAvatar.SetFreeDiamonds(homeOwnerAvatar.GetFreeDiamonds() + diamondsCount);
                                    homeOwnerAvatar.GetChangeListener().FreeDiamondsAdded(diamondsCount);
                                }
                            }
                            else
                            {
                                int gainCount = LogicMath.Min(homeOwnerAvatar.GetUnusedResourceCap(lootResourceData), lootCount);

                                if (gainCount > 0)
                                {
                                    homeOwnerAvatar.CommodityCountChangeHelper(0, lootResourceData, gainCount);
                                }
                            }
                        }
                        else
                        {
                            Debugger.Error("LogicObstacle::clearingFinished - Home owner avatar is NULL!");
                        }
                    }

                    if (obstacleData.GetVillageType() == this._level.GetVillageType())
                    {
                        // ?
                    }

                    if (this._clearTimer != null)
                    {
                        this._clearTimer.Destruct();
                        this._clearTimer = null;
                    }

                    this._fadeTime = 1;
                }
            }
        }
        public override int Execute(LogicLevel level)
        {
            if (this.m_resourceData != null && this.m_resourceCount > 0 && !this.m_resourceData.IsPremiumCurrency())
            {
                LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                if (this.m_resource2Data != null && this.m_resource2Count > 0)
                {
                    if (playerAvatar.GetUnusedResourceCap(this.m_resourceData) >= this.m_resourceCount &&
                        playerAvatar.GetUnusedResourceCap(this.m_resource2Data) >= this.m_resource2Count)
                    {
                        int resourceCost  = LogicGamePlayUtil.GetResourceDiamondCost(this.m_resourceCount, this.m_resourceData);
                        int resourceCost2 = LogicGamePlayUtil.GetResourceDiamondCost(this.m_resource2Count, this.m_resource2Data);

                        if (playerAvatar.HasEnoughDiamonds(resourceCost + resourceCost2, true, level))
                        {
                            playerAvatar.UseDiamonds(resourceCost + resourceCost2);
                            playerAvatar.CommodityCountChangeHelper(0, this.m_resourceData, this.m_resourceCount);
                            playerAvatar.CommodityCountChangeHelper(0, this.m_resource2Data, this.m_resource2Count);
                            playerAvatar.GetChangeListener().DiamondPurchaseMade(5, this.m_resource2Data.GetGlobalID(), this.m_resource2Count, resourceCost + resourceCost2,
                                                                                 level.GetVillageType());

                            if (this.m_command != null)
                            {
                                int cmdType = (int)this.m_command.GetCommandType();

                                if (cmdType < 1000)
                                {
                                    if (cmdType >= 500 && cmdType < 700)
                                    {
                                        this.m_command.Execute(level);
                                    }
                                }
                            }

                            return(0);
                        }
                    }
                }
                else
                {
                    if (playerAvatar.GetUnusedResourceCap(this.m_resourceData) >= this.m_resourceCount)
                    {
                        int resourceCost = LogicGamePlayUtil.GetResourceDiamondCost(this.m_resourceCount, this.m_resourceData);

                        if (playerAvatar.HasEnoughDiamonds(resourceCost, true, level))
                        {
                            playerAvatar.UseDiamonds(resourceCost);
                            playerAvatar.CommodityCountChangeHelper(0, this.m_resourceData, this.m_resourceCount);
                            playerAvatar.GetChangeListener().DiamondPurchaseMade(5, this.m_resourceData.GetGlobalID(), this.m_resourceCount, resourceCost, level.GetVillageType());

                            if (this.m_command != null)
                            {
                                int cmdType = (int)this.m_command.GetCommandType();

                                if (cmdType < 1000)
                                {
                                    if (cmdType >= 500 && cmdType < 700)
                                    {
                                        this.m_command.Execute(level);
                                    }
                                }
                            }

                            return(0);
                        }
                    }
                }
            }

            return(-1);
        }
Esempio n. 25
0
        public void SetBattleOver()
        {
            if (this.m_battleOver)
            {
                return;
            }

            this.m_level.GetBattleLog().SetBattleEnded(LogicDataTables.GetGlobals().GetAttackLengthSecs() - this.GetRemainingAttackSeconds());
            this.m_level.GetMissionManager().Tick();

            LogicArrayList <LogicComponent> components = this.m_level.GetComponentManager().GetComponents(LogicComponentType.COMBAT);

            for (int i = 0; i < components.Size(); i++)
            {
                ((LogicCombatComponent)components[i]).Boost(0, 0, 0);
            }

            bool duelMatch = (this.m_level.GetMatchType() & 0xFFFFFFFE) == 8;

            if (duelMatch)
            {
                LogicAvatar avatar = this.m_level.GetVisitorAvatar();

                if (avatar != null && avatar.IsClientAvatar())
                {
                    ((LogicClientAvatar)avatar).RemoveUnitsVillage2();
                }
            }

            if (this.m_state == 3)
            {
                this.EndDefendState();
            }
            else
            {
                LogicBattleLog battleLog = this.m_level.GetBattleLog();

                if (battleLog.GetBattleStarted())
                {
                    LogicAvatar visitorAvatar   = this.m_level.GetVisitorAvatar();
                    LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();

                    int stars = battleLog.GetStars();

                    if (!this.m_level.GetVisitorAvatar().IsClientAvatar() || !this.m_level.GetHomeOwnerAvatar().IsClientAvatar())
                    {
                        if (visitorAvatar.IsClientAvatar() && homeOwnerAvatar.IsNpcAvatar())
                        {
                            LogicNpcAvatar npcAvatar = (LogicNpcAvatar)homeOwnerAvatar;
                            LogicNpcData   npcData   = npcAvatar.GetNpcData();

                            int npcStars = visitorAvatar.GetNpcStars(npcData);

                            if (stars > npcStars && npcData.IsSinglePlayer())
                            {
                                visitorAvatar.SetNpcStars(npcData, stars);
                                visitorAvatar.GetChangeListener().CommodityCountChanged(0, npcData, stars);
                            }

                            // TODO: LogicBattleLog::sendNpcAttackEndEvents.
                        }
                    }
                    else
                    {
                        LogicClientAvatar attacker = (LogicClientAvatar)visitorAvatar;
                        LogicClientAvatar defender = (LogicClientAvatar)homeOwnerAvatar;

                        int originalAttackerScore = attacker.GetScore();
                        int originalDefenderScore = defender.GetScore();
                        int matchType             = this.m_level.GetMatchType();

                        if (matchType == 1 || !LogicDataTables.GetGlobals().ScoringOnlyFromMatchedMode() && (matchType == 0 || matchType == 2 || matchType == 4 || matchType == 6))
                        {
                            LogicGamePlayUtil.CalculateCombatScore(attacker, defender, stars, false,
                                                                   matchType == 4, battleLog.GetDestructionPercentage(), this.m_calendar.GetStarBonusMultiplier(), duelMatch);

                            if (!duelMatch && homeOwnerAvatar.GetTownHallLevel() >= LogicDataTables.GetGlobals().GetLootCartEnabledTownHall())
                            {
                                LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE);

                                if (resourceTable.GetItemCount() > 0)
                                {
                                    bool hasStolen = false;

                                    for (int i = 0; i < resourceTable.GetItemCount(); i++)
                                    {
                                        LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i);

                                        if (!data.IsPremiumCurrency())
                                        {
                                            if (battleLog.GetStolenResources(data) > 0)
                                            {
                                                hasStolen = true;
                                            }
                                        }
                                    }

                                    if (hasStolen)
                                    {
                                        LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(0);
                                        LogicObstacle          lootCart          = gameObjectManager.GetLootCart();

                                        if (lootCart == null)
                                        {
                                            gameObjectManager.AddLootCart();
                                            lootCart = gameObjectManager.GetLootCart();
                                        }

                                        if (lootCart != null)
                                        {
                                            LogicLootCartComponent lootCartComponent = lootCart.GetLootCartComponent();

                                            if (lootCartComponent != null)
                                            {
                                                for (int i = 0; i < resourceTable.GetItemCount(); i++)
                                                {
                                                    LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i);

                                                    if (!data.IsPremiumCurrency() && data.GetWarResourceReferenceData() == null)
                                                    {
                                                        int lootPercentage = lootCart.GetObstacleData().GetLootDefensePercentage();
                                                        int lootCount      = battleLog.GetStolenResources(data) * lootPercentage / 100;

                                                        lootCartComponent.SetResourceCount(i,
                                                                                           LogicMath.Min(LogicMath.Max(lootCount, lootCartComponent.GetResourceCount(i)),
                                                                                                         lootCartComponent.GetCapacityCount(i)));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            this.m_level.UpdateBattleShieldStatus(false);

                            if (stars > 0)
                            {
                                LogicArrayList <LogicDataSlot> castedUnits         = battleLog.GetCastedUnits();
                                LogicArrayList <LogicDataSlot> castedSpells        = battleLog.GetCastedSpells();
                                LogicArrayList <LogicUnitSlot> castedAllianceUnits = battleLog.GetCastedAllianceUnits();

                                LogicArrayList <LogicDataSlot> placedUnits = new LogicArrayList <LogicDataSlot>(castedUnits.Size());

                                for (int i = 0; i < castedUnits.Size(); i++)
                                {
                                    placedUnits.Add(new LogicDataSlot(castedUnits[i].GetData(), castedUnits[i].GetCount()));
                                }

                                for (int i = 0; i < castedSpells.Size(); i++)
                                {
                                    int idx = -1;

                                    for (int j = 0; j < placedUnits.Size(); j++)
                                    {
                                        if (placedUnits[j].GetData() == castedSpells[i].GetData())
                                        {
                                            idx = j;
                                            break;
                                        }
                                    }

                                    if (idx != -1)
                                    {
                                        placedUnits[idx].SetCount(placedUnits[idx].GetCount() + castedSpells[i].GetCount());
                                    }
                                    else
                                    {
                                        placedUnits.Add(new LogicDataSlot(castedSpells[i].GetData(), castedSpells[i].GetCount()));
                                    }
                                }

                                for (int i = 0; i < castedAllianceUnits.Size(); i++)
                                {
                                    placedUnits.Add(new LogicDataSlot(castedAllianceUnits[i].GetData(), castedAllianceUnits[i].GetCount()));
                                }

                                for (int i = 0; i < placedUnits.Size(); i++)
                                {
                                    LogicCombatItemData   data = (LogicCombatItemData)placedUnits[i].GetData();
                                    LogicCalendarUseTroop calendarUseTroopEvent = this.m_calendar.GetUseTroopEvents(data);

                                    if (calendarUseTroopEvent != null)
                                    {
                                        int count = attacker.GetEventUnitCounterCount(data);

                                        if (placedUnits[i].GetCount() >= count >> 16)
                                        {
                                            int progressCount = (short)count + 1;
                                            int eventCounter  = progressCount | (int)(count & 0xFFFF0000);

                                            attacker.SetCommodityCount(6, data, eventCounter);
                                            attacker.GetChangeListener().CommodityCountChanged(6, data, eventCounter);

                                            if (calendarUseTroopEvent.GetParameter(0) == progressCount)
                                            {
                                                int diamonds = calendarUseTroopEvent.GetParameter(2);
                                                int xp       = calendarUseTroopEvent.GetParameter(3);

                                                attacker.XpGainHelper(xp);
                                                attacker.SetDiamonds(attacker.GetDiamonds() + diamonds);
                                                attacker.SetFreeDiamonds(attacker.GetFreeDiamonds() + diamonds);
                                                attacker.GetChangeListener().FreeDiamondsAdded(diamonds, 9);

                                                Debugger.HudPrint(string.Format("USE TROOP Event: Awarding XP: {0} GEMS {1}", xp, diamonds));
                                            }
                                        }
                                    }
                                }

                                for (int i = 0; i < placedUnits.Size(); i++)
                                {
                                    placedUnits[i].Destruct();
                                }

                                placedUnits.Destruct();
                            }
                        }

                        if (this.m_state != 5 &&
                            this.m_level.GetDefenseShieldActivatedHours() == 0 &&
                            battleLog.GetDestructionPercentage() > 0)
                        {
                            int defenseVillageGuardCounter = defender.GetDefenseVillageGuardCounter() + 1;

                            defender.SetDefenseVillageGuardCounter(defenseVillageGuardCounter);
                            defender.GetChangeListener().DefenseVillageGuardCounterChanged(defenseVillageGuardCounter);

                            int villageGuardMins = (defenseVillageGuardCounter & 0xFFFFFF) == 3 * ((defenseVillageGuardCounter & 0xFFFFFF) / 3)
                                ? defender.GetLeagueTypeData().GetVillageGuardInMins()
                                : LogicDataTables.GetGlobals().GetDefaultDefenseVillageGuard();

                            this.m_level.GetHome().GetChangeListener().GuardActivated(60 * villageGuardMins);

                            Debugger.HudPrint(string.Format("Battle end. No Shield, Village Guard for defender: {0}", villageGuardMins));
                        }

                        battleLog.SetAttackerScore(attacker.GetScore() - originalAttackerScore);
                        battleLog.SetDefenderScore(defender.GetScore() - originalDefenderScore);
                        battleLog.SetOriginalAttackerScore(originalAttackerScore);
                        battleLog.SetOriginalDefenderScore(originalDefenderScore);

                        if (this.m_state != 5)
                        {
                            if (stars != 0)
                            {
                                if (matchType != 3 && matchType != 7 && matchType != 8 && matchType != 9)
                                {
                                    if (matchType == 5)
                                    {
                                        if (stars > this.m_level.GetPreviousAttackStars() && !this.m_level.GetIgnoreAttack())
                                        {
                                            this.m_level.GetAchievementManager().IncreaseWarStars(stars);
                                        }
                                    }
                                    else
                                    {
                                        this.m_level.GetAchievementManager().PvpAttackWon();
                                    }
                                }
                            }
                            else if (matchType > 9 || matchType == 3 || matchType == 5 || matchType == 7 || matchType == 8 || matchType == 9)
                            {
                                this.m_level.GetAchievementManager().PvpDefenseWon();
                            }
                        }
                    }
                }
            }

            this.m_battleOver = true;
        }
        public override void CreateReferences()
        {
            base.CreateReferences();

            this.m_damage                     = new int[this.m_upgradeLevelCount];
            this.m_troopDamagePermil          = new int[this.m_upgradeLevelCount];
            this.m_buildingDamagePermil       = new int[this.m_upgradeLevelCount];
            this.m_executeHealthPermil        = new int[this.m_upgradeLevelCount];
            this.m_damagePermilMin            = new int[this.m_upgradeLevelCount];
            this.m_preferredDamagePermilMin   = new int[this.m_upgradeLevelCount];
            this.m_boostTimeMS                = new int[this.m_upgradeLevelCount];
            this.m_speedBoost                 = new int[this.m_upgradeLevelCount];
            this.m_speedBoost2                = new int[this.m_upgradeLevelCount];
            this.m_damageBoostPercent         = new int[this.m_upgradeLevelCount];
            this.m_duplicateLifetime          = new int[this.m_upgradeLevelCount];
            this.m_duplicateHousing           = new int[this.m_upgradeLevelCount];
            this.m_radius                     = new int[this.m_upgradeLevelCount];
            this.m_numberOfHits               = new int[this.m_upgradeLevelCount];
            this.m_randomRadius               = new int[this.m_upgradeLevelCount];
            this.m_timeBetweenHitsMS          = new int[this.m_upgradeLevelCount];
            this.m_jumpBoostMS                = new int[this.m_upgradeLevelCount];
            this.m_jumpHousingLimit           = new int[this.m_upgradeLevelCount];
            this.m_freezeTimeMS               = new int[this.m_upgradeLevelCount];
            this.m_strengthWeight             = new int[this.m_upgradeLevelCount];
            this.m_buildingDamageBoostPercent = new int[this.m_upgradeLevelCount];
            this.m_shieldProjectileSpeed      = new int[this.m_upgradeLevelCount];
            this.m_shieldProjectileDamageMod  = new int[this.m_upgradeLevelCount];
            this.m_extraHealthPermil          = new int[this.m_upgradeLevelCount];
            this.m_extraHealthMin             = new int[this.m_upgradeLevelCount];
            this.m_extraHealthMax             = new int[this.m_upgradeLevelCount];
            this.m_poisonDamage               = new int[this.m_upgradeLevelCount];
            this.m_attackSpeedBoost           = new int[this.m_upgradeLevelCount];
            this.m_invulnerabilityTime        = new int[this.m_upgradeLevelCount];
            this.m_maxUnitsHit                = new int[this.m_upgradeLevelCount];
            this.m_unitsToSpawn               = new int[this.m_upgradeLevelCount];
            this.m_spawnDuration              = new int[this.m_upgradeLevelCount];

            this.m_preDeployEffect   = new LogicEffectData[this.m_upgradeLevelCount];
            this.m_deployEffect      = new LogicEffectData[this.m_upgradeLevelCount];
            this.m_deployEffect2     = new LogicEffectData[this.m_upgradeLevelCount];
            this.m_enemyDeployEffect = new LogicEffectData[this.m_upgradeLevelCount];
            this.m_chargingEffect    = new LogicEffectData[this.m_upgradeLevelCount];
            this.m_hitEffect         = new LogicEffectData[this.m_upgradeLevelCount];

            for (int i = 0; i < this.m_upgradeLevelCount; i++)
            {
                this.m_damage[i]                     = LogicGamePlayUtil.DPSToSingleHit(this.GetClampedIntegerValue("Damage", i), 1000);
                this.m_troopDamagePermil[i]          = this.GetClampedIntegerValue("TroopDamagePermil", i);
                this.m_buildingDamagePermil[i]       = this.GetClampedIntegerValue("BuildingDamagePermil", i);
                this.m_executeHealthPermil[i]        = this.GetClampedIntegerValue("ExecuteHealthPermil", i);
                this.m_damagePermilMin[i]            = this.GetClampedIntegerValue("DamagePermilMin", i);
                this.m_preferredDamagePermilMin[i]   = this.GetClampedIntegerValue("PreferredDamagePermilMin", i);
                this.m_boostTimeMS[i]                = this.GetClampedIntegerValue("BoostTimeMS", i);
                this.m_speedBoost[i]                 = this.GetClampedIntegerValue("SpeedBoost", i);
                this.m_speedBoost2[i]                = this.GetClampedIntegerValue("SpeedBoost2", i);
                this.m_damageBoostPercent[i]         = this.GetClampedIntegerValue("DamageBoostPercent", i);
                this.m_duplicateLifetime[i]          = this.GetClampedIntegerValue("DuplicateLifetime", i);
                this.m_duplicateHousing[i]           = this.GetClampedIntegerValue("DuplicateHousing", i);
                this.m_radius[i]                     = (this.GetClampedIntegerValue("Radius", i) << 9) / 100;
                this.m_numberOfHits[i]               = this.GetClampedIntegerValue("NumberOfHits", i);
                this.m_randomRadius[i]               = (this.GetClampedIntegerValue("RandomRadius", i) << 9) / 100;
                this.m_timeBetweenHitsMS[i]          = this.GetClampedIntegerValue("TimeBetweenHitsMS", i);
                this.m_jumpBoostMS[i]                = this.GetClampedIntegerValue("JumpBoostMS", i);
                this.m_jumpHousingLimit[i]           = this.GetClampedIntegerValue("JumpHousingLimit", i);
                this.m_hitEffect[i]                  = LogicDataTables.GetEffectByName(this.GetClampedValue("HitEffect", i), this);
                this.m_chargingEffect[i]             = LogicDataTables.GetEffectByName(this.GetClampedValue("ChargingEffect", i), this);
                this.m_preDeployEffect[i]            = LogicDataTables.GetEffectByName(this.GetClampedValue("PreDeployEffect", i), this);
                this.m_deployEffect[i]               = LogicDataTables.GetEffectByName(this.GetClampedValue("DeployEffect", i), this);
                this.m_enemyDeployEffect[i]          = LogicDataTables.GetEffectByName(this.GetClampedValue("EnemyDeployEffect", i), this);
                this.m_deployEffect2[i]              = LogicDataTables.GetEffectByName(this.GetClampedValue("DeployEffect2", i), this);
                this.m_freezeTimeMS[i]               = this.GetClampedIntegerValue("FreezeTimeMS", i);
                this.m_strengthWeight[i]             = this.GetClampedIntegerValue("StrengthWeight", i);
                this.m_buildingDamageBoostPercent[i] = this.GetClampedIntegerValue("BuildingDamageBoostPercent", i);
                this.m_shieldProjectileSpeed[i]      = this.GetClampedIntegerValue("ShieldProjectileSpeed", i);
                this.m_shieldProjectileDamageMod[i]  = this.GetClampedIntegerValue("ShieldProjectileDamageMod", i);
                this.m_extraHealthPermil[i]          = this.GetClampedIntegerValue("ExtraHealthPermil", i);
                this.m_extraHealthMin[i]             = this.GetClampedIntegerValue("ExtraHealthMin", i);
                this.m_extraHealthMax[i]             = this.GetClampedIntegerValue("ExtraHealthMax", i);
                this.m_poisonDamage[i]               = LogicGamePlayUtil.DPSToSingleHit(this.GetClampedIntegerValue("PoisonDPS", i), 1000);
                this.m_attackSpeedBoost[i]           = this.GetClampedIntegerValue("AttackSpeedBoost", i);
                this.m_invulnerabilityTime[i]        = this.GetClampedIntegerValue("InvulnerabilityTime", i);
                this.m_maxUnitsHit[i]                = this.GetClampedIntegerValue("MaxUnitsHit", i);
                this.m_unitsToSpawn[i]               = this.GetClampedIntegerValue("UnitsToSpawn", i);
                this.m_spawnDuration[i]              = this.GetClampedIntegerValue("SpawnDuration", i);
            }

            this.m_poisonIncreaseSlowly   = this.GetBooleanValue("PoisonIncreaseSlowly", 0);
            this.m_poisonAffectAir        = this.GetBooleanValue("PoisonAffectAir", 0);
            this.m_spawnFirstGroupSize    = this.GetIntegerValue("SpawnFirstGroupSize", 0);
            this.m_scaleByTownHall        = this.GetBooleanValue("ScaleByTH", 0);
            this.m_pauseCombatComponentMs = this.GetIntegerValue("PauseCombatComponentsMs", 0);
            this.m_damageTHPercent        = this.GetIntegerValue("DamageTHPercent", 0);

            if (this.m_damageTHPercent <= 0)
            {
                this.m_damageTHPercent = 100;
            }

            this.m_shrinkReduceSpeedRatio = this.GetIntegerValue("ShrinkReduceSpeedRatio", 0);
            this.m_shrinkHitpointsRatio   = this.GetIntegerValue("ShrinkHitpointsRatio", 0);
            this.m_deployEffect2Delay     = this.GetIntegerValue("DeployEffect2Delay", 0);
            this.m_hitTimeMS                  = this.GetIntegerValue("HitTimeMS", 0);
            this.m_deployTimeMS               = this.GetIntegerValue("DeployTimeMS", 0);
            this.m_chargingTimeMS             = this.GetIntegerValue("ChargingTimeMS", 0);
            this.m_spellForgeLevel            = this.GetIntegerValue("SpellForgeLevel", 0) - 1;
            this.m_randomRadiusAffectsOnlyGfx = this.GetBooleanValue("RandomRadiusAffectsOnlyGfx", 0);
            this.m_spawnObstacle              = LogicDataTables.GetObstacleByName(this.GetValue("SpawnObstacle", 0), this);
            this.m_numObstacles               = this.GetIntegerValue("NumObstacles", 0);
            this.m_troopsOnly                 = this.GetBooleanValue("TroopsOnly", 0);
            this.m_targetInfoString           = this.GetValue("TargetInfoString", 0);

            string preferredTarget = this.GetValue("PreferredTarget", 0);

            if (preferredTarget.Length != 0)
            {
                this.m_preferredTarget = LogicDataTables.GetBuildingClassByName(preferredTarget, null);

                if (this.m_preferredTarget == null)
                {
                    this.m_preferredTarget = LogicDataTables.GetBuildingByName(preferredTarget, null);

                    if (this.m_preferredTarget == null)
                    {
                        this.m_preferredTarget = LogicDataTables.GetCharacterByName(preferredTarget, null);

                        if (this.m_preferredTarget == null)
                        {
                            Debugger.Warning(string.Format("CSV row ({0}) has an invalid reference ({1})", this.GetName(), preferredTarget));
                        }
                    }
                }
            }

            this.m_preferredTargetDamageMod = this.GetIntegerValue("PreferredTargetDamageMod", 0);

            if (this.m_preferredTargetDamageMod == 0)
            {
                this.m_preferredTargetDamageMod = 100;
            }

            this.m_heroDamageMultiplier = this.GetIntegerValue("HeroDamageMultiplier", 0);

            if (this.m_heroDamageMultiplier == 0)
            {
                this.m_heroDamageMultiplier = 100;
            }

            this.m_snapToGrid          = this.GetBooleanValue("SnapToGrid", 0);
            this.m_boostDefenders      = this.GetBooleanValue("BoostDefenders", 0);
            this.m_boostLinkedToPoison = this.GetBooleanValue("BoostLinkedToPoison", 0);
            this.m_scaleDeployEffects  = this.GetBooleanValue("ScaleDeployEffects", 0);
            this.m_summonTroop         = LogicDataTables.GetCharacterByName(this.GetValue("SummonTroop", 0), null);
        }
Esempio n. 27
0
 public int GetDieDamage(int upgLevel)
 {
     return(LogicGamePlayUtil.DPSToSingleHit(this.m_dieDamage[upgLevel], 1000));
 }
Esempio n. 28
0
        /// <summary>
        ///     Executes this command.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            if (this._resourceData != null && this._resourceCount > 0 && !this._resourceData.PremiumCurrency)
            {
                LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                if (this._resource2Data != null && this._resource2Count > 0)
                {
                    int resourceCost  = LogicGamePlayUtil.GetResourceDiamondCost(this._resourceCount, this._resourceData);
                    int resourceCost2 = LogicGamePlayUtil.GetResourceDiamondCost(this._resource2Count, this._resource2Data);

                    if (playerAvatar.GetUnusedResourceCap(this._resourceData) >= this._resourceCount &&
                        playerAvatar.GetUnusedResourceCap(this._resource2Data) >= this._resource2Count)
                    {
                        if (playerAvatar.HasEnoughDiamonds(resourceCost + resourceCost2, true, level))
                        {
                            playerAvatar.UseDiamonds(resourceCost + resourceCost2);
                            playerAvatar.CommodityCountChangeHelper(0, this._resourceData, this._resourceCount);
                            playerAvatar.CommodityCountChangeHelper(0, this._resource2Data, this._resource2Count);

                            Debugger.Print("LogicBuyResourcesCommand::execute buy resources: " + (resourceCost + resourceCost2));

                            if (this._command != null)
                            {
                                int cmdType = this._command.GetCommandType();

                                if (cmdType < 1000)
                                {
                                    if (cmdType >= 500 && cmdType < 700)
                                    {
                                        this._command.Execute(level);
                                    }
                                }
                            }

                            return(0);
                        }
                    }
                }
                else
                {
                    int resourceCost = LogicGamePlayUtil.GetResourceDiamondCost(this._resourceCount, this._resourceData);

                    if (playerAvatar.GetUnusedResourceCap(this._resourceData) >= this._resourceCount)
                    {
                        if (playerAvatar.HasEnoughDiamonds(resourceCost, true, level))
                        {
                            playerAvatar.UseDiamonds(resourceCost);
                            playerAvatar.CommodityCountChangeHelper(0, this._resourceData, this._resourceCount);

                            Debugger.Print("LogicBuyResourcesCommand::execute buy resources: " + resourceCost);

                            if (this._command != null)
                            {
                                int cmdType = this._command.GetCommandType();

                                if (cmdType < 1000)
                                {
                                    if (cmdType >= 500 && cmdType < 700)
                                    {
                                        this._command.Execute(level);
                                    }
                                }
                            }

                            return(0);
                        }
                    }
                }
            }

            return(-1);
        }
Esempio n. 29
0
        public override void Tick()
        {
            LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();

            if (homeOwnerAvatar != null)
            {
                this.m_updateAvatarCooldown += 64;

                if (this.m_updateAvatarCooldown > 1000)
                {
                    homeOwnerAvatar.UpdateStarBonusLimitCooldown();
                    homeOwnerAvatar.UpdateLootLimitCooldown();

                    this.m_updateAvatarCooldown -= 1000;
                }
            }

            if (this.m_parent.IsAlive())
            {
                if (!this.IsEmpty())
                {
                    if (this.m_bunkerSearchTime > 0)
                    {
                        this.m_bunkerSearchTime -= 64;
                    }
                    else
                    {
                        bool airTriggered = false;
                        bool groundLocked = false;

                        if (this.m_team == 1)
                        {
                            bool inAirDistance    = false;
                            bool inGroundDistance = false;

                            int clanCastleRadius = LogicDataTables.GetGlobals().GetClanCastleRadius();

                            if (LogicDataTables.GetGlobals().CastleTroopTargetFilter())
                            {
                                LogicCharacter closestGroundAttacker = this.ClosestAttacker(false);
                                LogicCharacter closestAirAttacker    = this.ClosestAttacker(true);

                                if (closestAirAttacker != null)
                                {
                                    inAirDistance = closestAirAttacker.GetPosition().GetDistanceSquaredTo(this.m_parent.GetX(), this.m_parent.GetY()) <
                                                    clanCastleRadius * clanCastleRadius;
                                }

                                if (closestGroundAttacker != null)
                                {
                                    inGroundDistance = closestGroundAttacker.GetPosition().GetDistanceSquaredTo(this.m_parent.GetX(), this.m_parent.GetY()) <
                                                       clanCastleRadius * clanCastleRadius;
                                }
                            }
                            else
                            {
                                LogicCharacter closestAttacker =
                                    (LogicCharacter)this.m_parent.GetLevel().GetGameObjectManager()
                                    .GetClosestGameObject(this.m_parent.GetX(), this.m_parent.GetY(), this.m_filter);

                                if (closestAttacker != null)
                                {
                                    inAirDistance = inGroundDistance = closestAttacker.GetPosition().GetDistanceSquaredTo(this.m_parent.GetX(), this.m_parent.GetY()) <
                                                                       clanCastleRadius * clanCastleRadius;
                                }
                            }

                            groundLocked = !inGroundDistance;
                            airTriggered = inAirDistance;

                            if (!airTriggered && groundLocked)
                            {
                                this.m_bunkerSearchTime = LogicDataTables.GetGlobals().GetBunkerSearchTime();
                                return;
                            }
                        }
                        else
                        {
                            airTriggered = true;
                        }

                        LogicCharacterData spawnData = null;
                        int spawnLevel = -1;

                        for (int i = 0; i < this.GetUnitTypeCount(); i++)
                        {
                            LogicCombatItemData data = this.GetUnitType(i);

                            if (data != null)
                            {
                                int count = this.GetUnitCount(i);

                                if (count > 0)
                                {
                                    int upgLevel = this.GetUnitLevel(i);

                                    if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                                    {
                                        LogicCharacterData    characterData    = (LogicCharacterData)data;
                                        LogicAttackerItemData attackerItemData = characterData.GetAttackerItemData(upgLevel);

                                        if (!(airTriggered & groundLocked) || attackerItemData.GetTrackAirTargets(false))
                                        {
                                            if (airTriggered | groundLocked || attackerItemData.GetTrackGroundTargets(false))
                                            {
                                                this.RemoveUnits(data, upgLevel, 1);

                                                spawnData  = characterData;
                                                spawnLevel = upgLevel;
                                            }
                                        }
                                    }
                                }
                            }

                            if (spawnData != null)
                            {
                                break;
                            }
                        }

                        if (spawnData != null)
                        {
                            LogicCharacter character =
                                (LogicCharacter)LogicGameObjectFactory.CreateGameObject(spawnData, this.m_parent.GetLevel(), this.m_parent.GetVillageType());

                            character.GetHitpointComponent().SetTeam(this.m_team);

                            if (character.GetChildTroops() != null)
                            {
                                LogicArrayList <LogicCharacter> childrens = character.GetChildTroops();

                                for (int i = 0; i < childrens.Size(); i++)
                                {
                                    childrens[i].GetHitpointComponent().SetTeam(this.m_team);
                                }
                            }

                            character.SetUpgradeLevel(spawnLevel == -1 ? 0 : spawnLevel);
                            character.SetAllianceUnit();

                            if (character.GetCharacterData().IsJumper())
                            {
                                character.GetMovementComponent().EnableJump(3600000);
                            }

                            if (this.m_team == 1)
                            {
                                if (LogicDataTables.GetGlobals().EnableDefendingAllianceTroopJump())
                                {
                                    character.GetMovementComponent().EnableJump(3600000);
                                }

                                if (LogicDataTables.GetGlobals().AllianceTroopsPatrol())
                                {
                                    character.GetCombatComponent().SetSearchRadius(LogicDataTables.GetGlobals().GetClanCastleRadius() >> 9);

                                    if (this.m_parent.GetGameObjectType() == LogicGameObjectType.BUILDING)
                                    {
                                        character.GetMovementComponent().SetBaseBuilding((LogicBuilding)this.m_parent);
                                    }
                                }
                            }
                            else
                            {
                                LogicAvatar visitorAvatar = this.m_parent.GetLevel().GetVisitorAvatar();

                                visitorAvatar.RemoveAllianceUnit(spawnData, spawnLevel);
                                visitorAvatar.GetChangeListener().AllianceUnitRemoved(spawnData, spawnLevel);

                                LogicBattleLog battleLog = this.m_parent.GetLevel().GetBattleLog();

                                battleLog.IncrementDeployedAllianceUnits(spawnData, 1, spawnLevel);
                                battleLog.SetAllianceUsed(true);
                            }

                            if (this.m_team == 1)
                            {
                                int spawnOffsetX = 0;
                                int spawnOffsetY = 0;

                                switch (this.m_troopSpawnOffset)
                                {
                                case 0:
                                    spawnOffsetX = 1;
                                    spawnOffsetY = 0;
                                    break;

                                case 1:
                                    spawnOffsetX = -1;
                                    spawnOffsetY = 0;
                                    break;

                                case 2:
                                    spawnOffsetX = 0;
                                    spawnOffsetY = 1;
                                    break;

                                case 3:
                                    spawnOffsetX = 0;
                                    spawnOffsetY = -1;
                                    break;
                                }

                                character.SetInitialPosition(this.m_parent.GetMidX() + ((this.m_parent.GetWidthInTiles() << 8) - 128) * spawnOffsetX,
                                                             this.m_parent.GetMidY() + ((this.m_parent.GetHeightInTiles() << 8) - 128) * spawnOffsetY);

                                if (++this.m_troopSpawnOffset > 3)
                                {
                                    this.m_troopSpawnOffset = 0;
                                }
                            }
                            else if (LogicDataTables.GetGlobals().AllowClanCastleDeployOnObstacles())
                            {
                                int posX = this.m_parent.GetX() + (this.m_parent.GetWidthInTiles() << 9) - 128;
                                int posY = this.m_parent.GetY() + (this.m_parent.GetHeightInTiles() << 8);

                                if (LogicGamePlayUtil.GetNearestValidAttackPos(this.m_parent.GetLevel(), posX, posY, out int outputX, out int outputY))
                                {
                                    character.SetInitialPosition(outputX, outputY);
                                }
                                else
                                {
                                    character.SetInitialPosition(posX, posY);
                                }
                            }
                            else
                            {
                                character.SetInitialPosition(this.m_parent.GetX() + (this.m_parent.GetWidthInTiles() << 9) - 128,
                                                             this.m_parent.GetY() + (this.m_parent.GetHeightInTiles() << 8));
                            }

                            this.m_parent.GetGameObjectManager().AddGameObject(character, -1);
                        }

                        this.m_bunkerSearchTime = LogicDataTables.GetGlobals().GetBunkerSearchTime();
                    }
                }
            }
Esempio n. 30
0
        /// <summary>
        ///     Finishes the construction of the <see cref="LogicBuilding"/>.
        /// </summary>
        public void FinishConstruction(bool ignoreState)
        {
            int state = this._level.GetState();

            if (state == 1 || !LogicDataTables.GetGlobals().CompleteConstructionOnlyHome() && ignoreState)
            {
                LogicAvatar homeOwnerAvatar = this._level.GetHomeOwnerAvatar();

                if (homeOwnerAvatar != null && homeOwnerAvatar.IsClientAvatar())
                {
                    LogicTrapData data = this.GetTrapData();

                    if (this._constructionTimer != null)
                    {
                        this._constructionTimer.Destruct();
                        this._constructionTimer = null;
                    }

                    this._level.GetWorkerManagerAt(this._data.GetVillageType()).DeallocateWorker(this);

                    if (this._upgLevel != 0 || this._upgrading)
                    {
                        if (this._upgLevel >= data.GetUpgradeLevelCount() - 1)
                        {
                            Debugger.Warning("LogicTrap - Trying to upgrade to level that doesn't exist! - " + data.GetName());
                            this._upgLevel = data.GetUpgradeLevelCount() - 1;
                        }
                        else
                        {
                            this._upgLevel += 1;
                        }
                    }

                    if (!ignoreState && !this._disarmed)
                    {
                        if (this.GetListener() != null)
                        {
                            // Listener.
                        }
                    }

                    this.XpGainHelper(LogicGamePlayUtil.TimeToExp(data.GetBuildTime(this._upgLevel)), homeOwnerAvatar, ignoreState);

                    if (this._disarmed)
                    {
                        // Listener.
                    }

                    this._fadeTime  = 0;
                    this._disarmed  = false;
                    this._upgrading = false;

                    if (this._listener != null)
                    {
                        this._listener.RefreshState();
                    }

                    if (state == 1)
                    {
                        this._level.GetAchievementManager().RefreshStatus();
                    }
                }
                else
                {
                    Debugger.Warning("LogicTrap::finishCostruction failed - Avatar is null or not client avatar");
                }
            }
        }