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(); } } }
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(); } } } }