示例#1
0
    private List <LootTableDrop> RollFromTableInternal(LootTableData table)
    {
        LootTableEntryData entry = RollForEntry(table);

        List <LootTableDrop> drops            = RollForDrop(entry);
        List <LootTableDrop> unprocessedDrops = new List <LootTableDrop>();
        List <LootTableDrop> finalDrops       = new List <LootTableDrop>();

        while (drops.Count > 0)
        {
            for (int i = drops.Count - 1; i >= 0; i--)
            {
                // Check if the drop is a table
                LootTableDrop drop = drops[i];
                if (drop.Type == LootTableDrop.DropType.TABLE)
                {
                    // first remove the drop, add results list to tableDrops
                    drops.RemoveAt(i);
                    // Add new drops to the unprocessed drops list
                    unprocessedDrops.AddRange(RollFromTable(drop.ItemId));
                }
                else
                {
                    finalDrops.Add(drop);
                }
            }
            // Things that we've found need to be processed
            drops = new List <LootTableDrop>(unprocessedDrops);
            unprocessedDrops.Clear();
        }

        return(finalDrops);
    }
    public static NodePromise GenerateLootCrate(LootTableData lootTable, float minItemLevel, float Variance, float magicFind, int activeZoneMongoID = -1, CrateTypeData lootCrateType = null, Action <LootCrate> callback = null)
    {
        LootCrate lootCrate;

        if (lootCrateType == null)
        {
            CrateTypeData ctd = MathHelper.WeightedRandom(lootTable.crateType).Key;
            lootCrate = new LootCrate(lootTable.Identity, minItemLevel, Variance, ctd, magicFind);
        }
        else
        {
            lootCrate = new LootCrate(lootTable.Identity, minItemLevel, Variance, lootCrateType, magicFind);
        }

        lootCrate.ExplorationID = activeZoneMongoID;

        return(API.LootCrates.Add(lootCrate)
               .Then(res => {
            //dataMan.allLootCratesList.Add(lootCrate);
            if (callback != null)
            {
                callback(lootCrate);
            }
        })
               .Catch(err => {
            traceError("Could not generate a new LootCrate: " + GameAPIManager.GetErrorMessage(err));
        }));
    }
示例#3
0
    public IEnumerator LoadLootTableData()
    {
        TextAsset[] data = Resources.LoadAll <TextAsset>(LOOT_TABLE_DATA_PATH);

        // Look at each file, each file contains a LootTableSetData which can contain one or more LootTableData
        for (int i = 0, count = data.Length; i < count; i++)
        {
            LootTableSetData lootTableSet = (LootTableSetData)Serializer.Deserialize(typeof(LootTableSetData), data[i].text);
            if (lootTableSet != null)
            {
                // Look at each LootTableData in the set
                for (int j = 0, count2 = lootTableSet.Set.Count; j < count2; j++)
                {
                    LootTableData lootTableData = lootTableSet.Set[j];
                    if (!_cachedLootTableData.ContainsKey(lootTableData.Id))
                    {
                        _cachedLootTableData.Add(lootTableData.Id, lootTableData);
                    }
                    else
                    {
                        Debug.LogError("LootTableManager already has a loot table with id: " + lootTableData.Id + " cached");
                    }
                }
            }
            yield return(new WaitForEndOfFrame());
        }
    }
示例#4
0
    private LootTableEntryData RollForEntry(LootTableData table)
    {
        List <LootTableEntryData> entries = table.Entries;
        LootTableEntryData        entry   = null;

        // sum up the weights
        float totalWeight = 0f;

        for (int i = 0, count = entries.Count; i < count; i++)
        {
            totalWeight += entries[i].Weight;
        }

        // Roll a random value from 0 to totalWeight and pick the first item that brings rollingTotalWeight above totalweight
        float roll = UnityEngine.Random.Range(0, totalWeight);
        float rollingTotalWeight = 0f;

        for (int i = 0, count = entries.Count; i < count; i++)
        {
            rollingTotalWeight += entries[i].Weight;
            if (roll <= rollingTotalWeight)
            {
                entry = entries[i];
                break;
            }
        }

        return(entry);
    }
示例#5
0
    public List <Item> GenerateItems()
    {
        LootCollection lootCollect = LootTableData.GetRandomItems(this);

        _generatedItems = lootCollect.randomItems;

        return(_generatedItems);
    }
    public BossFightData(string Identity, List <BossData> monsters, LootTableData lootTable, int Gold, int Experience)
    {
        this.Identity   = Identity;
        this.monsters   = monsters;
        this.lootTable  = lootTable;
        this.Gold       = Gold;
        this.Experience = Experience;

        if (lootTable == null)
        {
            UnityEngine.Debug.Log("ERROR ERROR NO LOOT TABLE");
        }
    }
示例#7
0
    public List <LootTableDrop> RollFromTable(string lootTableId)
    {
        LootTableData        lootTable = null;
        List <LootTableDrop> drops     = null;

        if (_cachedLootTableData.TryGetValue(lootTableId, out lootTable))
        {
            drops = RollFromTableInternal(lootTable);
        }
        else
        {
            Debug.LogError("No loot table with id: " + lootTableId + " found");
        }

        return(drops);
    }
示例#8
0
 public ZoneData(string Identity, string Name, string Description, int Act, int Zone, int ActZoneID, float BossPower, int ZoneHP, LootTableData LootTable, float MinItemLevel, float Variance, float MonsterTimer, BossFightData BossFight, List <MonsterData> Monsters, ZoneDifficulty Difficulty, string StoryEvent = "")
 {
     this.Identity     = Identity;
     this.Name         = Name;
     this.Description  = Description;
     this.LootTable    = LootTable;
     this.Act          = Act;
     this.Zone         = Zone;
     this.ActZoneID    = ActZoneID;
     this.MonsterTimer = MonsterTimer;
     this.BossPower    = BossPower;
     this.ZoneHP       = ZoneHP;
     this.BossFight    = BossFight;
     this.Monsters     = Monsters;
     this.MinItemLevel = MinItemLevel;
     this.Variance     = Variance;
     this.Difficulty   = Difficulty;
     this.StoryEvent   = StoryEvent;
 }