Exemple #1
0
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (playerAvatar != null)
            {
                level.GetPlayerAvatar().SetNameChangeState(this.m_state);
                return(0);
            }

            return(-1);
        }
        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 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);
        }
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (playerAvatar != null)
            {
                playerAvatar.SetLeagueType(this.m_leagueType);

                if (this.m_leagueType != 0)
                {
                    playerAvatar.SetLeagueInstanceId(this.m_leagueInstanceId.Clone());
                }
                else
                {
                    playerAvatar.SetLeagueInstanceId(null);
                    playerAvatar.SetAttackWinCount(0);
                    playerAvatar.SetAttackLoseCount(0);
                    playerAvatar.SetDefenseWinCount(0);
                    playerAvatar.SetDefenseLoseCount(0);
                }

                playerAvatar.GetChangeListener().LeagueChanged(this.m_leagueType, this.m_leagueInstanceId);
                return(0);
            }

            return(-1);
        }
Exemple #5
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);
        }
        public override int Execute(LogicLevel level)
        {
            level.GetPlayerAvatar().SetAccountBound();
            level.GetAchievementManager().RefreshStatus();

            return(0);
        }
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (playerAvatar != null && this.m_achievementData != null)
            {
                if (playerAvatar.IsAchievementCompleted(this.m_achievementData) && !playerAvatar.IsAchievementRewardClaimed(this.m_achievementData))
                {
                    playerAvatar.XpGainHelper(this.m_achievementData.GetExpReward());

                    if (this.m_achievementData.GetDiamondReward() > 0)
                    {
                        int diamondReward = this.m_achievementData.GetDiamondReward();

                        playerAvatar.SetDiamonds(playerAvatar.GetDiamonds() + diamondReward);
                        playerAvatar.SetFreeDiamonds(playerAvatar.GetFreeDiamonds() + diamondReward);
                        playerAvatar.GetChangeListener().FreeDiamondsAdded(diamondReward, 4);
                    }

                    playerAvatar.SetAchievementRewardClaimed(this.m_achievementData, true);
                    playerAvatar.GetChangeListener().CommodityCountChanged(1, this.m_achievementData, 1);

                    return(0);
                }
            }

            return(-1);
        }
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (playerAvatar != null)
            {
                if (playerAvatar.IsInAlliance())
                {
                    if (playerAvatar.GetAllianceId().Equals(this.m_allianceId))
                    {
                        playerAvatar.SetAllianceId(null);
                        playerAvatar.SetAllianceName(null);
                        playerAvatar.SetAllianceBadgeId(-1);
                        playerAvatar.SetAllianceLevel(-1);
                        playerAvatar.GetChangeListener().AllianceLeft();
                    }
                }

                level.GetGameListener().AllianceLeft();

                return(0);
            }

            return(-1);
        }
