コード例 #1
0
        public int GetResourceCost(LogicResourceData resourceData)
        {
            int cost = 0;

            LogicAvatar    homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();
            LogicCalendar  calendar        = this.m_level.GetCalendar();
            LogicDataTable table           = LogicDataTables.GetTable(LogicDataType.CHARACTER);

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

                if (calendar.IsProductionEnabled(data) && !data.IsSecondaryTroop())
                {
                    int count = homeOwnerAvatar.GetUnitPresetCount(data, this.m_presetId);

                    if (count > 0)
                    {
                        if (data.GetTrainingResource() == resourceData)
                        {
                            cost += count * calendar.GetTrainingCost(data, homeOwnerAvatar.GetUnitUpgradeLevel(data));
                        }
                    }
                }
            }

            table = LogicDataTables.GetTable(LogicDataType.SPELL);

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

                if (calendar.IsProductionEnabled(data))
                {
                    int count = homeOwnerAvatar.GetUnitPresetCount(data, this.m_presetId);

                    if (count > 0)
                    {
                        if (data.GetTrainingResource() == resourceData)
                        {
                            cost += count * calendar.GetTrainingCost(data, homeOwnerAvatar.GetUnitUpgradeLevel(data));
                        }
                    }
                }
            }

            return(cost);
        }
コード例 #2
0
        public void AddDefendingHero()
        {
            LogicAvatar visitorAvatar   = this.m_parent.GetLevel().GetVisitorAvatar();
            LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();

            int randomPatrolPoint = visitorAvatar != null
                ? (int)(((visitorAvatar.GetResourceCount(LogicDataTables.GetGoldData()) + 10 * this.m_hero.GetGlobalID()) & 0x7FFFFFFFu) % this.m_patrolPath.Size())
                : 0;
            int upgLevel      = homeOwnerAvatar.GetUnitUpgradeLevel(this.m_hero);
            int heroHitpoints = this.m_hero.GetHeroHitpoints(homeOwnerAvatar.GetHeroHealth(this.m_hero), upgLevel);

            if (this.m_hero.HasEnoughHealthForAttack(heroHitpoints, upgLevel))
            {
                LogicVector2   patrolPoint = this.m_patrolPath[randomPatrolPoint];
                LogicCharacter hero        = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(this.m_hero, this.m_parent.GetLevel(), this.m_parent.GetVillageType());

                hero.GetMovementComponent().SetBaseBuilding((LogicBuilding)this.m_parent);
                hero.GetHitpointComponent().SetTeam(1);
                hero.SetUpgradeLevel(upgLevel);
                hero.GetHitpointComponent().SetHitpoints(heroHitpoints);

                hero.SetInitialPosition(patrolPoint.m_x, patrolPoint.m_y);

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

                hero.GetCombatComponent().SetSearchRadius(this.m_hero.GetMaxSearchRadiusForDefender() / 512);

                if (LogicDataTables.GetGlobals().EnableDefendingAllianceTroopJump())
                {
                    hero.GetMovementComponent().EnableJump(3600000);
                }
            }
        }
コード例 #3
0
        public int GetTotalSeconds()
        {
            LogicUnitProductionSlot slot = null;

            for (int i = 0; i < this.m_slots.Size(); i++)
            {
                LogicUnitProductionSlot tmp = this.m_slots[i];

                if (!tmp.IsTerminate())
                {
                    slot = tmp;
                    break;
                }
            }

            if (slot != null)
            {
                LogicAvatar         homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();
                LogicCombatItemData data            = (LogicCombatItemData)slot.GetData();

                return(data.GetTrainingTime(homeOwnerAvatar.GetUnitUpgradeLevel(data), this.m_level, 0));
            }

            return(0);
        }
