public void XpGainHelper(int xp, LogicAvatar homeOwnerAvatar, bool inHomeState)
        {
            LogicClientAvatar playerAvatar = this.m_level.GetPlayerAvatar();

            if (!homeOwnerAvatar.IsInExpLevelCap())
            {
                if (homeOwnerAvatar == playerAvatar && this.m_level.GetState() == 1 && inHomeState)
                {
                    if (this.m_listener != null)
                    {
                        this.m_listener.XpGained(xp);
                    }
                }
            }

            homeOwnerAvatar.XpGainHelper(xp);
        }
Пример #2
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;
            }
        }
Пример #3
0
        public override void DeathEvent()
        {
            LogicHitpointComponent hitpointComponent = this.GetHitpointComponent();
            LogicCharacterData     data = this.GetCharacterData();

            if (hitpointComponent != null && hitpointComponent.GetTeam() == 1 && !this.IsHero() && !data.IsSecondaryTroop() &&
                this.m_level.GetVillageType() == 0 && this.m_allianceUnit)
            {
                LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();

                homeOwnerAvatar.RemoveAllianceUnit(data, this.m_upgradeLevel);
                homeOwnerAvatar.GetChangeListener().AllianceUnitRemoved(data, this.m_upgradeLevel);
            }

            if (data.GetSpecialAbilityType() != LogicCharacterData.SPECIAL_ABILITY_TYPE_RESPAWN_AS_CANNON ||
                data.GetSpecialAbilityLevel(this.m_upgradeLevel) <= 0)
            {
                if (data.GetSpecialAbilityType() == LogicCharacterData.SPECIAL_ABILITY_TYPE_SPAWN_UNITS)
                {
                    if (data.GetSpecialAbilityLevel(this.m_upgradeLevel) > 0)
                    {
                        this.CheckSpawning(null, data.GetSpecialAbilityAttribute(this.m_upgradeLevel), 0, 0);
                    }
                }
                else if (data.GetSecondaryTroop() != null)
                {
                    this.CheckSpawning(null, 0, 0, 0);
                }
            }
            else if (!this.m_ejected)
            {
                this.CheckSpawning(LogicDataTables.GetCharacterByName("MovingCannonSecondary", null), 1, data.GetSpecialAbilityAttribute(this.m_upgradeLevel), 500);
            }

            this.AddTombstoneIfNeeded();

            if (this.m_parent != null)
            {
                this.m_parent.RemoveChildren(this);
                this.m_parent = null;
            }

            base.DeathEvent();
        }
Пример #4
0
        public void LoadRevengeAttackState(LogicClientHome home, LogicAvatar homeOwnerAvatar, LogicAvatar visitorAvatar, int currentTimestamp, int secondsSinceLastSave,
                                           int secondsSinceLastMaintenance, LogicLong revengeId)
        {
            if (this.m_state != 0)
            {
                Debugger.Error("loadAttackState called from invalid state");
            }
            else
            {
                this.m_state          = 2;
                this.m_startTimestamp = currentTimestamp;
                this.m_secondsSinceLastMaintenance = secondsSinceLastMaintenance;
                this.m_configuration.Load((LogicJSONObject)LogicJSONParser.Parse(home.GetGlobalJSON()));
                this.m_calendar.Load(home.GetCalendarJSON(), currentTimestamp);

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

                this.m_battleTimer = new LogicTimer();
                this.m_battleTimer.StartTimer(LogicDataTables.GetGlobals().GetAttackLengthSecs() + LogicDataTables.GetGlobals().GetAttackPreparationLengthSecs(),
                                              this.m_level.GetLogicTime(), false, -1);

                if (homeOwnerAvatar.IsClientAvatar())
                {
                    this.m_level.SetMatchType(4, revengeId);
                    this.m_level.SetHome(home, false);
                    this.m_level.SetHomeOwnerAvatar(homeOwnerAvatar);
                    this.m_level.SetVisitorAvatar(visitorAvatar);
                    this.m_level.FastForwardTime(secondsSinceLastSave);

                    homeOwnerAvatar.SetLevel(this.m_level);

                    this.m_level.LoadingFinished();
                    this.m_replay = new LogicReplay(this.m_level);
                }
                else
                {
                    Debugger.Error("loadDirectAttackState called and home owner is not client avatar");
                }
            }
        }