Exemple #9
0
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (level.GetVillageType() == 1)
            {
                LogicGameMode gameMode = level.GetGameMode();

                if (!gameMode.IsInAttackPreparationMode())
                {
                    if (gameMode.GetState() != 5)
                    {
                        return(-9);
                    }
                }

                if (this.m_oldUnitData != null && this.m_newUnitData != null && gameMode.GetCalendar().IsProductionEnabled(this.m_newUnitData))
                {
                    if (!this.m_newUnitData.IsUnlockedForBarrackLevel(playerAvatar.GetVillage2BarrackLevel()))
                    {
                        if (gameMode.GetState() != 7)
                        {
                            return(-7);
                        }
                    }

                    int oldUnitCount   = playerAvatar.GetUnitCountVillage2(this.m_oldUnitData);
                    int oldUnitsInCamp = this.m_oldUnitData.GetUnitsInCamp(playerAvatar.GetUnitUpgradeLevel(this.m_oldUnitData));

                    if (oldUnitCount >= oldUnitsInCamp)
                    {
                        int newUnitCount   = playerAvatar.GetUnitCountVillage2(this.m_newUnitData);
                        int newUnitsInCamp = this.m_newUnitData.GetUnitsInCamp(playerAvatar.GetUnitUpgradeLevel(this.m_newUnitData));

                        playerAvatar.SetUnitCountVillage2(this.m_oldUnitData, oldUnitCount - oldUnitsInCamp);
                        playerAvatar.SetUnitCountVillage2(this.m_newUnitData, newUnitCount + newUnitsInCamp);

                        LogicArrayList <LogicDataSlot> unitsNew = playerAvatar.GetUnitsNewVillage2();

                        for (int i = 0; i < unitsNew.Size(); i++)
                        {
                            LogicDataSlot slot = unitsNew[i];

                            if (slot.GetCount() > 0)
                            {
                                playerAvatar.CommodityCountChangeHelper(8, slot.GetData(), -slot.GetCount());
                            }
                        }

                        return(0);
                    }

                    return(-23);
                }

                return(-7);
            }

            return(-10);
        }
        /// <summary>
        ///     Executes this command.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            if (LogicDataTables.GetGlobals().UseNewTraining())
            {
                if (level.GetVillageType() == 0)
                {
                    LogicClientAvatar   playerAvatar   = level.GetPlayerAvatar();
                    LogicUnitProduction unitProduction = this._productionType == 1
                        ? level.GetGameObjectManager().GetSpellProduction()
                        : level.GetGameObjectManager().GetUnitProduction();

                    if (unitProduction.CanBeBoosted())
                    {
                        int cost = unitProduction.GetBoostCost();

                        if (playerAvatar.HasEnoughDiamonds(cost, true, level))
                        {
                            playerAvatar.UseDiamonds(cost);
                            unitProduction.Boost();

                            return(0);
                        }

                        return(-2);
                    }

                    return(-1);
                }

                return(-32);
            }

            return(-99);
        }
Exemple #11
0
        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 (this.m_unitData != null)
                {
                    LogicUnitUpgradeComponent unitUpgradeComponent = building.GetUnitUpgradeComponent();

                    if (unitUpgradeComponent != null && unitUpgradeComponent.CanStartUpgrading(this.m_unitData))
                    {
                        LogicClientAvatar playerAvatar = level.GetPlayerAvatar();
                        int upgradeLevel = playerAvatar.GetUnitUpgradeLevel(this.m_unitData);
                        int upgradeCost  = this.m_unitData.GetUpgradeCost(upgradeLevel);
                        LogicResourceData upgradeResourceData = this.m_unitData.GetUpgradeResource(upgradeLevel);

                        if (playerAvatar.HasEnoughResources(upgradeResourceData, upgradeCost, true, this, false))
                        {
                            playerAvatar.CommodityCountChangeHelper(0, upgradeResourceData, -upgradeCost);
                            unitUpgradeComponent.StartUpgrading(this.m_unitData);

                            return(0);
                        }
                    }
                }
            }

            return(-1);
        }
Exemple #12
0
        public int ChangeVillage(LogicLevel level, bool force)
        {
            if (this.m_villageType != 0 && !force)
            {
                LogicVillageObject ship = level.GetGameObjectManagerAt(0).GetShipyard();

                if (ship == null || ship.GetUpgradeLevel() <= 0)
                {
                    return(-23);
                }
            }

            if (level.GetGameObjectManagerAt(1).GetTownHall() != null)
            {
                level.SetVillageType(this.m_villageType);

                if (level.GetState() == 1)
                {
                    level.GetPlayerAvatar().SetVariableByName("VillageToGoTo", this.m_villageType);
                }

                level.GetGameObjectManager().RespawnObstacles();
            }

            return(0);
        }
Exemple #13
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);
        }
Exemple #14
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;

                    if (!LogicDataTables.GetGlobals().AllowCancelBuildingConstruction() &&
                        building.GetUpgradeLevel() == 0 &&
                        building.IsConstructing())
                    {
                        if (!building.IsUpgrading())
                        {
                            return(-2);
                        }
                    }

                    if (building.IsConstructing())
                    {
                        building.GetListener().CancelNotification();
                        building.CancelConstruction();

                        return(0);
                    }
                }
                else if (gameObject.GetGameObjectType() == LogicGameObjectType.OBSTACLE)
                {
                    LogicObstacle obstacle = (LogicObstacle)gameObject;

                    if (obstacle.IsClearingOnGoing())
                    {
                        LogicObstacleData data         = obstacle.GetObstacleData();
                        LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                        playerAvatar.CommodityCountChangeHelper(0, data.GetClearResourceData(), data.GetClearCost());
                        obstacle.CancelClearing();

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

                    if (trap.IsConstructing())
                    {
                        trap.GetListener().CancelNotification();
                        trap.CancelConstruction();

                        return(0);
                    }
                }
            }

            return(-1);
        }
