Elin Decompiled Documentation EA 23.240 Nightly
Loading...
Searching...
No Matches
TraitSeed.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Linq;
3using UnityEngine;
4
5public class TraitSeed : Trait
6{
7 public static List<SourceObj.Row> listSeeds;
8
10
11 public override int InstallBottomPriority => 10000;
12
13 public override bool CanExtendBuild => true;
14
15 public override bool CanChangeHeight => false;
16
17 public override bool CanName => true;
18
19 public override int DefaultStock => 3 + EClass.rnd(10);
20
21 public override void OnCreate(int lv)
22 {
24 owner.c_seed = EClass.rnd(10000);
25 }
26
27 public override void SetName(ref string s)
28 {
29 s = "_of".lang(row.GetName(), s);
30 }
31
32 public override void WriteNote(UINote n, bool identified)
33 {
34 base.WriteNote(n, identified);
35 int num = 1;
36 if (!row._growth.IsEmpty() && row._growth.Length >= 4)
37 {
38 if (row._growth.Length >= 5)
39 {
40 num = row._growth[4].ToInt();
41 }
42 n.AddText("isHarvestCrop".lang(num.ToString() ?? ""));
43 }
44 n.AddText("isConsumeFertility".lang((0.1f * (float)row.costSoil).ToString() ?? ""));
45 if (row.tag.Contains("flood"))
46 {
47 n.AddText("isWaterCrop");
48 }
49 if (row.growth != null)
50 {
51 if (row.growth.GrowOnLand)
52 {
53 n.AddText("isGrowOnLand");
54 }
55 if (row.growth.GrowUndersea)
56 {
57 n.AddText("isGrowUndersea");
58 }
59 if (row.growth.NeedSunlight)
60 {
61 n.AddText("isNeedSun");
62 }
63 }
64 if (row.growth == null || !row.growth.CanLevelSeed)
65 {
66 n.AddText("isDecoSeed", FontColor.Warning);
67 }
68 }
69
70 public void TrySprout(bool force = false, bool sucker = false, VirtualDate date = null)
71 {
72 Point pos = owner.pos;
73 if (!pos.HasObj && pos.cell.CanGrow(row, date ?? new VirtualDate()))
74 {
75 pos.SetObj(row.id, 1, owner.dir);
77 if (sucker)
78 {
80 }
81 else
82 {
83 owner.Destroy();
84 }
85 }
86 }
87
88 public static Thing MakeSeed(string id, PlantData plant = null)
89 {
90 return MakeSeed(EClass.sources.objs.alias[id], plant);
91 }
92
93 public static Thing MakeSeed(SourceObj.Row obj, PlantData plant = null)
94 {
95 Thing thing = plant?.seed;
97 {
98 thing = null;
99 }
100 Thing thing2 = ThingGen.Create("seed");
101 ApplySeed(thing2, obj.id);
102 if (thing != null && obj.growth != null && obj.growth.CanLevelSeed)
103 {
104 foreach (Element value in thing.elements.dict.Values)
105 {
106 if (value.IsFoodTrait)
107 {
108 thing2.elements.SetTo(value.id, value.Value);
109 }
110 }
111 thing2.SetEncLv(thing.encLV);
112 thing2.elements.SetBase(2, EClass.curve(thing2.encLV, 50, 10, 80));
113 thing2.c_refText = thing.c_refText;
114 thing2.c_seed = thing.c_seed;
115 int num = plant?.water ?? 0;
116 int num2 = plant?.fert ?? 0;
117 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) ? 25 : 0));
119 {
120 num3 = 2 + num3 * 2;
121 }
122 if (EClass.rnd(num3) == 0 && EClass._zone.IsPCFactionOrTent)
123 {
124 int num4 = Mathf.Max(5, EClass.pc.Evalue(286)) - thing2.encLV;
125 if (num4 <= 0)
126 {
128 {
129 Msg.Say("seedLvLimit", thing2);
130 }
131 }
132 else
133 {
134 int num5 = Mathf.Clamp(EClass.rnd(num4) - 5, 1, EClass.player.isAutoFarming ? 3 : 10);
135 LevelSeed(thing2, obj, num5);
136 EClass.pc.PlaySound("seed_level");
137 }
138 }
139 Rand.SetSeed();
140 }
141 thing2.SetBlessedState(BlessedState.Normal);
142 return thing2;
143 }
144
145 public static void LevelSeed(Thing t, SourceObj.Row obj, int num)
146 {
147 if (obj == null || obj.growth == null || !obj.growth.CanLevelSeed)
148 {
149 return;
150 }
151 for (int i = 0; i < num; i++)
152 {
153 if (obj == null || obj.objType == "crop")
154 {
155 if (t.encLV == 0)
156 {
158 }
159 else
160 {
163 }
164 }
165 t.ModEncLv(1);
166 }
167 }
168
169 public static Thing MakeSeed(string idSource)
170 {
171 return MakeSeed(EClass.sources.objs.alias[idSource]);
172 }
173
174 public static Thing ApplySeed(Thing t, int refval)
175 {
176 t.refVal = refval;
177 SourceObj.Row row = EClass.sources.objs.map.TryGetValue(refval);
178 if (row != null && row.vals.Length != 0)
179 {
180 t.idSkin = row.vals[0].ToInt();
181 }
182 return t;
183 }
184
185 public static Thing MakeSeed(SourceObj.Row obj)
186 {
187 Thing thing = ThingGen.Create("seed");
188 ApplySeed(thing, obj.id);
189 return thing;
190 }
191
192 public static Thing MakeRandomSeed(bool enc = false)
193 {
194 Thing thing = ThingGen.Create("seed", null);
195 SourceObj.Row randomSeedObj = GetRandomSeedObj();
196 ApplySeed(thing, randomSeedObj.id);
197 return thing;
198 }
199
201 {
202 if (listSeeds == null)
203 {
204 listSeeds = EClass.sources.objs.rows.Where((SourceObj.Row s) => s.HasTag(CTAG.seed) && !s.HasTag(CTAG.rareSeed) && s.alias != "redpepper").ToList();
205 }
206 return listSeeds.RandomItemWeighted((SourceObj.Row a) => a.chance);
207 }
208}
BlessedState
Definition: BlessedState.cs:2
CTAG
Definition: CTAG.cs:2
@ plant
FontColor
Definition: FontColor.cs:2
if(item3.idFile==idFirstFile &&item3.id==idFirstTopic)
Definition: UIBook.cs:627
void Add(Act a, string s="")
Definition: ActPlan.cs:11
ElementContainerCard elements
Definition: Card.cs:41
string id
Definition: Card.cs:35
bool HasElement(int ele, int req=1)
Definition: Card.cs:5897
SoundSource PlaySound(string id, float v=1f, bool spatial=true)
Definition: Card.cs:6129
string c_refText
Definition: Card.cs:1629
int c_seed
Definition: Card.cs:1305
virtual void SetBlessedState(BlessedState s)
Definition: Card.cs:3892
Point pos
Definition: Card.cs:59
int refVal
Definition: Card.cs:206
int encLV
Definition: Card.cs:326
void ModEncLv(int a)
Definition: Card.cs:3843
void SetEncLv(int a)
Definition: Card.cs:3861
void Destroy()
Definition: Card.cs:5067
virtual Thing Thing
Definition: Card.cs:2058
int Evalue(int ele)
Definition: Card.cs:2571
int dir
Definition: Card.cs:146
int LV
Definition: Card.cs:386
bool CanGrow(SourceObj.Row obj, VirtualDate date)
Definition: Cell.cs:1653
static void AddRandomFoodEnc(Thing t)
Definition: CraftUtil.cs:43
static void ModRandomFoodEnc(Thing t)
Definition: CraftUtil.cs:22
Definition: EClass.cs:6
static int curve(int _a, int start, int step, int rate=75)
Definition: EClass.cs:69
static Zone _zone
Definition: EClass.cs:21
static Map _map
Definition: EClass.cs:19
static int rnd(long a)
Definition: EClass.cs:59
static SourceManager sources
Definition: EClass.cs:43
static Player player
Definition: EClass.cs:13
static Chara pc
Definition: EClass.cs:15
Dictionary< int, Element > dict
void SetTo(int id, int v)
Element SetBase(string alias, int v, int potential=0)
int id
Definition: ELEMENT.cs:250
int Value
Definition: ELEMENT.cs:292
bool IsFoodTrait
Definition: ELEMENT.cs:364
PlantData AddPlant(Point pos, Thing seed)
Definition: Map.cs:1952
Definition: Msg.cs:5
static string Say(string idLang, string ref1, string ref2=null, string ref3=null, string ref4=null)
Definition: Msg.cs:58
bool isAutoFarming
Definition: Player.cs:1181
Definition: Point.cs:9
void SetObj(int id=0, int value=1, int dir=0)
Definition: Point.cs:928
bool HasObj
Definition: Point.cs:137
Cell cell
Definition: Point.cs:51
Definition: Rand.cs:4
static void SetSeed(int a=-1)
Definition: Rand.cs:37
SourceObj objs
string GetName(int id)
Definition: SourceObj.cs:149
static Thing Create(string id, int idMat=-1, int lv=-1)
Definition: ThingGen.cs:53
Definition: Thing.cs:8
int id
Definition: TileRow.cs:8
static SourceObj.Row GetRandomSeedObj()
Definition: TraitSeed.cs:200
override void SetName(ref string s)
Definition: TraitSeed.cs:27
override void OnCreate(int lv)
Definition: TraitSeed.cs:21
override int InstallBottomPriority
Definition: TraitSeed.cs:11
override bool CanName
Definition: TraitSeed.cs:17
static Thing ApplySeed(Thing t, int refval)
Definition: TraitSeed.cs:174
override void WriteNote(UINote n, bool identified)
Definition: TraitSeed.cs:32
static Thing MakeSeed(SourceObj.Row obj, PlantData plant=null)
Definition: TraitSeed.cs:93
override int DefaultStock
Definition: TraitSeed.cs:19
override bool CanChangeHeight
Definition: TraitSeed.cs:15
static Thing MakeSeed(string idSource)
Definition: TraitSeed.cs:169
override bool CanExtendBuild
Definition: TraitSeed.cs:13
static Thing MakeRandomSeed(bool enc=false)
Definition: TraitSeed.cs:192
void TrySprout(bool force=false, bool sucker=false, VirtualDate date=null)
Definition: TraitSeed.cs:70
static void LevelSeed(Thing t, SourceObj.Row obj, int num)
Definition: TraitSeed.cs:145
static Thing MakeSeed(string id, PlantData plant=null)
Definition: TraitSeed.cs:88
static List< SourceObj.Row > listSeeds
Definition: TraitSeed.cs:7
static Thing MakeSeed(SourceObj.Row obj)
Definition: TraitSeed.cs:185
SourceObj.Row row
Definition: TraitSeed.cs:9
Definition: Trait.cs:7
Card owner
Definition: Trait.cs:27
Definition: UINote.cs:6
UIItem AddText(string text, FontColor color=FontColor.DontChange)
Definition: UINote.cs:113
Definition: Zone.cs:12
bool IsPCFactionOrTent
Definition: Zone.cs:473
virtual bool IsUserZone
Definition: Zone.cs:268
static List< Thing > Suckers
Definition: Zone.cs:80