コード例 #4
0
        public void AddUnitsToQueue(LogicCombatItemData data, int count)
        {
            LogicCalendar          calendar          = this.m_level.GetCalendar();
            LogicAvatar            homeOwnerAvatar   = this.m_level.GetHomeOwnerAvatar();
            LogicClientAvatar      playerAvatar      = this.m_level.GetPlayerAvatar();
            LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(0);
            LogicUnitProduction    production        = gameObjectManager.GetUnitProduction();

            if (data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
            {
                if (data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_SPELL)
                {
                    return;
                }

                production = gameObjectManager.GetSpellProduction();
            }

            if (production != null)
            {
                int trainCost = calendar.GetTrainingCost(data, homeOwnerAvatar.GetUnitUpgradeLevel(data));

                for (int i = 0; i < count; i++)
                {
                    if (production.CanAddUnitToQueue(data, true) &&
                        playerAvatar.HasEnoughResources(data.GetTrainingResource(), trainCost, false, null, false))
                    {
                        playerAvatar.CommodityCountChangeHelper(0, data.GetTrainingResource(), -trainCost);
                        production.AddUnitToQueue(data, production.GetSlotCount(), true);
                    }
                }
            }
        }
コード例 #5
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);
        }
コード例 #6
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");
            }
        }
コード例 #7
0
        public void StartUpgrading()
        {
            if (this.CanStartUpgrading(true))
            {
                ((LogicBuilding)this.m_parent).DestructBoost();

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

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

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

                this.m_timer = new LogicTimer();
                this.m_timer.StartTimer(this.GetTotalSeconds(), this.m_parent.GetLevel().GetLogicTime(), true,
                                        this.m_parent.GetLevel().GetHomeOwnerAvatarChangeListener().GetCurrentTimestamp());
                this.m_upgLevel = homeOwnerAvatar.GetUnitUpgradeLevel(this.m_hero) + 1;

                homeOwnerAvatar.SetHeroState(this.m_hero, 1);
                homeOwnerAvatar.GetChangeListener().CommodityCountChanged(2, this.m_hero, 1);
            }
        }
コード例 #8
0
        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);
                }
            }
        }
コード例 #9
0
        public int GetMaxUnitsInCamp(LogicCharacterData data)
        {
            LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();

            if (homeOwnerAvatar != null)
            {
                return(data.GetUnitsInCamp(homeOwnerAvatar.GetUnitUpgradeLevel(data)));
            }

            Debugger.Error("AVATAR = NULL");

            return(0);
        }
コード例 #10
0
        /// <summary>
        ///     Gets the max unit count.
        /// </summary>
        public int GetMaxCapacity()
        {
            LogicAvatar        homeOwnerAvatar = this._parent.GetLevel().GetHomeOwnerAvatar();
            LogicCharacterData characterData   = (LogicCharacterData)this._unit.GetData();

            if (homeOwnerAvatar != null)
            {
                return(characterData.GetUnitsInCamp(homeOwnerAvatar.GetUnitUpgradeLevel(characterData)));
            }

            Debugger.Error("AVATAR = NULL");

            return(0);
        }
コード例 #11
0
        public int AddUnitToQueue(LogicCombatItemData data)
        {
            if (data != null)
            {
                if (this.CanAddUnitToQueue(data, false))
                {
                    LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();

                    for (int i = this.m_slots.Size() - 1; i >= 0; i--)
                    {
                        LogicUnitProductionSlot tmp = this.m_slots[i];

                        if (tmp != null)
                        {
                            if (tmp.GetData() == data)
                            {
                                tmp.SetCount(tmp.GetCount() + 1);
                                this.MergeSlots();

                                return(i);
                            }

                            break;
                        }
                    }

                    this.m_slots.Add(new LogicUnitProductionSlot(data, 1, false));
                    this.MergeSlots();

                    if (this.m_slots.Size() > 0)
                    {
                        LogicCombatItemData productionData = this.GetCurrentlyTrainedUnit();

                        if (productionData != null && this.m_timer == null)
                        {
                            this.m_timer = new LogicTimer();
                            this.m_timer.StartTimer(productionData.GetTrainingTime(homeOwnerAvatar.GetUnitUpgradeLevel(productionData), this.m_level, 0),
                                                    this.m_level.GetLogicTime(), false, -1);
                        }
                    }
                }
            }
            else
            {
                Debugger.Error("LogicUnitProduction - Trying to add NULL character!");
            }

            return(-1);
        }
