public void Generate(IEntity e) { BaseContainer cont = null; LootStage stage = LootStage.Death; int luckChance = 0; bool hasBeenStolenFrom = false; Mobile from = e as Mobile; if (e is BaseCreature bc) { cont = bc.Backpack as BaseContainer; stage = bc.LootStage; luckChance = bc.KillersLuck; hasBeenStolenFrom = bc.StealPackGenerated; } else { cont = e as BaseContainer; } if (cont != null) { Generate(from, cont, stage, luckChance, hasBeenStolenFrom); } }
public bool CanGenerate(LootStage stage, bool hasBeenStolenFrom) { switch (stage) { case LootStage.Spawning: if (!AtSpawnTime) { return(false); } break; case LootStage.Stolen: if (!OnStolen) { return(false); } break; case LootStage.Death: if (OnStolen && hasBeenStolenFrom) { return(false); } break; } return(true); }
public Item Construct(IEntity from, int luckChance, LootStage stage, bool hasBeenStolenFrom) { int totalChance = 0; for (int i = 0; i < Items.Length; ++i) { totalChance += Items[i].Chance; } int rnd = Utility.Random(totalChance); for (int i = 0; i < Items.Length; ++i) { LootPackItem item = Items[i]; if (rnd < item.Chance) { Item loot = null; if (item.ConstructCallback != null) { loot = item.ConstructCallback(from); } else { loot = item.Construct(IsInTokuno(from), IsMondain(from), IsStygian(from)); } if (loot != null) { return(Mutate(from, luckChance, loot)); } } rnd -= item.Chance; } return(null); }
public void Generate(IEntity from, BaseContainer cont, LootStage stage, int luckChance, bool hasBeenStolenFrom) { if (cont == null) { return; } bool checkLuck = true; for (int i = 0; i < m_Entries.Length; ++i) { LootPackEntry entry = m_Entries[i]; if (!entry.CanGenerate(stage, hasBeenStolenFrom)) { continue; } bool shouldAdd = entry.Chance > Utility.Random(10000); if (!shouldAdd && checkLuck) { checkLuck = false; if (CheckLuck(luckChance)) { shouldAdd = entry.Chance > Utility.Random(10000); } } if (!shouldAdd) { continue; } Item item = entry.Construct(from, luckChance, stage, hasBeenStolenFrom); if (item != null) { if (from is BaseCreature && item.LootType == LootType.Blessed) { Timer.DelayCall(TimeSpan.FromMilliseconds(25), () => { var corpse = ((BaseCreature)from).Corpse; if (corpse != null) { if (!corpse.TryDropItem((BaseCreature)from, item, false)) { corpse.DropItem(item); } } else { item.Delete(); } }); } else if (item.Stackable) { cont.DropItemStacked(item); } else { cont.DropItem(item); } } } }