Esempio n. 1
0
        public override void applyCondition(Player player, bool shouldSend)
        {
            if (!Provider.isServer)
            {
                return;
            }
            if (!this.shouldReset)
            {
                return;
            }
            NPCItemCondition.search.Clear();
            player.inventory.search(NPCItemCondition.search, this.id, false, true);
            NPCItemCondition.search.Sort(NPCItemCondition.qualityAscendingComparator);
            ushort num = this.amount;
            byte   b   = 0;

            while ((int)b < NPCItemCondition.search.Count)
            {
                InventorySearch inventorySearch = NPCItemCondition.search[(int)b];
                if (player.equipment.checkSelection(inventorySearch.page, inventorySearch.jar.x, inventorySearch.jar.y))
                {
                    player.equipment.dequip();
                }
                if ((ushort)inventorySearch.jar.item.amount > num)
                {
                    player.inventory.sendUpdateAmount(inventorySearch.page, inventorySearch.jar.x, inventorySearch.jar.y, (byte)((ushort)inventorySearch.jar.item.amount - num));
                    break;
                }
                num -= (ushort)inventorySearch.jar.item.amount;
                player.inventory.sendUpdateAmount(inventorySearch.page, inventorySearch.jar.x, inventorySearch.jar.y, 0);
                player.crafting.removeItem(inventorySearch.page, inventorySearch.jar);
                if (inventorySearch.page < PlayerInventory.SLOTS)
                {
                    player.equipment.sendSlot(inventorySearch.page);
                }
                if (num == 0)
                {
                    break;
                }
                b += 1;
            }
        }
Esempio n. 2
0
        public void sell(Player player)
        {
            ItemAsset itemAsset = Assets.find(EAssetType.ITEM, base.id) as ItemAsset;

            VendorBuying.search.Clear();
            player.inventory.search(VendorBuying.search, base.id, false, true);
            VendorBuying.search.Sort(VendorBuying.qualityAscendingComparator);
            ushort num = (ushort)itemAsset.amount;
            byte   b   = 0;

            while ((int)b < VendorBuying.search.Count)
            {
                InventorySearch inventorySearch = VendorBuying.search[(int)b];
                if (player.equipment.checkSelection(inventorySearch.page, inventorySearch.jar.x, inventorySearch.jar.y))
                {
                    player.equipment.dequip();
                }
                if ((ushort)inventorySearch.jar.item.amount > num)
                {
                    player.inventory.sendUpdateAmount(inventorySearch.page, inventorySearch.jar.x, inventorySearch.jar.y, (byte)((ushort)inventorySearch.jar.item.amount - num));
                    break;
                }
                num -= (ushort)inventorySearch.jar.item.amount;
                player.inventory.sendUpdateAmount(inventorySearch.page, inventorySearch.jar.x, inventorySearch.jar.y, 0);
                player.crafting.removeItem(inventorySearch.page, inventorySearch.jar);
                if (inventorySearch.page < PlayerInventory.SLOTS)
                {
                    player.equipment.sendSlot(inventorySearch.page);
                }
                if (num == 0)
                {
                    break;
                }
                b += 1;
            }
            player.skills.askAward(base.cost);
        }
