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); }
public void CheckSpawning(LogicCharacterData spawnCharacterData, int spawnCount, int spawnUpgradeLevel, int invulnerabilityTime) { LogicCharacterData data = this.GetCharacterData(); if (spawnCharacterData == null) { spawnCharacterData = data.GetSecondaryTroop(); if (spawnCharacterData == null) { spawnCharacterData = data.GetAttackerItemData(this.m_upgradeLevel).GetSummonTroop(); if (spawnCharacterData == null) { return; } } } if (spawnCharacterData.IsSecondaryTroop() || this.IsHero()) { int totalSpawnCount = spawnCount; int upgLevel = this.m_upgradeLevel; if (upgLevel >= spawnCharacterData.GetUpgradeLevelCount()) { upgLevel = spawnCharacterData.GetUpgradeLevelCount() - 1; } if (this.IsHero()) { if (this.m_summonSpawnCount >= spawnCount) { return; } upgLevel = spawnUpgradeLevel; totalSpawnCount = LogicMath.Max(0, LogicMath.Min(3, spawnCount - this.m_summonSpawnCount)); } else { if (data.GetSecondaryTroopCount(this.m_upgradeLevel) != 0) { totalSpawnCount = data.GetSecondaryTroopCount(this.m_upgradeLevel); } else if (spawnCount == 0) { totalSpawnCount = data.GetAttackerItemData(this.m_upgradeLevel).GetSummonTroopCount(); if (this.m_summonTroops.Size() + totalSpawnCount > data.GetAttackerItemData(this.m_upgradeLevel).GetSummonLimit()) { totalSpawnCount = data.GetAttackerItemData(this.m_upgradeLevel).GetSummonLimit() - this.m_summonTroops.Size(); } } } if (totalSpawnCount > 0) { LogicVector2 position = new LogicVector2(); LogicRandom random = new LogicRandom(this.m_globalId); int team = this.GetHitpointComponent().GetTeam(); bool randomizeSecSpawnDist = this.GetCharacterData().GetRandomizeSecSpawnDist(); for (int i = 0, j = 0, k = 0; i < totalSpawnCount; i++, j += 360, k += 100) { int seed = j / totalSpawnCount; if (this.IsHero()) { seed = 360 * (i + this.m_summonSpawnCount) / LogicMath.Max(1, LogicMath.Min(6, spawnCount)); } int rnd = 59 * this.m_globalId % 360 + seed; if (spawnCharacterData.IsFlying()) { LogicCharacterData parentData = this.GetCharacterData(); position.Set(this.GetX() + LogicMath.GetRotatedX(parentData.GetSecondarySpawnOffset(), 0, rnd), this.GetY() + LogicMath.GetRotatedY(parentData.GetSecondarySpawnOffset(), 0, rnd)); } else if (spawnCharacterData.GetSpeed() == 0) { position.Set(this.GetX(), this.GetY()); } else { if (!this.m_level.GetTileMap().GetNearestPassablePosition(this.GetX(), this.GetY(), position, 1536)) { continue; } } LogicCharacter spawnGameObject = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(spawnCharacterData, this.m_level, this.m_villageType); if (this.GetCharacterData().GetAttackerItemData(this.m_upgradeLevel).GetSummonTroop() != null || this.IsHero()) { this.m_summonTroops.Add(spawnGameObject); } spawnGameObject.GetHitpointComponent().SetTeam(team); spawnGameObject.SetUpgradeLevel(upgLevel); spawnGameObject.SetInitialPosition(position.m_x, position.m_y); if (this.m_duplicate) { spawnGameObject.m_duplicateLifeTime = this.m_duplicateLifeTime; spawnGameObject.m_duplicate = true; } if (!this.IsHero()) { spawnGameObject.m_summoner = (LogicCharacterData)this.m_data; } if (invulnerabilityTime > 0) { spawnGameObject.GetHitpointComponent().SetInvulnerabilityTime(invulnerabilityTime); } int secondarySpawnDistance = this.IsHero() ? 768 : this.GetCharacterData().GetSecondarySpawnDistance(); if (secondarySpawnDistance > 0) { if (randomizeSecSpawnDist) { secondarySpawnDistance = (int)(random.Rand(secondarySpawnDistance) + ((uint)secondarySpawnDistance >> 1)); } position.Set(LogicMath.Cos(rnd, secondarySpawnDistance), LogicMath.Sin(rnd, secondarySpawnDistance)); int pushBackSpeed = spawnGameObject.GetCharacterData().GetPushbackSpeed(); if (pushBackSpeed <= 0) { pushBackSpeed = 1; } int pushBackTime = 2 * secondarySpawnDistance / (3 * pushBackSpeed); if (this.GetHitpointComponent().GetHitpoints() > 0) { if (this.GetAttackerItemData().GetSummonTroop() != null) { spawnGameObject.SetSpawnTime(pushBackTime); } else if (this.IsHero()) { spawnGameObject.SetSpawnTime(pushBackTime + k); } } spawnGameObject.GetMovementComponent().GetMovementSystem().PushTrap(position, pushBackTime, 0, false, false); } if (team == 1 || spawnGameObject.GetCharacterData().IsJumper()) { spawnGameObject.GetMovementComponent().EnableJump(3600000); spawnGameObject.GetCombatComponent().RefreshTarget(true); } if (team == 1) { if (LogicDataTables.GetGlobals().AllianceTroopsPatrol()) { spawnGameObject.GetCombatComponent().SetSearchRadius(LogicDataTables.GetGlobals().GetClanCastleRadius() >> 9); if (this.GetMovementComponent().GetBaseBuilding() != null) { spawnGameObject.GetMovementComponent().SetBaseBuilding(this.GetMovementComponent().GetBaseBuilding()); } } } this.GetGameObjectManager().AddGameObject(spawnGameObject, -1); if (this.IsHero()) { ++this.m_summonSpawnCount; } } position.Destruct(); } } else { Debugger.Warning("checkSpawning: trying to spawn normal troops!"); } }
public void SetUpgradeLevel(int upgLevel) { this.m_upgradeLevel = upgLevel; LogicCharacterData data = this.GetCharacterData(); LogicHitpointComponent hitpointComponent = this.GetHitpointComponent(); LogicCombatComponent combatComponent = this.GetCombatComponent(); int hp = data.GetHitpoints(upgLevel); int damagePercentage = 100; if (data.GetScaleByTH()) { LogicAvatar avatar = this.m_level.GetHomeOwnerAvatar(); if (hitpointComponent != null && hitpointComponent.GetTeam() == 0) { avatar = this.m_level.GetVisitorAvatar(); } int tmp1 = 700 * avatar.GetTownHallLevel() / (LogicDataTables.GetTownHallLevelCount() - 1); damagePercentage = tmp1 / 10 + 30; hp = damagePercentage * hp / 100; if (damagePercentage * hp < 200) { hp = 1; } if (tmp1 < -289) { damagePercentage = 1; } } hitpointComponent.SetMaxHitpoints(hp); hitpointComponent.SetHitpoints(data.GetHitpoints(upgLevel)); hitpointComponent.SetDieEffect(data.GetDieEffect(upgLevel), data.GetDieEffect2(upgLevel)); if (combatComponent != null) { combatComponent.SetAttackValues(data.GetAttackerItemData(upgLevel), damagePercentage); } if (this.m_childrens != null) { for (int i = 0; i < this.m_childrens.Size(); i++) { this.m_childrens[i].SetUpgradeLevel(upgLevel); } } if (this.IsHero()) { LogicHeroData heroData = (LogicHeroData)this.m_data; LogicAvatar avatar = this.m_level.GetHomeOwnerAvatar(); if (hitpointComponent.GetTeam() == 0) { avatar = this.m_level.GetVisitorAvatar(); } this.m_flying = heroData.IsFlying(avatar.GetHeroMode(heroData)); this.GetMovementComponent().SetFlying(this.m_flying); } if (data.GetAutoMergeDistance() > 0) { this.m_autoMergeTime = 2000; } int speed = data.GetSpeed(); if (data.GetSpecialAbilityLevel(this.m_upgradeLevel) > 0 && data.GetSpecialAbilityType() == LogicCharacterData.SPECIAL_ABILITY_TYPE_SPEED_BOOST) { speed = speed * data.GetSpecialAbilityAttribute(this.m_upgradeLevel) / 100; } this.GetMovementComponent().SetSpeed(speed); }
public override void Tick() { LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar(); if (homeOwnerAvatar != null) { this.m_updateAvatarCooldown += 64; if (this.m_updateAvatarCooldown > 1000) { homeOwnerAvatar.UpdateStarBonusLimitCooldown(); homeOwnerAvatar.UpdateLootLimitCooldown(); this.m_updateAvatarCooldown -= 1000; } } if (this.m_parent.IsAlive()) { if (!this.IsEmpty()) { if (this.m_bunkerSearchTime > 0) { this.m_bunkerSearchTime -= 64; } else { bool airTriggered = false; bool groundLocked = false; if (this.m_team == 1) { bool inAirDistance = false; bool inGroundDistance = false; int clanCastleRadius = LogicDataTables.GetGlobals().GetClanCastleRadius(); if (LogicDataTables.GetGlobals().CastleTroopTargetFilter()) { LogicCharacter closestGroundAttacker = this.ClosestAttacker(false); LogicCharacter closestAirAttacker = this.ClosestAttacker(true); if (closestAirAttacker != null) { inAirDistance = closestAirAttacker.GetPosition().GetDistanceSquaredTo(this.m_parent.GetX(), this.m_parent.GetY()) < clanCastleRadius * clanCastleRadius; } if (closestGroundAttacker != null) { inGroundDistance = closestGroundAttacker.GetPosition().GetDistanceSquaredTo(this.m_parent.GetX(), this.m_parent.GetY()) < clanCastleRadius * clanCastleRadius; } } else { LogicCharacter closestAttacker = (LogicCharacter)this.m_parent.GetLevel().GetGameObjectManager() .GetClosestGameObject(this.m_parent.GetX(), this.m_parent.GetY(), this.m_filter); if (closestAttacker != null) { inAirDistance = inGroundDistance = closestAttacker.GetPosition().GetDistanceSquaredTo(this.m_parent.GetX(), this.m_parent.GetY()) < clanCastleRadius * clanCastleRadius; } } groundLocked = !inGroundDistance; airTriggered = inAirDistance; if (!airTriggered && groundLocked) { this.m_bunkerSearchTime = LogicDataTables.GetGlobals().GetBunkerSearchTime(); return; } } else { airTriggered = true; } LogicCharacterData spawnData = null; int spawnLevel = -1; for (int i = 0; i < this.GetUnitTypeCount(); i++) { LogicCombatItemData data = this.GetUnitType(i); if (data != null) { int count = this.GetUnitCount(i); if (count > 0) { int upgLevel = this.GetUnitLevel(i); if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { LogicCharacterData characterData = (LogicCharacterData)data; LogicAttackerItemData attackerItemData = characterData.GetAttackerItemData(upgLevel); if (!(airTriggered & groundLocked) || attackerItemData.GetTrackAirTargets(false)) { if (airTriggered | groundLocked || attackerItemData.GetTrackGroundTargets(false)) { this.RemoveUnits(data, upgLevel, 1); spawnData = characterData; spawnLevel = upgLevel; } } } } } if (spawnData != null) { break; } } if (spawnData != null) { LogicCharacter character = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(spawnData, this.m_parent.GetLevel(), this.m_parent.GetVillageType()); character.GetHitpointComponent().SetTeam(this.m_team); if (character.GetChildTroops() != null) { LogicArrayList <LogicCharacter> childrens = character.GetChildTroops(); for (int i = 0; i < childrens.Size(); i++) { childrens[i].GetHitpointComponent().SetTeam(this.m_team); } } character.SetUpgradeLevel(spawnLevel == -1 ? 0 : spawnLevel); character.SetAllianceUnit(); if (character.GetCharacterData().IsJumper()) { character.GetMovementComponent().EnableJump(3600000); } if (this.m_team == 1) { if (LogicDataTables.GetGlobals().EnableDefendingAllianceTroopJump()) { character.GetMovementComponent().EnableJump(3600000); } if (LogicDataTables.GetGlobals().AllianceTroopsPatrol()) { character.GetCombatComponent().SetSearchRadius(LogicDataTables.GetGlobals().GetClanCastleRadius() >> 9); if (this.m_parent.GetGameObjectType() == LogicGameObjectType.BUILDING) { character.GetMovementComponent().SetBaseBuilding((LogicBuilding)this.m_parent); } } } else { LogicAvatar visitorAvatar = this.m_parent.GetLevel().GetVisitorAvatar(); visitorAvatar.RemoveAllianceUnit(spawnData, spawnLevel); visitorAvatar.GetChangeListener().AllianceUnitRemoved(spawnData, spawnLevel); LogicBattleLog battleLog = this.m_parent.GetLevel().GetBattleLog(); battleLog.IncrementDeployedAllianceUnits(spawnData, 1, spawnLevel); battleLog.SetAllianceUsed(true); } if (this.m_team == 1) { int spawnOffsetX = 0; int spawnOffsetY = 0; switch (this.m_troopSpawnOffset) { case 0: spawnOffsetX = 1; spawnOffsetY = 0; break; case 1: spawnOffsetX = -1; spawnOffsetY = 0; break; case 2: spawnOffsetX = 0; spawnOffsetY = 1; break; case 3: spawnOffsetX = 0; spawnOffsetY = -1; break; } character.SetInitialPosition(this.m_parent.GetMidX() + ((this.m_parent.GetWidthInTiles() << 8) - 128) * spawnOffsetX, this.m_parent.GetMidY() + ((this.m_parent.GetHeightInTiles() << 8) - 128) * spawnOffsetY); if (++this.m_troopSpawnOffset > 3) { this.m_troopSpawnOffset = 0; } } else if (LogicDataTables.GetGlobals().AllowClanCastleDeployOnObstacles()) { int posX = this.m_parent.GetX() + (this.m_parent.GetWidthInTiles() << 9) - 128; int posY = this.m_parent.GetY() + (this.m_parent.GetHeightInTiles() << 8); if (LogicGamePlayUtil.GetNearestValidAttackPos(this.m_parent.GetLevel(), posX, posY, out int outputX, out int outputY)) { character.SetInitialPosition(outputX, outputY); } else { character.SetInitialPosition(posX, posY); } } else { character.SetInitialPosition(this.m_parent.GetX() + (this.m_parent.GetWidthInTiles() << 9) - 128, this.m_parent.GetY() + (this.m_parent.GetHeightInTiles() << 8)); } this.m_parent.GetGameObjectManager().AddGameObject(character, -1); } this.m_bunkerSearchTime = LogicDataTables.GetGlobals().GetBunkerSearchTime(); } } }