Beispiel #1
0
        protected void btnGetBonus_Click(object sender, EventArgs e)
        {
            var luckyPlayerID = ConfigGlobal.LuckyPlayerID;

            var player  = PlayerStrip.GetPlayerInfoByPlayerID(luckyPlayerID);
            var gPlayer = PlayerStrip.GetPlayerInfo(userid);

            var clubs = ClubLogic.GetActiveUserClubs(player.UserID);
            var isLuckyPlayerLeader =
                clubs.Exists(
                    delegate(Club club)
            {
                return
                (ClubLogic.GetClubLeads(club.ID.Value)
                 .Exists(delegate(UserClub uc) { return uc.Userid == this.userid; }));
            });

            var script = string.Empty;
            var CanGetLuckyPlayerBonus = false;

            if ((gPlayer.UserID == player.UserID) || isLuckyPlayerLeader)
            {
                CanGetLuckyPlayerBonus = true;
            }

            if (player != null && gPlayer != null && !ConfigGlobal.LuckyPlayerBonusGot && CanGetLuckyPlayerBonus)
            {
                var totalBonus = LuckyPlayer.CalcTotalBonus();

                var bonusToUser = (int)(totalBonus * ConfigGlobal.LuckyPlayerBonusPercentage);
                var bonusToClub = totalBonus - bonusToUser;

                var userInfo = Users.GetUserInfo(userid);
                userInfo.Extcredits2 += bonusToUser;

                AdminUsers.UpdateUserAllInfo(userInfo);

                //club update
                //List<Club> clubs = ClubLogic.GetActiveUserClubs(userid);
                var clubID = -1;

                if (clubs.Count == 0)
                {
                    bonusToClub = 0;
                }
                else
                {
                    var club = clubs[0];
                    clubID = club.ID.Value;

                    club.Fortune += bonusToClub;

                    ClubLogic.SaveClub(club);
                }

                LuckyPlayer.SetBonusGot(gPlayer.ID, bonusToClub, clubID, player.ID);

                Config.Cache.RefreshCache();

                script = $"alert('您已获得幸运球员奖金{bonusToUser}枪手币,球会获得{bonusToClub}枪手币');";

                btnGetBonus.Visible = true;
                btnGetBonus.Enabled = false;
                btnGetBonus.Text    = "已领取";
            }
            else
            {
                script = "alert('您无法领取今日的幸运球员奖金');";
            }

            Page.ClientScript.RegisterClientScriptBlock(typeof(string), "alert", script, true);
        }