public int GetMaxMiniSpellForgeLevel() { LogicArrayList <LogicComponent> components = this.m_components[(int)LogicComponentType.UNIT_PRODUCTION]; if (components.Size() > 0) { int maxUpgLevel = -1; int idx = 0; do { LogicUnitProductionComponent component = (LogicUnitProductionComponent)components[idx]; if (component.GetProductionType() != 0) { if (component.GetParent().GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding parent = (LogicBuilding)component.GetParent(); if (parent.GetBuildingData().GetProducesUnitsOfType() == 2 && (!parent.IsConstructing() || parent.IsUpgrading())) { maxUpgLevel = LogicMath.Max(parent.GetUpgradeLevel(), maxUpgLevel); } } } } while (++idx != components.Size()); return(maxUpgLevel); } return(-1); }
private static LogicArrayList <T> GetRankingList <T>(LogicArrayList <T> fullContent, LogicLong clientId) where T : RankingEntry { LogicArrayList <T> rankingList = new LogicArrayList <T>(ScoringManager.CLIENT_RANKING_LIST_SIZE); if (fullContent != null) { for (int i = 0, c = LogicMath.Min(fullContent.Size(), ScoringManager.CLIENT_RANKING_LIST_SIZE); i < c; i++) { rankingList.Add(fullContent[i]); } for (int i = ScoringManager.CLIENT_RANKING_LIST_SIZE; i < fullContent.Size(); i++) { if (fullContent[i].GetId().Equals(clientId)) { if (i > 0) { rankingList.Add(fullContent[i - 1]); } rankingList.Add(fullContent[i]); if (i + 1 < fullContent.Size()) { rankingList.Add(fullContent[i + 1]); } break; } } } return(rankingList); }
public void CalculateLoot(bool includeStorage) { if (includeStorage) { LogicArrayList <LogicComponent> resourceStorageComponents = this.m_components[(int)LogicComponentType.RESOURCE_STORAGE]; for (int i = 0; i < resourceStorageComponents.Size(); i++) { ((LogicResourceStorageComponent)resourceStorageComponents[i]).RecalculateAvailableLoot(); } } LogicArrayList <LogicComponent> resourceProductionComponents = this.m_components[(int)LogicComponentType.RESOURCE_PRODUCTION]; for (int i = 0; i < resourceProductionComponents.Size(); i++) { ((LogicResourceProductionComponent)resourceProductionComponents[i]).RecalculateAvailableLoot(); } LogicArrayList <LogicComponent> warResourceStorageComponents = this.m_components[(int)LogicComponentType.WAR_RESOURCE_STORAGE]; Debugger.DoAssert(warResourceStorageComponents.Size() < 2, "Too many war storage components"); for (int i = 0; i < warResourceStorageComponents.Size(); i++) { ((LogicWarResourceStorageComponent)warResourceStorageComponents[i]).RecalculateAvailableLoot(); } }
private void CalculateDuelRanking() { LogicArrayList <AllianceMemberEntry> arrayList = new LogicArrayList <AllianceMemberEntry>(this.Members.Count); foreach (AllianceMemberEntry member in this.Members.Values) { int idx = -1; for (int i = 0; i < arrayList.Size(); i++) { if (member.GetDuelScore() > arrayList[i].GetDuelScore()) { idx = i; break; } } arrayList.Add(idx == -1 ? arrayList.Size() : idx, member); } for (int i = 0; i < arrayList.Size(); i++) { arrayList[i].SetOrderVillage2(i + 1); if (arrayList[i].GetPreviousOrderVillage2() == 0) { arrayList[i].SetPreviousOrderVillage2(i + 1); } } }
protected sealed override void Encode(ByteStream stream) { for (int i = 0; i < 2; i++) { LogicArrayList <AllianceRankingEntry> allianceRankingList = this.AllianceRankingList[i]; stream.WriteVInt(allianceRankingList.Size()); for (int j = 0; j < allianceRankingList.Size(); j++) { allianceRankingList[j].Encode(stream); } } stream.WriteVInt(this.AvatarRankingList.Size()); for (int i = 0; i < this.AvatarRankingList.Size(); i++) { this.AvatarRankingList[i].Encode(stream); } stream.WriteVInt(this.AvatarDuelRankingList.Size()); for (int i = 0; i < this.AvatarDuelRankingList.Size(); i++) { this.AvatarDuelRankingList[i].Encode(stream); } }
public static async Task <LogicArrayList <AllianceHeaderEntry> > GetAllianceHeaderList(LogicArrayList <LogicLong> ids) { LogicArrayList <AllianceHeaderEntry> allianceList = new LogicArrayList <AllianceHeaderEntry>(ids.Size()); Task <IOperationResult <string> >[] results = new Task <IOperationResult <string> > [ids.Size()]; for (int i = 0; i < ids.Size(); i++) { results[i] = ServerSearch.AllianceDatabase.Get(ids[i]); } for (int i = 0; i < ids.Size(); i++) { IOperationResult <string> result = await results[i]; if (result.Success) { LogicJSONObject jsonObject = LogicJSONParser.ParseObject(result.Value); AllianceHeaderEntry allianceHeaderEntry = new AllianceHeaderEntry(); allianceHeaderEntry.Load(jsonObject); allianceHeaderEntry.SetAllianceId(new LogicLong(jsonObject.GetJSONNumber(CouchbaseDocument.JSON_ATTRIBUTE_ID_HIGH).GetIntValue(), jsonObject.GetJSONNumber(CouchbaseDocument.JSON_ATTRIBUTE_ID_LOW).GetIntValue())); allianceList.Add(allianceHeaderEntry); } } return(allianceList); }
public override int Execute(LogicLevel level) { LogicArrayList <LogicComponent> components = level.GetComponentManager().GetComponents(LogicComponentType.VILLAGE2_UNIT); int remainingSecs = 0; for (int i = 0; i < components.Size(); i++) { remainingSecs += ((LogicVillage2UnitComponent)components[i]).GetRemainingSecs(); } LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); int speedUpCost = LogicGamePlayUtil.GetSpeedUpCost(remainingSecs, 4, 1); if (!playerAvatar.HasEnoughDiamonds(speedUpCost, true, level)) { return(-1); } playerAvatar.UseDiamonds(speedUpCost); for (int i = 0; i < components.Size(); i++) { LogicVillage2UnitComponent component = (LogicVillage2UnitComponent)components[i]; if (component.GetCurrentlyTrainedUnit() != null && component.GetRemainingSecs() > 0) { component.ProductionCompleted(); } } playerAvatar.GetChangeListener().DiamondPurchaseMade(16, 0, 0, speedUpCost, 1); return(0); }
private void SortProduction(LogicArrayList <LogicCombatItemData> arrayList) { for (int i = 0; i < arrayList.Size(); i++) { bool change = false; for (int j = 0; j < arrayList.Size() - 1; j++) { LogicCombatItemData data = arrayList[j]; LogicCombatItemData nextData = arrayList[j + 1]; int sort1 = data.GetRequiredProductionHouseLevel() + 100 * data.GetUnitOfType() + 500 * data.GetCombatItemType(); int sort2 = nextData.GetRequiredProductionHouseLevel() + 100 * nextData.GetUnitOfType() + 500 * nextData.GetCombatItemType(); if (sort1 > sort2) { arrayList[j] = nextData; arrayList[j + 1] = data; change = true; } } if (!change) { break; } } }
public override int Execute(LogicLevel level) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (level.GetVillageType() == 1) { LogicGameMode gameMode = level.GetGameMode(); if (!gameMode.IsInAttackPreparationMode()) { if (gameMode.GetState() != 5) { return(-9); } } if (this.m_oldUnitData != null && this.m_newUnitData != null && gameMode.GetCalendar().IsProductionEnabled(this.m_newUnitData)) { if (!this.m_newUnitData.IsUnlockedForBarrackLevel(playerAvatar.GetVillage2BarrackLevel())) { if (gameMode.GetState() != 7) { return(-7); } } int oldUnitCount = playerAvatar.GetUnitCountVillage2(this.m_oldUnitData); int oldUnitsInCamp = this.m_oldUnitData.GetUnitsInCamp(playerAvatar.GetUnitUpgradeLevel(this.m_oldUnitData)); if (oldUnitCount >= oldUnitsInCamp) { int newUnitCount = playerAvatar.GetUnitCountVillage2(this.m_newUnitData); int newUnitsInCamp = this.m_newUnitData.GetUnitsInCamp(playerAvatar.GetUnitUpgradeLevel(this.m_newUnitData)); playerAvatar.SetUnitCountVillage2(this.m_oldUnitData, oldUnitCount - oldUnitsInCamp); playerAvatar.SetUnitCountVillage2(this.m_newUnitData, newUnitCount + newUnitsInCamp); LogicArrayList <LogicDataSlot> unitsNew = playerAvatar.GetUnitsNewVillage2(); for (int i = 0; i < unitsNew.Size(); i++) { LogicDataSlot slot = unitsNew[i]; if (slot.GetCount() > 0) { playerAvatar.CommodityCountChangeHelper(8, slot.GetData(), -slot.GetCount()); } } return(0); } return(-23); } return(-7); } return(-10); }
public static void AddDonation(LogicArrayList <DonationContainer> arrayList, LogicLong avatarId, LogicCombatItemData data, int upgLevel) { Debugger.DoAssert(arrayList != null, "pDonations cannot be null"); int index = -1; for (int i = 0; i < arrayList.Size(); i++) { if (LogicLong.Equals(arrayList[i].GetAvatarId(), avatarId)) { index = i; break; } } if (index != -1) { arrayList[index].AddUnit(data, upgLevel); } else { DonationContainer donationContainer = new DonationContainer(avatarId.Clone()); donationContainer.AddUnit(data, upgLevel); arrayList.Add(donationContainer); } }
public static void LoadDebugJSON(LogicLevel level, string json) { LogicJSONObject jsonObject = LogicJSONParser.ParseObject(json); if (jsonObject != null) { LogicArrayList <LogicComponent> unitStorageComponents = level.GetComponentManager().GetComponents(LogicComponentType.UNIT_STORAGE); for (int i = 0; i < unitStorageComponents.Size(); i++) { ((LogicUnitStorageComponent)unitStorageComponents[i]).RemoveAllUnits(); } level.SetLoadingVillageType(0); LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("buildings"), LogicGameObjectType.BUILDING, 0); LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("obstacles"), LogicGameObjectType.OBSTACLE, 0); LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("traps"), LogicGameObjectType.TRAP, 0); LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("decos"), LogicGameObjectType.DECO, 0); level.SetLoadingVillageType(1); LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("buildings2"), LogicGameObjectType.BUILDING, 1); LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("obstacles2"), LogicGameObjectType.OBSTACLE, 1); LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("traps2"), LogicGameObjectType.TRAP, 1); LogicDebugUtil.LoadDebugJSONArray(level, jsonObject.GetJSONArray("decos2"), LogicGameObjectType.DECO, 1); level.SetLoadingVillageType(-1); } }
private static void OnSendAvatarStreamsToClientMessageReceived(SendAvatarStreamsToClientMessage message) { AvatarStreamMessage avatarStreamMessage = new AvatarStreamMessage(); LogicArrayList <LogicLong> ids = message.StreamIds; LogicArrayList <AvatarStreamEntry> avatarStreamList = new LogicArrayList <AvatarStreamEntry>(ids.Size()); for (int i = 0; i < ids.Size(); i++) { AvatarStreamEntry avatarStreamEntry = StreamManager.GetAvatarStream(ids[i]); if (avatarStreamEntry != null) { avatarStreamList.Add(avatarStreamEntry); } } avatarStreamMessage.SetStreamEntries(avatarStreamList); avatarStreamMessage.Encode(); ServerMessageManager.SendMessage(StreamMessageManager.CreateForwardLogicMessage(avatarStreamMessage, message.SessionId), ServerManager.GetProxySocket(message.SessionId)); for (int i = 0; i < avatarStreamList.Size(); i++) { AvatarStreamEntry avatarStreamEntry = avatarStreamList[i]; if (avatarStreamEntry.IsNew()) { avatarStreamEntry.SetNew(false); StreamManager.Save(avatarStreamEntry); } } }
protected sealed override void Save(LogicJSONObject jsonObject) { LogicJSONArray allianceRankingListArray = new LogicJSONArray(2); LogicJSONArray avatarRankingArray = new LogicJSONArray(SeasonDocument.RANKING_LIST_SIZE); LogicJSONArray avatarDuelRankingArray = new LogicJSONArray(SeasonDocument.RANKING_LIST_SIZE); for (int i = 0; i < 2; i++) { LogicJSONArray allianceRankingArray = new LogicJSONArray(SeasonDocument.RANKING_LIST_SIZE); LogicArrayList <AllianceRankingEntry> allianceRankingList = this.AllianceRankingList[i]; for (int j = 0; j < allianceRankingList.Size(); j++) { allianceRankingArray.Add(allianceRankingList[j].Save()); } allianceRankingListArray.Add(allianceRankingArray); } for (int i = 0; i < this.AvatarRankingList.Size(); i++) { avatarRankingArray.Add(this.AvatarRankingList[i].Save()); } for (int i = 0; i < this.AvatarDuelRankingList.Size(); i++) { avatarDuelRankingArray.Add(this.AvatarDuelRankingList[i].Save()); } jsonObject.Put(SeasonDocument.JSON_ATTRIBUTE_ALLIANCE_RANKINGS, allianceRankingListArray); jsonObject.Put(SeasonDocument.JSON_ATTRIBUTE_AVATAR_RANKINGS, avatarRankingArray); jsonObject.Put(SeasonDocument.JSON_ATTRIBUTE_AVATAR_DUEL_RANKINGS, avatarDuelRankingArray); jsonObject.Put(SeasonDocument.JSON_ATTRIBUTE_NEXT_CHECK_TIME, new LogicJSONString(this.NextCheckTime.ToString("O"))); }
public void SetMaxPercentageArray(LogicArrayList <int> max) { for (int i = 0; i < max.Size(); i++) { this.m_maxPercentageResourceCount[i] = max[i]; } }
public LogicComponent GetClosestComponent(int x, int y, LogicComponentFilter filter) { LogicArrayList <LogicComponent> components = this.m_components[(int)filter.GetComponentType()]; LogicComponent closestComponent = null; int closestDistance = 0; for (int i = 0, size = components.Size(); i < size; i++) { LogicComponent component = components[i]; if (filter.TestComponent(component)) { int distance = component.GetParent().GetPosition().GetDistanceSquaredTo(x, y); if (distance < closestDistance || closestComponent == null) { closestDistance = distance; closestComponent = component; } } } return(closestComponent); }
public static LogicJSONArray DataSlotArrayToJSONArray(LogicArrayList <LogicDataSlot> dataSlotArray) { LogicJSONArray jsonArray = new LogicJSONArray(dataSlotArray.Size()); for (int i = 0; i < dataSlotArray.Size(); i++) { LogicDataSlot dataSlot = dataSlotArray[i]; LogicJSONArray objectArray = new LogicJSONArray(); objectArray.Add(new LogicJSONNumber(dataSlot.GetData().GetGlobalID())); objectArray.Add(new LogicJSONNumber(dataSlot.GetCount())); jsonArray.Add(objectArray); } return(jsonArray); }
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); } } } } }
public void CreateProjectile(LogicProjectileData data) { LogicTrapData trapData = this.GetTrapData(); LogicVector2 position = new LogicVector2(); LogicArrayList <LogicGameObject> characters = this.GetGameObjectManager().GetGameObjects(LogicGameObjectType.CHARACTER); LogicGameObject closestGameObject = null; for (int i = 0, minDistance = 0; i < characters.Size(); i++) { LogicCharacter character = (LogicCharacter)characters[i]; LogicHitpointComponent hitpointComponent = character.GetHitpointComponent(); if (hitpointComponent != null && hitpointComponent.GetTeam() == 0) { if (character.IsFlying() && character.IsAlive()) { int housingSpace = character.GetCharacterData().GetHousingSpace(); if (housingSpace >= trapData.GetMinTriggerHousingLimit() && character.GetChildTroops() == null) { if (trapData.GetHealerTrigger() || character.GetCombatComponent() == null || !character.GetCombatComponent().IsHealer()) { position.m_x = character.GetPosition().m_x - this.GetMidX(); position.m_y = character.GetPosition().m_y - this.GetMidY(); int lengthSquared = position.GetLengthSquared(); if (minDistance == 0 || lengthSquared < minDistance) { minDistance = lengthSquared; closestGameObject = character; } } } } } } position.Destruct(); if (closestGameObject != null) { LogicProjectile projectile = (LogicProjectile)LogicGameObjectFactory.CreateGameObject(data, this.m_level, this.m_villageType); projectile.SetInitialPosition(null, this.GetMidX(), this.GetMidY()); projectile.SetTarget(this.GetMidX(), this.GetMidY(), 0, closestGameObject, data.GetRandomHitPosition()); projectile.SetDamage(trapData.GetDamage(this.m_upgLevel)); projectile.SetDamageRadius(trapData.GetDamageRadius(this.m_upgLevel)); projectile.SetPushBack(trapData.GetPushback(), !trapData.GetDoNotScalePushByDamage()); projectile.SetMyTeam(1); projectile.SetHitEffect(trapData.GetDamageEffect(), null); this.GetGameObjectManager().AddGameObject(projectile, -1); } }
public void SetMaxArray(LogicArrayList <int> max) { for (int i = 0; i < max.Size(); i++) { this.m_maxResourceCount[i] = max[i]; } this.m_parent.GetLevel().RefreshResourceCaps(); }
public void SetCapacityCount(LogicArrayList <int> count) { for (int i = 0; i < count.Size(); i++) { this.m_capCount[i] = count[i]; } this.m_parent.GetLevel().RefreshResourceCaps(); }
public override int Execute(LogicLevel level) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { if (gameObject.GetVillageType() == level.GetVillageType()) { LogicResourceProductionComponent resourceProductionComponent = gameObject.GetResourceProductionComponent(); if (resourceProductionComponent != null) { if (LogicDataTables.GetGlobals().CollectAllResourcesAtOnce()) { int baseAvailableResources = resourceProductionComponent.GetResourceCount(); int baseCollectedResources = resourceProductionComponent.CollectResources(true); bool storageIsFull = baseAvailableResources > 0 && baseCollectedResources == 0; LogicArrayList <LogicComponent> components = level.GetComponentManager().GetComponents(resourceProductionComponent.GetComponentType()); for (int i = 0; i < components.Size(); i++) { LogicResourceProductionComponent component = (LogicResourceProductionComponent)components[i]; if (resourceProductionComponent != component && resourceProductionComponent.GetResourceData() == component.GetResourceData()) { int availableResources = component.GetResourceCount(); int collectedResources = component.CollectResources(!storageIsFull); if (availableResources > 0) { if (collectedResources == 0) { storageIsFull = true; } } } } } else { resourceProductionComponent.CollectResources(true); } return(0); } return(-1); } return(-3); } return(-2); }
public void ApplyExtraHealthPermil(int x, int y, int radius, int team, int extraHealthPermil, int extraHealthMin, int extraHealthMax, int time, int targetType) { LogicArrayList <LogicComponent> components = this.GetComponentManager().GetComponents(LogicComponentType.HITPOINT); for (int i = 0; i < components.Size(); i++) { LogicHitpointComponent hitpointComponent = (LogicHitpointComponent)components[i]; LogicGameObject parent = hitpointComponent.GetParent(); if (!parent.IsHidden() && hitpointComponent.GetHitpoints() != 0 && hitpointComponent.GetTeam() == team) { LogicMovementComponent movementComponent = parent.GetMovementComponent(); if (movementComponent != null) { if (parent.GetGameObjectType() == LogicGameObjectType.CHARACTER) { LogicCharacter character = (LogicCharacter)parent; if (character.GetCharacterData().GetAuraSpell(character.GetUpgradeLevel()) == this.m_data) { continue; } } if (parent.IsFlying()) { if (targetType != 1) { continue; } } else if (targetType == 0) { continue; } int distanceX = x - parent.GetMidX(); int distanceY = y - parent.GetMidY(); if (LogicMath.Abs(distanceX) <= radius && LogicMath.Abs(distanceY) <= radius && distanceX * distanceX + distanceY * distanceY < (uint)(radius * radius)) { int hp = hitpointComponent.GetOriginalHitpoints() + LogicMath.Clamp(extraHealthPermil * hitpointComponent.GetOriginalHitpoints() / 1000, 100 * extraHealthMin, 100 * extraHealthMax); if (hp >= hitpointComponent.GetMaxHitpoints()) { hitpointComponent.SetExtraHealth(hp, time); } } } } } }
public static float GetAttackStrength(int townHallLevel, int castleUpgLevel, LogicArrayList <LogicHeroData> unlockedHeroes, int[] heroUpgLevel, LogicArrayList <LogicCharacterData> unlockedCharacters, int[] characterUpgLevel, int totalHousingSpace, LogicArrayList <LogicSpellData> unlockedSpells, int[] spellUpgLevel, int totalSpellHousingSpace) { float castleStrength = 0f; float heroStrength = 0f; float housingSpellStrength = 0f; float[] chStrengths = new float[unlockedCharacters.Size()]; if (castleUpgLevel > -1) { castleStrength = (castleUpgLevel + 1) * 10f * (castleUpgLevel >= 4 ? 4f : 2f); Debugger.HudPrint("(Attack Strength) Clan Castle: " + castleStrength); } for (int i = 0; i < unlockedHeroes.Size(); i++) { heroStrength += LogicStrengthUtil.GetHeroStrength(unlockedHeroes[i], heroUpgLevel[i], false); } for (int i = 0; i < unlockedCharacters.Size(); i++) { chStrengths[i] = LogicStrengthUtil.GetCharacterStrength(unlockedCharacters[i], characterUpgLevel[i]); } float housingCharacterStrength = LogicStrengthUtil.GetGlobalCharacterStrength(unlockedCharacters, chStrengths, townHallLevel); float characterStrength = totalHousingSpace * 0.01f * housingCharacterStrength; for (int i = 0; i < unlockedSpells.Size(); i++) { housingSpellStrength += LogicStrengthUtil.GetSpellStrength(unlockedSpells[i], spellUpgLevel[i]); } float spellStrength = totalSpellHousingSpace * 0.5f * housingSpellStrength; Debugger.HudPrint(string.Format("(Attack Strength) Heroes: {0}", heroStrength)); Debugger.HudPrint(string.Format("(Attack Strength) Troops: ({0} * {1} army capacity) {2}", housingCharacterStrength, totalHousingSpace, characterStrength)); Debugger.HudPrint(string.Format("(Attack Strength) Spells: ({0} * {1} spell capacity) {2}", housingSpellStrength, totalSpellHousingSpace, spellStrength)); return(castleStrength + heroStrength + characterStrength + spellStrength); }
private static LogicJSONArray SaveStringArray(LogicArrayList <string> arrayList) { LogicJSONArray jsonArray = new LogicJSONArray(); for (int i = 0; i < arrayList.Size(); i++) { jsonArray.Add(new LogicJSONString(arrayList[i])); } return(jsonArray); }
public static void LoadDebugJSONArray(LogicLevel level, LogicJSONArray jsonArray, LogicGameObjectType gameObjectType, int villageType) { if (jsonArray != null) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(villageType); LogicArrayList <LogicGameObject> prevGameObjects = new LogicArrayList <LogicGameObject>(); prevGameObjects.AddAll(gameObjectManager.GetGameObjects(gameObjectType)); for (int i = 0; i < prevGameObjects.Size(); i++) { gameObjectManager.RemoveGameObject(prevGameObjects[i]); } for (int i = 0; i < jsonArray.Size(); i++) { LogicJSONObject jsonObject = jsonArray.GetJSONObject(i); LogicJSONNumber dataNumber = jsonObject.GetJSONNumber("data"); LogicJSONNumber lvlNumber = jsonObject.GetJSONNumber("lvl"); LogicJSONBoolean lockedBoolean = jsonObject.GetJSONBoolean("locked"); LogicJSONNumber xNumber = jsonObject.GetJSONNumber("x"); LogicJSONNumber yNumber = jsonObject.GetJSONNumber("y"); if (dataNumber != null && xNumber != null && yNumber != null) { LogicGameObjectData data = (LogicGameObjectData)LogicDataTables.GetDataById(dataNumber.GetIntValue()); if (data != null) { LogicGameObject gameObject = LogicGameObjectFactory.CreateGameObject(data, level, villageType); if (gameObjectType == LogicGameObjectType.BUILDING) { ((LogicBuilding)gameObject).StartConstructing(true); } if (lockedBoolean != null && lockedBoolean.IsTrue()) { ((LogicBuilding)gameObject).Lock(); } gameObject.Load(jsonObject); gameObjectManager.AddGameObject(gameObject, -1); if (lvlNumber != null) { LogicDebugUtil.SetBuildingUpgradeLevel(level, gameObject.GetGlobalID(), lvlNumber.GetIntValue(), villageType); } } } } } }
public void UpdateAutoMerge() { if (this.m_autoMergeTime > 0) { int autoMergeGroupSize = this.GetCharacterData().GetAutoMergeGroupSize(); int autoMergeDistance = this.GetCharacterData().GetAutoMergeDistance(); if (autoMergeGroupSize > 0) { LogicArrayList <LogicGameObject> characters = this.GetGameObjectManager().GetGameObjects(LogicGameObjectType.CHARACTER); LogicCharacter closestCharacter = null; for (int i = 0; i < characters.Size(); i++) { LogicCharacter character = (LogicCharacter)characters[i]; if (character != this) { if (character.GetData() == this.GetData()) { if (this.m_autoMergeSize == 0 && character.m_autoMergeSize >= autoMergeGroupSize) { if (character.GetHitpointComponent().GetTeam() == this.GetHitpointComponent().GetTeam() && character.IsAlive()) { if (character.m_autoMergeTime > 0) { int distanceSquared = this.GetPosition().GetDistanceSquared(character.GetPosition()); if (distanceSquared <= autoMergeDistance * autoMergeDistance) { closestCharacter = character; } } } } } } } if (closestCharacter != null) { closestCharacter.m_autoMergeSize += 1; closestCharacter.GetCombatComponent().SetMergeDamage(90 * closestCharacter.m_autoMergeSize); closestCharacter.GetHitpointComponent() .SetMaxHitpoints(closestCharacter.GetCharacterData().GetHitpoints(this.m_upgradeLevel) * (closestCharacter.m_autoMergeSize + 1)); closestCharacter.GetHitpointComponent() .SetHitpoints(closestCharacter.GetCharacterData().GetHitpoints(this.m_upgradeLevel) * (closestCharacter.m_autoMergeSize + 1)); this.GetGameObjectManager().RemoveGameObject(this); } } } }
public void RemoveGameObjectReferences(LogicGameObject gameObject) { for (int i = 0; i < LogicComponent.COMPONENT_TYPE_COUNT; i++) { LogicArrayList <LogicComponent> components = this.m_components[(int)LogicComponentType.UNIT_STORAGE]; for (int j = 0; j < components.Size(); j++) { components[j].RemoveGameObjectReferences(gameObject); } } }
public void CheckExecutableServerCommands(int endSubTick, LogicArrayList <LogicCommand> commands) { for (int i = 0; i < commands.Size(); i++) { LogicCommand command = commands[i]; if (command.IsServerCommand()) { commands.Remove(i--); } } }
public void TrainUnits() { LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar(); LogicDataTable characterTable = LogicDataTables.GetTable(LogicDataType.CHARACTER); LogicDataTable spellTable = LogicDataTables.GetTable(LogicDataType.SPELL); LogicArrayList <LogicCombatItemData> productionUnits = new LogicArrayList <LogicCombatItemData>(characterTable.GetItemCount()); LogicArrayList <LogicCombatItemData> productionSpells = new LogicArrayList <LogicCombatItemData>(spellTable.GetItemCount()); for (int i = 0; i < characterTable.GetItemCount(); i++) { LogicCharacterData data = (LogicCharacterData)characterTable.GetItemAt(i); if (this.m_level.GetCalendar().IsProductionEnabled(data) && !data.IsSecondaryTroop()) { productionUnits.Add(data); } } this.SortProduction(productionUnits); for (int i = 0; i < productionUnits.Size(); i++) { int unitCount = homeOwnerAvatar.GetUnitPresetCount(productionUnits[i], this.m_presetId); if (unitCount > 0) { this.AddUnitsToQueue(productionUnits[i], unitCount); } } for (int i = 0; i < spellTable.GetItemCount(); i++) { LogicSpellData data = (LogicSpellData)spellTable.GetItemAt(i); if (this.m_level.GetCalendar().IsProductionEnabled(data)) { productionSpells.Add(data); } } this.SortProduction(productionSpells); for (int i = 0; i < productionSpells.Size(); i++) { int spellCount = homeOwnerAvatar.GetUnitPresetCount(productionSpells[i], this.m_presetId); if (spellCount > 0) { this.AddUnitsToQueue(productionSpells[i], spellCount); } } }