DataClass.cs 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace SoftKitty.InventoryEngine
  6. {
  7. #region System Class
  8. public enum MouseButtons
  9. {
  10. LeftClick,
  11. RightClick,
  12. MiddleClick
  13. }
  14. public enum AlterKeys
  15. {
  16. LeftCtrl,
  17. LeftShift,
  18. LeftAlt,
  19. None
  20. }
  21. public enum ClickFunctions
  22. {
  23. Use,
  24. Split,
  25. Drop,
  26. MarkFavorite
  27. }
  28. [System.Serializable]
  29. public class ClickSetting
  30. {
  31. public AlterKeys key;
  32. public MouseButtons mouseButton;
  33. public ClickFunctions function;
  34. }
  35. #endregion
  36. #region AttributeClass
  37. [System.Serializable]
  38. public class Attribute {
  39. /// <summary>
  40. /// The key of this attribute. You will need this key to access speficied Attribute from Item class.
  41. /// </summary>
  42. public string key;
  43. /// <summary>
  44. /// The display name of this attribute.
  45. /// </summary>
  46. public string name;
  47. /// <summary>
  48. /// The value string of this attribute
  49. /// </summary>
  50. public string value="";
  51. /// <summary>
  52. /// Whether this attribute a string. For example, an attribute can be the name of the creator, that will make this attribute a string.
  53. /// </summary>
  54. public bool stringValue = false;
  55. /// <summary>
  56. /// Increment value when this attribute leveled up.
  57. /// </summary>
  58. public float upgradeIncrement = 0F;
  59. /// <summary>
  60. /// Whether this attribute should display as bold font and sort before other stats.
  61. /// </summary>
  62. public bool coreStats = false;
  63. /// <summary>
  64. /// Whether this attribute visible in the hover information panel.
  65. /// </summary>
  66. public bool visible = true;
  67. /// <summary>
  68. /// Whether this attribute visible in the stats panel.
  69. /// </summary>
  70. public bool visibleInStatsPanel = true;
  71. /// <summary>
  72. /// The display format type in the hover information panel.
  73. /// </summary>
  74. public int displayFormat = 0;
  75. /// <summary>
  76. /// Suffixes string when display this attribute.
  77. /// </summary>
  78. public string suffixes = "";
  79. /// <summary>
  80. /// Whether display compare information for this attribute in mouse hover information panel.
  81. /// </summary>
  82. public bool compareInfo = true;
  83. /// <summary>
  84. /// Random chance to unlock this attribute when item being created.
  85. /// </summary>
  86. public int randomChange = 100;
  87. /// <summary>
  88. /// Whether this attribute is Locked, locked attribute is not valid and invisible.
  89. /// </summary>
  90. public bool locked = false;
  91. /// <summary>
  92. /// Whether this attribute has fixed value.
  93. /// </summary>
  94. public bool isFixed = true;
  95. /// <summary>
  96. /// The minimal value of this attribute if this attribute has random value.
  97. /// </summary>
  98. public float minValue = 0F;
  99. /// <summary>
  100. /// The maximum value of this attribute if this attribute has random value.
  101. /// </summary>
  102. public float maxValue = 0F;
  103. [HideInInspector]
  104. public bool fold = true;
  105. /// <summary>
  106. /// Get an instance of this attribute.
  107. /// </summary>
  108. /// <returns></returns>
  109. public Attribute Copy()
  110. {
  111. Attribute _newAtt = new Attribute();
  112. _newAtt.key = key;
  113. _newAtt.name = name;
  114. _newAtt.value = value;
  115. _newAtt.stringValue = stringValue;
  116. _newAtt.upgradeIncrement = upgradeIncrement;
  117. _newAtt.visible = visible;
  118. _newAtt.locked = locked;
  119. _newAtt.randomChange = randomChange;
  120. _newAtt.minValue = minValue;
  121. _newAtt.maxValue = maxValue;
  122. _newAtt.displayFormat = displayFormat;
  123. _newAtt.suffixes = suffixes;
  124. _newAtt.coreStats = coreStats;
  125. _newAtt.compareInfo = compareInfo;
  126. _newAtt.visibleInStatsPanel = visibleInStatsPanel;
  127. _newAtt.isFixed = isFixed;
  128. return _newAtt;
  129. }
  130. /// <summary>
  131. /// Whether this attribute numberical
  132. /// </summary>
  133. /// <returns></returns>
  134. public bool isNumber()
  135. {
  136. return !stringValue;
  137. }
  138. /// <summary>
  139. /// When creating an item, call this to decide wether this attribute should be locked.
  140. /// </summary>
  141. public void Init()
  142. {
  143. if (isFixed)
  144. {
  145. locked = false;
  146. }
  147. else
  148. {
  149. locked = (Random.Range(0, 100) > randomChange);
  150. if(!stringValue)value = Random.Range(minValue,maxValue).ToString("0.0");
  151. }
  152. }
  153. /// <summary>
  154. /// Retrieve the float value of this attribute.
  155. /// </summary>
  156. /// <param name="_upgradeLevel"></param>
  157. /// <returns></returns>
  158. public float GetFloat(int _upgradeLevel = 0)
  159. {
  160. if (stringValue || (locked && !isFixed)) return 0F;
  161. float _result = 0F;
  162. float.TryParse(value, out _result);
  163. _result += upgradeIncrement * _upgradeLevel;
  164. return _result;
  165. }
  166. /// <summary>
  167. /// Retrieve the int value of this attribute.
  168. /// </summary>
  169. /// <param name="_upgradeLevel"></param>
  170. /// <returns></returns>
  171. public int GetInt(int _upgradeLevel = 0)
  172. {
  173. if (stringValue || (locked && !isFixed)) return 0;
  174. int _result = 0;
  175. int.TryParse(value, out _result);
  176. _result += Mathf.FloorToInt(upgradeIncrement * _upgradeLevel);
  177. return _result;
  178. }
  179. /// <summary>
  180. /// Retrieve the string value of this attribute.
  181. /// </summary>
  182. /// <returns></returns>
  183. public string GetString()
  184. {
  185. if (locked && !isFixed) return "None";
  186. return value;
  187. }
  188. /// <summary>
  189. /// Change the value of this attribute.
  190. /// </summary>
  191. /// <param name="_value"></param>
  192. public void UpdateValue(float _value)
  193. {
  194. value = _value.ToString();
  195. }
  196. /// <summary>
  197. /// Change the value of this attribute.
  198. /// </summary>
  199. /// <param name="_value"></param>
  200. public void UpdateValue(int _value)
  201. {
  202. value = _value.ToString();
  203. }
  204. /// <summary>
  205. /// Change the value of this attribute.
  206. /// </summary>
  207. /// <param name="_value"></param>
  208. public void UpdateValue(string _value)
  209. {
  210. value = _value;
  211. }
  212. }
  213. #endregion
  214. #region Enchantment Class
  215. [System.Serializable]
  216. public class Enchantment
  217. {
  218. /// <summary>
  219. /// The unique id of this Enchantment.
  220. /// </summary>
  221. public int uid;
  222. /// <summary>
  223. /// The display name of this Enchantment.
  224. /// </summary>
  225. public string name;
  226. /// <summary>
  227. /// The prefixes string of this Enchantment, the prefixes string will be displayed in the front of the item name.
  228. /// </summary>
  229. public string prefixes="";
  230. /// <summary>
  231. /// Only one prefixes string with highest priority will be displayed if an item has multiple enchantments.
  232. /// </summary>
  233. public int prefixesPriority = 0;
  234. /// <summary>
  235. /// The suffixes string of this Enchantment, the suffixes string will be displayed in the end of the item name.
  236. /// </summary>
  237. public string suffixes="";
  238. /// <summary>
  239. /// Only one suffixes string with highest priority will be displayed if an item has multiple enchantments.
  240. /// </summary>
  241. public int suffixesPriority = 0;
  242. /// <summary>
  243. /// The attributes list this enchantment will add to the item.
  244. /// </summary>
  245. public List<Attribute> attributes=new List<Attribute>();
  246. [HideInInspector]
  247. public bool fold = true;
  248. /// <summary>
  249. /// Get the description string of this enchantment, will looks like "[Deadly] Attack +10 Speed +5"
  250. /// </summary>
  251. /// <returns></returns>
  252. public string GetDescription()
  253. {
  254. string _result = "[<color=#" + ColorUtility.ToHtmlStringRGB(ItemManager.instance.EnchantingNameColor) + ">"+ name + "</color>] ";
  255. foreach(var obj in attributes) {
  256. _result += "<color=#" + ColorUtility.ToHtmlStringRGB(ItemManager.instance.AttributeNameColor) + ">" + obj.name + "</color>"+ (obj.GetFloat() > 0 ? " + " : " ") + obj.value+" ";
  257. }
  258. return _result;
  259. }
  260. }
  261. #endregion
  262. #region Currency Class
  263. [System.Serializable]
  264. public class Currency
  265. {
  266. /// <summary>
  267. /// The display name of this currency.
  268. /// </summary>
  269. public string name;
  270. /// <summary>
  271. /// The icon sprite of this currency.
  272. /// </summary>
  273. public Sprite icon;
  274. /// <summary>
  275. /// The value text color of this currency.
  276. /// </summary>
  277. public Color color;
  278. /// <summary>
  279. /// The exchange rate settings of this currency.
  280. /// x: the target currency id | y: the exchange rate | z: 0= Disable auto exchange 1=Enable auto exchange
  281. /// </summary>
  282. public List<Vector3> ExchangeRate=new List<Vector3>();
  283. public bool fold = true;
  284. }
  285. [System.Serializable]
  286. public class CurrencySet
  287. {
  288. public List<int> Currency = new List<int>();
  289. public bool KeepPostive = true;
  290. public CurrencySet(){
  291. Currency = new List<int>();
  292. }
  293. public CurrencySet(List<int> _value)
  294. {
  295. Currency = new List<int>();
  296. Init(_value.ToArray());
  297. }
  298. public CurrencySet(int [] _value)
  299. {
  300. Currency = new List<int>();
  301. Init(_value);
  302. }
  303. /// <summary>
  304. /// Copy the data of this instance so you can assign it to another instance.
  305. /// </summary>
  306. /// <returns></returns>
  307. public CurrencySet Copy()
  308. {
  309. CurrencySet _copy = new CurrencySet();
  310. _copy.Currency = new List<int>();
  311. for (int i = 0; i < Currency.Count; i++)
  312. {
  313. _copy.Currency.Add(Currency[i]);
  314. }
  315. return _copy;
  316. }
  317. /// <summary>
  318. /// Add a new currency.
  319. /// </summary>
  320. /// <param name="_value"></param>
  321. public void Add(int _value)
  322. {
  323. Currency.Add(_value);
  324. }
  325. /// <summary>
  326. /// Get the count of currency list.
  327. /// </summary>
  328. public int Count
  329. {
  330. get
  331. {
  332. return Currency.Count;
  333. }
  334. }
  335. /// <summary>
  336. /// Get the array of currency values.
  337. /// </summary>
  338. /// <returns></returns>
  339. public int[] GetCurrencyArray()
  340. {
  341. return Currency.ToArray();
  342. }
  343. public void Init()
  344. {
  345. for (int i = 0; i < ItemManager.instance.currencies.Count; i++)
  346. {
  347. if (Currency.Count <= i)
  348. {
  349. Currency.Add(0);
  350. }
  351. }
  352. }
  353. public void Init(int [] _currency)
  354. {
  355. Init();
  356. for (int i = 0; i < _currency.Length; i++)
  357. {
  358. if (Currency.Count < i + 1)
  359. Currency.Add(_currency[i]);
  360. else
  361. Currency[i] = _currency[i];
  362. }
  363. }
  364. public void Reset()
  365. {
  366. Currency = new List<int>();
  367. }
  368. /// <summary>
  369. /// Get the exchange rate from _source to _target.
  370. /// </summary>
  371. /// <param name="_source"></param>
  372. /// <param name="_target"></param>
  373. /// <param name="_onlyAutoExchange"></param>
  374. /// <returns></returns>
  375. private int GetExchangeRate(int _source, int _target, bool _onlyAutoExchange = false)
  376. {
  377. for (int i = 0; i < ItemManager.instance.currencies[_target].ExchangeRate.Count; i++)
  378. {
  379. if (Mathf.FloorToInt(ItemManager.instance.currencies[_target].ExchangeRate[i].x) == _source
  380. && (!_onlyAutoExchange || ItemManager.instance.currencies[_target].ExchangeRate[i].z > 0F))
  381. {
  382. return Mathf.FloorToInt(ItemManager.instance.currencies[_target].ExchangeRate[i].y);
  383. }
  384. }
  385. return 0;
  386. }
  387. /// <summary>
  388. /// Retrieves the currency value by its index number, Set _includeExchangedValue to true if you want to get the total amount of this currency including the exchanged value from other currencies.
  389. /// </summary>
  390. /// <param name="_type"></param>
  391. /// <param name="_includeExchangedValue"></param>
  392. /// <returns></returns>
  393. public int GetCurrency(int _type, bool _includeExchangedValue = false)
  394. {
  395. if (_type < Currency.Count)
  396. {
  397. int _value = Currency[_type];
  398. if (_includeExchangedValue)
  399. {
  400. for (int i = 0; i < Currency.Count; i++)
  401. {
  402. if (_type != i && GetExchangeRate(_type, i) > 0)
  403. {
  404. _value += GetExchangeRate(_type, i) * GetCurrency(i, true);
  405. }
  406. }
  407. }
  408. return _value;
  409. }
  410. else
  411. return 0;
  412. }
  413. /// <summary>
  414. /// Adds to the currency value by its index number. The _add value can be negative.
  415. /// </summary>
  416. /// <param name="_type"></param>
  417. /// <param name="_add"></param>
  418. public void AddCurrency(int _type, int _add)
  419. {
  420. if (_type < Currency.Count)
  421. {
  422. Currency[_type] += _add;
  423. }
  424. else
  425. {
  426. for (int i = Currency.Count; i < _type; i++)
  427. {
  428. Currency.Add(0);
  429. }
  430. Currency.Add(_add);
  431. }
  432. AutoExchange(_type);
  433. }
  434. /// <summary>
  435. /// Overrides the currency value by its index number.
  436. /// </summary>
  437. /// <param name="_type"></param>
  438. /// <param name="_value"></param>
  439. public void SetCurrency(int _type, int _value)
  440. {
  441. if (_type < Currency.Count)
  442. {
  443. Currency[_type] = _value;
  444. }
  445. else
  446. {
  447. for (int i = Currency.Count; i < _type; i++)
  448. {
  449. Currency.Add(0);
  450. }
  451. Currency.Add(_value);
  452. }
  453. AutoExchange(_type);
  454. }
  455. /// <summary>
  456. /// Exchange all currencies into higher value currency if possible.
  457. /// </summary>
  458. public void AutoExchange()
  459. {
  460. for (int u = 0; u < Currency.Count; u++)
  461. {
  462. for (int i = 0; i < Currency.Count; i++)
  463. {
  464. AutoExchange(i);
  465. }
  466. }
  467. }
  468. /// <summary>
  469. /// Collapse specified currency by its index number into lowest value currency.
  470. /// </summary>
  471. /// <param name="_type"></param>
  472. public void CollapseToLowestCurrency(int _type)
  473. {
  474. for (int u = 0; u < ItemManager.instance.currencies[_type].ExchangeRate.Count; u++)
  475. {
  476. int _target = Mathf.FloorToInt(ItemManager.instance.currencies[_type].ExchangeRate[u].x);
  477. if (ItemManager.instance.currencies[_type].ExchangeRate[u].z > 0F
  478. && ItemManager.instance.currencies[_type].ExchangeRate[u].y > 0F
  479. && _target != _type
  480. && Currency[_type] > 0)
  481. {
  482. Currency[_target] += Mathf.FloorToInt(Currency[_type] * ItemManager.instance.currencies[_type].ExchangeRate[u].y);
  483. Currency[_type] = 0;
  484. CollapseToLowestCurrency(_type);
  485. }
  486. }
  487. }
  488. /// <summary>
  489. /// Collapse all currencies into lowest value currency.
  490. /// </summary>
  491. public void CollapseAllToLowestCurrenc()
  492. {
  493. for (int i = 0; i < Currency.Count; i++) CollapseToLowestCurrency(i);
  494. }
  495. /// <summary>
  496. /// Exchange specified currencies into higher value currency if possible.
  497. /// </summary>
  498. /// <param name="_type"></param>
  499. private void AutoExchange(int _type)
  500. {
  501. if (Currency[_type] == 0) return;
  502. for (int i = 0; i < Currency.Count; i++)
  503. {
  504. if (i != _type)
  505. {
  506. int _rate = GetExchangeRate(_type, i, true);
  507. if (Currency[_type] > 0)
  508. {
  509. if (Currency[_type] >= _rate && _rate > 0)
  510. {
  511. int _exchangeAmount = Mathf.FloorToInt(Currency[_type] * 1F / _rate);
  512. Currency[_type] = Currency[_type] % _rate;
  513. AddCurrency(i, _exchangeAmount);
  514. }
  515. }
  516. else
  517. {
  518. if (_rate > 0)
  519. {
  520. float _amount = -Currency[_type] * 1F / _rate;
  521. int _exchangeAmount = KeepPostive? Mathf.CeilToInt(_amount): Mathf.FloorToInt(_amount);
  522. Currency[_type] += _exchangeAmount * _rate;
  523. AddCurrency(i, -_exchangeAmount);
  524. }
  525. }
  526. }
  527. }
  528. }
  529. }
  530. #endregion
  531. #region Item Class
  532. [System.Serializable]
  533. public class Item
  534. {
  535. /// <summary>
  536. /// The unique id of this Item, in most scenarios you will need this uid to access an item.
  537. /// </summary>
  538. public int uid;
  539. /// <summary>
  540. /// The display name of this Item.
  541. /// </summary>
  542. public string name;
  543. /// <summary>
  544. /// The description text of this Item.
  545. /// </summary>
  546. public string description;
  547. /// <summary>
  548. /// The category index of this item. You can manage the categories on the "InventoryEngine" prefab.
  549. /// </summary>
  550. public int type;
  551. /// <summary>
  552. /// The icon texture of this item.
  553. /// </summary>
  554. public Texture2D icon;
  555. /// <summary>
  556. /// The quality index of this item. You can mange the quality levels on the "InventoryEngine" prefab.
  557. /// </summary>
  558. public int quality = 0;
  559. /// <summary>
  560. /// Whether this item is tradable with NPC merchant.
  561. /// </summary>
  562. public bool tradeable = true;
  563. /// <summary>
  564. /// Whether this item is deletable when drag out from inventory.
  565. /// </summary>
  566. public bool deletable = true;
  567. /// <summary>
  568. /// Whether this item is useable when right click or triggered from hot bar.
  569. /// </summary>
  570. public bool useable = false;
  571. /// <summary>
  572. /// Whether this item will be consumed when use.
  573. /// </summary>
  574. public bool consumable = false;
  575. /// <summary>
  576. /// Whether this item is visible on the interface. If an item is not visible, it wll be put into HiddenStacks of InventoryHolder component.
  577. /// </summary>
  578. public bool visible = true;
  579. /// <summary>
  580. /// The base price of this item when trading.
  581. /// </summary>
  582. public int price = 0;
  583. /// <summary>
  584. /// The currency index of the trading price.
  585. /// </summary>
  586. public int currency = 0;
  587. /// <summary>
  588. /// The maximum number this item can be stack.
  589. /// </summary>
  590. public int maxiumStack = 99;
  591. /// <summary>
  592. /// The enchancement level of this item.
  593. /// </summary>
  594. public int upgradeLevel = 0;
  595. /// <summary>
  596. /// The weight value of this item.
  597. /// </summary>
  598. public float weight = 0.1F;
  599. /// <summary>
  600. /// The drop rate of this item (0~100)%
  601. /// </summary>
  602. public int dropRates = 0;
  603. /// <summary>
  604. /// Whether this item is in player's favorite list.
  605. /// </summary>
  606. public bool favorite = false;
  607. /// <summary>
  608. /// The attributes list of this item,
  609. /// </summary>
  610. public List<Attribute> attributes = new List<Attribute>();
  611. /// <summary>
  612. /// Maximum number of random attributes this item can have.
  613. /// </summary>
  614. public int maximumRandomAttributes = 5;
  615. /// <summary>
  616. /// The enchantments list of this item.
  617. /// </summary>
  618. public List<int> enchantments = new List<int>();
  619. /// <summary>
  620. /// The materials list required to craft this item.
  621. /// </summary>
  622. public List<Vector2> craftMaterials = new List<Vector2>();
  623. /// <summary>
  624. /// The action string list of this item.
  625. /// </summary>
  626. public List<string> actions = new List<string>();
  627. /// <summary>
  628. /// The tag string list of this item.
  629. /// </summary>
  630. public List<string> tags = new List<string>();
  631. /// <summary>
  632. /// Custom data. You could use them to link audio clips, prefabs, images, etc.
  633. /// </summary>
  634. public List<CustomField> customData = new List<CustomField>();
  635. public float lastUseTimeStamp = 0F;
  636. /// <summary>
  637. /// The attribute key for use/equip restriction.
  638. /// </summary>
  639. public string restrictionKey;
  640. /// <summary>
  641. /// The attribute value for use/equip restriction.
  642. /// </summary>
  643. public int restrictionValue;
  644. /// <summary>
  645. /// The socketing slots number, if Socketing module is enabled, player will be able to socketing other items with specified tag and category into this item to boost its attributes.
  646. /// </summary>
  647. public int socketingSlots = 0;
  648. /// <summary>
  649. /// The list of socketed items, if Socketing module is enabled, player will be able to socketing other items with specified tag and category into this item to boost its attributes.
  650. /// When the value of the list is -2, means this socket is locked, if it is -1 means this socket is empty, any number larger or equal to 0 represents the uid of this item.
  651. /// </summary>
  652. public List<int> socketedItems = new List<int>();
  653. /// <summary>
  654. /// This item will only recieve skocketing items with any tag in this list.
  655. /// </summary>
  656. public List<string> socketingTag = new List<string>();
  657. /// <summary>
  658. /// Retrieve the item display name with prefixes and suffixes.
  659. /// </summary>
  660. public string nameWithAffixing
  661. {
  662. get
  663. {
  664. string _prefixes = "";
  665. string _suffixes = "";
  666. int _prefixesLevel = -1;
  667. int _suffixesLevel = -1;
  668. foreach (var obj in enchantments) {
  669. if (ItemManager.enchantmentDic[obj].prefixesPriority> _prefixesLevel && ItemManager.enchantmentDic[obj].prefixes!="") {
  670. _prefixes = "<color=#"+ ColorUtility.ToHtmlStringRGB(ItemManager.instance.EnchantingPrefixesColor)+">"+ ItemManager.enchantmentDic[obj].prefixes+"</color> ";
  671. _prefixesLevel = ItemManager.enchantmentDic[obj].prefixesPriority;
  672. }
  673. if (ItemManager.enchantmentDic[obj].suffixesPriority > _suffixesLevel && ItemManager.enchantmentDic[obj].suffixes != "")
  674. {
  675. _suffixes = " <color=#" + ColorUtility.ToHtmlStringRGB(ItemManager.instance.EnchantingSuffxesColor) + ">" + ItemManager.enchantmentDic[obj].suffixes + "</color>";
  676. _suffixesLevel = ItemManager.enchantmentDic[obj].suffixesPriority;
  677. }
  678. }
  679. return _prefixes + nameWithColorCode + _suffixes;
  680. }
  681. }
  682. public string nameWithColorCode
  683. {
  684. get
  685. {
  686. return ItemManager.instance.UseQualityColorForItemName ? ("<color=#" + ColorUtility.ToHtmlStringRGB(GetQualityColor()) + ">" + name + "</color>") : name;
  687. }
  688. }
  689. public string compiledDescription
  690. {
  691. get
  692. {
  693. string _result = description.Replace("<br>","\n");
  694. Dictionary<string, Attribute> _attDic = new Dictionary<string, Attribute>();
  695. foreach (var att in attributes) {
  696. if (!_attDic.ContainsKey(att.key))
  697. {
  698. _attDic.Add(att.key, att.Copy());
  699. }
  700. else
  701. {
  702. if (!att.stringValue)
  703. {
  704. _attDic[att.key].UpdateValue(_attDic[att.key].GetFloat()+ att.GetFloat());
  705. }
  706. }
  707. }
  708. int _index = 0;
  709. while(_index<_result.Length) {
  710. int _startIndex = _result.IndexOf("{", _index);
  711. int _endIndex = _result.IndexOf("}", _startIndex>-1?(_startIndex +1):(_index+1));
  712. if (_startIndex > -1 && _endIndex>-1)
  713. {
  714. string _attText = _result.Substring(_startIndex + 1, _endIndex - _startIndex - 1);
  715. if (_attDic.ContainsKey(_attText))
  716. {
  717. _result=_result.Replace(_result.Substring(_startIndex, _endIndex + 1 - _startIndex), _attDic[_attText].GetFloat(upgradeLevel).ToString());
  718. _index = _startIndex + 1;
  719. }
  720. else
  721. {
  722. _index = _endIndex + 1;
  723. }
  724. }
  725. else
  726. {
  727. _index = _result.Length;
  728. }
  729. }
  730. _attDic.Clear();
  731. return _result;
  732. }
  733. }
  734. #if MASTER_CHARACTER_CREATOR
  735. /// <summary>
  736. /// The MCC equipment binding
  737. /// </summary>
  738. [HideInInspector]
  739. public MasterCharacterCreator.EquipmentAppearance equipAppearance=null;
  740. #endif
  741. [HideInInspector]
  742. public bool fold = true;
  743. /// <summary>
  744. /// If you want to create an Item with specified UID, try use: new Item(int _uid);
  745. /// </summary>
  746. public Item()
  747. {
  748. fold = true;
  749. }
  750. /// <summary>
  751. /// Create an Item by the UID of the database on the "InventoryEngine" prefab.
  752. /// When _initializeEnchantments is set to true, depending on your Enchantments settings on the "InventoryEngine" prefab the enchantments of this item could be randomized.
  753. /// When _initializeSocketingSlots is set to true, depending on your Socketing settings on the "InventoryEngine" prefab the socketing slots of this item could be randomized.
  754. /// </summary>
  755. /// <returns></returns>
  756. public Item (int _uid,bool _initializeEnchantments=true, bool _initializeSocketingSlots= true)
  757. {
  758. if (ItemManager.itemDic.ContainsKey(_uid))
  759. {
  760. Item _ref = ItemManager.itemDic[_uid];
  761. uid = _ref.uid;
  762. name = _ref.name;
  763. description = _ref.description;
  764. type = _ref.type;
  765. icon = _ref.icon;
  766. quality = _ref.quality;
  767. tradeable = _ref.tradeable;
  768. deletable = _ref.deletable;
  769. useable = _ref.useable;
  770. consumable = _ref.consumable;
  771. price = _ref.price;
  772. currency = _ref.currency;
  773. maxiumStack = _ref.maxiumStack;
  774. upgradeLevel = _ref.upgradeLevel;
  775. weight = _ref.weight;
  776. dropRates = _ref.dropRates;
  777. favorite = _ref.favorite;
  778. attributes.Clear();
  779. maximumRandomAttributes = _ref.maximumRandomAttributes;
  780. restrictionKey = _ref.restrictionKey;
  781. restrictionValue = _ref.restrictionValue;
  782. lastUseTimeStamp = _ref.lastUseTimeStamp;
  783. int _attCount = 0;
  784. foreach (var att in _ref.attributes)
  785. {
  786. Attribute _newAtt = att.Copy();
  787. _newAtt.Init();
  788. if(att.randomChange >= 100 || _attCount< maximumRandomAttributes)attributes.Add(_newAtt);
  789. if (att.randomChange < 100 && !_newAtt.locked) _attCount++;
  790. }
  791. craftMaterials.Clear();
  792. craftMaterials.AddRange(_ref.craftMaterials);
  793. enchantments.Clear();
  794. enchantments.AddRange(_ref.enchantments);
  795. actions.Clear();
  796. actions.AddRange(_ref.actions);
  797. tags.Clear();
  798. tags.AddRange(_ref.tags);
  799. socketingTag.Clear();
  800. socketingTag.AddRange(_ref.socketingTag);
  801. socketingSlots = _ref.socketingSlots;
  802. socketedItems = new List<int>();
  803. socketedItems.AddRange(_ref.socketedItems);
  804. customData.Clear();
  805. customData.AddRange(_ref.customData);
  806. if (_initializeEnchantments) RandomEnchantment();
  807. if (_initializeSocketingSlots) ResetocketingSlots();
  808. #if MASTER_CHARACTER_CREATOR
  809. equipAppearance= new MasterCharacterCreator.EquipmentAppearance();
  810. equipAppearance.Type = _ref.equipAppearance.Type;
  811. equipAppearance.UseCustomColor = _ref.equipAppearance.UseCustomColor;
  812. equipAppearance.CustomColor1 = _ref.equipAppearance.CustomColor1;
  813. equipAppearance.CustomColor2 = _ref.equipAppearance.CustomColor2;
  814. equipAppearance.CustomColor3 = _ref.equipAppearance.CustomColor3;
  815. equipAppearance.MaleMeshId = _ref.equipAppearance.MaleMeshId;
  816. equipAppearance.FemaleMeshId = _ref.equipAppearance.FemaleMeshId;
  817. equipAppearance.uiFold = _ref.equipAppearance.uiFold;
  818. #endif
  819. fold = true;
  820. }
  821. else
  822. {
  823. Debug.LogError("Using invalid Item UID when creating a new item.");
  824. }
  825. }
  826. /// <summary>
  827. /// Get an instance of this item data.
  828. /// When _initializeEnchantments is set to true, depending on your Enchantments settings on the "InventoryEngine" prefab the enchantments of this item could be randomized.
  829. /// When _initializeSocketingSlots is set to true, depending on your Socketing settings on the "InventoryEngine" prefab the socketing slots of this item could be randomized.
  830. /// </summary>
  831. /// <returns></returns>
  832. public Item Copy()
  833. {
  834. Item _newItem = new Item();
  835. _newItem.uid = uid;
  836. _newItem.name = name;
  837. _newItem.description = description;
  838. _newItem.type = type;
  839. _newItem.icon = icon;
  840. _newItem.quality = quality;
  841. _newItem.tradeable = tradeable;
  842. _newItem.deletable = deletable;
  843. _newItem.useable = useable;
  844. _newItem.consumable = consumable;
  845. _newItem.price = price;
  846. _newItem.currency = currency;
  847. _newItem.maxiumStack = maxiumStack;
  848. _newItem.upgradeLevel = upgradeLevel;
  849. _newItem.weight = weight;
  850. _newItem.dropRates = dropRates;
  851. _newItem.favorite = favorite;
  852. _newItem.restrictionKey = restrictionKey;
  853. _newItem.restrictionValue = restrictionValue;
  854. _newItem.maximumRandomAttributes = maximumRandomAttributes;
  855. _newItem.lastUseTimeStamp = lastUseTimeStamp;
  856. _newItem.attributes.Clear();
  857. foreach (var att in attributes)
  858. {
  859. _newItem.attributes.Add(att.Copy());
  860. }
  861. _newItem.craftMaterials.Clear();
  862. _newItem.craftMaterials.AddRange(craftMaterials);
  863. _newItem.enchantments.Clear();
  864. _newItem.enchantments.AddRange(enchantments);
  865. _newItem.actions.Clear();
  866. _newItem.actions.AddRange(actions);
  867. _newItem.tags.Clear();
  868. _newItem.tags.AddRange(tags);
  869. _newItem.socketingSlots = socketingSlots;
  870. _newItem.socketedItems = new List<int>();
  871. _newItem.socketedItems.AddRange(socketedItems);
  872. _newItem.socketingTag.Clear();
  873. _newItem.socketingTag.AddRange(socketingTag);
  874. _newItem.customData.Clear();
  875. _newItem.customData.AddRange(customData);
  876. #if MASTER_CHARACTER_CREATOR
  877. _newItem.equipAppearance= new MasterCharacterCreator.EquipmentAppearance();
  878. _newItem.equipAppearance.Type = equipAppearance.Type;
  879. _newItem.equipAppearance.UseCustomColor = equipAppearance.UseCustomColor;
  880. _newItem.equipAppearance.CustomColor1 = equipAppearance.CustomColor1;
  881. _newItem.equipAppearance.CustomColor2 = equipAppearance.CustomColor2;
  882. _newItem.equipAppearance.CustomColor3 = equipAppearance.CustomColor3;
  883. _newItem.equipAppearance.MaleMeshId = equipAppearance.MaleMeshId;
  884. _newItem.equipAppearance.FemaleMeshId = equipAppearance.FemaleMeshId;
  885. _newItem.equipAppearance.uiFold = equipAppearance.uiFold;
  886. #endif
  887. _newItem.fold = true;
  888. return _newItem;
  889. }
  890. /// <summary>
  891. /// Return whether this item can be use or equip by compare the attribute value of the InventoryHolder with the restriction attribute setting.
  892. /// </summary>
  893. /// <param name="_holder"></param>
  894. /// <returns></returns>
  895. public bool AbleToUse(InventoryHolder _holder)
  896. {
  897. if (restrictionKey != "" && restrictionValue > 0)
  898. return _holder.GetAttributeValue(restrictionKey,true) >= restrictionValue;
  899. else
  900. return true;
  901. }
  902. /// <summary>
  903. /// Get custom data by its key string.
  904. /// </summary>
  905. /// <param name="_key"></param>
  906. /// <returns></returns>
  907. public Object GetCustomData(string _key)
  908. {
  909. foreach (var obj in customData) {
  910. if (obj.key == _key) return obj.value;
  911. }
  912. return null;
  913. }
  914. /// <summary>
  915. /// Get the total cool down time of this item.
  916. /// </summary>
  917. /// <returns></returns>
  918. public float GetCoolDownTime()
  919. {
  920. return GetAttributeFloat(ItemManager.instance.CoolDownAttributeKey);
  921. }
  922. /// <summary>
  923. /// Get the remaining cool down time of this item.
  924. /// </summary>
  925. /// <returns></returns>
  926. public float GetRemainCoolDownTime()
  927. {
  928. return Mathf.Max(0F, lastUseTimeStamp + GetCoolDownTime() - Time.time);
  929. }
  930. /// <summary>
  931. /// Return whether this item is being cool down.
  932. /// </summary>
  933. /// <returns></returns>
  934. public bool isCoolDown()
  935. {
  936. return GetRemainCoolDownTime() > 0F;
  937. }
  938. /// <summary>
  939. /// When the item is used, call this function to set the time stamp.
  940. /// </summary>
  941. public void SetCoolDownTimeStamp()
  942. {
  943. lastUseTimeStamp = Time.time;
  944. }
  945. /// <summary>
  946. /// Override the remaining cool down time.
  947. /// </summary>
  948. /// <param name="_coolDownTime"></param>
  949. public void SetRemainCoolDownTime(float _coolDownTime)
  950. {
  951. lastUseTimeStamp = Time.time - GetCoolDownTime() + _coolDownTime;
  952. }
  953. /// <summary>
  954. /// Add time in seconds to the remaining cool down time, the _addValue can be either postive or negative.
  955. /// </summary>
  956. /// <param name="_addValue"></param>
  957. public void AddRemainCoolDownTime(float _addValue)
  958. {
  959. lastUseTimeStamp = Time.time - (GetCoolDownTime()- GetRemainCoolDownTime())+ _addValue;
  960. }
  961. /// <summary>
  962. /// Get the float value of an Attribute of this item with the attribute key.
  963. /// </summary>
  964. /// <param name="_key"></param>
  965. /// <returns></returns>
  966. public float GetAttributeFloat(string _key)
  967. {
  968. float _result = 0F;
  969. foreach (Attribute att in attributes)
  970. {
  971. if(att.key == _key) _result += att.GetFloat(upgradeLevel);
  972. }
  973. foreach (int _ent in enchantments) {
  974. if (ItemManager.enchantmentDic.ContainsKey(_ent))
  975. {
  976. foreach (Attribute att in ItemManager.enchantmentDic[_ent].attributes) {
  977. if (att.key == _key) _result += att.GetFloat();
  978. }
  979. }
  980. }
  981. foreach (int _socket in socketedItems)
  982. {
  983. if (_socket>=0 && ItemManager.itemDic.ContainsKey(_socket))
  984. {
  985. foreach (Attribute att in ItemManager.itemDic[_socket].attributes)
  986. {
  987. if (att.key == _key) _result += att.GetFloat();
  988. }
  989. }
  990. }
  991. return _result;
  992. }
  993. /// <summary>
  994. /// Get the int value of an Attribute of this item with the attribute key.
  995. /// </summary>
  996. /// <param name="_key"></param>
  997. /// <returns></returns>
  998. public int GetAttributeInt(string _key)
  999. {
  1000. int _result = 0;
  1001. foreach (Attribute att in attributes)
  1002. {
  1003. if (att.key == _key) _result += att.GetInt(upgradeLevel);
  1004. }
  1005. foreach (int _ent in enchantments)
  1006. {
  1007. if (ItemManager.enchantmentDic.ContainsKey(_ent))
  1008. {
  1009. foreach (Attribute att in ItemManager.enchantmentDic[_ent].attributes)
  1010. {
  1011. if (att.key == _key) _result += att.GetInt();
  1012. }
  1013. }
  1014. }
  1015. foreach (int _socket in socketedItems)
  1016. {
  1017. if (_socket >= 0 && ItemManager.itemDic.ContainsKey(_socket))
  1018. {
  1019. foreach (Attribute att in ItemManager.itemDic[_socket].attributes)
  1020. {
  1021. if (att.key == _key) _result += att.GetInt();
  1022. }
  1023. }
  1024. }
  1025. return _result;
  1026. }
  1027. /// <summary>
  1028. /// Get the string value of an Attribute of this item with the attribute key.
  1029. /// </summary>
  1030. /// <param name="_key"></param>
  1031. /// <returns></returns>
  1032. public string GetAttributeString(string _key)
  1033. {
  1034. string _result = "None";
  1035. foreach (Attribute att in attributes)
  1036. {
  1037. if (att.key == _key) _result = att.GetString();
  1038. }
  1039. return _result;
  1040. }
  1041. /// <summary>
  1042. /// Change the value of an Attribute of this item with the attribute key.
  1043. /// </summary>
  1044. /// <param name="_key"></param>
  1045. /// <param name="_value"></param>
  1046. public void UpdateAttribute(string _key, float _value)
  1047. {
  1048. foreach (Attribute att in attributes)
  1049. {
  1050. if (att.key == _key) att.UpdateValue(_value);
  1051. }
  1052. }
  1053. /// <summary>
  1054. /// Change the value of an Attribute of this item with the attribute key.
  1055. /// </summary>
  1056. /// <param name="_key"></param>
  1057. /// <param name="_value"></param>
  1058. public void UpdateAttribute(string _key, int _value)
  1059. {
  1060. foreach (Attribute att in attributes)
  1061. {
  1062. if (att.key == _key) att.UpdateValue(_value);
  1063. }
  1064. }
  1065. /// <summary>
  1066. /// Change the value of an Attribute of this item with the attribute key.
  1067. /// </summary>
  1068. /// <param name="_key"></param>
  1069. /// <param name="_value"></param>
  1070. public void UpdateAttribute(string _key, string _value)
  1071. {
  1072. foreach (Attribute att in attributes)
  1073. {
  1074. if (att.key == _key) att.UpdateValue(_value);
  1075. }
  1076. }
  1077. /// <summary>
  1078. /// Add an Attribute to this item with the attribute key and float value.
  1079. /// </summary>
  1080. /// <param name="_key"></param>
  1081. /// <param name="_value"></param>
  1082. public void AddAttribute(string _key, float _value)
  1083. {
  1084. foreach (Attribute att in ItemManager.instance.itemAttributes)
  1085. {
  1086. if (att.key == _key)
  1087. {
  1088. Attribute _newAtt = att.Copy();
  1089. _newAtt.value = _value.ToString();
  1090. attributes.Add(_newAtt);
  1091. }
  1092. }
  1093. }
  1094. /// <summary>
  1095. /// Add an Attribute to this item with the attribute key and int value.
  1096. /// </summary>
  1097. /// <param name="_key"></param>
  1098. /// <param name="_value"></param>
  1099. public void AddAttribute(string _key, int _value)
  1100. {
  1101. foreach (Attribute att in ItemManager.instance.itemAttributes)
  1102. {
  1103. if (att.key == _key)
  1104. {
  1105. Attribute _newAtt = att.Copy();
  1106. _newAtt.value = _value.ToString();
  1107. attributes.Add(_newAtt);
  1108. }
  1109. }
  1110. }
  1111. /// <summary>
  1112. /// Add an Attribute to this item with the attribute key and string value.
  1113. /// </summary>
  1114. /// <param name="_key"></param>
  1115. /// <param name="_value"></param>
  1116. public void AddAttribute(string _key, string _value)
  1117. {
  1118. foreach (Attribute att in ItemManager.instance.itemAttributes)
  1119. {
  1120. if (att.key == _key)
  1121. {
  1122. Attribute _newAtt = att.Copy();
  1123. _newAtt.value = _value;
  1124. attributes.Add(_newAtt);
  1125. }
  1126. }
  1127. }
  1128. /// <summary>
  1129. /// Remove an Attribute of this item with the attribute key.
  1130. /// </summary>
  1131. /// <param name="_key"></param>
  1132. public void RemoveAttribute(string _key)
  1133. {
  1134. for (int i=0;i<attributes.Count;i++) {
  1135. if (attributes[i].key == _key) attributes.RemoveAt(i);
  1136. }
  1137. }
  1138. /// <summary>
  1139. /// Remove all Attributes of this this item.
  1140. /// </summary>
  1141. public void ClearAttribute()
  1142. {
  1143. attributes.Clear();
  1144. }
  1145. /// <summary>
  1146. /// Retrieve the tag string of this item which contains the specified "_text".
  1147. /// </summary>
  1148. /// <param name="_text"></param>
  1149. /// <param name="_caseSensitive"></param>
  1150. /// <returns></returns>
  1151. public string GetTagContainText(string _text, bool _caseSensitive = true)
  1152. {
  1153. if (!_caseSensitive) _text = _text.ToLower();
  1154. foreach (string obj in tags)
  1155. {
  1156. if (_caseSensitive)
  1157. {
  1158. if (obj.Contains(_text)) return obj;
  1159. }
  1160. else
  1161. {
  1162. if (obj.ToLower().Contains(_text)) return obj;
  1163. }
  1164. }
  1165. return "";
  1166. }
  1167. /// <summary>
  1168. /// Whether any tag of this item contains the specified "_text".
  1169. /// </summary>
  1170. /// <param name="_text"></param>
  1171. /// <param name="_caseSensitive"></param>
  1172. /// <returns></returns>
  1173. public bool isTagContainText(string _text, bool _caseSensitive=true)
  1174. {
  1175. if (!_caseSensitive) _text = _text.ToLower();
  1176. foreach (string obj in tags)
  1177. {
  1178. if (_caseSensitive)
  1179. {
  1180. if (obj.Contains(_text)) return true;
  1181. }
  1182. else
  1183. {
  1184. if (obj.ToLower().Contains(_text)) return true;
  1185. }
  1186. }
  1187. return false;
  1188. }
  1189. /// <summary>
  1190. /// Whether any tag of this item matchs the specified "_tag", "#1","#2","#3" in the tags will be ignored. For example, an item with tag:"Weapon#2" will return true if you call isTagMatchText("Weapon");
  1191. /// </summary>
  1192. /// <param name="_tag"></param>
  1193. /// <returns></returns>
  1194. public bool isTagMatchText(string _tag)
  1195. {
  1196. return tags.Contains(_tag.Replace("#1", "").Replace("#2", "").Replace("#3", ""));
  1197. }
  1198. public bool isTagsMatchList(List<string> _tags, bool _allMatch)
  1199. {
  1200. foreach (string obj in _tags) {
  1201. if (!tags.Contains(obj) && _allMatch) return false;
  1202. if (!_allMatch && tags.Contains(obj)) return true;
  1203. }
  1204. return _allMatch?true:false;
  1205. }
  1206. /// <summary>
  1207. /// Add an enchantment to this item by its UID.
  1208. /// </summary>
  1209. /// <param name="_uid"></param>
  1210. public void AddEnchantment(int _uid)
  1211. {
  1212. if (ItemManager.enchantmentDic.ContainsKey(_uid))
  1213. {
  1214. enchantments.Add(_uid);
  1215. }
  1216. else
  1217. {
  1218. Debug.LogError("Trying to add enchantment with invalid uid.");
  1219. }
  1220. }
  1221. /// <summary>
  1222. /// Replace the enchantments with a new set of enchantments by a list of their UID.
  1223. /// </summary>
  1224. /// <param name="_enchantments"></param>
  1225. public void ReplaceEnchantment(List<int> _enchantments)
  1226. {
  1227. enchantments.Clear();
  1228. for (int i=0;i< _enchantments.Count;i++) {
  1229. AddEnchantment(_enchantments[i]);
  1230. }
  1231. }
  1232. /// <summary>
  1233. /// Remove an enchantment by its UID.
  1234. /// </summary>
  1235. /// <param name="_uid"></param>
  1236. public void RemoveEnchantment(int _uid)
  1237. {
  1238. if (ItemManager.enchantmentDic.ContainsKey(_uid))
  1239. {
  1240. enchantments.Remove(_uid);
  1241. }
  1242. else
  1243. {
  1244. Debug.LogError("Trying to remove enchantment with invalid uid.");
  1245. }
  1246. }
  1247. /// <summary>
  1248. /// Set random enchantments for this item, and return the list of uid. Please note there're chances for no enchantment at all.
  1249. /// </summary>
  1250. /// <returns></returns>
  1251. public List<int> RandomEnchantment()
  1252. {
  1253. if (ItemManager.instance.EnableEnchanting && ItemManager.instance.RandomEnchantmentsForNewItem && type== ItemManager.instance.EnchantingCategoryID && Random.Range(0, 100) < ItemManager.instance.EnchantingSuccessRate)
  1254. {
  1255. List<int> _newEnchantments = new List<int>();
  1256. int _count = Random.Range(Mathf.FloorToInt(ItemManager.instance.EnchantmentNumberRange.x), Mathf.FloorToInt(ItemManager.instance.EnchantmentNumberRange.y));
  1257. for (int i = 0; i < _count; i++)
  1258. {
  1259. int _uid = Random.Range(0, ItemManager.enchantmentDic.Count);
  1260. if (!_newEnchantments.Contains(_uid)) _newEnchantments.Add(_uid);
  1261. }
  1262. ReplaceEnchantment(_newEnchantments);
  1263. return _newEnchantments;
  1264. }
  1265. return enchantments;
  1266. }
  1267. /// <summary>
  1268. /// Remove all enchantments of this item.
  1269. /// </summary>
  1270. public void ResetEnchantment()
  1271. {
  1272. enchantments.Clear();
  1273. }
  1274. /// <summary>
  1275. /// Reset the socketing slots of this item.
  1276. /// </summary>
  1277. public void ResetocketingSlots()
  1278. {
  1279. if (ItemManager.instance.EnableSocketing && type== ItemManager.instance.SocketedCategoryFilter)
  1280. {
  1281. if (ItemManager.instance.RandomSocketingSlotsNummber)
  1282. {
  1283. socketingSlots = Random.Range(ItemManager.instance.MinimalSocketingSlotsNumber, ItemManager.instance.MaxmiumSocketingSlotsNumber);
  1284. socketedItems = new List<int>();
  1285. bool _locked = false;
  1286. for (int i=0;i< socketingSlots;i++) {
  1287. if ((ItemManager.instance.LockSocketingSlotsByDefault && Random.Range(0, 100) < ItemManager.instance.RandomChanceToLockSocketingSlots) || _locked)
  1288. {
  1289. _locked = true;
  1290. socketedItems.Add(-2);
  1291. }
  1292. else
  1293. {
  1294. socketedItems.Add(-1);
  1295. }
  1296. }
  1297. }
  1298. }
  1299. else
  1300. {
  1301. socketingSlots = 0;
  1302. socketedItems = new List<int>();
  1303. }
  1304. }
  1305. /// <summary>
  1306. /// Override the socketed item list.
  1307. /// </summary>
  1308. /// <param name="_sockets"></param>
  1309. public void ReplaceSocketing(List<int> _sockets)
  1310. {
  1311. socketedItems.Clear();
  1312. socketingSlots = _sockets.Count;
  1313. for (int i = 0; i < _sockets.Count; i++)
  1314. {
  1315. socketedItems.Add(_sockets[i]);
  1316. }
  1317. }
  1318. /// <summary>
  1319. /// Reset the enhancement level of this item to 0.
  1320. /// </summary>
  1321. ///
  1322. public void ResetUpgrade()
  1323. {
  1324. upgradeLevel = 0;
  1325. }
  1326. /// <summary>
  1327. /// Pop the enhancement level of this item by 1.
  1328. /// </summary>
  1329. public int Upgrade()
  1330. {
  1331. upgradeLevel++;
  1332. return upgradeLevel;
  1333. }
  1334. /// <summary>
  1335. /// Reset the attributes of this item to match the database.
  1336. /// </summary>
  1337. public void ResetAttributes()
  1338. {
  1339. attributes.Clear();
  1340. Dictionary<string, bool> _attLock = new Dictionary<string, bool>();
  1341. foreach (var obj in attributes)
  1342. {
  1343. if (!_attLock.ContainsKey(obj.key)) _attLock.Add(obj.key, obj.locked);
  1344. }
  1345. foreach (var _att in ItemManager.itemDic[uid].attributes)
  1346. {
  1347. attributes.Add(_att.Copy());
  1348. }
  1349. foreach (var obj in attributes)
  1350. {
  1351. if (_attLock.ContainsKey(obj.key)) obj.locked = _attLock[obj.key];
  1352. }
  1353. _attLock.Clear();
  1354. }
  1355. /// <summary>
  1356. /// Reset all settings of this item to match the database
  1357. /// </summary>
  1358. public void ResetAll()
  1359. {
  1360. price = ItemManager.itemDic[uid].price;
  1361. favorite = false;
  1362. ResetUpgrade();
  1363. ResetAttributes();
  1364. ResetEnchantment();
  1365. ResetocketingSlots();
  1366. }
  1367. /// <summary>
  1368. /// Get the color of the quality level of this item.
  1369. /// </summary>
  1370. /// <returns></returns>
  1371. public Color GetQualityColor()
  1372. {
  1373. if (ItemManager.itemQualityDic.ContainsKey(quality))
  1374. {
  1375. return ItemManager.itemQualityDic[quality].color;
  1376. }
  1377. else return Color.gray;
  1378. }
  1379. /// <summary>
  1380. /// Get the display name of the quality level of this item.
  1381. /// </summary>
  1382. /// <returns></returns>
  1383. public string GetQualityName()
  1384. {
  1385. if (ItemManager.itemQualityDic.ContainsKey(quality))
  1386. {
  1387. return ItemManager.itemQualityDic[quality].name;
  1388. }
  1389. else return "Unknown";
  1390. }
  1391. /// <summary>
  1392. /// Get the color of the category of this item.
  1393. /// </summary>
  1394. /// <returns></returns>
  1395. public Color GetTypeColor()
  1396. {
  1397. if (ItemManager.itemTypesDic.ContainsKey(type))
  1398. {
  1399. return ItemManager.itemTypesDic[type].color;
  1400. }
  1401. else return Color.gray;
  1402. }
  1403. /// <summary>
  1404. /// Get the display name of the category of this item.
  1405. /// </summary>
  1406. /// <returns></returns>
  1407. public string GetTypeName()
  1408. {
  1409. if (ItemManager.itemTypesDic.ContainsKey(type))
  1410. {
  1411. return ItemManager.itemTypesDic[type].name;
  1412. }
  1413. else return "Unknown";
  1414. }
  1415. }
  1416. #endregion
  1417. #region InventoryStack Class
  1418. [System.Serializable]
  1419. public class InventoryStack
  1420. {
  1421. /// <summary>
  1422. /// The Item object in this InventoryStack.
  1423. /// </summary>
  1424. public Item Item;
  1425. /// <summary>
  1426. /// The number of items in this InventoryStack.
  1427. /// </summary>
  1428. public int Number = 0;
  1429. /// <summary>
  1430. /// Wehther this InventoryStack is empty
  1431. /// </summary>
  1432. public bool Empty = true;
  1433. public bool Fold = true;
  1434. public InventoryStack(ItemSave _item)
  1435. {
  1436. if (ItemManager.itemDic.ContainsKey(_item.uid))
  1437. {
  1438. Item = ItemManager.itemDic[_item.uid].Copy();
  1439. Item.upgradeLevel = _item.upgrade;
  1440. Item.enchantments.Clear();
  1441. Item.enchantments.AddRange(_item.enchantments);
  1442. Item.socketedItems.Clear();
  1443. if(_item.socketedItem!=null) Item.socketedItems.AddRange(_item.socketedItem);
  1444. Item.socketingSlots = Item.socketedItems.Count;
  1445. if (_item.attributeLock != null && _item.attributeValue!=null)
  1446. {
  1447. for (int i = 0; i < Mathf.Min(_item.attributeValue.Length, _item.attributeLock.Length, Item.attributes.Count); i++)
  1448. {
  1449. Item.attributes[i].locked = _item.attributeLock[i];
  1450. Item.attributes[i].value = _item.attributeValue[i];
  1451. }
  1452. }
  1453. Item.favorite = _item.fav;
  1454. Number = _item.number;
  1455. Empty = false;
  1456. }
  1457. else
  1458. {
  1459. Item = null;
  1460. Empty = true;
  1461. Number = 0;
  1462. Debug.LogError("Failed to create InventoryItem with invalid item uid!");
  1463. }
  1464. Fold = true;
  1465. }
  1466. public InventoryStack(int _uid, int _number)
  1467. {
  1468. if (ItemManager.itemDic.ContainsKey(_uid))
  1469. {
  1470. Item = ItemManager.itemDic[_uid].Copy();
  1471. Empty = false;
  1472. Number = _number;
  1473. }
  1474. else
  1475. {
  1476. Item = null;
  1477. Empty = true;
  1478. Number = 0;
  1479. Debug.LogError("Failed to create InventoryItem with invalid item uid!");
  1480. }
  1481. Fold = true;
  1482. }
  1483. public InventoryStack(Item _item, int _number)
  1484. {
  1485. if (_item != null)
  1486. Item = _item.Copy();
  1487. else
  1488. Item = null;
  1489. Empty = false;
  1490. Number = _number;
  1491. Fold = true;
  1492. }
  1493. public InventoryStack()
  1494. {
  1495. Empty = true;
  1496. Item = null;
  1497. Number = 0;
  1498. Fold = true;
  1499. }
  1500. /// <summary>
  1501. /// Get an instance of this InventoryStack.
  1502. /// </summary>
  1503. /// <returns></returns>
  1504. public InventoryStack Copy()
  1505. {
  1506. InventoryStack _newStack = new InventoryStack();
  1507. if (Item != null)
  1508. _newStack.Item = Item.Copy();
  1509. else
  1510. _newStack.Item = null;
  1511. _newStack.Number = Number;
  1512. _newStack.Empty = Empty;
  1513. _newStack.Fold = true;
  1514. return _newStack;
  1515. }
  1516. /// <summary>
  1517. /// Merges another InventoryStack (_source) with this one if they contain the same item; otherwise, it swaps them. Returns the resulting stack. You should assign the result to the source.
  1518. /// The resulting stack is what's left after merge.
  1519. /// For example, if an InventoryStack has 80 "HP Potion", and the maxmium stack number of this "HP Potion" is 99, you trying to merge another InventoryStack object with 30 "HP Potion",
  1520. /// it will make this InventoryStack has 99 "HP Potion" and return a new InventoryStack object with 11 "HP Potion".
  1521. /// </summary>
  1522. /// <param name="_source"></param>
  1523. /// <returns></returns>
  1524. public InventoryStack Merge(InventoryStack _source)
  1525. {
  1526. bool _swap = false;
  1527. if (Item != null && !Empty)
  1528. {
  1529. if (Item.uid != _source.Item.uid || Number >= Item.maxiumStack)
  1530. {
  1531. _swap = true;
  1532. }
  1533. }
  1534. else
  1535. {
  1536. _swap = true;
  1537. }
  1538. if (_swap) {
  1539. InventoryStack _mCopy = Copy();
  1540. Item = _source.Item.Copy();
  1541. Number = _source.Number;
  1542. Empty = _source.Empty;
  1543. return _mCopy;
  1544. }
  1545. int _free = Mathf.Max(0, _source.Item.maxiumStack - Number);
  1546. int _add = Mathf.Min(_source.Number, _free);
  1547. AddNumber(_add);
  1548. InventoryStack _result = _source.Copy();
  1549. _result.AddNumber(-_add);
  1550. return _result;
  1551. }
  1552. /// <summary>
  1553. /// Split this InventoryStack into a new InventoryStack object with specified number.
  1554. /// </summary>
  1555. /// <param name="_number"></param>
  1556. /// <returns>Return the new InventoryStack object with specified number split out from this InventoryStack</returns>
  1557. public InventoryStack Split(int _number)
  1558. {
  1559. if (isEmpty() || _number <= 0) return null;
  1560. InventoryStack _split = Copy();
  1561. _number = Mathf.Min(Number, _number);
  1562. _split.OverideNumber(_number);
  1563. AddNumber(-_number);
  1564. return _split;
  1565. }
  1566. /// <summary>
  1567. /// Set the data of this InventoryStack.
  1568. /// </summary>
  1569. /// <param name="_data"></param>
  1570. public void Set(InventoryStack _data)
  1571. {
  1572. if (_data.Item != null)
  1573. Item = _data.Item.Copy();
  1574. else
  1575. Item = null;
  1576. Number = _data.Number;
  1577. Empty = _data.Empty;
  1578. }
  1579. /// <summary>
  1580. /// Get the total weight of the items in this InventoryStack.
  1581. /// </summary>
  1582. /// <returns></returns>
  1583. public float GetWeight()
  1584. {
  1585. if (isEmpty()) return 0F;
  1586. return Item.weight * Number;
  1587. }
  1588. /// <summary>
  1589. /// Returns whether the items in this InventoryStack have the specified tag.
  1590. /// </summary>
  1591. /// <param name="_tag"></param>
  1592. /// <returns></returns>
  1593. public bool isTagMatchText(string _tag)
  1594. {
  1595. if (Item != null)
  1596. return Item.isTagMatchText(_tag);
  1597. else
  1598. return false;
  1599. }
  1600. /// <summary>
  1601. /// Returns whether the tags of this item match the specified tag list.
  1602. /// </summary>
  1603. /// <param name="_tags"></param>
  1604. /// <param name="_allMatch"></param>
  1605. /// <returns></returns>
  1606. public bool isTagsMatchList(List<string> _tags, bool _allMatch = true)
  1607. {
  1608. if (Item == null) return false;
  1609. return Item.isTagsMatchList(_tags, _allMatch);
  1610. }
  1611. /// <summary>
  1612. /// Returns whether the items in this InventoryStack have any tag contains the specified text.
  1613. /// </summary>
  1614. /// <param name="_text"></param>
  1615. /// <param name="_caseSensitive"></param>
  1616. /// <returns></returns>
  1617. public bool isTagContainText(string _text, bool _caseSensitive = true)
  1618. {
  1619. if (Item == null) return false;
  1620. return Item.isTagContainText(_text, _caseSensitive);
  1621. }
  1622. /// <summary>
  1623. /// Returns the tag of the item which contains the specified text.
  1624. /// </summary>
  1625. /// <param name="_text"></param>
  1626. /// <param name="_caseSensitive"></param>
  1627. /// <returns></returns>
  1628. public string GetTagContainText(string _text, bool _caseSensitive = true)
  1629. {
  1630. if (Item == null) return "";
  1631. return Item.GetTagContainText(_text, _caseSensitive);
  1632. }
  1633. /// <summary>
  1634. /// Returns the UID of the items in this InventoryStack. Returns -1 if the stack is empty.
  1635. /// </summary>
  1636. /// <returns></returns>
  1637. public int GetItemId()
  1638. {
  1639. if (Item != null)
  1640. return Item.uid;
  1641. else
  1642. return -1;
  1643. }
  1644. /// <summary>
  1645. /// Returns the category ID of the items in this InventoryStack. Returns _emptyResult if the stack is empty.
  1646. /// </summary>
  1647. /// <param name="_emptyResult"></param>
  1648. /// <returns></returns>
  1649. public int GetType(int _emptyResult=0)
  1650. {
  1651. if (!isEmpty())
  1652. {
  1653. return Item.type;
  1654. }
  1655. else
  1656. {
  1657. return _emptyResult;
  1658. }
  1659. }
  1660. /// <summary>
  1661. /// Returns the upgrade level of the items in this InventoryStack.
  1662. /// </summary>
  1663. /// <returns></returns>
  1664. public int GetUpgradeLevel()
  1665. {
  1666. if (!isEmpty())
  1667. {
  1668. return Item.upgradeLevel;
  1669. }
  1670. else
  1671. {
  1672. return 0;
  1673. }
  1674. }
  1675. /// <summary>
  1676. /// Returns the available space in this stack. For example, if the maximum stack size is 99 and the current quantity is 10, the available space would be 89.
  1677. /// </summary>
  1678. /// <returns></returns>
  1679. public int GetAvailableSpace()
  1680. {
  1681. if (Item != null && !Empty)
  1682. {
  1683. return Mathf.Max(0, Item.maxiumStack - Number);
  1684. }
  1685. else
  1686. {
  1687. return 0;
  1688. }
  1689. }
  1690. /// <summary>
  1691. /// Returns whether the items in this InventoryStack match the provided conditions
  1692. /// </summary>
  1693. /// <param name="_uid"></param>
  1694. /// <param name="_upgradeLevel"></param>
  1695. /// <param name="_enchantments"></param>
  1696. /// <param name="_sockets"></param>
  1697. /// <returns></returns>
  1698. public bool isSameItem(int _uid, int _upgradeLevel,List<int> _enchantments, List<int> _sockets)
  1699. {
  1700. if (!isEmpty())
  1701. {
  1702. return Item.uid == _uid && Item.upgradeLevel == _upgradeLevel
  1703. && Item.enchantments.TrueForAll(_enchantments.Contains) && Item.enchantments.Count == _enchantments.Count
  1704. && Item.socketedItems.TrueForAll(_sockets.Contains) && Item.socketedItems.Count == _sockets.Count;
  1705. }
  1706. else
  1707. {
  1708. return false;
  1709. }
  1710. }
  1711. /// <summary>
  1712. /// Returns whether the items in this InventoryStack match the provided conditions
  1713. /// </summary>
  1714. /// <param name="_uid"></param>
  1715. /// <param name="_upgradeLevel"></param>
  1716. /// <param name="_enchantments"></param>
  1717. /// <returns></returns>
  1718. public bool isSameItem(int _uid, int _upgradeLevel, List<int> _enchantments)
  1719. {
  1720. if (!isEmpty())
  1721. {
  1722. return Item.uid == _uid && Item.upgradeLevel == _upgradeLevel
  1723. && Item.enchantments.TrueForAll(_enchantments.Contains) && Item.enchantments.Count == _enchantments.Count;
  1724. }
  1725. else
  1726. {
  1727. return false;
  1728. }
  1729. }
  1730. /// <summary>
  1731. /// Returns whether the items in this InventoryStack match the provided conditions
  1732. /// </summary>
  1733. /// <param name="_uid"></param>
  1734. /// <param name="_upgradeLevel"></param>
  1735. /// <returns></returns>
  1736. public bool isSameItem(int _uid, int _upgradeLevel)
  1737. {
  1738. if (!isEmpty())
  1739. {
  1740. return Item.uid == _uid && Item.upgradeLevel== _upgradeLevel;
  1741. }
  1742. else
  1743. {
  1744. return false;
  1745. }
  1746. }
  1747. /// <summary>
  1748. /// Returns whether the items in this InventoryStack match the provided conditions
  1749. /// </summary>
  1750. /// <param name="_uid"></param>
  1751. /// <returns></returns>
  1752. public bool isSameItem(int _uid)
  1753. {
  1754. if (!isEmpty())
  1755. {
  1756. return Item.uid == _uid;
  1757. }
  1758. else
  1759. {
  1760. return false;
  1761. }
  1762. }
  1763. /// <summary>
  1764. /// Returns whether this InventoryStack is empty.
  1765. /// </summary>
  1766. /// <returns></returns>
  1767. public bool isEmpty()
  1768. {
  1769. return Item == null || Number <= 0 || Empty;
  1770. }
  1771. /// <summary>
  1772. /// Returns whether the items in this InventoryStack can be merged with the provided item UID.
  1773. /// </summary>
  1774. /// <param name="_uid"></param>
  1775. /// <returns></returns>
  1776. public bool canBeMerged(int _uid)
  1777. {
  1778. if (!isEmpty())
  1779. {
  1780. return Item.uid == _uid;
  1781. }
  1782. else
  1783. {
  1784. return true;
  1785. }
  1786. }
  1787. /// <summary>
  1788. /// Delete the items in this InventoryStack.
  1789. /// </summary>
  1790. public void Delete()
  1791. {
  1792. Empty = true;
  1793. Item = null;
  1794. Number = 0;
  1795. }
  1796. /// <summary>
  1797. /// Overide the number of the items in this InventoryStack.
  1798. /// </summary>
  1799. /// <param name="_number"></param>
  1800. public void OverideNumber(int _number)
  1801. {
  1802. Number = Mathf.Max(0, _number);
  1803. }
  1804. /// <summary>
  1805. /// Add number to the items in this InventoryStack. The added number can be negative.
  1806. /// </summary>
  1807. /// <param name="_number"></param>
  1808. public void AddNumber(int _number)
  1809. {
  1810. Number = Mathf.Max(0, Number + _number);
  1811. }
  1812. /// <summary>
  1813. /// Cosume the items in this InventoryStack. Returns the result of success, if the items in this InventoryStack is not enough to consume, returns false.
  1814. /// </summary>
  1815. /// <param name="_number"></param>
  1816. /// <returns></returns>
  1817. public bool Consume(int _number)
  1818. {
  1819. if (Number >= _number)
  1820. {
  1821. Number -= _number;
  1822. return true;
  1823. }
  1824. else
  1825. {
  1826. return false;
  1827. }
  1828. }
  1829. }
  1830. #endregion
  1831. #region Item Save Data Class
  1832. [System.Serializable]
  1833. public class ItemSave
  1834. {
  1835. public int uid;
  1836. public int upgrade;
  1837. public int number;
  1838. public bool fav=false;
  1839. public int[] enchantments;
  1840. public int[] socketedItem;
  1841. public bool[] attributeLock=new bool[0];
  1842. public string[] attributeValue=new string[0];
  1843. }
  1844. [System.Serializable]
  1845. public class ItemSaveRoot
  1846. {
  1847. public ItemSave[] items;
  1848. public ItemSave[] hiddenItems;
  1849. public int[] currency;
  1850. }
  1851. [System.Serializable]
  1852. public class ActionBarSlotSave
  1853. {
  1854. public int key;
  1855. public int itemId = -1;
  1856. public int upgradeLevel = 0;
  1857. public List<int> enchantments = new List<int>();
  1858. public List<int> sockets = new List<int>();
  1859. }
  1860. [System.Serializable]
  1861. public class ActionBarSave
  1862. {
  1863. public ActionBarSlotSave[] slots;
  1864. }
  1865. [System.Serializable]
  1866. public class ActionBarSaveRoot
  1867. {
  1868. public ActionBarSave[] sets;
  1869. }
  1870. #endregion
  1871. #region InventorySnapShot
  1872. [System.Serializable]
  1873. public class InventorySnapShot
  1874. {
  1875. public List<InventoryStack> Stacks = new List<InventoryStack>();
  1876. public List<InventoryStack> HiddenStacks = new List<InventoryStack>();
  1877. public CurrencySet Currency = new CurrencySet();
  1878. public float Weight = 0F;
  1879. public List<int> CurrencyValue
  1880. {
  1881. get
  1882. {
  1883. return Currency.Currency;
  1884. }
  1885. }
  1886. public int GetCurrency(int _type, bool _includeExchangedValue = false)
  1887. {
  1888. return Currency.GetCurrency(_type, _includeExchangedValue);
  1889. }
  1890. public int GetItemNumber(int _uid)
  1891. {
  1892. int _result = 0;
  1893. for (int i = 0; i < Stacks.Count; i++)
  1894. {
  1895. if (Stacks[i].isSameItem(_uid))
  1896. {
  1897. _result += Stacks[i].Number;
  1898. }
  1899. }
  1900. for (int i = 0; i < HiddenStacks.Count; i++)
  1901. {
  1902. if (HiddenStacks[i].isSameItem(_uid))
  1903. {
  1904. _result += HiddenStacks[i].Number;
  1905. }
  1906. }
  1907. return _result;
  1908. }
  1909. public InventorySnapShot(InventoryHolder _holder)
  1910. {
  1911. Weight = _holder.GetWeight();
  1912. Stacks = new List<InventoryStack>();
  1913. HiddenStacks = new List<InventoryStack>();
  1914. for (int i = 0; i < _holder.Stacks.Count; i++)
  1915. {
  1916. Stacks.Add(_holder.Stacks[i].Copy());
  1917. }
  1918. for (int i = 0; i < _holder.HiddenStacks.Count; i++)
  1919. {
  1920. HiddenStacks.Add(_holder.HiddenStacks[i].Copy());
  1921. }
  1922. Currency = _holder.Currency.Copy();
  1923. }
  1924. }
  1925. #endregion
  1926. #region Misc Class
  1927. [System.Serializable]
  1928. public class StringColorData
  1929. {
  1930. public string name;
  1931. public Color color;
  1932. public bool visible = true;
  1933. }
  1934. [System.Serializable]
  1935. public class ActionSlotData
  1936. {
  1937. public KeyCode key;
  1938. public int itemId = -1;
  1939. public int upgradeLevel=0;
  1940. public List<int> enchantments = new List<int>();
  1941. public List<int> sockets = new List<int>();
  1942. public ActionSlotData()
  1943. {
  1944. itemId = -1;
  1945. upgradeLevel = 0;
  1946. enchantments = new List<int>();
  1947. sockets = new List<int>();
  1948. key = KeyCode.None;
  1949. }
  1950. }
  1951. [System.Serializable]
  1952. public class ActionSlotSet
  1953. {
  1954. public List<ActionSlotData> slots = new List<ActionSlotData>();
  1955. }
  1956. [System.Serializable]
  1957. public class GraphicsSet
  1958. {
  1959. public string name;
  1960. public Color color;
  1961. public Color defaultColor;
  1962. public MaskableGraphic[] graphics;
  1963. public bool visible = true;
  1964. public bool visibleAdjustable = false;
  1965. }
  1966. [System.Serializable]
  1967. public class RectSet
  1968. {
  1969. public RectTransform rect;
  1970. public Vector2 widthMinMax;
  1971. public Vector2 heightMinMax;
  1972. }
  1973. [System.Serializable]
  1974. public class RectSetting
  1975. {
  1976. public string name;
  1977. public float widthLerp = 0.5F;
  1978. public float heightLerp = 0.5F;
  1979. public RectSet [] set;
  1980. public bool widthAdjustable = false;
  1981. public bool heightAdjustable = false;
  1982. }
  1983. [System.Serializable]
  1984. public class BlockByTag
  1985. {
  1986. public string tag="";
  1987. public ItemIcon blockIcon;
  1988. public InventoryItem blockedItem;
  1989. }
  1990. [System.Serializable]
  1991. public class CustomField
  1992. {
  1993. public string key;
  1994. public Object value;
  1995. }
  1996. #endregion
  1997. }