/// <summary> 开始游戏回调 </summary> private void OnBtnBeginGameClick() { if (m_IsSelectRoleView) { RoleCreateRequestProto proto = new RoleCreateRequestProto(); proto.JobId = (byte)m_SelectJobId; proto.RoleName = m_SelectRoleView.IFNickName.text; if (string.IsNullOrEmpty(proto.RoleName)) { TipsUtil.ShowTextTips(1000306); return; } NetWorkSocket.Instance.SendMsg(proto.ToArray()); } else { if (!m_IsHaveRole) { RoleCreateRequestProto proto = new RoleCreateRequestProto(); proto.JobId = (byte)m_SelectJobId; proto.RoleName = m_SelectRoleView.IFNickName.text; if (string.IsNullOrEmpty(proto.RoleName)) { TipsUtil.ShowTextTips(1000306); return; } NetWorkSocket.Instance.SendMsg(proto.ToArray()); } else { EnterGame(); } } }
public static RoleCreateRequestProto GetProto(byte[] buffer) { RoleCreateRequestProto proto = new RoleCreateRequestProto(); using (MMO_MemoryStream ms = new MMO_MemoryStream(buffer)) { proto.JobId = (byte)ms.ReadByte(); proto.RoleName = ms.ReadUTF8String(); } return(proto); }
/// <summary> 客户端请求创建角色 </summary> /// <param name="role"></param> /// <param name="buffer"></param> private void OnRoleCreate(Role role, byte[] buffer) { RoleCreateRequestProto proto = RoleCreateRequestProto.GetProto(buffer); //查询昵称是否存在 int count = RoleCacheModel.Instance.GetCount(string.Format("[NickName]='{0}'", proto.RoleName)); MFReturnValue <object> retValue = null; if (count > 0) { //角色名已经存 retValue = new MFReturnValue <object>(); retValue.HasError = true; } else { RoleEntity entity = new RoleEntity(); entity.JobId = proto.JobId; entity.NickName = proto.RoleName; entity.Status = Mmcoy.Framework.AbstractBase.EnumEntityStatus.Released; entity.AccountId = role.AccountId; entity.CreateTime = DateTime.Now; entity.UpdateTime = DateTime.Now; entity.Level = 1; //给角色战斗相关的属性赋值(根据 职业 等级) JobEntity jobEntity = JobDBModel.Instance.Get(entity.JobId); JobLevelEntity jobLevelEntity = JobLevelDBModel.Instance.Get(entity.Level); entity.Attack = (int)Math.Round(jobLevelEntity.Attack * (jobEntity.AttackCoefficient * 0.01f)); entity.AttackAddition = 0; entity.Defense = (int)Math.Round(jobLevelEntity.Defense * jobEntity.DefenseCoefficient * 0.01f); entity.DefenseAddition = 0; entity.Res = (int)Math.Round(jobEntity.ResCoefficient * jobLevelEntity.Res * 0.01f); entity.ResAddition = 0; entity.Hit = (int)Math.Round(jobEntity.HitCoefficient * jobLevelEntity.Hit * 0.01f); entity.HitAddition = 0; entity.Cri = (int)Math.Round(jobEntity.CriCoefficient * jobLevelEntity.Cri * 0.01f); entity.CriAddition = 0; entity.Dodge = (int)Math.Round(jobEntity.DodgeCoefficient * jobLevelEntity.Dodge * 0.01f); entity.DodgeAddition = 0; entity.CurrHP = entity.MaxHP = jobLevelEntity.HP; entity.CurrMP = entity.MaxMP = jobLevelEntity.MP; entity.Fighting = FightingUtil.GetRoleFighting(entity.MaxHP, entity.Attack, 0, entity.Defense, 0, entity.Res, 0, entity.Hit, 0, entity.Dodge, 0, entity.Cri, 0); entity.FightingAddition = 0; entity.LastInWorldMapId = 1; retValue = RoleCacheModel.Instance.Create(entity); Console.WriteLine(retValue.ReturnCode + " " + retValue.OutputValues["Id"] + " " + retValue.Message); } OnRoleCreateResponse(role, retValue); }