Esempio n. 3
0
 public void askCraft(CSteamID steamID, ushort id, byte index, bool force)
 {
     if (base.channel.checkOwner(steamID))
     {
         if (base.player.equipment.isBusy)
         {
             return;
         }
         if (!base.player.tryToPerformRateLimitedAction())
         {
             return;
         }
         ItemAsset itemAsset = (ItemAsset)Assets.find(EAssetType.ITEM, id);
         if (itemAsset != null)
         {
             if ((int)index >= itemAsset.blueprints.Count)
             {
                 return;
             }
             Blueprint blueprint = itemAsset.blueprints[(int)index];
             if (blueprint.skill == EBlueprintSkill.REPAIR && (uint)blueprint.level > Provider.modeConfigData.Gameplay.Repair_Level_Max)
             {
                 return;
             }
             if (!string.IsNullOrEmpty(blueprint.map) && !blueprint.map.Equals(Level.info.name, StringComparison.InvariantCultureIgnoreCase))
             {
                 return;
             }
             if (blueprint.tool != 0 && base.player.inventory.has(blueprint.tool) == null)
             {
                 return;
             }
             if (blueprint.skill != EBlueprintSkill.NONE)
             {
                 bool flag = PowerTool.checkFires(base.transform.position, 16f);
                 if ((blueprint.skill == EBlueprintSkill.CRAFT && base.player.skills.skills[2][1].level < blueprint.level) || (blueprint.skill == EBlueprintSkill.COOK && (!flag || base.player.skills.skills[2][3].level < blueprint.level)) || (blueprint.skill == EBlueprintSkill.REPAIR && base.player.skills.skills[2][7].level < blueprint.level))
                 {
                     return;
                 }
             }
             bool flag2 = false;
             while (blueprint.areConditionsMet(base.player))
             {
                 List <InventorySearch>[] array = new List <InventorySearch> [blueprint.supplies.Length];
                 byte b = 0;
                 while ((int)b < blueprint.supplies.Length)
                 {
                     BlueprintSupply        blueprintSupply = blueprint.supplies[(int)b];
                     List <InventorySearch> list            = base.player.inventory.search(blueprintSupply.id, false, true);
                     if (list.Count == 0)
                     {
                         return;
                     }
                     ushort num = 0;
                     byte   b2  = 0;
                     while ((int)b2 < list.Count)
                     {
                         num += (ushort)list[(int)b2].jar.item.amount;
                         b2  += 1;
                     }
                     if (num < blueprintSupply.amount && blueprint.type != EBlueprintType.AMMO)
                     {
                         return;
                     }
                     if (blueprint.type == EBlueprintType.AMMO)
                     {
                         list.Sort(PlayerCrafting.amountAscendingComparator);
                     }
                     else
                     {
                         list.Sort(PlayerCrafting.qualityAscendingComparator);
                     }
                     array[(int)b] = list;
                     b            += 1;
                 }
                 if (blueprint.type == EBlueprintType.REPAIR)
                 {
                     List <InventorySearch> list2 = base.player.inventory.search(itemAsset.id, false, false);
                     byte b3 = byte.MaxValue;
                     byte b4 = byte.MaxValue;
                     byte b5 = 0;
                     while ((int)b5 < list2.Count)
                     {
                         if (list2[(int)b5].jar.item.quality < b3)
                         {
                             b3 = list2[(int)b5].jar.item.quality;
                             b4 = b5;
                         }
                         b5 += 1;
                     }
                     if (b4 == 255)
                     {
                         return;
                     }
                     InventorySearch inventorySearch = list2[(int)b4];
                     if (base.player.equipment.checkSelection(inventorySearch.page, inventorySearch.jar.x, inventorySearch.jar.y))
                     {
                         base.player.equipment.dequip();
                     }
                     byte b6 = 0;
                     while ((int)b6 < array.Length)
                     {
                         BlueprintSupply        blueprintSupply2 = blueprint.supplies[(int)b6];
                         List <InventorySearch> list3            = array[(int)b6];
                         byte b7 = 0;
                         while ((ushort)b7 < blueprintSupply2.amount)
                         {
                             InventorySearch inventorySearch2 = list3[(int)b7];
                             if (base.player.equipment.checkSelection(inventorySearch2.page, inventorySearch2.jar.x, inventorySearch2.jar.y))
                             {
                                 base.player.equipment.dequip();
                             }
                             this.removeItem(inventorySearch2.page, inventorySearch2.jar);
                             if (inventorySearch2.page < PlayerInventory.SLOTS)
                             {
                                 base.player.equipment.sendSlot(inventorySearch2.page);
                             }
                             b7 += 1;
                         }
                         b6 += 1;
                     }
                     base.player.inventory.sendUpdateQuality(inventorySearch.page, inventorySearch.jar.x, inventorySearch.jar.y, 100);
                     if (itemAsset.type == EItemType.REFILL && inventorySearch.jar.item.state[0] == 3)
                     {
                         inventorySearch.jar.item.state[0] = 1;
                         base.player.inventory.sendUpdateInvState(inventorySearch.page, inventorySearch.jar.x, inventorySearch.jar.y, inventorySearch.jar.item.state);
                     }
                     base.channel.send("tellCraft", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[0]);
                 }
                 else if (blueprint.type == EBlueprintType.AMMO)
                 {
                     List <InventorySearch> list4 = base.player.inventory.search(itemAsset.id, true, true);
                     int  num2 = -1;
                     byte b8   = byte.MaxValue;
                     byte b9   = 0;
                     while ((int)b9 < list4.Count)
                     {
                         if ((int)list4[(int)b9].jar.item.amount > num2 && list4[(int)b9].jar.item.amount < itemAsset.amount)
                         {
                             num2 = (int)list4[(int)b9].jar.item.amount;
                             b8   = b9;
                         }
                         b9 += 1;
                     }
                     if (b8 == 255)
                     {
                         return;
                     }
                     InventorySearch inventorySearch3 = list4[(int)b8];
                     int             num3             = (int)itemAsset.amount - num2;
                     if (base.player.equipment.checkSelection(inventorySearch3.page, inventorySearch3.jar.x, inventorySearch3.jar.y))
                     {
                         base.player.equipment.dequip();
                     }
                     List <InventorySearch> list5 = array[0];
                     byte b10 = 0;
                     while ((int)b10 < list5.Count)
                     {
                         InventorySearch inventorySearch4 = list5[(int)b10];
                         if (inventorySearch4.jar != inventorySearch3.jar)
                         {
                             if (base.player.equipment.checkSelection(inventorySearch4.page, inventorySearch4.jar.x, inventorySearch4.jar.y))
                             {
                                 base.player.equipment.dequip();
                             }
                             if ((int)inventorySearch4.jar.item.amount > num3)
                             {
                                 base.player.inventory.sendUpdateAmount(inventorySearch4.page, inventorySearch4.jar.x, inventorySearch4.jar.y, (byte)((int)inventorySearch4.jar.item.amount - num3));
                                 num3 = 0;
                                 break;
                             }
                             num3 -= (int)inventorySearch4.jar.item.amount;
                             base.player.inventory.sendUpdateAmount(inventorySearch4.page, inventorySearch4.jar.x, inventorySearch4.jar.y, 0);
                             if ((index == 0 && itemAsset.blueprints.Count > 1) || itemAsset.blueprints.Count == 1)
                             {
                                 this.removeItem(inventorySearch4.page, inventorySearch4.jar);
                                 if (inventorySearch4.page < PlayerInventory.SLOTS)
                                 {
                                     base.player.equipment.sendSlot(inventorySearch4.page);
                                 }
                             }
                             if (num3 == 0)
                             {
                                 break;
                             }
                         }
                         b10 += 1;
                     }
                     base.player.inventory.sendUpdateAmount(inventorySearch3.page, inventorySearch3.jar.x, inventorySearch3.jar.y, (byte)((int)itemAsset.amount - num3));
                     base.channel.send("tellCraft", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[0]);
                 }
                 else
                 {
                     byte b11 = 0;
                     while ((int)b11 < array.Length)
                     {
                         BlueprintSupply        blueprintSupply3 = blueprint.supplies[(int)b11];
                         List <InventorySearch> list6            = array[(int)b11];
                         byte b12 = 0;
                         while ((ushort)b12 < blueprintSupply3.amount)
                         {
                             InventorySearch inventorySearch5 = list6[(int)b12];
                             if (base.player.equipment.checkSelection(inventorySearch5.page, inventorySearch5.jar.x, inventorySearch5.jar.y))
                             {
                                 base.player.equipment.dequip();
                             }
                             this.removeItem(inventorySearch5.page, inventorySearch5.jar);
                             if (inventorySearch5.page < PlayerInventory.SLOTS)
                             {
                                 base.player.equipment.sendSlot(inventorySearch5.page);
                             }
                             b12 += 1;
                         }
                         b11 += 1;
                     }
                     byte b13 = 0;
                     while ((int)b13 < blueprint.outputs.Length)
                     {
                         BlueprintOutput blueprintOutput = blueprint.outputs[(int)b13];
                         byte            b14             = 0;
                         while ((ushort)b14 < blueprintOutput.amount)
                         {
                             if (blueprint.transferState)
                             {
                                 base.player.inventory.forceAddItem(new Item(blueprintOutput.id, array[0][0].jar.item.amount, array[0][0].jar.item.quality, array[0][0].jar.item.state), true);
                             }
                             else
                             {
                                 base.player.inventory.forceAddItem(new Item(blueprintOutput.id, EItemOrigin.CRAFT), true);
                             }
                             b14 += 1;
                         }
                         b13 += 1;
                     }
                     blueprint.applyConditions(base.player, true);
                     blueprint.grantRewards(base.player, true);
                     base.channel.send("tellCraft", ESteamCall.OWNER, ESteamPacket.UPDATE_RELIABLE_BUFFER, new object[0]);
                 }
                 if (!flag2)
                 {
                     flag2 = true;
                     base.player.sendStat(EPlayerStat.FOUND_CRAFTS);
                     if (blueprint.build != 0)
                     {
                         EffectManager.sendEffect(blueprint.build, EffectManager.SMALL, base.transform.position);
                         if (Provider.isServer)
                         {
                             AlertTool.alert(base.transform.position, 8f);
                         }
                     }
                 }
                 if (!force || blueprint.type == EBlueprintType.REPAIR || blueprint.type == EBlueprintType.AMMO)
                 {
                     return;
                 }
             }
             return;
         }
     }
 }
