Elin Modding Docs Doc
Loading...
Searching...
No Matches
TraitSeed.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using UnityEngine;
5
6// Token: 0x02000451 RID: 1105
7public class TraitSeed : Trait
8{
9 // Token: 0x17000999 RID: 2457
10 // (get) Token: 0x06001EE6 RID: 7910 RVA: 0x000B06DA File Offset: 0x000AE8DA
11 public SourceObj.Row row
12 {
13 get
14 {
15 return EClass.sources.objs.map[this.owner.refVal];
16 }
17 }
18
19 // Token: 0x1700099A RID: 2458
20 // (get) Token: 0x06001EE7 RID: 7911 RVA: 0x000B06FB File Offset: 0x000AE8FB
21 public override bool CanExtendBuild
22 {
23 get
24 {
25 return true;
26 }
27 }
28
29 // Token: 0x1700099B RID: 2459
30 // (get) Token: 0x06001EE8 RID: 7912 RVA: 0x000B06FE File Offset: 0x000AE8FE
31 public override bool CanName
32 {
33 get
34 {
35 return true;
36 }
37 }
38
39 // Token: 0x1700099C RID: 2460
40 // (get) Token: 0x06001EE9 RID: 7913 RVA: 0x000B0701 File Offset: 0x000AE901
41 public override int DefaultStock
42 {
43 get
44 {
45 return 3 + EClass.rnd(10);
46 }
47 }
48
49 // Token: 0x06001EEA RID: 7914 RVA: 0x000B070C File Offset: 0x000AE90C
50 public override void OnCreate(int lv)
51 {
52 TraitSeed.ApplySeed(this.owner.Thing, TraitSeed.GetRandomSeedObj().id);
53 this.owner.c_seed = EClass.rnd(10000);
54 }
55
56 // Token: 0x06001EEB RID: 7915 RVA: 0x000B073E File Offset: 0x000AE93E
57 public override void SetName(ref string s)
58 {
59 s = "_of".lang(this.row.GetName(), s, null, null, null);
60 }
61
62 // Token: 0x06001EEC RID: 7916 RVA: 0x000B075C File Offset: 0x000AE95C
63 public override void WriteNote(UINote n, bool identified)
64 {
65 base.WriteNote(n, identified);
66 int num = 1;
67 if (!this.row._growth.IsEmpty() && this.row._growth.Length >= 4)
68 {
69 if (this.row._growth.Length >= 5)
70 {
71 num = this.row._growth[4].ToInt();
72 }
73 n.AddText("isHarvestCrop".lang(num.ToString() ?? "", null, null, null, null), FontColor.DontChange);
74 }
75 n.AddText("isConsumeFertility".lang((0.1f * (float)this.row.costSoil).ToString() ?? "", null, null, null, null), FontColor.DontChange);
76 if (this.row.tag.Contains("flood"))
77 {
78 n.AddText("isWaterCrop", FontColor.DontChange);
79 }
80 if (this.row.growth != null && this.row.growth.NeedSunlight)
81 {
82 n.AddText("isNeedSun", FontColor.DontChange);
83 }
84 }
85
86 // Token: 0x06001EED RID: 7917 RVA: 0x000B0868 File Offset: 0x000AEA68
87 public void TrySprout(bool force = false, bool sucker = false, VirtualDate date = null)
88 {
89 Point pos = this.owner.pos;
90 if (!pos.HasObj && pos.cell.CanGrow(this.row, date ?? new VirtualDate(0)))
91 {
92 pos.SetObj(this.row.id, 1, 0);
93 EClass._map.AddPlant(pos, this.owner.Thing);
94 if (sucker)
95 {
96 Zone.Suckers.Add(this.owner.Thing);
97 return;
98 }
99 this.owner.Destroy();
100 }
101 }
102
103 // Token: 0x06001EEE RID: 7918 RVA: 0x000B08F8 File Offset: 0x000AEAF8
104 public static Thing MakeSeed(SourceObj.Row obj, PlantData plant = null)
105 {
106 Thing thing = (plant != null) ? plant.seed : null;
107 if (EClass._zone.IsUserZone)
108 {
109 thing = null;
110 }
111 Thing thing2 = ThingGen.Create("seed", -1, -1);
112 TraitSeed.ApplySeed(thing2, obj.id);
113 if (thing != null)
114 {
115 foreach (Element element in thing.elements.dict.Values)
116 {
117 if (element.IsFoodTrait)
118 {
119 thing2.elements.SetTo(element.id, element.Value);
120 }
121 }
122 thing2.SetEncLv(thing.encLV);
123 thing2.elements.SetBase(2, EClass.curve(thing2.encLV, 50, 10, 80), 0);
124 thing2.c_refText = thing.c_refText;
125 thing2.c_seed = thing.c_seed;
126 int num = (plant != null) ? plant.water : 0;
127 int num2 = (plant != null) ? plant.fert : 0;
128 int num3 = 220 / (Mathf.Clamp(EClass.pc.Evalue(286) - thing.LV, 0, 50) * 2 + 10 + num * 2 + ((num2 > 0) ? 20 : 0) + (EClass.pc.HasElement(1325, 1) ? 25 : 0));
129 if (EClass.player.isAutoFarming)
130 {
131 num3 = 2 + num3 * 2;
132 }
133 if (EClass.rnd(num3) == 0)
134 {
135 int num4 = Mathf.Max(5, EClass.pc.Evalue(286)) - thing2.encLV;
136 if (num4 <= 0)
137 {
138 if (!EClass.player.isAutoFarming)
139 {
140 Msg.Say("seedLvLimit", thing2, null, null, null);
141 }
142 }
143 else
144 {
145 int num5 = Mathf.Clamp(EClass.rnd(num4) - 5, 1, EClass.player.isAutoFarming ? 3 : 10);
146 TraitSeed.LevelSeed(thing2, obj, num5);
147 EClass.pc.PlaySound("seed_level", 1f, true);
148 }
149 }
150 Rand.SetSeed(-1);
151 }
152 thing2.SetBlessedState(BlessedState.Normal);
153 return thing2;
154 }
155
156 // Token: 0x06001EEF RID: 7919 RVA: 0x000B0B0C File Offset: 0x000AED0C
157 public static void LevelSeed(Thing t, SourceObj.Row obj, int num)
158 {
159 for (int i = 0; i < num; i++)
160 {
161 if (obj == null || obj.objType == "crop")
162 {
163 if (t.encLV == 0)
164 {
165 CraftUtil.AddRandomFoodEnc(t);
166 }
167 else
168 {
169 Rand.SetSeed(t.c_seed);
170 CraftUtil.ModRandomFoodEnc(t);
171 }
172 }
173 t.ModEncLv(1);
174 }
175 }
176
177 // Token: 0x06001EF0 RID: 7920 RVA: 0x000B0B62 File Offset: 0x000AED62
178 public static Thing MakeSeed(string idSource)
179 {
180 return TraitSeed.MakeSeed(EClass.sources.objs.alias[idSource]);
181 }
182
183 // Token: 0x06001EF1 RID: 7921 RVA: 0x000B0B80 File Offset: 0x000AED80
184 public static Thing ApplySeed(Thing t, int refval)
185 {
186 t.refVal = refval;
187 SourceObj.Row row = EClass.sources.objs.map.TryGetValue(refval, null);
188 if (row != null && row.vals.Length != 0)
189 {
190 t.idSkin = row.vals[0].ToInt();
191 }
192 return t;
193 }
194
195 // Token: 0x06001EF2 RID: 7922 RVA: 0x000B0BCB File Offset: 0x000AEDCB
196 public static Thing MakeSeed(SourceObj.Row obj)
197 {
198 Thing thing = ThingGen.Create("seed", -1, -1);
199 TraitSeed.ApplySeed(thing, obj.id);
200 return thing;
201 }
202
203 // Token: 0x06001EF3 RID: 7923 RVA: 0x000B0BE8 File Offset: 0x000AEDE8
204 public static Thing MakeRandomSeed(bool enc = false)
205 {
206 Thing thing = ThingGen.Create("seed", null);
207 SourceObj.Row randomSeedObj = TraitSeed.GetRandomSeedObj();
208 TraitSeed.ApplySeed(thing, randomSeedObj.id);
209 return thing;
210 }
211
212 // Token: 0x06001EF4 RID: 7924 RVA: 0x000B0C18 File Offset: 0x000AEE18
213 public static SourceObj.Row GetRandomSeedObj()
214 {
215 if (TraitSeed.listSeeds == null)
216 {
217 TraitSeed.listSeeds = (from s in EClass.sources.objs.rows
218 where s.HasTag(CTAG.seed) && !s.HasTag(CTAG.rareSeed)
219 select s).ToList<SourceObj.Row>();
220 }
221 return TraitSeed.listSeeds.RandomItemWeighted((SourceObj.Row a) => (float)a.chance);
222 }
223
224 // Token: 0x040010CD RID: 4301
225 public static List<SourceObj.Row> listSeeds;
226}
Definition Msg.cs:7
Definition Point.cs:11
Definition Thing.cs:10
Definition Trait.cs:9
Definition Zone.cs:14