Пример #5
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);
        }
Пример #6
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);
                    }
                }
            }
        }
        public override int Execute(LogicLevel level)
        {
            if (this.m_excludeMemberList == null || this.m_excludeMemberList.Size() <= LogicDataTables.GetGlobals().GetWarMaxExcludeMembers())
            {
                if (this.m_enemyAllianceId != null)
                {
                    LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                    if (homeOwnerAvatar.IsInAlliance())
                    {
                        if (homeOwnerAvatar.GetAllianceRole() == LogicAvatarAllianceRole.LEADER || homeOwnerAvatar.GetAllianceRole() == LogicAvatarAllianceRole.CO_LEADER)
                        {
                            LogicBuilding allianceCastle = level.GetGameObjectManagerAt(0).GetAllianceCastle();

                            if (allianceCastle != null)
                            {
                                LogicBunkerComponent bunkerComponent = allianceCastle.GetBunkerComponent();

                                if (bunkerComponent != null && bunkerComponent.GetArrangedWarCooldownTime() == 0)
                                {
                                    bunkerComponent.StartArrangedWarCooldownTime();
                                    homeOwnerAvatar.GetChangeListener().StartArrangedWar(this.m_excludeMemberList, this.m_enemyAllianceId, 0, 0, 0);

                                    return(0);
                                }

                                return(-5);
                            }

                            return(-4);
                        }

                        return(-3);
                    }

                    return(-2);
                }

                return(-3);
            }

            return(-1);
        }
