示例#1
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);
        }
        /// <summary>
        ///     Executes this instance.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            for (int i = 0; i < this._unitsCount.Count; i++)
            {
                if (this._unitsCount[i] < 0)
                {
                    return(-1);
                }
            }

            if (LogicDataTables.GetGlobals().EnableTroopDeletion() && level.GetState() == 1 && this._unitsData.Count > 0)
            {
                LogicClientAvatar playerAvatar = level.GetPlayerAvatar();
                Int32             removedUnits = 0;

                for (int i = 0; i < this._unitsData.Count; i++)
                {
                    LogicCombatItemData data = this._unitsData[i];
                    Int32 unitCount          = this._unitsCount[i];

                    if (this._removeType[i] != 0)
                    {
                        Int32 upgLevel = this._unitsUpgLevel[i];

                        if (data.GetCombatItemType() != 0)
                        {
                            if (data.GetCombatItemType() == 1)
                            {
                                playerAvatar.SetAllianceUnitCount(data, upgLevel, LogicMath.Max(0, playerAvatar.GetAllianceUnitCount(data, upgLevel) - unitCount));

                                if (unitCount > 0)
                                {
                                    do
                                    {
                                        playerAvatar.GetChangeListener().AllianceUnitRemoved(data, upgLevel);
                                    } while (--unitCount != 0);
                                }

                                removedUnits |= 2;
                            }
                        }
                        else
                        {
                            LogicBuilding allianceCastle = level.GetGameObjectManagerAt(0).GetAllianceCastle();

                            if (allianceCastle != null)
                            {
                                LogicBunkerComponent bunkerComponent = allianceCastle.GetBunkerComponent();
                                Int32 unitTypeIndex = bunkerComponent.GetUnitTypeIndex(data);

                                if (unitTypeIndex != -1)
                                {
                                    Int32 cnt = bunkerComponent.GetUnitCount(unitTypeIndex);

                                    if (cnt > 0)
                                    {
                                        bunkerComponent.RemoveUnits(data, upgLevel, cnt);
                                        playerAvatar.SetAllianceUnitCount(data, upgLevel, LogicMath.Max(0, playerAvatar.GetAllianceUnitCount(data, upgLevel) - unitCount));

                                        removedUnits |= 1;

                                        if (unitCount > 0)
                                        {
                                            do
                                            {
                                                playerAvatar.GetChangeListener().AllianceUnitRemoved(data, upgLevel);
                                            } while (--unitCount != 0);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (playerAvatar != null && data != null)
                        {
                            playerAvatar.CommodityCountChangeHelper(0, data, -unitCount);
                        }

                        LogicArrayList <LogicComponent> components = level.GetComponentManager().GetComponents(0);

                        for (int j = 0; j < components.Count; j++)
                        {
                            if (unitCount > 0)
                            {
                                LogicUnitStorageComponent storageComponent = (LogicUnitStorageComponent)components[j];
                                Int32 unitTypeIndex = storageComponent.GetUnitTypeIndex(data);

                                if (unitTypeIndex != -1)
                                {
                                    Int32 cnt = storageComponent.GetUnitCount(unitTypeIndex);

                                    if (cnt > 0)
                                    {
                                        cnt = LogicMath.Min(cnt, unitCount);
                                        storageComponent.RemoveUnits(data, cnt);

                                        int type = 2;

                                        if (data.GetCombatItemType() == 0)
                                        {
                                            if (storageComponent.GetParentListener() != null)
                                            {
                                                LogicGameObjectListener listener = storageComponent.GetParentListener();

                                                for (int k = 0; k < cnt; k++)
                                                {
                                                    listener.UnitRemoved(data);
                                                }
                                            }

                                            type = 1;
                                        }

                                        unitCount    -= cnt;
                                        removedUnits |= type;
                                    }
                                }
                            }
                        }
                    }
                }

                switch (removedUnits)
                {
                case 3:
                    if (LogicDataTables.GetGlobals().UseNewTraining())
                    {
                        level.GetGameObjectManager().GetUnitProduction().MergeSlots();
                        level.GetGameObjectManager().GetSpellProduction().MergeSlots();
                    }
                    break;

                case 2:
                    if (LogicDataTables.GetGlobals().UseNewTraining())
                    {
                        level.GetGameObjectManager().GetSpellProduction().MergeSlots();
                    }
                    break;

                case 1:
                    if (LogicDataTables.GetGlobals().UseNewTraining())
                    {
                        level.GetGameObjectManager().GetUnitProduction().MergeSlots();
                    }
                    break;

                default:
                    Debugger.Print("WTF: " + removedUnits);
                    break;
                }
            }

            return(0);
        }