80 lines
2.7 KiB
C#
80 lines
2.7 KiB
C#
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using BlueWater.Interfaces;
|
||
|
using UnityEngine;
|
||
|
using Random = UnityEngine.Random;
|
||
|
|
||
|
namespace BlueWater.Items
|
||
|
{
|
||
|
[Serializable]
|
||
|
public class ItemDropTable : IIdx
|
||
|
{
|
||
|
[field: SerializeField, Tooltip("드랍 테이블 인덱스")]
|
||
|
public int Idx { get; set; }
|
||
|
|
||
|
[field: SerializeField, Tooltip("드랍 테이블 이름")]
|
||
|
public string Name { get; set; }
|
||
|
|
||
|
[field: SerializeField]
|
||
|
public int ItemIdx1 { get; set; }
|
||
|
[field: SerializeField]
|
||
|
public int ItemProb1 { get; set; }
|
||
|
[field: SerializeField]
|
||
|
public int ItemMin1 { get; set; }
|
||
|
[field: SerializeField]
|
||
|
public int ItemMax1 { get; set; }
|
||
|
|
||
|
[field: SerializeField]
|
||
|
public int ItemIdx2 { get; set; }
|
||
|
[field: SerializeField]
|
||
|
public int ItemProb2 { get; set; }
|
||
|
[field: SerializeField]
|
||
|
public int ItemMin2 { get; set; }
|
||
|
[field: SerializeField]
|
||
|
public int ItemMax2 { get; set; }
|
||
|
|
||
|
[field: SerializeField]
|
||
|
public int ItemIdx3 { get; set; }
|
||
|
[field: SerializeField]
|
||
|
public int ItemProb3 { get; set; }
|
||
|
[field: SerializeField]
|
||
|
public int ItemMin3 { get; set; }
|
||
|
[field: SerializeField]
|
||
|
public int ItemMax3 { get; set; }
|
||
|
|
||
|
[field: SerializeField]
|
||
|
public int ItemIdx4 { get; set; }
|
||
|
[field: SerializeField]
|
||
|
public int ItemProb4 { get; set; }
|
||
|
[field: SerializeField]
|
||
|
public int ItemMin4 { get; set; }
|
||
|
[field: SerializeField]
|
||
|
public int ItemMax4 { get; set; }
|
||
|
|
||
|
[field: SerializeField, Tooltip("설명"), TextArea(3, 10)]
|
||
|
public string Description { get; set; }
|
||
|
|
||
|
public List<ItemSlot> GetDroppedItemList()
|
||
|
{
|
||
|
var newItemSlotList = new List<ItemSlot>();
|
||
|
|
||
|
CheckAndAddItem(newItemSlotList, ItemIdx1, ItemProb1, ItemMin1, ItemMax1);
|
||
|
CheckAndAddItem(newItemSlotList, ItemIdx2, ItemProb2, ItemMin2, ItemMax2);
|
||
|
CheckAndAddItem(newItemSlotList, ItemIdx3, ItemProb3, ItemMin3, ItemMax3);
|
||
|
CheckAndAddItem(newItemSlotList, ItemIdx4, ItemProb4, ItemMin4, ItemMax4);
|
||
|
|
||
|
return newItemSlotList;
|
||
|
}
|
||
|
|
||
|
private void CheckAndAddItem(List<ItemSlot> itemSlotList, int itemIdx, int probability, int min, int max)
|
||
|
{
|
||
|
if (itemIdx == 0) return;
|
||
|
|
||
|
var dropChance = Random.Range(0, 101);
|
||
|
if (dropChance > probability) return;
|
||
|
|
||
|
var randomCount = Random.Range(min, max + 1);
|
||
|
itemSlotList.Add(new ItemSlot(itemIdx, randomCount));
|
||
|
}
|
||
|
}
|
||
|
}
|