예제 #1
0
        public void Craft(PlayerObject player, ulong index, uint count, int[] slots)
        {
            S.CraftItem p = new S.CraftItem();

            RecipeInfo recipe = null;

            for (int i = 0; i < CraftGoods.Count; i++)
            {
                if (CraftGoods[i].Item.UniqueID != index)
                {
                    continue;
                }
                recipe = CraftGoods[i];
                break;
            }

            UserItem goods = recipe.Item;

            if (goods == null || count == 0 || count > goods.Info.StackSize)
            {
                player.Enqueue(p);
                return;
            }

            bool hasItems = true;

            List <int> usedSlots = new List <int>();

            //Check Items
            foreach (var ingredient in recipe.Ingredients)
            {
                uint amount = ingredient.Count * count;

                for (int i = 0; i < slots.Length; i++)
                {
                    int slot = slots[i];

                    if (usedSlots.Contains(slot))
                    {
                        continue;
                    }

                    if (slot < 0 || slot > player.Info.Inventory.Length)
                    {
                        continue;
                    }

                    UserItem item = player.Info.Inventory[slot];

                    if (item == null || item.Info != ingredient.Info)
                    {
                        continue;
                    }

                    usedSlots.Add(slot);

                    if (amount <= item.Count)
                    {
                        amount = 0;
                    }
                    else
                    {
                        hasItems = false;
                    }

                    break;
                }

                if (amount > 0)
                {
                    hasItems = false;
                    break;
                }
            }

            if (!hasItems)
            {
                player.Enqueue(p);
                return;
            }

            UserItem craftedItem = Envir.CreateFreshItem(goods.Info);

            craftedItem.Count = count;

            if (!player.CanGainItem(craftedItem))
            {
                player.Enqueue(p);
                return;
            }

            //Take Items
            foreach (var ingredient in recipe.Ingredients)
            {
                uint amount = ingredient.Count * count;

                for (int i = 0; i < slots.Length; i++)
                {
                    int slot = slots[i];

                    if (slot < 0)
                    {
                        continue;
                    }

                    UserItem item = player.Info.Inventory[slot];

                    if (item == null || item.Info != ingredient.Info)
                    {
                        continue;
                    }

                    if (item.Count > amount)
                    {
                        player.Enqueue(new S.DeleteItem {
                            UniqueID = item.UniqueID, Count = amount
                        });
                        player.Info.Inventory[slot].Count -= amount;
                        break;
                    }
                    else
                    {
                        player.Enqueue(new S.DeleteItem {
                            UniqueID = item.UniqueID, Count = item.Count
                        });
                        amount -= item.Count;
                        player.Info.Inventory[slot] = null;
                    }

                    break;
                }
            }

            //Give Item
            player.GainItem(craftedItem);

            p.Success = true;
            player.Enqueue(p);
        }
예제 #2
0
        public void Buy(PlayerObject player, ulong index, uint count)
        {
            UserItem goods = null;

            for (int i = 0; i < Goods.Count; i++)
            {
                if (Goods[i].UniqueID != index)
                {
                    continue;
                }
                goods = Goods[i];
                break;
            }

            bool isUsed    = false;
            bool isBuyBack = false;

            var callingNPC = NPCObject.Get(player.NPCObjectID);

            if (callingNPC != null)
            {
                if (goods == null)
                {
                    for (int i = 0; i < callingNPC.UsedGoods.Count; i++)
                    {
                        if (callingNPC.UsedGoods[i].UniqueID != index)
                        {
                            continue;
                        }
                        goods  = callingNPC.UsedGoods[i];
                        isUsed = true;
                        break;
                    }
                }

                if (goods == null)
                {
                    if (!callingNPC.BuyBack.ContainsKey(player.Name))
                    {
                        callingNPC.BuyBack[player.Name] = new List <UserItem>();
                    }
                    for (int i = 0; i < callingNPC.BuyBack[player.Name].Count; i++)
                    {
                        if (callingNPC.BuyBack[player.Name][i].UniqueID != index)
                        {
                            continue;
                        }
                        goods     = callingNPC.BuyBack[player.Name][i];
                        isBuyBack = true;
                        break;
                    }
                }
            }

            if (goods == null || count == 0 || count > goods.Info.StackSize)
            {
                return;
            }

            if (isBuyBack && count > goods.Count)
            {
                count = goods.Count;
            }
            else
            {
                goods.Count = count;
            }

            uint cost = goods.Price();

            cost = (uint)(cost * PriceRate(player));
            uint baseCost = (uint)(goods.Price() * PriceRate(player, true));

            if (player.NPCPage.Key.ToUpper() == PearlBuyKey)//pearl currency
            {
                if (cost > player.Info.PearlCount)
                {
                    return;
                }
            }
            else if (cost > player.Account.Gold)
            {
                return;
            }

            UserItem item = (isBuyBack || isUsed) ? goods : Envir.CreateFreshItem(goods.Info);

            item.Count = goods.Count;

            if (!player.CanGainItem(item))
            {
                return;
            }

            if (player.NPCPage.Key.ToUpper() == PearlBuyKey)//pearl currency
            {
                player.Info.PearlCount -= (int)cost;
            }
            else
            {
                player.Account.Gold -= cost;
                player.Enqueue(new S.LoseGold {
                    Gold = cost
                });

                if (callingNPC != null && callingNPC.Conq != null)
                {
                    callingNPC.Conq.GoldStorage += (cost - baseCost);
                }
            }
            player.GainItem(item);

            if (isUsed)
            {
                callingNPC.UsedGoods.Remove(goods); //If used or buyback will destroy whole stack instead of reducing to remaining quantity

                List <UserItem> newGoodsList = new List <UserItem>();
                newGoodsList.AddRange(Goods);
                newGoodsList.AddRange(callingNPC.UsedGoods);

                callingNPC.NeedSave = true;

                player.Enqueue(new S.NPCGoods {
                    List = newGoodsList, Rate = PriceRate(player)
                });
            }

            if (isBuyBack)
            {
                callingNPC.BuyBack[player.Name].Remove(goods); //If used or buyback will destroy whole stack instead of reducing to remaining quantity
                player.Enqueue(new S.NPCGoods {
                    List = callingNPC.BuyBack[player.Name], Rate = PriceRate(player)
                });
            }
        }
