Exemplo n.º 1
0
 void SendCharacterData(EPlayerData data, bool onlysendbag = false)
 {
     SendBag(data.Bag);
     if (!onlysendbag)
     {
         var plr = tsp.TPlayer;
         plr.statLife             = data.Life;
         plr.statLifeMax          = data.MaxLife;
         plr.statMana             = data.Mana;
         plr.statManaMax          = data.MaxMana;
         plr.SpawnX               = data.SpawnX;
         plr.SpawnY               = data.SpawnY;
         plr.skinVariant          = data.skinVariant;
         plr.hair                 = data.hair;
         plr.hairDye              = (byte)data.hairDye;
         plr.hairColor            = (Color)data.hairColor;
         plr.pantsColor           = (Color)data.pantsColor;
         plr.underShirtColor      = (Color)data.underShirtColor;
         plr.shoeColor            = (Color)data.shoeColor;
         plr.hideVisibleAccessory = data.hideVisibleAccessory;
         plr.skinColor            = (Color)data.skinColor;
         plr.eyeColor             = (Color)data.eyeColor;
         this.SendDataToAll(PacketTypes.PlayerInfo, "", Index);
         this.SendDataToAll(PacketTypes.PlayerHp, "", Index);
         this.SendDataToAll(PacketTypes.PlayerMana, "", Index);
     }
 }
Exemplo n.º 2
0
 public static async void GetAllCharacter()
 {
     await Task.Run(() =>
     {
         var reader = RunSql($"SELECT * FROM EternalLandData");
         while (reader.Read())
         {
             var t    = typeof(EPlayerData);
             var list = new List <string>();
             var data = new EPlayerData();
             try
             {
                 for (int i = 0; i < reader.Reader.FieldCount; i++)
                 {
                     list.Add(reader.Reader.GetName(i));
                 }
                 t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly).ForEach(temp =>
                 {
                     var attr = temp.GetCustomAttribute(typeof(ShouldSave), false);  //反射获得用户自定义属性
                     if (list.Contains(temp.Name))
                     {
                         Type type = temp.FieldType;
                         if (type == typeof(string))
                         {
                             temp.SetValue(data, reader.Get <string>(temp.Name));
                         }
                         else if (type == typeof(int))
                         {
                             temp.SetValue(data, reader.Get <int>(temp.Name));
                         }
                         else if (type == typeof(List <EItem>))
                         {
                             temp.SetValue(data, JsonConvert.DeserializeObject <List <EItem> >(reader.Get <string>(temp.Name)));
                         }
                         else if (type == typeof(Microsoft.Xna.Framework.Color?))
                         {
                             temp.SetValue(data, TShock.Utils.DecodeColor(reader.Get <int>(temp.Name)));
                         }
                         else if (type == typeof(bool[]))
                         {
                             temp.SetValue(data, JsonConvert.DeserializeObject <bool[]>(reader.Get <string>(temp.Name)));
                         }
                         else
                         {
                             temp.SetValue(data, reader.Get <string>(temp.Name));
                         }
                     }
                 });
             }
             catch (Exception ex) { Log.Error(ex.InnerException == null ? ex : ex.InnerException); }
             Game.GameData.Character.Add(data.Name, data);
         }
         Log.Info($"共载入 {GameData.Character.Count} 条角色数据.");
     });
 }
Exemplo n.º 3
0
 public bool ChangeCharacter(string name)
 {
     if (GameData.Character.ContainsKey(name))
     {
         TempCharacter = GameData.Character[name];
         SendCharacterData(GameData.Character[name]);
         UserManager.UpdateInfoToOtherPlayers(this);
         return(true);
     }
     else
     {
         this.SendErrorEX($"<Internal Error> 无法变更玩家角色 => 未找到名为 {name} 的角色信息.");
         return(false);
     }
 }
