コード例 #1
0
        public void RefreshArmyCampSize(bool unk)
        {
            if (this.m_unit != null && this.m_productionTimer == null)
            {
                int maxUnits  = this.GetMaxUnitsInCamp((LogicCharacterData)this.m_unit.GetData());
                int unitCount = this.m_unit.GetCount();

                if (maxUnits > unitCount)
                {
                    LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();
                    homeOwnerAvatar.CommodityCountChangeHelper(7, this.m_unit.GetData(), maxUnits - unitCount);
                    this.m_unit.SetCount(maxUnits);

                    if (this.m_parent.GetLevel().GetState() == 1)
                    {
                        LogicGameObjectListener listener = this.m_parent.GetListener();

                        if (listener != null)
                        {
                            for (int i = unitCount; i < maxUnits; i++)
                            {
                                if (i > 25)
                                {
                                    return;
                                }

                                // TODO: Implement listener.
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
        public void FinishUpgrading(bool tick)
        {
            if (this.m_timer != null)
            {
                LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();

                if (homeOwnerAvatar.GetUnitUpgradeLevel(this.m_hero) < this.m_upgLevel || this.m_upgLevel == 0)
                {
                    homeOwnerAvatar.CommodityCountChangeHelper(1, this.m_hero, 1);
                }

                this.m_parent.GetLevel().GetWorkerManagerAt(this.m_parent.GetData().GetVillageType()).DeallocateWorker(this.m_parent);

                homeOwnerAvatar.SetHeroState(this.m_hero, 3);
                homeOwnerAvatar.GetChangeListener().CommodityCountChanged(2, this.m_hero, 3);

                this.SetFullHealth();

                this.m_timer.Destruct();
                this.m_timer = null;
            }
            else
            {
                Debugger.Warning("LogicHeroBaseComponent::finishUpgrading called and m_pHero is NULL");
            }
        }
コード例 #3
0
        public static LogicSpell CastSpell(LogicAvatar avatar, LogicSpellData spellData, bool allianceSpell, int upgLevel, LogicLevel level, int x, int y)
        {
            if (allianceSpell)
            {
                avatar.RemoveAllianceUnit(spellData, upgLevel);
            }
            else
            {
                avatar.CommodityCountChangeHelper(0, spellData, -1);
            }

            if (!allianceSpell)
            {
                upgLevel = avatar.GetUnitUpgradeLevel(spellData);
            }

            LogicSpell spell = (LogicSpell)LogicGameObjectFactory.CreateGameObject(spellData, level, level.GetVillageType());

            spell.SetUpgradeLevel(upgLevel);
            spell.SetInitialPosition(x, y);
            level.GetGameObjectManager().AddGameObject(spell, -1);
            level.GetGameListener().AttackerPlaced(spellData);

            LogicBattleLog battleLog = level.GetBattleLog();

            if (battleLog != null)
            {
                battleLog.IncrementCastedSpells(spellData, 1);
                battleLog.SetCombatItemLevel(spellData, upgLevel);
            }

            return(spell);
        }
コード例 #4
0
        public void ProductionCompleted()
        {
            this.m_unit.SetCount(this.GetMaxUnitsInCamp((LogicCharacterData)this.m_unit.GetData()));

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

            LogicAvatar         homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();
            LogicCombatItemData combatItemData  = (LogicCombatItemData)this.m_unit.GetData();

            int unitCount = this.m_parent.GetLevel().GetMissionManager().IsVillage2TutorialOpen()
                ? this.m_unit.GetCount() - homeOwnerAvatar.GetUnitCountVillage2(combatItemData)
                : this.m_unit.GetCount();

            homeOwnerAvatar.CommodityCountChangeHelper(7, this.m_unit.GetData(), unitCount);

            if (this.m_parent.GetLevel().GetGameListener() != null)
            {
                // ?
            }

            int state = this.m_parent.GetLevel().GetState();

            if (state == 1)
            {
                if (this.m_parent.GetListener() != null)
                {
                    // ?
                }
            }
        }
コード例 #5
0
        /// <summary>
        ///     Called when the training of the unit is finished.
        /// </summary>
        public void TrainingFinished()
        {
            this._unit.SetCount(this.GetMaxCapacity());

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

            LogicAvatar         homeOwnerAvatar = this._parent.GetLevel().GetHomeOwnerAvatar();
            LogicCombatItemData combatItemData  = (LogicCombatItemData)this._unit.GetData();

            int unitCount = this._parent.GetLevel().GetMissionManager().IsVillage2TutorialOpen()
                ? this._unit.GetCount() - homeOwnerAvatar.GetUnitCountVillage2(combatItemData)
                : this._unit.GetCount();

            homeOwnerAvatar.CommodityCountChangeHelper(7, this._unit.GetData(), unitCount);

            if (this._parent.GetLevel().GetGameListener() != null)
            {
                // ?
            }

            int state = this._parent.GetLevel().GetState();

            if (state == 1)
            {
                if (this._parent.GetListener() != null)
                {
                    // ?
                }
            }
        }
コード例 #6
0
        public override void ResourcesStolen(int damage, int hp)
        {
            if (damage > 0 && hp > 0)
            {
                LogicDataTable table = LogicDataTables.GetTable(LogicDataType.RESOURCE);

                for (int i = 0; i < this.m_stealableResourceCount.Size(); i++)
                {
                    LogicResourceData data = (LogicResourceData)table.GetItemAt(i);

                    int stealableResource = this.GetStealableResourceCount(i);

                    if (damage < hp)
                    {
                        stealableResource = damage * stealableResource / hp;
                    }

                    if (stealableResource > 0 && data.GetWarResourceReferenceData() != null)
                    {
                        this.m_parent.GetLevel().GetBattleLog().IncreaseStolenResourceCount(data.GetWarResourceReferenceData(), stealableResource);
                        this.m_resourceCount[i] -= stealableResource;

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

                        homeOwnerAvatar.CommodityCountChangeHelper(0, data, -stealableResource);
                        visitorAvatar.CommodityCountChangeHelper(0, data.GetWarResourceReferenceData(), stealableResource);

                        this.m_stealableResourceCount[i] = LogicMath.Max(this.m_stealableResourceCount[i] - stealableResource, 0);
                    }
                }
            }
        }
コード例 #7
0
        public virtual void ResourcesStolen(int damage, int hp)
        {
            if (damage > 0 && hp > 0)
            {
                LogicDataTable table = LogicDataTables.GetTable(LogicDataType.RESOURCE);

                for (int i = 0; i < this.m_stealableResourceCount.Size(); i++)
                {
                    LogicResourceData data = (LogicResourceData)table.GetItemAt(i);

                    int stealableResource = this.GetStealableResourceCount(i);

                    if (damage < hp)
                    {
                        stealableResource = damage * stealableResource / hp;
                    }

                    if (stealableResource > 0)
                    {
                        this.m_parent.GetLevel().GetBattleLog().IncreaseStolenResourceCount(data, stealableResource);
                        this.m_resourceCount[i] -= stealableResource;

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

                        homeOwnerAvatar.CommodityCountChangeHelper(0, data, -stealableResource);
                        visitorAvatar.CommodityCountChangeHelper(0, data, stealableResource);

                        if (homeOwnerAvatar.IsNpcAvatar())
                        {
                            LogicNpcData npcData = ((LogicNpcAvatar)homeOwnerAvatar).GetNpcData();

                            if (data == LogicDataTables.GetGoldData())
                            {
                                visitorAvatar.CommodityCountChangeHelper(1, npcData, stealableResource);
                            }
                            else if (data == LogicDataTables.GetElixirData())
                            {
                                visitorAvatar.CommodityCountChangeHelper(2, npcData, stealableResource);
                            }
                        }

                        this.m_stealableResourceCount[i] = LogicMath.Max(this.m_stealableResourceCount[i] - stealableResource, 0);
                    }
                }
            }
        }
コード例 #8
0
        /// <summary>
        ///     Casts the specified spell.
        /// </summary>
        public static LogicSpell CastSpell(LogicAvatar avatar, LogicSpellData spellData, bool allianceSpell, int upgLevel, LogicLevel level, int x, int y)
        {
            if (allianceSpell)
            {
                avatar.RemoveAllianceUnit(spellData, upgLevel);
            }
            else
            {
                avatar.CommodityCountChangeHelper(0, spellData, -1);
            }

            LogicSpell spell = (LogicSpell)LogicGameObjectFactory.CreateGameObject(spellData, level, level.GetVillageType());

            spell.SetUpgradeLevel(upgLevel);
            return(spell);
        }
コード例 #9
0
        public void CancelUpgrade()
        {
            if (this.m_unit != null)
            {
                LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();
                int         upgLevel        = homeOwnerAvatar.GetUnitUpgradeLevel(this.m_unit);

                homeOwnerAvatar.CommodityCountChangeHelper(0, this.m_unit.GetUpgradeResource(upgLevel), this.m_unit.GetUpgradeCost(upgLevel));

                this.m_unit = null;
            }

            if (this.m_timer != null)
            {
                this.m_timer.Destruct();
                this.m_timer = null;
            }
        }
コード例 #10
0
        /// <summary>
        ///     Cancels the construction of trap.
        /// </summary>
        public void CancelConstruction()
        {
            LogicAvatar homeOwnerAvatar = this._level.GetHomeOwnerAvatar();

            if (homeOwnerAvatar != null && homeOwnerAvatar.IsClientAvatar())
            {
                if (this._constructionTimer != null)
                {
                    this._constructionTimer.Destruct();
                    this._constructionTimer = null;

                    int upgLevel = this._upgLevel;

                    if (this._upgrading)
                    {
                        this.SetUpgradeLevel(this._upgLevel);
                        upgLevel += 1;
                    }

                    LogicTrapData     data = this.GetTrapData();
                    LogicResourceData buildResourceData = data.GetBuildResource();
                    Int32             buildCost         = data.GetBuildCost(upgLevel);
                    Int32             refundedCount     = LogicMath.Max(LogicDataTables.GetGlobals().GetBuildCancelMultiplier() * buildCost / 100, 0);
                    Debugger.Print("LogicTrap::cancelConstruction refunds: " + refundedCount);

                    homeOwnerAvatar.CommodityCountChangeHelper(0, buildResourceData, refundedCount);

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

                    if (upgLevel != 0)
                    {
                        if (this._listener != null)
                        {
                            this._listener.RefreshState();
                        }
                    }
                    else
                    {
                        this.GetGameObjectManager().RemoveGameObject(this);
                    }
                }
            }
        }
コード例 #11
0
        public static LogicCharacter PlaceAttacker(LogicAvatar avatar, LogicCharacterData characterData, LogicLevel level, int x, int y)
        {
            avatar.CommodityCountChangeHelper(level.GetVillageType() == 1 ? 7 : 0, characterData, -1);

            LogicCharacter character    = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(characterData, level, level.GetVillageType());
            int            upgradeLevel = avatar.GetUnitUpgradeLevel(characterData);

            if (level.GetMissionManager().GetMissionByCategory(2) != null && level.GetVillageType() == 1 && level.GetHomeOwnerAvatar() != null)
            {
                LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                if (homeOwnerAvatar.IsNpcAvatar())
                {
                    upgradeLevel = LogicMath.Clamp(LogicDataTables.GetGlobals().GetVillage2StartUnitLevel(), 0, characterData.GetUpgradeLevelCount() - 1);
                }
            }

            character.SetUpgradeLevel(upgradeLevel);
            character.SetInitialPosition(x, y);

            if (characterData.IsJumper())
            {
                character.GetMovementComponent().EnableJump(3600000);
                character.GetCombatComponent().RefreshTarget(true);
            }

            level.GetGameObjectManager().AddGameObject(character, -1);
            level.GetGameListener().AttackerPlaced(characterData);

            LogicBattleLog battleLog = level.GetBattleLog();

            if (battleLog != null)
            {
                battleLog.IncrementDeployedAttackerUnits(characterData, 1);
                battleLog.SetCombatItemLevel(characterData, upgradeLevel);
            }

            character.UpdateAutoMerge();
            return(character);
        }
コード例 #12
0
        /// <summary>
        ///     Places the specified attacker.
        /// </summary>
        public static LogicCharacter PlaceAttacker(LogicAvatar avatar, LogicCharacterData characterData, LogicLevel level, int x, int y)
        {
            avatar.CommodityCountChangeHelper(level.GetVillageType() == 1 ? 7 : 0, characterData, -1);

            LogicCharacter character    = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(characterData, level, level.GetVillageType());
            Int32          upgradeLevel = avatar.GetUnitUpgradeLevel(characterData);

            if (level.GetMissionManager().GetMissionByCategory(2) != null && level.GetVillageType() == 1 && level.GetHomeOwnerAvatar() != null)
            {
                LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                if (homeOwnerAvatar.IsNpcAvatar())
                {
                    upgradeLevel = LogicMath.Clamp(LogicDataTables.GetGlobals().GetVillage2StartUnitLevel(), 0, characterData.GetUpgradeLevelCount());
                }
            }

            character.SetUpgradeLevel(upgradeLevel);
            character.SetInitialPosition(x, y);

            return(character);
        }
コード例 #13
0
        public void CancelUpgrade()
        {
            if (this.m_timer != null)
            {
                LogicAvatar       homeOwnerAvatar     = this.m_parent.GetLevel().GetHomeOwnerAvatar();
                int               upgradeLevel        = homeOwnerAvatar.GetUnitUpgradeLevel(this.m_hero);
                int               upgradeCost         = this.m_hero.GetUpgradeCost(upgradeLevel);
                LogicResourceData upgradeResourceData = this.m_hero.GetUpgradeResource(upgradeLevel);

                homeOwnerAvatar.CommodityCountChangeHelper(0, upgradeResourceData, LogicDataTables.GetGlobals().GetHeroUpgradeCancelMultiplier() * upgradeCost / 100);

                this.m_parent.GetLevel().GetWorkerManagerAt(this.m_parent.GetData().GetVillageType()).DeallocateWorker(this.m_parent);

                homeOwnerAvatar.SetHeroState(this.m_hero, 3);
                homeOwnerAvatar.GetChangeListener().CommodityCountChanged(2, this.m_hero, 3);

                this.m_timer.Destruct();
                this.m_timer = null;
            }
            else
            {
                Debugger.Warning("LogicHeroBaseComponent::cancelUpgrade called even upgrade is not on going!");
            }
        }
コード例 #14
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);
        }
コード例 #15
0
        public void DivideAvatarUnitsToStorages(int villageType)
        {
            if (this.m_level.GetHomeOwnerAvatar() != null)
            {
                if (villageType == 1)
                {
                    for (int i = this.m_units.Size() - 1; i >= 0; i--)
                    {
                        this.m_units[i].Destruct();
                        this.m_units.Remove(i);
                    }

                    LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();
                    LogicArrayList <LogicComponent> components = this.m_components[(int)LogicComponentType.VILLAGE2_UNIT];

                    if (homeOwnerAvatar.GetUnitsNewTotalVillage2() <= 0 || LogicDataTables.GetGlobals().Village2TrainingOnlyUseRegularStorage())
                    {
                        for (int i = 0; i < components.Size(); i++)
                        {
                            LogicVillage2UnitComponent village2UnitComponent = (LogicVillage2UnitComponent)components[i];
                            LogicCombatItemData        unitData = village2UnitComponent.GetUnitData();

                            int idx = -1;

                            for (int j = 0; j < this.m_units.Size(); j++)
                            {
                                if (this.m_units[j].GetData() == unitData)
                                {
                                    idx = j;
                                    break;
                                }
                            }

                            if (idx == -1)
                            {
                                this.m_units.Add(new LogicDataSlot(unitData, -village2UnitComponent.GetUnitCount()));
                            }
                            else
                            {
                                this.m_units[idx].SetCount(this.m_units[idx].GetCount() - village2UnitComponent.GetUnitCount());
                            }
                        }

                        LogicArrayList <LogicDataSlot> units = homeOwnerAvatar.GetUnitsVillage2();

                        for (int i = 0; i < units.Size(); i++)
                        {
                            LogicDataSlot       slot = units[i];
                            LogicCombatItemData data = (LogicCombatItemData)slot.GetData();

                            int count = slot.GetCount();
                            int idx   = -1;

                            for (int j = 0; j < this.m_units.Size(); j++)
                            {
                                if (this.m_units[j].GetData() == data)
                                {
                                    idx = j;
                                    break;
                                }
                            }

                            if (idx == -1)
                            {
                                this.m_units.Add(new LogicDataSlot(data, count));
                            }
                            else
                            {
                                this.m_units[idx].SetCount(this.m_units[idx].GetCount() + count);
                            }
                        }

                        for (int i = 0; i < this.m_units.Size(); i++)
                        {
                            LogicDataSlot      slot     = this.m_units[i];
                            LogicCharacterData unitData = (LogicCharacterData)slot.GetData();

                            int unitCount = slot.GetCount();

                            if (unitCount != 0)
                            {
                                for (int j = 0; j < components.Size(); j++)
                                {
                                    LogicVillage2UnitComponent component = (LogicVillage2UnitComponent)components[j];

                                    if (component.GetUnitData() == unitData)
                                    {
                                        int highestBuildingLevel = this.m_level.GetGameObjectManagerAt(1).GetHighestBuildingLevel(unitData.GetProductionHouseData());

                                        if (unitData.IsUnlockedForProductionHouseLevel(highestBuildingLevel))
                                        {
                                            if (unitCount < 0)
                                            {
                                                int count = component.GetUnitCount();

                                                if (count >= -unitCount)
                                                {
                                                    component.SetUnit(unitData, LogicMath.Max(0, count + unitCount));
                                                    unitCount += count;
                                                }
                                                else
                                                {
                                                    component.SetUnit(unitData, 0);
                                                    unitCount += count;
                                                }
                                            }
                                            else
                                            {
                                                int maxUnits = component.GetMaxUnitsInCamp(unitData);
                                                int addCount = LogicMath.Min(maxUnits, unitCount);

                                                component.SetUnit(unitData, addCount);
                                                unitCount -= addCount;
                                            }

                                            component.TrainUnit(unitData);
                                        }
                                        else
                                        {
                                            component.RemoveUnits();
                                        }
                                    }

                                    if (unitCount == 0)
                                    {
                                        break;
                                    }
                                }

                                if (unitCount > 0)
                                {
                                    homeOwnerAvatar.SetUnitCountVillage2(unitData, 0);
                                    homeOwnerAvatar.GetChangeListener().CommodityCountChanged(7, unitData, 0);
                                }
                            }
                        }
                    }
                    else
                    {
                        LogicArrayList <LogicDataSlot> unitsNew = homeOwnerAvatar.GetUnitsNewVillage2();

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

                            int count = slot.GetCount();
                            int index = -1;

                            for (int j = 0; j < this.m_units.Size(); j++)
                            {
                                if (this.m_units[j].GetData() == data)
                                {
                                    index = j;
                                    break;
                                }
                            }

                            if (count > 0)
                            {
                                if (index != -1)
                                {
                                    this.m_units[index].SetCount(this.m_units[index].GetCount() + count);
                                    this.m_units.Add(new LogicDataSlot(data, count));
                                }
                                else
                                {
                                    this.m_units.Add(new LogicDataSlot(data, count));
                                }
                            }
                        }

                        for (int i = 0; i < this.m_units.Size(); i++)
                        {
                            homeOwnerAvatar.CommodityCountChangeHelper(8, this.m_units[i].GetData(), -this.m_units[i].GetCount());
                        }

                        for (int i = 0; i < this.m_units.Size(); i++)
                        {
                            LogicDataSlot      slot = this.m_units[i];
                            LogicCharacterData data = (LogicCharacterData)slot.GetData();

                            int count = slot.GetCount();

                            if (count > 0)
                            {
                                for (int j = 0; j < components.Size(); j++)
                                {
                                    LogicVillage2UnitComponent village2UnitComponent = (LogicVillage2UnitComponent)components[j];

                                    int maxUnitsInCamp = village2UnitComponent.GetMaxUnitsInCamp(data);
                                    int addCount       = LogicMath.Min(count, maxUnitsInCamp);

                                    village2UnitComponent.SetUnit(data, addCount);
                                    village2UnitComponent.TrainUnit(data);

                                    count -= addCount;

                                    if (count <= 0)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    for (int i = this.m_units.Size() - 1; i >= 0; i--)
                    {
                        this.m_units[i].Destruct();
                        this.m_units.Remove(i);
                    }

                    LogicArrayList <LogicComponent> components = this.m_components[(int)LogicComponentType.UNIT_STORAGE];

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

                        for (int j = 0; j < storageComponent.GetUnitTypeCount(); j++)
                        {
                            LogicCombatItemData unitType = storageComponent.GetUnitType(j);
                            int unitCount = storageComponent.GetUnitCount(j);
                            int index     = -1;

                            for (int k = 0; k < this.m_units.Size(); k++)
                            {
                                LogicDataSlot tmp = this.m_units[k];

                                if (tmp.GetData() == unitType)
                                {
                                    index = k;
                                    break;
                                }
                            }

                            if (index != -1)
                            {
                                this.m_units[index].SetCount(this.m_units[index].GetCount() - unitCount);
                            }
                            else
                            {
                                this.m_units.Add(new LogicDataSlot(unitType, -unitCount));
                            }
                        }
                    }

                    LogicArrayList <LogicDataSlot> units = this.m_level.GetHomeOwnerAvatar().GetUnits();

                    for (int i = 0; i < units.Size(); i++)
                    {
                        LogicDataSlot slot  = units[i];
                        int           index = -1;

                        for (int j = 0; j < this.m_units.Size(); j++)
                        {
                            LogicDataSlot tmp = this.m_units[j];

                            if (tmp.GetData() == slot.GetData())
                            {
                                index = j;
                                break;
                            }
                        }

                        if (index != -1)
                        {
                            this.m_units[index].SetCount(this.m_units[index].GetCount() + slot.GetCount());
                        }
                        else
                        {
                            this.m_units.Add(new LogicDataSlot(slot.GetData(), slot.GetCount()));
                        }
                    }

                    LogicArrayList <LogicDataSlot> spells = this.m_level.GetHomeOwnerAvatar().GetSpells();

                    for (int i = 0; i < spells.Size(); i++)
                    {
                        LogicDataSlot slot  = spells[i];
                        int           index = -1;

                        for (int j = 0; j < this.m_units.Size(); j++)
                        {
                            LogicDataSlot tmp = this.m_units[j];

                            if (tmp.GetData() == slot.GetData())
                            {
                                index = j;
                                break;
                            }
                        }

                        if (index != -1)
                        {
                            this.m_units[index].SetCount(this.m_units[index].GetCount() + slot.GetCount());
                        }
                        else
                        {
                            this.m_units.Add(new LogicDataSlot(slot.GetData(), slot.GetCount()));
                        }
                    }

                    for (int i = 0; i < this.m_units.Size(); i++)
                    {
                        LogicDataSlot       slot = this.m_units[i];
                        LogicCombatItemData data = (LogicCombatItemData)slot.GetData();
                        int unitCount            = slot.GetCount();

                        if (unitCount != 0)
                        {
                            for (int j = 0; j < components.Size(); j++)
                            {
                                LogicUnitStorageComponent unitStorageComponent = (LogicUnitStorageComponent)components[j];

                                if (unitCount >= 0)
                                {
                                    while (unitStorageComponent.CanAddUnit(data))
                                    {
                                        unitStorageComponent.AddUnit(data);

                                        if (--unitCount <= 0)
                                        {
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    int idx = unitStorageComponent.GetUnitTypeIndex(data);

                                    if (idx != -1)
                                    {
                                        int count = unitStorageComponent.GetUnitCount(idx);

                                        if (count < -unitCount)
                                        {
                                            unitStorageComponent.RemoveUnits(data, count);
                                            unitCount += count;
                                        }
                                        else
                                        {
                                            unitStorageComponent.RemoveUnits(data, -unitCount);
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }