public void SetUpgradeLevel(int upgLevel)
        {
            LogicTrapData data = this.GetTrapData();

            this.m_upgLevel  = LogicMath.Clamp(upgLevel, 0, data.GetUpgradeLevelCount() - 1);
            this.m_numSpawns = data.GetNumSpawns(this.m_upgLevel);
        }
Пример #2
0
        public int GetShockwaveArcLength()
        {
            LogicVector2 pos = new LogicVector2(this.GetMidX() - (this.m_targetPosition.m_x >> 3), this.GetMidY() - (this.m_targetPosition.m_y >> 3));

            int length          = pos.GetLength();
            int shockwaveLength = this.m_maxAttackRange - length;

            if (shockwaveLength >= this.m_minAttackRange)
            {
                int arcLength         = (this.m_shockwaveArcLength << 9) / 100;
                int expandedArcLength = LogicMath.Clamp(shockwaveLength * arcLength / ((this.m_shockwaveExpandRadius << 9) / 100), 0, arcLength);

                if (expandedArcLength < 0)
                {
                    expandedArcLength = arcLength;
                }

                if (expandedArcLength > arcLength)
                {
                    expandedArcLength = arcLength;
                }

                int calculateArcLength = 18000 * expandedArcLength / (314 * shockwaveLength);

                if (calculateArcLength < 180)
                {
                    return(calculateArcLength);
                }

                return(180);
            }

            return(0);
        }
        public static bool FindPoint(LogicTileMap tileMap, LogicVector2 pos1, LogicVector2 pos2, LogicVector2 pos3, LogicVector2 pos4)
        {
            pos1.Set(pos2.m_x, pos2.m_y);
            pos1.Substract(pos3);

            int length = pos1.GetLength();

            pos1.m_x = (pos1.m_x << 7) / length;
            pos1.m_y = (pos1.m_y << 7) / length;

            pos4.Set(pos3.m_x, pos3.m_y);

            int radius = LogicMath.Clamp(length / 128, 10, 25);

            for (int i = 0; i < radius; i++)
            {
                if (tileMap.IsPassablePathFinder(pos4.m_x >> 8, pos4.m_y >> 8))
                {
                    pos4.m_x = (int)((pos4.m_x & 0xFFFFFF00) | 128);
                    pos4.m_y = (int)((pos4.m_y & 0xFFFFFF00) | 128);

                    return(true);
                }

                pos4.Add(pos1);
            }

            return(false);
        }
Пример #4
0
        /// <summary>
        ///     Loads this instance from json.
        /// </summary>
        public override void Load(LogicJSONObject jsonObject)
        {
            LogicJSONNumber  hpNumber     = jsonObject.GetJSONNumber("hp");
            LogicJSONBoolean regenBoolean = jsonObject.GetJSONBoolean("reg");

            if (hpNumber != null)
            {
                if (this._parent.GetLevel().GetState() != 2)
                {
                    this._hp = LogicMath.Clamp(hpNumber.GetIntValue(), 0, this._maxHp);
                }
                else
                {
                    this._hp = this._maxHp;
                }
            }
            else
            {
                this._hp = this._maxHp;
            }

            if (regenBoolean != null)
            {
                this._regenerationEnabled = regenBoolean.IsTrue();
            }
            else
            {
                this._regenerationEnabled = false;
            }
        }
Пример #5
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 void SetAllianceSettings(string description, AllianceType type, int badgeId, int requiredScore, int requiredDuelScore, int warFrequency, LogicData originData, bool publicWarLog, bool arrangedWarEnabled)
        {
            int allianceLevel = this.Header.GetAllianceLevel();

            if (description == null)
            {
                description = string.Empty;
            }
            if (description.Length > 128)
            {
                description = description.Substring(0, 128);
            }

            type = (AllianceType)LogicMath.Clamp((int)type, (int)AllianceType.OPEN, (int)AllianceType.CLOSED);

            AllianceBadgeUtil.ParseAllianceBadgeLayer(badgeId, out LogicAllianceBadgeLayerData middle, out LogicAllianceBadgeLayerData background, out LogicAllianceBadgeLayerData foreground);

            if (middle != null && middle.GetRequiredClanLevel() > allianceLevel)
            {
                middle = AllianceBadgeUtil.GetFirstUnlockedAllianceBadgeLayerByType(LogicAllianceBadgeLayerType.MIDDLE, allianceLevel);
            }
            if (background != null && background.GetRequiredClanLevel() > allianceLevel)
            {
                background = AllianceBadgeUtil.GetFirstUnlockedAllianceBadgeLayerByType(LogicAllianceBadgeLayerType.BACKGROUND, allianceLevel);
            }
            if (foreground != null && foreground.GetRequiredClanLevel() > allianceLevel)
            {
                foreground = AllianceBadgeUtil.GetFirstUnlockedAllianceBadgeLayerByType(LogicAllianceBadgeLayerType.FOREGROUND, allianceLevel);
            }

            badgeId = AllianceBadgeUtil.GetAllianceBadgeId(middle, background, foreground);

            if (originData != null && originData.GetDataType() != LogicDataType.REGION)
            {
                originData = null;
            }

            this.Description = description;
            this.Header.SetAllianceType(type);
            this.Header.SetAllianceBadgeId(badgeId);
            this.Header.SetRequiredScore(requiredScore);
            this.Header.SetRequiredDuelScore(requiredDuelScore);
            this.Header.SetWarFrequency(warFrequency);
            this.Header.SetOriginData(originData);
            this.Header.SetPublicWarLog(publicWarLog);
            this.Header.SetArrangedWarEnabled(arrangedWarEnabled);

            if (this.Members.Count != 0)
            {
                LogicAllianceSettingsChangedCommand allianceSettingsChangedCommand = new LogicAllianceSettingsChangedCommand();

                allianceSettingsChangedCommand.SetAllianceData(this.Id, badgeId);

                this.AllowServerCommand(allianceSettingsChangedCommand);
                this.SendPiranhaMessage(this.GetAllianceFulEntryUpdateMessage(), 1);
            }
        }
Пример #7
0
        public void SetCount(int idx, int count)
        {
            this.m_resourceCount[idx] = LogicMath.Clamp(count, 0, this.GetMax(idx));

            if (this.m_parent.GetListener() != null)
            {
                this.m_parent.GetListener().RefreshResourceCount();
            }
        }
