public override void TakeActionAffter(bool state)
        {
            switch (_chatType)
            {
            case ChatType.AllService:
            {
                GlobalRemoteService.SendAllServerChat(Current.UserId, _content);
                // 每日
                UserHelper.EveryDayTaskProcess(Current.UserId, TaskType.WorldChat, 1);
            }
            break;

            case ChatType.World:
            {
                GlobalRemoteService.SendWorldChat(Current.UserId, _content);
            }
            break;

            case ChatType.Whisper:
            {
                GlobalRemoteService.SendWhisperChat(Current.UserId, _whisperUserID, _content);
            }
            break;

            case ChatType.Guild:
            {
                if (!GetGuild.GuildID.IsEmpty())
                {
                    GlobalRemoteService.SendGuildChat(Current.UserId, _content);
                }
            }
            break;
            }
        }
        public override bool TakeAction()
        {
            GlobalRemoteService.SendUserData(GetBasis, GetGuild.GuildID);

            string content = "欢迎进入勇者之怒!";

            GlobalRemoteService.SendSystemChat(Current.UserId, content);
            return(true);
        }
        public override bool TakeAction()
        {
            var guildData = new ShareCacheStruct <GuildsCache>().FindKey(GetGuild.GuildID);

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


            if (Current.UserId == _DestUid ||
                (guildData.FindAtevent().UserID != Current.UserId && guildData.FindVice(Current.UserId) == null))
            {
                receipt = RequestGuildResult.NoAuthority;
                return(true);
            }

            var basis  = UserHelper.FindUserBasis(_DestUid);
            var guild  = UserHelper.FindUserGuild(_DestUid);
            var member = guildData.FindMember(_DestUid);

            if (basis == null || member == null)
            {
                return(false);
            }


            GuildLogData log = new GuildLogData()
            {
                UserId   = basis.UserID,
                UserName = basis.NickName,
                LogTime  = DateTime.Now,
                Content  = string.Format("玩家 {0} 被移出公会。", basis.NickName),
            };

            guildData.NewLog(log);

            foreach (var v in guildData.MemberList)
            {
                PushMessageHelper.GuildMemberRemoveNotification(GameSession.Get(v.UserID), _DestUid);
                PushMessageHelper.NewGuildLogNotification(GameSession.Get(v.UserID));
            }

            guildData.RemoveMember(member);
            guild.GuildID = string.Empty;
            GlobalRemoteService.SendUserData(basis, guild.GuildID);

            receipt = RequestGuildResult.Successfully;
            return(true);
        }
Example #4
0
        public override bool TakeAction()
        {
            bool isAtevent = false;
            var  guildsSet = new ShareCacheStruct <GuildsCache>();
            var  guildData = guildsSet.FindKey(GetGuild.GuildID);

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


            var member = guildData.FindMember(Current.UserId);

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

            isAtevent = member.JobTitle == GuildJobTitle.Atevent;


            guildData.RemoveMember(member);
            GetGuild.GuildID = string.Empty;

            if (guildData.MemberList.Count > 0)
            {
                if (isAtevent)
                {
                    var ac = guildData.FindAteventCandidate();
                    if (ac != null)
                    {
                        ac.JobTitle = GuildJobTitle.Atevent;
                        foreach (var v in guildData.MemberList)
                        {
                            PushMessageHelper.GuildMemberChangeNotification(GameSession.Get(v.UserID), ac.UserID);
                        }
                    }
                }

                GuildLogData log = new GuildLogData()
                {
                    UserId   = Current.UserId,
                    UserName = GetBasis.NickName,
                    LogTime  = DateTime.Now,
                    Content  = string.Format("玩家 {0} 退出了公会。", GetBasis.NickName),
                };
                guildData.NewLog(log);

                foreach (var v in guildData.MemberList)
                {
                    PushMessageHelper.GuildMemberRemoveNotification(GameSession.Get(v.UserID), Current.UserId);
                    PushMessageHelper.NewGuildLogNotification(GameSession.Get(v.UserID));
                }
            }


            GlobalRemoteService.SendUserData(GetBasis, GetGuild.GuildID);

            receipt = true;
            return(true);
        }
