Exemple #1
0
        public override bool TakeAction()
        {
            receipt     = new RobData();
            receipt.Rob = GetLottery.Rob;

            var rob = UserHelper.FindUserBasis(GetLottery.Rob.RivalUid);

            receipt.Rob.RivalLevel = rob.UserLv;
            var lotterycfg = new ShareCacheStruct <Config_Lottery>().Find(t => (t.Type == LotteryAwardType.Rob));

            if (lotterycfg == null)
            {
                return(false);
            }
            receipt.TodayRobList = GetFriends.TodayRobList.ToList();
            foreach (var v in GetFriends.FriendsList)
            {
                JPFriendRobData friendrob = new JPFriendRobData()
                {
                    UserId = v.UserId,
                };
                if (v.RobGold.Equals("0"))
                {
                    var enemy = GetEnemys.FindEnemy(v.UserId);
                    if (enemy != null && !enemy.RobGold.Equals("0"))
                    {
                        v.RobGold = enemy.RobGold;
                        continue;
                    }
                    var        rival      = UserHelper.FindUserBasis(v.UserId);
                    int        baseValue  = lotterycfg.Content.ToInt();
                    int        goldMin    = baseValue / 4;
                    int        goldmax    = random.Next(baseValue - goldMin) + goldMin;
                    BigInteger targetGold = Math.Ceiling(rival.UserLv / 50.0).ToInt() * goldmax;
                    v.RobGold = targetGold.ToString();
                }
                friendrob.Gold = v.RobGold;
                receipt.FriendRobList.Add(friendrob);
            }
            foreach (var v in GetEnemys.EnemyList)
            {
                JPEnemyRobData enemyrob = new JPEnemyRobData()
                {
                    UserId = v.UserId,
                };
                if (v.RobGold.Equals("0"))
                {
                    var friend = GetFriends.FindFriend(v.UserId);
                    if (friend != null && !friend.RobGold.Equals("0"))
                    {
                        v.RobGold = friend.RobGold;
                        continue;
                    }
                    var        rival      = UserHelper.FindUserBasis(v.UserId);
                    int        baseValue  = lotterycfg.Content.ToInt();
                    int        goldMin    = baseValue / 4;
                    int        goldmax    = random.Next(baseValue - goldMin) + goldMin;
                    BigInteger targetGold = Math.Ceiling(rival.UserLv / 50.0).ToInt() * goldmax;
                    v.RobGold = targetGold.ToString();
                }
                enemyrob.Gold = v.RobGold;
                receipt.EnemyRobList.Add(enemyrob);
            }

            return(true);
        }
        public override bool TakeAction()
        {
            receipt        = new RobReceipt();
            receipt.Result = false;

            if (GetLottery.RobTimes <= 0)
            {
                return(true);
            }
            if (GetLottery.Rob.RivalUid != selectId &&
                !GetEnemys.IsHaveEnemy(selectId) &&
                !GetFriends.IsHaveFriend(selectId))
            {
                return(true);
            }

            var rival = UserHelper.FindUserBasis(selectId);

            if (rival == null)
            {
                return(true);
            }
            var rivalEnemy = UserHelper.FindUserEnemy(rival.UserID);

            if (rivalEnemy == null)
            {
                return(true);
            }

            var lotterycfg = new ShareCacheStruct <Config_Lottery>().Find(t => (t.Type == LotteryAwardType.Rob));

            if (lotterycfg == null)
            {
                return(false);
            }

            GetLottery.RobTimes--;

            BigInteger dummyGold = 0;

            if (GetLottery.Rob.RivalUid == selectId)
            {
                dummyGold = BigInteger.Parse(GetLottery.Rob.Gold);

                GetLottery.Rob.RivalUid       = 0;
                GetLottery.Rob.RivalName      = string.Empty;
                GetLottery.Rob.RivalAvatarUrl = string.Empty;
                GetLottery.Rob.Gold           = "0";
                UserHelper.RandomRobTarget(Current.UserId);
            }
            if (GetFriends.IsHaveFriend(selectId))
            {
                var frienddata = GetFriends.FindFriend(selectId);
                dummyGold = BigInteger.Parse(frienddata.RobGold);

                frienddata.RobGold = "0";
                GetFriends.AddRobRecord(selectId);
            }
            if (GetEnemys.IsHaveEnemy(selectId))
            {
                var enemydata = GetEnemys.FindEnemy(selectId);
                dummyGold = BigInteger.Parse(enemydata.RobGold);

                GetEnemys.RemoveEnemy(rival.UserID);
            }

            if (result == EventStatus.Bad)
            {
                dummyGold = dummyGold / 5;
            }

            receipt.Gold = dummyGold.ToString();
            UserHelper.RewardsGold(Current.UserId, dummyGold);
            BigInteger realGold = rival.GoldNum <= dummyGold * 2 ? rival.GoldNum / 2 : dummyGold;

            UserHelper.ConsumeGold(rival.UserID, realGold);

            int levelDown = 0;

            if (result == EventStatus.Good)
            {
                int downlv = rival.UserLv <= 1000 ? 10 : rival.UserLv / 100;
                levelDown = Math.Max(rival.UserLv - downlv, 0);
                levelDown = Math.Min(levelDown, downlv);
                //rival.UserLv = Math.Max(rival.UserLv - levelDown, 10);
                //UserHelper.UserLvChange(rival.UserID);
                //PushMessageHelper.UserLvChangeNotification(GameSession.Get(rival.UserID));
                rival.BackLevelNum += downlv;
            }

            rivalEnemy.AddEnemy(new EnemyData()
            {
                UserId = Current.UserId
            });



            EnemyLogData log = new EnemyLogData()
            {
                RivalUid        = Current.UserId,
                RivalName       = GetBasis.NickName,
                RivalAvatarUrl  = GetBasis.AvatarUrl,
                LogTime         = DateTime.Now,
                LossGold        = realGold.ToString(),
                LevelDown       = levelDown,
                IsSteal         = false,
                Status          = result,
                RivalProfession = GetBasis.Profession
            };

            rivalEnemy.PushLog(log);
            PushMessageHelper.NewStealRobNotification(GameSession.Get(rival.UserID));



            receipt.Lottery = GetLottery;
            receipt.Result  = true;


            return(true);
        }