예제 #3
0
        public void Buy(PlayerObject player, ulong index, uint count)
        {
            UserItem goods = null;

            for (int i = 0; i < Goods.Count; i++)
            {
                if (Goods[i].UniqueID != index)
                {
                    continue;
                }
                goods = Goods[i];
                break;
            }

            bool isUsed = false;

            if (goods == null)
            {
                for (int i = 0; i < UsedGoods.Count; i++)
                {
                    if (UsedGoods[i].UniqueID != index)
                    {
                        continue;
                    }
                    goods  = UsedGoods[i];
                    isUsed = true;
                    break;
                }
            }

            bool isBuyBack = false;

            if (goods == null)
            {
                if (!BuyBack.ContainsKey(player.Name))
                {
                    BuyBack[player.Name] = new List <UserItem>();
                }
                for (int i = 0; i < BuyBack[player.Name].Count; i++)
                {
                    if (BuyBack[player.Name][i].UniqueID != index)
                    {
                        continue;
                    }
                    goods     = BuyBack[player.Name][i];
                    isBuyBack = true;
                    break;
                }
            }

            if (goods == null || goods.Count == 0 || goods.Count > goods.Info.StackSize)
            {
                return;
            }

            uint cost = goods.Price();

            cost = (uint)(cost * Info.PriceRate);

            if (player.NPCPage.Key.ToUpper() == PearlBuyKey)//pearl currency
            {
                if (cost > player.Info.PearlCount)
                {
                    return;
                }
            }
            else if (cost > player.Account.Gold)
            {
                return;
            }

            UserItem item = (isBuyBack || isUsed ? goods : Envir.CreateFreshItem(goods.Info));

            item.Count = goods.Count;

            if (!player.CanGainItem(item))
            {
                return;
            }

            if (player.NPCPage.Key.ToUpper() == PearlBuyKey)//pearl currency
            {
                player.Info.PearlCount -= (int)cost;
            }
            else
            {
                player.Account.Gold -= cost;
                player.Enqueue(new S.LoseGold {
                    Gold = cost
                });
            }
            player.GainItem(item);

            if (isUsed)
            {
                UsedGoods.Remove(goods);

                List <UserItem> newGoodsList = new List <UserItem>();
                newGoodsList.AddRange(Goods);
                newGoodsList.AddRange(UsedGoods);

                NeedSave = true;

                player.Enqueue(new S.NPCGoods {
                    List = newGoodsList, Rate = Info.PriceRate
                });
            }

            if (isBuyBack)
            {
                BuyBack[player.Name].Remove(goods);
                player.Enqueue(new S.NPCGoods {
                    List = BuyBack[player.Name], Rate = Info.PriceRate
                });
            }
        }
