Example #1
0
        public static T Get <T>(int id)
        {
            ConfigComponent configComponent = Game.Scene.GetComponent <ConfigComponent>();
            IConfig         config          = configComponent.Get(typeof(T), id);

            return((T)config);
        }
Example #2
0
        int getRewardItemId(int luckyValue)
        {
            int itemId = 1;

            int r    = Common_Random.getRandom(1, 1000);
            int temp = 0;

            ConfigComponent       configCom    = Game.Scene.GetComponent <ConfigComponent>();
            List <ZhuanpanConfig> shopInfoList = new List <ZhuanpanConfig>();

            for (int i = 1; i < configCom.GetAll(typeof(ZhuanpanConfig)).Length + 1; ++i)
            {
                ZhuanpanConfig config = (ZhuanpanConfig)configCom.Get(typeof(ZhuanpanConfig), i);

                if (r <= (config.Probability + temp))
                {
                    itemId = config.itemId;
                    break;
                }
                else
                {
                    temp += config.Probability;
                }
            }

            return(itemId);
        }
Example #3
0
        string getReward(int itemId, int LuckyValue)
        {
            string reward = "1:1";

            ConfigComponent       configCom    = Game.Scene.GetComponent <ConfigComponent>();
            List <ZhuanpanConfig> shopInfoList = new List <ZhuanpanConfig>();

            for (int i = 1; i < configCom.GetAll(typeof(ZhuanpanConfig)).Length + 1; ++i)
            {
                ZhuanpanConfig config = (ZhuanpanConfig)configCom.Get(typeof(ZhuanpanConfig), i);

                if (config.itemId == itemId)
                {
                    if (config.propId != 3)
                    {
                        reward = (config.propId + ":" + config.PropNum);
                    }
                    else
                    {
                        reward = (config.propId + ":" + config.PropNum);
                    }

                    if (LuckyValue >= 99)
                    {
                        reward += ";111:10";
                    }
                }
            }

            return(reward);
        }
Example #4
0
        public static CharacterConfig GetCharacterConfig(long id)
        {
            ConfigComponent configComponent = Game.Scene.GetComponent <ConfigComponent>();
            CharacterConfig data            = configComponent.Get(typeof(CharacterConfig), id) as CharacterConfig;

            if (data == null)
            {
                //DB存檔資料預設值會跑到這裡來,可能要改善一下
                //Log.Info($"Character Config ID [{id}] doesnt exist!");
            }
            return(data);
        }
        protected override void Run(ETModel.Session session, A1011_SpawnMonster_M2C message)
        {
            //服务端通知客户端刷新一波士兵 2战士 1法师
            TimerComponent     timerComponent     = ETModel.Game.Scene.GetComponent <TimerComponent>();
            ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>();
            GameObject         bundleGameObject   = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");
            ConfigComponent    config             = Game.Scene.GetComponent <ConfigComponent>();
            Moba5V5Component   moba = Moba5V5Component.instance;

            //创建24个野怪 其中61号Boss1跳过 配置编号49-72
            for (int i = 0; i < 24; i++)
            {
                if (i == 12)
                {
                    continue;
                }

                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 49);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
            }
        }
Example #6
0
        /// <summary>
        /// 获取在线时长
        /// </summary>
        /// <param name="userId"></param>
        public static async Task <int> GetRestOnlineSeconds(long userId)
        {
            DBProxyComponent proxyComponent  = Game.Scene.GetComponent <DBProxyComponent>();
            ConfigComponent  configComponent = Game.Scene.GetComponent <ConfigComponent>();

            List <GamerInfoDB> gamerInfos = await proxyComponent.QueryJson <GamerInfoDB>($"{{UId:{userId}}}");

            if (gamerInfos.Count == 0)
            {
                TreasureConfig config = (TreasureConfig)configComponent.Get(typeof(TreasureConfig), 1);
                return(config.TotalTime);
            }
            else
            {
                for (int j = 1; j < gamerInfos.Count; j++)
                {
                    await proxyComponent.Delete <GamerInfoDB>(gamerInfos[j].Id);
                }
            }

            TreasureConfig treasureConfig =
                configComponent.Get(typeof(TreasureConfig), ++gamerInfos[0].DailyTreasureCount) as TreasureConfig;

            //当天的宝箱已领取完
            if (treasureConfig == null)
            {
                return(-1);
            }

            int i = treasureConfig.TotalTime - gamerInfos[0].DailyOnlineTime;

//            Log.Debug("TotalTime" + treasureConfig.TotalTime);
//            Log.Debug("gamerInfos[0].DailyOnlineTime" + gamerInfos[0].DailyOnlineTime);
//            Log.Debug("还剩" + i);

            return(i);
        }
Example #7
0
        /// <summary>
        /// 记录玩家数据
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="totalSeconds"></param>
        /// <returns></returns>
        public static async Task RecordGamerInfo(long userId, int totalSeconds)
        {
            DBProxyComponent proxyComponent  = Game.Scene.GetComponent <DBProxyComponent>();
            ConfigComponent  configComponent = Game.Scene.GetComponent <ConfigComponent>();

            List <GamerInfoDB> gamerInfos = await proxyComponent.QueryJson <GamerInfoDB>($"{{UId:{userId}}}");

            GamerInfoDB gamerInfo;

            if (gamerInfos.Count == 0)
            {
                gamerInfo = ComponentFactory.CreateWithId <GamerInfoDB>(IdGenerater.GenerateId());
            }
            else
            {
                gamerInfo = gamerInfos[0];
            }

            gamerInfo.UId              = userId;
            gamerInfo.DailyOnlineTime += totalSeconds;
            gamerInfo.TotalOnlineTime += totalSeconds;

            TreasureConfig treasureConfig =
                configComponent.Get(typeof(TreasureConfig), ++gamerInfo.DailyTreasureCount) as TreasureConfig;

//            Log.Debug(gamerInfo.DailyTreasureCount + "");
//            Log.Debug(JsonHelper.ToJson(treasureConfig));


            if (gamerInfo.DailyOnlineTime > treasureConfig?.TotalTime)
            {
                gamerInfo.DailyOnlineTime = treasureConfig.TotalTime;
            }

            --gamerInfo.DailyTreasureCount;

            await proxyComponent.Save(gamerInfo);

            //记录玩家在线时长
            await DBCommonUtil.UpdateChengjiu(userId, 107, totalSeconds);

            await DBCommonUtil.UpdateChengjiu(userId, 108, totalSeconds);

            await DBCommonUtil.UpdateChengjiu(userId, 109, totalSeconds);
        }
