示例#1
0
        public LootResult LootAction(Player actingPlayer, Player targetPlayer, Weapon targetItem)
        {
            var lootResult = new LootResult()
            {
                ActingPlayer = actingPlayer,
                TargetPlayer = targetPlayer,
                TargetItem   = targetItem,
                Action       = PlayerAction.Loot
            };

            actingPlayer.Weapon = targetItem;

            return(lootResult);
        }
示例#2
0
 private void setLootResult(LootResult result, List <LootObjData> list, int index)
 {
     result._loots[index] = new Dictionary <ItemData, int>();
     foreach (LootObjData ld in list)
     {
         ItemData data = getItemData(ld._lootId);
         if (result._loots[index].ContainsKey(data))
         {
             result._loots[index][data] += ld._lootCount;
         }
         else
         {
             result._loots[index][data] = ld._lootCount;
         }
     }
 }
示例#3
0
        // PUBLIC METHODS: ------------------------------------------------------------------------

        public LootResult Get()
        {
            List <Loot> chances     = new List <Loot>();
            int         totalWeight = 0;

            if (this.noDropWeight > 0)
            {
                totalWeight += this.noDropWeight;
                chances.Add(new Loot(null, 0, this.noDropWeight));
            }

            for (int i = 0; i < this.loot.Length; ++i)
            {
                chances.Add(this.loot[i]);
                totalWeight += this.loot[i].weight;
            }

            chances.Sort((Loot x, Loot y) => y.weight.CompareTo(x.weight));
            int random = Random.Range(0, totalWeight);

            for (int i = 0; i < chances.Count; ++i)
            {
                Loot item = chances[i];
                if (random < item.weight)
                {
                    LootResult result = new LootResult(item.item, item.amount);
                    if (result.item == null || result.amount < 1)
                    {
                        return(new LootResult(null, 0));
                    }

                    EVENT_LOOT.Invoke(result);
                    return(result);
                }

                random -= item.weight;
            }

            return(new LootResult(null, 0));
        }