コード例 #1
0
        private static ChestType DropTableRoll(LootTable dropLootTable, Player player, string predefinedDropRollId)
        {
            LootTableItem item;
            ChestType     nONE = ChestType.NONE;

            ModifyDropTableWeights(dropLootTable, player);
            if (!string.IsNullOrEmpty(predefinedDropRollId))
            {
                LootTableItem item2 = new LootTableItem();
                item2.Id = predefinedDropRollId;
                item     = item2;
            }
            else
            {
                item = dropLootTable.roll();
            }
            if ((item != null) && (item.Id != "NO_DROP"))
            {
                try
                {
                    nONE = (ChestType)((int)Enum.Parse(typeof(ChestType), item.Id));
                }
                catch (Exception)
                {
                    UnityEngine.Debug.LogError("Cannot parse ChestType enum from boss chest loot table roll: " + item.Id);
                }
            }
            dropLootTable.resetWeights(true);
            return(nONE);
        }
コード例 #2
0
 public void setWeightForItem(LootTableItem lti, int weight)
 {
     if (!this.originalWeightsInitialized())
     {
         this.initializeOriginalWeights();
     }
     lti.Weight = weight;
 }
コード例 #3
0
 public LootTableItem(LootTableItem another)
 {
     this.Id     = string.Empty;
     this.Id     = another.Id;
     this.Weight = another.Weight;
     if (another.SubTable != null)
     {
         this.SubTable = new LootTable(another.SubTable);
     }
 }
コード例 #4
0
 public void debugPrintContent([Optional, DefaultParameterValue(0)] int depth)
 {
     for (int i = 0; i < this.Items.Count; i++)
     {
         LootTableItem item = this.Items[i];
         string        str  = string.Empty;
         for (int j = 0; j < depth; j++)
         {
             str = str + "    ";
         }
         string str2 = str;
         Debug.Log(string.Concat(new object[] { str2, item.Id, ": ", item.Weight }));
         if ((item != null) && (item.SubTable != null))
         {
             item.SubTable.debugPrintContent(++depth);
         }
     }
 }
コード例 #5
0
 public void setAllWeightsTo(int weight, bool includeSubTables)
 {
     if (!this.originalWeightsInitialized())
     {
         this.initializeOriginalWeights();
     }
     for (int i = 0; i < this.Items.Count; i++)
     {
         LootTableItem item = this.Items[i];
         if (item != null)
         {
             item.Weight = weight;
             if (includeSubTables && (item.SubTable != null))
             {
                 item.SubTable.setAllWeightsTo(weight, true);
             }
         }
     }
 }
コード例 #6
0
 private void loadItemCsv(string csvFilePath)
 {
     string[,] strArray = CsvUtils.Deserialize(ResourceUtil.LoadSafe <TextAsset>(csvFilePath, false).text);
     for (int i = 0; i < strArray.GetLength(1); i++)
     {
         if (strArray[0, i] != null)
         {
             Item res  = new Item();
             int  num2 = 0;
             res.Id            = strArray[num2++, i];
             res.Name          = _.L(strArray[num2++, i], null, false);
             res.Type          = base.parseEnumType <ItemType>(strArray[num2++, i]);
             res.Accessories   = base.parseOrderedEnumStringDict <AccessoryType>(strArray[num2++, i]);
             res.SpriteId      = strArray[num2++, i];
             res.BodyMaterials = base.parseStringList(strArray[num2++, i]);
             res.Rarity        = base.parseInt(strArray[num2++, i]);
             List <PerkType> list = base.parseEnumList <PerkType>(strArray[num2++, i]);
             for (int j = 0; j < list.Count; j++)
             {
                 PerkType     perkType     = list[j];
                 float        bestModifier = ConfigPerks.GetBestModifier(perkType);
                 PerkInstance item         = new PerkInstance();
                 item.Type     = perkType;
                 item.Modifier = bestModifier;
                 res.FixedPerks.PerkInstances.Add(item);
             }
             res.FromChest = base.parseEnumType <ChestType>(strArray[num2++, i]);
             res.postDeserializeInitialization();
             base.addResource(res.Id, res);
             this.m_orderedItemIds.Add(res.Id);
             this.m_sortedItems.Add(res);
             if (res.FromChest != ChestType.NONE)
             {
                 LootTableItem item3 = new LootTableItem();
                 item3.Id = res.Id;
                 LootTableItem item2 = item3;
                 this.m_dynamicChestLootTables[res.FromChest].Items.Add(item2);
             }
         }
     }
 }
コード例 #7
0
 public void setWeightForIds(string id, int weight, bool includeSubTables)
 {
     if (!this.originalWeightsInitialized())
     {
         this.initializeOriginalWeights();
     }
     for (int i = 0; i < this.Items.Count; i++)
     {
         LootTableItem item = this.Items[i];
         if (item != null)
         {
             if (item.Id == id)
             {
                 item.Weight = weight;
             }
             if (includeSubTables && (item.SubTable != null))
             {
                 item.SubTable.setWeightForIds(id, weight, true);
             }
         }
     }
 }
コード例 #8
0
 public void resetWeights(bool includeSubTables)
 {
     if (!this.originalWeightsInitialized())
     {
         this.initializeOriginalWeights();
     }
     foreach (KeyValuePair <LootTableItem, int> pair in this.m_originalWeights)
     {
         pair.Key.Weight = pair.Value;
     }
     if (includeSubTables)
     {
         for (int i = 0; i < this.Items.Count; i++)
         {
             LootTableItem item = this.Items[i];
             if ((item != null) && (item.SubTable != null))
             {
                 item.SubTable.resetWeights(true);
             }
         }
     }
 }
コード例 #9
0
 public void initializeOriginalWeights()
 {
     if (this.m_originalWeights == null)
     {
         this.m_originalWeights = new Dictionary <LootTableItem, int>();
     }
     else
     {
         this.m_originalWeights.Clear();
     }
     for (int i = 0; i < this.Items.Count; i++)
     {
         LootTableItem key = this.Items[i];
         if (key != null)
         {
             this.m_originalWeights.Add(key, key.Weight);
             if (key.SubTable != null)
             {
                 key.SubTable.initializeOriginalWeights();
             }
         }
     }
 }
コード例 #10
0
 public LootTableItem getFirstMatchingItem(string id)
 {
     if (!this.originalWeightsInitialized())
     {
         this.initializeOriginalWeights();
     }
     for (int i = 0; i < this.Items.Count; i++)
     {
         LootTableItem item = this.Items[i];
         if (item != null)
         {
             if (item.Id == id)
             {
                 return(item);
             }
             if (item.SubTable != null)
             {
                 return(item.SubTable.getFirstMatchingItem(id));
             }
         }
     }
     return(null);
 }
コード例 #11
0
        public LootTableItem roll()
        {
            if (!this.originalWeightsInitialized())
            {
                this.initializeOriginalWeights();
            }
            int num = 0;

            for (int i = 0; i < this.Items.Count; i++)
            {
                num += this.Items[i].Weight;
            }
            int           num3 = UnityEngine.Random.Range(1, num + 1);
            int           num4 = 0;
            LootTableItem item = null;

            for (int j = 0; j < this.Items.Count; j++)
            {
                LootTableItem item2 = this.Items[j];
                num4 += item2.Weight;
                if (num3 <= num4)
                {
                    item = item2;
                    break;
                }
            }
            if ((this.Type == LootTableType.NoReplacement) && (item != null))
            {
                item.Weight = 0;
            }
            if ((item != null) && (item.SubTable != null))
            {
                return(item.SubTable.roll());
            }
            return(item);
        }