Exemplo n.º 4
0
 public static async void SaveCharacter(EPlayerData data)
 {
     await Task.Run(() =>
     {
         string sql = string.Empty;
         try
         {
             List <object> value = new List <object>();
             int num             = 0;
             var t     = typeof(EPlayerData);
             var field = t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
             for (int i = 0; i < field.Length; i++)
             {
                 sql += $"{(num == 0 ? "" : ",")}{field[i].Name}=@{num}";
                 if (field[i].FieldType == typeof(Microsoft.Xna.Framework.Color?))
                 {
                     value.Add(TShock.Utils.EncodeColor((Microsoft.Xna.Framework.Color?)field[i].GetValue(data)));
                 }
                 else if (field[i].FieldType == typeof(List <EItem>))
                 {
                     value.Add(JsonConvert.SerializeObject(field[i].GetValue(data)));
                 }
                 else if (field[i].FieldType == typeof(bool[]))
                 {
                     value.Add(JsonConvert.SerializeObject(field[i].GetValue(data)));
                 }
                 else
                 {
                     value.Add(field[i].GetValue(data));
                 }
                 num++;
             }
             var reader = RunSql($"REPLACE INTO EternalLandData SET {sql}", value.ToArray());
         }
         catch (Exception ex) { Log.Error((ex.InnerException == null ? ex : ex.InnerException) + $"\nSQL语句为 {sql}."); }
     });
 }
Exemplo n.º 5
0
 public void SetToOriginCharacter()
 {
     SendCharacterData(Character);
     TempCharacter = null;
     UserManager.UpdateInfoToOtherPlayers(this);
 }
