Profit from Effects

heeheehee

Developer
Staff member
Profit from Effects (Penultimate version)

[size=+2]Profit_FX 1.65[/size]
[SIZE=-1]Profit_FX requires ZLib, revision 8356 or newer (profit_fx-old only requires 7915), and some intuition as to how to use it.[/SIZE]

I began this as a side-project with the idea that it'd eventually be incorporated into aqualectrix's PriceAdvisor script. Moved it away from that thread to stop wasting space and threadjacking and whatnot.

Basically, it's a modification of zarqon's profit.ash , except a lot of additional features:
  • Uses duration of effects, as obtained from relfx.txt. Accurate for sauce potions, Crimbo09 campground items, and all sushi. And everything else that matters to farmers. I hope.
  • Handles Slime Tube properly -- encounters are based on active ML.
  • Takes Fishy into account if you're adventuring in the Sea.
  • Factors in profit from noncombats, using information from noncombats.txt.
  • Advises you whether maximizing combats or noncombats would be optimal; accounts removing Fresh/Hippy Scent and managing related skills. Does not cast any skills, in case you're worried about that.
  • Does some sneaky stuff for script authors who might want to import it. It's a lot of crappy code (i.e. poorly-written) to include here, so they're not provided here.
  • Takes Olfaction into account if you have the skill. Suggests the most profitable monster to olfact, if verbosity is set to 2 or higher.
  • Figuring of revenue from each item is as follows: If the fifth mallprice (Mafia feature) is min-priced, assume that the item will be autosold. Otherwise, use fifth mallprice.
  • Supports effects gained from resting, to some extent.

This script requires ZLib.ash and revision 8014 or later. Just put this script in your scripts folder, and after importing it, you can use it in your scripts by calling the following function:
float meat_gain(location place, string itm).

Other possible site of interest: as of version 1.3, it now generates this following map upon execution:
drop[key].ct[i,m], where:
key is an item that is a possible drop from this zone,
i is an integer that allows Mafia to differentiate between multiple instances of the item,
m is the monster from which the item drops, which is used for olfaction and combat rate modifying purposes,
and the float yielded (drop[key].ct[i,m]) is the expected increase in drops of that item from using this additional item.

Also, another new variable as of 1.3: tot_meetz, the expected increase in raw meat from using this item, then adventuring at a specified location.

As of 1.55: Supports effects gained from resting (sort of). Just pass "rest" as the second parameter. Also, passing an empty string ("") as the second parameter now returns your estimated current MPA.

The only visible output if verbosity < 3 that this script produces tells the user which monster in this zone would be most profitable to olfact (verbosity = 2).

Notes: The function requests a string instead of an item to accommodate for cases such as sushi. Demon summoning is supported to an extent -- put the effect name instead of the item name. Finally, it does not support pickpocketing -- drop rates for PP-only items aren't even spaded out, are they?


This should not be the final version, because of unforeseen bugs that need squashing and additions that I feel like making. Automatically updates map files, which I'll upload as items get introduced to the game and people start yelling at me to update (It outputs a message to do so in the CLI if it encounters an unsupported item that affects MPA). Or when zones get added.

