Exemple #1
0
 /// <summary>
 /// 类型:方法
 /// 名称:Character
 /// 作者:taixihuase
 /// 作用:通过已有的角色信息构造一个新的角色实例
 /// 编写日期:2015/8/20
 /// </summary>
 /// <param name="character"></param>
 public Character(Character character)
     : base(character.Guid, character.Account, character.UniqueId, character.Nickname, character.Status)
 {
     WorldEnterTime = character.WorldEnterTime;
     Position = character.Position;
     Experience = character.Experience;
     Occupation = character.Occupation;
     Weapons = character.Weapons;
     Armors = character.Armors;
     Jewels = character.Jewels;
     Skills = character.Skills;
     Attribute = new CharacterAttribute();
     Type type = character.Attribute.GetType();
     var pi = type.GetProperties();
     foreach (var info in pi)
     {
         info.SetValue(Attribute, info.GetValue(character.Attribute, null), null);
     }
 }
 /// <summary>
 /// 类型:方法
 /// 名称:GetCharacterOriginalFromNickName
 /// 作者:taixihuase
 /// 作用:通过昵称获取用户初始信息
 /// 编写日期:2015/7/22
 /// </summary>
 /// <param name="nickName"></param>
 /// <param name="character"></param>
 /// <returns></returns>
 public bool GetCharacterOriginalFromNickname(string nickName, out Character character)
 {
     int id = Server.Users.GetUniqueIdFromNickname(nickName);
     if (id >= 0 && UniqueIdToCharacterOriginal.ContainsKey(id))
     {
         return GetCharacterOriginal(id, out character);
     }
     character = null;
     return false;
 }
 /// <summary>
 /// 类型:方法
 /// 名称:GetCharacterOriginal
 /// 作者:taixihuase
 /// 作用:通过编号获取角色初始信息
 /// 编写日期:2015/7/22
 /// </summary>
 /// <param name="uniqueId"></param>
 /// <param name="character"></param>
 /// <returns></returns>
 public bool GetCharacterOriginal(int uniqueId, out Character character)
 {
     return UniqueIdToCharacterOriginal.TryGetValue(uniqueId, out character);
 }
 /// <summary>
 /// 类型:方法
 /// 名称:GetCharacterCopy
 /// 作者:taixihuase
 /// 作用:通过编号获取角色加成信息
 /// 编写日期:2015/8/20
 /// </summary>
 /// <param name="uniqueId"></param>
 /// <param name="character"></param>
 /// <returns></returns>
 public bool GetCharacterCopy(int uniqueId, out Character character)
 {
     return UniqueIdToCharacterCopy.TryGetValue(uniqueId, out character);
 }
 public bool CharacterLoad(Character character)
 {
     lock (this)
     {
         if (!UniqueIdToCharacterOriginal.ContainsKey(character.UniqueId))
         {
             UniqueIdToCharacterOriginal.Add(character.UniqueId, character);
             return true;
         }
         return false;
     }
 }
 /// <summary>
 /// 类型:方法
 /// 名称:CharacterEnter
 /// 作者:taixihuase
 /// 作用:添加一个角色连接
 /// 编写日期:2015/7/22
 /// </summary>
 /// <param name="uniqueId"></param>
 /// <param name="copy"></param>
 /// <returns></returns>
 public bool CharacterEnter(int uniqueId, out Character copy)
 {
     lock (this)
     {
         Character original;
         if (GetCharacterOriginal(uniqueId, out original))
         {
             original.WorldEnterTime = DateTime.Now;
             original.Status = UserInfo.StatusType.Gaming;
             copy = new Character(original);
             copy.ApplyEquipments();
             UniqueIdToCharacterCopy.Add(copy.UniqueId, copy);
             AddGamingCharacter(Server.Users.TryGetPeer(copy.Guid));
             return true;
         }
         copy = null;
         return false;
     }
 }