Пример #8
0
        /// <summary>
        ///     Gets if the player has travel.
        /// </summary>
        public bool HasTravel(LogicAvatar playerAvatar)
        {
            LogicDataTable missionTable = LogicDataTables.GetTable(20);

            for (int i = 0; i < missionTable.GetItemCount(); i++)
            {
                LogicMissionData missionData = (LogicMissionData)missionTable.GetItemAt(i);

                if (missionData.GetMissionType() == 23)
                {
                    if (playerAvatar.IsMissionCompleted(missionData))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #9
0
        public void Update(int activeTimestamp, LogicAvatar homeOwnerAvatar, LogicLevel level)
        {
            Debugger.DoAssert(activeTimestamp != -1, "You must set a valid time for calendar.");

            if (this.m_activeTimestamp != activeTimestamp)
            {
                this.m_activeTimestamp = activeTimestamp;

                if (this.HasNewActiveCalendarEvents(this.m_activeCalendarEvents, activeTimestamp, activeTimestamp))
                {
                    this.m_activeCalendarEvents = this.GetActiveCalendarEvents(activeTimestamp, activeTimestamp);

                    if (homeOwnerAvatar != null && level != null)
                    {
                        this.UpdateUseTroopEvent(homeOwnerAvatar, level);
                    }
                }
            }
        }
        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);
        }
        public bool SetSleep(bool enabled)
        {
            LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();
            int         state           = homeOwnerAvatar.GetHeroState(this.m_hero);

            if (state != 0)
            {
                int newState = enabled ? 2 : 3;

                if (state != newState)
                {
                    homeOwnerAvatar.SetHeroState(this.m_hero, newState);
                    homeOwnerAvatar.GetChangeListener().CommodityCountChanged(2, this.m_hero, newState);

                    return(true);
                }
            }

            return(false);
        }
Пример #12
0
        public bool IsNotEmpty()
        {
            LogicAvatar    homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();
            LogicDataTable table           = LogicDataTables.GetTable(LogicDataType.RESOURCE);

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

                if (data.GetWarResourceReferenceData() != null)
                {
                    if (homeOwnerAvatar.GetResourceCount(data) > 0)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #13
0
        public void RecalculateAvailableLoot()
        {
            LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();

            if (!homeOwnerAvatar.IsNpcAvatar())
            {
                int matchType = this.m_parent.GetLevel().GetMatchType();

                if (matchType >= 10 || matchType != 3 && matchType != 5)
                {
                    int resourceProductionLootPercentage = LogicDataTables.GetGlobals().GetResourceProductionLootPercentage(this.m_resourceData);

                    if (homeOwnerAvatar.IsClientAvatar())
                    {
                        LogicAvatar visitorAvatar = this.m_parent.GetLevel().GetVisitorAvatar();

                        if (visitorAvatar != null && visitorAvatar.IsClientAvatar())
                        {
                            resourceProductionLootPercentage = resourceProductionLootPercentage *
                                                               LogicDataTables.GetGlobals().GetLootMultiplierByTownHallDiff(visitorAvatar.GetTownHallLevel(),
                                                                                                                            homeOwnerAvatar.GetTownHallLevel()) / 100;
                        }
                    }

                    if (resourceProductionLootPercentage > 100)
                    {
                        resourceProductionLootPercentage = 100;
                    }

                    this.m_availableLoot = (int)((long)this.GetResourceCount() * resourceProductionLootPercentage / 100L);
                }
                else
                {
                    this.m_availableLoot = 0;
                }
            }
            else
            {
                this.m_availableLoot = 0;
            }
        }
        public override int Execute(LogicLevel level)
        {
            if (level.GetGameMode().GetState() == 1)
            {
                LogicAvatar avatar = level.GetHomeOwnerAvatar();

                if (avatar != null)
                {
                    if (this.m_deliverableBundle != null)
                    {
                        if (this.m_billingPackageData != null)
                        {
                            LogicDeliveryHelper.Deliver(level, this.m_deliverableBundle);
                            LogicOffer offer = level.GetOfferManager().GetOfferById(this.m_offerId);

                            if (offer != null)
                            {
                                offer.SetState(4);
                                offer.AddPayCount(1);
                            }

                            /*else
                             * {
                             *  Debugger.Warning(string.Format("Delivering offerUid:{0}. Offer was no longer found.", this.m_offerId));
                             * }*/

                            return(0);
                        }

                        return(-4);
                    }

                    return(-3);
                }

                return(-2);
            }

            return(-1);
        }
Пример #15
0
        /// <summary>
        ///     Gets if this mission is a open tutorial mission.
        /// </summary>
        public bool IsOpenTutorialMission()
        {
            if (this._data.GetVillageType() == this._level.GetVillageType())
            {
                if (this._data.GetMissionCategory() == 2)
                {
                    LogicAvatar homeOwnerAvatar = this._level.GetHomeOwnerAvatar();

                    if (homeOwnerAvatar == null || !homeOwnerAvatar.IsNpcAvatar() || this._level.GetVillageType() != -1)
                    {
                        LogicGameObjectManager gameObjectManager = this._level.GetGameObjectManagerAt(0);

                        if (gameObjectManager.GetShipyard() == null || gameObjectManager.GetShipyard().GetUpgradeLevel() != 0)
                        {
                            int missionType = this._data.GetMissionType();

                            if ((missionType == 16 || missionType == 14) && this._level.GetState() == 1 && this._level.GetVillageType() == 0)
                            {
                                if (gameObjectManager.GetShipyard().IsConstructing())
                                {
                                    return(false);
                                }
                            }

                            return(this._data.GetMissionCategory() != 1);
                        }
                    }

                    return(true);
                }
                else
                {
                    return(this._data.GetMissionCategory() != 1);
                }
            }
            else
            {
                return(false);
            }
        }
Пример #16
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);
        }
        public override int Execute(LogicLevel level)
        {
            this.m_level = level;

            if (level.GetVillageType() == 0)
            {
                if (LogicDataTables.GetGlobals().EnablePresets())
                {
                    LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                    if (homeOwnerAvatar.GetTownHallLevel() >= LogicDataTables.GetGlobals().GetEnablePresetsTownHallLevel())
                    {
                        if (this.m_presetId <= 3)
                        {
                            if (this.HasEnoughFreeHousingSpace())
                            {
                                int elixirCost     = this.GetResourceCost(LogicDataTables.GetElixirData());
                                int darkElixirCost = this.GetResourceCost(LogicDataTables.GetDarkElixirData());

                                if (level.GetPlayerAvatar().HasEnoughResources(LogicDataTables.GetElixirData(), elixirCost, LogicDataTables.GetDarkElixirData(), darkElixirCost,
                                                                               true,
                                                                               this, false))
                                {
                                    this.TrainUnits();
                                    return(0);
                                }
                            }

                            return(-1);
                        }

                        return(-2);
                    }
                }

                return(-3);
            }

            return(-32);
        }
        /// <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 override int Execute(LogicLevel level)
        {
            if (this.m_excludeMemberList == null || this.m_excludeMemberList.Size() <= LogicDataTables.GetGlobals().GetWarMaxExcludeMembers())
            {
                LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                if (homeOwnerAvatar.IsInAlliance())
                {
                    if (homeOwnerAvatar.GetAllianceRole() == LogicAvatarAllianceRole.LEADER || homeOwnerAvatar.GetAllianceRole() == LogicAvatarAllianceRole.CO_LEADER)
                    {
                        homeOwnerAvatar.GetChangeListener().StartWar(this.m_excludeMemberList);
                        return(0);
                    }

                    return(-3);
                }

                return(-2);
            }

            return(-1);
        }
Пример #20
0
        public void UpdateUseTroopEvent(LogicAvatar homeOwnerAvatar, LogicLevel level)
        {
            for (int i = 0; i < this.m_activeCalendarEvents.Size(); i++)
            {
                int idx = this.m_startedEvents.IndexOf(this.m_activeCalendarEvents[i].GetId());

                if (idx == -1)
                {
                    this.m_activeCalendarEvents[i].StartUseTroopEvent(homeOwnerAvatar, level);
                }
            }

            while (this.m_startedEvents.Size() > 0)
            {
                this.m_startedEvents.Remove(0);
            }

            for (int i = 0; i < this.m_activeCalendarEvents.Size(); i++)
            {
                this.m_startedEvents.Add(this.m_activeCalendarEvents[i].GetId());
            }
        }
Пример #21
0
        /// <summary>
        ///     Loads the npc attack state.
        /// </summary>
        public void LoadNpcAttackState(LogicClientHome home, LogicAvatar homeOwnerAvatar, LogicAvatar visitorAvatar, int currentTimestamp, int secondsSinceLastSave)
        {
            if (this._state == 1)
            {
                Debugger.Error("loadAttackState called from invalid state");
            }
            else
            {
                this._state            = 2;
                this._currentTimestamp = currentTimestamp;
                this._calendar.Load(home.GetCalendarJSON(), currentTimestamp);

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

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

                    homeOwnerAvatar.SetResourceCount(LogicDataTables.GetGoldData(), LogicMath.Max(npcData.Gold - visitorAvatar.GetLootedNpcGold(npcData), 0));
                    homeOwnerAvatar.SetResourceCount(LogicDataTables.GetElixirData(), LogicMath.Max(npcData.Elixir - visitorAvatar.GetLootedNpcElixir(npcData), 0));

                    this._level.SetMatchType(2, 0);
                    this._level.SetHome(home, false);
                    this._level.SetHomeOwnerAvatar(homeOwnerAvatar);
                    this._level.SetVisitorAvatar(visitorAvatar);
                    this._level.FastForwardTime(secondsSinceLastSave);
                    this._level.LoadingFinished();
                }
                else
                {
                    Debugger.Error("loadNpcAttackState called and home owner is not npc avatar");
                }
            }
        }
        public bool SpeedUpHealth()
        {
            LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();

            if (homeOwnerAvatar.IsClientAvatar())
            {
                LogicClientAvatar clientAvatar = (LogicClientAvatar)homeOwnerAvatar;
                int speedUpCost = this.GetSpeedUpHealthCost();

                if (clientAvatar.HasEnoughDiamonds(speedUpCost, true, this.m_parent.GetLevel()))
                {
                    clientAvatar.UseDiamonds(speedUpCost);
                    clientAvatar.GetChangeListener().DiamondPurchaseMade(9, this.m_hero.GetGlobalID(), clientAvatar.GetUnitUpgradeLevel(this.m_hero) + 1, speedUpCost,
                                                                         this.m_parent.GetLevel().GetVillageType());

                    this.SetFullHealth();

                    return(true);
                }
            }

            return(false);
        }
