public static async Task <PlayerBaseInfo> addPlayerBaseInfo(long uid, string Phone, string name, string head) { DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); ConfigComponent configCom = Game.Scene.GetComponent <ConfigComponent>(); AccountInfo accountInfo = await DBCommonUtil.getAccountInfo(uid); List <PlayerBaseInfo> playerBaseInfos = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{uid}}}"); if (playerBaseInfos.Count > 0) { return(playerBaseInfos[0]); } PlayerBaseInfo playerBaseInfo = ComponentFactory.CreateWithId <PlayerBaseInfo>(IdGenerater.GenerateId()); playerBaseInfo.Id = uid; if (string.IsNullOrEmpty(name)) { playerBaseInfo.Name = uid.ToString(); } else { List <PlayerBaseInfo> playerBaseInfos_temp = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{Name:'{name}'}}"); // 昵称已经有人用了 if (playerBaseInfos_temp.Count > 0) { playerBaseInfo.Name = (name + uid.ToString().Substring(6)); } playerBaseInfo.Name = name; } if (string.IsNullOrEmpty(head)) { int random = Common_Random.getRandom(1, 5); //百分之五十的概率随机生成男生或女生头像 int rate = Common_Random.getRandom(1, 100); if (rate <= 50) { playerBaseInfo.Icon = $"f_icon{random}"; } else { playerBaseInfo.Icon = $"m_icon{random}"; } } else { playerBaseInfo.Icon = head; } if (accountInfo != null) { accountInfo.Phone = Phone; } else { Log.Error("addPlayerBaseInfo() accountInfo==null uid = " + uid); } playerBaseInfo.PlayerSound = Common_Random.getRandom(1, 4); await proxyComponent.Save(playerBaseInfo); await proxyComponent.Save(accountInfo); Log.Debug("增加新用户完毕"); //// 插入任务数据 //{ // Log.Debug("增加新用户任务"); // for (int i = 1; i < configCom.GetAll(typeof(TaskConfig)).Length + 1; ++i) // { // int id = 100 + i; // TaskConfig config = (TaskConfig) configCom.Get(typeof(TaskConfig), id); // TaskProgressInfo progress = // ComponentFactory.CreateWithId<TaskProgressInfo>(IdGenerater.GenerateId()); // progress.IsGet = false; // progress.UId = uid; // progress.Name = config.Name; // progress.TaskId = (int) config.Id; // progress.IsComplete = false; // progress.Target = config.Target; // progress.Reward = config.Reward; // progress.Desc = config.Desc; // progress.CurProgress = 0; // await proxyComponent.Save(progress); // } // Log.Debug("增加新用户任务完毕"); //} //插入新用户成就 //{ // Log.Debug("增加新用户成就"); // for (int i = 1; i < configCom.GetAll(typeof(ChengjiuConfig)).Length + 1; ++i) // { // int id = 100 + i; // ChengjiuConfig config = (ChengjiuConfig) configCom.Get(typeof(ChengjiuConfig), id); // ChengjiuInfo chengjiu = ComponentFactory.CreateWithId<ChengjiuInfo>(IdGenerater.GenerateId()); // chengjiu.IsGet = false; // chengjiu.UId = uid; // chengjiu.Name = config.Name; // chengjiu.TaskId = (int) config.Id; // chengjiu.IsComplete = false; // chengjiu.Target = config.Target; // chengjiu.Reward = config.Reward; // chengjiu.Desc = config.Desc; // chengjiu.CurProgress = 0; // await proxyComponent.Save(chengjiu); // } // Log.Debug("增加新用户成就完毕"); //} return(playerBaseInfo); }
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; //类型 } }
public static async Task Log_Login(long uid, Session session, string clientVersion) { DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); ConfigComponent configCom = Game.Scene.GetComponent <ConfigComponent>(); List <Log_Login> log_Logins = await proxyComponent.QueryJson <Log_Login>( $"{{CreateTime:/^{DateTime.Now.GetCurrentDay()}/,Uid:{uid}}}"); if (log_Logins.Count == 0) { // 今天第一天登录,做一些处理 Log.Debug("今天第一天登录"); // 重置转盘次数 { List <PlayerBaseInfo> playerBaseInfos = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{uid}}}"); if (playerBaseInfos.Count > 0) { playerBaseInfos[0].ZhuanPanCount = 0; if (playerBaseInfos[0].VipTime.CompareTo(CommonUtil.getCurTimeNormalFormat()) > 0) { playerBaseInfos[0].ZhuanPanCount = 1; } //重置赠送好友房钥匙 playerBaseInfos[0].IsGiveFriendKey = false; await proxyComponent.Save(playerBaseInfos[0]); } else { Log.Warning($"玩家{uid}的PlayerBaseInfo为null"); } } // 重置任务 { List <TaskProgressInfo> progressList = await proxyComponent.QueryJson <TaskProgressInfo>($"{{UId:{uid}}}"); if (progressList.Count > 0) { for (int i = 0; i < progressList.Count; ++i) { progressList[i].IsGet = false; progressList[i].IsComplete = false; progressList[i].CurProgress = 0; await proxyComponent.Save(progressList[i]); } } } //重置每天在线时长和宝箱次数 { List <GamerInfoDB> gamerInfo = await proxyComponent.QueryJson <GamerInfoDB>($"{{UId:{uid}}}"); if (gamerInfo.Count > 0) { gamerInfo[0].DailyOnlineTime = 0; gamerInfo[0].DailyTreasureCount = 0; await proxyComponent.Save(gamerInfo[0]); } } } Log_Login log_Login = ComponentFactory.CreateWithId <Log_Login>(IdGenerater.GenerateId()); log_Login.Uid = uid; log_Login.ip = session.RemoteAddress.ToString(); log_Login.clientVersion = clientVersion; await proxyComponent.Save(log_Login); }
protected override async ETTask Run(ETModel.Session session, M2C_CreateUnits message) { UnitComponent unitComponent = ETModel.Game.Scene.GetComponent <UnitComponent>(); foreach (UnitInfo unitInfo in message.Units) { //TODO 暂时先忽略除英雄之外的Unit(如技能碰撞体),后期需要配表来解决这一块的逻辑,并且需要在协议里指定Unit的类型Id(注意不是运行时的Id,是Excel表中的类型Id) //TODO 诺手UnitTypeId暂定10001 if (unitComponent.Get(unitInfo.UnitId) != null || unitInfo.UnitTypeId != 10001) { continue; } //根据不同名称和ID,创建英雄 Unit unit = UnitFactory.CreateHero("NuoKe", unitInfo.UnitId); //因为血条需要,创建热更层unit HotfixUnit hotfixUnit = HotfixUnitFactory.CreateHotfixUnit(unit, true); hotfixUnit.AddComponent <FallingFontComponent>(); unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z); 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(); //Log.Info("行为树创建完成"); //添加英雄数据 M2C_GetHeroDataResponse M2C_GetHeroDataResponse = await Game.Scene.GetComponent <SessionComponent>() .Session.Call(new C2M_GetHeroDataRequest() { UnitID = unitInfo.UnitId }) as M2C_GetHeroDataResponse; ETModel.Game.Scene.GetComponent <UnitComponent>().Get(unitInfo.UnitId) .AddComponent <HeroDataComponent, long>(M2C_GetHeroDataResponse.HeroDataID); // 创建头顶Bar Game.EventSystem.Run(EventIdType.CreateHeadBar, unitInfo.UnitId); // 挂载头顶Bar hotfixUnit.AddComponent <HeroHeadBarComponent, Unit, FUI>(unit, Game.Scene.GetComponent <FUIComponent>().Get(unitInfo.UnitId)); } if (ETModel.Game.Scene.GetComponent <UnitComponent>().MyUnit == null) { // 给自己的Unit添加引用 ETModel.Game.Scene.GetComponent <UnitComponent>().MyUnit = ETModel.Game.Scene.GetComponent <UnitComponent>().Get(PlayerComponent.Instance.MyPlayer.UnitId); ETModel.Game.Scene.GetComponent <UnitComponent>().MyUnit .AddComponent <CameraComponent, Unit>(ETModel.Game.Scene.GetComponent <UnitComponent>().MyUnit); Game.EventSystem.Run(EventIdType.EnterMapFinish); } //ETModel.Log.Info($"{DateTime.UtcNow}完成一次创建Unit"); await ETTask.CompletedTask; }