Elin:Code Analysis/Unclassified: Difference between revisions

m
Move the beekeeping code from the Bee hive page.
m (Move the beekeeping code from the Bee hive page.)
 
(7 intermediate revisions by 2 users not shown)
Line 7: Line 7:
'''For authors''': Please note the version of game tested on for each section added.
'''For authors''': Please note the version of game tested on for each section added.


==Sword Mage - Talisman Trait (EA23.54)==
== Drink from well (EA23.67)==
{{Version|23.67}}
<syntaxhighlight lang="c#" line="1">
<syntaxhighlight lang="c#" line="1">
    case MixType.Talisman:
public override void TrySetAct(ActPlan p)
{
int num2 = EClass.pc.Evalue(1418);
Thing thing4 = ai.ings[1];
SourceElement.Row source2 = (thing4.trait as TraitSpellbook).source;
int num3 = thing4.c_charges * source2.charge * (100 + num2 * 50) / 500 + 1;
int num4 = 100;
Thing thing5 = ThingGen.Create("talisman").SetNum(num3);
thing5.refVal = source2.id;
thing5.encLV = num4 * (100 + num2 * 10) / 100;
thing.ammoData = thing5;
thing.c_ammo = num3;
EClass.pc.Say("talisman", thing, thing5);
thing4.Destroy();
break;
}
</syntaxhighlight>
 
* The "talisman mastery 2" trait of swordmage positively influence the effect of created talismans. Specifically:
** The number of charges created by swordmage will be '''(magic_book_charges * num_of_charge_gained_if_read * 2 / 5) + 1'''.
** For a normal PC, the number of charges will be '''(magic_book_charges * num_of_charge_gained_if_read * 1 / 5) + 1'''.
*** For example, for a magic book with 3 reads left with each read giving PC 10 charges, the number of talisman charge by swordmage would be 13, while by normal PC would be 7.
** The talisman level created by swordmage is fixed at 120, while fixed at 100 by normal PC.
 
== Food Effect (EA 23.62 Hotfix 1) ==
'''Food Effect''' is one of the most important part of Elin and Elona. As the saying goes "you are what you eat." We shall put the entire code here, and track any changes affecting the biggest part of the game: cooking and eating.
 
