Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ItemShopSellbackHelper.cs
Go to the documentation of this file.
1
using
System.Collections.Generic
;
2
3
namespace
Terraria.GameContent
;
4
5
public
class
ItemShopSellbackHelper
6
{
7
private
class
ItemMemo
8
{
9
public
readonly
int
itemNetID
;
10
11
public
readonly
int
itemPrefix
;
12
13
public
int
stack
;
14
15
public
ItemMemo
(
Item
item)
16
{
17
itemNetID
= item.netID;
18
itemPrefix
= item.prefix;
19
stack
= item.stack;
20
}
21
22
public
bool
Matches
(
Item
item)
23
{
24
if
(item.netID ==
itemNetID
)
25
{
26
return
item.prefix ==
itemPrefix
;
27
}
28
return
false
;
29
}
30
}
31
32
private
List<ItemMemo>
_memos
=
new
List<ItemMemo>
();
33
34
public
void
Add
(
Item
item)
35
{
36
ItemMemo
itemMemo
=
_memos
.Find((
ItemMemo
x) => x.
Matches
(item));
37
if
(
itemMemo
!=
null
)
38
{
39
itemMemo.stack += item.stack;
40
}
41
else
42
{
43
_memos
.
Add
(
new
ItemMemo
(item));
44
}
45
}
46
47
public
void
Clear
()
48
{
49
_memos
.
Clear
();
50
}
51
52
public
int
GetAmount
(
Item
item)
53
{
54
return
_memos
.Find((
ItemMemo
x) => x.
Matches
(item))?.stack ?? 0;
55
}
56
57
public
int
Remove
(
Item
item)
58
{
59
ItemMemo
itemMemo
=
_memos
.Find((
ItemMemo
x) => x.
Matches
(item));
60
if
(
itemMemo
==
null
)
61
{
62
return
0;
63
}
64
int
stack =
itemMemo
.stack;
65
itemMemo.stack -= item.stack;
66
if
(
itemMemo
.stack <= 0)
67
{
68
_memos
.
Remove
(
itemMemo
);
69
return
stack;
70
}
71
return
stack -
itemMemo
.stack;
72
}
73
}
System.Collections.Generic.Dictionary.Remove
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
Definition
Dictionary.cs:893
System.Collections.Generic.Dictionary.Clear
void Clear()
Definition
Dictionary.cs:904
System.Collections.Generic.Dictionary.Add
void Add(TKey key, TValue value)
Definition
Dictionary.cs:873
System.Collections.Generic.Dictionary
Definition
Dictionary.cs:14
Terraria.GameContent.ItemShopSellbackHelper.ItemMemo.itemNetID
readonly int itemNetID
Definition
ItemShopSellbackHelper.cs:9
Terraria.GameContent.ItemShopSellbackHelper.ItemMemo.Matches
bool Matches(Item item)
Definition
ItemShopSellbackHelper.cs:22
Terraria.GameContent.ItemShopSellbackHelper.ItemMemo.stack
int stack
Definition
ItemShopSellbackHelper.cs:13
Terraria.GameContent.ItemShopSellbackHelper.ItemMemo.ItemMemo
ItemMemo(Item item)
Definition
ItemShopSellbackHelper.cs:15
Terraria.GameContent.ItemShopSellbackHelper.ItemMemo.itemPrefix
readonly int itemPrefix
Definition
ItemShopSellbackHelper.cs:11
Terraria.GameContent.ItemShopSellbackHelper.ItemMemo
Definition
ItemShopSellbackHelper.cs:8
Terraria.GameContent.ItemShopSellbackHelper.GetAmount
int GetAmount(Item item)
Definition
ItemShopSellbackHelper.cs:52
Terraria.GameContent.ItemShopSellbackHelper.Add
void Add(Item item)
Definition
ItemShopSellbackHelper.cs:34
Terraria.GameContent.ItemShopSellbackHelper._memos
List< ItemMemo > _memos
Definition
ItemShopSellbackHelper.cs:32
Terraria.GameContent.ItemShopSellbackHelper.Remove
int Remove(Item item)
Definition
ItemShopSellbackHelper.cs:57
Terraria.GameContent.ItemShopSellbackHelper.Clear
void Clear()
Definition
ItemShopSellbackHelper.cs:47
Terraria.GameContent.ItemShopSellbackHelper
Definition
ItemShopSellbackHelper.cs:6
Terraria.Item
Definition
Item.cs:22
System.Collections.Generic
Definition
IHashKeyCollection.cs:1
Terraria.GameContent
Definition
AchievementsHelper.cs:1
source
Terraria.GameContent
ItemShopSellbackHelper.cs
Generated by
1.10.0