Example #5
0
        public override bool TakeAction()
        {
            UserRank rankinfo      = null;
            UserRank rivalrankinfo = null;


            rankinfo = UserHelper.FindRankUser(Current.UserId, RankType.Combat);
            if (rankinfo == null)
            {
                new BaseLog("Action1403").SaveLog(string.Format("Not found user combat rank. UserId={0}", Current.UserId));
                ErrorInfo = Language.Instance.CombatRankDataException;
                return(true);
            }
            UserBasisCache rival = UserHelper.FindUserBasis(rankinfo.FightDestUid);

            if (rival == null)
            {
                ErrorInfo = Language.Instance.CombatRankDataException;
                return(true);
            }

            rivalrankinfo = UserHelper.FindRankUser(rankinfo.FightDestUid, RankType.Combat);
            if (rivalrankinfo == null)
            {
                new BaseLog("Action1403").SaveLog(string.Format("Not found user combat rank. UserId={0}", rankinfo.FightDestUid));
                ErrorInfo = Language.Instance.CombatRankDataException;
                return(true);
            }

            //if (GetBasis.CombatRankID <= rival.CombatRankID)
            //{
            //    ErrorInfo = Language.Instance.CombatRankDataException;
            //    return true;
            //}
            if (!rankinfo.IsFighting || !rivalrankinfo.IsFighting)
            {
                ErrorInfo = Language.Instance.CombatRankDataException;
                return(true);
            }



            int fromRankId = GetBasis.CombatRankID;
            int toRankId   = rival.CombatRankID;

            //TraceLog.WriteLine(string.Format("#BEGIN srcId:[{0}] destId:[{1}]", fromid, toid));
            GetBasis.UserStatus = UserStatus.MainUi;



            if (result == EventStatus.Good)
            {
                if (GetBasis.CombatRankID > rival.CombatRankID)
                {
                    var ranking = RankingFactory.Get <UserRank>(CombatRanking.RankingKey);
                    ranking.TryMove(fromRankId, toRankId);
                    GetBasis.CombatRankID = toRankId;
                    rival.CombatRankID    = fromRankId;
                    if (GetBasis.CombatRankID <= 10)
                    {
                        string context = string.Format("恭喜 {0} 挑战 {1} 成功,成为通天塔第{2}名!", GetBasis.NickName, rival.NickName, rankinfo.RankId);
                        //GlobalRemoteService.SendNotice(NoticeMode.World, context);
                        //PushMessageHelper.SendNoticeToOnlineUser(NoticeMode.Game, context);

                        //var chatService = new TryXChatService();
                        //chatService.SystemSend(context);
                        //PushMessageHelper.SendSystemChatToOnlineUser();
                    }
                }
            }
            else
            {
                if (GetBasis.CombatRankID <= rival.CombatRankID)
                {
                    var ranking = RankingFactory.Get <UserRank>(CombatRanking.RankingKey);
                    ranking.TryMove(fromRankId, toRankId);
                    GetBasis.CombatRankID = toRankId;
                    rival.CombatRankID    = fromRankId;
                }
                GetCombat.LastFailedDate = DateTime.Now;
            }

            int rankrise = result == EventStatus.Good ? MathUtils.Subtraction(fromRankId, toRankId, 0) : 0;

            //TraceLog.WriteLine(string.Format("###END srcId:[{0}] destId:[{1}]", GetBasis.CombatData.RankID, rival.CombatData.RankID));

            // 日志
            CombatLogData log = new CombatLogData();

            log.RivalUid       = rankinfo.FightDestUid;
            log.RivalName      = rival.NickName;
            log.RivalAvatarUrl = rival.AvatarUrl;
            log.LogTime        = DateTime.Now;
            log.Type           = EventType.Challenge;
            log.Status         = result;
            log.RankIdDiff     = rankrise;
            log.RankId         = GetBasis.CombatRankID;
            GetCombat.PushCombatLog(log);

            string content = UserHelper.FormatCombatLog(log);

            GlobalRemoteService.SendSystemChat(Current.UserId, content);


            CombatLogData rivallog = new CombatLogData();

            rivallog.RivalUid       = Current.UserId;
            rivallog.RivalName      = GetBasis.NickName;
            rivallog.RivalAvatarUrl = GetBasis.AvatarUrl;
            rivallog.LogTime        = DateTime.Now;
            rivallog.Type           = EventType.PassiveChallenge;
            rivallog.Status         = result;
            rivallog.RankIdDiff     = rankrise;
            rivallog.RankId         = rival.CombatRankID;
            UserHelper.FindUserCombat(rival.UserID).PushCombatLog(rivallog);

            content = UserHelper.FormatCombatLog(rivallog);
            GlobalRemoteService.SendSystemChat(rival.UserID, content);

            rankinfo.IsFighting      = false;
            rankinfo.FightDestUid    = 0;
            rivalrankinfo.IsFighting = false;

            receipt                = new CombatFightEndData();
            receipt.Result         = result;
            receipt.CurrRankId     = GetBasis.CombatRankID;
            receipt.RankRise       = rankrise;
            receipt.LastFailedTime = Util.ConvertDateTimeStamp(GetCombat.LastFailedDate);
            receipt.AwardGold      = "0";

            BigInteger gold       = ConfigEnvSet.GetInt("User.CombatWinAwardGold");
            BigInteger awardValue = Math.Ceiling(GetBasis.UserLv / 50.0).ToInt() * gold;

            if (result == EventStatus.Good)
            {
                receipt.AwardGold = awardValue.ToString();
                UserHelper.RewardsGold(Current.UserId, awardValue, UpdateCoinOperate.NormalReward, true);
            }
            else
            {
                awardValue       /= 4;
                receipt.AwardGold = awardValue.ToString();
                UserHelper.RewardsGold(Current.UserId, awardValue, UpdateCoinOperate.NormalReward, true);
            }


            // 每日
            UserHelper.EveryDayTaskProcess(Current.UserId, TaskType.Combat, 1);

            // 成就
            UserHelper.AchievementProcess(Current.UserId, AchievementType.CombatRandID, "1");

            PushMessageHelper.NewCombatLogNotification(Current);
            PushMessageHelper.NewCombatLogNotification(GameSession.Get(rival.UserID));
            return(true);
        }
        public static void Run()
        {
            //AppstoreClientManager.Current.InitConfig();
            //var dispatch = TaskDispatch.StartTask();
            //dispatch.Add(new StudyTask());

            lock (thisLock)
            {
                _isRunning = false;
            }
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

#if NO_MERGE_SERVICE_DATA
            var httpHost = GetSection().HttpHost;
            var httpPort = GetSection().HttpPort;
            var httpName = GetSection().HttpName;
            if (!string.IsNullOrEmpty(httpHost))
            {
                var names = httpName.Split(',');
                new NewHttpListener(httpHost, httpPort, new HashSet <string>(names));
            }


            LoadGlobalData();

            // 上传该服务器的状态
            TimeListener.Append(PlanConfig.EveryMinutePlan(submitServerStatus, "submitServerStatus", "00:00", "23:59", ConfigurationManager.AppSettings["ServerStatusSendInterval"].ToInt()));
            // 自动机器人,64争霸赛
            TimeListener.Append(PlanConfig.EveryMinutePlan(LoopAction, "LoopAction", "00:00", "23:59", 3));
            // new GameActiveCenter(null);
            // new GuildGameActiveCenter(null);
            //每天执行用于整点刷新
            TimeListener.Append(PlanConfig.EveryDayPlan(UserHelper.DoZeroRefreshDataTask, "DoZeroRefreshDataTask", "00:00"));
            //TimeListener.Append(PlanConfig.EveryMinutePlan(UserHelper.DoZeroRefreshDataTask, "DoZeroRefreshDataTask", "08:00", "22:00", 60));
            //每天5点执行用于整点刷新
            TimeListener.Append(PlanConfig.EveryDayPlan(UserHelper.DoEveryDayRefreshDataTask, "EveryDayRefreshDataTask", "05:00"));
            // 每周二,周五
            TimeListener.Append(PlanConfig.EveryWeekPlan(UserHelper.DoTuesdayRefreshTask, "TuesdayRefreshTask", DayOfWeek.Tuesday, "04:00"));
            //TimeListener.Append(PlanConfig.EveryWeekPlan(UserHelper.DoFridayRefreshTask, "FridayRefreshTask", DayOfWeek.Friday, "04:00"));

            DataHelper.InitData();

            InitRanking();


            if (DataHelper.IsFirstOpenService)
            {
                string ncikName    = string.Empty;
                var    botsNameSet = new ShareCacheStruct <Config_BotsName>();
                for (int i = 0; i < 5; ++i)
                {
                    ncikName  = botsNameSet.FindKey(random.Next(botsNameSet.Count)).String;
                    ncikName += botsNameSet.FindKey(random.Next(botsNameSet.Count)).Value;
                    UserCenterUser ucu = Util.CreateUserCenterUser(Util.GetRandomGUIDPwd(), "0000", GameEnvironment.ProductServerId);
                    Action1005.CreateRole(ucu.UserID, "", ucu.ServerID, ucu.OpenID, ucu.RetailID, ncikName, random.Next(1) + 1, "");
                }
            }
            //Bots.InitBots();

            //if (competition64 == null)
            //{
            //    competition64 = new Competition64();
            //    competition64.Initialize();
            //}

            GlobalRemoteService.Reuest();

            stopwatch.Stop();
            new BaseLog().SaveLog("系统全局运行环境加载所需时间:" + stopwatch.Elapsed.TotalMilliseconds + "ms");

            SendServerStatus(ServerStatus.Unhindered, 0);
#else
            MERGE_SERVICE.Run();
#endif
            lock (thisLock)
            {
                _isRunning = true;
            }
        }
        public override bool TakeAction()
        {
            receipt = new LotteryData();

            var itemSet = new ShareCacheStruct <Config_Item>();

            int times = isFiveTimes ? 5 : 1;

            if (GetLottery.LotteryTimes <= times)
            {
                int needDiamond = ConfigEnvSet.GetInt("User.BuyLotteryTimesNeedDiamond") * (times - GetLottery.LotteryTimes);
                if (GetBasis.DiamondNum < needDiamond)
                {
                    receipt.Result = RequestLotteryResult.NoDiamond;
                    return(true);
                }
                UserHelper.ConsumeDiamond(Current.UserId, needDiamond);
                //receipt.Result = RequestLotteryResult.NoTimes;
                //return true;
            }

            BigInteger      awardGold    = 0;
            int             awardDiamond = 0;
            List <ItemData> awardItem    = new List <ItemData>();

            int lotteryId = 0;
            LotteryAwardType awardType = LotteryAwardType.Gold;

            GetLottery.StealTimes = 0;
            GetLottery.RobTimes   = 0;
            for (int i = 0; i < times; ++i)
            {
                if (GetLottery.TotalCount == 0)
                {
                    lotteryId = 7;
                    awardType = LotteryAwardType.Steal;
                }
                else if (GetLottery.TotalCount == 1)
                {
                    lotteryId = 8;
                    awardType = LotteryAwardType.Rob;
                }
                else
                {
                    var randlottery = UserHelper.RandomLottery(GetBasis.UserLv);
                    if (randlottery != null)
                    {
                        lotteryId = randlottery.ID;
                        awardType = randlottery.Type;
                    }
                }

                Config_Lottery lott = new ShareCacheStruct <Config_Lottery>().FindKey(lotteryId);
                if (lott == null)
                {
                    return(false);
                }

                LottItem item = new LottItem();
                item.ID   = lotteryId;
                item.Type = awardType;
                switch (lott.Type)
                {
                case LotteryAwardType.Gold:
                {
                    BigInteger resourceNum = BigInteger.Parse(lott.Content);
                    BigInteger value       = Math.Ceiling(GetBasis.UserLv / 50.0).ToInt() * resourceNum;
                    awardGold += value;

                    item.ItemID = 0;
                    item.Num    = value.ToString();
                }
                break;

                case LotteryAwardType.Diamond:
                {
                    awardDiamond += lott.Content.ToInt();
                    item.ItemID   = 0;
                    item.Num      = lott.Content;
                }
                break;

                case LotteryAwardType.Gem:
                {
                    int maxCount = lott.Content.ToInt();
                    if (maxCount > 0)
                    {
                        var lotteryGem = UserHelper.RandomLotteryGem();

                        item.ItemID = lotteryGem.ID;
                        item.Num    = maxCount.ToString();

                        awardItem.Add(new ItemData()
                            {
                                ID = lotteryGem.ID, Num = maxCount
                            });
                    }
                }
                break;

                case LotteryAwardType.Debris:
                {
                    var debris = itemSet.FindAll(t => (t.ItemType == ItemType.Debris));
                    foreach (var v in GetElf.ElfList)
                    {
                        var elfCard = itemSet.Find(t => t.ResourceNum.ToInt() == v.ID);
                        if (elfCard == null)
                        {
                            continue;
                        }

                        debris.RemoveAll(t => (t.ResourceNum.ToInt() == elfCard.ItemID));
                    }
                    if (debris.Count == 0)
                    {
                        debris = itemSet.FindAll(t => (t.ItemType == ItemType.Debris));
                    }

                    int maxCount = lott.Content.ToInt();
                    if (maxCount > 0)
                    {
                        int index   = random.Next(debris.Count);
                        int awardId = debris[index].ItemID;

                        item.ItemID = awardId;
                        item.Num    = maxCount.ToString();

                        awardItem.Add(new ItemData()
                            {
                                ID = awardId, Num = maxCount
                            });
                    }
                }
                break;

                case LotteryAwardType.Elf:
                {
                    item.ItemID = lott.Content.ToInt();
                    item.Num    = "1";

                    awardItem.Add(new ItemData()
                        {
                            ID = lott.Content.ToInt(), Num = 1
                        });

                    var itemcfg = new ShareCacheStruct <Config_Item>().FindKey(item.ItemID);
                    if (itemcfg != null)
                    {
                        string context = string.Format("恭喜 {0} 在幸运大夺宝中获得精灵 {1}",
                                                       GetBasis.NickName, itemcfg.ItemName);
                        GlobalRemoteService.SendNotice(NoticeMode.World, context);
                    }
                }
                break;

                case LotteryAwardType.Steal:
                {
                    GetLottery.StealTimes++;
                    UserHelper.RandomStealTarget(Current.UserId);
                }
                break;

                case LotteryAwardType.Rob:
                {
                    GetLottery.RobTimes++;
                    UserHelper.RandomRobTarget(Current.UserId);
                }
                break;

                case LotteryAwardType.Vit:
                {
                    GetBasis.Vit += lott.Content.ToInt();
                    PushMessageHelper.UserVitChangedNotification(Current);
                }
                break;
                }
                receipt.AwardList.Add(item);

                GetLottery.TotalCount++;
            }

            UserHelper.RewardsGold(Current.UserId, awardGold, UpdateCoinOperate.NormalReward, true);
            UserHelper.RewardsDiamond(Current.UserId, awardDiamond);
            UserHelper.RewardsItems(Current.UserId, awardItem);

            if (GetLottery.LotteryTimes == ConfigEnvSet.GetInt("User.LotteryTimesMax"))
            {
                GetLottery.StartRestoreLotteryTimesDate = DateTime.Now;
            }
            if (GetLottery.LotteryTimes > 0)
            {
                GetLottery.LotteryTimes = MathUtils.Subtraction(GetLottery.LotteryTimes, times, 0);
            }

            UserHelper.EveryDayTaskProcess(Current.UserId, TaskType.Lottery, times);

            receipt.Result = RequestLotteryResult.OK;

            return(true);
        }