Exemple #7
0
        /// <summary>
        /// 类型:方法
        /// 名称:UpdateCharacterAttribute
        /// 作者:taixihuase
        /// 作用:更新一条装备属性对角色属性的作用效果
        /// 编写日期:2015/8/19
        /// </summary>
        /// <param name="character"></param>
        /// <param name="attribute"></param>
        /// <param name="activated"></param>
        protected void UpdateCharacterAttribute(Character.Character character, KeyValuePair<AttributeCode, float> attribute, bool activated)
        {
            int sign = activated ? 1 : -1;

            float f = attribute.Value;
            int i = Convert.ToInt32(f);

            switch (attribute.Key)
            {
                case AttributeCode.Null:

                    break;

                    #region 特殊命名格式的属性值改变

                case AttributeCode.Attack_Both:
                    character.Attribute.AttackPhysicalMin += i*sign;
                    character.Attribute.AttackPhysicalMax += i*sign;
                    if (character.Attribute.AttackPhysicalMin <= 0)
                    {
                        character.Attribute.AttackPhysicalMin = 0;
                    }
                    if (character.Attribute.AttackPhysicalMax <= 0)
                    {
                        character.Attribute.AttackPhysicalMax = 0;
                    }
                    character.Attribute.AttackMagicMin += i*sign;
                    character.Attribute.AttackMagicMax += i*sign;
                    if (character.Attribute.AttackMagicMin <= 0)
                    {
                        character.Attribute.AttackMagicMin = 0;
                    }
                    if (character.Attribute.AttackMagicMax <= 0)
                    {
                        character.Attribute.AttackMagicMax = 0;
                    }
                    break;

                case AttributeCode.Attack_Magic:
                    character.Attribute.AttackMagicMin += i*sign;
                    character.Attribute.AttackMagicMax += i*sign;
                    if (character.Attribute.AttackMagicMin <= 0)
                    {
                        character.Attribute.AttackMagicMin = 0;
                    }
                    if (character.Attribute.AttackMagicMax <= 0)
                    {
                        character.Attribute.AttackMagicMax = 0;
                    }
                    break;

                case AttributeCode.Attack_Physical:
                    character.Attribute.AttackPhysicalMin += i*sign;
                    character.Attribute.AttackPhysicalMax += i*sign;
                    if (character.Attribute.AttackPhysicalMin <= 0)
                    {
                        character.Attribute.AttackPhysicalMin = 0;
                    }
                    if (character.Attribute.AttackPhysicalMax <= 0)
                    {
                        character.Attribute.AttackPhysicalMax = 0;
                    }
                    break;

                case AttributeCode.Attack_Percent_Both:
                    character.Attribute.AttackPercentPhysical += f*sign;
                    if (character.Attribute.AttackPercentPhysical <= 0)
                    {
                        character.Attribute.AttackPercentPhysical = 0;
                    }
                    character.Attribute.AttackPercentMagic += f*sign;
                    if (character.Attribute.AttackPercentMagic <= 0)
                    {
                        character.Attribute.AttackPercentMagic = 0;
                    }
                    break;

                case AttributeCode.Attack_Percent_Physical:
                    character.Attribute.AttackPercentPhysical += f*sign;
                    if (character.Attribute.AttackPercentPhysical <= 0)
                    {
                        character.Attribute.AttackPercentPhysical = 0;
                    }
                    break;

                case AttributeCode.Attack_Percent_Magic:
                    character.Attribute.AttackPercentMagic += f*sign;
                    if (character.Attribute.AttackPercentMagic <= 0)
                    {
                        character.Attribute.AttackPercentMagic = 0;
                    }
                    break;

                case AttributeCode.Defense_Both:
                    character.Attribute.DefensePhysicalBase += i*sign;
                    if (character.Attribute.DefensePhysicalBase <= 0)
                    {
                        character.Attribute.DefensePhysicalBase = 0;
                    }
                    character.Attribute.DefenseMagicBase += i*sign;
                    if (character.Attribute.DefenseMagicBase <= 0)
                    {
                        character.Attribute.DefenseMagicBase = 0;
                    }
                    break;

                case AttributeCode.Defense_Physical:
                    character.Attribute.DefensePhysicalBase += i*sign;
                    if (character.Attribute.DefensePhysicalBase <= 0)
                    {
                        character.Attribute.DefensePhysicalBase = 0;
                    }
                    break;

                case AttributeCode.Defense_Magic:
                    character.Attribute.DefenseMagicBase += i*sign;
                    if (character.Attribute.DefenseMagicBase <= 0)
                    {
                        character.Attribute.DefenseMagicBase = 0;
                    }
                    break;

                case AttributeCode.Defense_Percent_Both:
                    character.Attribute.DefensePercentPhysical += f*sign;
                    if (character.Attribute.DefensePercentPhysical <= 0)
                    {
                        character.Attribute.DefensePercentPhysical = 0;
                    }
                    character.Attribute.DefensePercentMagic += f*sign;
                    if (character.Attribute.DefensePercentMagic <= 0)
                    {
                        character.Attribute.DefensePercentMagic = 0;
                    }
                    break;

                case AttributeCode.Defense_Percent_Physical:
                    character.Attribute.DefensePercentPhysical += f*sign;
                    if (character.Attribute.DefensePercentPhysical <= 0)
                    {
                        character.Attribute.DefensePercentPhysical = 0;
                    }
                    break;

                case AttributeCode.Defense_Percent_Magic:
                    character.Attribute.DefensePercentMagic += f*sign;
                    if (character.Attribute.DefensePercentMagic <= 0)
                    {
                        character.Attribute.DefensePercentMagic = 0;
                    }
                    break;

                case AttributeCode.Life_Increase:
                    character.Attribute.HitPointBase += i*sign;
                    if (character.Attribute.HitPointBase <= 0)
                    {
                        character.Attribute.HitPointBase = 0;
                    }
                    break;

                case AttributeCode.Mana_Increase:
                    character.Attribute.ManaBase += i*sign;
                    if (character.Attribute.ManaBase <= 0)
                    {
                        character.Attribute.ManaBase = 0;
                    }
                    break;

                    #endregion

                    #region 根据枚举名反射改变属性值

                default:
                {
                    string code = attribute.Key.ToString().Replace("_", "");
                    Type type = typeof (CharacterAttribute);

                    if (code.Contains("Both"))
                    {
                        string physical = code.Replace("Both", "Physical");
                        var pi = type.GetProperty(physical);
                        float pv = (float) pi.GetValue(character.Attribute, null);
                        pv += f*sign;
                        if (pv <= 0)
                        {
                            pv = 0;
                        }
                        pi.SetValue(character.Attribute, pv, null);

                        string magic = code.Replace("Both", "Magic");
                        pi = type.GetProperty(magic);
                        float mv = (float) pi.GetValue(character.Attribute, null);
                        mv += f*sign;
                        if (mv <= 0)
                        {
                            mv = 0;
                        }
                        pi.SetValue(character.Attribute, mv, null);
                    }
                    else if (code.Contains("All"))
                    {
                        string attr = code.Replace("All", "");
                        var pi = type.GetProperties().Where(x => x.Name.StartsWith(attr));
                        foreach (var propertyInfo in pi)
                        {
                            int newv = (int) propertyInfo.GetValue(character.Attribute, null);
                            newv += i*sign;
                            if (newv <= 0)
                            {
                                newv = 0;
                            }
                            propertyInfo.SetValue(character.Attribute, newv, null);
                        }
                    }
                    else
                    {
                        var pi = type.GetProperty(code);
                        var t = pi.PropertyType;
                        if (t == typeof (int))
                        {
                            int newv = (int) pi.GetValue(character.Attribute, null);
                            newv += i*sign;
                            if (newv <= 0)
                            {
                                newv = 0;
                            }
                            pi.SetValue(character.Attribute, newv, null);
                        }
                        else if (t == typeof (float))
                        {
                            float newv = (float) pi.GetValue(character.Attribute, null);
                            newv += f*sign;
                            if (newv <= 0)
                            {
                                newv = 0;
                            }
                            pi.SetValue(character.Attribute, newv, null);
                        }
                    }
                    break;
                }

                    #endregion
            }
        }
