public void CalculateAvailableResources(LogicLevel level, int matchType) { for (int i = this.m_availableLootCount.Size() - 1; i >= 0; i--) { this.m_availableLootCount[i].Destruct(); this.m_availableLootCount.Remove(i); } LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i); LogicResourceData warResourceReferenceData = data.GetWarResourceReferenceData(); LogicDataSlot dataSlot = null; if (warResourceReferenceData != null) { for (int j = 0; j < this.m_availableLootCount.Size(); j++) { if (this.m_availableLootCount[j].GetData() == warResourceReferenceData) { dataSlot = this.m_availableLootCount[j]; break; } } Debugger.DoAssert(dataSlot != null, "Didn't find the resource slot"); } else { this.m_availableLootCount.Add(dataSlot = new LogicDataSlot(data, 0)); } if (matchType == 8 || matchType == 9) { LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar(); if (homeOwnerAvatar != null) { LogicArrayList <LogicDataSlot> resourceCount = homeOwnerAvatar.GetResources(); for (int j = 0; j < resourceCount.Size(); j++) { if (resourceCount[j].GetData() == data) { dataSlot.SetCount(resourceCount[j].GetCount()); } } } } else { LogicComponentManager componentManager = level.GetComponentManagerAt(level.GetVillageType()); if (warResourceReferenceData == null) { LogicArrayList <LogicComponent> resourceProductionComponents = componentManager.GetComponents(LogicComponentType.RESOURCE_PRODUCTION); LogicArrayList <LogicComponent> resourceStorageComponents = componentManager.GetComponents(LogicComponentType.RESOURCE_STORAGE); for (int j = 0; j < resourceProductionComponents.Size(); j++) { LogicResourceProductionComponent resourceProductionComponent = (LogicResourceProductionComponent)resourceProductionComponents[j]; LogicGameObject gameObject = resourceProductionComponent.GetParent(); if (gameObject.IsAlive() && resourceProductionComponent.IsEnabled()) { if (resourceProductionComponent.GetResourceData() == data) { dataSlot.SetCount(dataSlot.GetCount() + resourceProductionComponent.GetStealableResourceCount()); } } } for (int j = 0; j < resourceStorageComponents.Size(); j++) { LogicResourceStorageComponent resourceStorageComponent = (LogicResourceStorageComponent)resourceStorageComponents[j]; LogicGameObject gameObject = resourceStorageComponent.GetParent(); if (gameObject.IsAlive() && resourceStorageComponent.IsEnabled()) { dataSlot.SetCount(dataSlot.GetCount() + resourceStorageComponent.GetStealableResourceCount(i)); } } } else { LogicArrayList <LogicComponent> warResourceStorageComponents = componentManager.GetComponents(LogicComponentType.WAR_RESOURCE_STORAGE); for (int j = 0; j < warResourceStorageComponents.Size(); j++) { LogicWarResourceStorageComponent resourceWarStorageComponent = (LogicWarResourceStorageComponent)warResourceStorageComponents[j]; LogicGameObject gameObject = resourceWarStorageComponent.GetParent(); if (gameObject.IsAlive() && resourceWarStorageComponent.IsEnabled()) { dataSlot.SetCount(dataSlot.GetCount() + resourceWarStorageComponent.GetStealableResourceCount(i)); } } } } } }