Example #8
0
        protected override async void Run(Session session, C2G_LoginGate message, Action <G2C_LoginGate> reply)
        {
            G2C_LoginGate response = new G2C_LoginGate();

            try
            {
                long userId = Game.Scene.GetComponent <NjmjGateSessionKeyComponent>().Get(message.Key);
                if (userId == 0)
                {
                    response.Error   = ErrorCode.ERR_ConnectGateKeyError;
                    response.Message = "Gate key验证失败!";
                    reply(response);
                    return;
                }

                // 检测是否已存在
                UserComponentSystem.CheckIsExistTheUser(userId);

                //创建User对象
                User user = UserFactory.Create(userId, session);
                await user.AddComponent <MailBoxComponent>().AddLocation();

                //添加心跳包
                session.AddComponent <HeartBeatComponent>().CurrentTime = TimeHelper.ClientNowSeconds();
                //添加User对象关联到Session上
                session.AddComponent <SessionUserComponent>().User = user;

                //添加消息转发组件
                session.AddComponent <MailBoxComponent, string>(ActorType.GateSession);

                response.PlayerId = user.Id;
                response.Uid      = userId;

                ConfigComponent  configCom      = Game.Scene.GetComponent <ConfigComponent>();
                DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();

                {
                    //商城
                    if (ShopData.getInstance().getDataList().Count == 0)
                    {
                        List <ShopConfig> shopList = new List <ShopConfig>();
                        for (int i = 1; i < configCom.GetAll(typeof(ShopConfig)).Length + 1; ++i)
                        {
                            int        id     = 1000 + i;
                            ShopConfig config = (ShopConfig)configCom.Get(typeof(ShopConfig), id);
                            shopList.Add(config);
                        }
                        ShopData.getInstance().getDataList().AddRange(shopList);
                    }

                    //#region AddShopInfo
                    List <ShopInfo> shopInfoList = new List <ShopInfo>();
                    for (int i = 0; i < ShopData.getInstance().getDataList().Count; ++i)
                    {
                        ShopConfig config = ShopData.getInstance().getDataList()[i];
                        ShopInfo   info   = new ShopInfo();
                        info.Id           = (int)config.Id;
                        info.Name         = config.Name;
                        info.Price        = config.Price;
                        info.ShopType     = config.shopType;
                        info.Desc         = config.Desc;
                        info.CurrencyType = config.CurrencyType;
                        info.Items        = config.Items;
                        info.Icon         = config.Icon;
                        info.VipPrice     = config.VipPrice;
                        shopInfoList.Add(info);
                    }
                    response.ShopInfoList = shopInfoList;
                }
                {
                    //任务
                    if (TaskData.getInstance().getDataList().Count == 0)
                    {
                        List <TaskConfig> taskList = new List <TaskConfig>();
                        for (int i = 1; i < configCom.GetAll(typeof(TaskConfig)).Length + 1; ++i)
                        {
                            int        id     = 100 + i;
                            TaskConfig config = (TaskConfig)configCom.Get(typeof(TaskConfig), id);
                            taskList.Add(config);
                        }
                        TaskData.getInstance().getDataList().AddRange(taskList);
                    }
                }

                {
                    //成就
                    if (ChengjiuData.getInstance().getDataList().Count == 0)
                    {
                        List <ChengjiuConfig> chengjiuList = new List <ChengjiuConfig>();
                        for (int i = 1; i < configCom.GetAll(typeof(ChengjiuConfig)).Length + 1; ++i)
                        {
                            int            id     = 100 + i;
                            ChengjiuConfig config = (ChengjiuConfig)configCom.Get(typeof(ChengjiuConfig), id);
                            chengjiuList.Add(config);
                        }
                        ChengjiuData.getInstance().getDataList().AddRange(chengjiuList);
                    }
                }

                List <UserBag> bagInfoList = await proxyComponent.QueryJson <UserBag>($"{{UId:{userId}}}");

                response.BagList = new List <Bag>();
                List <Bag> bagList = new List <Bag>();
                for (int i = 0; i < bagInfoList.Count; ++i)
                {
                    Bag bag = new Bag();
                    bag.ItemId = bagInfoList[i].BagId;
                    bag.Count  = bagInfoList[i].Count;
                    bagList.Add(bag);
                }
                response.BagList = bagList;

                PlayerBaseInfo playerBaseInfo = await DBCommonUtil.getPlayerBaseInfo(userId);

                // 老用户检测
                {
                    try
                    {
                        AccountInfo accountInfo = await DBCommonUtil.getAccountInfo(userId);

                        if (accountInfo.OldAccountState == 1)
                        {
                            string url = "http://fksq.hy51v.com:10086/CheckIsOldUser?machine_id=" + accountInfo.MachineId + "&game_id=217";
                            string str = HttpUtil.GetHttp(url);
                            Log.Debug("web地址:" + url);
                            Log.Debug("判断是否是老用户:" + str);

                            JObject result  = JObject.Parse(str);
                            string  old_uid = (string)result.GetValue("old_uid");

                            // 不是老用户
                            if (string.IsNullOrEmpty(old_uid))
                            {
                                accountInfo.OldAccountState = 3;
                                await proxyComponent.Save(accountInfo);
                            }
                            // 是老用户
                            else
                            {
                                List <Log_OldUserBind> log_OldUserBinds = await proxyComponent.QueryJson <Log_OldUserBind>($"{{macId:'{accountInfo.MachineId}'}}");

                                if (log_OldUserBinds.Count > 0)
                                {
                                    accountInfo.OldAccountState = 3;
                                    await proxyComponent.Save(accountInfo);
                                }
                                else
                                {
                                    accountInfo.OldAccountState = 2;
                                    await proxyComponent.Save(accountInfo);

                                    // 记录绑定日志
                                    {
                                        Log_OldUserBind log_OldUserBind = ComponentFactory.CreateWithId <Log_OldUserBind>(IdGenerater.GenerateId());
                                        log_OldUserBind.Uid          = userId;
                                        log_OldUserBind.OldUid       = old_uid;
                                        log_OldUserBind.macId        = accountInfo.MachineId;
                                        log_OldUserBind.isSendReward = 1;

                                        await proxyComponent.Save(log_OldUserBind);
                                    }

                                    {
                                        url = ("http://fksq.hy51v.com:10086/GetOldNjmjData?UserId=" + old_uid);
                                        str = HttpUtil.GetHttp(url);

                                        result = JObject.Parse(str);
                                        int moneyAmount  = (int)result.GetValue("moneyAmount");
                                        int gIngotAmount = (int)result.GetValue("gIngotAmount");

                                        Log.Debug("老用户金币=" + moneyAmount + "   元宝=" + gIngotAmount);

                                        playerBaseInfo.GoldNum = moneyAmount;
                                        playerBaseInfo.WingNum = gIngotAmount;
                                        await proxyComponent.Save(playerBaseInfo);

                                        await DBCommonUtil.changeWealthWithStr(userId, "111:10;2:10", "老用户赠送");
                                    }

                                    // 发送老用户广播
                                    Actor_OldUser actor_OldUser = new Actor_OldUser();
                                    actor_OldUser.OldAccount = old_uid;
                                    Game.Scene.GetComponent <UserComponent>().BroadCastToSingle(actor_OldUser, userId);
                                }
                            }
                        }
                        else if (accountInfo.OldAccountState == 2)
                        {
                            List <Log_OldUserBind> log_OldUserBinds = await proxyComponent.QueryJson <Log_OldUserBind>($"{{macId:'{accountInfo.MachineId}'}}");

                            if (log_OldUserBinds.Count > 0)
                            {
                                if (log_OldUserBinds[0].isSendReward != 1)
                                {
                                    log_OldUserBinds[0].isSendReward = 1;
                                    await proxyComponent.Save(log_OldUserBinds[0]);

                                    await DBCommonUtil.SendMail(userId, "更新游戏奖励", "亲爱的玩家,南京麻将最新版本更新了,特意送上更新奖励,请笑纳,祝您游戏愉快!", "111:10;2:10");
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error("检测是否是老用户出错:" + ex);
                    }
                }

                #region 用户活动所获得的头像数据
                List <OtherData> otherDatas = await proxyComponent.QueryJson <OtherData>($"{{UId:{userId}}}");

                if (otherDatas.Count > 0)
                {
                    response.ownIcon = otherDatas[0].OwnIcon;
                }
                #endregion

                reply(response);
                session.Send(new G2C_TestHotfixMessage()
                {
                    Info = "recv hotfix message success"
                });

                // vip上线全服广播
                {
                    if (playerBaseInfo.VipTime.CompareTo(CommonUtil.getCurTimeNormalFormat()) > 0)
                    {
                        Actor_LaBa actor_LaBa = new Actor_LaBa();
                        actor_LaBa.LaBaContent = "贵族玩家" + playerBaseInfo.Name + "上线啦!";
                        Game.Scene.GetComponent <UserComponent>().BroadCast(actor_LaBa);
                    }
                }
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
        public async override void Run()
        {
            RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();

            if (roomComponent == null)
            {
                //TODO:用command時防呆,這邊先return,應該有更好的做法
                return;
            }

            ConfigComponent configComponent = Game.Scene.GetComponent <ConfigComponent>();

            IConfig[] roadSettings = configComponent.GetAll(typeof(RoadSetting));

            StartConfigComponent startConfigComponent = Game.Scene.GetComponent <StartConfigComponent>();
            StartConfig          startConfig          = startConfigComponent.StartConfig;

            for (int i = 0; i < roadSettings.Length; i++)
            {
                RoadSetting roadSetting = roadSettings[i] as RoadSetting;
                if (roadSetting == null)
                {
                    continue;
                }
                if (roadSetting.Id < RoadHelper.RoamingIdStart || roadSetting.Id > RoadHelper.RoamingIdEnd)
                {
                    continue;
                }
                int mapIndex = startConfigComponent.MapConfigs.IndexOf(startConfig);
                if (startConfig.AppType != AppType.AllServer)
                {
                    if (roadSetting.MapServerIndex != mapIndex)
                    {
                        continue;
                    }
                }
                var      mapLimitSetting = (MapLimitSetting)configComponent.Get(typeof(MapLimitSetting), roadSetting.MapServerIndex);
                RoomInfo roamingRoomInfo = new RoomInfo()
                {
                    Title          = string.Empty,
                    RoadSettingId  = roadSetting.Id,
                    MaxMemberCount = mapLimitSetting == null ? 1000 : mapLimitSetting.MaxUserCount,
                };

                var room = roomComponent.GetRoamingBySettingId(roadSetting.Id);

                if (room == null)
                {
                    roamingRoomInfo.NowMemberCount = 0;
                    room = await roomComponent.CreateRoamingRoom(roamingRoomInfo);
                }
                else
                {
                    room.SetData(roamingRoomInfo);
                }

                roomComponent.Update(room).Coroutine();

                //RoomInfo teamRoomInfo = new RoomInfo()
                //{
                //    Title = $"測試組隊_{RandomHelper.RandomNumber(1515, 54861655)}",
                //    RoadSettingId = roadSetting.Id,
                //    MaxMemberCount = 8,
                //    NowMemberCount = 0,
                //};

                //TeamRoomData teamRoomData = new TeamRoomData()
                //{
                //    LeaderName = $"測試玩家_{i}",
                //    LeaderUid = 989898989,
                //    StartUTCTimeTick = DateTime.UtcNow.Ticks,
                //};

                //roomComponent.CreateTeamRoom(teamRoomInfo, teamRoomData);
            }
        }
Example #10
0
        protected override async ETTask Run(ETModel.Session session, M2C_CreateUnits message)
        {
            foreach (UnitInfo unitInfo in message.Units)
            {
                //TODO 暂时先忽略除英雄之外的Unit(如技能碰撞体),后期需要配表来解决这一块的逻辑,并且需要在协议里指定Unit的类型Id(注意不是运行时的Id,是Excel表中的类型Id)
                //TODO 诺手UnitTypeId暂定10001
                if (UnitComponent.Instance.Get(unitInfo.UnitId) != null || unitInfo.UnitTypeId != 10001)
                {
                    continue;
                }

                //根据不同名称和ID,创建英雄
                Unit unit = UnitFactory.CreateHero(unitInfo.UnitId, "NuoKe", (RoleCamp)unitInfo.RoleCamp);
                //因为血条需要,创建热更层unit
                HotfixUnit hotfixUnit = HotfixUnitFactory.CreateHotfixUnit(unit, true);

                hotfixUnit.AddComponent <FallingFontComponent>();

                unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z);

                //添加英雄数据
                M2C_GetHeroDataResponse M2C_GetHeroDataResponse = await Game.Scene.GetComponent <SessionComponent>()
                                                                  .Session.Call(new C2M_GetHeroDataRequest()
                {
                    UnitID = unitInfo.UnitId
                }) as M2C_GetHeroDataResponse;

                UnitComponent.Instance.Get(unitInfo.UnitId)
                .AddComponent <HeroDataComponent, long>(M2C_GetHeroDataResponse.HeroDataID);

                unit.AddComponent <NP_RuntimeTreeManager>();

                //Log.Info("开始创建行为树");
                ConfigComponent configComponent = Game.Scene.GetComponent <ConfigComponent>();
                NP_RuntimeTreeFactory.CreateSkillNpRuntimeTree(unit, configComponent.Get <Client_SkillCanvasConfig>(10001).NPBehaveId,
                                                               configComponent.Get <Client_SkillCanvasConfig>(10001).BelongToSkillId).Start();
                NP_RuntimeTreeFactory.CreateSkillNpRuntimeTree(unit, configComponent.Get <Client_SkillCanvasConfig>(10002).NPBehaveId,
                                                               configComponent.Get <Client_SkillCanvasConfig>(10002).BelongToSkillId).Start();
                NP_RuntimeTreeFactory.CreateSkillNpRuntimeTree(unit, configComponent.Get <Client_SkillCanvasConfig>(10003).NPBehaveId,
                                                               configComponent.Get <Client_SkillCanvasConfig>(10003).BelongToSkillId).Start();
                NP_RuntimeTreeFactory.CreateSkillNpRuntimeTree(unit, configComponent.Get <Client_SkillCanvasConfig>(10004).NPBehaveId,
                                                               configComponent.Get <Client_SkillCanvasConfig>(10004).BelongToSkillId).Start();
                //Log.Info("行为树创建完成");

                // 创建头顶Bar
                Game.EventSystem.Run(EventIdType.CreateHeadBar, unitInfo.UnitId);
                // 挂载头顶Bar
                hotfixUnit.AddComponent <HeroHeadBarComponent, Unit, FUI>(unit,
                                                                          Game.Scene.GetComponent <FUIComponent>().Get(unitInfo.UnitId));
            }

            if (UnitComponent.Instance.MyUnit == null)
            {
                // 给自己的Unit添加引用
                UnitComponent.Instance.MyUnit =
                    UnitComponent.Instance.Get(PlayerComponent.Instance.MyPlayer.UnitId);
                UnitComponent.Instance.MyUnit
                .AddComponent <CameraComponent, Unit>(UnitComponent.Instance.MyUnit);

                UnitComponent.Instance.MyUnit.AddComponent <OutLineComponent>();

                Game.Scene.GetComponent <M5V5GameComponent>().GetHotfixUnit(PlayerComponent.Instance.MyPlayer.UnitId).AddComponent <PlayerHeroControllerComponent>();

                Game.EventSystem.Run(EventIdType.EnterMapFinish);
            }

            //ETModel.Log.Info($"{DateTime.UtcNow}完成一次创建Unit");
            await ETTask.CompletedTask;
        }
Example #11
0
        protected override async Task Run(Gamer gamer, C2M_ActorGamerGetTreasure message, Action <M2C_ActorGamerGetTreasure> reply)
        {
            M2C_ActorGamerGetTreasure response = new M2C_ActorGamerGetTreasure();

            try
            {
                DBProxyComponent proxyComponent  = Game.Scene.GetComponent <DBProxyComponent>();
                ConfigComponent  configComponent = Game.Scene.GetComponent <ConfigComponent>();

                //记录数据
                gamer.EndTime = DateTime.Now;
                TimeSpan span         = gamer.EndTime - gamer.StartTime;
                int      totalSeconds = (int)span.TotalSeconds;
                //await DBCommonUtil.RecordGamerTime(gamer.EndTime, false, gamer.UserID);
                await DBCommonUtil.RecordGamerInfo(gamer.UserID, totalSeconds);

                List <GamerInfoDB> gamerInfos = await proxyComponent.QueryJson <GamerInfoDB>($"{{UId:{gamer.UserID}}}");

                if (gamerInfos.Count == 0)
                {
                    response.Error   = ErrorCode.ERR_Common;
                    response.Message = "未到时间";
                    reply(response);
                    return;
                }
                GamerInfoDB gamerInfo = gamerInfos[0];
                gamerInfo.DailyTreasureCount++;
                TreasureConfig config = configComponent.Get(typeof(TreasureConfig), gamerInfo.DailyTreasureCount) as TreasureConfig;

                Log.Debug("config:" + JsonHelper.ToJson(config));

                if (config == null)
                {
                    response.Error   = ErrorCode.ERR_Common;
                    response.Message = "宝箱已领取完";
                }
                else
                {
                    if (gamerInfo.DailyOnlineTime >= config.TotalTime)
                    {
                        await DBCommonUtil.ChangeWealth(gamer.UserID, 1, config.Reward, "游戏内宝箱奖励");

                        await proxyComponent.Save(gamerInfo);

                        //下一个奖励
                        TreasureConfig treasureConfig = (TreasureConfig)configComponent.Get(typeof(TreasureConfig), ++gamerInfo.DailyTreasureCount);
                        //宝箱领完了
                        if (treasureConfig == null)
                        {
                            response.RestSeconds = -1;
                            response.Reward      = config.Reward;
                        }
                        else
                        {
                            response.RestSeconds = treasureConfig.TotalTime - gamerInfo.DailyOnlineTime;
                            response.Reward      = config.Reward;
                        }
                    }
                    else
                    {
                        response.Error   = ErrorCode.ERR_Common;
                        response.Message = "未到时间";
                    }
                }

                reply(response);

                gamer.StartTime = DateTime.Now;
                //await DBCommonUtil.RecordGamerTime(gamer.EndTime, false, gamer.UserID);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }

            await Task.CompletedTask;
        }
Example #12
0
 //获取微信Post外网地址
 public static string GetOuterPostAddress()
 {
     if (string.IsNullOrEmpty(outerPostAddressStr))
     {
         ConfigComponent           configComponent           = Game.Scene.GetComponent <ConfigComponent>();
         HttpListenerAddressConfig httpListenerAddressConfig = (HttpListenerAddressConfig)configComponent.Get(typeof(HttpListenerAddressConfig), 0);
         outerPostAddressStr = httpListenerAddressConfig.OuterPostAddress;
     }
     return(outerPostAddressStr);
 }
        protected override async void Run(ETModel.Session session, A1010_NewArmyWave_M2C message)
        {
            //服务端通知客户端刷新一波士兵 1坦克 战士 1法师
            TimerComponent     timerComponent     = ETModel.Game.Scene.GetComponent <TimerComponent>();
            ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>();
            GameObject         bundleGameObject   = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");
            ConfigComponent    config             = Game.Scene.GetComponent <ConfigComponent>();
            Moba5V5Component   moba = Moba5V5Component.instance;

            //创建3个蓝方坦克 配置编号37-39
            for (int i = 0; i < 3; i++)
            {
                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 37);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
                character.route  = moba5V5Config.Route; //默认导航线路
            }
            //创建3个红方坦克 配置编号46-48
            for (int i = 0; i < 3; i++)
            {
                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 46);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
                character.route  = moba5V5Config.Route; //默认导航线路
            }

            await timerComponent.WaitAsync(1000);

            for (int i = 0; i < 3; i++)
            {
                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 31);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
                character.route  = moba5V5Config.Route; //默认导航线路
            }
            for (int i = 0; i < 3; i++)
            {
                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 40);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
                character.route  = moba5V5Config.Route; //默认导航线路
            }

            await timerComponent.WaitAsync(1000);

            //创建3个蓝方法师 配置编号34-36
            for (int i = 0; i < 3; i++)
            {
                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 34);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
                character.route  = moba5V5Config.Route; //默认导航线路
            }
            //创建3个红方法师 配置编号43-45
            for (int i = 0; i < 3; i++)
            {
                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 43);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
                character.route  = moba5V5Config.Route; //默认导航线路
            }
        }
        protected override async void Run(ETModel.Session session, A1004_CreateMoba5V5Secene_M2C message)
        {
            //开启加载界面 切换UI
            UIComponent uiComponent = Game.Scene.GetComponent <UIComponent>();
            UI          ui          = uiComponent.Get(UIType.SekiaLobby);

            if (ui == null)
            {
                return;
            }
            if (ui.GetComponent <SekiaLobbyComponent>().isMatching == false)
            {
                return;
            }
            uiComponent.Create(UIType.Moba5V5UI);
            uiComponent.Remove(UIType.SekiaLobby);

            //切换场景
            using (SceneChangeComponent sceneChangeComponent = ETModel.Game.Scene.AddComponent <SceneChangeComponent>())
            {
                await sceneChangeComponent.ChangeSceneAsync(SceneType.Moba5V5Map);
            }

            //加载配置
            ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>();
            await resourcesComponent.LoadBundleAsync($"unit.unity3d");

            GameObject       bundleGameObject = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");
            ConfigComponent  config           = Game.Scene.GetComponent <ConfigComponent>();
            Moba5V5Component moba             = Game.Scene.AddComponent <Moba5V5Component>();

            //创建空气墙 编号73和74
            for (int i = 0; i < 2; i++)
            {
                Moba5V5Config qiang       = (Moba5V5Config)config.Get(typeof(Moba5V5Config), 73 + i);
                GameObject    qiangPrefab = bundleGameObject.Get <GameObject>(qiang.Prefab);
                qiangPrefab.transform.position    = new Vector3((float)qiang.Position[0], (float)qiang.Position[1], (float)qiang.Position[2]);
                qiangPrefab.transform.eulerAngles = new Vector3(0, qiang.Rotation, 0);
                qiangPrefab.name = $"Qiang{(i + 1).ToString()}";
                UnityEngine.Object.Instantiate(qiangPrefab).transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
            }

            //创建10个英雄的GameObject和Gamer MobaID编号1-10
            for (int i = 0; i < message.Gamers.Count; i++)
            {
                //获取英雄配置 角色配置 技能配置
                HeroConfig    heroConfig    = (HeroConfig)config.Get(typeof(HeroConfig), message.Gamers[i].HeroID);
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 1);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(heroConfig.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer, long>(message.Gamers[i].UserID);
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                GamerAnimatorComponent anime = gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
                character.route  = moba5V5Config.Route; //默认导航线路
                character.anime  = anime;

                //确认本地玩家
                if (gamer.UserID == GamerComponent.Instance.MyUser.UserID)
                {
                    gamer.AddComponent <GamerCameraComponent>();
                    moba.myGamer = gamer;
                }
            }

            //创建攻击类建筑 MobaID编号11-30
            for (int i = 0; i < 20; i++)
            {
                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 11);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = GameObject.Find($"/World/5v5_Map/mobaTower{i+1}");
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();

                //设置角色
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
            }

            //初始加载完成
            SessionComponent.Instance.Session.Send(new A1007_GamerReadyMoba5V5_C2M());
            //等待服务端通知游戏计时开始
            //等待服务端通知刷新第一波小兵
            //等待服务端通知刷新普通野怪
            //等待服务端通知刷新大龙
        }