=== Human or not human? ===
<syntaxhighlight lang="c#" line="1">
    public static bool IsHumanFlesh(Thing food)
{
{
if (food.HasTag(CTAG.notHumanMeat))
p.TrySetAct("actDrink", delegate
{
return false;
}
if (food.id == "deadbody")
{
return true;
}
if (food.source._origin != "meat" && food.source._origin != "dish")
{
return false;
}
string[] components = food.source.components;
for (int i = 0; i < components.Length; i++)
{
{
if (components[i].Contains("egg"))
if (Charges <= 0)
{
{
EClass.pc.Say("drinkWell_empty", EClass.pc, owner);
return false;
return false;
}
}
}
EClass.pc.Say("drinkWell", EClass.pc, owner);
if (!IsHumanFlesh(food.refCard))
EClass.pc.PlaySound("drink");
{
EClass.pc.PlayAnime(AnimeID.Shiver);
return IsHumanFlesh(food.refCard2);
if (IsHoly || EClass.rnd(5) == 0)
}
{
return true;
ActEffect.Proc(EffectId.ModPotential, EClass.pc, null, (!polluted && (IsHoly || EClass.rnd(2) == 0)) ? 100 : (-100));
}
}
</syntaxhighlight>
else if (EClass.rnd(5) == 0)
 
* This part of the code controls whether the corpse is considered human flesh:
** If the food has id of "deadbody", then it is automatically True.
** If the food is not meat or dish, it is automatically False.
*** Probably want to disinclude milk, eggs, etc.
** If the food components contains egg, then it is not considered human flesh.
*** '''This can potentially be exploited to put human flesh and egg together and create a non-human flesh dish.'''
*** Not many recipes put meat and egg together though.
** The refCard effects '''need to be confirmed'''.
 
=== Undead or not? ===
<syntaxhighlight lang="c#" line="1">
public static bool IsUndeadFlesh(Thing food)
{
if (food.source._origin != "meat" && food.source._origin != "dish")
{
return false;
}
if (!IsUndeadFlesh(food.refCard))
{
return IsUndeadFlesh(food.refCard2);
}
return true;
}
</syntaxhighlight>
 
* The code for undead flesh is much more simple.
** It checks if the food in question is raw meat or a complete dish. If not returns false.
** It then checks the refCards of the food & components. ('''Need confirmation''')
 
=== How much does this food give you? ===
'''WARNING''': This section is not based on empirical analysis.
 
Please beware the editor's understanding of this part of the code is rudimentary only.
 
* There are a few main contributing factor of a dish.
** One of them is a overall modifier, in code this is depicted as '''num2'''
<syntaxhighlight lang="c#" line="1">
bool flag = EClass._zone.IsPCFaction && c.IsInSpot<TraitSpotDining>();
int num = (food.isCrafted ? ((EClass.pc.Evalue(1650) >= 3) ? 5 : 0) : 0);
    float num2 = (float)(100 + (food.HasElement(757) ? 10 : 0) + (flag ? 10 : 0) + num + Mathf.Min(food.QualityLv * 10, 100)) / 200f;
if (num2 < 0.1f)
{
num2 = 0.1f;
}
</syntaxhighlight>
* This value is first set start from 100, if just cooked +10, if consumed in the eating area in PC region +10, if crafted by PC with 3 level of gourmet +5. Each level of food quality +10 ('''Need confirmation if it is the value shown on screen'''), then divided by 200.
** Example: A dish crafted by a normal PC, with food quality of lvl 5, consumed in the eating area, would have a value of 0.8.
** If this value is less than 0.1, it is set at 0.1.
 
<syntaxhighlight lang="c#" line="1">
bool flag2 = IsHumanFlesh(food);
bool flag3 = IsUndeadFlesh(food);
bool flag4 = c.HasElement(1205);
bool flag5 = food.IsDecayed || flag3;
    if (food.IsBlessed)
{
num2 *= 1.5f;
}
if (food.IsCursed)
{
num2 *= 0.5f;
}
if (flag4)
{
if (flag2)
{
{
num5 *= 2f;
BadEffect(EClass.pc);
num2 *= 1.5f;
}
}
else
else if (EClass.rnd(4) == 0)
{
{
num5 *= 0.5f;
ActEffect.Proc(EffectId.Mutation, EClass.pc);
num2 /= 2f;
num3 /= 2;
}
}
}
else if (EClass.rnd(EClass.debug.enable ? 2 : 10) == 0 && !polluted && !EClass.player.wellWished)
        else if (flag2)
{
num5 = 0f;
num2 *= 0.5f;
}
</syntaxhighlight>
 
* With the previous value, if the food is blessed, increase 50%, if the food is cursed, cut by 50%.
* If the consumer have canniblism and the dish is human, increase 50%, if dish is not human, cut by 50%, while the nutrition of the dish is also cut by 50%.
* If the consumer doesn't have cannibilism and the dish is human, cut by 50%.
 
<syntaxhighlight lang="c#" line="1">
if (c.HasElement(1200))
{
num2 *= 1.25f;
}
if (!c.IsPC)
{
num2 *= 3f;
}
</syntaxhighlight>
 
* If the PC have the trait of Efficient Feeder (Juere), the value is increase by 25%.
* If the consumer is not PC, increased by 200%.
** This is the main reason why pets outpaces PC really fast... They eat 3 times more efficient than PC!
 
<syntaxhighlight lang="c#" line="1">
switch (food.source._origin)
{
{
case "meat":
if (EClass.player.CountKeyItem("well_wish") > 0)
if (c.IsPC)
{
{
c.Say("food_raw_meat");
EClass.player.ModKeyItem("well_wish", -1);
ActEffect.Proc(EffectId.Wish, EClass.pc, null, 10 + EClass.player.CountKeyItem("well_enhance") * 10);
EClass.player.wellWished = true;
}
}
num2 *= 0.7f;
else
num5 = 0.5f;
break;
case "fish":
if (c.IsHuman)
{
{
if (c.IsPC)
Msg.SayNothingHappen();
{
c.Say("food_raw_fish");
}
num2 *= 0.9f;
num5 = 0.5f;
}
}
break;
}
case "dough":
else if (polluted)
if (c.IsPC)
{
{
EClass.pc.Say("drinkWater_dirty");
c.Say("food_raw_powder");
BadEffect(EClass.pc);
}
}
num2 *= 0.9f;
else
num5 = 0.5f;
{
break;
EClass.pc.Say("drinkWater_clear");
}
ModCharges(-1);
return true;
}, owner);
}
</syntaxhighlight>
</syntaxhighlight>


* If the food is not rotten:
* These code explains what happens when you drink water from well.
** If the food is raw, depend on the category, its value is further decreased: meat -30%, fish -10%, dough -10%.
* These effects will be applied step by step.
* In 1/5 chance, potential of a main attribute will increase (50%) or decrease (50%).
** This will be forced to trigger if it i a holy well, and will be 100% increase.
* Then in another 1/5 chance, bad effect will be applied to the PC, with equal chance of being one of the seven: Blind, Paralyze, Sleep, Poison, Faint, Disease, Confuse.
* Then in another 1/4 chance, a mutation will be applied to the PC.
* Then in another 1/10 chance, and when PC hasn't wished in this year, and when the well isn't polluted, a wish is granted.
** This chance is increased to 1/2 if user in debug mode.
** The strength of wish is 10 + 10 * the amount of saliva a PC have.
* Then, the normal effect will be triggered.
** If the well is polluted, debuff will be applied to the PC.
** If the well is clean, it is as if the PC drank real water.


<syntaxhighlight lang="c#" line="1">
    int num3 = food.Evalue(10);
    float num6 = Mathf.Min(c.hunger.value, num3);
    if (c.hunger.GetPhase() >= 3)
{
num6 *= 1.1f;
}
if (flag5 && !c.HasElement(480))
{
c.ModExp(70, -300);
c.ModExp(71, -300);
c.ModExp(72, -200);
c.ModExp(73, -200);
c.ModExp(74, -200);
c.ModExp(75, 500);
c.ModExp(76, -200);
c.ModExp(77, -300);
}
</syntaxhighlight>


* The nutrition value (num3) of food is loaded, and the actual nutrition can be absorbed by a character cannot exceed its current hunger value.
* Overall Chances for non-holy, non-polluted well:
* If the character is hungry, then the actual nutrition is increased by 10%.
** 10% Main Attribute Potential Increase
** A reminder, this is an independent 10% modifier.
** 10% Main Attribute Potential Decrease
* If the food is rot and the character cannot take rotten food, each of the characters main attribute will be heavily penalized, except Will, which will have a heavy increase.
** 16% 1 of 7 type of Bad effect on PC
** Guess eating rotten food train your will.
** 16% Random Mutation on PC
** '''4.8% Wish''' (if PC meet the requirement)
** 43.2% Plain Water.


== Gamble Chest (EA23.96)==
{{Version|23.96}}
<syntaxhighlight lang="c#" line="1">
<syntaxhighlight lang="c#" line="1">
    else
public override IEnumerable<AIAct.Status> Run()
{
this.owner.Say("lockpick_start", this.owner, this.target, null, null);
this.owner.PlaySound("lock_pick", 1f, true);
while (this.target.Num > 0 && this.IsValid())
{
{
num2 = num2 * num6 / 10f;
this.owner.PlaySound("lock_open_small", 1f, true);
if (c.HasCondition<ConAnorexia>())
this.owner.LookAt(this.target);
this.target.renderer.PlayAnime(AnimeID.Shiver, default(Vector3), false);
yield return base.KeepRunning();
EClass.player.stats.gambleChest++;
Rand.SetSeed(EClass.game.seed + EClass.player.stats.gambleChest);
bool flag = this.owner.Evalue(280) + 5 >= EClass.rnd(this.target.c_lockLv + 10);
if (EClass.rnd(20) == 0)
{
flag = true;
}
if (EClass.rnd(20) == 0)
{
{
num2 = 0.01f;
flag = false;
}
}
List<Element> list = food.ListValidTraits(isCraft: true, limit: false);
int num = 20 + this.target.c_lockLv / 3;
foreach (Element value in food.elements.dict.Values)
if (flag)
{
{
if (value.source.foodEffect.IsEmpty() || !list.Contains(value))
num *= 3;
EClass.player.stats.gambleChestOpen++;
Rand.SetSeed(EClass.game.seed + EClass.player.stats.gambleChestOpen);
bool flag2 = 100 + this.owner.LUC > EClass.rnd(10000);
if (EClass.debug.enable && EClass.rnd(2) == 0)
{
{
continue;
flag2 = true;
}
}
string[] foodEffect = value.source.foodEffect;
if (flag2)
int id = value.id;
float num7 = num2 * (float)value.Value;
if (value.source.category == "food" && c.IsPC)
{
bool flag6 = num7 >= 0f;
string text = value.source.GetText(flag6 ? "textInc" : "textDec", returnNull: true);
if (text != null)
{
Msg.SetColor(flag6 ? "positive" : "negative");
c.Say(text);
}
}
</syntaxhighlight>
 
* The eventual gain of food is multiplied by its actual nutrition value, divided by 10.
* If the character is currently in Anorxeia, it can only gain 1% of the original benefit of eating.
<syntaxhighlight lang="c#" line="1">
switch (foodEffect[0])
{
case "exp":
{
{
id = ((foodEffect.Length > 1) ? EClass.sources.elements.alias[foodEffect[1]].id : value.id);
this.owner.PlaySound("money", 1f, true);
int a = (int)(num7 * (float)((foodEffect.Length > 2) ? foodEffect[2].ToInt() : 4)) * 2 / 3;
this.owner.PlayAnime(AnimeID.Jump, false);
c.ModExp(id, a);
Thing thing = ThingGen.Create("money", -1, -1).SetNum(EClass.rndHalf(50 * (100 + this.target.c_lockLv * 10)));
break;
this.owner.Pick(thing, false, true);
this.owner.Say("gambleChest_win", thing, null, null);
}
}
case "pot":
else
{
{
id = ((foodEffect.Length > 1) ? EClass.sources.elements.alias[foodEffect[1]].id : value.id);
this.owner.Say("gambleChest_loss", null, null);
int vTempPotential = c.elements.GetElement(id).vTempPotential;
int num8 = EClass.rndHalf((int)(num7 / 5f) + 1);
num8 = num8 * 100 / Mathf.Max(100, vTempPotential * 2 / 3);
c.elements.ModTempPotential(id, num8, 8);
break;
}
}
Rand.SetSeed(-1);
}
else
{
this.owner.Say("gambleChest_broke", this.target.GetName(NameStyle.Full, 1), null);
this.owner.PlaySound("rock_dead", 1f, true);
}
this.target.ModNum(-1, true);
this.owner.ModExp(280, num);
if (EClass.rnd(2) == 0)
{
this.owner.stamina.Mod(-1);
}
}
yield break;
}
</syntaxhighlight>
</syntaxhighlight>


* The food effect for attribute experiences and attribute potential is different.
* This code defines what happens when you open a gamble chest.
** For attribute experiences, the experience gained is (overall modifier (num2)) *  (actual nutrition (num6)) / 10 * dish exp level * 8 / 3.
* Winning only grants you orens.
** For potential increase, the increase is a value between 50% and 100% of (overall modifier (num2)) *  (actual nutrition (num6)) / 10 * dish exp level / 5 + 1.
* The maximum orens you can win is (500 × Chest Level) + 5000.  
*** However the value will be further penalized if the temporal potential is already over 150.
** For example, if the chest's name ends with +50, based on this formula, you can win an amount between 15000 and 30000 orens.
* If a gamble chest is unlocked by an informer, a bug causes the winning amount to be between 2,500 and 3,000 orens.
* The minimum orens you can win is half of the maximum.
* The winning chance is based on the total number of gamble chests opened, allowing players to exploit it through save scumming. For example, if you save your progress, open chests, and win on the 9th one, reloading will always result in a win on the 9th chest.


== Honeycomb production <ref>The code was obtained from [https://www.reddit.com/r/ElinsInn/comments/1k10qxh/question_about_beehives/ u/grenadier42's decompilation of the Nightly code as of 18 Apr 2025.]</ref> ==
<syntaxhighlight lang="c#" line="1">
<syntaxhighlight lang="c#" line="1">
if (!c.IsPCParty)
int soilCost = EClass._zone.GetSoilCost();
{
CS$<>8__locals1.flower = 5;
num3 *= 2;
int num = Mathf.Min(100, 70 + (this.MaxSoil - soilCost));
}
int num2 = 0;
num3 = num3 * (100 + c.Evalue(1235) * 10) / (100 + c.Evalue(1234) * 10 + c.Evalue(1236) * 15);
foreach (Thing thing3 in EClass._map.things)
c.hunger.Mod(-num3);
{
    if (thing3.IsInstalled && thing3.trait is TraitBeekeep && !thing3.things.IsFull(0))
    {
        CS$<>8__locals1.flower -= 3 + EClass.rnd(5 + num2 * 4);
        num2++;
        if (CS$<>8__locals1.flower < 0)
        {
            break;
        }
        if (EClass.rnd(100) <= num)
        {
            Thing thing4 = ThingGen.Create("honey", -1, -1);
            thing4.SetEncLv(CS$<>8__locals1.lv / 10);
            thing4.elements.SetBase(2, EClass.curve(CS$<>8__locals1.lv, 50, 10, 80), 0);
            thing3.AddThing(thing4, true, -1, -1);
        }
    }
}
</syntaxhighlight>
</syntaxhighlight>


* After calculation of nutrition, the fillingness of the food is increased by 10% for light eater, decreased by 10% for heavy eater, and 15% for Norlanders.
Every day a base is updated, the above code runs, which causes each beehive to process whether a honeycomb is produced or not depending on the number of flowers remaining on the map.
* If the character is not in PC party, the fillingness increases by 100%.
To be eligible to run the code, the beehive must be installed on the map (rather than in a container or dropped on the floor) and it must have free slots in its inventory, otherwise it will be treated as if it does not exist.
As a tent is not a 'base', beehives do not work within tents.


=== Is this food tasty? ===
The base 'flower power' of each map is 5, to which the sum total of the Flower, Blue Flower, Yellow Flower, White Flower and Cotton plants on the map is added; i.e. three eligible flowers results in a 'flower power' of 8.
Each successive hive deducts 3 + random (0 to 5 + 4(n-1)) 'flower power' to produce one honeycomb - so the first takes 3 to 8 'flower power', the second takes 3 to 12 'flower power', and so on and so forth.


<syntaxhighlight lang="c#" line="1">
Finally, eligible hives have a probability ([Available Fertility] + 70%) of creating honeycombs; hives on maps with 30 Fertility will have a 100% chance of producing honeycombs if enough 'flower power' is available, while maps with -70 Fertility have a close to 0% chance (the random number generated has to be exactly zero to produce a honeycomb). Because growing flowers takes Fertility in itself, adding flowers increases the maximum number of beehives that can potentially produce honeycombs at the same time it also reduces the probability each beehive actually produces any honeycombs. As the required 'flower power' increases with the number of hives on a map in a geometric manner but the fertility effect is linear, honeycomb production tends to be flower-limited at smaller numbers and Fertility-limited at large numbers.
float num4 = 40f;
float num5 = 1f;
num4 += (float)food.Evalue(70);
num4 += (float)(food.Evalue(72) / 2);
num4 += (float)(food.Evalue(73) / 2);
num4 += (float)(food.Evalue(75) / 2);
num4 += (float)(food.Evalue(76) * 3 / 2);
num4 += (float)food.Evalue(440);
num4 += (float)(food.Evalue(445) / 2);
num4 -= (float)food.Evalue(71);
num4 -= (float)(num3 / 2);
num4 *= num5;
if (idTaste.IsEmpty())
{
if (num4 > 100f)
{
idTaste = "food_great";
}
else if (num4 > 70f)
{
idTaste = "food_good";
}
else if (num4 > 50f)
{
idTaste = "food_soso";
}
else if (num4 > 30f)
{
idTaste = "food_average";
}
else
{
idTaste = "food_bad";
}
</syntaxhighlight>


* The base tastiness of food start at 40, and is heavily related with the exp level of food involved.
When honeycombs are produced, their quality is dependent on the quality of the best eligible flower on the map; a single +70 flower in a field of +0 flowers will still result in all hives producing stacks of +7 honeycombs.
* For each value of STR, tastiness increase by 1.
Flowers can still contribute to honeycomb production even if defertilized (e.g. to survive winter without the usage of sun lamps).
* For each value of PER, DEX, WIL, tastiness increase by 0.5.
* For each value of MAG, tastiness increase by 1.5.
* For each value of STR2 (potential of strength?), tastiness increase by 1.
* For each value of WIL2 (potential of will?), tastiness increase by 0.5.
* For each value of END, tastiness decrease by 1. (The description is the size of the dish...)
* For each on paper nutrition value, the tastiness decrease by 0.5. (The more filling, the less delicious)
* If food is raw, -50%.
* If human flesh, with canniblism, +100%, without canniblism, -50%.
* If food is raw, -100%.


* The final value will be the tastfulness of a dish, >100 great, 70-100 good, 50-70, so so, 30-50 average, <30 bad.
Bee hives spawn neutral bees around them. Killing the bees has no effect on hives or honeycomb production, and there does not need to be a valid path from the beehive to the flowers for honeycombs to be produced.


See the table below for a summary of the number of flowers each hive requires as per the above formula.
Remember to deduct the base 'flower power' of 5 from these numbers; for instance, 25 flowers has a non-zero chance of producing honeycombs from the 10th beehive.


[[File:Beehive.jpg|alt=Table of hive number vs flower count|Number of flowers needed for each hive]]


[[Category:EN]]
[[Category:EN]]
[[Category:Elin Spoiler]]
[[Category:Elin Spoiler]]
<references />