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); }
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(); }
private void UpdateMuscle() { MoveViceBone viceBonePtr = null; MoveMuscle musclePtr = null; for (int i = 0; i < muscleNum; i++) { musclePtr = GetMuscle(i); viceBonePtr = GetViceBone(musclePtr.viceBoneId); MoveBone baseBone = GetBaseBone(viceBonePtr.baseBoneId); musclePtr.dir = baseBone.dir; Vector2 offsetDir = LogicMath.GetRotateNewPos(baseBone.dir, musclePtr.sinWithBoneDir, musclePtr.cosWithBoneDir); musclePtr.pos = baseBone.pos + offsetDir * musclePtr.deltaLength; } }
public virtual void ResourcesStolen(int damage, int hp) { if (damage > 0 && hp > 0) { LogicDataTable table = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < this.m_stealableResourceCount.Size(); i++) { LogicResourceData data = (LogicResourceData)table.GetItemAt(i); int stealableResource = this.GetStealableResourceCount(i); if (damage < hp) { stealableResource = damage * stealableResource / hp; } if (stealableResource > 0) { this.m_parent.GetLevel().GetBattleLog().IncreaseStolenResourceCount(data, stealableResource); this.m_resourceCount[i] -= stealableResource; LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar(); LogicAvatar visitorAvatar = this.m_parent.GetLevel().GetVisitorAvatar(); homeOwnerAvatar.CommodityCountChangeHelper(0, data, -stealableResource); visitorAvatar.CommodityCountChangeHelper(0, data, stealableResource); if (homeOwnerAvatar.IsNpcAvatar()) { LogicNpcData npcData = ((LogicNpcAvatar)homeOwnerAvatar).GetNpcData(); if (data == LogicDataTables.GetGoldData()) { visitorAvatar.CommodityCountChangeHelper(1, npcData, stealableResource); } else if (data == LogicDataTables.GetElixirData()) { visitorAvatar.CommodityCountChangeHelper(2, npcData, stealableResource); } } this.m_stealableResourceCount[i] = LogicMath.Max(this.m_stealableResourceCount[i] - stealableResource, 0); } } } }
/// <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); }
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 void DivideAvatarResourcesToStorages() { LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar(); if (homeOwnerAvatar != null) { LogicArrayList <LogicComponent> resourceStorageComponents = this.m_components[(int)LogicComponentType.RESOURCE_STORAGE]; LogicArrayList <LogicComponent> warResourceStorageComponents = this.m_components[(int)LogicComponentType.WAR_RESOURCE_STORAGE]; LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i); if (!data.IsPremiumCurrency()) { if (data.GetWarResourceReferenceData() != null) { Debugger.DoAssert(warResourceStorageComponents.Size() < 2, "Too many war storage components"); for (int j = 0; j < warResourceStorageComponents.Size(); j++) { LogicWarResourceStorageComponent warResourceStorageComponent = (LogicWarResourceStorageComponent)warResourceStorageComponents[j]; warResourceStorageComponent.SetCount(i, homeOwnerAvatar.GetResourceCount(data)); } } else { for (int j = 0; j < resourceStorageComponents.Size(); j++) { ((LogicResourceStorageComponent)resourceStorageComponents[j]).SetCount(i, 0); } int resourceCount = homeOwnerAvatar.GetResourceCount(data); if (this.m_level.GetBattleLog() != null && data.GetVillageType() == 1) { resourceCount = LogicMath.Max(resourceCount - this.m_level.GetBattleLog().GetCostCount(data), 0); } this.AddResources(i, resourceCount, true); } } } } }
/// <summary> /// Gets the remaining attack seconds. /// </summary> public int GetRemainingAttackSeconds() { if ((this._state == 2 || this._state == 5) && !this._battleOver) { if (!this._level.InvulnerabilityEnabled()) { if (this._battleTimer != null) { return(LogicMath.Max(this._battleTimer.GetRemainingSeconds(this._level.GetLogicTime()), 1)); } } return(1); } return(0); }
public void Freeze(int time, int delay) { if (this.m_freezeTime > 0 && this.m_freezeDelay == 0) { this.m_freezeTime = LogicMath.Max(time - delay, this.m_freezeTime); } else if (this.m_freezeDelay > 0) { this.m_freezeDelay = LogicMath.Max(delay, this.m_freezeDelay); this.m_freezeTime = LogicMath.Max(time, this.m_freezeTime); } else { this.m_freezeTime = time; this.m_freezeDelay = delay; } }
/// <summary> /// Loads all accounts from database. /// </summary> internal static void LoadAccounts() { int dbCount = DatabaseManager.GetDatabaseCount(0); for (int i = 0; i < dbCount; i++) { CouchbaseDatabase database = DatabaseManager.GetDatabaseAt(0, i); if (database != null) { int highId = i; int maxLowId = database.GetHigherId(); object locker = new object(); Parallel.For(1, maxLowId + 1, new ParallelOptions { MaxDegreeOfParallelism = 4 }, id => { LogicLong accId = new LogicLong(highId, id); if (NetManager.GetDocumentOwnerId(ServiceCore.ServiceNodeType, id) == ServiceCore.ServiceNodeId) { string json = database.GetDocument(accId); if (json != null) { Account account = new Account(); account.Load(json); lock (locker) { AccountManager._accounts.Add(account.Id, account); AccountManager._accountCounters[highId] = LogicMath.Max(id, AccountManager._accountCounters[highId]); } } } }); } else { Logging.Warning("AccountManager::loadAccounts pDatabase->NULL"); } } }
public int GetClampedIntegerValue(string columnName, int index) { int columnIndex = this.GetColumnIndexByName(columnName); if (columnIndex != -1) { int arraySize = this.m_table.GetArraySizeAt(this, columnIndex); if (index >= arraySize || arraySize < 1) { index = LogicMath.Max(arraySize - 1, 0); } return(this.m_table.GetIntegerValueAt(columnIndex, this.m_rowOffset + index)); } return(0); }
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); }
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); }
/// <summary> /// Cancels the construction of trap. /// </summary> public void CancelConstruction() { LogicAvatar homeOwnerAvatar = this._level.GetHomeOwnerAvatar(); if (homeOwnerAvatar != null && homeOwnerAvatar.IsClientAvatar()) { if (this._constructionTimer != null) { this._constructionTimer.Destruct(); this._constructionTimer = null; int upgLevel = this._upgLevel; if (this._upgrading) { this.SetUpgradeLevel(this._upgLevel); upgLevel += 1; } LogicTrapData data = this.GetTrapData(); LogicResourceData buildResourceData = data.GetBuildResource(); Int32 buildCost = data.GetBuildCost(upgLevel); Int32 refundedCount = LogicMath.Max(LogicDataTables.GetGlobals().GetBuildCancelMultiplier() * buildCost / 100, 0); Debugger.Print("LogicTrap::cancelConstruction refunds: " + refundedCount); homeOwnerAvatar.CommodityCountChangeHelper(0, buildResourceData, refundedCount); this._level.GetWorkerManagerAt(this._data.GetVillageType()).DeallocateWorker(this); if (upgLevel != 0) { if (this._listener != null) { this._listener.RefreshState(); } } else { this.GetGameObjectManager().RemoveGameObject(this); } } } }
public 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; }
public void SpawnUnit(int count) { LogicTrapData data = this.GetTrapData(); LogicCharacterData spawnData = this.m_useAirMode[this.m_level.GetActiveLayout(this.m_villageType)] ? data.GetSpawnedCharAir() : data.GetSpawnedCharGround(); if (spawnData != null) { LogicVector2 position = new LogicVector2(); for (int i = 0, j = 59, k = 0, l = 0; i < count; i++, j += 59, k += 128, l += 360) { int random = l / data.GetNumSpawns(this.m_upgLevel) + j * this.m_numSpawns % 360; int randomX = (byte)(k & 0x80) ^ 0x180; int posX = this.GetMidX() + LogicMath.GetRotatedX(randomX, 0, random); int posY = this.GetMidY() + LogicMath.GetRotatedY(randomX, 0, random); if (spawnData.IsFlying()) { position.m_x = posX; position.m_y = posY; } else { if (!this.m_level.GetTileMap().GetNearestPassablePosition(posX, posY, position, 1536)) { continue; } } LogicCharacter character = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(spawnData, this.m_level, this.m_villageType); character.GetHitpointComponent().SetTeam(1); character.GetMovementComponent().EnableJump(3600000); character.SetInitialPosition(position.m_x, position.m_y); character.SetSpawnTime(200); this.GetGameObjectManager().AddGameObject(character, -1); } position.Destruct(); } }
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); } } } }
private void _InitMusclePosInfo() { MoveMuscle musclePtr = null; MoveViceBone viceBonePtr = null; for (int i = 0; i < c_nMaxActorNum; i++) { musclePtr = GetMuscle(i); //获取副骨骼 viceBonePtr = GetViceBone(musclePtr.viceBoneId); Debug.Log("=4=init=======>>" + " musclePtr.viceBoneId = " + musclePtr.viceBoneId); //肌肉 musclePtr.dir = viceBonePtr.dir; Vector2 offsetDir = LogicMath.GetRotateNewPos(viceBonePtr.dir, musclePtr.sinWithBoneDir, musclePtr.cosWithBoneDir); //计算位置 musclePtr.pos = viceBonePtr.pos + offsetDir * musclePtr.deltaLength; Debug.Log("=4=init=======>>" + " musclePtr.pos = " + musclePtr.pos + ", viceBonePtr.pos = " + viceBonePtr.pos + ", musclePtr.dir = " + musclePtr.dir + ",offsetDir = " + offsetDir + ",MusclePos = " + musclePtr.pos); } }
public bool GetNearestPassablePosition(int x, int y, LogicVector2 output, int radius) { int minDistance = -1; int startTileX = (x - radius) >> 8; int endTileX = (x + radius) >> 8; while (startTileX <= endTileX) { int startTileY = (y - radius) >> 8; int endTileY = (y + radius) >> 8; int posX = (startTileX << 8); int posY = (startTileY << 8); int distX = x - (startTileX << 8); int distY = y - (startTileY << 8); while (startTileY <= endTileY) { if (this.IsPassablePathFinder(startTileX, startTileY)) { int dist = LogicMath.Max(LogicMath.Abs(distX), LogicMath.Abs(distY)); if (minDistance < 0 || dist < minDistance) { minDistance = dist; output.m_x = posX; output.m_y = posY; } } posY += 256; distY -= 256; startTileY += 1; } startTileX += 1; } return(minDistance > -1); }
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); } } }
public int GetRemainingSeconds(LogicTime time) { int remaining = this.m_remainingTime - time.GetTick() - this.m_fastForward; if (LogicDataTables.GetGlobals().MoreAccurateTime()) { if (remaining > 0) { return(LogicMath.Max((int)(16L * remaining / 1000 + 1), 1)); } } else { if (remaining > 0) { return(LogicMath.Max((remaining + 59) / 60, 1)); } } return(0); }
public int GetSpeed() { int speed = this.m_speed; if (this.m_boostTime[0] > 0) { speed += this.m_boostSpeed[0]; } if (this.m_slowTime > 0) { speed = (int)((long)speed * (this.m_slowSpeed + 100) / 100); } if (this.m_parent != null && this.m_parent.GetParent().IsFrozen()) { speed = 0; } return(LogicMath.Max(0, speed)); }
public void EjectCharacters() { LogicArrayList <LogicComponent> components = this.GetComponentManager().GetComponents(LogicComponentType.MOVEMENT); int ejectHousingSpace = this.GetTrapData().GetEjectHousingLimit(this.m_upgLevel); int radius = this.GetTrapData().GetTriggerRadius(); for (int i = 0; i < components.Size(); i++) { LogicMovementComponent movementComponent = (LogicMovementComponent)components[i]; LogicGameObject parent = movementComponent.GetParent(); if (parent.GetGameObjectType() == LogicGameObjectType.CHARACTER) { LogicCharacter character = (LogicCharacter)parent; if (character.GetHitpointComponent() != null && character.GetHitpointComponent().GetTeam() == 0 && character.GetCharacterData().GetHousingSpace() <= ejectHousingSpace) { int distanceX = character.GetX() - this.GetMidX(); int distanceY = character.GetY() - this.GetMidY(); if (LogicMath.Abs(distanceX) <= radius && LogicMath.Abs(distanceY) <= radius) { if (character.GetCombatComponent() == null || character.GetCombatComponent().GetUndergroundTime() <= 0) { int distanceSquared = distanceX * distanceX + distanceY * distanceY; if (distanceSquared < (uint)(radius * radius)) { character.Eject(null); ejectHousingSpace -= character.GetCharacterData().GetHousingSpace(); } } } } } } }
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); }
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; } }
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); }
public void ObjectClose(LogicGameObject gameObject) { LogicHitpointComponent hitpointComponent = gameObject.GetHitpointComponent(); if (hitpointComponent == null || hitpointComponent.GetTeam() != 1) { if (gameObject.GetGameObjectType() == LogicGameObjectType.CHARACTER) { LogicCharacter character = (LogicCharacter)gameObject; LogicCharacterData data = character.GetCharacterData(); if (data.GetHousingSpace() < this.m_minTriggerHousingLimit) { return; } } LogicCombatComponent combatComponent = gameObject.GetCombatComponent(); if (combatComponent == null || combatComponent.GetUndergroundTime() <= 0) { if ((!gameObject.IsFlying() || this.m_airTrigger) && (gameObject.IsFlying() || this.m_groundTrigger)) { if (this.m_healerTrigger || combatComponent == null || !combatComponent.IsHealer()) { int distanceX = gameObject.GetX() - this.m_parent.GetMidX(); int distanceY = gameObject.GetY() - this.m_parent.GetMidY(); if (LogicMath.Abs(distanceX) <= this.m_triggerRadius && LogicMath.Abs(distanceY) <= this.m_triggerRadius && distanceX * distanceX + distanceY * distanceY < (uint)(this.m_triggerRadius * this.m_triggerRadius)) { this.Trigger(); } } } } } }
public static float GetCharacterStrength(LogicCharacterData data, int upgLevel) { if (data.IsProductionEnabled()) { float attackStrength = data.GetHitpoints(upgLevel) * 0.04f + LogicMath.Abs(data.GetAttackerItemData(upgLevel).GetDamagePerMS(0, false)) * 0.2f; if (data.GetUnitsInCamp(upgLevel) > 0 && data.GetUnitsInCamp(0) > 0) { attackStrength = (float)data.GetUnitsInCamp(upgLevel) / data.GetUnitsInCamp(0) * attackStrength; } for (int i = data.GetSpecialAbilityLevel(upgLevel); i > 0; i--) { attackStrength *= 1.1f; } return(attackStrength * 0.01f * data.GetStrengthWeight(upgLevel) / data.GetHousingSpace() * 10f); } return(0f); }
/// <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); } }
/// <summary> /// Loads the npc attack state. /// </summary> public void LoadNpcAttackState(LogicClientHome home, LogicAvatar homeOwnerAvatar, LogicAvatar visitorAvatar, int currentTimestamp, int secondsSinceLastSave) { if (this._state == 1) { Debugger.Error("loadAttackState called from invalid state"); } else { this._state = 2; this._currentTimestamp = currentTimestamp; this._calendar.Load(home.GetCalendarJSON(), currentTimestamp); if (this._battleTimer != null) { this._battleTimer.Destruct(); this._battleTimer = null; } if (homeOwnerAvatar.IsNpcAvatar()) { LogicNpcAvatar npcAvatar = (LogicNpcAvatar)homeOwnerAvatar; LogicNpcData npcData = npcAvatar.GetNpcData(); homeOwnerAvatar.SetResourceCount(LogicDataTables.GetGoldData(), LogicMath.Max(npcData.Gold - visitorAvatar.GetLootedNpcGold(npcData), 0)); homeOwnerAvatar.SetResourceCount(LogicDataTables.GetElixirData(), LogicMath.Max(npcData.Elixir - visitorAvatar.GetLootedNpcElixir(npcData), 0)); this._level.SetMatchType(2, 0); this._level.SetHome(home, false); this._level.SetHomeOwnerAvatar(homeOwnerAvatar); this._level.SetVisitorAvatar(visitorAvatar); this._level.FastForwardTime(secondsSinceLastSave); this._level.LoadingFinished(); } else { Debugger.Error("loadNpcAttackState called and home owner is not npc avatar"); } } }