[SIZE=-1]
7/20: Various bugfixes. It's been a while.
4/4: Now uses the nifty item_drop_array(), which was introduced in revision 8356. This resulted in a noticeably smaller file. The old version is also included for those who don't use the newest revisions.
3/21: Not really an update, but this just replaces all instances of is_numeric() to is_integer in accordance with Mafia changes.
3/15: Wow, it's been a while. Added preliminary support for resting (pass "rest" as the second parameter). Also added an option to receive the standalone MPA of a zone, based on current modifiers (pass "" as the second parameter).
2/15: Fixed another possible error with the noncombat-parsing section. Added Dungeons of Doom to noncombats.txt. Why it wasn't there, I don't know. Fixed error with potion of detection.
2/6: Cleaned up some code (lines 174-237 expanded to 174-246 as a byproduct, but it's much easier to read). Also squished some Olfaction errors.
1/30: Bugfix -- previously, it would not work for items like Angry Farmer Candy, where there are multiple sources of the same effect not in relfx.txt (Just an example -- in the future, there might be other, relevant effects that it wouldn't have worked for). Also updated relfx.txt to include some other sources of Brined Liver. Also added stripping item names of trademarks.
1/27: Added some code, now requires revision 8014 or later (attempts to get duration if possible). Also made it return a value no matter what.
1/24: Added another two lines of code. You now have the option to have the script automatically set your valueOfAdventure each time it executes. False by default, of course.
1/24: Meh, felt like adding version checking for the script. Just one line of code, so it's not worthy of an entire update.
1/23 (Yeah, again): Added a sneaky map that actually contains all item drops. Also, a float that contains the increased meat. Whoo!
1/23: Erm, yeah. Change to ZLib and the adding of the type aggregate compel me to update using the new version of load_current_map. Whoo!
1/14: Added automatic data file update functionality. This should be the final version of this script, unless I find something that absolutely needs fixing.
1/12: Fixed the 8-Bit Realm screwiness and olfaction problems. Got even messier, though. =P
1/8: Added version numbers.
1/3: Stopped threadjacking and created this thread.
[/SIZE]
 

Attachments

  • profit_fx.ash
    19.7 KB · Views: 123
Last edited:

dj_d

Member
This seems really cool, but - could you explain for people with small tired minds like me what this does, again? :)
 

xKiv

Active member
Using item X while farming location Y will net you a total of Z sweet meatz ... so don't sell it for less in mall!
 

heeheehee

Developer
Staff member
As noted, it's basically the extra meat you'd get from farming, using that specific item. The only known error so far is a Mafia-limitation -- from what I've observed, item_drops stores each individual drop in a map, using the item as the key and the rate as the return value. The end-result is that if a monster can drop multiple instances of an item, the last one listed in monsters.txt is the only rate that it returns. This is especially problematic in zones like the 8-Bit Realm and Hole in the Sky for obvious reasons.

Edit: I've been working on a workaround for this for quite some time, but ugh, my code is just so ugly -- is there a way to repeat for each key in a record? It'd be so much easier.

Double edit: New version up, but it returns some wonky results (i.e. no change in MPA for olfacting monsters? I'll try to find the problem behind this). Good news, it now tells you to olfact bloopers in the 8-bit realm, and MPA there is more accurate. Tested with 200 turns; MPA was 2.07 less than expected. Close enough!


On another completely unrelated note, should I add a snippet to increase accuracy by importing all mall prices from here? It'd use a slight modification of the whole "automatically update map files", downloading from that site instead of zarqon's MMM.

I'm going to wait on the second one in case of ethical issues, but yeah. Just throwing that out there as a possible feature in the future, and another resource for other scripters to use.
 
Last edited:
Revision 8014 adds some neat stuff for potion duration/effect that might save your map some work. (On the other hand, it doesn't know about things that KoL doesn't place in the "potions" category, so the map is still necessary.)
 

heeheehee

Developer
Staff member
Awesome. Got the new version up, which may or may not mean that I'll just need to do less updating of the maps. Go laziness!
 

heeheehee

Developer
Staff member
New version! (Been a while; I got sidetracked.)

Notable additions (copied from the version update, really): Added preliminary support for resting (pass "rest" as the second parameter). Also added an option to receive the standalone MPA of a zone, based on current modifiers (pass "" as the second parameter).
 

Theraze

Active member
I know it's been a while since it's been updated but... got bored and realized that the 'final' version had the display section stripped out of loc_profit. Tried to splice it back in from zarqon's profit... think this should hopefully be accurate and actually work if you're wondering for more information on which monster makes an area best, etc. This is part of my quick 3-alias best location package. :D

Edit: Realized that when I fixed the no-display result to give the proper one, hadn't fixed the display version to return the same result, so it was still giving the /100+fammeat version. This one should give same results whether or not you're displaying them.
 
Last edited:

Theraze

Active member
Updated version that will skip beer lenses after the third drop (and they stop being possible). Got tired of my farming location getting stuck for the brawl because of beer lenses...
 

Theraze

Active member
Here's an updated version that will actually display if you have olfaction, which all versions above won't. As well, it will display the olfaction-values below, not just the standard-values.

Can you guess who just hit 200 lucre on the first character that actually remembered to bounty hunt? :) Anyways, example of a display for the brawl post-beer lens below.
You will want to olfact Werecougar for 572.1618375 MPA rather than 362.66999999999996.
Generating report...
Profit Estimate for A Barroom Brawl
5 monsters dropping 0.0 meat and 768.35 worth in items.
Meat/Adv 572.1618375 (assuming 0.0% noncombats)
Meat/Combat 362.67
Best monster Werecougar (561.44 meat)
Total zone value 768.35
Familiar (30 lb. Ninja Pirate Zombie Robot)
Average bonus 209.0
Meat (+117.0%)
Average meatdrop 0.0
Meatiest monster Werecougar (0.0 meat)
Items (+142.0%)
Average itemdrop 153.67000000000002
Returned: 572.1618375

Edit: Uh... there's still some sort of bizarre bug with olfaction and meat. Returning ameat for Giant Castle
It is more profitable to maximize combats.
Cast Musk.
Cast Cantata.
You will want to olfact Goth Giant for 880.422319444762 MPA rather than 795.2460007936509.
Returned: 228.2
Returning omeat:
It is more profitable to maximize combats.
Cast Musk.
Cast Cantata.
You will want to olfact Goth Giant for 880.422319444762 MPA rather than 795.2460007936509.
Returned: 12337.62648
Now I wouldn't mind getting 12337.6 meat per fight on average... but I think something went wrong with the calculations there. All I've done to generate these is changed the if (!display) line to return ameat and omeat, so it should be using the same info that everything else uses. Also, looks kind of like tot_meetz is only getting set if you have non-combats... so the Oasis has an average meatdrop of 0, the GC has an average meatdrop of 2252.

Edit2:
Meat (+117.0%)
Average meatdrop 38.03333333333333
Meatiest monster Goth Giant (326.0 meat)
When the omeat lines had been copied from the olfactval bit, the *100 on olfactval hadn't been taken into account. Threw some /100 bits on both of the spots using rate[bestmon] and now it properly gives a reduced/accurate meat value. New profit_fx attached. In addition to the omeat fix, also moved tot_meetz from a global variable to live inside the loc_profit function for safety and defined it outside of the NC section, since it didn't appear to have been doing anything useful where it was. It multiplied best meat by rate1 and then subtracted itself, before it was set... so it was confused code designed for some sort of recursion, but that recursion doesn't currently exist, so... current version, eh.
 
Last edited:

BlanketThief

New member
It looks like the profit calculations from +/- combat is outputting the inverse of what it should be. +Combat being better when I've lowered my +item/meat bonuses and such (and-com outputting a higher profit calculation when I've increased my meat/item drop bonuses respectively)

