private static void BuyItem(Player player, ref MsgItem packet) { if (Collections.Items.TryGetValue(packet.Param, out var item)) { if (GameWorld.Find(packet.UnqiueId, out Npc shop)) { if (shop.Inventory == null) { Output.WriteLine($"Shop {shop.UniqueId} null."); return; } if (!shop.Inventory.HasItem(item.ItemId)) { Output.WriteLine($"Item {item.ItemId} not found in Shop {shop.UniqueId}"); return; } if (player.Money >= item.PriceBaseline) { if (player.Inventory.Count < 40) { var cloned = CloneChamber.Clone(item); cloned.UniqueId = YiCore.Random.Next(1000, 100000); player.Inventory.Items.AddOrUpdate(cloned.UniqueId, cloned); player.Money -= cloned.PriceBaseline; player.Send(new MsgItemInformation(cloned, MsgItemPosition.Inventory)); } } } } }
public static Item Create(Item original) { if (!Enum.IsDefined(typeof(RebornItemEffect), original.RebornEffect)) { original.RebornEffect = RebornItemEffect.None; } var clone = CloneChamber.Clone(original); clone.UniqueId = UniqueIdGenerator.GetNext(EntityType.Item); return(clone); }
public static Task Spawn(int max = 0) { return(Task.Run(() => { foreach (var spawn in Collections.Spawns) { Monster monster; if (!Collections.BaseMonsters.TryGetValue(spawn.Value.MobId, out monster)) { continue; } for (var i = 0; i < spawn.Value.Amount; i++) { var obj = CloneChamber.Clone(Collections.BaseMonsters[spawn.Value.MobId]); obj.SpawnId = spawn.Key; obj.UniqueId = UniqueIdGenerator.GetNext(EntityType.Monster); obj.MapId = spawn.Value.MapId; obj.Location.X = spawn.Value.Xstart; obj.Location.Y = spawn.Value.Ystart; if (!GameWorld.Maps.ContainsKey(obj.MapId)) { continue; } var spawnAttempts = 0; while (true) { if (spawnAttempts > 1000) { break; } spawnAttempts++; if (GameWorld.Maps[obj.MapId].MobValid(obj.Location.X, obj.Location.Y)) { Collections.Monsters.AddOrUpdate(obj.UniqueId, obj); GameWorld.Maps[obj.MapId].LoadInEntity(obj); break; } obj.Location.X = (ushort)YiCore.Random.Next(spawn.Value.Xstart - 10, spawn.Value.Xstart + spawn.Value.Xend + 10); obj.Location.Y = (ushort)YiCore.Random.Next(spawn.Value.Ystart - 10, spawn.Value.Ystart + spawn.Value.Yend + 10); if (obj.Look == 900 || obj.Look == 910)//Guard1 Guard2 { obj.Brain = new GuardBrain(obj); } } } } })); }
public static bool Buy(Player player, int shopId, int productId) { var last = false; var ownerId = BoothPool.Keys.FirstOrDefault(c => c == shopId); if (!GameWorld.Find(ownerId - 10000000, out YiObj owner)) { return(false); } var product = owner?.Inventory.FindByUID(productId); if (product == null || !BoothPool[ownerId].ContainsKey(product.UniqueId)) { return(false); } var price = BoothPool[ownerId][product.UniqueId].Product.Price; if (player.Money < price) { return(false); } if (player.Inventory.Count >= 40) { return(false); } player.Money -= price; owner.Money += price; if (product.StackAmount == 1) { Remove(owner, productId); owner.Inventory.RemoveItem(product); last = true; } else { product.StackAmount--; product.Product.Price += product.Product.Price / 2; } var purchased = CloneChamber.Clone(product); purchased.StackAmount = 1; player.Inventory.AddItem(purchased); Show(player, shopId); return(last); }
public bool AddItem(Item item, int count = 1) { if (Items.Count + count > 40) { return(false); } for (var i = 0; i < count; i++) { var clone = CloneChamber.Clone(item); clone.UniqueId = YiCore.Random.Next(1000, 100000); Items.TryAdd(clone.UniqueId, clone); (_owner as Player)?.Send(new MsgItemInformation(clone, MsgItemPosition.Inventory)); } return(true); }
public static bool Buy(Player player, int shopId, int itemId) { var last = false; var ownerId = BoothPool.Keys.FirstOrDefault(c => c == shopId); if (!GameWorld.Find(ownerId - 10000000, out YiObj owner)) { return(false); } if (!owner.Inventory.TryGetItem(itemId, out var item) || !BoothPool[ownerId].ContainsKey(item.UniqueId)) { return(false); } var price = BoothPool[ownerId][item.UniqueId].Price; if (player.Money < price) { return(false); } if (player.Inventory.Count >= 40) { return(false); } player.Money -= price; owner.Money += price; if (item.StackAmount == 1) { Remove(owner, itemId); owner.Inventory.RemoveItem(item); last = true; } else { item.StackAmount--; //item.Price += item.Price / 2; } var purchased = CloneChamber.Clone(item); purchased.StackAmount = 1; player.Inventory.AddItem(purchased); Show(player, shopId); return(last); }
public static void Spawn() { var _sync = new object(); var sw = Stopwatch.StartNew(); Parallel.ForEach(Collections.Spawns, spawn => { var amount = spawn.Value.Amount; if (!Collections.BaseMonsters.TryGetValue(spawn.Value.MobId, out var monster)) { return; } if (monster.Look != 900 && monster.Look != 910) { amount = (ushort)(amount * 9); } for (var i = 0; i < amount; i++) { var obj = CloneChamber.Clone(Collections.BaseMonsters[spawn.Value.MobId]); obj.SpawnId = spawn.Key; obj.MapId = spawn.Value.MapId; obj.Location.X = spawn.Value.Xstart; obj.Location.Y = spawn.Value.Ystart; var spawnAttempts = 0; while (true) { if (spawnAttempts > 100) { break; } spawnAttempts++; lock (_sync) { if (!GameWorld.Maps.ContainsKey(obj.MapId) || GameWorld.Maps[obj.MapId].MobValid(obj.Location.X, obj.Location.Y)) { if (obj.Look == 900 || obj.Look == 910) //Guard1 Guard2 { obj.Brain = new GuardBrain(obj); } obj.UniqueId = UniqueIdGenerator.GetNext(EntityType.Monster); Collections.Monsters.Add(obj.UniqueId, obj); GameWorld.Maps[obj.MapId].LoadInEntity(obj); break; } } obj.Location.X = (ushort)SafeRandom.Next(spawn.Value.Xstart - 10, spawn.Value.Xstart + spawn.Value.Xend + 10); obj.Location.Y = (ushort)SafeRandom.Next(spawn.Value.Ystart - 10, spawn.Value.Ystart + spawn.Value.Yend + 10); } } }); sw.Stop(); Debug.WriteLine($"[MobGenerator] Spawnd {Collections.Monsters.Count}\t Monsters in {sw.Elapsed.TotalMilliseconds}ms"); }