12 public static Recipe GetOrCreate(
string id)
14 Recipe recipe =
Recipe.recipeCache.TryGetValue(
id,
null);
18 if (recipeSource !=
null)
20 recipe =
Recipe.Create(recipeSource, -1,
null);
21 Recipe.recipeCache.Add(
id, recipe);
30 string type = _source.type;
32 recipe.id = _source.id;
33 recipe._source = _source;
37 recipe.BuildIngredientList(ing);
40 recipe.VirtualBlock =
true;
50 if (recipeSource ==
null)
57 _source = recipeSource,
61 recipeCard.BuildIngredientList(t);
62 if (t.uid == 0 || recipeCard.ingredients[0].uid == 0 || recipeCard.ingredients[0].thing ==
null)
64 Debug.LogError(
"expection: invalid ingredient " + ((t !=
null) ? t.ToString() :
null));
70 public static void DropIngredients(
string id,
string idMatMain,
int num = 1)
74 orCreate.BuildIngredientList();
75 Msg.Say(
"dropReward");
78 Thing thing =
ThingGen.Create(ingredient.id, -1, -1).SetNum(ingredient.req);
79 if (ingredient == orCreate.ingredients[0])
81 thing.ChangeMaterial(idMatMain);
84 EClass.player.DropReward(thing,
true);
95 if ((result = this._source) ==
null)
109 return this.renderRow.DefaultMaterial;
119 return this.source.row as
TileRow;
129 return this.source.row;
139 return this.GetName();
149 if (!(this.source.type ==
"Bridge") ||
this.source.row.tileType is
TileTypeBridge)
151 return this.renderRow.tileType;
159 public virtual bool IsFloorOrBridge
163 return this.tileType.IsFloorOrBridge;
169 public int MaxAltitude
173 if (this.IsThing || this.IsBridge || this.tileType.blockRenderMode == BlockRenderMode.Pillar)
175 return this.tileType.MaxAltitude;
187 return EClass.player.recipes.knownRecipes.TryGetValue(this.
id, 0);
197 return this.tileType.IsFloor;
213 public virtual bool IsBlock
217 return !this.IsFloorOrBridge;
223 public bool IsWallOrFence
227 return this.tileType.IsWallOrFence;
237 return this.source.type ==
"Bridge";
243 public virtual bool IsThing
253 public virtual Card Mold
262 public bool IsStaticLV()
264 string idFactory = this.source.idFactory;
265 return idFactory ==
"factory_floor" || idFactory ==
"factory_block" || idFactory ==
"factory_wall" || idFactory ==
"factory_platform" || this.renderRow.Category.IsChildOf(
"block");
269 public int GetQualityBonus()
271 if (this.IsStaticLV())
275 Element reqSkill = this.source.GetReqSkill();
276 int num = reqSkill.Value -
EClass.pc.Evalue(reqSkill.id);
280 num2 +=
EClass.curve(-num, 10, 20, 80) / 10 * 10 + 10;
281 if (this.RecipeLv > 0)
283 num2 += (int)Mathf.Sqrt((
float)(
this.RecipeLv - 1)) * 10;
291 return -(num - 4) * 10;
300 if (this._dir % 2 != 0)
302 return this.renderRow.H;
304 return this.renderRow.W;
314 if (this._dir % 2 != 0)
316 return this.renderRow.W;
318 return this.renderRow.H;
324 public virtual bool RequireIngredients
333 public virtual int GetRefVal()
351 public virtual string GetIdThing()
377 public bool MultiSize
381 return this.W != 1 || this.H != 1;
386 public virtual bool ShouldShowHighlight(HitResult r)
388 return r != HitResult.Valid;
392 public BaseTileSelector.BoxType GetBoxType()
407 return EClass.screen.tileSelector;
412 public int GetDefaultColor()
416 Thing thing = this.ingredients[0].thing;
417 return this.renderRow.GetColorInt(thing.isDyed ? thing.DyeMat : thing.material);
419 return this.renderRow.GetColorInt(this.DefaultMaterial);
426 if (this.ingredients.Count > 0)
428 if (this.ingredients[0].thing !=
null)
430 num = this.ingredients[0].thing.material.id;
434 num = this.ingredients[0].mat;
441 return EClass.sources.materials.rows[num];
447 if (this.idMat != -1)
449 return EClass.sources.materials.rows[this.idMat];
453 int num = (this.ingredients.Count > 0) ? this.ingredients[this.source.colorIng].mat : 3;
458 return EClass.sources.materials.rows[num];
460 this.ingredients[0].RefreshThing();
461 Thing thing = this.ingredients[0].thing;
464 return EClass.sources.materials.rows[3];
468 return thing.material;
475 public virtual int CostMoney
484 public virtual void BuildIngredientList()
486 if (this.UseStock || !this.RequireIngredients)
490 this.ingredients = this.source.GetIngredients();
494 public void BuildIngredientList(
Thing t)
496 this.UseStock =
true;
506 this.ingredients.Add(item);
510 public virtual void OnChangeIngredient()
516 public virtual bool CanRotate
520 return this.tileType.CanRotate(
true) && this.tileRow._tiles.Length > 1;
525 public virtual Thing Craft(BlessedState blessed,
bool sound =
false, List<Thing> ings =
null,
bool model =
false)
527 string type = this.source.type;
529 if (!(type ==
"Block"))
531 if (!(type ==
"Obj"))
533 thing =
ThingGen.CreateFloor(this.tileRow.id,
this.GetMainMaterial().id,
this.source.isBridge);
537 thing =
ThingGen.CreateObj(this.tileRow.id,
this.GetMainMaterial().id);
542 thing =
ThingGen.CreateBlock(this.tileRow.id,
this.GetMainMaterial().id);
548 thing.trait.OnCrafted(
this);
549 thing.SetBlessedState(blessed);
554 Msg.Say(
"crafted", thing,
null,
null,
null);
556 if (thing.GetRootCard() ==
EClass.pc)
558 EClass.pc.HoldCard(thing, -1);
564 public bool HasSameTile(
Point point,
int dir,
int altitude,
int bridgeHeight)
568 if (point.growth !=
null && point.sourceObj ==
this.tileRow && point.cell.matObj ==
this.GetColorMaterial())
572 if (dir == point.cell.objDir && point.cell.matObj ==
this.GetColorMaterial() && point.sourceObj ==
this.tileRow)
577 else if (this.IsBridge)
579 if (dir == point.cell.floorDir && point.matBridge ==
this.GetColorMaterial() && point.sourceBridge ==
this.tileRow && Mathf.Clamp(bridgeHeight + altitude, 0, 255) == (
int)point.cell.bridgeHeight)
584 else if (this.IsFloorOrBridge)
586 if (dir == point.cell.floorDir && point.matFloor ==
this.GetColorMaterial() && point.sourceFloor ==
this.tileRow)
591 else if (this.IsWallOrFence)
593 if (point.matBlock ==
this.GetColorMaterial() && point.sourceBlock ==
this.tileRow && dir == point.cell.blockDir)
598 else if (this.IsBlock && point.matBlock ==
this.GetColorMaterial() && point.sourceBlock ==
this.tileRow)
600 return !point.sourceBlock.tileType.AltitudeAsDir || dir == point.cell.objDir;
606 public virtual void Build(
TaskBuild task)
608 this.Build(task.owner,
null, task.pos, (
this.ingredients.Count > 0) ?
this.ingredients[0].mat : task.recipe.idMat, task.dir, task.altitude, task.bridgeHeight);
612 public virtual void Build(
Chara chara,
Card t,
Point pos,
int mat,
int dir,
int altitude,
int bridgeHeight)
618 EClass.pc.PlaySound(
EClass.sources.materials.rows[mat].GetSoundImpact(
null), 1f,
true);
619 pos.cell.isModified =
true;
620 string type = this.source.type;
621 if (!(type ==
"Block"))
625 if (pos.sourceObj.tileType.RemoveOnFloorChange && (!
BuildMenu.Instance || !
EClass.debug.ignoreBuildRule))
627 EClass._map.SetObj(pos.x, pos.z, 0, 1, 0);
629 EClass._map.SetFloor(pos.x, pos.z, mat,
this.tileRow.id, dir);
632 if (type ==
"Bridge")
634 if (pos.sourceObj.tileType.RemoveOnFloorChange)
636 EClass._map.SetObj(pos.x, pos.z, 0, 1, 0);
638 EClass._map.SetBridge(pos.x, pos.z, Mathf.Clamp(bridgeHeight + altitude, 0, 255), mat,
this.tileRow.id, dir);
641 if (!(type ==
"Obj"))
645 EClass._map.SetObj(pos.x, pos.z, mat,
this.tileRow.id, 1, dir);
646 if (this.tileType.ChangeBlockDir)
648 EClass._map.SetBlockDir(pos.x, pos.z, dir);
650 if (pos.growth !=
null)
652 pos.growth.SetDefaultStage();
658 int ramp = this.tileRow.id;
661 ramp =
EClass.sources.materials.rows[mat].ramp;
663 if (
EClass.scene.actionMode.IsRoofEditMode(
null))
665 EClass._map.SetRoofBlock(pos.x, pos.z, mat, ramp, dir, altitude);
668 if (pos.HasObj && !pos.sourceObj.tileType.CanBuiltOnBlock)
670 EClass._map.MineObjSound(pos);
671 EClass._map.SetObj(pos.x, pos.z, 0, 1, 0);
673 EClass._map.SetBlock(pos.x, pos.z, mat, ramp, dir);
674 if (this.tileType.IsBlockPass && pos.HasChara)
676 foreach (
Chara t2
in pos.ListCharas())
678 chara.Kick(t2,
false,
true);
681 if (this.tileType.AltitudeAsDir)
683 pos.cell.objDir = dir;
685 foreach (
Card card
in pos.ListCards(
false))
687 if (card.isThing && card.placeState == PlaceState.roaming)
689 card._Move(card.pos.GetNearestPoint(
false,
true,
true,
false),
Card.MoveType.Walk);
697 public unsafe
virtual void OnRenderMarker(
Point point,
bool active, HitResult result,
bool main,
int dir,
int bridgeHeight)
703 RenderParam renderParam = this.tileRow.GetRenderParam(this.DefaultMaterial, this._dir, point, bridgeHeight);
704 renderParam.matColor = (float)(active ?
EClass.Colors.blockColors.Active :
EClass.Colors.blockColors.Inactive);
705 point.ApplyAnime(renderParam);
706 if (this.tileType.IsWater)
708 if (
EClass.screen.guide.isActive)
710 EClass.screen.guide.passGuideFloor.Add(point, (
float)result, 0.3f);
714 if (this.tileType.IsWallOrFence && point.HasNonWallBlock)
716 Vector3 vector = *point.Position();
717 if (
EClass.screen.guide.isActive)
719 EClass.screen.guide.passGuideBlock.Add(ref vector, 5f, 0f);
722 if (this.renderRow.renderData.pass ==
EClass.screen.tileMap.passBlock ||
this.renderRow.renderData.pass ==
EClass.screen.tileMap.passBlockEx ||
this.renderRow.renderData.pass ==
EClass.screen.tileMap.passLiquid)
724 if (bridgeHeight > 0 && !point.cell.skipRender &&
EClass.screen.guide.isActive)
726 EClass.screen.guide.passGuideFloor.Add(point, (
float)result, 0.3f);
728 if (!this.tileType.IsWallOrFence && (point.HasChara || (point.HasObj && point.cell.blocked)))
730 Vector3 vector2 = *point.Position();
731 if (
EClass.screen.guide.isActive)
733 EClass.screen.guide.passGuideBlock.Add(ref vector2, 5f, 0f);
737 if (
EClass.scene.actionMode.IsRoofEditMode(
null))
739 EClass.screen.tileMap.SetRoofHeight(renderParam, point.cell, point.x, point.z, 0, bridgeHeight,
this.tileType.IsWallOrFence ?
this._dir : -1,
true);
741 renderParam.y = renderParam.y - EClass.screen.tileMap.rendererBlockMarker.offset.y + this.renderRow.renderData.offset.y;
742 renderParam.z +=
EClass.setting.render.tileMarkerZ;
743 int num = (this.tileType.blockRenderMode == BlockRenderMode.Pillar) ? (this._dir + 1 + ((this._dir >= 7) ? this._dir : 0)) : 1;
746 EClass.screen.tileMap.rendererBlockMarker.Draw(renderParam);
749 EClass.screen.tileMap.rendererBlockMarker.DrawRepeat(renderParam, num, this.tileType.RepeatSize,
false);
754 if (this.renderRow.renderData.pass ==
EClass.screen.tileMap.passFloor ||
this.renderRow.renderData.pass ==
EClass.screen.tileMap.passFloorEx ||
this.renderRow.renderData.pass ==
EClass.screen.tileMap.passFloorWater)
760 renderParam.z += ((point.cell.liquidLv > 0) ? -0.01f :
EClass.setting.render.tileMarkerZFloor);
761 EClass.screen.tileMap.rendererFloorMarker.Draw(renderParam);
764 renderParam.z +=
EClass.setting.render.tileMarkerZ;
765 this.renderRow.renderData.Draw(renderParam);
771 public string GetName()
773 if (this.UseStock && this.ingredients[0].thing ==
null)
777 string text = this.UseStock ? this.ingredients[0].thing.Name : this.source.Name;
780 text = (
"card_" + this.source.id).lang();
784 text = this.source.row.GetText(
"aka",
false);
788 text =
"(" + this.source.row.GetField(
"id") +
")";
790 return text.ToTitleCase(
false);
794 public virtual string GetDetail()
796 return this.renderRow.GetText(
"detail",
false).IsEmpty(this.source.GetDetail());
800 public virtual void WriteNote(UINote n)
807 public void WriteReqFactory(UINote n,
bool hasFactory =
true)
809 if (this.source.NeedFactory)
811 n.AddHeaderTopic(
"reqFactory".lang(this.source.NameFactory.TagColor(hasFactory ? FontColor.Default : FontColor.Bad,
null),
null,
null,
null,
null),
null);
817 public void WriteReqSkill(UINote n)
819 n.AddHeaderTopic(
"reqSkill",
null);
820 Element reqSkill = this.source.GetReqSkill();
821 int value =
EClass.pc.elements.GetOrCreateElement(reqSkill).Value;
822 Color textColor =
EClass.Colors.Skin.GetTextColor((value >= reqSkill.Value) ? FontColor.Good : FontColor.Warning);
823 n.AddText(
null,
string.Concat(
new string[]
827 reqSkill.Value.ToString(),
831 }), textColor).text1.SetSize(-1);
838 return this.tileRow.renderData;
842 public virtual void OnSelected()
847 public virtual void OnChangeAltitude(
int a)
852 public virtual void Rotate()
854 if (EInput.isShiftDown || Input.GetMouseButton(1))
862 if (this.tileType.AltitudeAsDir)
864 if (this._dir >= this.tileType.MaxAltitude)
870 this._dir = this.tileType.MaxAltitude - 1;
875 int num = this.tileRow._tiles.Length;
876 if (this.tileRow.tileType ==
TileType.Door)
884 if (this._dir >= num)
896 public virtual void SetDir(
int d)
906 public virtual Recipe Duplicate()
908 return IO.DeepCopy<
Recipe>(
this);
912 public virtual void SetImage(Image icon)
914 this.renderRow.SetImage(icon,
null, this.renderRow.GetColorInt((
this.ingredients !=
null &&
this.ingredients.Count > 0 &&
this.ingredients[0].thing !=
null) ?
this.ingredients[0].thing.material :
this.DefaultMaterial),
true, 0,
this.idSkin);
918 public bool IsCraftable()
922 if (!ingredient.optional &&
EClass._map.Stocked.ListThingStack(ingredient, StockSearchMode.AroundPC).max < ingredient.req)
931 public int GetMaxCount()
934 for (
int i = 0; i < this.ingredients.Count; i++)
937 Thing thing = ingredient.thing;
939 if (!ingredient.optional || thing !=
null)
941 if (thing !=
null && !thing.isDestroyed)
943 num2 = thing.Num / ingredient.req;
955 public void SetTextDifficulty(UIText text)
957 Element reqSkill = this.source.GetReqSkill();
958 int value =
EClass.pc.elements.GetOrCreateElement(reqSkill).Value;
959 string text2 = reqSkill.Name +
" " + reqSkill.Value.ToString();
964 public int GetSortVal()
966 Element reqSkill = this.source.GetReqSkill();
967 return reqSkill.source.id * 10000 - reqSkill.Value;
971 public static Dictionary<string, Recipe> recipeCache =
new Dictionary<string, Recipe>();
983 public bool UseStock;
987 public bool IngAsProduct;
991 public bool VirtualBlock;
1000 public int idMat = -1;
1006 public Recipe.State state;
1025 public bool IsThingSpecified
1029 return this.uid != 0;
1035 public string IdThing
1043 return EClass.sources.categories.map[this.id].GetIdThing();
1048 public Thing RefreshThing()
1050 if (this.thing ==
null)
1052 this.thing =
EClass.pc.things.Find(this.uid);
1053 if (this.thing ==
null)
1055 this.thing =
EClass._map.Stocked.Find(this.uid);
1056 if (this.thing ==
null)
1058 this.thing =
EClass.pc.things.Find(this.
id, this.mat, this.refVal);
1059 if (this.thing ==
null)
1061 this.thing =
EClass._map.Stocked.Find(this.
id, this.mat, this.refVal,
false);
1070 public bool CanSetThing(
Thing t)
1072 return !(t.id != this.id) && t.Num >=
this.req;
1076 public void SetThing(
Thing t =
null)
1078 this.uid = ((t !=
null) ? t.uid : 0);
1080 this.mat = ((t !=
null) ? t.material.id : -1);
1084 public string GetName()
1089 if (this.idOther.Count > 0)
1091 foreach (
string text2
in this.idOther)
1096 return "ingCat".lang(text,
null,
null,
null,
null);
1098 string str =
EClass.sources.cards.map[this.id].GetName().IsEmpty((
"card_" + this.
id).lang());
1099 string text3 = this.tag.IsEmpty() ?
"" : (
"(" + (
"tag_" + this.tag).lang() +
")");
1100 if (this.idOther.Count > 0)
1102 foreach (
string key
in this.idOther)
1104 text3 = text3 +
", " +
EClass.sources.cards.map[key].GetName();
1112 internal static string <GetName>g__CatName|18_0(
string id)
1114 return EClass.sources.categories.map[id].GetName();
1127 public int mat = -1;
1131 public int refVal = -1;
1143 public List<string> idOther =
new List<string>();
1149 public bool optional;