Exemple #15
0
        public override int Execute(LogicLevel level)
        {
            if (this.m_decoData != null)
            {
                if (this.m_decoData.GetVillageType() == level.GetVillageType())
                {
                    if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, this.m_decoData.GetWidth(), this.m_decoData.GetHeight(), null))
                    {
                        LogicClientAvatar playerAvatar      = level.GetPlayerAvatar();
                        LogicResourceData buildResourceData = this.m_decoData.GetBuildResource();

                        int buildCost = this.m_decoData.GetBuildCost();

                        if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false) && !level.IsDecoCapReached(this.m_decoData, true))
                        {
                            if (buildResourceData.IsPremiumCurrency())
                            {
                                playerAvatar.UseDiamonds(buildCost);
                                playerAvatar.GetChangeListener().DiamondPurchaseMade(1, this.m_decoData.GetGlobalID(), 0, buildCost, level.GetVillageType());
                            }
                            else
                            {
                                playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost);
                            }

                            LogicDeco deco = (LogicDeco)LogicGameObjectFactory.CreateGameObject(this.m_decoData, level, level.GetVillageType());

                            deco.SetInitialPosition(this.m_x << 9, this.m_y << 9);
                            level.GetGameObjectManager().AddGameObject(deco, -1);

                            int width  = deco.GetWidthInTiles();
                            int height = deco.GetHeightInTiles();

                            for (int i = 0; i < width; i++)
                            {
                                for (int j = 0; j < height; j++)
                                {
                                    LogicObstacle tallGrass = level.GetTileMap().GetTile(this.m_x + i, this.m_y + j).GetTallGrass();

                                    if (tallGrass != null)
                                    {
                                        level.GetGameObjectManager().RemoveGameObject(tallGrass);
                                    }
                                }
                            }

                            return(0);
                        }
                    }

                    return(-1);
                }

                return(-32);
            }

            return(-1);
        }
        /// <summary>
        ///     Executes this instance.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            if (true)
            {
                int tileX = this._x >> 9;
                int tileY = this._y >> 9;

                if (level.GetTileMap().GetTile(tileX, tileY) != null)
                {
                    // if (level.GetTileMap().IsPassablePathFinder(this._x >> 8, this._y >> 8))
                    {
                        if (level.GetTileMap().IsValidAttackPos(tileX, tileY))
                        {
                            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                            if (playerAvatar != null)
                            {
                                int unitCount = level.GetVillageType() == 1 ? playerAvatar.GetUnitCountVillage2(this._data) : playerAvatar.GetUnitCount(this._data);

                                if (unitCount > 0)
                                {
                                    if (level.GetBattleLog() != null)
                                    {
                                        // ?
                                    }

                                    if (level.GetGameMode().IsInAttackPreparationMode())
                                    {
                                        level.GetGameMode().EndAttackPreparation();
                                    }

                                    LogicCharacter character = LogicPlaceAttackerCommand.PlaceAttacker(playerAvatar, this._data, level, this._x, this._y);

                                    if (character != null)
                                    {
                                        // TODO: Finish this.
                                    }

                                    return(0);
                                }

                                return(-7);
                            }

                            return(-5);
                        }

                        return(-4);
                    }

                    // return -2;
                }

                return(-3);
            }

            return(-1);
        }
        /// <summary>
        ///     Executes this command.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            if (this._villageType == 0)
            {
                level.GetPlayerAvatar().SetVariableByName("SeenBuilderMenu", 1);
                return(0);
            }

            return(-1);
        }
