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; }
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 static bool giveUser(ref DataContainer cont, long I_Id) { UnreadableSQLExecuter exec = new UnreadableSQLExecuter(); exec.query = "update `BelongsTo` set Amount=Amount+1 where I_Id=? and C_Id=?"; exec.add_parameter(I_Id); exec.add_parameter(cont.c_data.C_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); return false; } if (exec.rows_affected == 0) { exec = new UnreadableSQLExecuter(); exec.query = "insert into `BelongsTo` (I_Id,C_Id,Amount,Equipped) values (?,?,1,0)"; exec.add_parameter(I_Id); exec.add_parameter(cont.c_data.C_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); return false; } } cont.c_data.calculateItemStats(); return true; }
public void addBuff(string name,string runsoutat,long amount,long type) { UnreadableSQLExecuter exec = new UnreadableSQLExecuter(); exec.query = "insert into `Buff`(Name, Amount, Type, RunsOutAt, C_Id) values(?,?,?,?,?) "; exec.add_parameter(name); exec.add_parameter(amount); exec.add_parameter(type); exec.add_parameter(runsoutat); exec.add_parameter(C_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); error = true; error_string = exec.error_string; return; } calculateBuffs(); }
public bool attack() { container.c_data.calculateItemStats(); container.c_data.calculateBuffs(); Health -= container.c_data.Damage + container.c_data.BuffDamage+container.c_data.ItemDamage - PhRes; UnreadableSQLExecuter u_exec = new UnreadableSQLExecuter(); if (Health <= 0) //congrats... you killed it { u_exec.query = "update `MonsterIsIn`,`Monster` set `MonsterIsIn`.RespawnAtTime=`MonsterIsIn`.RespawnTime+now(),`MonsterIsIn`.Health =`Monster`.MaxHealth where `MonsterIsIn`.M_Id=? and `MonsterIsIn`.R_Id=?"; u_exec.add_parameter(M_Id); u_exec.add_parameter(container.r_data.R_Id); u_exec.execute_query(); if (u_exec.error) // an error occured somewhere during the loading of the monster attributes { Console.WriteLine(u_exec.error_string); error = true; error_string = u_exec.error_string; return false; } return true; } u_exec.query = "update `MonsterIsIn` set Health=? where M_Id=? and R_Id =?"; u_exec.add_parameter(Health); u_exec.add_parameter(M_Id); u_exec.add_parameter(container.r_data.R_Id); u_exec.execute_query(); if (u_exec.error) // an error occured somewhere during the loading of the player attributes { Console.WriteLine(u_exec.error_string); error = true; error_string = u_exec.error_string; return false; } container.c_data.takeDamage(Damage); return false; }
public bool died() { UnreadableSQLExecuter exec = new UnreadableSQLExecuter(); exec.query = "update `Character` set Health=MaxHealth, R_Id=1 where C_Id=?"; exec.add_parameter(C_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); return false; } loadAttributes(); return true; }
public bool take() { if (!isValid()) { return false; } UnreadableSQLExecuter exec = new UnreadableSQLExecuter(); exec.query = "update Takeable set RespawnAtTime=NOW()+Respawntime where I_Id=? and O_Id=?"; exec.add_parameter(I_Id); exec.add_parameter(O_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); return false; } return Item.giveUser(ref container, I_Id); ; }
private bool register() { Name = Name.Trim(); if (!check_register(Name, Password)) // check register adds the parameters to the command. { return false; } UnreadableSQLExecuter exec = new UnreadableSQLExecuter(); exec.query = "insert into User (Name,Password,LastLogin) values (?,?,NOW())"; exec.add_parameter(Name); exec.add_parameter(Password); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); return false; } return true; }
// here as well private bool unequip_weapon() { UnreadableSQLExecuter exec = new UnreadableSQLExecuter(); exec.query = "update `BelongsTo`,`Item` set `BelongsTo`.Equipped=0 where `BelongsTo`.I_Id=`Item`.I_Id and `Item`.Category='Weapon' and `BelongsTo`.C_Id = ?"; exec.add_parameter(container.c_data.C_Id); exec.execute_query(); if (exec.error) { Console.WriteLine(exec.error_string); return false; } return true; }
// it is assumed that the user ownes this item private bool unequip_armor() { // find out if an armor of this type is allready equipped UnreadableSQLExecuter exec = new UnreadableSQLExecuter(); exec.query = "update `BelongsTo`,`Armor` set `BelongsTo`.Equipped = 0 where `BelongsTo`.I_Id = `Armor`.I_Id and `BelongsTo`.Equipped=1 and `BelongsTo`.C_Id=? and `Armor`.Type in (select Type from Armor where 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); return false; } return true; }
public bool equip() { if (Category == "Armor") { unequip_armor(); if (error) { return false; } } else if (Category == "Weapon") { unequip_weapon(); if (error) { return false; } } else//it is nothing you can equip { Console.WriteLine("Failed to equip object: " + Category); return false; } UnreadableSQLExecuter u_exec = new UnreadableSQLExecuter(); u_exec.query = "Update `BelongsTo` set Equipped =1 where C_Id=? and I_Id=?"; u_exec.add_parameter(container.c_data.C_Id); u_exec.add_parameter(I_Id); u_exec.execute_query(); if (u_exec.error) { Console.WriteLine(u_exec.error_string); return false; } Equipped = true; container.c_data.calculateItemStats(); return true; }
public void destroyItem(long amount) { UnreadableSQLExecuter u_exec = new UnreadableSQLExecuter(); u_exec.query = "update `BelongsTo` set Amount=Amount-? where I_Id=? and C_Id=?"; u_exec.add_parameter(amount); u_exec.add_parameter(I_Id); u_exec.add_parameter(container.c_data.C_Id); u_exec.execute_query(); if (u_exec.error) { Console.WriteLine(u_exec.error_string); this.error = true; this.error_string = u_exec.error_string; return ; } u_exec = new UnreadableSQLExecuter(); u_exec.query = "delete from `BelongsTo` where Amount<=0"; u_exec.execute_query(); if (u_exec.error) { Console.WriteLine(u_exec.error_string); this.error = true; this.error_string = u_exec.error_string; } }