Пример #23
0
        public void LoadVisitState(LogicClientHome home, LogicAvatar homeOwnerAvatar, LogicAvatar visitorAvatar, int currentTimestamp, int secondsSinceLastSave)
        {
            if (this.m_state != 0)
            {
                Debugger.Error("loadVisitState called from invalid state");
            }
            else
            {
                this.m_state          = 4;
                this.m_startTimestamp = currentTimestamp;
                this.m_configuration.Load((LogicJSONObject)LogicJSONParser.Parse(home.GetGlobalJSON()));
                this.m_calendar.Load(home.GetCalendarJSON(), currentTimestamp);
                this.m_level.SetNpcVillage(homeOwnerAvatar.IsNpcAvatar());
                this.m_level.SetHome(home, false);
                this.m_level.SetHomeOwnerAvatar(homeOwnerAvatar);
                this.m_level.SetVisitorAvatar(visitorAvatar);
                this.m_level.FastForwardTime(secondsSinceLastSave);

                homeOwnerAvatar.SetLevel(this.m_level);

                this.m_level.LoadingFinished();
            }
        }
Пример #24
0
        public void DebugVillage2UnitAdded(bool updateComponents)
        {
            LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();

            if (homeOwnerAvatar != null)
            {
                if (updateComponents)
                {
                    LogicArrayList <LogicComponent> components = this.m_components[(int)LogicComponentType.VILLAGE2_UNIT];
                    LogicArrayList <LogicDataSlot>  units      = homeOwnerAvatar.GetUnitsVillage2();

                    for (int i = 0; i < LogicMath.Min(components.Size(), units.Size()); i++)
                    {
                        LogicVillage2UnitComponent component = (LogicVillage2UnitComponent)components[i];
                        LogicDataSlot      unitSlot          = units[i];
                        LogicCharacterData characterData     = (LogicCharacterData)unitSlot.GetData();

                        component.RemoveUnits();
                        component.SetUnit(characterData, component.GetMaxUnitsInCamp(characterData));
                    }
                }
            }
        }