Esempio n. 4
0
        private static void updateSelection(Blueprint[] view, byte typeIndex, bool uncraftable, string search)
        {
            bool             flag = PowerTool.checkFires(Player.player.transform.position, 16f);
            List <Blueprint> list;

            if (view == null)
            {
                list = new List <Blueprint>();
                foreach (ItemAsset itemAsset in Assets.find(EAssetType.ITEM))
                {
                    if (itemAsset != null)
                    {
                        for (int j = 0; j < itemAsset.blueprints.Count; j++)
                        {
                            Blueprint blueprint = itemAsset.blueprints[j];
                            if ((search.Length <= 0) ? (blueprint.type == (EBlueprintType)typeIndex) : PlayerDashboardCraftingUI.searchBlueprintText(blueprint, search))
                            {
                                list.Add(blueprint);
                            }
                        }
                    }
                }
            }
            else
            {
                list = new List <Blueprint>(view);
            }
            List <Blueprint> list2 = new List <Blueprint>();

            for (int k = 0; k < list.Count; k++)
            {
                Blueprint blueprint2 = list[k];
                if (blueprint2.skill != EBlueprintSkill.REPAIR || (uint)blueprint2.level <= Provider.modeConfigData.Gameplay.Repair_Level_Max)
                {
                    if (string.IsNullOrEmpty(blueprint2.map) || blueprint2.map.Equals(Level.info.name, StringComparison.InvariantCultureIgnoreCase))
                    {
                        ItemAsset itemAsset2 = (ItemAsset)Assets.find(EAssetType.ITEM, blueprint2.source);
                        ushort    num        = 0;
                        bool      flag2      = true;
                        blueprint2.hasSupplies = true;
                        blueprint2.hasSkills   = (blueprint2.skill == EBlueprintSkill.NONE || (blueprint2.skill == EBlueprintSkill.CRAFT && Player.player.skills.skills[2][1].level >= blueprint2.level) || (blueprint2.skill == EBlueprintSkill.COOK && flag && Player.player.skills.skills[2][3].level >= blueprint2.level) || (blueprint2.skill == EBlueprintSkill.REPAIR && Player.player.skills.skills[2][7].level >= blueprint2.level));
                        List <InventorySearch>[] array2 = new List <InventorySearch> [blueprint2.supplies.Length];
                        byte b = 0;
                        while ((int)b < blueprint2.supplies.Length)
                        {
                            BlueprintSupply        blueprintSupply = blueprint2.supplies[(int)b];
                            List <InventorySearch> list3           = Player.player.inventory.search(blueprintSupply.id, false, true);
                            ushort num2 = 0;
                            byte   b2   = 0;
                            while ((int)b2 < list3.Count)
                            {
                                num2 += (ushort)list3[(int)b2].jar.item.amount;
                                b2   += 1;
                            }
                            num += num2;
                            blueprintSupply.hasAmount = num2;
                            if (blueprint2.type == EBlueprintType.AMMO)
                            {
                                if (blueprintSupply.hasAmount == 0)
                                {
                                    blueprint2.hasSupplies = false;
                                }
                            }
                            else if (blueprintSupply.hasAmount < blueprintSupply.amount)
                            {
                                blueprint2.hasSupplies = false;
                            }
                            if (blueprintSupply.hasAmount < blueprintSupply.amount && blueprintSupply.isCritical)
                            {
                                flag2 = false;
                            }
                            array2[(int)b] = list3;
                            b += 1;
                        }
                        if (blueprint2.tool != 0)
                        {
                            InventorySearch inventorySearch = Player.player.inventory.has(blueprint2.tool);
                            blueprint2.tools   = ((inventorySearch == null) ? 0 : 1);
                            blueprint2.hasTool = (inventorySearch != null);
                            if (inventorySearch == null && blueprint2.toolCritical)
                            {
                                flag2 = false;
                            }
                        }
                        else
                        {
                            blueprint2.tools   = 1;
                            blueprint2.hasTool = true;
                        }
                        if (!flag2)
                        {
                            num = 0;
                        }
                        if (blueprint2.type == EBlueprintType.REPAIR)
                        {
                            List <InventorySearch> list4 = Player.player.inventory.search(itemAsset2.id, false, false);
                            byte b3 = byte.MaxValue;
                            byte b4 = byte.MaxValue;
                            byte b5 = 0;
                            while ((int)b5 < list4.Count)
                            {
                                if (list4[(int)b5].jar.item.quality < b3)
                                {
                                    b3 = list4[(int)b5].jar.item.quality;
                                    b4 = b5;
                                }
                                b5 += 1;
                            }
                            if (b4 != 255)
                            {
                                blueprint2.items = (ushort)list4[(int)b4].jar.item.quality;
                                num += 1;
                            }
                            else
                            {
                                blueprint2.items = 0;
                            }
                            blueprint2.hasItem = (b4 != byte.MaxValue);
                        }
                        else if (blueprint2.type == EBlueprintType.AMMO)
                        {
                            List <InventorySearch> list5 = Player.player.inventory.search(itemAsset2.id, true, true);
                            int  num3 = -1;
                            byte b6   = byte.MaxValue;
                            byte b7   = 0;
                            while ((int)b7 < list5.Count)
                            {
                                if ((int)list5[(int)b7].jar.item.amount > num3 && list5[(int)b7].jar.item.amount < itemAsset2.amount)
                                {
                                    num3 = (int)list5[(int)b7].jar.item.amount;
                                    b6   = b7;
                                }
                                b7 += 1;
                            }
                            if (b6 != 255)
                            {
                                if (list5[(int)b6].jar.item.id == blueprint2.supplies[0].id)
                                {
                                    BlueprintSupply blueprintSupply2 = blueprint2.supplies[0];
                                    blueprintSupply2.hasAmount -= (ushort)num3;
                                }
                                blueprint2.supplies[0].amount = (ushort)((byte)((int)itemAsset2.amount - num3));
                                blueprint2.items = (ushort)list5[(int)b6].jar.item.amount;
                                num += 1;
                            }
                            else
                            {
                                blueprint2.supplies[0].amount = 0;
                                blueprint2.items = 0;
                            }
                            blueprint2.hasItem = (b6 != byte.MaxValue);
                            if (b6 == 255)
                            {
                                blueprint2.products = 0;
                            }
                            else if (blueprint2.items + blueprint2.supplies[0].hasAmount > (ushort)itemAsset2.amount)
                            {
                                blueprint2.products = (ushort)itemAsset2.amount;
                            }
                            else
                            {
                                blueprint2.products = blueprint2.items + blueprint2.supplies[0].hasAmount;
                            }
                        }
                        else
                        {
                            blueprint2.hasItem = true;
                        }
                        if (uncraftable)
                        {
                            if (blueprint2.hasSupplies && blueprint2.hasTool && blueprint2.hasItem && blueprint2.hasSkills)
                            {
                                list2.Add(blueprint2);
                            }
                        }
                        else if (view != null)
                        {
                            if (blueprint2.hasSupplies && blueprint2.hasTool && blueprint2.hasItem && blueprint2.hasSkills)
                            {
                                list2.Insert(0, blueprint2);
                            }
                            else
                            {
                                list2.Add(blueprint2);
                            }
                        }
                        else if (blueprint2.hasSupplies && blueprint2.hasTool && blueprint2.hasItem && blueprint2.hasSkills)
                        {
                            list2.Insert(0, blueprint2);
                        }
                        else if ((blueprint2.type == EBlueprintType.AMMO || blueprint2.type == EBlueprintType.REPAIR || num != 0) && blueprint2.hasItem)
                        {
                            list2.Add(blueprint2);
                        }
                    }
                }
            }
            PlayerDashboardCraftingUI.viewBlueprints  = view;
            PlayerDashboardCraftingUI.selectedType    = typeIndex;
            PlayerDashboardCraftingUI.hideUncraftable = uncraftable;
            PlayerDashboardCraftingUI.searchText      = search;
            PlayerDashboardCraftingUI.blueprints      = list2.ToArray();
            PlayerDashboardCraftingUI.blueprintsScrollBox.remove();
            PlayerDashboardCraftingUI.blueprintsScrollBox.area = new Rect(0f, 0f, 5f, (float)(PlayerDashboardCraftingUI.blueprints.Length * 205 - 10));
            for (int l = 0; l < PlayerDashboardCraftingUI.blueprints.Length; l++)
            {
                Blueprint      newBlueprint   = PlayerDashboardCraftingUI.blueprints[l];
                SleekBlueprint sleekBlueprint = new SleekBlueprint(newBlueprint);
                sleekBlueprint.positionOffset_Y = l * 205;
                sleekBlueprint.sizeOffset_X     = -30;
                sleekBlueprint.sizeOffset_Y     = 195;
                sleekBlueprint.sizeScale_X      = 1f;
                SleekButton sleekButton = sleekBlueprint;
                if (PlayerDashboardCraftingUI.< > f__mg$cache0 == null)
                {
                    PlayerDashboardCraftingUI.< > f__mg$cache0 = new ClickedButton(PlayerDashboardCraftingUI.onClickedBlueprintButton);
                }
                sleekButton.onClickedButton = PlayerDashboardCraftingUI.< > f__mg$cache0;
                PlayerDashboardCraftingUI.blueprintsScrollBox.add(sleekBlueprint);
            }
            PlayerDashboardCraftingUI.infoBox.isVisible = (PlayerDashboardCraftingUI.blueprints.Length == 0);
        }