Exemple #18
0
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar      playerAvatar       = level.GetPlayerAvatar();
            LogicGameObjectManager gameObjectManager  = level.GetGameObjectManager();
            LogicResourceData      repairResourceData = null;

            int repairCost = 0;

            for (int i = 0; i < this.m_gameObjectIds.Size(); i++)
            {
                LogicGameObject gameObject = gameObjectManager.GetGameObjectByID(this.m_gameObjectIds[i]);

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

                    if (trap.IsDisarmed() && !trap.IsConstructing())
                    {
                        LogicTrapData data = trap.GetTrapData();

                        repairResourceData = data.GetBuildResource();
                        repairCost        += data.GetRearmCost(trap.GetUpgradeLevel());
                    }
                }
            }

            if (repairResourceData != null && repairCost != 0)
            {
                if (playerAvatar.HasEnoughResources(repairResourceData, repairCost, true, this, false))
                {
                    playerAvatar.CommodityCountChangeHelper(0, repairResourceData, -repairCost);

                    for (int i = 0; i < this.m_gameObjectIds.Size(); i++)
                    {
                        LogicGameObject gameObject = gameObjectManager.GetGameObjectByID(this.m_gameObjectIds[i]);

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

                            if (trap.IsDisarmed() && !trap.IsConstructing())
                            {
                                trap.RepairTrap();
                            }
                        }
                    }

                    return(0);
                }

                return(-2);
            }

            return(-1);
        }
Exemple #19
0
        public override int Execute(LogicLevel level)
        {
            if (level.GetVillageType() == 1)
            {
                if (this.m_gameObjectId != 0)
                {
                    LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(1);
                    LogicGameObject        gameObject        = gameObjectManager.GetGameObjectByID(this.m_gameObjectId);

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

                        if (this.m_unitData != null && level.GetGameMode().GetCalendar().IsProductionEnabled(this.m_unitData))
                        {
                            if (this.m_unitData.GetVillageType() == 1)
                            {
                                LogicVillage2UnitComponent village2UnitComponent = building.GetVillage2UnitComponent();

                                if (village2UnitComponent != null)
                                {
                                    if (this.m_unitData.IsUnlockedForProductionHouseLevel(gameObjectManager.GetHighestBuildingLevel(this.m_unitData.GetProductionHouseData(), true))
                                        )
                                    {
                                        LogicClientAvatar playerAvatar  = level.GetPlayerAvatar();
                                        LogicResourceData trainResource = this.m_unitData.GetTrainingResource();
                                        int trainCost = this.m_unitData.GetTrainingCost(playerAvatar.GetUnitUpgradeLevel(this.m_unitData));

                                        if (playerAvatar.HasEnoughResources(trainResource, trainCost, true, this, false))
                                        {
                                            village2UnitComponent.TrainUnit(this.m_unitData);
                                            playerAvatar.CommodityCountChangeHelper(0, trainResource, -trainCost);
                                        }

                                        return(0);
                                    }

                                    return(-7);
                                }

                                return(-4);
                            }

                            return(-8);
                        }
                    }

                    return(-5);
                }

                return(-1);
            }

            return(-10);
        }
        public void SaveChallengeLayout(LogicLevel level, bool warLayout)
        {
            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (playerAvatar != null)
            {
                playerAvatar.SetVariableByName("ChallengeLayoutIsWar", warLayout ? 1 : 0);
            }

            level.SaveLayout(this.m_layoutId, 6);
        }
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (playerAvatar != null)
            {
                playerAvatar.AddWarReward(this.m_goldCount, this.m_elixirCount, this.m_darkElixirCount, 0, this.m_warInstanceId);
                return(0);
            }

            return(-1);
        }