Пример #25
0
        public void ObstacleCleared()
        {
            LogicAvatar    homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();
            LogicDataTable dataTable       = LogicDataTables.GetTable(LogicDataType.ACHIEVEMENT);

            if (homeOwnerAvatar != null)
            {
                if (homeOwnerAvatar.IsClientAvatar())
                {
                    LogicClientAvatar clientAvatar = (LogicClientAvatar)homeOwnerAvatar;

                    for (int i = 0; i < dataTable.GetItemCount(); i++)
                    {
                        LogicAchievementData achievementData = (LogicAchievementData)dataTable.GetItemAt(i);

                        if (achievementData.GetActionType() == LogicAchievementData.ACTION_TYPE_CLEAR_OBSTACLES)
                        {
                            this.RefreshAchievementProgress(clientAvatar, achievementData, clientAvatar.GetAchievementProgress(achievementData) + 1);
                        }
                    }
                }
            }
        }
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (playerAvatar != null)
            {
                playerAvatar.SetDuelScore(playerAvatar.GetDuelScore() + this.m_scoreGain);

                switch (this.m_resultType)
                {
                case 0:
                    playerAvatar.SetDuelLoseCount(playerAvatar.GetDuelLoseCount() + 1);
                    break;

                case 1:
                    playerAvatar.SetDuelWinCount(playerAvatar.GetDuelWinCount() + 1);
                    break;

                case 2:
                    playerAvatar.SetDuelDrawCount(playerAvatar.GetDuelDrawCount() + 1);
                    break;
                }

                level.GetAchievementManager().RefreshStatus();

                LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                if (homeOwnerAvatar.GetChangeListener() != null)
                {
                    homeOwnerAvatar.GetChangeListener().DuelScoreChanged(homeOwnerAvatar.GetAllianceId(), this.m_scoreGain, this.m_resultType, true);
                }

                return(0);
            }

            return(-1);
        }
