Beispiel #1
0
        public static int TransferPrizeFromInventory(PrizeType prizeType, string prizeID)
        {
            Lang lang = Service.Lang;
            StaticDataController staticDataController = Service.StaticDataController;
            CurrentPlayer        currentPlayer        = Service.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.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.Value.Amount > 0)
                        {
                            TroopTypeVO troopTypeVO = staticDataController.Get <TroopTypeVO>(current.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.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.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.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.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) ? lang.Get("AMOUNT_AND_NAME", new object[]
                {
                    num,
                    text2
                }) : text2;
                string instructions = lang.Get(text, new object[]
                {
                    text3
                });
                Service.UXController.MiscElementsManager.ShowPlayerInstructions(instructions, 1f, 2f);
            }
            return(result);
        }