public bool changeRoom(string direction) { ReadableSQLExecuter sql = new ReadableSQLExecuter(); sql.query = "select R_IdT from `Gate` where R_IdF=? and Direction=?"; sql.add_parameter(R_Id); sql.add_parameter(direction); sql.execute_query(); if (sql.error) { Console.WriteLine(sql.error_string); return false; } if (!sql.HasRows) { return false; } R_Id = Convert.ToInt64(sql.result[0][0]); UnreadableSQLExecuter exec = new UnreadableSQLExecuter(); exec.query = "update `Character` set R_Id=? where C_Id=?"; exec.add_parameter(R_Id); exec.add_parameter(container.c_data.C_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(sql.error_string); return false; } loadAttributes(); return true; }
public static Monster getMonsterByName(ref DataContainer cont, string monstername) { Monster to_return; ReadableSQLExecuter exec = new ReadableSQLExecuter(); // load monster attributes exec.query = "select `Monster`.M_Id from Monster, MonsterIsIn as MIIn where `Monster`.M_Id=MIIn.M_Id and MIIn.RespawnAtTime < NOW() and MIIn.R_Id=? and `Monster`.Name=?"; exec.add_parameter(cont.r_data.R_Id); exec.add_parameter(monstername); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); return null; } if (!exec.HasRows) // no monster with this name { Console.WriteLine("No monster " + monstername); return null; } long M_Id = Convert.ToInt64(exec.result[0][0]); to_return = new Monster(ref cont, M_Id); return to_return; }
private bool createCharacter(string name) { ReadableSQLExecuter sql = new ReadableSQLExecuter(); sql.query = "select C_Id from `Character` where Name=?"; sql.add_parameter(name); sql.execute_query(); if (sql.error) { Console.WriteLine(sql.error_string); return false; } if (sql.HasRows) { return false; } UnreadableSQLExecuter exec = new UnreadableSQLExecuter(); exec.query = "insert into `Character` (U_Id,Name,Money,Health,Damage,PhRes,MaxHealth,R_Id) values (?,?,200,100,30,10,100,1)"; exec.add_parameter(U_Id); exec.add_parameter(name); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); return false; } return true; }
public void calculateBuffs() { //load buff damage ReadableSQLExecuter exec = new ReadableSQLExecuter(); exec.add_parameter(C_Id); exec.query = "select sum(Amount) from `Buff` where Type=1 and RunsOutAt > now() and C_Id = ?"; exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); error = true; error_string = exec.error_string; return; } if (exec.HasRows) { if (exec.result[0][0] != DBNull.Value) { BuffDamage = Convert.ToInt64(exec.result[0][0]); } else { BuffDamage = 0; } } //load buff res exec = new ReadableSQLExecuter(); exec.add_parameter(C_Id); exec.query = "select sum(Amount) from `Buff` where Type=2 and RunsOutAt > now() and C_Id = ? "; exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); error = true; error_string = exec.error_string; return; } if (exec.HasRows) { if (exec.result[0][0] != DBNull.Value) { BuffPhRes = Convert.ToInt64(exec.result[0][0]); } else { BuffPhRes = 0; } } }
private bool selectCharacter(string name) { ReadableSQLExecuter sql = new ReadableSQLExecuter(); sql.query = "select C_Id from `Character` where Name=? and U_Id=?"; sql.add_parameter(name); sql.add_parameter(U_Id); sql.execute_query(); if (!sql.HasRows) { return false; } C_Id = Convert.ToInt64(sql.result[0][0]); return true; }
public static TakeableGameObject getObjectByName(ref DataContainer cont, string objectName,string object_in) { ReadableSQLExecuter sql = new ReadableSQLExecuter(); sql.query = "select O_Id from `Objekt` where `Objekt`.O_Id in (select O_Id from `Takeable` where R_Id=? and Takefrom=? and RespawnAtTime<NOW()) and `Objekt`.Name=?"; sql.add_parameter(cont.r_data.R_Id); sql.add_parameter(object_in); sql.add_parameter(objectName); sql.execute_query(); if (sql.error) { Console.WriteLine(sql.error_string); return null; } if (!sql.HasRows) { return null; } return new TakeableGameObject(ref cont, Convert.ToInt64(sql.result[0][0])); }
public static GameObject getObjectByName(ref DataContainer cont, string objectName) { ReadableSQLExecuter sql = new ReadableSQLExecuter(); sql.query = "select `Objekt`.O_Id from `Objekt`,`ObjInRoom` where `Objekt`.O_Id=`ObjInRoom`.O_Id and `ObjInRoom`.R_Id=? and `Objekt`.O_Id not in (select O_Id from `Takeable` where R_Id=? and not Takefrom='') and `Objekt`.Name=?"; sql.add_parameter(cont.r_data.R_Id); sql.add_parameter(cont.r_data.R_Id); sql.add_parameter(objectName); sql.execute_query(); if (sql.error) { Console.WriteLine(sql.error_string); return null; } if (!sql.HasRows) { return null; } return new GameObject(ref cont,Convert.ToInt64(sql.result[0][0])); }
public static Item getItemByName(ref DataContainer cont, string name) { ReadableSQLExecuter exec = new ReadableSQLExecuter(); exec.query = "select `Item`.I_Id from `Item`,`BelongsTo` where `Item`.I_Id=`BelongsTo`.I_Id and `BelongsTo`.C_Id=? and `Item`.Name=?"; exec.add_parameter(cont.c_data.C_Id); exec.add_parameter(name); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); return null; } if (!exec.HasRows) { return null; } return new Item(ref cont, Convert.ToInt64(exec.result[0][0])); }
public bool isValid() { ReadableSQLExecuter exec = new ReadableSQLExecuter(); exec.query = "select `Object`.O_Id from `Object`,`ObjectIn` where `Object`.O_Id=`ObjectIn`.O_Id and `Object`.O_Id=? and `ObjectIn`.R_Id=? "; exec.add_parameter(O_Id); exec.add_parameter(container.r_data.R_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); this.error = true; this.error_string = exec.error_string; return false; } if (!exec.HasRows) { return false; } return true; }
public void loadAttributes() { ReadableSQLExecuter sql = new ReadableSQLExecuter(); sql.query = "select `Room`.R_Id,`Room`.Name,`Room`.Description from `Room`,`Character` where `Room`.R_Id = `Character`.R_Id and `Character`.C_Id=?"; sql.add_parameter(container.c_data.C_Id); sql.execute_query(); if (sql.error) { Console.WriteLine(sql.error_string); return; } if (!sql.HasRows) // very unlikely { Console.WriteLine("Character Id not found"); return; } R_Id = Convert.ToInt64(sql.result[0][0]); Name = Convert.ToString(sql.result[0][1]); Description = Convert.ToString(sql.result[0][2]); }
private void loadAttributes() { ReadableSQLExecuter exec = new ReadableSQLExecuter(); exec.query = "select Name,Description from `Object` where O_Id=?"; exec.add_parameter(O_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); this.error = true; this.error_string = exec.error_string; } if (!exec.HasRows) { this.error = true; this.error_string = "Object Id not found."; return; } this.Name = Convert.ToString(exec.result[0][0]); this.Description = Convert.ToString(exec.result[0][1]); }
public bool login(string name, string password) { ReadableSQLExecuter sql = new ReadableSQLExecuter(); sql.query = "select U_Id from User where Name=? and Password=?"; sql.add_parameter(name); sql.add_parameter(password); sql.execute_query(); if (sql.error) { Console.WriteLine(sql.error_string); return false; } if (!sql.HasRows) { return false; } U_Id = Convert.ToInt64(sql.result[0][0]); return true; }
public static List<Monster> loadMonsters(ref DataContainer cont) { List<Monster> monsters = new List<Monster>(); ReadableSQLExecuter exec = new ReadableSQLExecuter(); exec.query = "select M_Id from MonsterIsIn where RespawnAtTime<NOW() and R_Id=?"; exec.add_parameter(cont.r_data.R_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); return null; } if (!exec.HasRows) { return null; } foreach (object[] tmp in exec.result) { long id = Convert.ToInt64(tmp[0]); monsters.Add(new Monster(ref cont, id)); } return monsters; }
public void calculateItemStats() { // load weapon damage ReadableSQLExecuter exec = new ReadableSQLExecuter(); exec.add_parameter(C_Id); exec.query = "select sum(`Weapon`.Damage) from `Weapon`,`BelongsTo` where `Weapon`.I_Id=`BelongsTo`.I_Id and `BelongsTo`.Equipped=1 and `BelongsTo`.C_Id = ?"; exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); error = true; error_string = exec.error_string; return; } if (exec.HasRows) { if (exec.result[0][0] != DBNull.Value) { ItemDamage = Convert.ToInt64(exec.result[0][0]); } else { ItemDamage = 0; } } else { ItemDamage = 0; } // load armor res exec = new ReadableSQLExecuter(); exec.add_parameter(C_Id); exec.query = "select sum(`Armor`.PhyRes) from `Armor`,`BelongsTo` where `Armor`.I_Id=`BelongsTo`.I_Id and `BelongsTo`.Equipped=1 and `BelongsTo`.C_Id = ?"; exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); error = true; error_string = exec.error_string; return; } if (exec.HasRows) { if (exec.result[0][0] != DBNull.Value) { ItemPhRes = Convert.ToInt64(exec.result[0][0]); } else { ItemPhRes = 0; } } else { ItemDamage = 0; } }
public void loadAttributes() { ReadableSQLExecuter exec = new ReadableSQLExecuter(); exec.query = "select `Item`.Name,`Item`.Description,`Item`.Category,`BelongsTo`.Equipped from `Item`,`BelongsTo` where `Item`.I_Id=`BelongsTo`.I_Id and `BelongsTo`.C_ID=? and `Item`.I_Id=?"; exec.add_parameter(container.c_data.C_Id); exec.add_parameter(I_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); this.error = true; this.error_string = exec.error_string; return; } if (!exec.HasRows) { this.error = true; this.error_string = "No Item with this Id was found"; return; } this.Name = Convert.ToString(exec.result[0][0]); this.Description = Convert.ToString(exec.result[0][1]); this.Category = Convert.ToString(exec.result[0][2]); this.Equipped = Convert.ToBoolean(exec.result[0][3]); }
private bool consumeDamage(long amount, long I_Id) { ReadableSQLExecuter exec = new ReadableSQLExecuter(); exec.query = "select Name from `Item` where I_Id=?"; exec.add_parameter(I_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); return false; } string Name = Convert.ToString(exec.result[0][0]); exec = new ReadableSQLExecuter(); exec.query = "select now()+Duration from `Consumable` where I_Id=?"; exec.add_parameter(I_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); return false; } double Buffduration = Convert.ToDouble(exec.result[0][0]); exec = new ReadableSQLExecuter(); exec.query = "insert into `Buff`(Name, Amount, Type, RunsOutAt, C_Id) values(?,?,1,?,?) "; exec.add_parameter(Name); exec.add_parameter(amount); exec.add_parameter(Convert.ToString(Buffduration)); exec.add_parameter(container.c_data.C_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); return false; } else { return true; } }
public static List<Item> loadItems(ref DataContainer cont) { List<Item> items = new List<Item>(); ReadableSQLExecuter exec = new ReadableSQLExecuter(); exec.query = "select I_Id from BelongsTo where C_Id=?"; exec.add_parameter(cont.c_data.C_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); return null; } if (!exec.HasRows) { return null; } foreach (object[] tmp in exec.result) { long id = Convert.ToInt64(tmp[0]); items.Add(new Item(ref cont, id)); } return items; }
private void writeStartMessage() { ReadableSQLExecuter sql = new ReadableSQLExecuter(); sql.query = "select Name from `Character` where U_Id=?"; sql.add_parameter(U_Id); sql.execute_query(); if (sql.error) { Console.WriteLine(sql.error_string); return; } string name; if (!sql.HasRows) { write("Du hast noch keinen Charakter!\nGebe 'neu' ein um einen Character zu erstellen."); dialogue_type = true; return; } write("Waehle aus der Liste den Charakter mit dem du spielen willst\n"); foreach (object[] names in sql.result) { name = Convert.ToString(names[0]); write(name + "\n"); } }
private void loadAttributes() { ReadableSQLExecuter exec = new ReadableSQLExecuter(); // load monster attributes exec.query = "select `Monster`.Name,`Monster`.Description,`Monster`.Damage,`Monster`.PhRes,`Monster`.MaxHealth,`Monster`.Hostile,MIIn.Health from Monster, MonsterIsIn as MIIn where `Monster`.M_Id=MIIn.M_Id and `Monster`.M_Id=? and MIIn.R_Id=?"; exec.add_parameter(M_Id); exec.add_parameter(container.r_data.R_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); error = true; error_string = exec.error_string; return; } if (!exec.HasRows) // this should not happen { error = true; error_string = "No Monster with this Id"; return; } Name = Convert.ToString(exec.result[0][0]); Description = Convert.ToString(exec.result[0][1]); Damage = Convert.ToInt64(exec.result[0][2]); PhRes = Convert.ToInt64(exec.result[0][3]); MaxHealth = Convert.ToInt64(exec.result[0][4]); Hostile = Convert.ToBoolean(exec.result[0][5]); Health = Convert.ToInt64(exec.result[0][6]); }
public bool isValid() { ReadableSQLExecuter exec = new ReadableSQLExecuter(); // load monster attributes exec.query = "select R_ID from MonsterIsIn where RespawnAtTime < NOW() and M_Id=? and R_Id=?"; exec.add_parameter(M_Id); exec.add_parameter(container.r_data.R_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); error = true; error_string = exec.error_string; return false; } if (!exec.HasRows) // this should not happen { return false; } return true; }
private bool check_register(string name, string password) { //check if lenght of name is between 3 and 12 and password lenght > 8 if (name.Length < 3 || name.Length > 12) { return false; } if (password.Length < 8) { return false; } ReadableSQLExecuter exec = new ReadableSQLExecuter(); exec.query = "select U_Id from User where Name=?"; //check if name already exist exec.add_parameter(name); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); return false; } if (exec.HasRows) { return false; } return true; }
private void changeHealth(long amount) { ReadableSQLExecuter exec = new ReadableSQLExecuter(); exec.query = "update `Character` set Health = case when Health+? <MaxHealth then Health+? else MaxHealth end where `Character`.C_Id=? "; exec.add_parameter(amount); exec.add_parameter(amount); exec.add_parameter(C_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); error = true; error_string = exec.error_string; } loadAttributes(); }
public long getOwnedAmount() { ReadableSQLExecuter exec = new ReadableSQLExecuter(); exec.query = "select Amount from `BelongsTo` where I_Id=? and C_Id=?"; exec.add_parameter(I_Id); exec.add_parameter(container.c_data.C_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); this.error = true; this.error_string = exec.error_string; return 0; } if (!exec.HasRows) { return 0; } return Convert.ToInt64(exec.result[0][0]); }
public void loadAttributes() { if (C_Id == 0) return; ReadableSQLExecuter exec = new ReadableSQLExecuter(); exec.query = "select Money,Health,Damage,PhRes,MaxHealth,Name from `Character` where C_Id = ?"; exec.add_parameter(C_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); error = true; error_string = exec.error_string; return ; } if (!exec.HasRows) // this should not happen { error = true; error_string = "No Character with this Id"; return; } object[] attributes = exec.result[0]; Money = Convert.ToInt64(attributes[0]); Health = Convert.ToInt64(attributes[1]); Damage = Convert.ToInt64(attributes[2]); PhRes = Convert.ToInt64(attributes[3]); MaxHealth = Convert.ToInt64(attributes[4]); Name = Convert.ToString(attributes[5]); return; }
public int consume(bool consumation_type) { if (Category != "Consumable") { return 2; } long amount = getOwnedAmount(); if (error) { Console.WriteLine(error_string); return -1; } if (amount==0) { return 1; } ReadableSQLExecuter exec = new ReadableSQLExecuter(); exec.query = "select Type,Amount,ConsumptionType,NOW()+Duration from Consumable where I_Id=?"; exec.add_parameter(I_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); error = true; error_string = exec.error_string; return -1; } if (!exec.HasRows) { Console.WriteLine("Consumable not found!"); return -1; } string buff_type = Convert.ToString(exec.result[0][0]); long buff_amount = Convert.ToInt64(exec.result[0][1]); string runsoutat = Convert.ToString(exec.result[0][3]); if (Convert.ToBoolean(exec.result[0][2]) != consumation_type) { return 3; } if (buff_type == "Health") { consumeHealth(buff_amount); if (error) { return -1; } } else if (buff_type == "PhRes") { container.c_data.addBuff(Name, runsoutat, buff_amount,2); } else if (buff_type == "Damage") { container.c_data.addBuff(Name, runsoutat, buff_amount, 1); } else { return 2; } destroyItem(1); return 0; }