コード例 #12
0
        public bool DragSlot(int slotIdx, int dragIdx)
        {
            this.m_locked = false;

            if (slotIdx > -1 && slotIdx < this.m_slots.Size())
            {
                LogicCombatItemData     productionData = this.GetCurrentlyTrainedUnit();
                LogicUnitProductionSlot slot           = this.m_slots[slotIdx];

                this.m_slots.Remove(slotIdx);

                if (slot != null)
                {
                    if (slotIdx <= dragIdx)
                    {
                        dragIdx -= 1;
                    }

                    if (dragIdx >= 0 && dragIdx <= this.m_slots.Size())
                    {
                        this.m_slots.Add(dragIdx, slot);
                        this.MergeSlots();

                        LogicCombatItemData prodData = this.GetCurrentlyTrainedUnit();
                        int prodIdx = this.GetCurrentlyTrainedIndex();

                        if (productionData != prodData && (dragIdx >= prodIdx || prodIdx == slotIdx || prodIdx == dragIdx + 1))
                        {
                            if (this.m_timer != null)
                            {
                                this.m_timer.Destruct();
                                this.m_timer = null;
                            }

                            LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();

                            this.m_timer = new LogicTimer();
                            this.m_timer.StartTimer(prodData.GetTrainingTime(homeOwnerAvatar.GetUnitUpgradeLevel(prodData), this.m_level, 0),
                                                    this.m_level.GetLogicTime(), false, -1);
                        }
                    }

                    return(true);
                }
            }

            return(false);
        }
コード例 #13
0
        public int GetTotalRemainingSeconds()
        {
            LogicAvatar           homeOwnerAvatar  = this.m_level.GetHomeOwnerAvatar();
            LogicComponentManager componentManager = this.m_level.GetComponentManagerAt(this.m_villageType);

            int totalMaxHousing   = componentManager.GetTotalMaxHousing(this.m_unitProductionType != LogicDataType.CHARACTER ? 1 : 0);
            int totalUsedCapacity = this.m_unitProductionType == LogicDataType.CHARACTER ? homeOwnerAvatar.GetUnitsTotalCapacity() : homeOwnerAvatar.GetSpellsTotalCapacity();
            int freeCapacity      = totalMaxHousing - totalUsedCapacity;
            int remainingSecs     = 0;

            for (int i = 0; i < this.m_slots.Size(); i++)
            {
                LogicUnitProductionSlot slot = this.m_slots[i];
                LogicCombatItemData     data = (LogicCombatItemData)slot.GetData();
                int housingSpace             = data.GetHousingSpace();
                int count = slot.GetCount();

                if (count > 0)
                {
                    if (i == 0)
                    {
                        if (!slot.IsTerminate() && freeCapacity - housingSpace >= 0)
                        {
                            if (this.m_timer != null)
                            {
                                remainingSecs += this.m_timer.GetRemainingSeconds(this.m_level.GetLogicTime());
                            }
                        }

                        freeCapacity -= housingSpace;
                        count        -= 1;
                    }

                    for (int j = 0; j < count; j++)
                    {
                        if (!slot.IsTerminate() && freeCapacity - housingSpace >= 0)
                        {
                            remainingSecs += data.GetTrainingTime(homeOwnerAvatar.GetUnitUpgradeLevel(data), this.m_level, 0);
                        }

                        freeCapacity -= housingSpace;
                    }
                }
            }

            return(remainingSecs);
        }
コード例 #14
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;
            }
        }
コード例 #15
0
        public int AddUnitToQueue(LogicCombatItemData data, int index, bool ignoreCapacity)
        {
            if (data != null)
            {
                if (this.CanAddUnitToQueue(data, ignoreCapacity))
                {
                    LogicAvatar         homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();
                    LogicCombatItemData productionData  = this.GetCurrentlyTrainedUnit();

                    this.m_slots.Add(index, new LogicUnitProductionSlot(data, 1, false));
                    this.MergeSlots();

                    if (productionData != null)
                    {
                        if (this.GetCurrentlyTrainedUnit() == data || this.GetCurrentlyTrainedIndex() != index)
                        {
                            return(index);
                        }
                    }
                    else
                    {
                        productionData = this.GetCurrentlyTrainedUnit();
                    }

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

                    this.m_timer = new LogicTimer();
                    this.m_timer.StartTimer(productionData.GetTrainingTime(homeOwnerAvatar.GetUnitUpgradeLevel(productionData), this.m_level, 0),
                                            this.m_level.GetLogicTime(), false, -1);

                    return(index);
                }
            }
            else
            {
                Debugger.Error("LogicUnitProduction - Trying to add NULL character!");
            }

            return(-1);
        }
