Esempio n. 1
0
 /// <summary>
 ///     Decodes this instnace.
 /// </summary>
 public override void Decode(ByteStream stream)
 {
     this._x            = stream.ReadInt();
     this._y            = stream.ReadInt();
     this._buildingData = (LogicBuildingData)stream.ReadDataReference(0);
     base.Decode(stream);
 }
Esempio n. 2
0
        private static bool CanUpgradeTHV2(LogicLevel level)
        {
            if (level.GetVillageType() == 1)
            {
                LogicDataTable buildingTable = LogicDataTables.GetTable(LogicDataType.BUILDING);

                for (int i = 0; i < buildingTable.GetItemCount(); i++)
                {
                    LogicBuildingData buildingData = (LogicBuildingData)buildingTable.GetItemAt(i);

                    if (buildingData.GetVillageType() == 1 &&
                        !level.IsBuildingCapReached(buildingData, false))
                    {
                        return(false);
                    }
                }

                LogicDataTable trapTable = LogicDataTables.GetTable(LogicDataType.TRAP);

                for (int i = 0; i < trapTable.GetItemCount(); i++)
                {
                    LogicTrapData trapData = (LogicTrapData)trapTable.GetItemAt(i);

                    if (trapData.GetVillageType() == 1 &&
                        !level.IsTrapCapReached(trapData, false))
                    {
                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }
        public override int Execute(LogicLevel level)
        {
            LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId);

            if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
            {
                LogicBuilding building = (LogicBuilding)gameObject;

                if (building.IsLocked())
                {
                    if (building.GetUpgradeLevel() == 0 && building.CanUnlock(true))
                    {
                        LogicBuildingData buildingData = building.GetBuildingData();

                        if (buildingData.GetConstructionTime(0, level, 0) == 0 || level.HasFreeWorkers(this, -1))
                        {
                            LogicClientAvatar playerAvatar  = level.GetPlayerAvatar();
                            LogicResourceData buildResource = buildingData.GetBuildResource(0);
                            int buildCost = buildingData.GetBuildCost(0, level);

                            if (playerAvatar.HasEnoughResources(buildResource, buildCost, true, this, false))
                            {
                                playerAvatar.CommodityCountChangeHelper(0, buildResource, -buildCost);
                                building.StartConstructing(true);
                                building.GetListener().RefreshState();

                                return(0);
                            }
                        }
                    }
                }
            }

            return(-1);
        }
Esempio n. 4
0
 /// <summary>
 ///     Destructs this instance.
 /// </summary>
 public override void Destruct()
 {
     base.Destruct();
     this._x            = 0;
     this._y            = 0;
     this._buildingData = null;
 }
Esempio n. 5
0
 public override void Decode(ByteStream stream)
 {
     this.m_x            = stream.ReadInt();
     this.m_y            = stream.ReadInt();
     this.m_buildingData = (LogicBuildingData)ByteStreamHelper.ReadDataReference(stream, LogicDataType.BUILDING);
     base.Decode(stream);
 }
Esempio n. 6
0
        public void IncrementDestroyedBuildingCount(LogicBuildingData data)
        {
            LogicBuildingClassData buildingClass = data.GetBuildingClass();

            if (buildingClass.IsTownHall() || buildingClass.IsTownHall2())
            {
                this.m_townhallDestroyed = true;
            }

            if (this.m_level != null)
            {
                LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();

                if (homeOwnerAvatar != null && homeOwnerAvatar.IsClientAvatar())
                {
                    if (this.m_level.GetState() == 2)
                    {
                        int matchType = this.m_level.GetMatchType();

                        if (matchType != 2 && matchType != 5)
                        {
                            this.m_level.GetAchievementManager().BuildingDestroyedInPvP(data);
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        public override void Destruct()
        {
            base.Destruct();

            this.m_buildingData  = null;
            this.m_buildingCount = 0;
            this.m_buildingLevel = 0;
        }
Esempio n. 8
0
        public override void ReadFromJSON(LogicJSONObject jsonObject)
        {
            base.ReadFromJSON(jsonObject);

            this.m_buildingData  = (LogicBuildingData)LogicJSONHelper.GetLogicData(jsonObject, "building");
            this.m_buildingCount = LogicJSONHelper.GetInt(jsonObject, "buildingNumber");
            this.m_buildingLevel = LogicJSONHelper.GetInt(jsonObject, "buildingLevel");
        }
Esempio n. 9
0
        public void StartUseTroopEvent(LogicAvatar homeOwnerAvatar, LogicLevel level)
        {
            if (homeOwnerAvatar != null)
            {
                for (int i = 0; i < this.m_useTroops.Size(); i++)
                {
                    LogicCalendarUseTroop calendarUseTroop = this.m_useTroops[i];
                    LogicCombatItemData   data             = calendarUseTroop.GetData();

                    int housingSpace;
                    int totalMaxHousing;
                    int unitCount;

                    if (data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                    {
                        housingSpace    = data.GetHousingSpace() * 2;
                        totalMaxHousing = data.GetHousingSpace() + 2 * (level.GetComponentManagerAt(data.GetVillageType()).GetTotalMaxHousing(data.GetCombatItemType()) *
                                                                        calendarUseTroop.GetParameter(1) / 100);
                        unitCount = totalMaxHousing / housingSpace;
                    }
                    else
                    {
                        LogicBuildingData troopHousingData      = LogicDataTables.GetBuildingByName("Troop Housing", null);
                        LogicBuildingData barrackData           = LogicDataTables.GetBuildingByName("Barrack", null);
                        LogicBuildingData darkElixirBarrackData = LogicDataTables.GetBuildingByName("Dark Elixir Barrack", null);

                        int townHallLevel        = homeOwnerAvatar.GetTownHallLevel();
                        int maxUpgradeLevelForTH = troopHousingData.GetMaxUpgradeLevelForTownHallLevel(townHallLevel);
                        int unitStorageCapacity  = troopHousingData.GetUnitStorageCapacity(maxUpgradeLevelForTH);

                        housingSpace = data.GetHousingSpace();

                        if (data.GetUnitOfType() == 1 && barrackData.GetRequiredTownHallLevel(data.GetRequiredProductionHouseLevel()) <= townHallLevel ||
                            data.GetUnitOfType() == 2 && darkElixirBarrackData.GetRequiredTownHallLevel(data.GetRequiredProductionHouseLevel()) <= townHallLevel)
                        {
                            int totalHousing = (int)((long)LogicDataTables.GetTownHallLevel(townHallLevel).GetUnlockedBuildingCount(troopHousingData) *
                                                     calendarUseTroop.GetParameter(1) *
                                                     unitStorageCapacity);
                            unitCount = (int)((housingSpace * 0.5f + totalHousing / 100) / housingSpace);
                        }
                        else
                        {
                            LogicBuildingData allianceCastleData = LogicDataTables.GetBuildingByName("Alliance Castle", null);

                            totalMaxHousing = allianceCastleData.GetUnitStorageCapacity(allianceCastleData.GetMaxUpgradeLevelForTownHallLevel(townHallLevel));
                            unitCount       = totalMaxHousing / housingSpace;
                        }
                    }

                    int eventCounter = LogicMath.Max(1, unitCount) << 16;

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

                    Debugger.HudPrint("EVENT: Use troop/spell event started!");
                }
            }
        }
Esempio n. 10
0
        public override int Execute(LogicLevel level)
        {
            LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId);

            if (gameObject != null)
            {
                if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                {
                    LogicBuilding     building     = (LogicBuilding)gameObject;
                    LogicBuildingData buildingData = building.GetBuildingData();

                    if (buildingData.GetGearUpBuildingData() == null || building.GetGearLevel() != 0)
                    {
                        if (building.GetAttackerItemData().HasAlternativeAttackMode())
                        {
                            LogicCombatComponent combatComponent = building.GetCombatComponent(false);

                            if (combatComponent != null)
                            {
                                combatComponent.ToggleAttackMode(this.m_layout, this.m_draftMode);

                                if (this.m_updateListener)
                                {
                                }

                                return(0);
                            }
                        }

                        return(-1);
                    }

                    return(-95);
                }

                if (gameObject.GetGameObjectType() == LogicGameObjectType.TRAP)
                {
                    LogicTrap trap = (LogicTrap)gameObject;

                    if (trap.HasAirMode())
                    {
                        trap.ToggleAirMode(this.m_layout, this.m_draftMode);

                        if (this.m_updateListener)
                        {
                        }

                        return(0);
                    }
                }
            }

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

            int upgLevel = 0;

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

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

                if (heroBaseComponent == null)
                {
                    return;
                }

                LogicBuildingData buildingData = building.GetBuildingData();

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

                LogicCombatComponent combatComponent = building.GetCombatComponent();

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

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

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

                if (avatar != null)
                {
                    avatar.GetChangeListener().CommodityCountChanged(0, data, secs);
                    avatar.SetHeroHealth(data, secs);
                }
            }
        }
        public static void AddDebugTroopsPreset(LogicLevel level, int townHallLevel, LogicClientAvatar playerAvatar)
        {
            if (playerAvatar != null)
            {
                LogicDataTable    characterTable = LogicDataTables.GetTable(LogicDataType.CHARACTER);
                LogicDataTable    spellTable     = LogicDataTables.GetTable(LogicDataType.SPELL);
                LogicBuildingData laboratoryData = LogicDataTables.GetBuildingByName("Laboratory", null);

                int laboratoryLevel = laboratoryData.GetMaxUpgradeLevelForTownHallLevel(townHallLevel);
                int totalHousing    = LogicDebugUtil.GetTotalCharacterMaxHousing(townHallLevel, true) / 5;

                for (int i = 0; i < characterTable.GetItemCount(); i++)
                {
                    playerAvatar.SetUnitCount((LogicCharacterData)characterTable.GetItemAt(i), 0);
                }

                for (int i = 0; i < spellTable.GetItemCount(); i++)
                {
                    playerAvatar.SetUnitCount((LogicSpellData)spellTable.GetItemAt(i), 0);
                }

                for (int i = 0; i < 7; i++)
                {
                    if (i != 2 && i != 5)
                    {
                        LogicCharacterData characterData = (LogicCharacterData)characterTable.GetItemAt(i);

                        if (characterData.GetVillageType() == 0)
                        {
                            int upgradeLevel = 0;

                            for (int j = characterData.GetUpgradeLevelCount(); j >= 2; j--)
                            {
                                int requiredLaboratoryLevel = characterData.GetRequiredLaboratoryLevel(j - 1);

                                if (laboratoryLevel >= requiredLaboratoryLevel)
                                {
                                    upgradeLevel = j - 1;
                                    break;
                                }
                            }

                            playerAvatar.SetUnitCount(characterData, totalHousing / characterData.GetHousingSpace());
                            playerAvatar.SetUnitUpgradeLevel(characterData, upgradeLevel);
                        }
                    }
                }
            }
            else
            {
                Debugger.Warning("addDebugTroopsPreset: pAvatar is NULL");
            }
        }
Esempio n. 13
0
        public override int Execute(LogicLevel level)
        {
            LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId);

            if (gameObject != null)
            {
                if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                {
                    LogicBuilding        building        = (LogicBuilding)gameObject;
                    LogicBuildingData    buildingData    = building.GetBuildingData();
                    LogicCombatComponent combatComponent = building.GetCombatComponent(false);

                    if (combatComponent != null && combatComponent.GetAttackerItemData().GetTargetingConeAngle() != 0)
                    {
                        if (this.m_baseLayout == -1)
                        {
                            combatComponent.ToggleAimAngle(buildingData.GetAimRotateStep(), this.m_layout, this.m_draftLayout);
                        }
                        else
                        {
                            int draftAngle   = combatComponent.GetAimAngle(this.m_baseLayout, this.m_baseDraftLayout);
                            int currentAngle = combatComponent.GetAimAngle(this.m_layout, this.m_draftLayout);

                            combatComponent.ToggleAimAngle(draftAngle - currentAngle, this.m_layout, this.m_draftLayout);
                        }

                        return(0);
                    }
                }
                else if (gameObject.GetGameObjectType() == LogicGameObjectType.TRAP)
                {
                    LogicTrap trap = (LogicTrap)gameObject;

                    if (trap.GetTrapData().GetDirectionCount() > 0)
                    {
                        if (this.m_baseLayout == -1)
                        {
                            trap.ToggleDirection(this.m_layout, this.m_draftLayout);
                        }
                        else
                        {
                            trap.SetDirection(this.m_layout, this.m_draftLayout, trap.GetDirection(this.m_baseLayout, this.m_baseDraftLayout));
                        }

                        return(0);
                    }

                    return(-21);
                }
            }

            return(-1);
        }
Esempio n. 14
0
        public override void Decode(ByteStream stream)
        {
            int count = LogicMath.Min(stream.ReadInt(), 10);

            for (int i = 0; i < count; i++)
            {
                this.m_position.Add(new LogicVector2(stream.ReadInt(), stream.ReadInt()));
            }

            this.m_buildingData = (LogicBuildingData)ByteStreamHelper.ReadDataReference(stream, LogicDataType.BUILDING);

            base.Decode(stream);
        }
Esempio n. 15
0
        public int GetBuildingBoostCost(LogicBuildingData data, int upgLevel)
        {
            for (int i = 0; i < this.m_buildingBoostCost.Size(); i++)
            {
                LogicDataSlot slot = this.m_buildingBoostCost[i];

                if (slot.GetData() == data)
                {
                    return(slot.GetCount());
                }
            }

            return(data.GetBoostCost(upgLevel));
        }
Esempio n. 16
0
        public void BuildingDestroyedInPvP(LogicBuildingData buildingData)
        {
            LogicDataTable    table        = LogicDataTables.GetTable(LogicDataType.ACHIEVEMENT);
            LogicClientAvatar playerAvatar = this.m_level.GetPlayerAvatar();

            for (int i = 0; i < table.GetItemCount(); i++)
            {
                LogicAchievementData data = (LogicAchievementData)table.GetItemAt(i);

                if (data.GetActionType() == LogicAchievementData.ACTION_TYPE_DESTROY && data.GetBuildingData() == buildingData)
                {
                    this.RefreshAchievementProgress(playerAvatar, data, playerAvatar.GetAchievementProgress(data) + 1);
                }
            }
        }
Esempio n. 17
0
        public int GetBuildingBoostCost(LogicBuildingData data, int upgLevel)
        {
            int buildingBoostCost = data.GetBoostCost(upgLevel);

            for (int i = this.m_activeCalendarEvents.Size() - 1; i >= 0; i--)
            {
                int cost = this.m_activeCalendarEvents[i].GetBuildingBoostCost(data, upgLevel);

                if (cost <= buildingBoostCost)
                {
                    buildingBoostCost = cost;
                }
            }

            return(buildingBoostCost);
        }
Esempio n. 18
0
        public bool IsBuildingUnlocked(LogicBuildingData buildingData)
        {
            LogicArrayList <LogicGameObject> gameObjects =
                this.m_level.GetGameObjectManagerAt(buildingData.GetVillageType()).GetGameObjects(LogicGameObjectType.BUILDING);

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

                if (building.GetData() == buildingData && !building.IsLocked())
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 19
0
        public override void Destruct()
        {
            base.Destruct();

            if (this.m_position != null)
            {
                for (int i = this.m_position.Size() - 1; i >= 0; i--)
                {
                    this.m_position[i].Destruct();
                    this.m_position.Remove(i);
                }

                this.m_position = null;
            }

            this.m_buildingData = null;
        }
        private void SpawnCharacter(int x, int y)
        {
            int idx = this.m_defenceTroopCount % 2;

            if (this.m_defenceTroopData[idx] == null)
            {
                idx = 0;
            }

            LogicBuilding     building     = (LogicBuilding)this.m_parent;
            LogicBuildingData buildingData = building.GetBuildingData();

            if (buildingData.IsEnabledInVillageType(this.m_parent.GetLevel().GetVillageType()) &&
                this.m_parent.GetLevel().GetState() != 1 &&
                this.m_parent.GetLevel().GetState() != 4)
            {
                LogicCharacterData data      = this.m_defenceTroopData[idx];
                LogicCharacter     character = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(data, this.m_parent.GetLevel(), this.m_parent.GetVillageType());

                character.SetInitialPosition(x, y);
                character.SetUpgradeLevel(this.m_defenceTroopUpgradeLevel - 1);
                character.GetHitpointComponent()?.SetTeam(1);

                if (LogicDataTables.GetGlobals().EnableDefendingAllianceTroopJump())
                {
                    character.GetMovementComponent().EnableJump(3600000);
                }

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

                character.GetCombatComponent().SetSearchRadius(LogicDataTables.GetGlobals().GetClanCastleRadius() >> 9);
                character.GetMovementComponent().GetMovementSystem().CreatePatrolArea(this.m_parent, this.m_parent.GetLevel(), true, this.m_defenceTroopCount);

                LogicDefenceUnitProductionComponent defenceUnitProductionComponent = building.GetDefenceUnitProduction();

                if (defenceUnitProductionComponent != null)
                {
                    defenceUnitProductionComponent.m_defenceTroops.Add(character);
                }

                ++this.m_defenceTroopCount;
            }
        }
        public static void Init()
        {
            GameBaseGenerator.HomeOwnerAvatar = new LogicClientAvatar();
            GameBaseGenerator.HomeOwnerAvatar.SetName("Supercell - Private CoC Server");
            GameBaseGenerator.HomeOwnerAvatar.SetExpLevel(500);
            GameBaseGenerator.HomeOwnerAvatar.SetScore(5000);
            GameBaseGenerator.HomeOwnerAvatar.SetLeagueType(LogicDataTables.GetTable(LogicDataType.LEAGUE).GetItemCount() - 1);

            GameBaseGenerator.m_random = new LogicRandom(Environment.TickCount);
            GameBaseGenerator.m_defenseBuildingArray = new LogicArrayList <LogicBuildingData>();
            GameBaseGenerator.m_otherBuildingArray   = new LogicArrayList <LogicBuildingData>();
            GameBaseGenerator.m_trapArray            = new LogicArrayList <LogicTrapData>();

            LogicDataTable buildingTable = LogicDataTables.GetTable(LogicDataType.BUILDING);
            LogicDataTable trapTable     = LogicDataTables.GetTable(LogicDataType.TRAP);

            for (int i = 0; i < buildingTable.GetItemCount(); i++)
            {
                LogicBuildingData buildingData = (LogicBuildingData)buildingTable.GetItemAt(i);

                if (buildingData.IsEnabledInVillageType(0))
                {
                    if (buildingData.GetBuildingClass().GetName() == "Defense")
                    {
                        GameBaseGenerator.m_defenseBuildingArray.Add(buildingData);
                    }
                    else
                    {
                        GameBaseGenerator.m_otherBuildingArray.Add(buildingData);
                    }
                }
            }

            for (int i = 0; i < trapTable.GetItemCount(); i++)
            {
                LogicTrapData trapData = (LogicTrapData)trapTable.GetItemAt(i);

                if (trapData.IsEnabledInVillageType(0))
                {
                    GameBaseGenerator.m_trapArray.Add(trapData);
                }
            }
        }
        public static int GetTotalCharacterMaxHousing(int townHallLevel, bool includeAllianceCastle)
        {
            LogicTownhallLevelData townhallLevelData = LogicDataTables.GetTownHallLevel(townHallLevel);
            LogicDataTable         table             = LogicDataTables.GetTable(LogicDataType.BUILDING);

            int housingSpace = 0;

            for (int i = 0; i < table.GetItemCount(); i++)
            {
                LogicBuildingData buildingData = (LogicBuildingData)table.GetItemAt(i);

                if (includeAllianceCastle || buildingData != LogicDataTables.GetAllianceCastleData())
                {
                    int unlockedBuildingCount = townhallLevelData.GetUnlockedBuildingCount(buildingData);

                    if (unlockedBuildingCount > 0 && !buildingData.IsForgesSpells())
                    {
                        housingSpace += unlockedBuildingCount * buildingData.GetUnitStorageCapacity(buildingData.GetMaxUpgradeLevelForTownHallLevel(townHallLevel));
                    }
                }
            }

            return(housingSpace);
        }
Esempio n. 23
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="LogicBuyBuildingCommand" /> class.
 /// </summary>
 public LogicBuyBuildingCommand(int x, int y, LogicBuildingData buildingData)
 {
     this._x            = x;
     this._y            = y;
     this._buildingData = buildingData;
 }
 public virtual void BuildingGearUpCapReached(LogicBuildingData data)
 {
 }
Esempio n. 25
0
 /// <summary>
 ///     Gets the building boost cost.
 /// </summary>
 public int GetBuildingBoostCost(LogicBuildingData data, int upgLevel)
 {
     return(data.GetBoostCost(upgLevel)); // TODO: Implement this.
 }
        /// <summary>
        ///     Executes this command.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            if (this._gameObjectIds.Count > 0)
            {
                LogicResourceData buildResourceData = null;
                int buildCost = 0;

                for (int i = 0; i < this._gameObjectIds.Count; i++)
                {
                    LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this._gameObjectIds[i]);

                    if (gameObject != null && gameObject.GetGameObjectType() == 0)
                    {
                        LogicBuilding     building     = (LogicBuilding)gameObject;
                        LogicBuildingData buildingData = building.GetBuildingData();

                        int upgradeLevel = building.GetUpgradeLevel();

                        if (buildingData.IsTownHallVillage2())
                        {
                            return(-76);
                        }

                        if (building.CanUpgrade(false) && buildingData.GetUpgradeLevelCount() > upgradeLevel + 1 && buildingData.GetAmountCanBeUpgraded(0) == 0)
                        {
                            buildResourceData = buildingData.GetBuildResource(upgradeLevel + 1);

                            if (this._useAltResources)
                            {
                                buildResourceData = buildingData.GetAltBuildResource(upgradeLevel + 1);
                            }

                            buildCost += buildingData.GetBuildCost(upgradeLevel + 1, level);
                        }
                    }
                }

                if (buildResourceData != null)
                {
                    LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                    if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false))
                    {
                        if (level.HasFreeWorkers(this, -1))
                        {
                            bool ignoreState = true;

                            for (int i = 0; i < this._gameObjectIds.Count; i++)
                            {
                                LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this._gameObjectIds[i]);

                                if (gameObject != null && gameObject.GetGameObjectType() == 0)
                                {
                                    LogicBuilding     building     = (LogicBuilding)gameObject;
                                    LogicBuildingData buildingData = building.GetBuildingData();

                                    int upgradeLevel = building.GetUpgradeLevel();

                                    if (building.CanUpgrade(false) && buildingData.GetUpgradeLevelCount() > upgradeLevel + 1 && buildingData.GetAmountCanBeUpgraded(0) == 0)
                                    {
                                        if (this._gameObjectIds.Count > 6)
                                        {
                                            ignoreState = (building.GetTileX() + building.GetTileY()) % (this._gameObjectIds.Count / 4) == 0;
                                        }

                                        building.StartUpgrading(ignoreState, false);
                                    }
                                }
                            }

                            playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost);

                            return(0);
                        }
                    }
                }
            }

            return(-2);
        }
