Elin:Code Analysis/Unclassified: Difference between revisions

From Ylvapedia
(add code analysis for gamble chest)
m (Move the beekeeping code from the Bee hive page.)
 
(One intermediate revision by one other user not shown)
Line 151: Line 151:
* This code defines what happens when you open a gamble chest.
* This code defines what happens when you open a gamble chest.
* Winning only grants you orens.
* Winning only grants you orens.
* The maximum orens you can win is (500 × Chest Level) + 5000. For example, if the chest's name ends with +50, based on this formula, you can win an amount between 15000 and 30000 orens.
* The maximum orens you can win is (500 × Chest Level) + 5000.  
** 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 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.
* 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">
int soilCost = EClass._zone.GetSoilCost();
CS$<>8__locals1.flower = 5;
int num = Mathf.Min(100, 70 + (this.MaxSoil - soilCost));
int num2 = 0;
foreach (Thing thing3 in EClass._map.things)
{
    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>
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.
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.
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.
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.
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.
Flowers can still contribute to honeycomb production even if defertilized (e.g. to survive winter without the usage of sun lamps).
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 />

Latest revision as of 12:27, 18 April 2025


This page is designed to feature code analysis that are currently unclassified into other pages, either due to being too minor detail, or don't have enough stuff to justify having its entire page.

Material in this page will be moved into other pages constantly. Please refrain from linking wiki articles onto this page.

For authors: Please note the version of game tested on for each section added.

Drink from well (EA23.67)

Version EA23.67: This article is at least 20 minor version or a major version behind the latest stable release of Elin. Please help update the page.
public override void TrySetAct(ActPlan p)
	{
		p.TrySetAct("actDrink", delegate
		{
			if (Charges <= 0)
			{
				EClass.pc.Say("drinkWell_empty", EClass.pc, owner);
				return false;
			}
			EClass.pc.Say("drinkWell", EClass.pc, owner);
			EClass.pc.PlaySound("drink");
			EClass.pc.PlayAnime(AnimeID.Shiver);
			if (IsHoly || EClass.rnd(5) == 0)
			{
				ActEffect.Proc(EffectId.ModPotential, EClass.pc, null, (!polluted && (IsHoly || EClass.rnd(2) == 0)) ? 100 : (-100));
			}
			else if (EClass.rnd(5) == 0)
			{
				BadEffect(EClass.pc);
			}
			else if (EClass.rnd(4) == 0)
			{
				ActEffect.Proc(EffectId.Mutation, EClass.pc);
			}
			else if (EClass.rnd(EClass.debug.enable ? 2 : 10) == 0 && !polluted && !EClass.player.wellWished)
			{
				if (EClass.player.CountKeyItem("well_wish") > 0)
				{
					EClass.player.ModKeyItem("well_wish", -1);
					ActEffect.Proc(EffectId.Wish, EClass.pc, null, 10 + EClass.player.CountKeyItem("well_enhance") * 10);
					EClass.player.wellWished = true;
				}
				else
				{
					Msg.SayNothingHappen();
				}
			}
			else if (polluted)
			{
				EClass.pc.Say("drinkWater_dirty");
				BadEffect(EClass.pc);
			}
			else
			{
				EClass.pc.Say("drinkWater_clear");
			}
			ModCharges(-1);
			return true;
		}, owner);
	}
  • These code explains what happens when you drink water from well.
  • 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.


  • Overall Chances for non-holy, non-polluted well:
    • 10% Main Attribute Potential Increase
    • 10% Main Attribute Potential Decrease
    • 16% 1 of 7 type of Bad effect on PC
    • 16% Random Mutation on PC
    • 4.8% Wish (if PC meet the requirement)
    • 43.2% Plain Water.

Gamble Chest (EA23.96)

Version EA23.96: This article is at least 20 minor version or a major version behind the latest stable release of Elin. Please help update the page.
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())
		{
			this.owner.PlaySound("lock_open_small", 1f, true);
			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)
			{
				flag = false;
			}
			int num = 20 + this.target.c_lockLv / 3;
			if (flag)
			{
				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)
				{
					flag2 = true;
				}
				if (flag2)
				{
					this.owner.PlaySound("money", 1f, true);
					this.owner.PlayAnime(AnimeID.Jump, false);
					Thing thing = ThingGen.Create("money", -1, -1).SetNum(EClass.rndHalf(50 * (100 + this.target.c_lockLv * 10)));
					this.owner.Pick(thing, false, true);
					this.owner.Say("gambleChest_win", thing, null, null);
				}
				else
				{
					this.owner.Say("gambleChest_loss", null, null);
				}
				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;
	}
  • This code defines what happens when you open a gamble chest.
  • Winning only grants you orens.
  • The maximum orens you can win is (500 × Chest Level) + 5000.
    • 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 [1]

int soilCost = EClass._zone.GetSoilCost();
CS$<>8__locals1.flower = 5;
int num = Mathf.Min(100, 70 + (this.MaxSoil - soilCost));
int num2 = 0;
foreach (Thing thing3 in EClass._map.things)
{
    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);
        }
    }
}

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. 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.

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.

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.

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. Flowers can still contribute to honeycomb production even if defertilized (e.g. to survive winter without the usage of sun lamps).

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.

Table of hive number vs flower count