public static LogicCharacter PlaceHero(LogicHeroData data, LogicLevel level, int x, int y, int hitpoints, int upgLevel) { LogicCharacter character = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(data, level, level.GetVillageType()); character.SetUpgradeLevel(upgLevel); character.GetHitpointComponent().SetHitpoints(hitpoints); character.SetInitialPosition(x, y); if (data.IsJumper()) { character.GetMovementComponent().EnableJump(3600000); character.GetCombatComponent().RefreshTarget(true); } level.GetGameObjectManager().AddGameObject(character, -1); level.GetGameListener().AttackerPlaced(data); LogicBattleLog battleLog = level.GetBattleLog(); if (battleLog != null) { battleLog.IncrementDeployedAttackerUnits(data, 1); battleLog.SetCombatItemLevel(data, upgLevel); } return(character); }
public void SetTeam(int team) { this.m_team = team; if (team != 0) { if (this.m_parent.GetGameObjectType() == LogicGameObjectType.CHARACTER) { LogicCharacter character = (LogicCharacter)this.m_parent; LogicCombatComponent combatComponent = character.GetCombatComponent(); if (combatComponent != null) { if (character.GetCharacterData().IsUnderground()) { combatComponent.SetUndergroundTime(0); } LogicMovementComponent movementComponent = character.GetMovementComponent(); if (movementComponent != null) { movementComponent.SetUnderground(false); } } } } }
public void AddDefendingHero() { LogicAvatar visitorAvatar = this.m_parent.GetLevel().GetVisitorAvatar(); LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar(); int randomPatrolPoint = visitorAvatar != null ? (int)(((visitorAvatar.GetResourceCount(LogicDataTables.GetGoldData()) + 10 * this.m_hero.GetGlobalID()) & 0x7FFFFFFFu) % this.m_patrolPath.Size()) : 0; int upgLevel = homeOwnerAvatar.GetUnitUpgradeLevel(this.m_hero); int heroHitpoints = this.m_hero.GetHeroHitpoints(homeOwnerAvatar.GetHeroHealth(this.m_hero), upgLevel); if (this.m_hero.HasEnoughHealthForAttack(heroHitpoints, upgLevel)) { LogicVector2 patrolPoint = this.m_patrolPath[randomPatrolPoint]; LogicCharacter hero = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(this.m_hero, this.m_parent.GetLevel(), this.m_parent.GetVillageType()); hero.GetMovementComponent().SetBaseBuilding((LogicBuilding)this.m_parent); hero.GetHitpointComponent().SetTeam(1); hero.SetUpgradeLevel(upgLevel); hero.GetHitpointComponent().SetHitpoints(heroHitpoints); hero.SetInitialPosition(patrolPoint.m_x, patrolPoint.m_y); this.m_parent.GetGameObjectManager().AddGameObject(hero, -1); hero.GetCombatComponent().SetSearchRadius(this.m_hero.GetMaxSearchRadiusForDefender() / 512); if (LogicDataTables.GetGlobals().EnableDefendingAllianceTroopJump()) { hero.GetMovementComponent().EnableJump(3600000); } } }
/// <summary> /// Executes this instance. /// </summary> public override int Execute(LogicLevel level) { if (true) { int tileX = this._x >> 9; int tileY = this._y >> 9; if (level.GetTileMap().GetTile(tileX, tileY) != null) { // if (level.GetTileMap().IsPassablePathFinder(this._x >> 8, this._y >> 8)) { if (level.GetTileMap().IsValidAttackPos(tileX, tileY)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar != null) { int unitCount = level.GetVillageType() == 1 ? playerAvatar.GetUnitCountVillage2(this._data) : playerAvatar.GetUnitCount(this._data); if (unitCount > 0) { if (level.GetBattleLog() != null) { // ? } if (level.GetGameMode().IsInAttackPreparationMode()) { level.GetGameMode().EndAttackPreparation(); } LogicCharacter character = LogicPlaceAttackerCommand.PlaceAttacker(playerAvatar, this._data, level, this._x, this._y); if (character != null) { // TODO: Finish this. } return(0); } return(-7); } return(-5); } return(-4); } // return -2; } return(-3); } return(-1); }
public void UpdateHeroHealthToAvatar(int hitpoint) { LogicAvatar avatar = this.m_team == 1 ? this.m_parent.GetLevel().GetHomeOwnerAvatar() : this.m_parent.GetLevel().GetVisitorAvatar(); LogicHeroData data = null; int upgLevel = 0; if (this.m_parent.IsHero()) { LogicCharacter character = (LogicCharacter)this.m_parent; data = (LogicHeroData)character.GetCharacterData(); upgLevel = character.GetUpgradeLevel(); } else if (this.m_parent.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)this.m_parent; LogicHeroBaseComponent heroBaseComponent = building.GetHeroBaseComponent(); if (heroBaseComponent == null) { return; } LogicBuildingData buildingData = building.GetBuildingData(); if (!buildingData.GetShareHeroCombatData()) { return; } LogicCombatComponent combatComponent = building.GetCombatComponent(); if (combatComponent == null || !combatComponent.IsEnabled()) { return; } data = buildingData.GetHeroData(); upgLevel = avatar.GetUnitUpgradeLevel(data); } if (data != null) { int secs = LogicMath.Min(data.GetSecondsToFullHealth(hitpoint, upgLevel), data.GetFullRegenerationTimeSec(upgLevel)); if (avatar != null) { avatar.GetChangeListener().CommodityCountChanged(0, data, secs); avatar.SetHeroHealth(data, secs); } } }
public void UpdatePushBack() { int startSpeed = this.m_pushTime * this.m_pushTime / this.m_pushInitTime; int endSpeed = this.m_pushInitTime - startSpeed; int pushBackX = (startSpeed * this.m_pushBackStartPosition.m_x + endSpeed * this.m_pushBackEndPosition.m_x) / this.m_pushInitTime; int pushBackY = (startSpeed * this.m_pushBackStartPosition.m_y + endSpeed * this.m_pushBackEndPosition.m_y) / this.m_pushInitTime; if (this.m_parent == null || this.m_parent.IsFlying() || this.m_parent.GetParent().GetLevel().GetTileMap().IsPassablePathFinder(pushBackX >> 8, pushBackY >> 8) || this.m_ignorePush) { this.SetPosition(pushBackX, pushBackY); } else { this.m_pushBackStartPosition.m_x = this.m_position.m_x; this.m_pushBackStartPosition.m_y = this.m_position.m_y; this.m_pushBackEndPosition.m_x = this.m_position.m_x; this.m_pushBackEndPosition.m_y = this.m_position.m_y; } this.m_pushTime = LogicMath.Max(this.m_pushTime - 16, 0); if (this.m_pushTime == 0) { LogicGameObject parent = this.m_parent.GetParent(); LogicCombatComponent combatComponent = parent.GetCombatComponent(); if (parent.GetGameObjectType() == LogicGameObjectType.CHARACTER) { LogicCharacter character = (LogicCharacter)parent; if (character.GetCharacterData().GetPickNewTargetAfterPushback() || this.m_ignorePush) { if (combatComponent != null) { combatComponent.ForceNewTarget(); } } } this.m_parent.NewTargetFound(); if (combatComponent != null) { combatComponent.StopAttack(); } this.m_ignorePush = false; } }
public override void Tick() { if (this.m_triggeredByRadius) { LogicLevel level = this.m_parent.GetLevel(); if (level.IsInCombatState()) { if (!this.m_triggered) { if (((level.GetLogicTime().GetTick() / 4) & 7) == 0) { LogicArrayList <LogicComponent> components = this.m_parent.GetComponentManager().GetComponents(LogicComponentType.MOVEMENT); for (int i = 0; i < components.Size(); i++) { LogicGameObject gameObject = components[i].GetParent(); if (gameObject.GetGameObjectType() == LogicGameObjectType.CHARACTER) { LogicCharacter character = (LogicCharacter)gameObject; LogicMovementComponent movementComponent = character.GetMovementComponent(); bool triggerDisabled = false; if (movementComponent != null) { LogicMovementSystem movementSystem = movementComponent.GetMovementSystem(); if (movementSystem != null && movementSystem.IsPushed()) { triggerDisabled = movementSystem.IgnorePush(); } } if (!triggerDisabled && character.GetCharacterData().GetTriggersTraps()) { this.ObjectClose(character); } } } } } } } }
private void SpawnCharacter(int x, int y) { int idx = this.m_defenceTroopCount % 2; if (this.m_defenceTroopData[idx] == null) { idx = 0; } LogicBuilding building = (LogicBuilding)this.m_parent; LogicBuildingData buildingData = building.GetBuildingData(); if (buildingData.IsEnabledInVillageType(this.m_parent.GetLevel().GetVillageType()) && this.m_parent.GetLevel().GetState() != 1 && this.m_parent.GetLevel().GetState() != 4) { LogicCharacterData data = this.m_defenceTroopData[idx]; LogicCharacter character = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(data, this.m_parent.GetLevel(), this.m_parent.GetVillageType()); character.SetInitialPosition(x, y); character.SetUpgradeLevel(this.m_defenceTroopUpgradeLevel - 1); character.GetHitpointComponent()?.SetTeam(1); if (LogicDataTables.GetGlobals().EnableDefendingAllianceTroopJump()) { character.GetMovementComponent().EnableJump(3600000); } this.m_parent.GetGameObjectManager().AddGameObject(character, -1); character.GetCombatComponent().SetSearchRadius(LogicDataTables.GetGlobals().GetClanCastleRadius() >> 9); character.GetMovementComponent().GetMovementSystem().CreatePatrolArea(this.m_parent, this.m_parent.GetLevel(), true, this.m_defenceTroopCount); LogicDefenceUnitProductionComponent defenceUnitProductionComponent = building.GetDefenceUnitProduction(); if (defenceUnitProductionComponent != null) { defenceUnitProductionComponent.m_defenceTroops.Add(character); } ++this.m_defenceTroopCount; } }
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); }
public override int Execute(LogicLevel level) { LogicArrayList <LogicGameObject> gameObjects = level.GetGameObjectManager().GetGameObjects(LogicGameObjectType.CHARACTER); for (int i = 0; i < gameObjects.Size(); i++) { LogicCharacter character = (LogicCharacter)gameObjects[i]; if (character.GetHitpointComponent().GetTeam() == 0 && character.IsHero() && character.GetData() == this.m_data && character.GetHitpointComponent().GetHitpoints() > 0) { if (this.m_data.HasAbility(character.GetUpgradeLevel())) { if (!this.m_data.HasOnceAbility() && character.GetAbilityCooldown() == 0 || this.m_data.HasOnceAbility() && !character.IsAbilityUsed()) { character.StartAbility(); } } } } return(0); }
/// <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); }
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 LogicCharacter ClosestAttacker(bool flyingTroop) { LogicGameObjectManager gameObjectManager = this.m_parent.GetLevel().GetGameObjectManagerAt(0); LogicArrayList <LogicGameObject> gameObjects = gameObjectManager.GetGameObjects(LogicGameObjectType.CHARACTER); int closestDistance = 0x7fffffff; LogicCharacter closestCharacter = null; for (int i = 0; i < gameObjects.Size(); i++) { LogicCharacter character = (LogicCharacter)gameObjects[i]; LogicHitpointComponent hitpointComponent = character.GetHitpointComponent(); LogicCombatComponent combatComponent = character.GetCombatComponent(); bool deployTime = combatComponent != null && combatComponent.GetUndergroundTime() > 0; if (!deployTime && (LogicDataTables.GetGlobals().SkeletonOpenClanCastle() || !LogicDataTables.IsSkeleton(character.GetCharacterData()))) { if (hitpointComponent != null) { if (character.IsAlive() && character.IsFlying() == flyingTroop && hitpointComponent.GetTeam() == 0) { int distance = character.GetPosition().GetDistanceSquaredTo(this.m_parent.GetMidX(), this.m_parent.GetMidY()); if (distance < closestDistance) { closestDistance = distance; closestCharacter = character; } } } } } return(closestCharacter); }
/// <summary> /// Places one unit. /// </summary> public bool PlaceOneUnit() { if (this._placePositionX == -1 && this._placePositionY == -1) { int widthArea = this._level.GetPlayArea().GetStartX(); int width = this._level.GetWidthInTiles(); if (width > 0) { int tileIdx = -1; int tmp = width / 2; for (int x = 0; x < width; x++) { if (widthArea >= 2) { int middleX = (widthArea - 1) / 2; int square = (tmp - x) * (tmp - x); for (int y = 0; y != widthArea - 1; y++, middleX--) { if (tileIdx == -1 || square + middleX * middleX < tileIdx) { if (this._level.GetTileMap().GetTile(x, y).GetPassableFlag() == 1) { this._placePositionX = x; this._placePositionY = y; tileIdx = square + middleX * middleX; } } } } } } } if (this._placePositionX == -1 && this._placePositionY == -1) { Debugger.Error("LogicNpcAttack::placeOneUnit - No attack position found!"); } else { LogicArrayList <LogicDataSlot> units = this._npcAvatar.GetUnits(); for (int i = 0; i < units.Count; i++) { LogicDataSlot slot = units[i]; if (slot.GetCount() > 0) { slot.SetCount(slot.GetCount() - 1); LogicCharacter character = LogicPlaceAttackerCommand.PlaceAttacker(this._npcAvatar, (LogicCharacterData)slot.GetData(), this._level, this._placePositionX, this._placePositionY); if (!this._unitsDeployed) { character.GetListener().MapUnlocked(); } // character.GetCombatComponent().SetPreferredTarget(this._buildingClass, 100, 0); this._unitsDeployed = true; return(true); } } } return(false); }
private void SimulateEndAttackState() { LogicLevel level = this.m_logicGameMode.GetLevel(); LogicGameObjectManager gameObjectManager = level.GetGameObjectManager(); LogicArrayList <LogicGameObject> characterList = gameObjectManager.GetGameObjects(LogicGameObjectType.CHARACTER); LogicArrayList <LogicGameObject> projectileList = gameObjectManager.GetGameObjects(LogicGameObjectType.PROJECTILE); LogicArrayList <LogicGameObject> spellList = gameObjectManager.GetGameObjects(LogicGameObjectType.SPELL); LogicArrayList <LogicGameObject> alliancePortalList = gameObjectManager.GetGameObjects(LogicGameObjectType.ALLIANCE_PORTAL); this.m_logicWatch.Start(); while (!this.m_logicGameMode.IsBattleOver()) { bool canStopBattle = !this.m_logicGameMode.GetConfiguration().GetBattleWaitForProjectileDestruction() || projectileList.Size() == 0; for (int i = 0; i < characterList.Size(); i++) { LogicCharacter character = (LogicCharacter)characterList[i]; LogicHitpointComponent hitpointComponent = character.GetHitpointComponent(); if (hitpointComponent != null && hitpointComponent.GetTeam() == 0) { LogicAttackerItemData data = character.GetAttackerItemData(); if (data.GetDamage(0, false) > 0 && (hitpointComponent.GetHitpoints() > 0 || this.m_logicGameMode.GetConfiguration().GetBattleWaitForDieDamage() && character.GetWaitDieDamage())) { canStopBattle = false; } } } for (int i = 0; i < spellList.Size(); i++) { LogicSpell spell = (LogicSpell)spellList[i]; if (!spell.GetHitsCompleted() && (spell.GetSpellData().IsDamageSpell() || spell.GetSpellData().GetSummonTroop() != null)) { canStopBattle = false; } } for (int i = 0; i < alliancePortalList.Size(); i++) { LogicAlliancePortal alliancePortal = (LogicAlliancePortal)alliancePortalList[i]; if (alliancePortal.GetBunkerComponent().GetTeam() == 0 && !alliancePortal.GetBunkerComponent().IsEmpty()) { canStopBattle = false; } } bool isEnded = canStopBattle || this.m_logicWatch.ElapsedMilliseconds >= 10000; if (isEnded) { LogicEndCombatCommand logicEndCombatCommand = new LogicEndCombatCommand(); logicEndCombatCommand.SetExecuteSubTick(this.m_logicGameMode.GetLevel().GetLogicTime().GetTick()); this.m_logicGameMode.GetCommandManager().AddCommand(logicEndCombatCommand); } this.m_logicGameMode.UpdateOneSubTick(); if (isEnded) { break; } } this.m_logicWatch.Reset(); if (!this.m_logicGameMode.IsBattleOver()) { this.m_logicGameMode.SetBattleOver(); } if (this.m_liveReplayId != null) { this.UpdateLiveReplay(this.m_logicGameMode.GetLevel().GetLogicTime().GetTick(), null); } }
public bool PlaceOneUnit() { if (this.m_placePositionX == -1 && this.m_placePositionY == -1) { int startAreaY = this.m_level.GetPlayArea().GetStartY(); int widthInTiles = this.m_level.GetWidthInTiles(); int minDistance = -1; for (int i = 0; i < widthInTiles; i++) { int centerY = (startAreaY - 1) / 2; for (int j = 0; j < startAreaY - 1; j++, centerY--) { int distance = ((widthInTiles >> 1) - i) * ((widthInTiles >> 1) - i) + centerY * centerY; if (minDistance == -1 || distance < minDistance) { LogicTile tile = this.m_level.GetTileMap().GetTile(i, j); if (tile.GetPassableFlag() != 0) { this.m_placePositionX = i; this.m_placePositionY = j; minDistance = distance; } } } } } if (this.m_placePositionX == -1 && this.m_placePositionY == -1) { Debugger.Error("LogicNpcAttack::placeOneUnit - No attack position found!"); } else { LogicArrayList <LogicDataSlot> units = this.m_npcAvatar.GetUnits(); for (int i = 0; i < units.Size(); i++) { LogicDataSlot slot = units[i]; if (slot.GetCount() > 0) { LogicCharacter character = LogicPlaceAttackerCommand.PlaceAttacker(this.m_npcAvatar, (LogicCharacterData)slot.GetData(), this.m_level, this.m_placePositionX << 9, this.m_placePositionY << 9); if (!this.m_unitsDeployStarted) { character.GetListener().MapUnlocked(); } character.GetCombatComponent().SetPreferredTarget(this.m_buildingClass, 100, false); this.m_unitsDeployStarted = true; return(true); } } } return(false); }
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 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 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 override int Execute(LogicLevel level) { if (level.IsReadyForAttack()) { int tileX = this.m_x >> 9; int tileY = this.m_y >> 9; if (level.GetTileMap().GetTile(tileX, tileY) != null) { if (level.GetTileMap().IsPassablePathFinder(this.m_x >> 8, this.m_y >> 8)) { if (level.GetTileMap().IsValidAttackPos(tileX, tileY)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar != null) { int unitCount = level.GetVillageType() == 1 ? playerAvatar.GetUnitCountVillage2(this.m_data) : playerAvatar.GetUnitCount(this.m_data); if (unitCount > 0) { if (level.GetBattleLog() != null) { if (!level.GetBattleLog().HasDeployedUnits() && level.GetTotalAttackerHeroPlaced() == 0) { level.UpdateLastUsedArmy(); } } if (level.GetGameMode().IsInAttackPreparationMode()) { level.GetGameMode().EndAttackPreparation(); } LogicCharacter character = LogicPlaceAttackerCommand.PlaceAttacker(playerAvatar, this.m_data, level, this.m_x, this.m_y); if (character != null && character.HasSpecialAbility()) { if (this.m_data.GetSpecialAbilityType() == LogicCharacterData.SPECIAL_ABILITY_TYPE_START_RAGE) { LogicSpellData specialAbilitySpellData = this.m_data.GetSpecialAbilitySpell(); level.BoostGameObject(character, specialAbilitySpellData.GetSpeedBoost(0), specialAbilitySpellData.GetSpeedBoost2(0), specialAbilitySpellData.GetDamageBoostPercent(0), specialAbilitySpellData.GetAttackSpeedBoost(0), 60 * this.m_data.GetSpecialAbilityAttribute(character.GetUpgradeLevel()), specialAbilitySpellData.GetBoostLinkedToPoison()); } else if (this.m_data.GetSpecialAbilityType() == LogicCharacterData.SPECIAL_ABILITY_TYPE_START_CLOAK) { character.SetStealthTime(15 * this.m_data.GetSpecialAbilityAttribute(character.GetUpgradeLevel())); } } return(0); } return(-7); } return(-5); } return(-4); } return(-2); } return(-3); } return(-1); }