Exemplo n.º 6
0
        public async static void AdminCommand(CommandArgs args)
        {
            var tsp  = args.Player;
            var eplr = tsp.EPlayer();

            if (eplr == null)
            {
                tsp.SendErrorEX("你尚未登录.");
                return;
            }
            string error = "命令無效. ";
            var    cmd   = args.Parameters;

            switch (args.Message.Split(' ')[0].ToLower())
            {
            case "/char":
                if (args.Parameters.Count >= 1)
                {
                    switch (cmd[0].ToLower())
                    {
                    case "save":
                        if (cmd.Count < 2)
                        {
                            tsp.SendErrorEX(error);
                            break;
                        }
                        else if (GameData.Character.ContainsKey(cmd[1]))
                        {
                            tsp.SendErrorEX("角色已存在. 如想更新角色信息请使用//updatecharacter <名称>");
                            break;
                        }
                        var data = new EPlayerData(tsp, cmd[1]);
                        DataBase.SaveCharacter(data);
                        GameData.Character.Add(cmd[1], data);
                        tsp.SendSuccessEX("执行完成.");
                        break;

                    case "update":
                        if (cmd.Count < 2)
                        {
                            tsp.SendErrorEX(error);
                            break;
                        }
                        else if (!GameData.Character.ContainsKey(cmd[1]))
                        {
                            tsp.SendErrorEX($"未找到角色存档: {cmd[1]}");
                            break;
                        }
                        data = new EPlayerData(tsp, cmd[1]);
                        DataBase.SaveCharacter(data);
                        GameData.Character[cmd[1]] = data;
                        tsp.SendSuccessEX("已更新角色数据.");
                        break;

                    case "turnto":
                        if (cmd.Count < 2)
                        {
                            tsp.SendErrorEX(error);
                            break;
                        }
                        else if (!GameData.Character.ContainsKey(cmd[1]))
                        {
                            tsp.SendErrorEX($"未找到角色存档: {cmd[1]}");
                            break;
                        }
                        eplr.ChangeCharacter(cmd[1]);
                        tsp.SendSuccessEX("执行完成.");
                        break;

                    case "turnback":
                        eplr.SetToOriginCharacter();
                        tsp.SendSuccessEX("执行完成.");
                        break;
                    }
                }
                break;

            case "/map":
                if (args.Parameters.Count >= 1)
                {
                    switch (cmd[0].ToLower())
                    {
                    case "set":
                        if (eplr.SettingPoint == 1 || eplr.SettingPoint == 2)
                        {
                            eplr.SendEX($"你已在进行区域{(eplr.SettingPoint == 1 ? "左上" : "右下")}角选定.");
                        }
                        else
                        {
                            eplr.SendEX($"开始进行地图区域选定. 请用任何镐子点击左上角物块.");
                            eplr.SettingPoint = 1;
                        }
                        break;

                    case "create":
                        if (cmd.Count < 2)
                        {
                            tsp.SendErrorEX(error);
                            break;
                        }
                        else if (cmd[1] == "MainWorld" || cmd[1] == "DefaultTerritory")
                        {
                            var d = new MapManager.MapData(0, 0, Main.maxTilesX, Main.maxTilesY, cmd[1]);
                            DataBase.SaveMap(cmd[1], d);
                            tsp.SendSuccessEX("执行完成.");
                            return;
                        }
                        else if (eplr.SettingPoint != 0)
                        {
                            tsp.SendErrorEX($"你正在选择第 {eplr.SettingPoint} 个点位, 无法创建地图.");
                            break;
                        }
                        else if (eplr.ChoosePoint[0] == null || eplr.ChoosePoint[1] == null)
                        {
                            tsp.SendErrorEX($"点位选择不完整, 请重新选择.");
                            break;
                        }
                        else if (GameData.Map.ContainsKey(cmd[1]))
                        {
                            tsp.SendErrorEX($"此地图名已存在. 如想更新地图请使用 {"//map update".ToColorful()}.");
                            break;
                        }
                        var data = new MapManager.MapData(eplr.ChoosePoint[0], eplr.ChoosePoint[1], cmd[1]);
                        DataBase.SaveMap(cmd[1], data);
                        tsp.SendSuccessEX("执行完成.");
                        break;

                    case "goto":
                        if (cmd.Count < 4)
                        {
                            tsp.SendErrorEX(error + ", 需包含生成到的坐标");
                            break;
                        }
                        else if (!GameData.Map.ContainsKey(cmd[1]))
                        {
                            tsp.SendErrorEX($"未找到地图: {cmd[1]}");
                            break;
                        }
                        eplr.JoinMap(MapManager.CreateMultiPlayerMap(cmd[1], int.Parse(cmd[2]), int.Parse(cmd[3])));
                        tsp.SendSuccessEX("执行完成.");
                        break;

                    case "update":
                        if (eplr.IsInAnotherWorld)
                        {
                            eplr.Map.Save();
                            eplr.SendSuccessEX("执行完成.");
                        }
                        else
                        {
                            eplr.SendErrorEX("未处于其他地图.");
                        }
                        break;

                    case "setspawn":
                        if (eplr.IsInAnotherWorld)
                        {
                            eplr.Map.SetSpawn(eplr.TileX, eplr.TileY);
                            eplr.Map.Save();
                            eplr.SendSuccessEX("执行完成.");
                        }
                        else
                        {
                            eplr.SendErrorEX("未处于其他地图.");
                        }
                        break;

                    /*case "wld":
                     *  if (cmd.Count > 2) eplr.JoinMap(MapManager.CreateMultiPlayerMap(new MapManager.MapData(2152, 394, int.Parse(cmd[1]), int.Parse(cmd[2])), 4100, 400));
                     *  else eplr.JoinMap(MapManager.CreateMultiPlayerMap(new MapManager.MapData(int.Parse(cmd[1]), int.Parse(cmd[2]), 200, 200), 4100, 450));
                     *  break;
                     * case "clear":
                     *  eplr.JoinMap(MapManager.CreateMultiPlayerMap(new MapManager.MapData(), 4100, 400));
                     *  break;*/
                    case "back":
                        eplr.BackToOriginMap();
                        break;

                    case "join":
                        if (UserManager.TryGetEPlayeFuzzy(cmd[1], out var t))
                        {
                            eplr.JoinMap(t[0].MapUUID);
                        }
                        break;
                    }
                }
                break;
            }
        }