Example #15
0
        //1,刷新所有配置表 2,发送邮件 3,解散房间 4,增减黑名单 5,生成报表 6,查看用户信息 7,强制离线 8,修改用户信息 9,查看游戏内信息
        protected override async void Run(Session session, C2G_GM message, Action <G2C_GM> reply)
        {
            G2C_GM response = new G2C_GM();

            try
            {
                DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>();
                if (Game.Scene.GetComponent <ConfigComponent>() != null)
                {
                    Game.Scene.RemoveComponent <ConfigComponent>();
                }
                Game.Scene.AddComponent <ConfigComponent>();
                ConfigComponent      configCom     = Game.Scene.GetComponent <ConfigComponent>();
                StartConfigComponent _config       = Game.Scene.GetComponent <StartConfigComponent>();
                IPEndPoint           mapIPEndPoint = _config.MapConfigs[0].GetComponent <InnerConfig>().IPEndPoint;
                Session mapSession = Game.Scene.GetComponent <NetInnerComponent>().Get(mapIPEndPoint);

                switch (message.Type)
                {
                case 1:
                {
                    //刷新所有配置表
                    List <PlayerBaseInfo> allInfos = await proxyComponent.QueryJsonDBInfos <PlayerBaseInfo>();

                    {
                        //商城
                        List <ShopConfig> shopList = new List <ShopConfig>();
                        for (int i = 1; i < configCom.GetAll(typeof(ShopConfig)).Length + 1; ++i)
                        {
                            int        id     = 1000 + i;
                            ShopConfig config = (ShopConfig)configCom.Get(typeof(ShopConfig), id);
                            shopList.Add(config);
                        }
                        ShopData.getInstance().getDataList().Clear();
                        ShopData.getInstance().getDataList().AddRange(shopList);
                    }
                    {
                        //任务
                        List <TaskConfig> taskList = new List <TaskConfig>();
                        for (int i = 1; i < configCom.GetAll(typeof(TaskConfig)).Length + 1; ++i)
                        {
                            int        id     = 100 + i;
                            TaskConfig config = (TaskConfig)configCom.Get(typeof(TaskConfig), id);
                            taskList.Add(config);
                        }
                        TaskData.getInstance().getDataList().Clear();
                        TaskData.getInstance().getDataList().AddRange(taskList);
                        for (int i = 0; i < allInfos.Count; ++i)
                        {
                            List <TaskProgressInfo> taskInfos = await proxyComponent.QueryJson <TaskProgressInfo>($"{{UId:{allInfos[i].Id}}}");

                            //无论删减任务 都要刷新一下任务的数据库
                            for (int j = 0; j < taskInfos.Count; ++j)
                            {
                                TaskConfig config = TaskData.getInstance().GetDataByTaskId(taskInfos[j].TaskId);
                                if (config != null)
                                {
                                    taskInfos[j].Name   = config.Name;
                                    taskInfos[j].Target = config.Target;
                                    taskInfos[j].Reward = config.Reward;
                                    taskInfos[j].Desc   = config.Desc;
                                    await proxyComponent.Save(taskInfos[j]);
                                }
                            }

                            #region 增加任务先不管 update时会重新添加
                            //if (TaskData.getInstance().getDataList().Count > taskInfos.Count)
                            //{
                            //    //增加了新任务
                            //    for (int j = 0; j < TaskData.getInstance().getDataList().Count; ++j)
                            //    {
                            //        List<TaskProgressInfo> progresses = await proxyComponent.QueryJson<TaskProgressInfo>($"{{UId:{allInfos[i].Id},TaskId:{TaskData.getInstance().getDataList()[j].Id}}}");
                            //        if (progresses.Count <= 0)
                            //        {
                            //            TaskProgressInfo progress =
                            //          ComponentFactory.CreateWithId<TaskProgressInfo>(IdGenerater.GenerateId());
                            //            progress.IsGet = false;
                            //            progress.UId = allInfos[i].Id;
                            //            progress.Name = TaskData.getInstance().getDataList()[j].Name;
                            //            progress.TaskId = (int)TaskData.getInstance().getDataList()[j].Id;
                            //            progress.IsComplete = false;
                            //            progress.Target = TaskData.getInstance().getDataList()[j].Target;
                            //            progress.Reward = TaskData.getInstance().getDataList()[j].Reward;
                            //            progress.Desc = TaskData.getInstance().getDataList()[j].Desc;
                            //            progress.CurProgress = 0;

                            //            await proxyComponent.Save(progress);
                            //        }
                            //    }
                            //}
                            #endregion

                            if (TaskData.getInstance().getDataList().Count < taskInfos.Count)
                            {
                                for (int j = 0; j < taskInfos.Count; ++j)
                                {
                                    TaskConfig config = TaskData.getInstance().GetDataByTaskId(taskInfos[j].TaskId);
                                    List <TaskProgressInfo> progresses = await proxyComponent.QueryJson <TaskProgressInfo>($"{{UId:{allInfos[i].Id},TaskId:{taskInfos[j].TaskId}}}");

                                    if (config == null)
                                    {
                                        if (progresses.Count > 0)
                                        {
                                            //删除该任务
                                            await proxyComponent.Delete <TaskProgressInfo>(progresses[0].Id);
                                        }
                                    }
                                }
                            }
                        }
                        {
                            //成就
                            List <ChengjiuConfig> chengjiuList = new List <ChengjiuConfig>();
                            for (int i = 1; i < configCom.GetAll(typeof(ChengjiuConfig)).Length + 1; ++i)
                            {
                                int            id     = 100 + i;
                                ChengjiuConfig config = (ChengjiuConfig)configCom.Get(typeof(ChengjiuConfig), id);
                                chengjiuList.Add(config);
                            }
                            ChengjiuData.getInstance().getDataList().Clear();
                            ChengjiuData.getInstance().getDataList().AddRange(chengjiuList);
                            for (int i = 0; i < allInfos.Count; ++i)
                            {
                                List <ChengjiuInfo> chengjiuInfos = await proxyComponent.QueryJson <ChengjiuInfo>($"{{UId:{allInfos[i].Id}}}");

                                //无论删减任务 都要刷新一下任务的数据库
                                for (int j = 0; j < chengjiuInfos.Count; ++j)
                                {
                                    ChengjiuConfig config = ChengjiuData.getInstance().GetDataByChengjiuId(chengjiuInfos[j].TaskId);
                                    if (config != null)
                                    {
                                        chengjiuInfos[j].Name   = config.Name;
                                        chengjiuInfos[j].Target = config.Target;
                                        chengjiuInfos[j].Reward = config.Reward;
                                        chengjiuInfos[j].Desc   = config.Desc;
                                        await proxyComponent.Save(chengjiuInfos[j]);
                                    }
                                }

                                #region 增加(暂时先不管 Update时会新加)
                                //if (ChengjiuData.getInstance().getDataList().Count > chengjiuInfos.Count)
                                //{
                                //    //增加了新成就
                                //    for (int j = chengjiuInfos.Count; j < ChengjiuData.getInstance().getDataList().Count; ++j)
                                //    {
                                //        List<ChengjiuInfo> progresses = await proxyComponent.QueryJson<ChengjiuInfo>($"{{UId:{allInfos[i].Id},TaskId:{ChengjiuData.getInstance().getDataList()[j].Id}}}");
                                //        if (progresses.Count <= 0)
                                //        {
                                //            Log.Debug("增加新成就");
                                //            ChengjiuInfo progress =
                                //          ComponentFactory.CreateWithId<ChengjiuInfo>(IdGenerater.GenerateId());
                                //            progress.IsGet = false;
                                //            progress.UId = allInfos[i].Id;
                                //            progress.Name = ChengjiuData.getInstance().getDataList()[j].Name;
                                //            progress.TaskId = (int)ChengjiuData.getInstance().getDataList()[j].Id;
                                //            progress.IsComplete = false;
                                //            progress.Target = ChengjiuData.getInstance().getDataList()[j].Target;
                                //            progress.Reward = ChengjiuData.getInstance().getDataList()[j].Reward;
                                //            progress.Desc = ChengjiuData.getInstance().getDataList()[j].Desc;
                                //            progress.CurProgress = 0;

                                //            await proxyComponent.Save(progress);
                                //        }
                                //    }
                                //}
                                #endregion

                                if (ChengjiuData.getInstance().getDataList().Count < chengjiuInfos.Count)
                                {
                                    for (int j = 0; j < chengjiuInfos.Count; ++j)
                                    {
                                        ChengjiuConfig      config     = ChengjiuData.getInstance().GetDataByChengjiuId(chengjiuInfos[j].TaskId);
                                        List <ChengjiuInfo> progresses = await proxyComponent.QueryJson <ChengjiuInfo>($"{{UId:{allInfos[i].Id},TaskId:{chengjiuInfos[j].TaskId}}}");

                                        if (config == null)
                                        {
                                            if (progresses.Count > 0)
                                            {
                                                //删除该成就
                                                await proxyComponent.Delete <ChengjiuInfo>(progresses[0].Id);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                break;

                case 2:
                {
                    //发送邮件 uid为空则为给全部玩家发送邮件
                    if (message.UId != -1)
                    {
                        Log.Debug("Mail" + message.UId + message.Title + message.Content + message.Reward);
                        await DBCommonUtil.SendMail(message.UId, message.Title, message.Content, message.Reward);
                    }
                    else
                    {
                        //分批发还是全部一次性发
                        List <PlayerBaseInfo> playerBaseInfos = await proxyComponent.QueryJsonDBInfos <PlayerBaseInfo>();

                        if (playerBaseInfos.Count > 0)
                        {
                            for (int i = 0; i < playerBaseInfos.Count; ++i)
                            {
                                await DBCommonUtil.SendMail(playerBaseInfos[i].Id, message.Title, message.Content, message.Reward);
                            }
                        }
                    }
                }
                break;

                case 3:
                {
                    //解散房间

                    M2G_GMInfo m2G_GMInfo = (M2G_GMInfo)await mapSession.Call(new G2M_GMInfo()
                        {
                            Type = 3, Uid = message.UId
                        });

                    response.Error   = m2G_GMInfo.Error;
                    response.Message = m2G_GMInfo.Message;
                }
                break;

                case 4:
                {
                    //增减黑名单(根据玩家IP)
                    List <BlackList> blackList = await proxyComponent.QueryJson <BlackList>($"{{ip:'{message.IP}'}}");

                    if (string.IsNullOrEmpty(message.EndTime))
                    {
                        //删除黑名单
                        if (blackList.Count > 0)
                        {
                            blackList[0].EndTime = "2000-01-01 00:00:00";
                            await proxyComponent.Save(blackList[0]);
                        }
                    }
                    else
                    {
                        if (blackList.Count > 0)
                        {
                            blackList[0].EndTime = message.EndTime;
                            await proxyComponent.Save(blackList[0]);
                        }
                        else
                        {
                            BlackList list = ComponentFactory.CreateWithId <BlackList>(IdGenerater.GenerateId());
                            list.Uid     = message.UId;
                            list.ip      = message.IP;
                            list.EndTime = message.EndTime;
                            list.Reason  = message.Reason;
                            await proxyComponent.Save(list);
                        }
                    }
                }
                break;

                case 5:
                {
                    //生成报表
                    string logData = await DataStatistics.Start(message.CreateBaobiaoTime, message.Content);

                    response.LogData = logData;
                }
                break;

                case 6:
                    //查看用户信息
                    List <PlayerBaseInfo> infos       = new List <PlayerBaseInfo>();
                    AccountInfo           accountInfo = null;
                    List <Log_Login>      logLogins   = new List <Log_Login>();
                    if (message.UId != 0)
                    {
                        infos = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{message.UId}}}");

                        accountInfo = await DBCommonUtil.getAccountInfo(message.UId);

                        logLogins = await proxyComponent.QueryJson <Log_Login>($"{{Uid:{message.UId}}}");
                    }
                    else if (!string.IsNullOrEmpty(message.Name))
                    {
                        infos = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{Name:'{message.Name}'}}");

                        if (infos.Count > 0)
                        {
                            accountInfo = await DBCommonUtil.getAccountInfo(infos[0].Id);

                            logLogins = await proxyComponent.QueryJson <Log_Login>($"{{Uid:{infos[0].Id}}}");
                        }
                    }

                    if (infos.Count > 0)
                    {
                        PlayerInfo info = new PlayerInfo();
                        info.Name           = infos[0].Name;
                        info.GoldNum        = infos[0].GoldNum;
                        info.WingNum        = infos[0].WingNum;
                        info.HuaFeiNum      = infos[0].HuaFeiNum;
                        info.IsRealName     = infos[0].IsRealName;
                        info.VipTime        = infos[0].VipTime;
                        info.EmogiTime      = infos[0].EmogiTime;
                        info.MaxHua         = infos[0].MaxHua;
                        info.TotalGameCount = infos[0].TotalGameCount;
                        info.WinGameCount   = infos[0].WinGameCount;
                        response.UId        = infos[0].Id;
                        M2G_GMInfo m2G_GMInfo = (M2G_GMInfo)await mapSession.Call(new G2M_GMInfo()
                        {
                            Type = 6, Uid = message.UId
                        });

                        Log.Debug(m2G_GMInfo.Type + "");
                        response.IsInGame = m2G_GMInfo.Type;
                        if (logLogins.Count > 0)
                        {
                            response.LastOnlineTime = logLogins[logLogins.Count - 1].CreateTime;
                        }
                        if (accountInfo != null)
                        {
                            info.Phone            = accountInfo.Phone;
                            response.RegisterTime = accountInfo.CreateTime;
                            response.Channel      = accountInfo.ChannelName;
                        }
                        response.Info = info;
                        response.Ip   = logLogins[logLogins.Count - 1].ip;
                    }
                    else
                    {
                        response.Message = "不存在该用户信息";
                        response.Error   = ErrorCode.ERR_Exception;
                        response.Info    = null;
                    }
                    break;

                case 7:
                {
                    //强制玩家离线
                    UserComponentSystem.ForceOffline(message.UId, message.Reason);
                }
                break;

                case 8:
                {
                    //更改用户信息
                    if (message.UId == -1)
                    {
                        List <PlayerBaseInfo> playerBaseInfos = await proxyComponent.QueryJsonDBInfos <PlayerBaseInfo>();

                        if (playerBaseInfos.Count > 0)
                        {
                            for (int i = 0; i < playerBaseInfos.Count; ++i)
                            {
                                if (!message.Icon.Equals("0"))
                                {
                                    playerBaseInfos[0].Icon = message.Icon;
                                    await proxyComponent.Save(playerBaseInfos[0]);
                                }
                                if (message.RestChangeNameCount != 0)
                                {
                                    playerBaseInfos[0].RestChangeNameCount = message.RestChangeNameCount;
                                    await proxyComponent.Save(playerBaseInfos[0]);
                                }
                                if (!message.Prop.Equals("0"))
                                {
                                    await DBCommonUtil.changeWealthWithStr(playerBaseInfos[i].Id, message.Prop, "GM中增加玩家道具");
                                }
                            }
                        }
                    }
                    else
                    {
                        List <PlayerBaseInfo> playerInfos = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{message.UId}}}");

                        if (playerInfos.Count > 0)
                        {
                            if (!message.Icon.Equals("0"))
                            {
                                playerInfos[0].Icon = message.Icon;
                                await proxyComponent.Save(playerInfos[0]);
                            }
                            if (message.RestChangeNameCount != 0)
                            {
                                playerInfos[0].RestChangeNameCount = message.RestChangeNameCount;
                                await proxyComponent.Save(playerInfos[0]);
                            }
                            if (!message.Prop.Equals("0"))
                            {
                                await DBCommonUtil.changeWealthWithStr(message.UId, message.Prop, "GM中增加玩家道具");
                            }
                        }
                        else
                        {
                            response.Error   = ErrorCode.ERR_Exception;
                            response.Message = "用户不存在,请检查UID是否正确";
                        }
                    }
                }
                break;

                case 9:
                {
                    //查看游戏内信息
                    M2G_GetRoomInfo getRoomInfo = (M2G_GetRoomInfo)await mapSession.Call(new G2M_GetRoomInfo());

                    response.Room = new RoomInfo();
                    response.Room.NewRoomCount = getRoomInfo.NewRoomCount;
                    response.Room.NewTotalPlayerInGameCount  = getRoomInfo.NewTotalPlayerInGameCount;
                    response.Room.JingRoomCount              = getRoomInfo.JingRoomCount;
                    response.Room.JingTotalPlayerInGameCount = getRoomInfo.JingTotalPlayerInGameCount;
                }
                break;

                case 10:
                {
                    // 发送通知
                    UserComponentSystem.EmergencyNotice(message.UId, message.Content);
                }
                break;

                case 11:
                {
                    //session
                    int count = Game.Scene.GetComponent <NetOuterComponent>().sessions.Count;
                    response.Channel = count.ToString();
                }
                break;

                case 12:
                {
                    //改变玩家好友房钥匙
                    long   uid     = message.UId;                   // -1代表给所有人发
                    int    num     = message.RestChangeNameCount;
                    string endTime = message.EndTime;               // 如果是删除钥匙,此参数可以为空
                    string reason  = message.Reason;

                    if (uid != -1)
                    {
                        if (num > 0)
                        {
                            await DBCommonUtil.AddFriendKey(uid, num, endTime, reason);
                        }
                        else if (num < 0)
                        {
                            await DBCommonUtil.DeleteFriendKey(uid, -num, reason);
                        }
                    }
                    else
                    {
                        List <AccountInfo> listData = await proxyComponent.QueryJsonDBInfos <AccountInfo>();

                        for (int i = 0; i < listData.Count; i++)
                        {
                            if (num > 0)
                            {
                                await DBCommonUtil.AddFriendKey(listData[i].Id, num, endTime, reason);
                            }
                            else if (num < 0)
                            {
                                await DBCommonUtil.DeleteFriendKey(listData[i].Id, -num, reason);
                            }
                        }
                    }
                }
                break;
                }
                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Example #16
0
        public void Start()
        {
            MyListerner = new HttpListener();
            while (true)
            {
                try
                {
                    MyListerner.AuthenticationSchemes = AuthenticationSchemes.Anonymous;
                    ConfigComponent           configComponent           = Game.Scene.GetComponent <ConfigComponent>();
                    HttpListenerAddressConfig httpListenerAddressConfig = (HttpListenerAddressConfig)configComponent.Get(typeof(HttpListenerAddressConfig), 0);
                    Log.Debug("服务器地址......" + httpListenerAddressConfig.Address);
                    MyListerner.Prefixes.Add(httpListenerAddressConfig.Address);
                    MyListerner.Start();
                }
                catch (Exception ex)
                {
                    Log.Debug(ex + "服务器启动失败......");
                    break;
                }
                Log.Debug("服务器启动成功......");

                //线程池
                int minThreadNum;
                int portThreadNum;
                int maxThreadNum;
                ThreadPool.GetMaxThreads(out maxThreadNum, out portThreadNum);
                ThreadPool.GetMinThreads(out minThreadNum, out portThreadNum);
                Log.Debug($"最大线程数:{maxThreadNum}");
                Log.Debug($"最小空闲线程数:{minThreadNum}");
                //ThreadPool.QueueUserWorkItem(new WaitCallback(TaskProc1), x);

                Log.Debug("\n等待客户连接中......");
                while (true)
                {
                    //等待请求连接
                    //没有请求则GetContext处于阻塞状态
                    HttpListenerContext ctx = MyListerner.GetContext();

                    ThreadPool.QueueUserWorkItem(new WaitCallback(TaskProc), ctx);
                }
            }
        }
Example #17
0
        protected override void Run(ETModel.Session session, A1012_NewMonster_M2C message)
        {
            //服务端通知客户端刷新一窝野怪
            TimerComponent     timerComponent     = ETModel.Game.Scene.GetComponent <TimerComponent>();
            ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>();
            GameObject         bundleGameObject   = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");
            ConfigComponent    config             = Game.Scene.GetComponent <ConfigComponent>();
            Moba5V5Component   moba = Moba5V5Component.instance;

            //野怪点ID 编号分别为:49 51 52 54 57 58 59 60 61 62 63 64 65 68 70 71
            int configID;      //配置编号
            int monsterNumber; //野怪数量

            switch (message.MonsterID)
            {
            case 49:     //蜥蜴
                configID      = 49;
                monsterNumber = 2;
                break;

            case 51:     //蓝Buff
                configID      = 51;
                monsterNumber = 1;
                break;

            case 52:     //狼
                configID      = 52;
                monsterNumber = 2;
                break;

            case 54:     //熊
                configID      = 54;
                monsterNumber = 3;
                break;

            case 57:     //红Buff
                configID      = 57;
                monsterNumber = 1;
                break;

            case 58:     //鸟
                configID      = 58;
                monsterNumber = 1;
                break;

            case 59:     //河道蟹
                configID      = 59;
                monsterNumber = 1;
                break;

            case 60:     //河道蟹
                configID      = 60;
                monsterNumber = 1;
                break;

            case 61:     //大Boss
                configID      = 61;
                monsterNumber = 1;
                break;

            case 62:     //小Boss
                configID      = 62;
                monsterNumber = 1;
                break;

            case 63:     //鸟
                configID      = 63;
                monsterNumber = 1;
                break;

            case 64:     //红buff
                configID      = 64;
                monsterNumber = 1;
                break;

            case 65:     //熊
                configID      = 65;
                monsterNumber = 3;
                break;

            case 68:     //狼
                configID      = 68;
                monsterNumber = 2;
                break;

            case 70:     //蓝Buff
                configID      = 70;
                monsterNumber = 1;
                break;

            case 71:     //蜥蜴
                configID      = 71;
                monsterNumber = 2;
                break;

            default:
                throw new Exception("未知野怪点");
            }

            for (int i = 0; i < monsterNumber; i++)
            {
                if (i == 12)
                {
                    continue;
                }

                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + configID);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
            }
        }