コード例 #16
0
        public bool CanStartUpgrading(bool callListener)
        {
            if (this.m_timer == null)
            {
                if (!this.IsMaxLevel())
                {
                    LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();

                    int requiredTownHallLevel = this.m_hero.GetRequiredTownHallLevel(homeOwnerAvatar.GetUnitUpgradeLevel(this.m_hero) + 1);
                    int townHallLevel         = this.m_parent.GetLevel().GetTownHallLevel(this.m_parent.GetLevel().GetVillageType());

                    if (townHallLevel >= requiredTownHallLevel)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #17
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);
        }
コード例 #18
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);
        }
コード例 #19
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!");
            }
        }
        public override void Load(LogicJSONObject root)
        {
            if (this.m_timer != null)
            {
                this.m_timer.Destruct();
                this.m_timer = null;
            }

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

            LogicJSONObject jsonObject = root.GetJSONObject("unit_prod");

            if (jsonObject != null)
            {
                LogicJSONNumber modeObject = jsonObject.GetJSONNumber("m");

                if (modeObject != null)
                {
                    this.m_mode = true;
                }

                LogicJSONNumber unitTypeObject = jsonObject.GetJSONNumber("unit_type");

                if (unitTypeObject != null)
                {
                    this.m_productionType = unitTypeObject.GetIntValue();
                }

                LogicJSONArray slotArray = jsonObject.GetJSONArray("slots");

                if (slotArray != null)
                {
                    for (int i = 0; i < slotArray.Size(); i++)
                    {
                        LogicJSONObject slotObject = slotArray.GetJSONObject(i);

                        if (slotObject != null)
                        {
                            LogicJSONNumber idObject = slotObject.GetJSONNumber("id");

                            if (idObject != null)
                            {
                                LogicData data = LogicDataTables.GetDataById(idObject.GetIntValue(),
                                                                             this.m_productionType == 0 ? LogicDataType.CHARACTER : LogicDataType.SPELL);

                                if (data != null)
                                {
                                    LogicJSONNumber countObject = slotObject.GetJSONNumber("cnt");

                                    if (countObject != null)
                                    {
                                        if (countObject.GetIntValue() > 0)
                                        {
                                            this.m_slots.Add(new LogicDataSlot(data, countObject.GetIntValue()));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (this.m_slots.Size() > 0)
                {
                    LogicJSONNumber timeObject = jsonObject.GetJSONNumber("t");

                    if (timeObject != null)
                    {
                        this.m_timer = new LogicTimer();
                        this.m_timer.StartTimer(timeObject.GetIntValue(), this.m_parent.GetLevel().GetLogicTime(), false, -1);
                    }
                    else
                    {
                        LogicCombatItemData data            = (LogicCombatItemData)this.m_slots[0].GetData();
                        LogicAvatar         homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();
                        int upgLevel = homeOwnerAvatar != null?homeOwnerAvatar.GetUnitUpgradeLevel(data) : 0;

                        this.m_timer = new LogicTimer();
                        this.m_timer.StartTimer(data.GetTrainingTime(upgLevel, this.m_parent.GetLevel(), 0), this.m_parent.GetLevel().GetLogicTime(), false, -1);
                    }
                }
            }
            else
            {
                this.m_productionType = 0;

                if (this.m_parent.GetVillageType() == 0)
                {
                    Debugger.Warning("LogicUnitProductionComponent::load - Component wasn't found from the JSON");
                }
            }
        }
コード例 #21
0
        public void ValidateTroopUpgradeLevels()
        {
            LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();

            if (homeOwnerAvatar != null)
            {
                if (homeOwnerAvatar.IsClientAvatar())
                {
                    int[] laboratoryLevels = new int[2];

                    for (int i = 0; i < 2; i++)
                    {
                        LogicBuilding laboratory = this.m_level.GetGameObjectManagerAt(i).GetLaboratory();

                        if (laboratory != null)
                        {
                            laboratoryLevels[i] = laboratory.GetUpgradeLevel();
                        }
                    }

                    LogicDataTable characterTable = LogicDataTables.GetTable(LogicDataType.CHARACTER);

                    for (int i = 0; i < characterTable.GetItemCount(); i++)
                    {
                        LogicCharacterData characterData = (LogicCharacterData)characterTable.GetItemAt(i);

                        int upgradeLevel    = homeOwnerAvatar.GetUnitUpgradeLevel(characterData);
                        int villageType     = characterData.GetVillageType();
                        int newUpgradeLevel = upgradeLevel;

                        if (upgradeLevel >= characterData.GetUpgradeLevelCount())
                        {
                            newUpgradeLevel = characterData.GetUpgradeLevelCount() - 1;
                        }

                        int laboratoryLevel = laboratoryLevels[villageType];
                        int requireLaboratoryLevel;

                        do
                        {
                            requireLaboratoryLevel = characterData.GetRequiredLaboratoryLevel(newUpgradeLevel--);
                        } while (newUpgradeLevel >= 0 && requireLaboratoryLevel > laboratoryLevel);

                        newUpgradeLevel += 1;

                        if (upgradeLevel > newUpgradeLevel)
                        {
                            homeOwnerAvatar.SetUnitUpgradeLevel(characterData, newUpgradeLevel);
                            homeOwnerAvatar.GetChangeListener().CommodityCountChanged(1, characterData, newUpgradeLevel);
                        }
                    }

                    LogicDataTable spellTable = LogicDataTables.GetTable(LogicDataType.SPELL);

                    for (int i = 0; i < spellTable.GetItemCount(); i++)
                    {
                        LogicSpellData spellData = (LogicSpellData)spellTable.GetItemAt(i);

                        int upgradeLevel    = homeOwnerAvatar.GetUnitUpgradeLevel(spellData);
                        int villageType     = spellData.GetVillageType();
                        int newUpgradeLevel = upgradeLevel;

                        if (upgradeLevel >= spellData.GetUpgradeLevelCount())
                        {
                            newUpgradeLevel = spellData.GetUpgradeLevelCount() - 1;
                        }

                        int laboratoryLevel = laboratoryLevels[villageType];
                        int requireLaboratoryLevel;

                        do
                        {
                            requireLaboratoryLevel = spellData.GetRequiredLaboratoryLevel(newUpgradeLevel--);
                        } while (newUpgradeLevel >= 0 && requireLaboratoryLevel > laboratoryLevel);

                        newUpgradeLevel += 1;

                        if (upgradeLevel > newUpgradeLevel)
                        {
                            homeOwnerAvatar.SetUnitUpgradeLevel(spellData, newUpgradeLevel);
                            homeOwnerAvatar.GetChangeListener().CommodityCountChanged(1, spellData, newUpgradeLevel);
                        }
                    }
                }
            }
        }
コード例 #22
0
        public override void LoadingFinished()
        {
            if (this.m_parent.GetLevel().IsInCombatState())
            {
                if (this.m_parent.GetVillageType() == this.m_parent.GetLevel().GetVillageType())
                {
                    if (this.m_parent.GetLevel().GetVillageType() == this.m_parent.GetVillageType())
                    {
                        this.m_patrolPath = this.CreatePatrolPath();
                    }
                }
            }

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

            if (!building.IsLocked() && homeOwnerAvatar.GetHeroState(this.m_hero) == 0)
            {
                homeOwnerAvatar.SetHeroState(this.m_hero, 3);
                homeOwnerAvatar.GetChangeListener().CommodityCountChanged(2, this.m_hero, 3);
            }

            if (this.m_timer != null)
            {
                int remainingSecs = this.m_timer.GetRemainingSeconds(this.m_parent.GetLevel().GetLogicTime());
                int totalSecs     = this.GetTotalSeconds();

                if (LogicDataTables.GetGlobals().ClampUpgradeTimes())
                {
                    if (remainingSecs > totalSecs)
                    {
                        this.m_timer.StartTimer(totalSecs, this.m_parent.GetLevel().GetLogicTime(), true,
                                                this.m_parent.GetLevel().GetHomeOwnerAvatarChangeListener().GetCurrentTimestamp());
                    }
                }
                else
                {
                    this.m_timer.StartTimer(LogicMath.Min(remainingSecs, totalSecs), this.m_parent.GetLevel().GetLogicTime(), false, -1);
                }

                if (!building.IsLocked() && homeOwnerAvatar.GetHeroState(this.m_hero) != 1)
                {
                    homeOwnerAvatar.SetHeroState(this.m_hero, 1);
                    homeOwnerAvatar.GetChangeListener().CommodityCountChanged(2, this.m_hero, 1);
                }
            }
            else
            {
                if (!building.IsLocked() && homeOwnerAvatar.GetHeroState(this.m_hero) == 1)
                {
                    homeOwnerAvatar.SetHeroState(this.m_hero, 3);
                    homeOwnerAvatar.GetChangeListener().CommodityCountChanged(2, this.m_hero, 3);
                }
            }

            if (this.m_hero.HasNoDefence() && !this.m_parent.GetLevel().IsInCombatState() && homeOwnerAvatar.GetHeroState(this.m_hero) == 3)
            {
                homeOwnerAvatar.SetHeroState(this.m_hero, 2);
                homeOwnerAvatar.GetChangeListener().CommodityCountChanged(2, this.m_hero, 2);
            }

            if (homeOwnerAvatar.GetHeroState(this.m_hero) == 3)
            {
                if (this.m_parent.GetLevel().IsInCombatState())
                {
                    if (!this.m_sharedHeroCombatData && !this.m_hero.HasNoDefence())
                    {
                        if (this.m_parent.GetVillageType() == this.m_parent.GetLevel().GetVillageType())
                        {
                            this.AddDefendingHero();
                        }
                    }
                }
            }

            int heroHealth           = homeOwnerAvatar.GetHeroHealth(this.m_hero);
            int fullRegenerationTime = this.m_hero.GetFullRegenerationTimeSec(homeOwnerAvatar.GetUnitUpgradeLevel(this.m_hero));

            if (fullRegenerationTime < heroHealth)
            {
                homeOwnerAvatar.GetChangeListener().CommodityCountChanged(0, this.m_hero, fullRegenerationTime);
                homeOwnerAvatar.SetHeroHealth(this.m_hero, fullRegenerationTime);
            }
        }
コード例 #23
0
        public bool RemoveUnit(LogicCombatItemData data, int index)
        {
            LogicUnitProductionSlot slot = null;
            bool removed = false;

            if (index > -1 &&
                this.m_slots.Size() > index &&
                this.m_slots[index].GetData() == data)
            {
                slot = this.m_slots[index];
            }
            else
            {
                index = -1;

                for (int i = 0; i < this.m_slots.Size(); i++)
                {
                    LogicUnitProductionSlot tmp = this.m_slots[i];

                    if (tmp.GetData() == data)
                    {
                        index = i;
                        break;
                    }
                }

                if (index == -1)
                {
                    return(false);
                }

                slot = this.m_slots[index];
            }

            int count = slot.GetCount();

            if (count > 0)
            {
                removed = true;
                slot.SetCount(count - 1);

                if (count == 1)
                {
                    int prodIdx = this.GetCurrentlyTrainedIndex();

                    if (prodIdx == index)
                    {
                        if (this.m_timer != null)
                        {
                            this.m_timer.Destruct();
                            this.m_timer = null;
                        }
                    }

                    this.m_slots[index].Destruct();
                    this.m_slots.Remove(index);
                }
            }

            if (this.m_slots.Size() > 0)
            {
                LogicUnitProductionSlot productionSlot = this.GetCurrentlyTrainedSlot();

                if (productionSlot == null || this.m_timer != null)
                {
                    if (!removed)
                    {
                        return(false);
                    }

                    this.MergeSlots();
                }
                else
                {
                    LogicAvatar         homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();
                    LogicCombatItemData productionData  = (LogicCombatItemData)productionSlot.GetData();

                    this.m_timer = new LogicTimer();
                    this.m_timer.StartTimer(productionData.GetTrainingTime(homeOwnerAvatar.GetUnitUpgradeLevel(productionData), this.m_level, 0), this.m_level.GetLogicTime(),
                                            false,
                                            -1);

                    if (removed)
                    {
                        this.MergeSlots();
                    }
                }
            }
            else
            {
                if (!removed)
                {
                    return(false);
                }

                this.MergeSlots();
            }

            return(true);
        }
コード例 #24
0
        public void Load(LogicJSONObject root)
        {
            if (this.m_timer != null)
            {
                this.m_timer.Destruct();
                this.m_timer = null;
            }

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

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

            LogicJSONObject jsonObject = root.GetJSONObject("unit_prod");

            if (jsonObject != null)
            {
                LogicJSONArray slotArray = jsonObject.GetJSONArray("slots");

                if (slotArray != null)
                {
                    for (int i = 0; i < slotArray.Size(); i++)
                    {
                        LogicJSONObject slotObject = slotArray.GetJSONObject(i);

                        if (slotObject != null)
                        {
                            LogicJSONNumber dataObject = slotObject.GetJSONNumber("id");

                            if (dataObject != null)
                            {
                                LogicData data = LogicDataTables.GetDataById(dataObject.GetIntValue());

                                if (data != null)
                                {
                                    LogicJSONNumber  countObject   = slotObject.GetJSONNumber("cnt");
                                    LogicJSONBoolean termineObject = slotObject.GetJSONBoolean("t");

                                    if (countObject != null)
                                    {
                                        if (countObject.GetIntValue() > 0)
                                        {
                                            LogicUnitProductionSlot slot = new LogicUnitProductionSlot(data, countObject.GetIntValue(), false);

                                            if (termineObject != null)
                                            {
                                                slot.SetTerminate(termineObject.IsTrue());
                                            }

                                            this.m_slots.Add(slot);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (this.m_slots.Size() > 0)
                {
                    LogicUnitProductionSlot slot = this.GetCurrentlyTrainedSlot();

                    if (slot != null)
                    {
                        LogicJSONNumber timeObject = jsonObject.GetJSONNumber("t");

                        if (timeObject != null)
                        {
                            this.m_timer = new LogicTimer();
                            this.m_timer.StartTimer(timeObject.GetIntValue(), this.m_level.GetLogicTime(), false, -1);
                        }
                        else
                        {
                            LogicCombatItemData combatItemData = (LogicCombatItemData)slot.GetData();
                            LogicAvatar         avatar         = this.m_level.GetHomeOwnerAvatar();
                            int upgradeLevel = 0;

                            if (avatar != null)
                            {
                                upgradeLevel = avatar.GetUnitUpgradeLevel(combatItemData);
                            }

                            this.m_timer = new LogicTimer();
                            this.m_timer.StartTimer(combatItemData.GetTrainingTime(upgradeLevel, this.m_level, 0), this.m_level.GetLogicTime(), false, -1);

                            Debugger.Print("LogicUnitProduction::load null timer, restart: " + this.m_timer.GetRemainingSeconds(this.m_level.GetLogicTime()));
                        }
                    }
                }

                LogicJSONNumber boostTimeObject = jsonObject.GetJSONNumber("boost_t");

                if (boostTimeObject != null)
                {
                    this.m_boostTimer = new LogicTimer();
                    this.m_boostTimer.StartTimer(boostTimeObject.GetIntValue(), this.m_level.GetLogicTime(), false, -1);
                }

                LogicJSONBoolean boostPauseObject = jsonObject.GetJSONBoolean("boost_pause");

                if (boostPauseObject != null)
                {
                    this.m_boostPause = boostPauseObject.IsTrue();
                }
            }
            else
            {
                Debugger.Warning("LogicUnitProduction::load - Component wasn't found from the JSON");
            }
        }