Exemple #22
0
        /// <summary>
        ///     Executes this command.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            int villageType = level.GetVillageType();

            if (this._buildingData.GetVillageType() == villageType)
            {
                if (this._buildingData.GetBuildingClass().CanBuy)
                {
                    if (level.IsValidPlaceForBuilding(this._x, this._y, this._buildingData.GetWidth(), this._buildingData.GetHeight(), null))
                    {
                        if (!level.IsBuildingCapReached(this._buildingData, true))
                        {
                            LogicClientAvatar playerAvatar      = level.GetPlayerAvatar();
                            LogicResourceData buildResourceData = this._buildingData.GetBuildResource(0);

                            int buildResourceCost = this._buildingData.GetBuildCost(0, level);

                            if (playerAvatar.HasEnoughResources(buildResourceData, buildResourceCost, true, this, false))
                            {
                                if (this._buildingData.IsWorkerBuilding() || this._buildingData.GetConstructionTime(0, level, 0) <= 0 && !LogicDataTables.GetGlobals().WorkerForZeroBuilTime() || level.HasFreeWorkers(this, -1))
                                {
                                    if (buildResourceData.PremiumCurrency)
                                    {
                                        playerAvatar.UseDiamonds(buildResourceCost);
                                    }
                                    else
                                    {
                                        playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildResourceCost);
                                    }


                                    LogicBuilding building = (LogicBuilding)LogicGameObjectFactory.CreateGameObject(this._buildingData, level, villageType);
                                    building.SetPositionXY(this._x << 9, this._y << 9);
                                    level.GetGameObjectManager().AddGameObject(building, -1);
                                    building.StartConstructing(false);

                                    if (this._buildingData.IsWall() && level.IsBuildingCapReached(this._buildingData, false))
                                    {
                                        level.GetGameListener().BuildingCapReached(this._buildingData);
                                    }
                                }
                            }

                            return(0);
                        }
                    }
                }

                return(-33);
            }

            return(-32);
        }
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (playerAvatar != null)
            {
                playerAvatar.SetLastUsedArmy(this.m_unitCount, this.m_spellCount);
                return(0);
            }

            return(-1);
        }
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (playerAvatar != null)
            {
                playerAvatar.AddDuelReward(this.m_goldCount, this.m_elixirCount, this.m_bonusGoldCount, this.m_bonusElixirCount, this.m_matchId);
                return(0);
            }

            return(-1);
        }
        public override int Execute(LogicLevel level)
        {
            level.SetWarTroopRequestMessage(this.m_message);

            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (playerAvatar != null)
            {
                playerAvatar.GetChangeListener().WarTroopRequestMessageChanged(this.m_message);
            }

            return(0);
        }