Example #8
0
        public override bool TakeAction()
        {
            var guildsSet = new ShareCacheStruct <GuildsCache>();

            if (!GetGuild.GuildID.IsEmpty())
            {
                var oldguild = guildsSet.FindKey(GetGuild.GuildID);
                if (oldguild != null && oldguild.FindMember(Current.UserId) != null)
                {
                    return(false);
                }
            }

            int needDiamond = ConfigEnvSet.GetInt("User.CreateGuildNeedDiamond");

            if (GetBasis.DiamondNum < needDiamond)
            {
                receipt = RequestGuildResult.NoDiamond;
                return(true);
            }
            if (guildsSet.Find(t => t.GuildName == _guildName) != null)
            {
                receipt = RequestGuildResult.HadName;
                return(true);
            }

            GuildsCache guild = new GuildsCache()
            {
                GuildID    = Guid.NewGuid().ToString(),
                GuildName  = _guildName,
                Liveness   = 0,
                RankID     = 0,
                CreateDate = DateTime.Now,
                Lv         = 1
            };

            GuildCharacter member = new GuildCharacter()
            {
                UserID   = Current.UserId,
                JobTitle = GuildJobTitle.Atevent,
                Liveness = 0
            };

            guild.AddNewMember(member);

            GuildLogData log = new GuildLogData()
            {
                UserId   = Current.UserId,
                UserName = GetBasis.NickName,
                LogTime  = DateTime.Now,
                Content  = string.Format("玩家 {0} 创建了公会。", GetBasis.NickName),
            };

            guild.NewLog(log);

            guildsSet.Add(guild);
            guildsSet.Update();
            GetGuild.GuildID = guild.GuildID;
            PushMessageHelper.JoinGuildNotification(Current);

            GlobalRemoteService.SendUserData(GetBasis, GetGuild.GuildID);

            receipt = RequestGuildResult.Successfully;
            return(true);
        }
        public override bool TakeAction()
        {
            var guildData = new ShareCacheStruct <GuildsCache>().FindKey(GetGuild.GuildID);

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

            var guildcfg = new ShareCacheStruct <Config_Society>().FindKey(guildData.Lv);

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


            if (guildData.FindAtevent().UserID != Current.UserId &&
                guildData.FindVice(Current.UserId) == null)
            {
                receipt = RequestGuildResult.NoAuthority;
                return(true);
            }

            var basis = UserHelper.FindUserBasis(_DestUid);
            var guild = UserHelper.FindUserGuild(_DestUid);

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



            if (_isAgree)
            {
                if (guildData.MemberList.Count >= guildcfg.Number)
                {
                    receipt = RequestGuildResult.Full;
                }

                else if (!guild.GuildID.IsEmpty())
                {
                    receipt = RequestGuildResult.HadGuild;
                }
                else
                {
                    GuildCharacter member = new GuildCharacter()
                    {
                        UserID   = basis.UserID,
                        JobTitle = GuildJobTitle.Normal,
                        Liveness = 0
                    };

                    GuildLogData log = new GuildLogData()
                    {
                        UserId   = basis.UserID,
                        UserName = basis.NickName,
                        LogTime  = DateTime.Now,
                        Content  = string.Format("玩家 {0} 加入了公会。", basis.NickName),
                    };
                    guildData.NewLog(log);

                    // 通知公会成员有新成员加入
                    foreach (var v in guildData.MemberList)
                    {
                        PushMessageHelper.NewGuildMemberNotification(GameSession.Get(v.UserID), _DestUid);
                        PushMessageHelper.NewGuildLogNotification(GameSession.Get(v.UserID));
                    }

                    guildData.AddNewMember(member);
                    guild.GuildID  = guildData.GuildID;
                    guild.IsSignIn = false;

                    // 通知新成员公会信息
                    PushMessageHelper.JoinGuildNotification(GameSession.Get(_DestUid));

                    GlobalRemoteService.SendUserData(basis, guild.GuildID);

                    receipt = RequestGuildResult.Successfully;
                }
            }
            // 从邀请列表里清除
            guildData.RemoveRequest(_DestUid);

            foreach (var v in guildData.MemberList)
            {
                PushMessageHelper.GuildApplyRemoveNotification(GameSession.Get(v.UserID), _DestUid);
            }
            return(true);
        }