예제 #4
0
        public void End_Match(bool foundWinner = false)
        {
            bool   failed      = false;
            string matchResult = "";

            if (foundWinner)
            {
                LMS_Rank     lmsRank       = null;
                PlayerObject winningPlayer = null;
                for (int i = 0; i < CurrentMap.Players.Count; i++)
                {
                    PlayerObject player = CurrentMap.Players[i];
                    if (player == null ||
                        player.Dead)
                    {
                        continue;
                    }
                    for (int x = 0; x < PlayerRanks.Count; x++)
                    {
                        if (player.Name == PlayerRanks[x].Player.Name &&
                            winningPlayer == null &&
                            lmsRank == null)
                        {
                            winningPlayer = player;
                            lmsRank       = PlayerRanks[x];
                        }
                    }
                }
                if (winningPlayer != null &&
                    lmsRank != null)
                {
                    //  TODO Reward players (send by mail)
                    matchResult = string.Format("{0} is the Victor of the match!", winningPlayer.Name);

                    winningPlayer.Teleport(Envir.GetMap(winningPlayer.BindMapIndex), winningPlayer.BindLocation, true, 0);
                    winningPlayer.InLMSBR = false;
                    List <LMS_RewardInfo> rewards = CreateRewards(1, winningPlayer);
                    if (rewards != null &&
                        rewards.Count > 0)
                    {
                        winningPlayer.ReceiveChat(string.Format("Victory is yours! Prize(s) will be sent via mail!"), ChatType.Hint);
                        List <UserItem> items = new List <UserItem>();
                        for (int i = 0; i < rewards.Count; i++)
                        {
                            if (rewards[i].ItemReward == null)
                            {
                                SMain.EnqueueDebugging(string.Format("Null reward"));
                                continue;
                            }
                            ItemInfo iInfo = Envir.GetItemInfo(rewards[i].ItemReward.Index);
                            if (iInfo == null)
                            {
                                SMain.EnqueueDebugging(string.Format("Null item info"));
                                continue;
                            }
                            UserItem item = Envir.CreateFreshItem(iInfo);
                            if (item != null)
                            {
                                items.Add(item);
                            }
                        }
                        MailInfo mail = new MailInfo(winningPlayer.Info.Index)
                        {
                            Items   = items,
                            Message = string.Format("Congratulations on winning the match! here is your prize(s)"),
                            Sender  = string.Format("LMS"),
                            MailID  = ++Envir.NextMailID
                        };
                        mail.Send();
                    }
                    SMain.EnqueueDebugging(string.Format("[LMS BR] Map {0} {1} wins the Match, made {2} kills.", CurrentMap.Info.Title, winningPlayer.Name, lmsRank.Kills));
                }
                else
                {
                    failed = true;
                }
            }
            if ((failed && foundWinner) || !foundWinner)
            {
                if (CurrentMap.Players.Count > 0)
                {
                    string[] finalPlayers = new string[CurrentMap.Players.Count];
                    if (finalPlayers.Length >= 1)
                    {
                        int index = 0;
                        for (int i = 0; i < CurrentMap.Players.Count; i++)
                        {
                            PlayerObject player = CurrentMap.Players[i];
                            if (player.Dead ||
                                player.IsGM)
                            {
                                continue;
                            }
                            finalPlayers[index] = player.Name;
                            player.Teleport(Envir.GetMap(player.BindMapIndex), player.BindLocation);
                            player.InLMSBR = failed;
                            index++;
                        }
                        Array.Resize(ref finalPlayers, index);
                    }
                    matchResult = "Stalemate, Players ";
                    for (int i = 0; i < finalPlayers.Length; i++)
                    {
                        matchResult += string.Format("{0}{1} ", finalPlayers[i], i - 1 <= finalPlayers.Length ? "," : " have drawn the match!");
                    }
                }
            }

            if (matchResult.Length > 0)
            {
                Envir.Broadcast(new ServerPackets.Chat {
                    Message = matchResult, Type = ChatType.Announcement
                });
            }
            StartTime        = 0;
            EndTime          = 0;
            SignedupPlayers  = new List <PlayerObject>();
            CircleLocations  = new List <Point>();
            PlayerRanks      = new List <LMS_Rank>();
            StartingLocation = Info.StartingLocation;
            Stage            = 0;
            Finished         = false;
            Started          = false;
        }
