示例#1
0
        public static SmartEntity FindLeastFullStarport()
        {
            float                   num              = 0f;
            int                     num2             = 0;
            SmartEntity             smartEntity      = null;
            NodeList <StarportNode> starportNodeList = Service.BuildingLookupController.StarportNodeList;

            for (StarportNode starportNode = starportNodeList.Head; starportNode != null; starportNode = starportNode.Next)
            {
                BuildingComponent buildingComp = starportNode.BuildingComp;
                SmartEntity       smartEntity2 = (SmartEntity)buildingComp.Entity;
                if (!ContractUtils.IsBuildingConstructing(smartEntity2))
                {
                    int starportFillSize = StorageSpreadUtils.GetStarportFillSize(smartEntity2);
                    int storage          = buildingComp.BuildingType.Storage;
                    if (smartEntity == null || (float)starportFillSize < num || ((float)starportFillSize == num && storage < num2))
                    {
                        num         = (float)starportFillSize;
                        num2        = storage;
                        smartEntity = smartEntity2;
                    }
                }
            }
            return(smartEntity);
        }
示例#2
0
 public static void AddTroopToStarportReserve(SmartEntity starport, TroopTypeVO troop)
 {
     if (starport != null)
     {
         int num = StorageSpreadUtils.GetStarportFillSize(starport);
         num += troop.Size;
         StorageSpreadUtils.SetStarportFillSize(starport, num);
     }
 }
 public static void AddTroopToStarportVisually(Entity starport, TroopTypeVO troop)
 {
     if (starport != null && starport.Get <BuildingComponent>() != null && troop != null)
     {
         float num     = StorageSpreadUtils.GetStarportFullnessPercent(starport);
         int   storage = starport.Get <BuildingComponent>().BuildingType.Storage;
         num += (float)troop.Size / (float)storage;
         if (num > 1f)
         {
             StorageSpreadUtils.UpdateAllStarportFullnessMeters();
             return;
         }
         StorageSpreadUtils.SetStarportFullnessPercent(starport, num);
     }
 }
示例#4
0
 private static int CompareStarportNode(StarportNode a, StarportNode b)
 {
     return(StorageSpreadUtils.CompareEntityStorage(a.BuildingComp, b.BuildingComp));
 }
