public static QuestMonster getRandomQuest(Player player, bool boss) { int playerValue = ModGeneric.getPlayerValue(player); List <QuestGenNPC> list = new List <QuestGenNPC>(); foreach (KeyValuePair <string, NPC> pair in Config.npcDefs.byName) { NPC npc = pair.Value; if (npc.townNPC || npc.friendly || npc.dontTakeDamage) { continue; } if (getNPCValue(npc) < 1) { continue; } if (boss != isBoss(npc)) { continue; } int tAmount = getBestAmount(playerValue, npc); if (tAmount > 0) { list.Add(new QuestGenNPC(npc, tAmount)); } } if (list.Count != 0) { int average = 0; for (int i = 0; i < list.Count; i++) { average += (int)list[i].npc.value * list[i].amount; } average = (int)(1d * average / list.Count); List <QuestGenNPC> list2 = new List <QuestGenNPC>(); for (int i = 0; i < list.Count; i++) { if (list2.Count == 0) { list2.Add(list[i]); } else { int val1 = (int)Math.Abs(list[i].npc.value * list[i].amount - average), val2 = (int)Math.Abs(list2[0].npc.value * list2[0].amount - average); if (val1 == val2) { list2.Add(list[i]); } else if (val1 < val2) { list2.Clear(); list2.Add(list[i]); } } } QuestGenNPC qgnpc = list2[list2.Count == 1 ? 0 : Main.rand.Next(list2.Count)]; return(new QuestMonster(qgnpc.amount, Reward.getRandomReward(getQuestValue(qgnpc)), qgnpc.npc)); } return(null); }
private static int getQuestValue(QuestGenNPC qgnpc) { return (int)(getNPCValue(qgnpc.npc)*(isBoss(qgnpc.npc) ? 5 : 1)*qgnpc.amount*(20d+Main.rand.NextDouble()*10d)); }
private static int getQuestValue(QuestGenNPC qgnpc) { return((int)(getNPCValue(qgnpc.npc) * (isBoss(qgnpc.npc) ? 5 : 1) * qgnpc.amount * (20d + Main.rand.NextDouble() * 10d))); }