Skip to content

Commit

Permalink
v2.1.0 - Added RandomItemPicks to PotEntry
Browse files Browse the repository at this point in the history
* Permitted negative value ItemDef stacks (increases chance of item not genning)
* Added RandomItemPicks to PotEntry
  • Loading branch information
hamstar0 committed Nov 28, 2021
1 parent 1bef2de commit 525e8d6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
10 changes: 8 additions & 2 deletions PotLuck/MyConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class MyFloatInputElement : FloatInputElement { }


public class PotItemEntry {
[Range(0, 999)]
[Range( -999, 999 )]
[DefaultValue(1)]
public int MinStack;

[Range( 0, 999 )]
[Range( 1, 999 )]
[DefaultValue( 1 )]
public int MaxStack;

Expand All @@ -32,6 +32,12 @@ public class PotEntry {
[DefaultValue( 1f )]
public float PercentChance;

[Range( -1, 100 )]
[DefaultValue( -1 )]
public int RandomItemPicks = -1;

//

[DefaultValue( false )]
public bool HardModeOnly;

Expand Down
13 changes: 12 additions & 1 deletion PotLuck/MyMod_Pot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,21 @@ public partial class PotLuckMod : Mod {

//

foreach( PotItemEntry itemEnt in potEnt.ItemDefs ) {
IEnumerable<PotItemEntry> itemDefs = potEnt.ItemDefs;
if( potEnt.RandomItemPicks >= 1 ) {
itemDefs = itemDefs
.OrderBy( i => Main.rand.Next() )
.Take( potEnt.RandomItemPicks );
}

foreach( PotItemEntry itemEnt in itemDefs ) {
var pos = new Vector2( tileX<<4, tileY<<4 );
int stack = rand.Next( itemEnt.MinStack, itemEnt.MaxStack );

if( stack <= 0 ) {
continue;
}

int who = Item.NewItem(
position: pos,
Type: itemEnt.ItemDef.Type,
Expand Down
2 changes: 1 addition & 1 deletion PotLuck/build.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
displayName = Pot Luck
author = hamstar
version = 2.0.0
version = 2.1.0
modReferences = ModLibsCore@1.0.0, ModLibsGeneral@1.0.0
buildIgnore = *.csproj, *.user, *.bat, obj\*, bin\*, .vs\*, .git\*
homepage = https://forums.terraria.org/index.php?threads/pot-luck.86129/

0 comments on commit 525e8d6

Please sign in to comment.