Пример #8
0
        public void ApplyExtraHealthPermil(int x, int y, int radius, int team, int extraHealthPermil, int extraHealthMin, int extraHealthMax, int time, int targetType)
        {
            LogicArrayList <LogicComponent> components = this.GetComponentManager().GetComponents(LogicComponentType.HITPOINT);

            for (int i = 0; i < components.Size(); i++)
            {
                LogicHitpointComponent hitpointComponent = (LogicHitpointComponent)components[i];
                LogicGameObject        parent            = hitpointComponent.GetParent();

                if (!parent.IsHidden() && hitpointComponent.GetHitpoints() != 0 && hitpointComponent.GetTeam() == team)
                {
                    LogicMovementComponent movementComponent = parent.GetMovementComponent();

                    if (movementComponent != null)
                    {
                        if (parent.GetGameObjectType() == LogicGameObjectType.CHARACTER)
                        {
                            LogicCharacter character = (LogicCharacter)parent;

                            if (character.GetCharacterData().GetAuraSpell(character.GetUpgradeLevel()) == this.m_data)
                            {
                                continue;
                            }
                        }

                        if (parent.IsFlying())
                        {
                            if (targetType != 1)
                            {
                                continue;
                            }
                        }
                        else if (targetType == 0)
                        {
                            continue;
                        }

                        int distanceX = x - parent.GetMidX();
                        int distanceY = y - parent.GetMidY();

                        if (LogicMath.Abs(distanceX) <= radius &&
                            LogicMath.Abs(distanceY) <= radius &&
                            distanceX * distanceX + distanceY * distanceY < (uint)(radius * radius))
                        {
                            int hp = hitpointComponent.GetOriginalHitpoints() +
                                     LogicMath.Clamp(extraHealthPermil * hitpointComponent.GetOriginalHitpoints() / 1000, 100 * extraHealthMin, 100 * extraHealthMax);

                            if (hp >= hitpointComponent.GetMaxHitpoints())
                            {
                                hitpointComponent.SetExtraHealth(hp, time);
                            }
                        }
                    }
                }
            }
        }
        public override void Decode(ByteStream stream)
        {
            base.Decode(stream);

            this.m_inputLayoutId  = stream.ReadInt();
            this.m_outputLayoutId = stream.ReadInt();

            this.m_inputLayoutId  = LogicMath.Clamp(this.m_inputLayoutId, 0, 7);
            this.m_outputLayoutId = LogicMath.Clamp(this.m_outputLayoutId, 0, 7);
        }
        public void LoadHitpoint(LogicJSONObject jsonObject)
        {
            LogicJSONNumber  hpNumber     = jsonObject.GetJSONNumber("hp");
            LogicJSONBoolean regenBoolean = jsonObject.GetJSONBoolean("reg");

            if (hpNumber != null)
            {
                this.m_hp = this.m_parent.GetLevel().GetState() != 2 ? LogicMath.Clamp(hpNumber.GetIntValue(), 0, this.m_maxHp) : this.m_maxHp;
            }
            else
            {
                this.m_hp = this.m_maxHp;
            }

            this.m_regenerationEnabled = regenBoolean != null && regenBoolean.IsTrue();
        }
Пример #11
0
        /// <summary>
        ///     Gets the troop housing build time village 2.
        /// </summary>
        public int GetTroopHousingBuildTimeVillage2(LogicLevel level, int ignoreBuildingCnt)
        {
            LogicBuildingData data = LogicDataTables.GetBuildingByName("Troop Housing2");

            if (data != null)
            {
                return(this._village2TroopHousingBuildTimeSecs[LogicMath.Clamp(level.GetGameObjectManagerAt(1).GetGameObjectCountByData(data) - ignoreBuildingCnt,
                                                                               0,
                                                                               this._village2TroopHousingBuildTimeSecs.Length - 1)]);
            }
            else
            {
                Debugger.Error("Could not find Troop Housing2 data");
            }

            return(0);
        }
Пример #12
0
        private static void OnAllianceUnitDonateResponseMessageReceived(AllianceUnitDonateResponseMessage message)
        {
            if (AllianceManager.TryGet(message.AccountId, out Alliance alliance))
            {
                StreamEntry streamEntry = StreamManager.GetAllianceStream(message.StreamId);

                if (streamEntry != null)
                {
                    DonateStreamEntry donateStreamEntry = (DonateStreamEntry)streamEntry;

                    if (message.Success)
                    {
                        LogicAllianceLevelData           allianceLevel = LogicDataTables.GetAllianceLevel(alliance.Header.GetAllianceLevel());
                        LogicAllianceUnitReceivedCommand logicAllianceUnitReceivedCommand = new LogicAllianceUnitReceivedCommand();
                        logicAllianceUnitReceivedCommand.SetData(message.MemberName, message.Data,
                                                                 LogicMath.Clamp(message.UpgradeLevel + allianceLevel.GetTroopDonationUpgrade(), 0, message.Data.GetUpgradeLevelCount() - 1));
                        ServerMessageManager.SendMessage(new GameAllowServerCommandMessage
                        {
                            AccountId     = donateStreamEntry.GetSenderAvatarId(),
                            ServerCommand = logicAllianceUnitReceivedCommand
                        }, 9);
                    }
                    else
                    {
                        donateStreamEntry.RemoveDonation(message.MemberId, message.Data, message.UpgradeLevel);
                        alliance.UpdateStreamEntry(donateStreamEntry);
                    }

                    donateStreamEntry.SetDonationPendingRequestCount(donateStreamEntry.GetDonationPendingRequestCount() - 1);

                    if (donateStreamEntry.IsCastleFull() && donateStreamEntry.GetDonationPendingRequestCount() <= 0)
                    {
                        alliance.RemoveStreamEntry(donateStreamEntry.GetId());
                        AllianceManager.Save(alliance);
                    }
                    else
                    {
                        StreamManager.Save(donateStreamEntry);
                    }
                }
            }
        }
Пример #13
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);
        }
Пример #14
0
        private static GameAvatar FindEnemy(MatchmakingEntry entry, Dictionary <long, GameAvatar> documents)
        {
            GameAvatar        document      = entry.Session.GameAvatar;
            LogicClientAvatar playerAvatar1 = document.LogicClientAvatar;

            int totalSecs       = TimeUtil.GetTimestamp() - entry.Timestamp;
            int strength1       = GameMatchmakingManager.CalculateStrength(playerAvatar1);
            int maxStrengthDiff = 50 + LogicMath.Clamp(totalSecs * 150 / 60, 0, 150);

            foreach (GameAvatar enemy in documents.Values)
            {
                LogicClientAvatar playerAvatar2 = enemy.LogicClientAvatar;

#if DEBUG
                if (ServerCore.Random.Rand(100) <= 95)
                {
                    continue;
                }
#else
                if (playerAvatar1.IsInAlliance() && playerAvatar2.IsInAlliance() && playerAvatar1.GetAllianceId().Equals(playerAvatar2.GetAllianceId()))
                {
                    continue;
                }

                int strength2 = GameMatchmakingManager.CalculateStrength(playerAvatar2);

                if (LogicMath.Abs(strength1 - strength2) >= maxStrengthDiff)
                {
                    continue;
                }
                if (document.HasRecentlyMatchedWithEnemy(enemy.Id))
                {
                    continue;
                }
#endif
                return(enemy);
            }

            return(null);
        }
        /// <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);
        }
