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