Пример #1
0
        public void RequestBuy(MsgPack msgPack)
        {
            RequestBuy data   = msgPack.Msg.RequestBuy;
            NetMsg     netMsg = new NetMsg
            {
                cmd = (int)Command.ResponseBuy
            };

            PlayerData playerData = _cacheSvc.GetPlayerDataBySession(msgPack.Session);

            if (playerData.Diamond < data.DiamondPay)
            {
                netMsg.err = (int)ErrorCode.LockDiamond;
            }
            else
            {
                playerData.Diamond -= data.DiamondPay;
                PshTask pshTask = null;
                switch (data.Type)
                {
                case 0:
                    playerData.Power += 100;
                    pshTask           = TaskSys.Instance.GetTaskPrangs(playerData, 4);
                    break;

                case 1:
                    playerData.Coin += 1000;
                    pshTask          = TaskSys.Instance.GetTaskPrangs(playerData, 5);
                    break;
                }

                if (!_cacheSvc.UpdatePlayerData(playerData.Id, playerData))
                {
                    netMsg.err = (int)ErrorCode.UpdateDbError;
                }
                else
                {
                    ResponseBuy responseBuy = new ResponseBuy
                    {
                        Type    = data.Type,
                        Diamond = playerData.Diamond,
                        Coin    = playerData.Coin,
                        Power   = playerData.Power,
                    };

                    //并包处理
                    netMsg.ResponseBuy = responseBuy;

                    netMsg.PshTask = pshTask;
                }
            }
            msgPack.Session.SendMsg(netMsg);
        }
Пример #2
0
 public static void OnRequestBuy(int storeId, int[] playerCurrencies)
 {
     RequestBuy?.Invoke(storeId, playerCurrencies);
 }