Exemplo n.º 1
0
        /// <summary>
        ///     Sets the upgrade level.
        /// </summary>
        public void SetUpgradeLevel(int upgLevel)
        {
            LogicTrapData data = this.GetTrapData();

            this._upgLevel  = LogicMath.Min(upgLevel, data.GetUpgradeLevelCount());
            this._numSpawns = data.GetNumSpawns(upgLevel);
        }
Exemplo n.º 2
0
        public void RefreshAchievementProgress(LogicClientAvatar avatar, LogicAchievementData data, int value)
        {
            if (this.m_level.GetState() != 5)
            {
                int currentValue = avatar.GetAchievementProgress(data);
                int newValue     = LogicMath.Min(value, 2000000000);

                if (currentValue < newValue)
                {
                    avatar.SetAchievementProgress(data, value);
                    avatar.GetChangeListener().CommodityCountChanged(0, data, newValue);
                }

                int tmp = LogicMath.Min(newValue, data.GetActionCount());

                if (currentValue < tmp)
                {
                    LogicClientAvatar playerAvatar = this.m_level.GetPlayerAvatar();

                    if (playerAvatar == avatar)
                    {
                        if (tmp == data.GetActionCount())
                        {
                            this.m_level.GetGameListener().AchievementCompleted(data);
                        }
                        else
                        {
                            this.m_level.GetGameListener().AchievementProgress(data);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public override void FastForwardTime(int time)
        {
            if (this.m_timer != null)
            {
                if (this.m_timer.GetEndTimestamp() == -1)
                {
                    this.m_timer.StartTimer(this.m_timer.GetRemainingSeconds(this.m_parent.GetLevel().GetLogicTime()) - time, this.m_parent.GetLevel().GetLogicTime(), false, -1);
                }
                else
                {
                    this.m_timer.AdjustEndSubtick(this.m_parent.GetLevel());
                }

                int clockTowerBoostTime = this.m_parent.GetLevel().GetUpdatedClockTowerBoostTime();

                if (clockTowerBoostTime > 0 && this.m_parent.GetLevel().IsClockTowerBoostPaused())
                {
                    LogicGameObjectData data = this.m_parent.GetData();

                    if (data.GetDataType() == LogicDataType.BUILDING)
                    {
                        if (data.GetVillageType() == 1)
                        {
                            this.m_timer.SetFastForward(this.m_timer.GetFastForward() +
                                                        60 * LogicMath.Min(time, clockTowerBoostTime) * (LogicDataTables.GetGlobals().GetClockTowerBoostMultiplier() - 1));
                        }
                    }
                }
            }
        }
        public override void Tick()
        {
            base.Tick();

            if (this.m_clearTimer != null)
            {
                if (this.m_clearTimer.GetRemainingSeconds(this.m_level.GetLogicTime()) > 0 && this.m_level.GetRemainingClockTowerBoostTime() > 0 &&
                    this.GetObstacleData().GetVillageType() == 1)
                {
                    this.m_clearTimer.SetFastForward(this.m_clearTimer.GetFastForward() + 4 * LogicDataTables.GetGlobals().GetClockTowerBoostMultiplier() - 4);
                }
            }

            if (this.m_fadeTime < 1)
            {
                if (this.m_clearTimer != null)
                {
                    if (this.m_clearTimer.GetRemainingSeconds(this.m_level.GetLogicTime()) <= 0)
                    {
                        this.ClearingFinished(false);
                    }
                }
            }
            else
            {
                this.m_fadeTime = LogicMath.Min(this.m_fadeTime + 64, this.GetFadingOutTime());
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Loads this instance from json.
        /// </summary>
        internal void Load(string json)
        {
            LogicJSONObject jsonObject = (LogicJSONObject)LogicJSONParser.Parse(json);

            this.Id                 = new LogicLong(LogicJSONHelper.GetJSONNumber(jsonObject, "id_hi"), LogicJSONHelper.GetJSONNumber(jsonObject, "id_lo"));
            this.PassToken          = LogicJSONHelper.GetJSONString(jsonObject, "pass_t");
            this.PlayTimeSecs       = LogicJSONHelper.GetJSONNumber(jsonObject, "pt_secs");
            this.AccountCreatedDate = LogicJSONHelper.GetJSONString(jsonObject, "acc_cr");
            this.TotalBan           = LogicJSONHelper.GetJSONNumber(jsonObject, "t_ban");

            LogicJSONArray sessionArray = jsonObject.GetJSONArray("sessions");

            if (sessionArray != null)
            {
                int size = LogicMath.Min(sessionArray.Size(), 20);

                for (int i = 0; i < size; i++)
                {
                    LogicJSONObject obj     = sessionArray.GetJSONObject(i);
                    AccountSession  session = new AccountSession();
                    session.Load(obj);
                    this.LastSessions.Add(session);
                }
            }

            LogicJSONObject banObject = jsonObject.GetJSONObject("ban");

            if (banObject != null)
            {
                this.CurrentBan = new AccountBan();
                this.CurrentBan.Load(banObject);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Initializes this instance.
        /// </summary>
        internal static void Initialize()
        {
            ClientManager._clients     = new LogicArrayList <GameMain>(4096);
            ClientManager._threads     = new LogicArrayList <Thread>(ClientManager.THREAD_COUNT);
            ClientManager._lastUpdates = new LogicArrayList <DateTime>(ClientManager.THREAD_COUNT);

            for (int i = 0; i < ClientManager.THREAD_COUNT; i++)
            {
                int threadIndex = i;

                ClientManager._threads.Add(new Thread(() =>
                {
                    while (true)
                    {
                        int startIndex = 1000 * threadIndex;
                        int endIndex   = LogicMath.Min(1000 * (threadIndex + 1), ClientManager._clients.Count - startIndex);

                        float time = (float)DateTime.UtcNow.Subtract(ClientManager._lastUpdates[threadIndex]).TotalSeconds;

                        ClientManager.Update(time, startIndex, endIndex);
                        ClientManager._lastUpdates[threadIndex] = DateTime.UtcNow;

                        Thread.Sleep(ClientManager.SLEEP_TIME);
                    }
                }));

                ClientManager._lastUpdates.Add(DateTime.UtcNow);
                ClientManager._threads[threadIndex].Start();
            }
        }
Exemplo n.º 7
0
        private static LogicArrayList <T> GetRankingList <T>(LogicArrayList <T> fullContent, LogicLong clientId) where T : RankingEntry
        {
            LogicArrayList <T> rankingList = new LogicArrayList <T>(ScoringManager.CLIENT_RANKING_LIST_SIZE);

            if (fullContent != null)
            {
                for (int i = 0, c = LogicMath.Min(fullContent.Size(), ScoringManager.CLIENT_RANKING_LIST_SIZE); i < c; i++)
                {
                    rankingList.Add(fullContent[i]);
                }

                for (int i = ScoringManager.CLIENT_RANKING_LIST_SIZE; i < fullContent.Size(); i++)
                {
                    if (fullContent[i].GetId().Equals(clientId))
                    {
                        if (i > 0)
                        {
                            rankingList.Add(fullContent[i - 1]);
                        }
                        rankingList.Add(fullContent[i]);
                        if (i + 1 < fullContent.Size())
                        {
                            rankingList.Add(fullContent[i + 1]);
                        }

                        break;
                    }
                }
            }

            return(rankingList);
        }
Exemplo n.º 8
0
        public override void Load(LogicJSONObject jsonObject)
        {
            this.LoadUpgradeLevel(jsonObject);

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

            LogicJSONNumber constTimeObject = jsonObject.GetJSONNumber("const_t");

            if (constTimeObject != null)
            {
                int constTime = constTimeObject.GetIntValue();

                if (!LogicDataTables.GetGlobals().ClampBuildingTimes())
                {
                    if (this.m_upgLevel < this.GetVillageObjectData().GetUpgradeLevelCount() - 1)
                    {
                        constTime = LogicMath.Min(constTime, this.GetVillageObjectData().GetBuildTime(this.m_upgLevel + 1));
                    }
                }

                this.m_constructionTimer = new LogicTimer();
                this.m_constructionTimer.StartTimer(constTime, this.m_level.GetLogicTime(), false, -1);

                LogicJSONNumber constTimeEndObject = jsonObject.GetJSONNumber("const_t_end");

                if (constTimeEndObject != null)
                {
                    this.m_constructionTimer.SetEndTimestamp(constTimeEndObject.GetIntValue());
                }

                LogicJSONNumber conffObject = jsonObject.GetJSONNumber("con_ff");

                if (conffObject != null)
                {
                    this.m_constructionTimer.SetFastForward(conffObject.GetIntValue());
                }

                LogicVillageObjectData villageObjectData = this.GetVillageObjectData();

                if (villageObjectData.IsRequiresBuilder() && !villageObjectData.IsAutomaticUpgrades())
                {
                    this.m_level.GetWorkerManagerAt(this.m_villageType).AllocateWorker(this);
                }

                this.m_upgrading = this.m_upgLevel != -1;
            }

            this.m_upgLevel = LogicMath.Clamp(this.m_upgLevel, 0, this.GetVillageObjectData().GetUpgradeLevelCount() - 1);

            base.Load(jsonObject);

            this.SetPositionXY((this.GetVillageObjectData().GetTileX100() << 9) / 100,
                               (this.GetVillageObjectData().GetTileY100() << 9) / 100);
        }
        public static int GetRadius(int x, int y)
        {
            x = LogicMath.Abs(x);
            y = LogicMath.Abs(y);
            int maxValue = LogicMath.Max(x, y);
            int minValue = LogicMath.Min(x, y);

            return(maxValue + (53 * minValue >> 7));
        }
Exemplo n.º 10
0
        public int GetRecommendedMax(int idx, int count)
        {
            int max = this.GetRecommendedMax(idx);

            if (this.m_maxPercentageResourceCount[idx] != 0)
            {
                return(LogicMath.Min(this.m_maxPercentageResourceCount[idx] * count / 100, max));
            }
            return(max);
        }
Exemplo n.º 11
0
        public override void Load(LogicJSONObject jsonObject)
        {
            LogicJSONNumber resourceTimeObject = jsonObject.GetJSONNumber("res_time");
            int             time = this.m_productionPer100Hour > 0 ? (int)(360000L * this.m_maxResources / this.m_productionPer100Hour) : 0;

            if (resourceTimeObject != null)
            {
                time = LogicMath.Min(resourceTimeObject.GetIntValue(), time);
            }

            this.m_resourceTimer.StartTimer(time, this.m_parent.GetLevel().GetLogicTime(), false, -1);
        }
Exemplo n.º 12
0
        public int GetRemainingSecs()
        {
            if (this.m_productionTimer != null)
            {
                int remainingSecs = this.m_productionTimer.GetRemainingSeconds(this.m_parent.GetLevel().GetLogicTime());
                int trainingTime  = this.m_unit != null?this.GetTrainingTime((LogicCombatItemData)this.m_unit.GetData()) : 0;

                return(LogicMath.Min(remainingSecs, trainingTime));
            }

            return(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);
                }
            }
        }
Exemplo n.º 14
0
        public override void Decode(ByteStream stream)
        {
            int count = LogicMath.Min(stream.ReadInt(), 10);

            for (int i = 0; i < count; i++)
            {
                this.m_position.Add(new LogicVector2(stream.ReadInt(), stream.ReadInt()));
            }

            this.m_buildingData = (LogicBuildingData)ByteStreamHelper.ReadDataReference(stream, LogicDataType.BUILDING);

            base.Decode(stream);
        }
Exemplo n.º 15
0
        public void DecreaseResources(int count)
        {
            int resourceCount = this.GetResourceCount();
            int removeCount   = LogicMath.Min(count, resourceCount);

            if (this.m_productionPer100Hour != 0)
            {
                int totalTime = (int)(360000L * this.m_maxResources / this.m_productionPer100Hour);
                int skipTime  = (int)(360000L * (resourceCount - removeCount) / this.m_productionPer100Hour);

                this.m_resourceTimer.StartTimer(totalTime - skipTime, this.m_parent.GetLevel().GetLogicTime(), false, -1);
            }
        }
Exemplo n.º 16
0
        public LogicTriggerComponent(LogicGameObject gameObject, int triggerRadius, bool airTrigger, bool groundTrigger, bool healerTrigger, int minTriggerHousingLimit) :
            base(gameObject)
        {
            this.m_triggerRadius          = triggerRadius;
            this.m_airTrigger             = airTrigger;
            this.m_groundTrigger          = groundTrigger;
            this.m_healerTrigger          = healerTrigger;
            this.m_minTriggerHousingLimit = minTriggerHousingLimit;

            int tmp = ((LogicMath.Min(this.m_parent.GetWidthInTiles(), this.m_parent.GetHeightInTiles()) << 9) + 1024) >> 1;

            this.m_triggeredByRadius = tmp < triggerRadius;
        }
        public override void Decode(ByteStream stream)
        {
            int size = LogicMath.Min(stream.ReadInt(), 500);

            for (int i = size; i > 0; i--)
            {
                this.m_xPositions.Add(stream.ReadInt());
                this.m_yPositions.Add(stream.ReadInt());
                this.m_gameObjectIds.Add(stream.ReadInt());
            }

            base.Decode(stream);
        }
Exemplo n.º 18
0
        public override void Decode(ByteStream stream)
        {
            this.m_layoutId = stream.ReadInt();

            for (int i = LogicMath.Min(500, stream.ReadInt()); i > 0; i--)
            {
                this.m_xPositions.Add(stream.ReadInt());
                this.m_yPositions.Add(stream.ReadInt());
                this.m_gameObjectIds.Add(stream.ReadInt());
            }

            base.Decode(stream);
        }
        public override void Encode(ChecksumEncoder encoder)
        {
            int size = LogicMath.Min(this.m_gameObjectIds.Size(), 500);

            encoder.WriteInt(size);

            for (int i = 0; i < size; i++)
            {
                encoder.WriteInt(this.m_xPositions[i]);
                encoder.WriteInt(this.m_yPositions[i]);
                encoder.WriteInt(this.m_gameObjectIds[i]);
            }

            base.Encode(encoder);
        }
Exemplo n.º 20
0
        public void Boost(int speed, int time)
        {
            if (speed < 0)
            {
                this.m_slowSpeed = LogicMath.Min(LogicMath.Max(-100, speed), this.m_slowSpeed);
                this.m_slowTime  = time;
            }
            else
            {
                int idx = this.m_boostSpeed[0] != 0 ? 1 : 0;

                this.m_boostSpeed[idx] = LogicMath.Max(speed, this.m_boostSpeed[idx]);
                this.m_boostTime[idx]  = time;
            }
        }
        public override void FastForwardTime(int time)
        {
            int heroHealthTime        = time;
            int constructionBoostTime = 0;
            int remainingBoostTime    = this.m_parent.GetRemainingBoostTime();

            if (remainingBoostTime > 0)
            {
                if (!this.m_parent.IsBoostPaused())
                {
                    heroHealthTime += LogicMath.Min(remainingBoostTime, time) * (LogicDataTables.GetGlobals().GetHeroRestBoostMultiplier() - 1);
                }
            }

            int clockTowerBoostTime = this.m_parent.GetLevel().GetUpdatedClockTowerBoostTime();

            if (clockTowerBoostTime > 0 && this.m_parent.GetLevel().IsClockTowerBoostPaused())
            {
                LogicGameObjectData data = this.m_parent.GetData();

                if (data.GetDataType() == LogicDataType.BUILDING && data.GetVillageType() == 1)
                {
                    int boost = LogicMath.Min(clockTowerBoostTime, time) * (LogicDataTables.GetGlobals().GetClockTowerBoostMultiplier() - 1);

                    heroHealthTime        += boost;
                    constructionBoostTime += boost;
                }
            }

            this.m_parent.GetLevel().GetHomeOwnerAvatar().FastForwardHeroHealth(this.m_hero, heroHealthTime);

            if (this.m_timer != null)
            {
                if (this.m_timer.GetEndTimestamp() == -1)
                {
                    this.m_timer.StartTimer(this.m_timer.GetRemainingSeconds(this.m_parent.GetLevel().GetLogicTime()) - time, this.m_parent.GetLevel().GetLogicTime(), false, -1);
                }
                else
                {
                    this.m_timer.AdjustEndSubtick(this.m_parent.GetLevel());
                }

                if (constructionBoostTime > 0)
                {
                    this.m_timer.SetFastForward(this.m_timer.GetFastForward() + 60 * constructionBoostTime);
                }
            }
        }
Exemplo n.º 22
0
        public override void Encode(ChecksumEncoder encoder)
        {
            int count = this.m_gameObjectIds.Size();

            encoder.WriteInt(this.m_layoutId);
            encoder.WriteInt(count);

            for (int i = LogicMath.Min(500, count); i > 0; i--)
            {
                encoder.WriteInt(this.m_xPositions[i]);
                encoder.WriteInt(this.m_yPositions[i]);
                encoder.WriteInt(this.m_gameObjectIds[i]);
            }

            base.Encode(encoder);
        }
Exemplo n.º 23
0
        public override void Encode(ChecksumEncoder encoder)
        {
            int count = LogicMath.Min(this.m_position.Size(), 10);

            encoder.WriteInt(count);

            for (int i = 0; i < count; i++)
            {
                encoder.WriteInt(this.m_position[i].m_x);
                encoder.WriteInt(this.m_position[i].m_y);
            }

            ByteStreamHelper.WriteDataReference(encoder, this.m_buildingData);

            base.Encode(encoder);
        }
Exemplo n.º 24
0
        public override void FastForwardTime(int secs)
        {
            LogicArrayList <LogicComponent> components = this.m_parent.GetComponentManager().GetComponents(LogicComponentType.VILLAGE2_UNIT);

            int barrackCount      = this.m_parent.GetGameObjectManager().GetBarrackCount();
            int barrackFoundCount = 0;

            for (int i = 0; i < barrackCount; i++)
            {
                LogicBuilding building = (LogicBuilding)this.m_parent.GetGameObjectManager().GetBarrack(i);

                if (building != null && !building.IsConstructing())
                {
                    barrackFoundCount += 1;
                }
            }

            if (components.Size() <= 0 || barrackFoundCount != 0 && components[0] == this)
            {
                LogicLevel level = this.m_parent.GetLevel();

                int clockTowerBoostTime = level.GetUpdatedClockTowerBoostTime();
                int boostTime           = 0;

                if (clockTowerBoostTime > 0 &&
                    !level.IsClockTowerBoostPaused())
                {
                    LogicGameObjectData data = this.m_parent.GetData();

                    if (data.GetDataType() == LogicDataType.BUILDING)
                    {
                        if (data.GetVillageType() == 1)
                        {
                            boostTime = LogicMath.Min(secs, clockTowerBoostTime) * (LogicDataTables.GetGlobals().GetClockTowerBoostMultiplier() - 1);
                        }
                    }
                }

                int remainingSecs = secs + boostTime;

                for (int i = 0; i < components.Size(); i++)
                {
                    remainingSecs = LogicMath.Max(0, remainingSecs - ((LogicVillage2UnitComponent)components[i]).FastForwardProduction(remainingSecs));
                }
            }
        }
        public static LogicTimer GetLogicTimer(LogicJSONObject jsonObject, LogicTime time, string key, int maxTime)
        {
            LogicJSONNumber number = (LogicJSONNumber)jsonObject.Get(key);

            if (number != null)
            {
                LogicTimer timer = new LogicTimer();

                int remainingSeconds = LogicMath.Min(number.GetIntValue(), maxTime);
                int tick             = time.GetTick();

                timer.m_remainingTime = tick + LogicTime.GetSecondsInTicks(remainingSeconds);

                return(timer);
            }

            return(null);
        }
Exemplo n.º 26
0
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (playerAvatar != null)
            {
                if (this.m_allianceCreate)
                {
                    LogicGlobals      globals  = LogicDataTables.GetGlobals();
                    LogicResourceData resource = globals.GetAllianceCreateResourceData();

                    int removeCount = LogicMath.Min(globals.GetAllianceCreateCost(), playerAvatar.GetResourceCount(resource));

                    playerAvatar.CommodityCountChangeHelper(0, resource, -removeCount);
                }

                playerAvatar.SetAllianceId(this.m_allianceId.Clone());
                playerAvatar.SetAllianceName(this.m_allianceName);
                playerAvatar.SetAllianceBadgeId(this.m_allianceBadgeId);
                playerAvatar.SetAllianceLevel(this.m_allianceExpLevel);
                playerAvatar.SetAllianceRole(this.m_allianceCreate ? LogicAvatarAllianceRole.LEADER : LogicAvatarAllianceRole.MEMBER);
                playerAvatar.GetChangeListener().AllianceJoined(playerAvatar.GetAllianceId(), this.m_allianceName, this.m_allianceBadgeId, this.m_allianceExpLevel,
                                                                playerAvatar.GetAllianceRole());

                LogicGameListener gameListener = level.GetGameListener();

                if (gameListener != null)
                {
                    if (this.m_allianceCreate)
                    {
                        gameListener.AllianceCreated();
                    }
                    else
                    {
                        gameListener.AllianceJoined();
                    }
                }

                return(0);
            }

            return(-1);
        }
        public void SetPoisonDamage(int damage, bool increaseSlowly)
        {
            int time = 8;

            if (this.m_poisonTime >= 80)
            {
                time = 24;

                if (this.m_poisonTime >= 320)
                {
                    time = 136;

                    if (this.m_poisonTime >= 1000)
                    {
                        time = 0;
                    }
                }
            }

            if (this.m_poisonDamage != 0)
            {
                if (this.m_poisonDamage >= damage)
                {
                    if (this.m_poisonDamage > damage)
                    {
                        time = damage * time / this.m_poisonDamage;
                    }
                }
                else
                {
                    this.m_poisonTime   = this.m_poisonDamage * this.m_poisonTime / damage;
                    this.m_poisonDamage = damage;
                }
            }
            else
            {
                this.m_poisonDamage = damage;
            }

            this.m_poisonTime     = increaseSlowly ? LogicMath.Min(time + this.m_poisonTime, 1000) : 1000;
            this.m_poisonInitTime = 640;
        }
Exemplo n.º 28
0
        public override void LoadingFinished()
        {
            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);
                }
            }
        }
        private static LogicGameObject CreateAndPlaceRandomlyGameObject(LogicGameObjectData data, LogicLevel level, int width, int height, int villageType)
        {
            int levelEndX = level.GetPlayArea().GetEndX();
            int levelEndY = level.GetPlayArea().GetEndY();
            int midX      = levelEndX / 2;
            int midY      = levelEndY / 2;

            int passCount = 1;

            while (true)
            {
                int startX = LogicMath.Max(midX - passCount, 0);
                int startY = LogicMath.Max(midY - passCount, 0);
                int endX   = LogicMath.Min(midX + passCount, levelEndX);
                int endY   = LogicMath.Min(midY + passCount, levelEndY);

                int possibility = LogicMath.Min((endX - startX) * (endY - startY), 20);

                for (int i = 0; i < possibility; i++)
                {
                    int x = startX + GameBaseGenerator.m_random.Rand(endX - startX);
                    int y = startY + GameBaseGenerator.m_random.Rand(endY - startY);

                    if (level.IsValidPlaceForBuilding(x, y, width, height, null))
                    {
                        LogicGameObject gameObject = LogicGameObjectFactory.CreateGameObject(data, level, villageType);
                        gameObject.SetInitialPosition(x << 9, y << 9);
                        level.GetGameObjectManagerAt(villageType).AddGameObject(gameObject, -1);
                        return(gameObject);
                    }
                }

                if (startX == 0 && startY == 0)
                {
                    return(null);
                }

                passCount += 2;
            }
        }
Exemplo n.º 30
0
        /// <summary>
        ///     Ticks this instance.
        /// </summary>
        public override void Tick()
        {
            base.Tick();

            if (this._clearTimer != null)
            {
                if (this._clearTimer.GetRemainingSeconds(this._level.GetLogicTime()) > 0 && this._level.GetRemainingClockTowerBoostTime() > 0 && this.GetObstacleData().GetVillageType() == 1)
                {
                    this._clearTimer.SetFastForward(this._clearTimer.GetFastForward() + 4 * LogicDataTables.GetGlobals().GetClockTowerBoostMultiplier() - 4);
                }
            }

            if (this._fadeTime < 1)
            {
                if (this._clearTimer != null)
                {
                    if (this._clearTimer.GetRemainingSeconds(this._level.GetLogicTime()) <= 0)
                    {
                        this.ClearingFinished(false);
                    }
                }
            }
            else
            {
                int tmp = 2000;

                if (this.GetObstacleData().LootDefensePercentage > 1)
                {
                    tmp = 4000;
                }

                if (this.GetObstacleData().TallGrass)
                {
                    tmp = 1000;
                }

                this._fadeTime = LogicMath.Min(this._fadeTime + 64, tmp);
            }
        }