User:Cuyler/common.js

/* Table holding the item type */ const rng_tbl = [ 0x0016, 0x001a, 0x001c, 0x001e, 0x0000, 0x0008, 0x0005, 0x0009, 0x0022, 0x0000, 0x000c, 0x0025, 0x000c, 0x0025, 0x0000, 0x000c, 0x0025, 0x000c, 0x0025, 0x0000,

0x0017, 0x001b, 0x001d, 0x001f, 0x0000, 0x0009, 0x0006, 0x000a, 0x0022, 0x0000, 0x000c, 0x0025, 0x000c, 0x0025, 0x0000, 0x000c, 0x0025, 0x000c, 0x0025, 0x0000,

0x000a, 0x0004, 0x0008, 0x000c, 0x0000, 0x0009, 0x0004, 0x0008, 0x000c, 0x0000, 0x0008, 0x0004, 0x0008, 0x000c, 0x0000, 0x0008, 0x0004, 0x0008, 0x000c, 0x0000,

0x000b, 0x0006, 0x0009, 0x000c, 0x0000, 0x000a, 0x0006, 0x0009, 0x000c, 0x0000, 0x0009, 0x0006, 0x0008, 0x000c, 0x0000, 0x0009, 0x0006, 0x0008, 0x000c, 0x0000,

0x0021, 0x0017, 0x001f, 0x0022, 0x0000, 0x0016, 0x001a, 0x001c, 0x001e, 0x0000, 0x001e, 0x000c, 0x001e, 0x000c, 0x0000, 0x001e, 0x000c, 0x001e, 0x000c, 0x0000,

0x0019, 0x0018, 0x0021, 0x001f, 0x0000, 0x0017, 0x001b, 0x001d, 0x001f, 0x0000, 0x001e, 0x000c, 0x001e, 0x000c, 0x0000, 0x001e, 0x000c, 0x001e, 0x000c, 0x0000,

0x0018, 0x0025, 0x000c, 0x0025, 0x0000, 0x0017, 0x0025, 0x000c, 0x0025, 0x0000, 0x0016, 0x0025, 0x000c, 0x0025, 0x0000, 0x0016, 0x0025, 0x000c, 0x0025, 0x0000,

0x0024, 0x0025, 0x000c, 0x0025, 0x0000, 0x0019, 0x0025, 0x000c, 0x0025, 0x0000, 0x0017, 0x0025, 0x000c, 0x0025, 0x0000, 0x0017, 0x0025, 0x000c, 0x0025, 0x0000 ];

/* All possible group names in order of generator index */ const group_names = [ "Apple", "Orange", "Peach", "Pear", "Random fruit", "Coconut", "Mushroom", "Candy", "100 Bells", "1,000 Bells", "10,000 Bells", "30,000 Bells", "Pitfall", "Purple Cosmos", "Blue Cosmos", "Yellow Cosmos", "Red Tulips", "White Tulips", "Yellow Tulips", "White Pansies", "Purple Pansies", "Yellow Pansies", "Common furniture", "Rare furniture", "50/50 Lottery furniture or Redd furniture", "Island furniture", "Common flooring", "Rare flooring", "Common wallpaper", "Rare wallpaper", "Common clothing", "Rare clothing", "50/50 Single-part fossil or Multi-part fossil", "Gyroid", "Umbrella", "K.K. aircheck", "Island NES", "Trash" ];

/* Base index into rng_tbl */ const base_idx_adj_tbl = [ 0x0000, 0x0078, 0x0028, 0x0050, 0x0000, 0x0050, 0x0000, 0x0000, 0x0078, 0x0028, 0x0028, 0x0028, 0x0000, 0x0050, 0x0000, 0x0028, 0x0050, 0x0028, 0x0078, 0x0028, 0x0000, 0x0000, 0x0050, 0x0028, 0x0000, 0x0000, 0x0078, 0x0050, 0x0000, 0x0028, 0x0078, 0x0028, 0x0050, 0x0000, 0x0028, 0x0000, 0x0000, 0x0050, 0x0078, 0x0028, 0x0028, 0x0028, 0x0000, 0x0050, 0x0028, 0x0050, 0x0078, 0x0000, 0x0000, 0x0000, 0x0050, 0x0050, 0x0028, 0x0000, 0x0078, 0x0000, 0x0000, 0x0028, 0x0050, 0x0000, 0x0078, 0x0028, 0x0028, 0x0000, 0x0028, 0x0050, 0x0000, 0x0078, 0x0000, 0x0050, 0x0000, 0x0028, 0x0050, 0x0000, 0x0078, 0x0000, 0x0078, 0x0000, 0x0028, 0x0078, 0x0028, 0x0000, 0x0050, 0x0028, 0x0000, 0x0000, 0x0078, 0x0028, 0x0050, 0x0028, 0x0028, 0x0000, 0x0078, 0x0000, 0x0028, 0x0000, 0x0050, 0x0078, 0x0000, 0x0078, 0x0050, 0x0028, 0x0000, 0x0078, 0x0000, 0x0000, 0x0000, 0x0050, 0x0078, 0x0050, 0x0028, 0x0000, 0x0000, 0x0000, 0x0000, 0x0050, 0x0028, 0x0078, 0x0050, 0x0000, 0x0028, 0x0050, 0x0028, 0x0078, 0x0028, 0X0000 ];

/* Adjustment into rng_tbl based on mood */ /* NOTE: Mood table goes: Neutral -> Angry -> Sad -> Happy */ const mood_adj_tbl = [ 0x5, 0x15, 0xA, 0x0 ];

/* Base index lookup sub-adjustment based on current hour */ const hour_adj_tbl = [ 0, 0, 0, 0,	0, 0, 1, 1,	1, 2, 2, 2,	3, 3, 3, 4,	4, 4, 5, 5,	5, 6, 6, 6 ];

function getFloatingItemPercentages(islanderIdx, hour, mood, usingGoldenShovel) { var percentages = {}; /* Get the offset into the item table */ var base_ofs = base_idx_adj_tbl[islanderIdx * 7 + hour_adj_tbl[hour]] + mood_adj_tbl[mood]; if (usingGoldenShovel) { base_ofs += 20;	// Golden shovel adds 20 to the offset }	if (base_ofs >= 160) { base_ofs = 0; // Anything out of bounds is set to offset 0 }	/* Get the four items starting at our base offset */ for (var i = 0; i < 4; i++) { var val = rng_tbl[base_ofs + i]; var name = group_names[val]; if (percentages[name] === undefined) { percentages[name] = 1; }		else { percentages[name]++; }	}	/* Divide by four to get percentages */ for (const [key, value] of Object.entries(percentages)) { percentages[key] = value / 4.0; }	return percentages; }