Exemple #8
0
 public void SetCharacterCopy(Character copy)
 {
     CharacterCopy = new Character(copy);
 }
Exemple #9
0
        /// <summary>
        /// 类型:方法
        /// 名称:LoadCharacter
        /// 作者:taixihuase
        /// 作用:当成功获取到角色数据时触发加载角色事件
        /// 编写日期:2015/7/29
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="character"></param>
        /// <returns></returns>
        private IEnumerator LoadCharacter(object sender, Character character)
        {
            LoadCharacter load;
            while ((load = FindObjectOfType<LoadCharacter>()) == null)
            {
                yield return null;
            }
            LoadCharacterEventArgs lc = new LoadCharacterEventArgs(character);
            load.OnLoad(sender, lc);

            Destroy(transform.parent.gameObject);
        }
Exemple #10
0
        /// <summary>
        /// 类型:方法
        /// 名称:TryLogin
        /// 作者:taixihuase
        /// 作用:通过登录数据尝试登录
        /// 编写日期:2015/7/14
        /// </summary>
        /// <param name="operationRequest"></param>
        /// <param name="sendParameters"></param>
        /// <param name="peer"></param>
        private static void TryLogin(OperationRequest operationRequest, SendParameters sendParameters, ServerPeer peer)
        {
            ServerPeer.Log.Debug("Logining...");

            LoginInfo login = (LoginInfo)
                Serialization.Deserialize(operationRequest.Parameters[(byte) ParameterCode.Login]);

            #region 对账号密码进行判断

            ServerPeer.Log.Debug(DateTime.Now + " : Loginning...");
            ServerPeer.Log.Debug(login.Account);
            ServerPeer.Log.Debug(login.Password);

            // 获取用户资料
            UserInfo user = new UserInfo(peer.PeerGuid, login.Account);
            UserCollection.UserReturn userReturn = peer.Server.Users.UserOnline(user, login.Password);

            // 若成功取得用户资料
            if (userReturn.ReturnCode == UserCollection.UserReturn.ReturnCodeType.Success)
            {
                ServerPeer.Log.Debug(user.LoginTime + " :User " + user.Nickname + " loginning...");

                // 用于选择的数据返回参数
                var parameter = new Dictionary<byte, object>();

                // 用于选择的字符串信息
                string message = "";

                // 用于选择的返回值
                short returnCode = -1;

                #region 获取角色资料

                Character character = new Character(user);
                CharacterCollection.CharacterReturn characterReturn =
                    peer.Server.Characters.SearchCharacter(character);

                // 若取得角色资料
                if (characterReturn.ReturnCode == CharacterCollection.CharacterReturn.ReturnCodeType.Success)
                {
                    byte[] playerBytes = Serialization.Serialize(character);
                    parameter.Add((byte) ParameterCode.Login, playerBytes);
                    returnCode = (short) ErrorCode.Ok;
                    message = "";

                    peer.Server.Characters.CharacterLoad(character);
                }
                else if (characterReturn.ReturnCode == CharacterNotFound)
                {
                    byte[] userBytes = Serialization.Serialize(user);
                    parameter.Add((byte) ParameterCode.Login, userBytes);
                    returnCode = (short) ErrorCode.CharacterNotFound;
                    message = characterReturn.DebugMessage.ToString();
                }

                #endregion

                OperationResponse response = new OperationResponse((byte) OperationCode.Login, parameter)
                {
                    ReturnCode = returnCode,
                    DebugMessage = message
                };
                peer.SendOperationResponse(response, sendParameters);
                ServerPeer.Log.Debug(user.LoginTime + " : User " + user.Account + " logins successfully");
            }
            // 若重复登录
            else if (userReturn.ReturnCode == RepeatedLogin)
            {
                OperationResponse response = new OperationResponse((byte) OperationCode.Login)
                {
                    ReturnCode = (short) ErrorCode.RepeatedOperation,
                    DebugMessage = "账号已登录!"
                };
                peer.SendOperationResponse(response, sendParameters);
                ServerPeer.Log.Debug(DateTime.Now + " : Failed to login " + user.Account + " Because of " +
                                     Enum.GetName(typeof (UserCollection.UserReturn.ReturnCodeType),
                                         userReturn.ReturnCode));
            }
            else
            {
                // 返回非法登录错误
                OperationResponse response = new OperationResponse((byte) OperationCode.Login)
                {
                    ReturnCode = (short) ErrorCode.InvalidOperation,
                    DebugMessage = userReturn.DebugMessage.ToString()
                };
                peer.SendOperationResponse(response, sendParameters);
                ServerPeer.Log.Debug(DateTime.Now + " : Failed to login " + user.Account + " Because of " +
                                     Enum.GetName(typeof (UserCollection.UserReturn.ReturnCodeType),
                                         userReturn.ReturnCode));
            }

            #endregion
        }
        /// <summary>
        /// 类型:方法
        /// 名称:GetCharacter
        /// 作者:taixihuase
        /// 作用:尝试从数据库获取玩家游戏角色信息
        /// 编写日期:2015/7/24
        /// </summary>
        /// <param name="character"></param>
        /// <returns></returns>
        public CharacterCollection.CharacterReturn GetCharacter(Character character)
        {
            CharacterCollection.CharacterReturn characterReturn = new CharacterCollection.CharacterReturn();

            if (character.Nickname == "abcd" || character.Nickname == "efgh")
            {
                #region 测试用例

                character.Position.SetPosition(10, 20, 30);
                int[] exp = new int[DataConstraint.CharacterMaxLevel];
                exp[0] = 0;
                for (int i = 1; i < exp.Length; i++)
                {
                    exp[i] = exp[i - 1] + 10;
                }
                character.Experience.SetEachLevelDemand(exp);
                character.Experience.SetExperience(0, 0, 0, 0);
                character.Experience.GainExperience(0);

                character.Occupation.UpdateOccupation(OccupationCode.Warrior, "战士");
                character.Occupation.BaseHitPoint = 50;
                character.Occupation.BaseLifeRecovery = 5;
                character.Occupation.BaseMana = 10;
                character.Occupation.BaseManaRecovery = 1;
                character.Occupation.Apply(character.Attribute);

                Weapon w = new Weapon(1, 2, "刀", OccupationCode.Warrior | OccupationCode.Paladin, 1, true, 1,
                    DataConstraint.EquipmentMaxDurability, 0, 200, 200, Weapon.WeaponType.Null,
                    Weapon.WeaponAttackType.Physical,
                    Weapon.WeaponElementType.Null);

                character.Weapons.Add(1, w);
                w.UpdateAttackLimit(100, 200, null, null);
                w.UpdateFixedAttribute(AttributeCode.Attack_Physical, 100);
                w.UpdateFixedAttribute(AttributeCode.Attack_Percent_Both, 10);
                w.Upgrade();
                w.Upgrade();
                w.Upgrade(AttributeCode.Attack_Percent_Both, 90);
                w.UpdateElementAttribute(Weapon.WeaponElementType.Lightning);
                w.UpgradeElementAttribute(0);
                w.UpgradeElementEnhanceAttribute(300);
                w.UpgradeElementExtraAttribute(10, 2);

                Armor a = new Armor(10, 20, "头盔", OccupationCode.Warrior, 1, true, 1,
                    DataConstraint.EquipmentMaxDurability, Armor.ArmorType.Helmet);

                character.Armors.Add(1, a);
                a.UpdateDefensePoints(1000, 2000);
                a.UpdateFixedAttribute(AttributeCode.Life_Increase, 1000);
                a.Upgrade();
                a.Upgrade(AttributeCode.Life_Increase_Percent, 50);

                Jewel j = new Jewel(100, 200, "戒指", OccupationCode.Common, 1, false, 1,
                    DataConstraint.EquipmentMaxDurability, Jewel.JewelType.Ring, Jewel.JewelAttributeType.Null);

                character.Jewels.Add(1, j);
                j.UpdateFixedAttribute(AttributeCode.Resistance_All, 22222);
                j.UpdateRandomAttribute(AttributeCode.Attr_Strength, 1234);

                #endregion

                characterReturn.ReturnCode = Success;
                characterReturn.DebugMessage.Append("成功获取角色数据");
            }
            else
            {
                characterReturn.ReturnCode = CharacterNotFound;
                characterReturn.DebugMessage.Append("当前账号尚未创建角色");
            }

            return characterReturn;
        }
        /// <summary>
        /// 类型:方法
        /// 名称:SaveCharacter
        /// 作者:taixihuase
        /// 作用:向数据库提交一个玩家的角色数据
        /// 编写日期:2015/7/24
        /// </summary>
        /// <param name="character"></param>
        public void SaveCharacter(Character character)
        {

        }
        /// <summary>
        /// 类型:方法
        /// 名称:CreateNewCharacter
        /// 作者:taixihuase
        /// 作用:根据数据库资料为玩家创建一个新的角色
        /// 编写日期:2015/7/24
        /// </summary>
        /// <param name="character"></param>
        public void CreateNewCharacter(Character character)
        {
            switch (character.Occupation.Type)
            {
                case OccupationCode.Warrior:
                {
                    character.Position.SetPosition(10, 20, 30);
                    int[] exp = new int[DataConstraint.CharacterMaxLevel];
                    exp[0] = 0;
                    for (int i = 1; i < exp.Length; i++)
                    {
                        exp[i] = exp[i - 1] + 10;
                    }
                    character.Experience.SetEachLevelDemand(exp);
                    character.Experience.SetExperience(0, 0, 0, 0);
                    character.Experience.GainExperience(0);

                    character.Occupation.UpdateOccupation(OccupationCode.Warrior, "战士");
                    character.Occupation.BaseHitPoint = 50;
                    character.Occupation.BaseLifeRecovery = 5;
                    character.Occupation.BaseMana = 10;
                    character.Occupation.BaseManaRecovery = 1;
                    character.Occupation.Apply(character.Attribute);

                    break;
                }
            }

            SaveCharacter(character);
        }
 /// <summary>
 /// 类型:方法
 /// 名称:GetCharacterPosition
 /// 作者:taixihuase
 /// 作用:获取玩家游戏上次离线时的位置信息
 /// 编写日期:2015/7/24
 /// </summary>
 /// <param name="character"></param>
 public void GetCharacterPosition(Character character)
 {
     if (character.Status == UserInfo.StatusType.Gaming)
     {
         character.Position.SetPosition(10, 20, 30);
     }
 }