Пример #27
0
        public void SpeedUp()
        {
            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;

            bool armyCampFull = false;

            while (!armyCampFull && this.m_slots.Size() > 0)
            {
                LogicUnitProductionSlot slot = this.m_slots[0];
                LogicCombatItemData     data = (LogicCombatItemData)slot.GetData();

                int count = slot.GetCount();

                if (count <= 0)
                {
                    break;
                }

                armyCampFull = true;

                do
                {
                    freeCapacity -= data.GetHousingSpace();

                    if (freeCapacity >= 0)
                    {
                        this.ProductionCompleted(true);
                        armyCampFull = false;
                    }
                } while (--count > 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");
                }
            }
        }
        /// <summary>
        ///     Executes this command.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            int count = this._gameObjectIds.Count;

            if (count > 0)
            {
                bool validSize        = true;
                bool validGameObjects = true;

                if (this._xPositions.Count != count || this._xPositions.Count != count || count > 500)
                {
                    validSize = false;
                }

                if (validSize)
                {
                    LogicGameObject[] gameObjects = new LogicGameObject[count];

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

                        if (gameObject != null)
                        {
                            int gameObjectType = gameObject.GetGameObjectType();

                            if (gameObjectType > 6 || gameObjectType == 3)
                            {
                                validGameObjects = false;
                            }

                            gameObjects[i] = gameObject;
                        }
                        else
                        {
                            validGameObjects = false;
                        }
                    }

                    if (validGameObjects)
                    {
                        bool validWallBlock = true;

                        for (int i = 0; i < count; i++)
                        {
                            LogicGameObject gameObject = gameObjects[i];

                            if (gameObject.GetGameObjectType() == 0 && ((LogicBuilding)gameObject).GetWallIndex() != 0 && validWallBlock)
                            {
                                LogicBuilding baseWallBlock = (LogicBuilding)gameObject;

                                int x             = this._xPositions[i];
                                int y             = this._yPositions[i];
                                int minX          = 0;
                                int minY          = 0;
                                int maxX          = 0;
                                int maxY          = 0;
                                int minWallBlockX = 0;
                                int minWallBlockY = 0;
                                int maxWallBlockX = 0;
                                int maxWallBlockY = 0;

                                bool success = true;

                                int wallBlockCnt = -1;

                                for (int j = 0; j < count; j++)
                                {
                                    LogicGameObject obj = gameObjects[j];

                                    if (obj.GetGameObjectType() == 0 && ((LogicBuilding)obj).GetWallIndex() == baseWallBlock.GetWallIndex())
                                    {
                                        LogicBuilding wallBlock = (LogicBuilding)obj;

                                        int tmp1 = x - this._xPositions[j];
                                        int tmp2 = y - this._yPositions[j];

                                        if ((x & this._xPositions[j]) != -1)
                                        {
                                            success = false;
                                        }

                                        minX = LogicMath.Min(minX, tmp1);
                                        minY = LogicMath.Min(minY, tmp2);
                                        maxX = LogicMath.Max(maxX, tmp1);
                                        maxY = LogicMath.Max(maxY, tmp2);

                                        int wallBlockX = wallBlock.GetBuildingData().GetWallBlockX(j);
                                        int wallBlockY = wallBlock.GetBuildingData().GetWallBlockY(j);

                                        minWallBlockX = LogicMath.Min(minWallBlockX, wallBlockX);
                                        minWallBlockY = LogicMath.Min(minWallBlockY, wallBlockY);
                                        maxWallBlockX = LogicMath.Min(maxWallBlockX, wallBlockX);
                                        maxWallBlockY = LogicMath.Min(maxWallBlockY, wallBlockY);

                                        ++wallBlockCnt;
                                    }
                                }

                                if (baseWallBlock.GetBuildingData().GetWallBlockCount() == wallBlockCnt)
                                {
                                    int wallBlockSizeX = maxWallBlockX - minWallBlockX;
                                    int wallBlockSizeY = maxWallBlockY - minWallBlockY;
                                    int lengthX        = maxX - minX;
                                    int lengthY        = maxY - minY;

                                    if (wallBlockSizeX != lengthX || wallBlockSizeY != lengthY)
                                    {
                                        if (!success && (wallBlockSizeX != lengthX) != (wallBlockSizeY != lengthY))
                                        {
                                            validGameObjects = false;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        // EditmodeInvalidGameObjectType.
                    }

                    bool objectsOverlap = false;

                    if (validGameObjects)
                    {
                        int idx = 0;

                        while (idx < count)
                        {
                            int x = this._xPositions[idx];
                            int y = this._yPositions[idx];

                            LogicGameObject gameObject = gameObjects[idx];

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

                            int tmp1 = x + width;
                            int tmp2 = y + height;

                            for (int i = 0; i < count; i++)
                            {
                                LogicGameObject gameObject2 = gameObjects[idx];

                                if (gameObject2 != gameObject)
                                {
                                    int x2      = this._xPositions[i];
                                    int y2      = this._yPositions[i];
                                    int width2  = gameObject2.GetWidthInTiles();
                                    int height2 = gameObject2.GetHeightInTiles();
                                    int tmp3    = x + width2;
                                    int tmp4    = y + height2;

                                    if (tmp1 > x2 && tmp2 > y2 && x2 < tmp3 && y2 < tmp4)
                                    {
                                        objectsOverlap = true;
                                        return(0);
                                    }
                                }
                            }

                            ++idx;
                        }
                    }

                    if (validGameObjects)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            int x = this._xPositions[i];
                            int y = this._yPositions[i];

                            LogicGameObject gameObject = gameObjects[i];

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

                            if (!level.IsValidPlaceForBuildingWithIgnoreList(x, y, width, height, gameObjects, count))
                            {
                                if (validGameObjects)
                                {
                                    // EditmodeInvalidPosition.
                                }

                                validGameObjects = false;
                            }
                        }
                    }

                    if (validGameObjects)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            int x = this._xPositions[i];
                            int y = this._yPositions[i];

                            LogicGameObject gameObject = gameObjects[i];

                            gameObject.SetPositionXY(x << 9, y << 9);
                        }

                        for (int i = 0; i < count; i++)
                        {
                            int x = this._xPositions[i];
                            int y = this._yPositions[i];

                            LogicGameObject gameObject = gameObjects[i];

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

                            for (int j = 0; j < width; j++)
                            {
                                for (int k = 0; k < height; k++)
                                {
                                    LogicObstacle tallGrass = level.GetTileMap().GetTile(x + j, y + k).GetTallGrass();

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

                        if (validGameObjects)
                        {
                            if (level.GetHomeOwnerAvatar() != null)
                            {
                                LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                                if (homeOwnerAvatar.GetTownHallLevel() >= LogicDataTables.GetGlobals().GetChallengeBaseCooldownTownHall())
                                {
                                    level.SetLayoutCooldownSecs(level.GetActiveLayout(level.GetVillageType()), LogicDataTables.GetGlobals().GetChallengeBaseSaveCooldown());
                                }
                            }
                        }

                        return(0);
                    }
                }
            }

            return(-1);
        }