Elin Modding Docs Doc
Loading...
Searching...
No Matches
AI_Shopping.cs
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4
5// Token: 0x020001ED RID: 493
6public class AI_Shopping : AIAct
7{
8 // Token: 0x06000E26 RID: 3622 RVA: 0x0006AFB8 File Offset: 0x000691B8
9 public static bool TryShop(Chara c, bool realtime)
10 {
11 if (c.memberType != FactionMemberType.Guest || !EClass._zone.IsPCFaction || EClass._map.props.sales.Count == 0)
12 {
13 return false;
14 }
15 Card card = EClass._map.props.sales.RandomItem<Card>();
16 int c_allowance = c.c_allowance;
17 if (!EClass.debug.enable && c_allowance <= 0)
18 {
19 return false;
20 }
21 bool flag = card.IsContainer && card.things.Count > 0;
22 List<Card> list = new List<Card>();
23 if (flag)
24 {
25 using (List<Thing>.Enumerator enumerator = card.things.GetEnumerator())
26 {
27 while (enumerator.MoveNext())
28 {
29 Thing thing = enumerator.Current;
30 if (TraitSalesTag.CanTagSale(thing, true))
31 {
32 list.Add(thing);
33 }
34 }
35 goto IL_C8;
36 }
37 }
38 list.Add(card);
39 IL_C8:
40 foreach (Card card2 in list)
41 {
42 int num = 25;
43 int price = card2.GetPrice(CurrencyType.Money, true, PriceType.PlayerShop, null);
44 if (price >= c_allowance)
45 {
46 num = num * 10 * price / c_allowance;
47 }
48 if (price >= 10000)
49 {
50 num *= 15;
51 }
52 else if (price >= 5000)
53 {
54 num *= 10;
55 }
56 else if (price >= 1000)
57 {
58 num *= 6;
59 }
60 else if (price >= 200)
61 {
62 num *= 3;
63 }
64 if (EClass.Branch != null)
65 {
66 if (EClass.Branch.policies.IsActive(2817, -1))
67 {
68 num = num * (300 + EClass.Branch.Evalue(2817)) / 100;
69 }
70 if (EClass.Branch.policies.IsActive(2816, -1))
71 {
72 num = num * (1000 + EClass.Branch.Evalue(2816) * 2) / 100;
73 }
74 }
75 if (!realtime)
76 {
77 num /= 4;
78 }
79 if (EClass.debug.enable || EClass.rnd(num + 1) == 0)
80 {
81 if (realtime)
82 {
83 c.SetAI(new AI_Shopping
84 {
85 container = (flag ? card : null),
86 dest = card2
87 });
88 return true;
89 }
90 AI_Shopping.Buy(c, card2, false, flag ? card : null);
91 }
92 }
93 return false;
94 }
95
96 // Token: 0x06000E27 RID: 3623 RVA: 0x0006B228 File Offset: 0x00069428
97 public static bool TryRestock(Chara c, bool realtime)
98 {
99 for (int i = 0; i < (realtime ? 1 : 10); i++)
100 {
101 bool flag = false;
102 foreach (Thing thing in EClass._map.things)
103 {
104 if (EClass.rnd(2) != 0 && thing.IsInstalled)
105 {
106 TraitSalesTag traitSalesTag = thing.trait as TraitSalesTag;
107 if (traitSalesTag != null && traitSalesTag.IsOn && !thing.GetStr(11, null).IsEmpty())
108 {
109 Thing thing2 = EClass._zone.TryGetRestock<TraitSpotStock>(thing.GetStr(11, null));
110 if (thing2 != null)
111 {
112 if (realtime)
113 {
114 thing.PlaySound("restock", 1f, true);
115 }
116 thing.Destroy();
117 thing2.isSale = true;
118 EClass._zone.AddCard(thing2, thing.pos).Install();
119 flag = true;
120 break;
121 }
122 }
123 }
124 }
125 if (!flag)
126 {
127 break;
128 }
129 }
130 return false;
131 }
132
133 // Token: 0x06000E28 RID: 3624 RVA: 0x0006B338 File Offset: 0x00069538
134 public override IEnumerable<AIAct.Status> Run()
135 {
136 Card _dest = this.container ?? this.dest;
137 if (_dest.ExistsOnMap)
138 {
139 yield return base.DoGoto(_dest.pos, 1, false, null);
140 }
141 if (!_dest.ExistsOnMap || !_dest.isSale)
142 {
143 yield return base.Success(null);
144 }
145 AI_Shopping.Buy(this.owner, this.dest, true, this.container);
146 yield return base.Success(null);
147 yield break;
148 }
149
150 // Token: 0x06000E29 RID: 3625 RVA: 0x0006B348 File Offset: 0x00069548
151 public static void SellChara(Chara c)
152 {
153 Msg.Say("sell_resident", c, null, null, null);
154 c.homeBranch.BanishMember(c, true);
155 EClass.player.ModKarma(-1);
156 }
157
158 // Token: 0x06000E2A RID: 3626 RVA: 0x0006B374 File Offset: 0x00069574
159 public static void Buy(Chara c, Card dest, bool realtime, Card container)
160 {
161 Point point = dest.pos.Copy();
162 int price = dest.GetPrice(CurrencyType.Money, true, PriceType.PlayerShop, null);
163 if (dest.isThing && (dest.isDestroyed || dest.Thing.IsSharedContainer))
164 {
165 return;
166 }
167 if (container == null && !dest.isSale)
168 {
169 return;
170 }
171 if (container != null && container.c_lockLv != 0)
172 {
173 return;
174 }
175 Card card = dest.isChara ? dest : dest.Split(1);
176 EClass.Branch.incomeShop += price;
177 card.isSale = false;
178 if (card == dest)
179 {
180 EClass._map.props.sales.Remove(card);
181 }
182 if (realtime)
183 {
184 c.Talk("shop_buy", null, null, false);
185 c.PlaySound("money", 1f, true);
186 Msg.alwaysVisible = true;
187 Msg.Say("shop_buy", c, card, Lang._currency(price, "money"), null);
188 if (card.isThing)
189 {
190 c.AddCard(card);
191 c.c_allowance -= price;
192 if (!c.TryUse(card.Thing))
193 {
194 card.ModNum(-1, true);
195 }
196 }
197 else
198 {
199 AI_Shopping.SellChara(card.Chara);
200 }
201 }
202 else if (card.isThing)
203 {
204 card.ModNum(-1, true);
205 }
206 else
207 {
208 AI_Shopping.SellChara(card.Chara);
209 }
210 if (card.isStolen || card.isChara)
211 {
212 Guild.Thief.AddContribution((int)Mathf.Sqrt((float)price) / 2);
213 }
214 if (container != null)
215 {
216 if (container.things.Count == 0)
217 {
218 container.isSale = false;
219 EClass._map.props.sales.Remove(container);
220 }
221 }
222 else if (!dest.ExistsOnMap && dest.isThing)
223 {
224 Thing thing = ThingGen.Create("tag_sell", -1, -1);
225 thing.isOn = true;
226 thing.SetStr(11, dest.category.id);
227 EClass._zone.AddCard(thing, point).Install();
228 }
229 EClass.Branch.Log("shop_buy", c, card, Lang._currency(price, "money"), null);
230 }
231
232 // Token: 0x04000D3A RID: 3386
233 public Card container;
234
235 // Token: 0x04000D3B RID: 3387
236 public Card dest;
237}
Definition AIAct.cs:7
Definition Card.cs:13
Definition Chara.cs:12
Definition Guild.cs:5
Definition Msg.cs:7
Definition Point.cs:11
Definition Thing.cs:10