Exemple #26
0
        public override int Execute(LogicLevel level)
        {
            if (level.IsReadyForAttack())
            {
                int tileX = this.m_x >> 9;
                int tileY = this.m_y >> 9;

                if (level.GetTileMap().GetTile(tileX, tileY) != null)
                {
                    if (level.GetVillageType() == 0)
                    {
                        LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                        if (playerAvatar != null)
                        {
                            int unitCount = this.m_allianceSpell ? playerAvatar.GetAllianceUnitCount(this.m_data, this.m_upgLevel) : playerAvatar.GetUnitCount(this.m_data);

                            if (unitCount > 0)
                            {
                                if (level.GetBattleLog() != null)
                                {
                                    if (!level.GetBattleLog().HasDeployedUnits() && level.GetTotalAttackerHeroPlaced() == 0)
                                    {
                                        level.UpdateLastUsedArmy();
                                    }
                                }

                                if (level.GetGameMode().IsInAttackPreparationMode())
                                {
                                    level.GetGameMode().EndAttackPreparation();
                                }

                                LogicCastSpellCommand.CastSpell(playerAvatar, this.m_data, this.m_allianceSpell, this.m_upgLevel, level, this.m_x, this.m_y);

                                return(0);
                            }
                        }

                        return(-3);
                    }

                    Debugger.Error("not available for village");

                    return(-23);
                }

                return(-3);
            }

            return(-1);
        }
        /// <summary>
        ///     Executes this instance.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            if (true)
            {
                int tileX = this._x >> 9;
                int tileY = this._y >> 9;

                if (level.GetTileMap().GetTile(tileX, tileY) != null)
                {
                    if (level.GetVillageType() == 0)
                    {
                        LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                        if (playerAvatar != null)
                        {
                            int unitCount = this._allianceSpell ? playerAvatar.GetAllianceUnitCount(this._data, this._upgLevel) : playerAvatar.GetUnitCount(this._data);

                            if (unitCount > 0)
                            {
                                if (level.GetBattleLog() != null)
                                {
                                    // ?
                                }

                                if (level.GetGameMode().IsInAttackPreparationMode())
                                {
                                    level.GetGameMode().EndAttackPreparation();
                                }

                                LogicCastSpellCommand.CastSpell(playerAvatar, this._data, this._allianceSpell, this._upgLevel, level, this._x, this._y);

                                return(0);
                            }
                        }

                        return(-3);
                    }
                    else
                    {
                        Debugger.Error("not available for village");
                    }

                    return(-23);
                }

                return(-3);
            }

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

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

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

                    if (building.CanSell())
                    {
                        playerAvatar.CommodityCountChangeHelper(0, building.GetSellResource(), building.GetSellPrice());
                        building.OnSell();

                        level.GetGameObjectManager().RemoveGameObject(building);

                        return(0);
                    }
                }
                else if (gameObject.GetGameObjectType() == LogicGameObjectType.DECO)
                {
                    LogicDeco         deco = (LogicDeco)gameObject;
                    LogicDecoData     data = deco.GetDecoData();
                    LogicResourceData buildResourceData = data.GetBuildResource();

                    int sellPrice = data.GetSellPrice();

                    if (buildResourceData.IsPremiumCurrency())
                    {
                        playerAvatar.SetDiamonds(playerAvatar.GetDiamonds() + sellPrice);
                        playerAvatar.SetFreeDiamonds(playerAvatar.GetFreeDiamonds() + sellPrice);
                        playerAvatar.GetChangeListener().FreeDiamondsAdded(sellPrice, 6);
                    }
                    else
                    {
                        playerAvatar.CommodityCountChangeHelper(0, buildResourceData, sellPrice);
                    }

                    level.GetGameObjectManager().RemoveGameObject(deco);

                    return(0);
                }
            }

            return(-1);
        }
        /// <summary>
        ///     Executes this command.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar playerAvatar = (LogicClientAvatar)level.GetPlayerAvatar();

            if (playerAvatar != null)
            {
                playerAvatar.SetName(this._avatarName);
                playerAvatar.SetNameSetByUser(true);
                playerAvatar.SetNameChangeState(this._nameChangeState);

                return(0);
            }

            return(-1);
        }
        /// <summary>
        ///     Trains the unit with new training.
        /// </summary>
        public int NewTrainingUnit(LogicLevel level)
        {
            if (LogicDataTables.GetGlobals().UseNewTraining())
            {
                if (this._unitData != null)
                {
                    LogicUnitProduction unitProduction = this._unitData.GetCombatItemType() == 1
                        ? level.GetGameObjectManager().GetSpellProduction()
                        : level.GetGameObjectManager().GetUnitProduction();

                    if (!unitProduction.IsLocked())
                    {
                        if (this._unitCount > 0)
                        {
                            if (this._unitData.GetDataType() == unitProduction.GetUnitProductionType())
                            {
                                LogicClientAvatar playerAvatar         = level.GetPlayerAvatar();
                                LogicResourceData trainingResourceData = this._unitData.GetTrainingResource();
                                Int32             trainingCost         = level.GetGameMode().GetCalendar().GetUnitTrainingCost(this._unitData, playerAvatar.GetUnitUpgradeLevel(this._unitData));
                                Int32             refundCount          = LogicMath.Max(trainingCost * (this._unitData.GetDataType() != 3
                                                                      ? LogicDataTables.GetGlobals().GetSpellCancelMultiplier()
                                                                      : LogicDataTables.GetGlobals().GetTrainCancelMultiplier()) / 100, 0);

                                while (unitProduction.RemoveUnit(this._unitData, this._slotId))
                                {
                                    playerAvatar.CommodityCountChangeHelper(0, trainingResourceData, refundCount);

                                    if (--this._unitCount <= 0)
                                    {
                                        break;
                                    }
                                }

                                return(0);
                            }
                        }

                        return(-1);
                    }

                    return(-23);
                }

                return(-1);
            }

            return(-99);
        }