public static Monster createFor( Player player ) { Monster mon = new Monster(); mon.player = player; mon.name = "a monster"; mon.hp = 15; mon.damage = 1; mon.money = 4; for ( int i = 0; i < player.getLevel(); i++ ) { mon.hp += _rand.Next( 0, 6 ); mon.damage += _rand.Next( 0, 2 ); mon.money += _rand.Next( 0, 5 ); } string sql = "REPLACE INTO monsters ( username, name, hp, damage, money ) " + " VALUES ('" + player.getUsername() + "', '" + mon.name + "', " + mon.hp + ", " + mon.damage + ", " + mon.money + ")"; _sqlite.exec( sql ); return mon; }
private static void cmd_tavern_info( Player player ) { Program.sendWhisper( player, "\"Need a little help, eh?\" says the barman." ); sendZoneList( player ); Program.sendWhisper( player, "\"You can also ask for !help or check your !status at any time." ); }
// ----- Tavern Commands -------------------- private static void cmd_tavern_drink( Player player ) { if ( !player.pay( 5 ) ) { Program.sendChannel( "Hehe, @" + player.getUsername() + " can't afford $5 for an ale." ); return; } var hp = player.heal( 5 ); Program.sendChannel( "@" + player.getUsername() + " drinks his $5 ale. [+ " + hp + " hp]" ); }
private static void cmd_forest_run( Player player ) { Monster mon = Monsters.loadFor( player ); if ( mon == null ) { Console.WriteLine( "ERROR: running from a fight where no monster exists" ); // Move player to forest player.changeZone( "forest" ); return; } // failure? if ( new Random().Next( 0, 3 ) == 0 ) { Program.sendWhisper( player, "You failed to run away!" ); mon.attack(); return; } // Move player to forest player.changeZone( "forest" ); Program.sendWhisper( player, "You successfully run away." ); mon.clear(); }
private static void cmd_forest_attack( Player player ) { Monster mon = Monsters.loadFor( player ); if ( mon == null ) { return; } mon.takeDamage( player.getDamage() ); if ( mon.isDead() ) { // Move player to forest player.changeZone( "forest" ); } else { mon.attack(); } }
// ----- Blacksmith Commands -------------------- // ----- Forest Commands -------------------- private static void cmd_forest_adventure( Player player ) { // Move player to fight room player.changeZone( "forestfight" ); // crete a new fight instance Monster mon = Monsters.createFor( player ); // Whisper fight status Program.sendWhisper( player, "You see " + mon.name + " [" + mon.hp + "]! You have " + player.getHp() + "/" + player.getMaxHp() + " hp." ); Program.sendWhisper( player, "You can !attack (!a) or !run (!r) -- Please WHISPER fight commands, do not spam the main channel." ); }
public static bool tryWhisperCommand( Player player, string zoneId, string command, string[] options = null ) { Zone zone = getZone( zoneId ); if ( zone == null ) { return false; } switch ( zoneId ) { case "forestfight": switch ( command ) { case "attack": case "a": cmd_forest_attack( player ); return true; case "run": case "r": cmd_forest_run( player ); return true; default: return false; } default: return false; } }
public static bool tryCommand( Player player, string zoneId, string command, string[] options = null ) { Zone zone = getZone( zoneId ); if ( zone == null ) { return false; } switch ( zoneId ) { case "tavern": switch ( command ) { case "drink": cmd_tavern_drink( player ); return true; case "info": cmd_tavern_info( player ); return true; default: return false; } case "blacksmith": switch ( command ) { default: return false; } case "forest": switch ( command ) { case "adventure": cmd_forest_adventure( player ); return true; default: return false; } case "forestfight": switch(command) { case "attack": case "a": case "run": case "r": Program.sendWhisper( player, "Fight commands go in the WHISPER window." ); return true; default: return false; } default: return false; } }
public static void sendZoneList( Player player ) { List<string> keywords = getZoneKeywords(); string message = "From here you can !go to the "; for ( int i = 0; i < keywords.Count; i++ ) { message += keywords[i]; if ( i < keywords.Count - 1 ) { message += ", "; } if ( i == keywords.Count - 2 ) { message += "or "; } } message += ". (eg: !go forest)"; Program.sendWhisper( player, message ); }
public PlayerCommand( Player player ) { _player = player; }
public PlayerCommand( string username ) { _player = new Player( username ); }
public static void clearFor( Player player ) { string sql = "DELETE FROM monsters WHERE username LIKE '" + player.getUsername() + "'"; _sqlite.exec( sql ); }
public static Monster loadFor( Player player ) { Monster mon = new Monster(); mon.player = player; string sql = "SELECT * FROM monsters WHERE username LIKE '" + player.getUsername() + "'"; SQLiteDataReader reader = _sqlite.query( sql ); if ( !reader.Read() ) { return null; } mon.name = reader.GetString( reader.GetOrdinal( "name" ) ); mon.hp = reader.GetInt32( reader.GetOrdinal( "hp" ) ); mon.damage = reader.GetInt32( reader.GetOrdinal( "damage" ) ); mon.money = reader.GetInt32( reader.GetOrdinal( "money" ) ); return mon; }