コード例 #1
0
        private static void _GiveItem(ClientInfo _cInfo, bool _announce)
        {
            string    _randomItem = ItemsList.RandomObject();
            ItemValue _itemValue  = new ItemValue();

            if (GameItems._gameItems.ContainsKey(_randomItem))
            {
                _itemValue = GameItems._gameItems[_randomItem].Clone();
            }
            else
            {
                _randomItem = _randomItem.ToLower();
                foreach (KeyValuePair <string, ItemValue> _key in GameItems._gameItems)
                {
                    if (_key.Key.ToLower().Equals(_randomItem))
                    {
                        _itemValue = _key.Value.Clone();
                    }
                }
            }
            EntityPlayer _player = GameManager.Instance.World.Players.dict[_cInfo.entityId];

            if (_itemValue.HasQuality)
            {
                int _lvl     = _player.GetLevel() * 10;
                int _min     = _lvl - 50;
                int _max     = _lvl + 50;
                int _quality = _random.Next(_min, _max);
                if (_quality > 600)
                {
                    _quality = _lvl;
                }
                _itemValue.Quality = _quality;
            }
            string _itemcounts = "1,5";

            if (Items.TryGetValue(_randomItem, out _itemcounts))
            {
                string[] _minmax = _itemcounts.Split(',');
                int      _min    = 1;
                int      _max    = 5;
                if (int.TryParse(_minmax[0], out _min) && int.TryParse(_minmax[1], out _max))
                {
                    int       _count    = _random.Next(_min, _max);
                    ItemStack _itemDrop = new ItemStack(_itemValue, _count);
                    GameManager.Instance.ItemDropServer(_itemDrop, _player.GetPosition(), Vector3.zero, -1, 60);
                    string _phrase7 = "{PlayerName} has received {ItemCount} {ItemName}.";
                    if (Phrases._Phrases.TryGetValue(7, out _phrase7))
                    {
                        _phrase7 = _phrase7.Replace("{0}", _cInfo.playerName);
                        _phrase7 = _phrase7.Replace("{1}", _count.ToString());
                        _phrase7 = _phrase7.Replace("{2}", _randomItem);
                        _phrase7 = _phrase7.Replace("{PlayerName}", _cInfo.playerName);
                        _phrase7 = _phrase7.Replace("{ItemCount}", _count.ToString());
                        _phrase7 = _phrase7.Replace("{ItemName}", _randomItem);
                    }
                    if (_announce || AlwaysShowResponse)
                    {
                        GameManager.Instance.GameMessageServer(_cInfo, string.Format("{0}{1}[-]", CustomCommands._chatcolor, _phrase7), "Server");
                    }
                    else
                    {
                        _cInfo.SendPackage(new NetPackageGameMessage(string.Format("{0}{1}[-]", CustomCommands._chatcolor, _phrase7), "Server"));
                    }
                    Players.Add(_cInfo.playerId, DateTime.Now);
                    UpdatePlayerXml();
                }
            }
        }