예제 #5
0
        public void Craft(PlayerObject player, ulong index, ushort count, int[] slots)
        {
            S.CraftItem p = new S.CraftItem();

            RecipeInfo recipe = null;

            for (int i = 0; i < CraftGoods.Count; i++)
            {
                if (CraftGoods[i].Item.UniqueID != index) continue;
                recipe = CraftGoods[i];
                break;
            }

            UserItem goods = recipe.Item;

            if (goods == null || count == 0 || count > goods.Info.StackSize)
            {
                player.Enqueue(p);
                return;
            }

            if (player.Account.Gold < recipe.Gold)
            {
                player.Enqueue(p);
                return;
            }

            bool hasItems = true;

            List<int> usedSlots = new List<int>();

            //Check Tools
            foreach (var tool in recipe.Tools)
            {
                for (int i = 0; i < slots.Length; i++)
                {
                    int slot = slots[i];

                    if (usedSlots.Contains(slot)) continue;

                    if (slot < 0 || slot > player.Info.Inventory.Length) continue;

                    UserItem item = player.Info.Inventory[slot];

                    if (item == null || item.Info != tool.Info) continue;

                    usedSlots.Add(slot);

                    if ((uint)Math.Floor(item.CurrentDura / 1000M) < count)
                    {
                        hasItems = false;
                        break;
                    }
                }

                if (!hasItems)
                {
                    break;
                }
            }

            //Check Ingredients
            foreach (var ingredient in recipe.Ingredients)
            {
                if (ingredient.Count * count > ingredient.Info.StackSize)
                {
                    player.Enqueue(p);
                    return;
                }

                ushort amount = (ushort)(ingredient.Count * count);

                for (int i = 0; i < slots.Length; i++)
                {
                    int slot = slots[i];

                    if (usedSlots.Contains(slot)) continue;

                    if (slot < 0 || slot > player.Info.Inventory.Length) continue;

                    UserItem item = player.Info.Inventory[slot];

                    if (item == null || item.Info != ingredient.Info) continue;

                    usedSlots.Add(slot);

                    if (ingredient.CurrentDura < ingredient.MaxDura && ingredient.CurrentDura > item.CurrentDura)
                    {
                        hasItems = false;
                        break;
                    }

                    if (amount > item.Count)
                    {
                        hasItems = false;
                        break;
                    }

                    amount = 0;
                    break;
                }

                if (amount > 0)
                {
                    hasItems = false;
                    break;
                }
            }

            if (!hasItems || usedSlots.Count != (recipe.Tools.Count + recipe.Ingredients.Count))
            {
                player.Enqueue(p);
                return;
            }

            if (count > (goods.Info.StackSize / goods.Count) || count < 1)
            {
                player.Enqueue(p);
                return;
            }

            UserItem craftedItem = Envir.CreateFreshItem(goods.Info);
            craftedItem.Count = (ushort)(goods.Count * count);

            if (!player.CanGainItem(craftedItem))
            {
                player.Enqueue(p);
                return;
            }

            List<int> usedSlots2 = new List<int>();

            //Use Tool Durability
            foreach (var tool in recipe.Tools)
            {
                for (int i = 0; i < slots.Length; i++)
                {
                    int slot = slots[i];

                    if (usedSlots2.Contains(slot)) continue;

                    if (slot < 0 || slot > player.Info.Inventory.Length) continue;

                    UserItem item = player.Info.Inventory[slot];

                    if (item == null || item.Info != tool.Info) continue;

                    usedSlots2.Add(slot);

                    player.DamageItem(item, (int)(count * 1000), true);

                    break;
                }
            }

            //Take Ingredients
            foreach (var ingredient in recipe.Ingredients)
            {
                ushort amount = (ushort)(ingredient.Count * count);

                for (int i = 0; i < slots.Length; i++)
                {
                    int slot = slots[i];

                    if (usedSlots2.Contains(slot)) continue;

                    if (slot < 0 || slot > player.Info.Inventory.Length) continue;

                    UserItem item = player.Info.Inventory[slot];

                    if (item == null || item.Info != ingredient.Info) continue;

                    usedSlots2.Add(slot);

                    if (item.Count > amount)
                    {
                        player.Enqueue(new S.DeleteItem { UniqueID = item.UniqueID, Count = amount });
                        player.Info.Inventory[slot].Count -= amount;
                        break;
                    }
                    else
                    {
                        player.Enqueue(new S.DeleteItem { UniqueID = item.UniqueID, Count = item.Count });
                        amount -= item.Count;
                        player.Info.Inventory[slot] = null;
                    }

                    break;
                }
            }

            //Take Gold
            player.Account.Gold -= recipe.Gold;
            player.Enqueue(new S.LoseGold { Gold = recipe.Gold });

            if (Envir.Random.Next(100) >= recipe.Chance + player.Stats[Stat.CraftRatePercent])
            {
                player.ReceiveChat("Crafting attempt failed.", ChatType.System);
            }
            else
            {
                //Give Item
                player.GainItem(craftedItem);
            }

            p.Success = true;
            player.Enqueue(p);
        }