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.)
 
(13 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)
{
p.TrySetAct("actDrink", delegate
{
{
int num2 = EClass.pc.Evalue(1418);
if (Charges <= 0)
Thing thing4 = ai.ings[1];
{
SourceElement.Row source2 = (thing4.trait as TraitSpellbook).source;
EClass.pc.Say("drinkWell_empty", EClass.pc, owner);
int num3 = thing4.c_charges * source2.charge * (100 + num2 * 50) / 500 + 1;
return false;
int num4 = 100;
}
Thing thing5 = ThingGen.Create("talisman").SetNum(num3);
EClass.pc.Say("drinkWell", EClass.pc, owner);
thing5.refVal = source2.id;
EClass.pc.PlaySound("drink");
thing5.encLV = num4 * (100 + num2 * 10) / 100;
EClass.pc.PlayAnime(AnimeID.Shiver);
thing.ammoData = thing5;
if (IsHoly || EClass.rnd(5) == 0)
thing.c_ammo = num3;
{
EClass.pc.Say("talisman", thing, thing5);
ActEffect.Proc(EffectId.ModPotential, EClass.pc, null, (!polluted && (IsHoly || EClass.rnd(2) == 0)) ? 100 : (-100));
thing4.Destroy();
}
break;
else if (EClass.rnd(5) == 0)
}
{
</syntaxhighlight>
BadEffect(EClass.pc);
 
}
* The "talisman mastery 2" trait of swordmage positively influence the effect of created talismans. Specifically:
else if (EClass.rnd(4) == 0)
** 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'''.
ActEffect.Proc(EffectId.Mutation, EClass.pc);
*** 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.
else if (EClass.rnd(EClass.debug.enable ? 2 : 10) == 0 && !polluted && !EClass.player.wellWished)
 
{
==Ether Diseases (EA23.61)==
if (EClass.player.CountKeyItem("well_wish") > 0)
===Depiction of Ether Disease in code: an Index===
{
<syntaxhighlight lang="c#" line="1">
EClass.player.ModKeyItem("well_wish", -1);
public const int etherManaBattery = 1564;
ActEffect.Proc(EffectId.Wish, EClass.pc, null, 10 + EClass.player.CountKeyItem("well_enhance") * 10);
public const int etherPoisonHand = 1565;
EClass.player.wellWished = true;
public const int etherProvoke = 1563;
}
public const int etherStupid = 1561;
else
public const int etherWeak = 1560;
{
public const int etherAddict = 1559;
Msg.SayNothingHappen();
public const int etherRain = 1558;
}
public const int etherHead = 1557;
}
public const int etherViolence = 1556;
else if (polluted)
public const int etherNeck = 1555;
{
public const int etherWing = 1554;
EClass.pc.Say("drinkWater_dirty");
public const int etherEye = 1553;
BadEffect(EClass.pc);
public const int etherFeet = 1552;
}
public const int etherArmor = 1562;
else
public const int etherUgly = 1551;
{
public const int etherGravity = 1550;
EClass.pc.Say("drinkWater_clear");
}
ModCharges(-1);
return true;
}, owner);
}
</syntaxhighlight>
</syntaxhighlight>


* All ether disease is depicted with integer (i.e. level). There are 16 kinds of diseases, and we will review each of them.
* These code explains what happens when you drink water from well.
* If you want to see for the effect yourself, just search for that number in code.
* 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.


=== Mana Battery ===
<syntaxhighlight lang="c#" line="1">
    case 1564:
ModBase(961, a * 5, hide: false);
break;
</syntaxhighlight>


* This disease increase your magic resistance (961) by 5 per level (there is only one level currently).
* 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|23.96}}
<syntaxhighlight lang="c#" line="1">
<syntaxhighlight lang="c#" line="1">
public void TryAbsorbRod(Thing t)
public override IEnumerable<AIAct.Status> Run()
{
{
if (!IsPC || !(t.trait is TraitRod) || t.c_charges <= 0 || !HasElement(1564))
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())
{
{
return;
this.owner.PlaySound("lock_open_small", 1f, true);
}
this.owner.LookAt(this.target);
Say("absorbRod", this, t);
this.target.renderer.PlayAnime(AnimeID.Shiver, default(Vector3), false);
TraitRod rod = t.trait as TraitRod;
yield return base.KeepRunning();
bool flag = false;
EClass.player.stats.gambleChest++;
if (rod.source != null)
Rand.SetSeed(EClass.game.seed + EClass.player.stats.gambleChest);
{
bool flag = this.owner.Evalue(280) + 5 >= EClass.rnd(this.target.c_lockLv + 10);
using IEnumerator<SourceElement.Row> enumerator = EClass.sources.elements.rows.Where((SourceElement.Row a) => a.id == rod.source.id).GetEnumerator();
if (EClass.rnd(20) == 0)
if (enumerator.MoveNext())
{
flag = true;
}
if (EClass.rnd(20) == 0)
{
flag = false;
}
int num = 20 + this.target.c_lockLv / 3;
if (flag)
{
{
SourceElement.Row current = enumerator.Current;
num *= 3;
if (IsPC)
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
{
{
GainAbility(current.id, t.c_charges * 100);
this.owner.Say("gambleChest_loss", null, null);
flag = true;
}
}
Rand.SetSeed(-1);
}
}
}
else
if (!flag)
{
{
this.owner.Say("gambleChest_broke", this.target.GetName(NameStyle.Full, 1), null);
mana.Mod(-50 * t.c_charges);
this.owner.PlaySound("rock_dead", 1f, true);
}
}
t.c_charges = 0;
this.target.ModNum(-1, true);
LayerInventory.SetDirty(t);
this.owner.ModExp(280, num);
}
if (EClass.rnd(2) == 0)
    ...
    public void GainAbility(int ele, int mtp = 100)
{
Element orCreateElement = elements.GetOrCreateElement(ele);
if (orCreateElement.ValueWithoutLink == 0)
{
elements.ModBase(orCreateElement.id, 1);
}
if (orCreateElement is Spell)
{
int num = mtp * orCreateElement.source.charge * (100 + Evalue(307) + (HasElement(307) ? 20 : 0)) / 100 / 100;
if (orCreateElement.source.charge == 1)
{
{
num = 1;
this.owner.stamina.Mod(-1);
}
}
orCreateElement.vPotential += Mathf.Max(1, num / 2 + EClass.rnd(num / 2 + 1));
}
}
Say("spell_gain", this, orCreateElement.Name);
yield break;
LayerAbility.SetDirty(orCreateElement);
}
}
</syntaxhighlight>


* 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 <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>
</syntaxhighlight>


* Once detect PC have mana battery, it will take the charges in a rod, then call Gainability(this spell, 100 * charge number) to give PC this spell.
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.
* This does not mean you get 100 wish spells for 1 charge of wish rod! Each spell have a unique charge parameter (see SourceGame/Element for more), and depend on the charge number it will give you number of spell casting.
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.
** This value is modified by your memorization skill. If you have the skill, a flat 20% is added, then for each skill level, 1% added.
As a tent is not a 'base', beehives do not work within tents.
** For example, for a wish rod, and you have lvl 80 memorization, the num will equal to = 100 * 1 (Wish has a charge number of 1) * (80+100+20) / 100 / 100 = 2
 
** Which is pretty good, yes, you get 2 wishes out of 1 rod, but can you cast it, hum?
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.
* After that, if you are not PC, your mana will be drained by 50 per charge of rod. Then the rod goes to 0 charges.
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 />