Esempio n. 27
0
 public LogicCalendarBuildingDestroyedSpawnUnit(LogicBuildingData buildingData, LogicCharacterData unitData, int count)
 {
     this.m_buildingData  = buildingData;
     this.m_characterData = unitData;
     this.m_count         = count;
 }
Esempio n. 28
0
 public void SetBuildingData(LogicBuildingData data)
 {
     this.m_buildingData = data;
 }
Esempio n. 29
0
        public bool ProductionCompleted(bool speedUp)
        {
            bool success = false;

            if (!this.m_locked)
            {
                LogicComponentFilter filter = new LogicComponentFilter();

                filter.SetComponentType(0);

                while (true)
                {
                    LogicAvatar           homeOwnerAvatar  = this.m_level.GetHomeOwnerAvatar();
                    LogicComponentManager componentManager = this.m_level.GetComponentManagerAt(this.m_villageType);
                    LogicCombatItemData   productionData   = this.GetWaitingForSpaceUnit();

                    if (speedUp)
                    {
                        if (this.m_slots.Size() <= 0)
                        {
                            return(false);
                        }

                        productionData = (LogicCombatItemData)this.m_slots[0].GetData();
                    }

                    if (productionData == null)
                    {
                        filter.Destruct();
                        return(false);
                    }

                    bool productionTerminate = this.m_slots[0].IsTerminate();
                    LogicBuildingData      buildingProductionData = productionData.GetProductionHouseData();
                    LogicGameObjectManager gameObjectManager      = this.m_level.GetGameObjectManagerAt(this.m_villageType);
                    LogicBuilding          productionHouse        = gameObjectManager.GetHighestBuilding(buildingProductionData);

                    if (LogicDataTables.GetGlobals().UseTroopWalksOutFromTraining())
                    {
                        int gameObjectCount = gameObjectManager.GetNumGameObjects();

                        for (int i = 0; i < gameObjectCount; i++)
                        {
                            LogicGameObject gameObject = gameObjectManager.GetGameObjectByIndex(i);

                            if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                            {
                                LogicBuilding building = (LogicBuilding)gameObject;
                                LogicUnitProductionComponent unitProductionComponent = building.GetUnitProductionComponent();

                                if (unitProductionComponent != null)
                                {
                                    if (unitProductionComponent.GetProductionType() == productionData.GetCombatItemType())
                                    {
                                        if (building.GetBuildingData().GetProducesUnitsOfType() == productionData.GetUnitOfType() &&
                                            !building.IsUpgrading() &&
                                            !building.IsConstructing())
                                        {
                                            if (productionData.IsUnlockedForProductionHouseLevel(building.GetUpgradeLevel()))
                                            {
                                                if (productionHouse != null)
                                                {
                                                    int seed = this.m_level.GetPlayerAvatar().GetExpPoints();

                                                    if (building.Rand(seed) % 1000 > 750)
                                                    {
                                                        productionHouse = building;
                                                    }
                                                }
                                                else
                                                {
                                                    productionHouse = building;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (productionHouse != null)
                    {
                        LogicUnitStorageComponent unitStorageComponent =
                            (LogicUnitStorageComponent)componentManager.GetClosestComponent(productionHouse.GetX(), productionHouse.GetY(), filter);

                        if (unitStorageComponent != null)
                        {
                            if (unitStorageComponent.CanAddUnit(productionData))
                            {
                                homeOwnerAvatar.CommodityCountChangeHelper(0, productionData, 1);
                                unitStorageComponent.AddUnit(productionData);

                                if (productionTerminate)
                                {
                                    this.RemoveUnit(productionData, -1);
                                }
                                else
                                {
                                    this.StartProducingNextUnit();
                                }

                                success = true;

                                if (this.m_slots.Size() > 0 && this.m_slots[0].IsTerminate() && this.m_slots[0].GetCount() > 0)
                                {
                                    continue;
                                }

                                break;
                            }

                            filter.AddIgnoreObject(unitStorageComponent.GetParent());
                        }
                        else
                        {
                            if (this.m_timer != null && this.m_timer.GetRemainingSeconds(this.m_level.GetLogicTime()) == 0)
                            {
                                success = this.TrainingFinished();
                            }

                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                filter.Destruct();

                if (success)
                {
                    this.m_nextProduction = 0;
                }
                else
                {
                    this.m_nextProduction = 2000;
                }
            }

            return(success);
        }
        public override int Execute(LogicLevel level)
        {
            if (this.m_gameObjectIds.Size() > 0)
            {
                LogicResourceData ammoResourceData = null;
                int ammoCost = 0;

                int idx = 0;

                do
                {
                    LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectIds[idx]);

                    if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                    {
                        LogicBuilding building = (LogicBuilding)gameObject;

                        if (building.GetData().GetVillageType() == level.GetVillageType())
                        {
                            LogicCombatComponent combatComponent = building.GetCombatComponent(false);

                            if (combatComponent != null && combatComponent.UseAmmo())
                            {
                                if (combatComponent.GetAmmoCount() < combatComponent.GetMaxAmmo() && !building.IsUpgrading())
                                {
                                    LogicBuildingData buildingData = building.GetBuildingData();

                                    ammoResourceData = buildingData.GetAmmoResourceData(0);
                                    ammoCost        += buildingData.GetAmmoCost(building.GetUpgradeLevel(), combatComponent.GetMaxAmmo() - combatComponent.GetAmmoCount());
                                }
                            }
                        }
                        else
                        {
                            return(-32);
                        }
                    }
                } while (++idx < this.m_gameObjectIds.Size());

                if (ammoResourceData != null && ammoCost > 0)
                {
                    LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                    if (playerAvatar.HasEnoughResources(ammoResourceData, ammoCost, true, this, false))
                    {
                        for (int i = 0; i < this.m_gameObjectIds.Size(); i++)
                        {
                            LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectIds[i]);

                            if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                            {
                                LogicBuilding        building        = (LogicBuilding)gameObject;
                                LogicCombatComponent combatComponent = building.GetCombatComponent(false);

                                if (combatComponent != null && combatComponent.UseAmmo())
                                {
                                    if (combatComponent.GetAmmoCount() < combatComponent.GetMaxAmmo())
                                    {
                                        int upgradeLevel = building.GetUpgradeLevel();
                                        LogicBuildingData buildingData         = building.GetBuildingData();
                                        LogicResourceData loadAmmoResourceData = buildingData.GetAmmoResourceData(upgradeLevel);
                                        int loadAmmoCost = buildingData.GetAmmoCost(upgradeLevel, combatComponent.GetMaxAmmo() - combatComponent.GetAmmoCount());


                                        if (playerAvatar.HasEnoughResources(loadAmmoResourceData, loadAmmoCost, true, this, false))
                                        {
                                            playerAvatar.CommodityCountChangeHelper(0, loadAmmoResourceData, -loadAmmoCost);
                                            combatComponent.LoadAmmo();

                                            continue;
                                        }
                                    }
                                }
                            }

                            break;
                        }

                        return(0);
                    }

                    return(-2);
                }
            }

            return(-1);
        }