File size: 3,696 Bytes
24b81cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
class QuantityConversions
{
static string GetItemQuantityText( EntityAI item, bool showMax = false )
{
string quantity_text = "";
if ( item.IsInherited( InventoryItem) )
{
ItemBase item_base;
Class.CastTo(item_base, item);
float quantity = item_base.GetQuantity();
int ammo;
if ( item.IsMagazine() )
{
Magazine magazine_item;
Class.CastTo(magazine_item, item);
ammo = magazine_item.GetAmmoCount();
return ammo.ToString();
}
else if ( item.IsInherited( ItemBook) )
{
return "";
}
int stack_max = item.GetQuantityMax();
//int max = item.ConfigGetInt("varQuantityMax");
//string unit = item.ConfigGetString("stackedUnit");
if (stack_max > 0)
{
if (stack_max == 1)
{
if (quantity > 1)
{
if (showMax)
quantity_text = string.Format("%1/%2", quantity.ToString(), stack_max.ToString() );
//quantity_text = string.Format("%i/%i", quantity, stack_max );
else
quantity_text = quantity.ToString();
}
else
{
quantity_text = "";
}
}
else
{
if (showMax)
quantity_text = string.Format("%1/%2", quantity.ToString(), stack_max.ToString() );
//quantity_text = string.Format("%i/%i", quantity, stack_max );
else
quantity_text = quantity.ToString();
// if (unit == "ml")
// {
// float liters = round(quantity / 1000.0);
// if ( quantity < 2000 )
// {
// liters = ( round( (quantity / 100.0) ) ) / 10;
// }
// quantity_text = ftoa(liters) + "l";
// }
// else
// {
// quantity_text = itoa(quantity) + unit;
// }
}
}
}
return quantity_text;
}
static float GetItemQuantity(InventoryItem item)
{
float quantity = 0;
if ( item.IsInherited(InventoryItem))
{
ItemBase item_base;
Class.CastTo(item_base, item);
if (item_base)
{
if (item.IsMagazine())
{
Magazine magazine_item;
Class.CastTo(magazine_item, item);
quantity = magazine_item.GetAmmoCount();
}
else
{
quantity = item_base.GetQuantity();
}
}
}
return quantity;
}
static float GetItemQuantityMax(InventoryItem item)
{
float quantity = 0;
if (item.IsInherited(InventoryItem))
{
ItemBase item_base;
Class.CastTo(item_base, item);
if (item_base)
{
if (item.IsMagazine())
{
Magazine magazine_item;
Class.CastTo(magazine_item, item);
quantity = magazine_item.GetAmmoMax();
}
else
{
quantity = item_base.GetQuantityMax();
}
}
}
return quantity;
}
static void GetItemQuantity( InventoryItem item, out float q_cur, out float q_min, out float q_max )
{
if ( item.IsInherited( InventoryItem ) )
{
ItemBase item_base;
Class.CastTo(item_base, item);
if ( item.IsMagazine() )
{
Magazine magazine_item;
Class.CastTo(magazine_item, item);
q_cur = magazine_item.GetAmmoCount();
q_min = 0;
q_max = magazine_item.GetAmmoMax();
}
else
{
q_cur = item_base.GetQuantity();
q_min = item_base.GetQuantityMin();
q_max = item_base.GetQuantityMax();
}
}
}
static int HasItemQuantity( notnull EntityAI item )
{
ItemBase ib;
if ( Class.CastTo(ib, item) )
{
if ( item.IsMagazine() )
return QUANTITY_COUNT;
if ( !ib.m_CanShowQuantity )
return QUANTITY_HIDDEN;
int max = item.GetQuantityMax();
if ( max > 0 )
{
if ( ib.m_HasQuantityBar )
{
return QUANTITY_PROGRESS;
}
else
{
if (max == 1)
{
return QUANTITY_HIDDEN;
}
else
{
return QUANTITY_COUNT;
}
}
}
}
return QUANTITY_HIDDEN;
}
} |