示例#5
0
        public static void UpdateAllStarportFullnessMeters()
        {
            GamePlayer worldOwner = GameUtils.GetWorldOwner();
            Dictionary <string, InventoryEntry> internalStorage = worldOwner.Inventory.Troop.GetInternalStorage();
            StaticDataController staticDataController           = Service.StaticDataController;
            List <TroopTypeVO>   list = new List <TroopTypeVO>();

            foreach (string current in internalStorage.Keys)
            {
                list.Add(staticDataController.Get <TroopTypeVO>(current));
            }
            List <StarportNode>     list2            = new List <StarportNode>();
            NodeList <StarportNode> starportNodeList = Service.BuildingLookupController.StarportNodeList;

            for (StarportNode starportNode = starportNodeList.Head; starportNode != null; starportNode = starportNode.Next)
            {
                if (!ContractUtils.IsBuildingConstructing((SmartEntity)starportNode.BuildingComp.Entity))
                {
                    list2.Add(starportNode);
                }
            }
            List <TroopTypeVO> arg_DE_0 = list;

            if (StorageSpreadUtils.< > f__mg$cache1 == null)
            {
                StorageSpreadUtils.< > f__mg$cache1 = new Comparison <TroopTypeVO>(StorageSpreadUtils.CompareTroop);
            }
            arg_DE_0.Sort(StorageSpreadUtils.< > f__mg$cache1);
            int count = list.Count;

            int[] array = new int[count];
            for (int i = 0; i < count; i++)
            {
                array[i] = internalStorage[list[i].Uid].Amount;
            }
            List <StarportNode> arg_147_0 = list2;

            if (StorageSpreadUtils.< > f__mg$cache2 == null)
            {
                StorageSpreadUtils.< > f__mg$cache2 = new Comparison <StarportNode>(StorageSpreadUtils.CompareStarportNode);
            }
            arg_147_0.Sort(StorageSpreadUtils.< > f__mg$cache2);
            int num    = 0;
            int count2 = list2.Count;
            Int32PriorityList int32PriorityList = new Int32PriorityList();

            int[] array2 = new int[count2];
            for (int j = 0; j < count2; j++)
            {
                int storage = list2[j].BuildingComp.BuildingType.Storage;
                array2[j] = storage;
                num      += storage;
                int priority = -j;
                int32PriorityList.Add(j, priority);
            }
            int num2 = 0;

            while (num2 < count && num > 0)
            {
                int size = list[num2].Size;
                int num3 = array[num2];
                while (num3 > 0 && num > 0)
                {
                    bool flag = false;
                    for (int k = 0; k < count2; k++)
                    {
                        int element = int32PriorityList.GetElement(k);
                        int num4    = array2[element];
                        if (size <= num4)
                        {
                            array2[element] -= size;
                            num             -= size;
                            int num5 = int32PriorityList.GetPriority(k);
                            int32PriorityList.RemoveAt(k);
                            num5 -= size * count2;
                            int32PriorityList.Add(element, num5);
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        int num6 = size;
                        int num7 = 0;
                        while (num7 < count2 && num6 > 0)
                        {
                            int num8 = array2[num7];
                            if (num8 > 0)
                            {
                                int num9 = (num6 >= num8) ? num8 : num6;
                                array2[num7] -= num9;
                                num          -= num9;
                                num6         -= num9;
                            }
                            num7++;
                        }
                    }
                    num3--;
                }
                num2++;
            }
            for (int l = 0; l < count2; l++)
            {
                BuildingComponent buildingComp = list2[l].BuildingComp;
                int         storage2           = buildingComp.BuildingType.Storage;
                int         num10    = storage2 - array2[l];
                SmartEntity starport = (SmartEntity)buildingComp.Entity;
                StorageSpreadUtils.SetStarportFullnessPercent(starport, (float)num10 / (float)storage2);
                StorageSpreadUtils.SetStarportFillSize(starport, num10);
            }
        }
示例#6
0
        public static int TransferPrizeFromInventory(PrizeType prizeType, string prizeID)
        {
            Lang             lang               = Service.Get <Lang>();
            IDataController  dataController     = Service.Get <IDataController>();
            CurrentPlayer    currentPlayer      = Service.Get <CurrentPlayer>();
            PrizeInventory   prizes             = currentPlayer.Prizes;
            Inventory        inventory          = currentPlayer.Inventory;
            InventoryStorage inventoryStorage   = null;
            IUpgradeableVO   finalUnitFromPrize = TimedEventPrizeUtils.GetFinalUnitFromPrize(prizeType, prizeID);
            string           text               = null;
            string           text2              = null;
            string           id = null;
            int result          = 0;
            int num             = 0;

            switch (prizeType)
            {
            case PrizeType.Currency:
                num = prizes.GetResourceAmount(prizeID);
                TimedEventPrizeUtils.GetCurrencyAmountToTransfer(prizeID, ref num, ref result);
                if (num > 0)
                {
                    inventory.ModifyItemAmount(prizeID, num);
                    prizes.ModifyResourceAmount(prizeID, -num);
                    text  = "INVENTORY_REWARD_USED_CURRENCY";
                    text2 = lang.Get(prizeID.ToUpper(), new object[0]);
                }
                else
                {
                    id = "INVENTORY_NO_ROOM";
                }
                break;

            case PrizeType.Infantry:
            case PrizeType.Vehicle:
            case PrizeType.Mercenary:
                inventoryStorage = inventory.Troop;
                if (inventoryStorage.GetTotalStorageCapacity() >= inventoryStorage.GetTotalStorageAmount() + finalUnitFromPrize.Size)
                {
                    num = 1;
                    inventoryStorage.ModifyItemAmount(finalUnitFromPrize.Uid, num);
                    prizes.ModifyTroopAmount(prizeID, -num);
                    text  = "INVENTORY_REWARD_USED_TROOP";
                    text2 = LangUtils.GetTroopDisplayName((TroopTypeVO)finalUnitFromPrize);
                    StorageSpreadUtils.UpdateAllStarportFullnessMeters();
                }
                else
                {
                    id = "NOT_ENOUGH_HOUSING";
                }
                result = prizes.GetTroopAmount(prizeID);
                break;

            case PrizeType.Hero:
                inventoryStorage = inventory.Hero;
                if (!Service.Get <BuildingLookupController>().HasHeroCommand())
                {
                    id = "INVENTORY_NO_HERO_COMMAND";
                }
                else if (inventoryStorage.GetTotalStorageCapacity() >= inventoryStorage.GetTotalStorageAmount() + finalUnitFromPrize.Size)
                {
                    bool flag = false;
                    foreach (KeyValuePair <string, InventoryEntry> current in inventoryStorage.GetInternalStorage())
                    {
                        if (current.get_Value().Amount > 0)
                        {
                            TroopTypeVO troopTypeVO = dataController.Get <TroopTypeVO>(current.get_Key());
                            if (troopTypeVO.UpgradeGroup == finalUnitFromPrize.UpgradeGroup)
                            {
                                flag = true;
                                break;
                            }
                        }
                    }
                    if (!flag)
                    {
                        flag = ContractUtils.HasExistingHeroContract(finalUnitFromPrize.UpgradeGroup);
                    }
                    if (!flag)
                    {
                        num = 1;
                        inventoryStorage.ModifyItemAmount(finalUnitFromPrize.Uid, num);
                        prizes.ModifyTroopAmount(prizeID, -num);
                        text  = "INVENTORY_REWARD_USED_HERO";
                        text2 = LangUtils.GetTroopDisplayName((TroopTypeVO)finalUnitFromPrize);
                        Service.Get <EventManager>().SendEvent(EventId.HeroMobilizedFromPrize, finalUnitFromPrize.Uid);
                    }
                    else
                    {
                        id = "INVENTORY_NO_ROOM_HERO_IN_QUEUE";
                    }
                }
                else
                {
                    id = "INVENTORY_NO_ROOM_HERO";
                }
                result = prizes.GetTroopAmount(prizeID);
                break;

            case PrizeType.SpecialAttack:
                inventoryStorage = inventory.SpecialAttack;
                if (!Service.Get <BuildingLookupController>().HasStarshipCommand())
                {
                    id = "INVENTORY_NO_FLEET_COMMAND";
                }
                else if (inventoryStorage.GetTotalStorageCapacity() >= inventoryStorage.GetTotalStorageAmount() + finalUnitFromPrize.Size)
                {
                    num = 1;
                    inventoryStorage.ModifyItemAmount(finalUnitFromPrize.Uid, num);
                    prizes.ModifySpecialAttackAmount(prizeID, -num);
                    text  = "INVENTORY_REWARD_USED_TROOP";
                    text2 = LangUtils.GetStarshipDisplayName((SpecialAttackTypeVO)finalUnitFromPrize);
                    Service.Get <EventManager>().SendEvent(EventId.StarshipMobilizedFromPrize, finalUnitFromPrize.Uid);
                }
                else
                {
                    id = "NOT_ENOUGH_SPACE";
                }
                result = prizes.GetSpecialAttackAmount(prizeID);
                break;
            }
            if (num > 0)
            {
                InventoryTransferRequest request = new InventoryTransferRequest(prizeID, num);
                Service.Get <ServerAPI>().Enqueue(new InventoryTransferCommand(request));
            }
            else
            {
                string message = lang.Get(id, new object[0]);
                AlertScreen.ShowModal(false, null, message, null, null);
            }
            if (text != null)
            {
                string text3 = (prizeType == PrizeType.Hero) ? text2 : lang.Get("AMOUNT_AND_NAME", new object[]
                {
                    num,
                    text2
                });
                string instructions = lang.Get(text, new object[]
                {
                    text3
                });
                Service.Get <UXController>().MiscElementsManager.ShowPlayerInstructions(instructions, 1f, 2f);
            }
            return(result);
        }
 public unsafe static long $Invoke12(long instance, long *args)
 {
     StorageSpreadUtils.UpdateAllStarportFullnessMeters();
     return(-1L);
 }
 public unsafe static long $Invoke11(long instance, long *args)
 {
     StorageSpreadUtils.SetStarportFullnessPercent((Entity)GCHandledObjects.GCHandleToObject(*args), *(float *)(args + 1));
     return(-1L);
 }
 public unsafe static long $Invoke10(long instance, long *args)
 {
     StorageSpreadUtils.SetStarportFillSize((Entity)GCHandledObjects.GCHandleToObject(*args), *(int *)(args + 1));
     return(-1L);
 }
示例#10
0
 public unsafe static long $Invoke9(long instance, long *args)
 {
     return(GCHandledObjects.ObjectToGCHandle(StorageSpreadUtils.GetStarportFullnessPercent((Entity)GCHandledObjects.GCHandleToObject(*args))));
 }
示例#11
0
 public unsafe static long $Invoke7(long instance, long *args)
 {
     return(GCHandledObjects.ObjectToGCHandle(StorageSpreadUtils.FindLeastFullStarport()));
 }
示例#12
0
 public unsafe static long $Invoke6(long instance, long *args)
 {
     return(GCHandledObjects.ObjectToGCHandle(StorageSpreadUtils.CompareTroop((TroopTypeVO)GCHandledObjects.GCHandleToObject(*args), (TroopTypeVO)GCHandledObjects.GCHandleToObject(args[1]))));
 }
示例#13
0
 public unsafe static long $Invoke5(long instance, long *args)
 {
     return(GCHandledObjects.ObjectToGCHandle(StorageSpreadUtils.CompareStorageNode((StorageNode)GCHandledObjects.GCHandleToObject(*args), (StorageNode)GCHandledObjects.GCHandleToObject(args[1]))));
 }
示例#14
0
 public unsafe static long $Invoke3(long instance, long *args)
 {
     return(GCHandledObjects.ObjectToGCHandle(StorageSpreadUtils.CompareEntityStorage((BuildingComponent)GCHandledObjects.GCHandleToObject(*args), (BuildingComponent)GCHandledObjects.GCHandleToObject(args[1]))));
 }
示例#15
0
 public unsafe static long $Invoke2(long instance, long *args)
 {
     return(GCHandledObjects.ObjectToGCHandle(StorageSpreadUtils.CalculateAssumedCurrencyInStorage((CurrencyType)(*(int *)args), (Entity)GCHandledObjects.GCHandleToObject(args[1]))));
 }
示例#16
0
 public unsafe static long $Invoke1(long instance, long *args)
 {
     StorageSpreadUtils.AddTroopToStarportVisually((Entity)GCHandledObjects.GCHandleToObject(*args), (TroopTypeVO)GCHandledObjects.GCHandleToObject(args[1]));
     return(-1L);
 }