Exemple #1
0
    public void Initialize(Battle.SessionResults results, Action continueButtonCallback)
    {
        // Temp
        if (results.IsVictory)
        {
            ResultLabel.text = "VICTORY";

            for (int i = 0, count = results.Drops.Count; i < count; i++)
            {
                LootTableDrop drop = results.Drops[i];
                GameObject    go   = GameObject.Instantiate(_itemDropPrefab.gameObject) as GameObject;
                go.transform.SetParent(_dropsParentTransform);
                go.transform.localScale = Vector3.one;

                go.GetComponent <GameResultsItemDrop>().Initialize(drop);
            }
        }
        else
        {
            ResultLabel.text = "DEFEAT";
        }



        _continueButtonCallback = continueButtonCallback;
    }
Exemple #2
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);
    }
Exemple #3
0
    private List <LootTableDrop> RollForDrop(LootTableEntryData entry)
    {
        List <LootTableDrop> possibleDrops = entry.Drops;
        List <LootTableDrop> drops         = new List <LootTableDrop>();

        // Check the style of the entry
        // If the drop style is to pick one of the drops, do a simple weighted roll
        if (entry.Style == LootTableEntryData.DropStyle.ONE_OF)
        {
            // sum up the weights
            float totalWeight = 0f;
            for (int i = 0, count = possibleDrops.Count; i < count; i++)
            {
                totalWeight += possibleDrops[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 = possibleDrops.Count; i < count; i++)
            {
                LootTableDrop drop = possibleDrops[i];
                rollingTotalWeight += drop.Weight;
                if (roll <= rollingTotalWeight)
                {
                    // +1 because range for ints is max exlusive
                    drop.Amount = UnityEngine.Random.Range(drop.AmountMin, drop.AmountMax + 1);
                    drops.Add(drop);
                    break;
                }
            }
        }
        else if (entry.Style == LootTableEntryData.DropStyle.ANY_OF)
        {
            // We want to roll a dice for each drop, the weights of an ANY_OF are treated as a percentage
            for (int i = 0, count = possibleDrops.Count; i < count; i++)
            {
                float         roll = UnityEngine.Random.Range(0f, 1f);
                LootTableDrop drop = possibleDrops[i];
                if (roll <= drop.Weight)
                {
                    // +1 because range for ints is max exlusive
                    drop.Amount = UnityEngine.Random.Range(drop.AmountMin, drop.AmountMax + 1);
                    drops.Add(drop);
                }
            }
        }

        return(drops);
    }
 public void Initialize(LootTableDrop drop)
 {
     if (drop.Type == LootTableDrop.DropType.WEAPON)
     {
         WeaponTileData data = Database.Instance.GetWeaponTileData(drop.ItemId);
         _itemIcon.sprite   = data.Sprite;
         _itemQuantity.text = drop.Amount.ToString();
     }
     else if (drop.Type == LootTableDrop.DropType.CURRENCY)
     {
         BaseItemData data = Database.Instance.GetItemData(drop.ItemId);
         _itemIcon.sprite   = data.Sprite;
         _itemQuantity.text = drop.Amount.ToString();
     }
 }