/// <summary> /// Decrease the Durability of the active weapon of a player /// </summary> /// <param name="pc">Player</param> /// <param name="amount">Amount of durability to lose</param> public static void WeaponLoseDura(ActorPC pc, ushort amount) { ActorEventHandlers.PC_EventHandler eh = (ActorEventHandlers.PC_EventHandler)pc.e; SagaDB.Items.Weapon weapon = SagaDB.Items.WeaponFactory.GetActiveWeapon(pc); weapon.durability -= amount; eh.C.UpdateWeaponInfo(SagaMap.Packets.Server.WeaponAdjust.Function.Durability, weapon.durability); }
public static Weapon GetActiveWeapon(SagaDB.Actors.ActorPC pc) { foreach (Weapon w in pc.Weapons) { if (w.active == 1) return w; } Weapon nw = new Weapon(); nw.type = 0; return nw; }
public void CreateChar(ref ActorPC aChar, int account_id) { if (aChar.Weapons == null) { Weapon newweapon = new Weapon(); aChar.Weapons = new List<Weapon>(); newweapon.name = aChar.weaponName; newweapon.level = 1; newweapon.type = 1; newweapon.augeSkillID = 150001; newweapon.U1 = 1; newweapon.exp = 0; newweapon.durability = 1800; newweapon.active = 1; newweapon.stones = new uint[6]; aChar.Weapons.Add(newweapon); } if(aChar.ShorcutIDs == null) aChar.ShorcutIDs = new Dictionary<byte, ActorPC.Shortcut>(); if(aChar.BattleSkills==null) aChar.BattleSkills = new Dictionary<uint,SkillInfo>(); if(aChar.LivingSkills==null)aChar.LivingSkills =new Dictionary<uint,SkillInfo>(); if (aChar.SpecialSkills == null) aChar.SpecialSkills = new Dictionary<uint, SkillInfo>(); if (aChar.InactiveSkills == null) aChar.InactiveSkills =new Dictionary<uint,SkillInfo>(); if (aChar.Tasks == null) aChar.Tasks = new Dictionary<string, SagaLib.MultiRunTask>(); try { db.Set(aChar); db.Commit(); } catch(Exception) { Console.WriteLine("Error: can't create new char in database"); this.isconnected = false; throw new Exception("can't create new char in database"); } finally { try { aChar.charID = (uint)db.Ext().GetObjectInfo(aChar).GetUUID().GetLongPart(); db.Set(aChar); db.Commit(); } catch (Exception) { Console.WriteLine("Error: can't create new char in database"); this.isconnected = false; throw new Exception("can't create new char in database"); } } }
public ActorPC GetChar(uint charID) { ActorPC result = null; try { IObjectSet queryResult = db.Get(new ActorPC(charID,worldID)); if (queryResult.Count > 0) result = (ActorPC)queryResult[0]; } catch (Exception) { Console.WriteLine("Error: can't get char from database"); this.isconnected = false; throw new Exception("can't get char from database"); } finally { } if (result.Weapons == null) { Weapon newweapon = new Weapon(); result.Weapons = new List<Weapon>(); newweapon.name = result.weaponName; newweapon.level = 1; newweapon.type = (ushort)result.weaponType; newweapon.augeSkillID = 150001; newweapon.U1 = 1; newweapon.exp = 0; newweapon.durability = 1000; newweapon.active = 1; result.Weapons.Add(newweapon); } if (result.ShorcutIDs == null) result.ShorcutIDs = new Dictionary<byte,ActorPC.Shortcut>(); return result; }
private void LoadWeapon( ref ActorPC aChar ) { string sqlstr; int i; DataRowCollection result = null; sqlstr = "SELECT * FROM weapon WHERE charID=" + aChar.charID + ";"; try { result = db.GetDataTable(sqlstr).Rows; } catch( Exception ex ) { Logger.ShowError( " can't get weapons from database" + ex.Message, null ); Logger.ShowError( ex, null ); } aChar.Weapons = new List<Weapon>(); if( result.Count == 0 ) { Weapon newweapon = new Weapon(); newweapon.name = aChar.weaponName; newweapon.level = 1; newweapon.type = (ushort)aChar.weaponType; newweapon.augeSkillID = 150001; newweapon.U1 = 1; newweapon.exp = 0; newweapon.durability = 1000; newweapon.active = 1; newweapon.stones = new uint[6]; aChar.Weapons.Add( newweapon ); } for( i = 0; i < result.Count; i++ ) { Weapon weapon = new Weapon(); weapon.stones = new uint[6]; weapon.name = (string)result[i]["name"]; weapon.level = (byte)result[i]["level"]; weapon.type = (byte)result[i]["type"]; weapon.exp = (uint)(int)result[i]["exp"]; weapon.augeSkillID = (uint)(int)result[i]["augeSkillID"]; weapon.durability = (ushort)(short)result[i]["durability"]; weapon.U1 = (byte)result[i]["U1"]; weapon.active = (byte)result[i]["active"]; weapon.stones[0] = (uint)(int)result[i]["slot1"]; weapon.stones[1] = (uint)(int)result[i]["slot2"]; weapon.stones[2] = (uint)(int)result[i]["slot3"]; weapon.stones[3] = (uint)(int)result[i]["slot4"]; weapon.stones[4] = (uint)(int)result[i]["slot5"]; weapon.stones[5] = (uint)(int)result[i]["slot6"]; aChar.Weapons.Add( weapon ); } }
private void SaveWeapon( ActorPC aChar ) { string sqlstr = "DELETE FROM weapon WHERE charID=" + aChar.charID + ";"; //MySqlHelper.ExecuteNonQuery( db, sqlstr, null ); if( aChar.Weapons == null ) { Weapon newweapon = new Weapon(); aChar.Weapons = new List<Weapon>(); newweapon.name = aChar.weaponName; newweapon.level = 1; newweapon.type = 1; newweapon.augeSkillID = 150001; newweapon.U1 = 1; newweapon.exp = 0; newweapon.durability = 1800; newweapon.active = 1; newweapon.stones = new uint[6]; aChar.Weapons.Add( newweapon ); } foreach( Weapon i in aChar.Weapons ) { sqlstr += string.Format( "INSERT INTO weapon ( charID , name , level , type , augeSkillID , exp , durability , U1 , active , slot1 , slot2 , slot3 , slot4 , slot5 , slot6 ) VALUES({0},N'{1}',{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14});", aChar.charID, i.name, i.level, i.type, i.augeSkillID, i.exp, i.durability, i.U1, i.active, i.stones[0], i.stones[1], i.stones[2], i.stones[3], i.stones[4], i.stones[5] ); } try { db.ExeSql(sqlstr); } catch (Exception ex) { Console.WriteLine("Error: can't insert new weapon in database" + ex.Message); } }
public void CreateChar(ref ActorPC aChar, int account_id) { Load(); if (aChar.Weapons == null) { Weapon newweapon = new Weapon(); aChar.Weapons = new List<Weapon>(); newweapon.name = aChar.weaponName; newweapon.level = 1; newweapon.type = 1; newweapon.augeSkillID = 150001; newweapon.U1 = 1; newweapon.exp = 0; newweapon.durability = 1800; newweapon.active = 1; newweapon.stones = new uint[6]; aChar.Weapons.Add(newweapon); } if(aChar.ShorcutIDs == null) aChar.ShorcutIDs = new Dictionary<byte, ActorPC.Shortcut>(); if(aChar.BattleSkills==null) aChar.BattleSkills = new Dictionary<uint,SkillInfo>(); if(aChar.LivingSkills==null)aChar.LivingSkills =new Dictionary<uint,SkillInfo>(); if (aChar.SpecialSkills == null) aChar.SpecialSkills = new Dictionary<uint, SkillInfo>(); if (aChar.InactiveSkills == null) aChar.InactiveSkills =new Dictionary<uint,SkillInfo>(); if (aChar.Tasks == null) aChar.Tasks = new Dictionary<string, SagaLib.MultiRunTask>(); if (aChar.JobLevels == null) aChar.JobLevels = new Dictionary<JobType, byte>(); aChar.QuestTable = new Dictionary<uint, SagaDB.Quest.Quest>(); aChar.PersonalQuestTable = new Dictionary<uint, SagaDB.Quest.Quest>(); aChar.MapInfo = new Dictionary<byte, byte>(); System.IO.FileStream fs = null; try { if (System.IO.Directory.Exists(dbpath + "Save") == false) System.IO.Directory.CreateDirectory(dbpath + "Save"); if (System.IO.Directory.Exists(dbpath + "Save/" + aChar.userName) == false) System.IO.Directory.CreateDirectory(dbpath + "Save/" + aChar.userName); fs = new System.IO.FileStream(dbpath + "Save/" + aChar.userName + "/" + aChar.name + ".dat", System.IO.FileMode.Create); System.Runtime.Serialization.Formatters.Binary.BinaryFormatter xs = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); xs.Serialize(fs, aChar); } catch(Exception ex) { Console.WriteLine("Error: can't create new char in database"); throw new Exception(ex.Message + "\r\n" + ex.StackTrace); } finally { try { this.myDB.CharNames.Add(aChar.name); aChar.charID = this.myDB.currentCharID; this.myDB.Chars.Add(aChar.charID, aChar.userName + "," + aChar.name); this.myDB.currentCharID++; if (fs != null) fs.Close(); Save(); } catch (Exception ex) { Console.WriteLine("Error: can't create new char in database"); throw new Exception(ex.Message + "\r\n" + ex.StackTrace); } } }
private void SaveWeapon( ActorPC aChar ) { string sqlstr = "DELETE FROM `weapon` WHERE charID='" + aChar.charID + "';"; //MySqlHelper.ExecuteNonQuery( db, sqlstr, null ); if( aChar.Weapons == null ) { Weapon newweapon = new Weapon(); aChar.Weapons = new List<Weapon>(); newweapon.name = aChar.weaponName; newweapon.level = 1; newweapon.type = 1; newweapon.augeSkillID = 150001; newweapon.U1 = 1; newweapon.exp = 0; newweapon.durability = 1800; newweapon.active = 1; newweapon.stones = new uint[6]; aChar.Weapons.Add( newweapon ); } foreach( Weapon i in aChar.Weapons ) { sqlstr += string.Format( "INSERT INTO `weapon`(`charID`,`name`,`level`,`type`,`augeSkillID`,`exp`,`durability`,`U1`,`active`,`slot1`,`slot2`,`slot3`,`slot4`,`slot5`,`slot6`) VALUE('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}');", aChar.charID, i.name, i.level, i.type, i.augeSkillID, i.exp, i.durability, i.U1, i.active, i.stones[0], i.stones[1], i.stones[2], i.stones[3], i.stones[4], i.stones[5] ); } try { SQLExecuteNonQuery(sqlstr); } catch (Exception ex) { Console.WriteLine("Error: can't insert new weapon in database" + ex.Message); } }