Line 447 is missing a " as well it seems
 

Theraze

Active member
Looks like on post 13, it's actually line 448 missing the ", but...

Regarding profit calculations being reversed, any specifics you've found suggesting it's backwards? Nothing I've seen seems reversed in #13, but I might be missing something.

Anyways, updated with new quote-mark bit. And removed the old/broken versions above.
 

Attachments

  • profit_fx.ash
    20.9 KB · Views: 38

BlanketThief

New member
Using a fairychaun, checking handful of pine needles (Hippy stench, 10 adv, +5% combat) at the Giant's Castle (+10% Combat rate already) gives
Code:
Meat/Adv will increase from 1067.119741367229 to 1041.3749517125398 => -25.744789654689157 additional meat per adventure.
Yield of -257.44789654689157 meat (over 10 turns).
Without fairychaun
Code:
Meat/Adv will increase from 826.1579296666666 to 810.0516124799999 => -16.10631718666673 additional meat per adventure.
Yield of -161.0631718666673 meat (over 10 turns).

Inverse applies to rock salt (+25 MPA with fairychaun, +16 without), relfx.txt does appear to have the correct values for these two items. I also used the Dungeons of Doom and some other area I can't recall to double check that the error isn't castle-specific.

edit: But given how I ended up changing line 447 to
Code:
itm = replace_string(itm,"・","");
from 
itm = replace_string(item,"・,"");
I may have just goofed.

Edit2: Still need to change 447 to add the quotation mark it seems, with line 448 giving off this error now "Expected ), found blue (profit_fx.ash, line 448)"

edit3: which is now fixed after changing line 448 to:
Code:
        vprint("Item: "+itm,"blue",3);
 
Last edited:

Theraze

Active member
Bah, I should have left the post 13. That was fine already. What line 447 does is remove the TM symbol if it exists, and it does it properly. If the item name has TM in it, replace that with "" (nothing). So... back to what we had in post 13.

Well, profit and profit_fx give very different results currently...

Profit:
Evaluating monsters based on current meat/item drop rates...
meat (150 @ +12.0): 168
heavy D (40 @ +17.0): 135 meat * 46.8% = 63
original G (40 @ +17.0): 143 meat * 46.8% = 67
Alphabet Giant avg. value: 298.0 meat.
meat (150 @ +12.0): 168
awful poetry journal (30 @ +17.0): 136 meat * 35.1% = 48
thin black candle (30 @ +17.0): 144 meat * 35.1% = 51
Warm Subject gift certificate (30 @ +17.0): 450 meat * 35.1% = 158
Goth Giant avg. value: 425.0 meat.
meat (150 @ +12.0): 168
furry fur (35 @ +17.0): 129 meat * 40.95% = 53
disturbing fanfic (30 @ +17.0): 132 meat * 35.1% = 46
wolf mask (10 @ +17.0): 165 meat * 11.7% = 19
Furry Giant avg. value: 286.0 meat.
meat (150 @ +12.0): 168
chaos butterfly (20 @ +17.0): 124 meat * 23.4% = 29
plot hole (20 @ +17.0): 128 meat * 23.4% = 30
probability potion (30 @ +17.0): 128 meat * 35.1% = 45
Possibility Giant avg. value: 272.0 meat.
meat (150 @ +12.0): 168
procrastination potion (30 @ +17.0): 138 meat * 35.1% = 48
Procrastination Giant avg. value: 216.0 meat.
meat (150 @ +12.0): 168
Angry Farmer candy (30 @ +17.0): 137 meat * 35.1% = 48
giant needle (30 @ +17.0): 165 meat * 35.1% = 58
Mick's IcyVapoHotness Rub (30 @ +17.0): 141 meat * 35.1% = 49
rave whistle (5 @ +17.0): 200 meat * 5.85% = 12
Raver Giant avg. value: 335.0 meat.
Generating report...
Profit Estimate for Giant's Castle6 monsters dropping 1008 meat and 824 worth in items.Meat/Adv229.0 (assuming 25.0% noncombats)Meat/Combat305.0Best monsterGoth Giant (425 meat)Total zone value1832Meat (+12.0%)Average meatdrop168Meatiest monsterRaver Giant (168 meat)Items (+17.0%)Average itemdrop137Itemiest monsterGoth Giant (257 worth)
Returned: 229.0
Profit_fx:
It is more profitable to maximize noncombats.
Generating report...
Profit Estimate for Giant's Castle6 monsters dropping 126.0 meat and 824.3235 worth in items.Meat/Adv324.989375 (assuming 25.0% noncombats)Meat/Combat158.38725Best monsterGoth Giant (424.23 meat)Total zone value950.3235Meat (+12.0%)Average meatdrop21.0Meatiest monsterGoth Giant (168.0 meat)Items (+17.0%)Average itemdrop137.38725
Returned: 324.989375
If I remember properly, I had to figure out something out for meat in profit.ash to make it work properly and it was having similar issues. Will do a new post if/when I get that sorted, but it appears to be prioritizing noncombats because it thinks NC are indeed better.
 

Attachments

  • profit_fx.ash
    20.9 KB · Views: 39

Theraze

Active member
Okay, this modifies the ameat to not multiply by freq and divide by 100. Not sure how it will work with olfaction yet, since I'm still in a class act run, but it DOES look right for normal...

If you look inside the file, you can see the individual monster tracking are still in there, I haven't validated this works yet. So... hey, easy monster infos with just a // to remove.
 

Attachments

  • profit_fx.ash
    21.1 KB · Views: 43

xKiv

Active member
Code:
                float rate1=freq[$monster[none]] < 100 ? ((100-(freq[$monster[none]]+combat_rate)*(noncombats[wear].NC_count/(noncombats[wear].NC_count+noncombats[wear].skip)))/(100-freq[$monster[none]])) : 0;
		float rate2=((freq[$monster[none]]+combat_rate)*noncombats[wear].NC_count/(noncombats[wear].NC_count+noncombats[wear].skip))/100;
...
      avgdval=avgdval*(rate1)+avg_meat_per_NC*(rate2);

Notice the + on combat_rate in both lines. The block of ifs one page up from that implies that combat_rate is higher with +combat% effects (as expected), so wouldn't this piece of code mean that value of noncombat is given higher weight when you run *less* +noncombat effects?

ETA: also, shouldn't the second freq[$monster[none]] for rate1 be also adorned by +-combat_rate? (+ or - depending on which is correct).
Also also, I would consider reporting value of combat_rate (i.e. how big combat rate modifier was considered by the script), rate1 and rate2 (effective combat/noncombat rates) and avg_meat_per_NC, for clearer overview and better debugging.
 
Last edited:

Theraze

Active member
You add the number, whether it's positive or negative. Adding up to +25 or as low as -25 combat rate... That doesn't look like a bug.
 
Top