Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace TroZenA.Database
- {
- using TroZenA;
- using TroZenA.Game;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- public static class JiangHu
- {
- public static Dictionary<ushort, Atribut> Atributes = new Dictionary<ushort, Atribut>();
- public static Dictionary<byte, List<byte>> CultivateStatus = new Dictionary<byte, List<byte>>();
- private static byte[] FreeCourse = new byte[] { 10, 20, 0x1a, 0x1f, 0x34 };
- private static ushort[] FreeCourseInCastle = new ushort[] { 0x126, 0x271, 0x341, 0x3e8, 0x61a };
- public static bool fullload = false;
- private static ushort[] GetPoints = new ushort[] { 100, 120, 150, 200, 300, 500 };
- private static double[] MinutesInCastle = new double[] { 31.25, 31.25, 32.0, 32.2, 30.0 };
- private static ushort[] MinutesOnTalent = new ushort[] { 0x3e8, 500, 0x180, 0x142, 0xc0 };
- private static ushort[] GetAlignmentExtraPoints = new ushort[9] { 0, 10, 13, 15, 18, 21, 25, 30, 50 };
- public static ushort AlignmentExtraPoints(byte amount)
- {
- return GetAlignmentExtraPoints[Math.Min(8, (int)amount)];
- }
- public static ushort GetFreeCourse(byte Talent)
- {
- if (Talent == 0)
- {
- Talent = 1;
- }
- return FreeCourse[Math.Min(4, Talent - 1)];
- }
- public static ushort GetFreeCourseInCastle(byte Talent)
- {
- if (Talent == 0)
- {
- Talent = 1;
- }
- return FreeCourseInCastle[Math.Min(4, Talent - 1)];
- }
- public static double GetMinutesInCastle(byte Talent)
- {
- if (Talent == 0)
- {
- Talent = 1;
- }
- return MinutesInCastle[Math.Min(4, Talent - 1)];
- }
- public static ushort GetMinutesOnTalent(byte Talent)
- {
- if (Talent == 0)
- {
- Talent = 1;
- }
- return MinutesOnTalent[Math.Min(4, Talent - 1)];
- }
- public static ushort GetPower(ushort UID)
- {
- if (Atributes.ContainsKey(UID))
- {
- return Atributes[UID].Power;
- }
- return 0;
- }
- public static ushort GetStatusPoints(byte Level)
- {
- if (Level == 0)
- {
- Level = 1;
- }
- return GetPoints[Math.Min(5, Level - 1)];
- }
- public static void LoadStatus()
- {
- try
- {
- TroZenA.Database.Read read;
- uint count;
- uint num2;
- string[] strArray;
- using (read = new TroZenA.Database.Read(@"database\JianghuAttributes.txt"))
- {
- if (read.Reader(true))
- {
- count = (uint)read.Count;
- for (num2 = 0; num2 < count; num2++)
- {
- strArray = read.ReadString("").Split(new char[] { ' ' });
- Atribut atribut = new Atribut
- {
- Type = byte.Parse(strArray[1]),
- Level = byte.Parse(strArray[2]),
- Power = ushort.Parse(strArray[3])
- };
- if (((atribut.Type == 10) || (atribut.Type == 11)) || (atribut.Type == 12))
- {
- atribut.Power = (ushort)(atribut.Power * 10);
- }
- ushort key = ValueToRoll(atribut.Type, atribut.Level);
- Atributes.Add(key, atribut);
- }
- }
- }
- using (read = new TroZenA.Database.Read(@"database\JingHuCultivateStatus.txt"))
- {
- if (read.Reader(true))
- {
- count = (uint)read.Count;
- for (num2 = 0; num2 < count; num2++)
- {
- strArray = read.ReadString("").Split(new char[] { ' ' });
- byte num4 = byte.Parse(strArray[0]);
- byte num5 = byte.Parse(strArray[1]);
- List<byte> list = new List<byte>();
- for (byte i = 0; i < num5; i = (byte)(i + 1))
- {
- list.Add(byte.Parse(strArray[2 + i]));
- }
- CultivateStatus.Add(num4, list);
- }
- }
- }
- }
- catch (Exception exception)
- {
- TroZenA.Console.WriteLine(exception.ToString());
- }
- }
- public static void LoadJiangHuOLD()
- {
- using (Read r = new Read("database\\JiangHu.txt"))
- {
- if (r.Reader())
- {
- int count = r.Count;
- for (uint x = 0; x < count; x++)
- {
- string data = r.ReadString("");
- if (data != null)
- {
- Game.JiangHu jiang = new Game.JiangHu(0);
- jiang.Load(data);
- Game.JiangHu.JiangHuClients.TryAdd(jiang.UID, jiang);
- Game.JiangHu.JiangHuRanking.UpdateRank(jiang);
- }
- }
- }
- }
- }
- public static void LoadJiangHu()
- {
- if (System.IO.File.Exists("database\\JiangHu.txt"))
- {
- LoadJiangHuOLD();
- foreach (var ijiang in Game.JiangHu.JiangHuClients.Values)
- {
- var jiang = ijiang as Game.JiangHu;
- if (jiang != null)
- {
- if (jiang.UID == 0)
- continue;
- using (var cmd = new MySqlCommand(MySqlCommandType.SELECT))
- {
- cmd.Select("jiang").Where("UID", jiang.UID);
- using (MySqlReader rdr = new MySqlReader(cmd))
- {
- if (!rdr.Read())
- {
- using (var command = new MySqlCommand(MySqlCommandType.INSERT))
- {
- command.Insert("jiang").Insert("UID", jiang.UID).Insert("OwnName", jiang.OwnName);
- command.Execute();
- }
- }
- }
- }
- }
- }
- SaveJiangHu();
- System.IO.File.Delete("database\\JiangHu.txt");
- }
- else
- {
- using (var cmd = new MySqlCommand(MySqlCommandType.SELECT))
- {
- cmd.Select("jiang");
- using (MySqlReader rdr = new MySqlReader(cmd))
- {
- while (rdr.Read())
- {
- Game.JiangHu jiang = new Game.JiangHu(0);
- jiang.UID = rdr.ReadUInt32("UID");
- jiang.OwnName = rdr.ReadString("OwnName");
- jiang.CustomizedName = rdr.ReadString("CustomizedName");
- byte[] data = rdr.ReadBlob("Powers");
- if (data.Length > 0)
- {
- using (var stream = new System.IO.MemoryStream(data))
- using (var reader = new System.IO.BinaryReader(stream))
- {
- jiang.Deserialize(reader);
- }
- }
- Game.JiangHu.JiangHuClients.TryAdd(jiang.UID, jiang);
- jiang.CreateStatusAtributes(null);
- }
- }
- }
- }
- }
- public static void New(Client.GameClient client)
- {
- if (client.Entity.MyJiang == null)
- return;
- using (var cmd = new MySqlCommand(MySqlCommandType.SELECT))
- {
- cmd.Select("jiang").Where("UID", client.Entity.UID);
- using (MySqlReader rdr = new MySqlReader(cmd))
- {
- if (!rdr.Read())
- {
- using (var command = new MySqlCommand(MySqlCommandType.INSERT))
- {
- command.Insert("jiang").Insert("UID", client.Entity.UID).Insert("CustomizedName", client.Entity.MyJiang.CustomizedName).Insert("OwnName", client.Entity.MyJiang.OwnName);
- command.Execute();
- }
- }
- }
- }
- }
- public static void SaveJiangHu()
- {
- foreach (var ijiang in Game.JiangHu.JiangHuClients.Values)
- {
- var jiang = ijiang as Game.JiangHu;
- if (jiang != null)
- {
- if (jiang.UID == 0)
- continue;
- try
- {
- MemoryStream stream = new MemoryStream();
- BinaryWriter writer = new BinaryWriter(stream);
- (jiang as Game.JiangHu).Serialize(writer);
- ///////////
- string SQL = "UPDATE `jiang` SET Powers=@Powers,OwnName=@OwnName,CustomizedName=@CustomizedName where UID = " + jiang.UID + " ;";
- byte[] rawData = stream.ToArray();
- using (var conn = DataHolder.MySqlConnection)
- {
- conn.Open();
- using (var cmd = new MySql.Data.MySqlClient.MySqlCommand())
- {
- cmd.Connection = conn;
- cmd.CommandText = SQL;
- cmd.Parameters.AddWithValue("@Powers", rawData);
- cmd.Parameters.AddWithValue("@OwnName", jiang.OwnName);
- cmd.Parameters.AddWithValue("@CustomizedName", jiang.CustomizedName);
- cmd.ExecuteNonQuery();
- }
- }
- }
- catch (Exception e)
- {
- System.Console.WriteLine(e);
- }
- }
- }
- }
- public static void SaveJiangHu(Client.GameClient client)
- {
- try
- {
- MemoryStream stream = new MemoryStream();
- BinaryWriter writer = new BinaryWriter(stream);
- client.Entity.MyJiang.Serialize(writer);
- ///////////
- string SQL = "UPDATE `jiang` SET Powers=@Powers,OwnName=@OwnName,CustomizedName=@CustomizedName where UID = " + client.Entity.UID + " ;";
- byte[] rawData = stream.ToArray();
- using (var conn = DataHolder.MySqlConnection)
- {
- conn.Open();
- using (var cmd = new MySql.Data.MySqlClient.MySqlCommand())
- {
- cmd.Connection = conn;
- cmd.CommandText = SQL;
- cmd.Parameters.AddWithValue("@Powers", rawData);
- cmd.Parameters.AddWithValue("@OwnName", client.Entity.MyJiang.OwnName);
- cmd.Parameters.AddWithValue("@CustomizedName", client.Entity.MyJiang.CustomizedName);
- cmd.ExecuteNonQuery();
- }
- }
- }
- catch (Exception e)
- {
- System.Console.WriteLine(e);
- }
- }
- public static ushort ValueToRoll(byte typ, byte level)
- {
- return (ushort)(typ + (level * 0x100));
- }
- public class Atribut
- {
- public byte Level;
- public ushort Power;
- public byte Type;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement