Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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));
                            }
                        }
                    }
                }
            }
        }