Пример #16
0
        public bool MoveTo(int x, int y, LogicTileMap tileMap, bool defaultEndPoint)
        {
            this.ClearPath();

            if (this.m_parent != null)
            {
                if (this.m_parent.GetParent().IsFrozen())
                {
                    return(false);
                }
            }

            this.m_wall      = null;
            this.m_wallCount = 0;

            this.m_pathStartPosition.m_x = this.m_position.m_x >> 8;
            this.m_pathStartPosition.m_y = this.m_position.m_y >> 8;
            this.m_pathEndPosition.m_x   = x >> 8;
            this.m_pathEndPosition.m_y   = y >> 8;

            this.m_pathStartPosition.m_x = LogicMath.Clamp(this.m_pathStartPosition.m_x, 0, 99);
            this.m_pathStartPosition.m_y = LogicMath.Clamp(this.m_pathStartPosition.m_y, 0, 99);
            this.m_pathEndPosition.m_x   = LogicMath.Clamp(this.m_pathEndPosition.m_x, 0, 99);
            this.m_pathEndPosition.m_y   = LogicMath.Clamp(this.m_pathEndPosition.m_y, 0, 99);

            LogicPathFinder pathFinder;

            if (this.m_parent == null)
            {
                pathFinder = this.m_pathFinder;
                pathFinder.ResetCostStrategyToDefault();
            }
            else
            {
                bool resetStrategyCost = true;
                int  strategyCost      = 256;

                LogicGameObject        parent            = this.m_parent.GetParent();
                LogicHitpointComponent hitpointComponent = parent.GetHitpointComponent();

                if (hitpointComponent != null)
                {
                    if (hitpointComponent.GetTeam() == 1)
                    {
                        resetStrategyCost = false;
                        strategyCost      = 768;
                    }
                }

                if (this.m_parent.CanJumpWall())
                {
                    resetStrategyCost = false;
                    strategyCost      = 16;
                }

                if (parent.GetGameObjectType() == LogicGameObjectType.CHARACTER)
                {
                    LogicCharacter character = (LogicCharacter)parent;

                    if (character.IsWallBreaker())
                    {
                        resetStrategyCost = false;
                        strategyCost      = 128;
                    }
                }

                pathFinder = tileMap.GetPathFinder();

                if (resetStrategyCost)
                {
                    pathFinder.ResetCostStrategyToDefault();
                }
                else
                {
                    pathFinder.SetCostStrategy(true, strategyCost);
                }

                pathFinder.FindPath(this.m_pathStartPosition, this.m_pathEndPosition, true);
                pathFinder.GetPathLength();

                int pathLength = pathFinder.GetPathLength();

                this.m_path.EnsureCapacity(pathLength + 1);

                if (pathLength != 0 && defaultEndPoint)
                {
                    LogicVector2 pathPoint = new LogicVector2(x, y);

                    this.CheckWall(pathPoint);
                    this.m_path.Add(pathPoint);
                }

                if (LogicDataTables.GetGlobals().UseNewPathFinder())
                {
                    LogicTileMap pathFinderTileMap = pathFinder.GetTileMap();

                    int width  = 2 * pathFinderTileMap.GetSizeX();
                    int height = 2 * pathFinderTileMap.GetSizeY();

                    int startTileIdx = this.m_pathStartPosition.m_x + width * this.m_pathStartPosition.m_y;
                    int endTileIdx   = this.m_pathEndPosition.m_x + width * this.m_pathEndPosition.m_y;

                    if (!defaultEndPoint)
                    {
                        LogicVector2 pathPoint = new LogicVector2((endTileIdx % width) << 8, (endTileIdx / height) << 8);

                        this.CheckWall(pathPoint);
                        this.m_path.Add(pathPoint);
                    }

                    if (pathLength > 0 && !pathFinder.IsLineOfSightClear())
                    {
                        int iterationCount = 0;

                        while (endTileIdx != startTileIdx && endTileIdx != -1)
                        {
                            endTileIdx = pathFinder.GetParent(endTileIdx);

                            if (endTileIdx != startTileIdx && endTileIdx != -1)
                            {
                                LogicVector2 pathPoint = new LogicVector2((endTileIdx % width) << 8, (endTileIdx / height) << 8);

                                pathPoint.m_x += 128;
                                pathPoint.m_y += 128;

                                this.CheckWall(pathPoint);
                                this.m_path.Add(pathPoint);

                                if (iterationCount >= 100000)
                                {
                                    Debugger.Warning("LMSystem: iteration count > 100000");
                                    break;
                                }
                            }

                            iterationCount += 1;
                        }
                    }
                }
                else
                {
                    for (int i = -pathLength, j = 0; j + i != 0; j++)
                    {
                        LogicVector2 pathPoint = new LogicVector2();

                        pathFinder.GetPathPoint(pathPoint, i + j);

                        if (i + j == -1 && this.m_pathStartPosition.Equals(pathPoint))
                        {
                            pathPoint.Destruct();
                            pathPoint = null;
                        }
                        else
                        {
                            if (j != 0 || !this.m_pathStartPosition.Equals(pathPoint))
                            {
                                pathPoint.m_x = (pathPoint.m_x << 8) | 128;
                                pathPoint.m_y = (pathPoint.m_y << 8) | 128;
                            }
                            else
                            {
                                pathPoint.m_x = x;
                                pathPoint.m_y = y;
                            }

                            this.CheckWall(pathPoint);
                            this.m_path.Add(pathPoint);
                        }
                    }
                }
            }

            this.CalculatePathLength();

            if (this.m_path.Size() > 0)
            {
                this.CalculateDirection(this.m_pathDistance);
                return(true);
            }

            return(false);
        }
        public override void FindPath(LogicVector2 startPosition, LogicVector2 endPosition, bool clampPathFinderCost)
        {
            this.m_maxHeapLength = 0;

            if (this.m_tileMap.IsPassablePathFinder(startPosition.m_x, startPosition.m_y))
            {
                if (!this.IsReachable(endPosition.m_x, endPosition.m_y) && clampPathFinderCost)
                {
                    int distance = LogicMath.Sqrt((endPosition.m_x - startPosition.m_x) * (endPosition.m_x - startPosition.m_x) +
                                                  (endPosition.m_y - startPosition.m_y) * (endPosition.m_y - startPosition.m_y));
                    int lowDistanceX  = LogicMath.Clamp(endPosition.m_x - distance, 0, 2 * this.m_mapWidth);
                    int lowDistanceY  = LogicMath.Clamp(endPosition.m_y - distance, 0, 2 * this.m_mapHeight);
                    int highDistanceX = LogicMath.Clamp(endPosition.m_x + distance, 0, 2 * this.m_mapWidth);
                    int highDistanceY = LogicMath.Clamp(endPosition.m_y + distance, 0, 2 * this.m_mapHeight);

                    int minX        = -1;
                    int minY        = -1;
                    int minDistance = 0x7FFFFFFF;

                    while (lowDistanceX < highDistanceX)
                    {
                        int posX = lowDistanceX;

                        for (int posY = lowDistanceY; posY < highDistanceY; posY++)
                        {
                            if (this.IsReachable(posX, posY))
                            {
                                int pointDistance = (posX - endPosition.m_x) * (posX - endPosition.m_x) +
                                                    (posY - endPosition.m_y) * (posY - endPosition.m_y);

                                if (pointDistance < minDistance)
                                {
                                    minX        = posX;
                                    minY        = posY;
                                    minDistance = pointDistance;
                                }
                            }
                        }

                        ++lowDistanceX;
                    }

                    if (minX == -1)
                    {
                        this.m_pathLength = 0;
                        return;
                    }

                    endPosition.m_x = minX;
                    endPosition.m_y = minY;
                }

                if (this.IsReachable(endPosition.m_x, endPosition.m_y))
                {
                    int startTileIndex = startPosition.m_x + startPosition.m_y * this.m_mapWidth;
                    int endTileIndex   = endPosition.m_x + endPosition.m_y * this.m_mapWidth;

                    if (this.IsLineOfSightClear(startPosition.m_x, startPosition.m_y, endPosition.m_x, endPosition.m_y))
                    {
                        this.m_pathLength = 0;
                        this.m_pathBuffer[this.m_pathLength++] = endTileIndex;
                        this.m_pathBuffer[this.m_pathLength++] = startTileIndex;
                    }
                    else
                    {
                        this.AStar(startTileIndex, endTileIndex);

                        if (this.m_pathLength > 0)
                        {
                            this.m_pathBuffer[this.m_pathLength++] = startTileIndex;
                        }
                    }
                }
                else
                {
                    this.m_pathLength = 0;
                }
            }
            else
            {
                this.m_pathLength = 0;
            }
        }
