Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
AI_Shopping.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using UnityEngine;
3
4public class AI_Shopping : AIAct
5{
6 public Card container;
7
8 public Card dest;
9
10 public static bool TryShop(Chara c, bool realtime)
11 {
12 if (c.memberType != FactionMemberType.Guest || !EClass._zone.IsPCFaction || EClass._map.props.sales.Count == 0)
13 {
14 return false;
15 }
16 Card card = EClass._map.props.sales.RandomItem();
17 int c_allowance = c.c_allowance;
18 if (!EClass.debug.enable && c_allowance <= 0)
19 {
20 return false;
21 }
22 bool flag = card.IsContainer && card.things.Count > 0;
23 List<Card> list = new List<Card>();
24 if (flag)
25 {
26 foreach (Thing thing in card.things)
27 {
28 if (TraitSalesTag.CanTagSale(thing, insideContainer: true))
29 {
30 list.Add(thing);
31 }
32 }
33 }
34 else
35 {
36 list.Add(card);
37 }
38 foreach (Card item in list)
39 {
40 int num = 25;
41 int price = item.GetPrice(CurrencyType.Money, sell: true, PriceType.PlayerShop);
42 if (price >= c_allowance)
43 {
44 num = num * 10 * price / c_allowance;
45 }
46 if (price >= 10000)
47 {
48 num *= 15;
49 }
50 else if (price >= 5000)
51 {
52 num *= 10;
53 }
54 else if (price >= 1000)
55 {
56 num *= 6;
57 }
58 else if (price >= 200)
59 {
60 num *= 3;
61 }
62 if (EClass.Branch != null)
63 {
65 {
66 num = num * (300 + EClass.Branch.Evalue(2817)) / 100;
67 }
69 {
70 num = num * (1000 + EClass.Branch.Evalue(2816) * 2) / 100;
71 }
72 }
73 if (!realtime)
74 {
75 num /= 4;
76 }
77 if (EClass.debug.enable || EClass.rnd(num + 1) == 0)
78 {
79 if (realtime)
80 {
81 c.SetAI(new AI_Shopping
82 {
83 container = (flag ? card : null),
84 dest = item
85 });
86 return true;
87 }
88 Buy(c, item, realtime: false, flag ? card : null);
89 }
90 }
91 return false;
92 }
93
94 public static bool TryRestock(Chara c, bool realtime)
95 {
96 for (int i = 0; i < (realtime ? 1 : 10); i++)
97 {
98 bool flag = false;
99 foreach (Thing thing2 in EClass._map.things)
100 {
101 if (EClass.rnd(2) == 0 || !thing2.IsInstalled || !(thing2.trait is TraitSalesTag { IsOn: not false }) || thing2.GetStr(11).IsEmpty())
102 {
103 continue;
104 }
105 Thing thing = EClass._zone.TryGetRestock<TraitSpotStock>(thing2.GetStr(11));
106 if (thing != null)
107 {
108 if (realtime)
109 {
110 thing2.PlaySound("restock");
111 }
112 thing2.Destroy();
113 thing.isSale = true;
114 EClass._zone.AddCard(thing, thing2.pos).Install();
115 flag = true;
116 break;
117 }
118 }
119 if (!flag)
120 {
121 break;
122 }
123 }
124 return false;
125 }
126
127 public override IEnumerable<Status> Run()
128 {
129 Card _dest = container ?? dest;
130 if (_dest.ExistsOnMap)
131 {
132 yield return DoGoto(_dest.pos, 1);
133 }
134 if (!_dest.ExistsOnMap || !_dest.isSale)
135 {
136 yield return Success();
137 }
138 Buy(owner, dest, realtime: true, container);
139 yield return Success();
140 }
141
142 public static void SellChara(Chara c)
143 {
144 Msg.Say("sell_resident", c);
145 c.homeBranch.BanishMember(c, skipMsg: true);
147 }
148
149 public static void Buy(Chara c, Card dest, bool realtime, Card container)
150 {
151 Point point = dest.pos.Copy();
152 int price = dest.GetPrice(CurrencyType.Money, sell: true, PriceType.PlayerShop);
153 if ((dest.isThing && (dest.isDestroyed || dest.Thing.IsSharedContainer)) || (container == null && !dest.isSale) || (container != null && container.c_lockLv != 0))
154 {
155 return;
156 }
157 Card card = (dest.isChara ? dest : dest.Split(1));
158 EClass.Branch.incomeShop += price;
159 card.isSale = false;
160 if (card == dest)
161 {
162 EClass._map.props.sales.Remove(card);
163 }
164 if (realtime)
165 {
166 c.Talk("shop_buy");
167 c.PlaySound("money");
168 Msg.alwaysVisible = true;
169 Msg.Say("shop_buy", c, card, Lang._currency(price, "money"));
170 if (card.isThing)
171 {
172 c.AddCard(card);
173 c.c_allowance -= price;
174 if (!c.TryUse(card.Thing))
175 {
176 card.ModNum(-1);
177 }
178 }
179 else
180 {
181 SellChara(card.Chara);
182 }
183 }
184 else if (card.isThing)
185 {
186 card.ModNum(-1);
187 }
188 else
189 {
190 SellChara(card.Chara);
191 }
192 if (card.isStolen || card.isChara)
193 {
194 Guild.Thief.AddContribution((int)Mathf.Sqrt(price) / 2);
195 }
196 if (container != null)
197 {
198 if (container.things.Count == 0)
199 {
200 container.isSale = false;
202 }
203 }
204 else if (!dest.ExistsOnMap && dest.isThing)
205 {
206 Thing thing = ThingGen.Create("tag_sell");
207 thing.isOn = true;
208 thing.SetStr(11, dest.category.id);
209 EClass._zone.AddCard(thing, point).Install();
210 }
211 EClass.Branch.Log("shop_buy", c, card, Lang._currency(price, "money"));
212 }
213}
CurrencyType
Definition: CurrencyType.cs:2
FactionMemberType
PriceType
Definition: PriceType.cs:2
Definition: AIAct.cs:6
new Chara owner
Definition: AIAct.cs:14
Status DoGoto(Point pos, int dist=0, bool ignoreConnection=false, Func< Status > _onChildFail=null)
Definition: AIAct.cs:432
static void Buy(Chara c, Card dest, bool realtime, Card container)
Definition: AI_Shopping.cs:149
static bool TryRestock(Chara c, bool realtime)
Definition: AI_Shopping.cs:94
static bool TryShop(Chara c, bool realtime)
Definition: AI_Shopping.cs:10
static void SellChara(Chara c)
Definition: AI_Shopping.cs:142
override IEnumerable< Status > Run()
Definition: AI_Shopping.cs:127
Card container
Definition: AI_Shopping.cs:6
void SetStr(int id, string value=null)
Definition: BaseCard.cs:63
string GetStr(int id, string defaultStr=null)
Definition: BaseCard.cs:54
Definition: Card.cs:11
bool isDestroyed
Definition: Card.cs:71
virtual bool isThing
Definition: Card.cs:1957
Thing Split(int a)
Definition: Card.cs:3231
SoundSource PlaySound(string id, float v=1f, bool spatial=true)
Definition: Card.cs:5404
virtual int GetPrice(CurrencyType currency=CurrencyType.Money, bool sell=false, PriceType priceType=PriceType.Default, Chara c=null)
Definition: Card.cs:6449
int c_lockLv
Definition: Card.cs:924
Card AddCard(Card c)
Definition: Card.cs:2887
bool isSale
Definition: Card.cs:838
void Talk(string idTopic, string ref1=null, string ref2=null, bool forceSync=false)
Definition: Card.cs:5949
bool ExistsOnMap
Definition: Card.cs:1961
Point pos
Definition: Card.cs:55
int c_allowance
Definition: Card.cs:1253
void Destroy()
Definition: Card.cs:4538
ThingContainer things
Definition: Card.cs:34
virtual Thing Thing
Definition: Card.cs:1934
Card Install()
Definition: Card.cs:3448
SourceCategory.Row category
Definition: Card.cs:1925
Definition: Chara.cs:10
bool TryUse(Thing t)
Definition: Chara.cs:7110
FactionMemberType memberType
Definition: Chara.cs:46
FactionBranch homeBranch
Definition: Chara.cs:889
bool enable
Definition: CoreDebug.cs:285
Definition: EClass.cs:5
static int rnd(int a)
Definition: EClass.cs:50
static Zone _zone
Definition: EClass.cs:20
static Map _map
Definition: EClass.cs:18
static FactionBranch Branch
Definition: EClass.cs:22
static Player player
Definition: EClass.cs:12
static CoreDebug debug
Definition: EClass.cs:48
int Evalue(int ele)
PolicyManager policies
string Log(string idLang, string ref1=null, string ref2=null, string ref3=null, string ref4=null)
void BanishMember(Chara c, bool skipMsg=false)
void AddContribution(int a)
Definition: FACTION.cs:316
Definition: Guild.cs:2
static GuildThief Thief
Definition: Guild.cs:27
Definition: Lang.cs:6
static string _currency(object a, string IDCurrency)
Definition: Lang.cs:162
List< Thing > things
Definition: Map.cs:49
PropsManager props
Definition: Map.cs:91
Definition: Msg.cs:5
static string Say(string idLang, string ref1, string ref2=null, string ref3=null, string ref4=null)
Definition: Msg.cs:58
void ModKarma(int a)
Definition: Player.cs:2289
Definition: Point.cs:9
Point Copy()
Definition: Point.cs:467
bool IsActive(int id, int days=-1)
List< Card > sales
Definition: PropsManager.cs:14
static Thing Create(string id, int idMat=-1, int lv=-1)
Definition: ThingGen.cs:53
Definition: Thing.cs:8
bool IsSharedContainer
Definition: Thing.cs:92
static bool CanTagSale(Card t, bool insideContainer=false)
Definition: TraitSalesTag.cs:9
bool IsPCFaction
Definition: Zone.cs:464
Card AddCard(Card t, Point point)
Definition: Zone.cs:1893