Exemple #15
0
 public void SetCharacterOriginal(Character original)
 {
     CharacterOriginal = new Character(original);
 }
        /// <summary>
        /// 类型:方法
        /// 名称:SearchCharacter
        /// 作者:taixihuase
        /// 作用:尝试搜索一个角色,同时返回搜索情况
        /// </summary>
        /// <param name="character"></param>
        /// <returns></returns>
        public CharacterReturn SearchCharacter(Character character)
        {
            CharacterReturn characterReturn = Server.Data.CharacterData.GetCharacter(character);

            return characterReturn;
        }
Exemple #17
0
 public virtual bool Cancel(Character.Character character)
 {
     if (IsUsing)
     {
         foreach (KeyValuePair<AttributeCode, float> attribute in FixedAttributes)
         {
             UpdateCharacterAttribute(character, attribute, false);
         }
         UpdateCharacterAttribute(character, RandomAttribute, false);
         character.Attribute.CalculateAttributes();
         IsUsing = false;
         return true;
     }
     return false;
 }
Exemple #18
0
 public void SetCharacter(Character original, Character copy)
 {
     SetUserInfo(new UserInfo(original.Guid, original.Account, original.UniqueId, original.Nickname, original.Status));
     SetCharacterOriginal(original);
     SetCharacterCopy(copy);
 }