Пример #18
0
 /// <summary>
 ///     Sets the max hitpoints.
 /// </summary>
 public void SetMaxHitpoints(int maxHp)
 {
     this._maxHp = maxHp;
     this._hp    = LogicMath.Clamp(this._hp, 0, 100 * maxHp);
 }
Пример #19
0
        public void ApplyDamagePermil(int x, int y, int unk1, int team, int unk2, int targetType, int damageType, int unk3, bool healing)
        {
            LogicSpellData spellData = this.GetSpellData();

            int radius                   = spellData.GetRadius(this.m_upgradeLevel);
            int troopDamagePermil        = spellData.GetTroopDamagePermil(this.m_upgradeLevel);
            int buildingDamagePermil     = spellData.GetBuildingDamagePermil(this.m_upgradeLevel);
            int executeHealthPermil      = spellData.GetExecuteHealthPermil(this.m_upgradeLevel);
            int damagePermilMin          = spellData.GetDamagePermilMin(this.m_upgradeLevel);
            int preferredTargetDamageMod = spellData.GetPreferredTargetDamageMod();
            int preferredDamagePermilMin = spellData.GetPreferredDamagePermilMin(this.m_upgradeLevel);

            LogicData preferredTarget = spellData.GetPreferredTarget();

            LogicVector2 pushBackPosition = new LogicVector2();
            LogicArrayList <LogicComponent> components = this.GetComponentManager().GetComponents(LogicComponentType.HITPOINT);

            int tmp = troopDamagePermil + 2 * buildingDamagePermil;

            for (int i = 0; i < components.Size(); i++)
            {
                LogicHitpointComponent hitpointComponent = (LogicHitpointComponent)components[i];
                LogicGameObject        parent            = hitpointComponent.GetParent();

                if (!parent.IsHidden() && hitpointComponent.GetHitpoints() != 0)
                {
                    if (hitpointComponent.GetTeam() == team)
                    {
                        if (tmp > 0 || tmp < 0 && parent.IsPreventsHealing())
                        {
                            continue;
                        }
                    }
                    else if (tmp < 0)
                    {
                        continue;
                    }

                    if (damageType == 2 && parent.GetGameObjectType() != LogicGameObjectType.CHARACTER)
                    {
                        continue;
                    }

                    int parentX;
                    int parentY;

                    LogicMovementComponent movementComponent = parent.GetMovementComponent();

                    if (movementComponent != null || parent.IsFlying())
                    {
                        if (parent.IsFlying())
                        {
                            if (targetType == 1)
                            {
                                continue;
                            }
                        }
                        else if (targetType == 0)
                        {
                            continue;
                        }

                        parentX = parent.GetMidX();
                        parentY = parent.GetMidY();
                    }
                    else
                    {
                        int posX = parent.GetX();
                        int posY = parent.GetY();

                        parentX = LogicMath.Clamp(x, posX, posX + (parent.GetWidthInTiles() << 9));
                        parentY = LogicMath.Clamp(y, posY, posY + (parent.GetHeightInTiles() << 9));
                    }

                    int distanceX = x - parentX;
                    int distanceY = y - parentY;

                    if (LogicMath.Abs(distanceX) <= radius &&
                        LogicMath.Abs(distanceY) <= radius &&
                        distanceX * distanceX + distanceY * distanceY < (uint)(radius * radius))
                    {
                        if (damageType == 1 && parent.GetGameObjectType() == LogicGameObjectType.BUILDING)
                        {
                            LogicBuilding building = (LogicBuilding)parent;

                            if (building.GetResourceStorageComponentComponent() != null &&
                                !building.GetBuildingData().IsTownHall() &&
                                !building.GetBuildingData().IsTownHallVillage2())
                            {
                                parent.SetDamageTime(10);
                                continue;
                            }
                        }

                        if (parent.GetGameObjectType() == LogicGameObjectType.BUILDING || parent.GetGameObjectType() == LogicGameObjectType.CHARACTER)
                        {
                            int dataDamagePermil = parent.GetGameObjectType() == LogicGameObjectType.BUILDING ? buildingDamagePermil : troopDamagePermil;

                            if (dataDamagePermil != 0)
                            {
                                int permil = 10 * hitpointComponent.GetMaxHitpoints() * dataDamagePermil / 10000;

                                if (10 * hitpointComponent.GetMaxHitpoints() * dataDamagePermil <= -10000)
                                {
                                    if (parent.IsHero())
                                    {
                                        permil = LogicDataTables.GetGlobals().GetHeroHealMultiplier() * permil / 100;
                                    }
                                }

                                bool isPreferredTarget = LogicCombatComponent.IsPreferredTarget(preferredTarget, parent);

                                int numberOfHits    = spellData.GetNumberOfHits(this.m_upgradeLevel);
                                int completePermil  = hitpointComponent.GetDamagePermilCount() / spellData.GetNumberOfHits(this.m_upgradeLevel);
                                int calculateDamage = isPreferredTarget
                                    ? permil / (completePermil + 1) + preferredTargetDamageMod * hitpointComponent.GetMaxHitpoints() / (100 * numberOfHits) * completePermil *
                                                      completePermil
                                    : permil / (2 * completePermil + 1);
                                int permilMin = isPreferredTarget ? preferredDamagePermilMin : damagePermilMin;
                                int damage    = hitpointComponent.GetMaxHitpoints() * permilMin / 10000;

                                if (calculateDamage >= damage)
                                {
                                    damage = calculateDamage;
                                }

                                if (executeHealthPermil > 0 && 1000 * (hitpointComponent.GetHitpoints() - damage) <= executeHealthPermil)
                                {
                                    damage = hitpointComponent.GetHitpoints();
                                }

                                hitpointComponent.CauseDamagePermil(damage);

                                if (healing)
                                {
                                    // Listener.
                                }

                                if ((distanceX | distanceX) == 0)
                                {
                                    distanceX = 1;
                                }

                                pushBackPosition.m_x = -distanceX;
                                pushBackPosition.m_y = -distanceY;

                                pushBackPosition.Normalize(512);

                                if (unk3 > 0 && movementComponent != null)
                                {
                                    movementComponent.GetMovementSystem().PushBack(pushBackPosition, damage, unk3, 0, false, true);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #20
0
 /// <summary>
 ///     Sets hitpoints.
 /// </summary>
 public void SetHitpoints(int hp)
 {
     this._hp = LogicMath.Clamp(hp, 0, 100 * this._maxHp);
 }
 public ProxySettings(LogicJSONObject jsonObject)
 {
     this.SessionCapacity = LogicMath.Clamp(jsonObject.GetJSONNumber("sessionCapacity").GetIntValue(), 0, 16000);
 }
Пример #22
0
 public int GetSecondsToFullHealth(int hp, int upgLevel)
 {
     return(60 * (this.m_regenerationTimeSecs[upgLevel] / 60 * (this.m_hitpoints[upgLevel] - LogicMath.Clamp(hp, 0, this.m_hitpoints[upgLevel])) /
                  this.m_hitpoints[upgLevel]));
 }
 public void SetResourceCount(int idx, int count)
 {
     this.m_lootCount[idx] = LogicMath.Clamp(count, 0, this.m_capCount[idx]);
 }
        private void Spawn()
        {
            int free = LogicMath.Min(LogicMath.Min(this.m_spawnCount, this.m_maxSpawned - this.m_spawned.Size()), this.m_maxLifetimeSpawns - this.m_lifeTimeSpawns);

            if (free > 0)
            {
                int x           = this.m_parent.GetX();
                int y           = this.m_parent.GetY();
                int tileX       = this.m_parent.GetTileX();
                int tileY       = this.m_parent.GetTileY();
                int width       = this.m_parent.GetWidthInTiles();
                int height      = this.m_parent.GetHeightInTiles();
                int levelWidth  = this.m_parent.GetLevel().GetWidthInTiles();
                int levelHeight = this.m_parent.GetLevel().GetHeightInTiles();

                int startTileX = LogicMath.Clamp(tileX - this.m_radius, 0, levelWidth);
                int startTileY = LogicMath.Clamp(tileY - this.m_radius, 0, levelHeight);
                int endTileX   = LogicMath.Clamp(tileX + this.m_radius + width, 0, levelWidth);
                int endTileY   = LogicMath.Clamp(tileY + this.m_radius + height, 0, levelHeight);

                int radius      = (this.m_radius << 9) * (this.m_radius << 9);
                int possibility = (endTileX - startTileX) * (endTileY - startTileY);

                LogicArrayList <LogicTile> spawnPoints = new LogicArrayList <LogicTile>(possibility);
                LogicTileMap tileMap = this.m_parent.GetLevel().GetTileMap();

                int spawnPointUpStartX = x + (width << 9);
                int spawnPointUpStartY = y + (height << 9);

                int tmp4 = y - 256 - (startTileY << 9);

                int startMidX = (startTileX << 9) | 256;
                int startMidY = (startTileY << 9) | 256;

                for (int i = startTileX, j = startMidX; i < endTileX; i++, j += 512)
                {
                    int tmp1 = j >= spawnPointUpStartX ? -spawnPointUpStartX + j + 1 : 0;
                    int tmp2 = j >= x ? tmp1 : x - j;

                    tmp2 *= tmp2;

                    for (int k = startTileY, l = startMidY, m = tmp4; k < endTileY; k++, l += 512, m -= 512)
                    {
                        LogicTile tile = tileMap.GetTile(i, k);

                        if (tile.GetGameObjectCount() == 0)
                        {
                            int tmp3 = y <= l ? l < spawnPointUpStartY ? 0 : -spawnPointUpStartY + l + 1 : m;

                            tmp3 *= tmp3;

                            if (tmp2 + tmp3 <= radius)
                            {
                                spawnPoints.Add(tile);
                            }
                        }
                    }
                }

                for (int i = free; i > 0 && spawnPoints.Size() > 0; i--, ++this.m_lifeTimeSpawns)
                {
                    int idx = this.m_randomizer.Rand(spawnPoints.Size());

                    LogicTile       tile       = spawnPoints[idx];
                    LogicGameObject gameObject = LogicGameObjectFactory.CreateGameObject(this.m_spawnData, this.m_parent.GetLevel(), this.m_parent.GetVillageType());

                    gameObject.SetInitialPosition(tile.GetX() << 9, tile.GetY() << 9);

                    this.m_parent.GetGameObjectManager().AddGameObject(gameObject, -1);
                    this.m_spawned.Add(gameObject.GetGlobalID());

                    spawnPoints.Remove(idx);
                }
            }
        }
        public void CauseDamage(int damage, int gameObjectId, LogicGameObject gameObject)
        {
            if (damage >= 0 || this.m_hp != 0)
            {
                if (this.m_parent == null)
                {
                    if (damage > 0 && this.m_invulnerabilityTime > 0)
                    {
                        return;
                    }
                }
                else
                {
                    LogicCombatComponent combatComponent = this.m_parent.GetCombatComponent();

                    if (combatComponent != null)
                    {
                        if (combatComponent.GetUndergroundTime() > 0 && damage > 0)
                        {
                            damage = 0;
                        }
                    }

                    if (!this.m_parent.GetLevel().GetInvulnerabilityEnabled())
                    {
                        if (damage > 0 && this.m_invulnerabilityTime > 0)
                        {
                            return;
                        }
                    }
                    else
                    {
                        damage = 0;
                    }

                    if (this.m_parent.GetGameObjectType() == LogicGameObjectType.CHARACTER)
                    {
                        LogicCharacter character = (LogicCharacter)this.m_parent;
                        LogicArrayList <LogicCharacter> childTroops = character.GetChildTroops();

                        if (childTroops != null && childTroops.Size() > 0 || character.GetSpawnDelay() > 0)
                        {
                            return;
                        }
                    }
                }

                if (gameObjectId != 0 && damage < 0)
                {
                    int prevHealingIdx = -1;
                    int healingIdx     = -1;

                    for (int i = 0; i < 8; i++)
                    {
                        if (this.m_healingId[i] == gameObjectId)
                        {
                            prevHealingIdx = i;
                        }
                        else if (healingIdx == -1)
                        {
                            healingIdx = i;

                            if (this.m_healingTime[i] > 0)
                            {
                                healingIdx = -1;
                            }
                        }
                    }

                    if (healingIdx < prevHealingIdx && prevHealingIdx != -1 && healingIdx != -1)
                    {
                        this.m_healingId[healingIdx]       = gameObjectId;
                        this.m_healingTime[healingIdx]     = 1000;
                        this.m_healingId[prevHealingIdx]   = 0;
                        this.m_healingTime[prevHealingIdx] = 0;
                    }
                    else if (prevHealingIdx == -1)
                    {
                        if (healingIdx != -1)
                        {
                            this.m_healingId[healingIdx]   = gameObjectId;
                            this.m_healingTime[healingIdx] = 1000;
                        }
                        else
                        {
                            healingIdx = 8;
                        }
                    }
                    else
                    {
                        healingIdx = prevHealingIdx;
                        this.m_healingTime[prevHealingIdx] = 1000;
                    }

                    damage = damage * LogicDataTables.GetGlobals().GetHealStackPercent(healingIdx) / 100;
                }

                int prevHp         = (this.m_hp + 99) / 100;
                int prevAccurateHp = this.m_hp;
                this.m_hp = LogicMath.Clamp(this.m_hp - damage, 0, this.m_maxHp);
                int hp = (this.m_hp + 99) / 100;

                if (prevHp > hp)
                {
                    LogicResourceStorageComponent resourceStorageComponent =
                        (LogicResourceStorageComponent)this.m_parent.GetComponent(LogicComponentType.RESOURCE_STORAGE);
                    LogicResourceProductionComponent resourceProductionComponent =
                        (LogicResourceProductionComponent)this.m_parent.GetComponent(LogicComponentType.RESOURCE_PRODUCTION);
                    LogicWarResourceStorageComponent warResourceStorageComponent =
                        (LogicWarResourceStorageComponent)this.m_parent.GetComponent(LogicComponentType.WAR_RESOURCE_STORAGE);

                    if (this.m_parent.GetGameObjectType() == LogicGameObjectType.BUILDING)
                    {
                        LogicBuilding building = (LogicBuilding)this.m_parent;

                        if (!building.GetBuildingData().IsLootOnDestruction() || prevAccurateHp > 0 && (this.m_hp == 0 || (uint)this.m_hp >= 0xFFFFFF3A))
                        {
                            if (resourceStorageComponent != null)
                            {
                                resourceStorageComponent.ResourcesStolen(prevHp - hp, prevHp);
                            }
                            if (resourceProductionComponent != null)
                            {
                                resourceProductionComponent.ResourcesStolen(prevHp - hp, prevHp);
                            }
                            if (warResourceStorageComponent != null)
                            {
                                warResourceStorageComponent.ResourcesStolen(prevHp - hp, prevHp);
                            }
                        }
                    }

                    if (this.m_parent.IsWall())
                    {
                        this.m_parent.RefreshPassable();
                    }
                    this.m_lastDamageTime = 0;
                }

                this.UpdateHeroHealthToAvatar(hp);

                if (damage <= 0)
                {
                    if (damage < 0)
                    {
                        // Listener
                    }
                }
                else
                {
                    if (this.m_parent.GetMovementComponent() != null)
                    {
                        this.m_parent.GetMovementComponent().SetPatrolFreeze();
                    }
                }

                if (prevAccurateHp > 0 && this.m_hp == 0)
                {
                    this.m_parent.DeathEvent();
                    this.m_parent.GetLevel().UpdateBattleStatus();

                    if (this.m_parent.IsWall())
                    {
                        this.WallRemoved();
                    }
                }
            }
        }
 public void SetMaxHitpoints(int maxHp)
 {
     this.m_maxHp      = 100 * maxHp;
     this.m_hp         = LogicMath.Clamp(this.m_hp, 0, this.m_maxHp);
     this.m_originalHp = this.m_maxHp;
 }
 public void SetHitpoints(int hp)
 {
     this.m_hp = LogicMath.Clamp(100 * hp, 0, this.m_maxHp);
 }
        public void CreateReferences(CSVRow row, LogicData data, int idx)
        {
            this.m_row   = row;
            this.m_data  = data;
            this.m_index = idx;

            this.m_pushBack      = row.GetClampedIntegerValue("PushBack", idx);
            this.m_airTargets    = row.GetClampedBooleanValue("AirTargets", idx);
            this.m_groundTargets = row.GetClampedBooleanValue("GroundTargets", idx);
            this.m_altAttackMode = row.GetClampedBooleanValue("AltAttackMode", idx);
            this.m_damage        = 100 * row.GetClampedIntegerValue("Damage", idx);

            int dps            = row.GetClampedIntegerValue("DPS", idx);
            int attackSpeed    = row.GetClampedIntegerValue("AttackSpeed", idx);
            int altDps         = row.GetClampedIntegerValue("AltDPS", idx);
            int altAttackSpeed = row.GetClampedIntegerValue("AltAttackSpeed", idx);

            if (this.m_altAttackMode && altAttackSpeed == 0)
            {
                altAttackSpeed = attackSpeed;
            }

            int cooldownOverride = row.GetClampedIntegerValue("CoolDownOverride", idx);

            if (cooldownOverride == 0)
            {
                int tmp = (int)(((dps | this.m_damage) >> 31) & 0xFFFFFAEC) + 1500;

                if (attackSpeed > tmp)
                {
                    cooldownOverride = attackSpeed - tmp;
                }
            }

            this.m_prepareSpeed = row.GetClampedIntegerValue("PrepareSpeed", idx);

            this.m_attackSpeed      = attackSpeed - cooldownOverride;
            this.m_altAttackSpeed   = altAttackSpeed - cooldownOverride;
            this.m_cooldownOverride = cooldownOverride;

            this.m_damageMulti = 100 * row.GetClampedIntegerValue("DamageMulti", idx);
            this.m_damageLvl2  = 100 * row.GetClampedIntegerValue("DamageLv2", idx);
            this.m_damageLvl3  = 100 * row.GetClampedIntegerValue("DamageLv3", idx);

            this.m_altDamage = this.m_damage;

            if (dps != 0)
            {
                if (altDps == 0)
                {
                    altDps = dps;
                }

                this.m_damage      = LogicGamePlayUtil.DPSToSingleHit(dps, this.m_attackSpeed + this.m_cooldownOverride);
                this.m_altDamage   = LogicGamePlayUtil.DPSToSingleHit(altDps, this.m_altAttackSpeed + this.m_cooldownOverride);
                this.m_damageMulti = LogicGamePlayUtil.DPSToSingleHit(row.GetClampedIntegerValue("DPSMulti", idx), this.m_attackSpeed + this.m_cooldownOverride);
                this.m_damageLvl2  = LogicGamePlayUtil.DPSToSingleHit(row.GetClampedIntegerValue("DPSLv2", idx), this.m_attackSpeed + this.m_cooldownOverride);
                this.m_damageLvl3  = LogicGamePlayUtil.DPSToSingleHit(row.GetClampedIntegerValue("DPSLv3", idx), this.m_attackSpeed + this.m_cooldownOverride);
            }

            this.m_hitEffectData       = LogicDataTables.GetEffectByName(row.GetClampedValue("HitEffect", idx), data);
            this.m_hitEffect2Data      = LogicDataTables.GetEffectByName(row.GetClampedValue("HitEffect2", idx), data);
            this.m_hitEffectActiveData = LogicDataTables.GetEffectByName(row.GetClampedValue("HitEffectActive", idx), data);

            this.m_attackRange  = (row.GetClampedIntegerValue("AttackRange", idx) << 9) / 100;
            this.m_damageRadius = (row.GetClampedIntegerValue("DamageRadius", idx) << 9) / 100;

            this.m_attackEffectData        = LogicDataTables.GetEffectByName(row.GetClampedValue("AttackEffect", idx), data);
            this.m_altAttackEffectData     = LogicDataTables.GetEffectByName(row.GetClampedValue("AttackEffectAlt", idx), data);
            this.m_ammoCount               = row.GetClampedIntegerValue("AmmoCount", idx);
            this.m_attackEffect2Data       = LogicDataTables.GetEffectByName(row.GetClampedValue("AttackEffect2", idx), data);
            this.m_attackEffectLv2Data     = LogicDataTables.GetEffectByName(row.GetClampedValue("AttackEffectLv2", idx), data);
            this.m_attackEffectLv3Data     = LogicDataTables.GetEffectByName(row.GetClampedValue("AttackEffectLv3", idx), data);
            this.m_transitionEffectLv2Data = LogicDataTables.GetEffectByName(row.GetClampedValue("TransitionEffectLv2", idx), data);
            this.m_transitionEffectLv3Data = LogicDataTables.GetEffectByName(row.GetClampedValue("TransitionEffectLv3", idx), data);
            this.m_altNumMultiTargets      = row.GetClampedIntegerValue("AltNumMultiTargets", idx);
            this.m_switchTimeLv2           = row.GetClampedIntegerValue("Lv2SwitchTime", idx);
            this.m_switchTimeLv3           = row.GetClampedIntegerValue("Lv3SwitchTime", idx);
            this.m_statusEffectTime        = row.GetClampedIntegerValue("StatusEffectTime", idx);
            this.m_speedMod              = row.GetClampedIntegerValue("SpeedMod", idx);
            this.m_altAttackRange        = (row.GetClampedIntegerValue("AltAttackRange", idx) << 9) / 100;
            this.m_projectileData        = LogicDataTables.GetProjectileByName(row.GetClampedValue("Projectile", idx), data);
            this.m_altProjectileData     = LogicDataTables.GetProjectileByName(row.GetClampedValue("AltProjectile", idx), data);
            this.m_shockwavePushStrength = row.GetClampedIntegerValue("ShockwavePushStrength", idx);
            this.m_hitSpellData          = LogicDataTables.GetSpellByName(row.GetClampedValue("HitSpell", idx), data);
            this.m_hitSpellLevel         = row.GetClampedIntegerValue("HitSpellLevel", idx);
            this.m_damage2             = 100 * row.GetClampedIntegerValue("Damage2", idx);
            this.m_damage2Radius       = (row.GetClampedIntegerValue("Damage2Radius", idx) << 9) / 100;
            this.m_damage2Delay        = row.GetClampedIntegerValue("Damage2Delay", idx);
            this.m_damage2Min          = 100 * row.GetClampedIntegerValue("Damage2Min", idx);
            this.m_damage2FalloffStart = (row.GetClampedIntegerValue("Damage2FalloffStart", idx) << 9) / 100;
            this.m_damage2FalloffEnd   = (row.GetClampedIntegerValue("Damage2FalloffStart", idx) << 9) / 100;

            if (this.m_damage2FalloffEnd < this.m_damage2FalloffStart)
            {
                Debugger.Error("Building " + row.GetName() + " has falloff end less than falloff start!");
            }

            if (this.m_damage2FalloffEnd > this.m_damage2Radius)
            {
                Debugger.Error("Building " + row.GetName() + " has falloff end greater than the damage radius!");
            }

            this.m_preAttackEffectData         = LogicDataTables.GetEffectByName(row.GetClampedValue("PreAttackEffect", idx), data);
            this.m_becomesTargetableEffectData = LogicDataTables.GetEffectByName(row.GetClampedValue("BecomesTargetableEffect", idx), data);
            this.m_increasingDamage            = row.GetClampedBooleanValue("IncreasingDamage", idx);
            this.m_preventsHealing             = row.GetClampedBooleanValue("PreventsHealing", idx);
            this.m_alternatePickNewTargetDelay = row.GetClampedIntegerValue("AlternatePickNewTargetDelay", idx);
            this.m_shockwaveArcLength          = row.GetClampedIntegerValue("ShockwaveArcLength", idx);
            this.m_shockwaveExpandRadius       = row.GetClampedIntegerValue("ShockwaveExpandRadius", idx);
            this.m_targetingConeAngle          = row.GetClampedIntegerValue("TargetingConeAngle", idx);
            this.m_penetratingProjectile       = row.GetClampedBooleanValue("PenetratingProjectile", idx);
            this.m_penetratingRadius           = (row.GetClampedIntegerValue("PenetratingRadius", idx) << 9) / 100;
            this.m_penetratingExtraRange       = (row.GetClampedIntegerValue("PenetratingExtraRange", idx) << 9) / 100;
            this.m_targetGroups               = row.GetClampedBooleanValue("TargetGroups", idx);
            this.m_fightWithGroups            = row.GetClampedBooleanValue("FightWithGroups", idx);
            this.m_targetGroupsRadius         = (row.GetClampedIntegerValue("TargetGroupsRadius", idx) << 9) / 100;
            this.m_targetGroupsRange          = (row.GetClampedIntegerValue("TargetGroupsRange", idx) << 9) / 100;
            this.m_targetGroupsMinWeight      = row.GetClampedIntegerValue("TargetGroupsMinWeight", idx);
            this.m_wakeUpSpace                = row.GetClampedIntegerValue("WakeUpSpace", idx);
            this.m_wakeUpSpeed                = row.GetClampedIntegerValue("WakeUpSpeed", idx);
            this.m_preferredTargetData        = LogicDataTables.GetCharacterByName(row.GetClampedValue("PreferredTarget", idx), data);
            this.m_preferredTargetDamageMod   = row.GetClampedIntegerValue("PreferredTargetDamageMod", idx);
            this.m_preferredTargetNoTargeting = row.GetClampedBooleanValue("PreferredTargetNoTargeting", idx);
            this.m_altAirTargets              = row.GetClampedBooleanValue("AltAirTargets", idx);
            this.m_altGroundTargets           = row.GetClampedBooleanValue("AltGroundTargets", idx);
            this.m_altMultiTargets            = row.GetClampedBooleanValue("AltMultiTargets", idx);
            this.m_minAttackRange             = (row.GetClampedIntegerValue("MinAttackRange", idx) << 9) / 100;

            if (this.m_preferredTargetData == null)
            {
                this.m_preferredTargetData = LogicDataTables.GetBuildingClassByName(row.GetClampedValue("PreferedTargetBuildingClass", idx), data);

                if (this.m_preferredTargetData == null)
                {
                    this.m_preferredTargetData = LogicDataTables.GetBuildingByName(row.GetClampedValue("PreferedTargetBuilding", idx), data);
                }

                this.m_preferredTargetDamageMod = row.GetClampedIntegerValue("PreferedTargetDamageMod", idx);

                if (this.m_preferredTargetDamageMod == 0)
                {
                    this.m_preferredTargetDamageMod = 100;
                }
            }

            this.m_summonTroopCount   = row.GetClampedIntegerValue("SummonTroopCount", idx);
            this.m_summonCooldown     = row.GetClampedIntegerValue("SummonCooldown", idx);
            this.m_summonEffectData   = LogicDataTables.GetEffectByName(row.GetClampedValue("SummonEffect", idx), data);
            this.m_summonLimit        = row.GetClampedIntegerValue("SummonLimit", idx);
            this.m_summonTroopData    = LogicDataTables.GetCharacterByName(row.GetClampedValue("SummonTroop", idx), data);
            this.m_spawnOnAttack      = row.GetClampedBooleanValue("SpawnOnAttack", idx);
            this.m_hideEffectData     = LogicDataTables.GetEffectByName(row.GetClampedValue("HideEffect", idx), data);
            this.m_rageProjectileData = LogicDataTables.GetProjectileByName(row.GetClampedValue("RageProjectile", idx), data);
            this.m_projectileBounces  = row.GetClampedIntegerValue("ProjectileBounces", idx);
            this.m_selfAsAoeCenter    = row.GetClampedBooleanValue("SelfAsAoeCenter", idx);

            if (this.m_damage2Delay > this.m_cooldownOverride + this.m_attackSpeed)
            {
                Debugger.Error(row.GetName() + " has Damage2Delay greater than the attack speed!");
            }

            if (this.m_ammoCount > 0 && (this.m_attackSpeed & 63) != 0)
            {
                Debugger.Error(string.Format("Invalid attack speed {0} (must be multiple of 64)", this.m_attackSpeed));
            }

            this.m_burstCount             = row.GetClampedIntegerValue("BurstCount", idx);
            this.m_burstDelay             = row.GetClampedIntegerValue("BurstDelay", idx);
            this.m_altBurstCount          = row.GetClampedIntegerValue("AltBurstCount", idx);
            this.m_altBurstDelay          = row.GetClampedIntegerValue("AltBurstDelay", idx);
            this.m_dummyProjectileCount   = row.GetClampedIntegerValue("DummyProjectileCount", idx);
            this.m_attackEffectSharedData = LogicDataTables.GetEffectByName(row.GetClampedValue("AttackEffectShared", idx), data);
            this.m_chainAttackDistance    = row.GetClampedIntegerValue("ChainAttackDistance", idx);
            this.m_newTargetAttackDelay   = row.GetClampedIntegerValue("NewTargetAttackDelay", idx);

            if (this.m_newTargetAttackDelay > 0)
            {
                this.m_newTargetAttackDelay = LogicMath.Clamp(attackSpeed - this.m_newTargetAttackDelay, 0, attackSpeed);
            }
        }
Пример #29
0
        public override void SubTick()
        {
            base.SubTick();

            this.m_areaShieldSpeed = 0;

            bool isInAreaShield   = false;
            int  damagePercentage = 100;

            if (this.m_myTeam == 1)
            {
                LogicVector2 areaShield = new LogicVector2();

                if (this.m_level.GetAreaShield(this.GetMidX(), this.GetMidY(), areaShield))
                {
                    this.m_areaShieldSpeed = areaShield.m_x;

                    isInAreaShield   = true;
                    damagePercentage = 0;
                }
            }

            if (this.m_targetReached)
            {
                if (this.m_damageTime > 0)
                {
                    this.UpdateDamage(damagePercentage);
                }
            }
            else
            {
                if (this.m_targetGroups)
                {
                    if (this.m_target != null && this.m_groups != null)
                    {
                        LogicCombatComponent combatComponent = this.m_groups.GetCombatComponent();

                        if (combatComponent != null && !combatComponent.IsInRange(this.m_target))
                        {
                            this.m_target = null;
                        }
                    }
                }

                if (isInAreaShield)
                {
                    this.m_areaShieldDelay = LogicMath.Min(this.m_areaShieldDelay + 16, 200);
                }
                else if (this.m_areaShieldDelay > 0)
                {
                    this.m_areaShieldDelay = LogicMath.Max(this.m_areaShieldDelay - 4, 0);
                }

                if (this.m_areaShieldDelay == 0)
                {
                    if (this.m_target != null && this.m_target.GetMovementComponent() != null)
                    {
                        this.m_targetPosition.Set(this.m_target.GetMidX() * 8, this.m_target.GetMidY() * 8);
                        this.m_targetPosition.Add(this.m_unk168);
                    }
                }
                else if (this.m_target != null && this.m_target.GetMovementComponent() != null)
                {
                    int x = this.m_unk168.m_x + this.m_target.GetMidX() * 8;
                    int y = this.m_unk168.m_y + this.m_target.GetMidY() * 8;

                    LogicVector2 tmp1 = new LogicVector2(x - this.m_unk276.m_x, y - this.m_unk276.m_y);
                    LogicVector2 tmp2 = new LogicVector2(this.m_unk152.m_x, this.m_unk152.m_y);

                    int length1 = tmp1.Normalize(512);
                    int length2 = tmp2.Normalize(512);

                    int angle1 = tmp1.GetAngle();
                    int angle2 = tmp2.GetAngle();

                    if (LogicMath.Abs(LogicMath.NormalizeAngle180(angle1 - angle2)) <= 30)
                    {
                        this.m_targetPosition.m_x += LogicMath.Clamp(x - this.m_targetPosition.m_x, length1 / -500, length1 / 500);
                        this.m_targetPosition.m_y += LogicMath.Clamp(y - this.m_targetPosition.m_y, length1 / -500, length1 / 500);
                    }
                    else
                    {
                        this.m_target = null;
                    }
                }

                this.m_unk144.m_x = this.m_targetPosition.m_x - this.m_unk276.m_x;
                this.m_unk144.m_y = this.m_targetPosition.m_y - this.m_unk276.m_y;

                int distance = (200 - this.m_areaShieldDelay) * (8 * this.GetSpeed() - 8 * this.m_areaShieldSpeed) / 200 + 8 * this.m_areaShieldSpeed;

                if (distance * distance >= this.m_unk144.GetDistanceSquaredTo(0, 0))
                {
                    this.TargetReached(damagePercentage);
                }
                else
                {
                    this.m_unk152.m_x = this.m_unk144.m_x;
                    this.m_unk152.m_y = this.m_unk144.m_y;

                    this.m_unk144.Normalize(distance);

                    this.m_unk276.m_x += this.m_unk144.m_x;
                    this.m_unk276.m_y += this.m_unk144.m_y;

                    this.SetPositionXY(this.m_unk276.m_x >> 3, this.m_unk276.m_y >> 3);

                    this.m_unk160.m_x = this.m_unk144.m_x >> 3;
                    this.m_unk160.m_y = this.m_unk144.m_y >> 3;
                }

                if (this.m_shockwavePushStrength > 0)
                {
                    this.UpdateShockwavePush(this.m_myTeam, this.m_flyingTarget ? 0 : 1);
                }

                if (this.m_penetrating)
                {
                    this.UpdatePenetrating(damagePercentage);
                }

                this.m_travelTime += 16;
            }
        }
Пример #30
0
 /// <summary>
 ///     Gets the loot multiplier by townhall difference.
 /// </summary>
 public int GetLootMultiplierByTownHallDiff(int townHallLevel1, int townHallLevel2)
 {
     return(this._lootMultiplierByTownHallDifference[LogicMath.Clamp(townHallLevel1 + 4 - townHallLevel2, 0, this._lootMultiplierByTownHallDifference.Length - 1)]);
 }