static int idw_do_keystroke (GR_EVENT *event)
{
  TSheet event_sheet;
  int n;

  if ( game.dismiss_sheet ) {
    if (event->keystroke.ch == '\r') {
      if (game.days == game.max_days) restart();
      
      game.dismiss_sheet = 0;
      game.in_transaction = 0;
      idw_do_draw();
    }
    
    return 1;
  }

  switch (event->keystroke.ch) {
    case '\r': /* Wheel button */
      if (! game.screen->menuitems[game.select].sheet) break;
      if ( (game.screen == &buy) && (!afford(game.select)) ) break;
      if ( (game.screen == &sell) && (!game.drugs[game.select]) ) break;
      if ( (game.screen->menuitems[game.select].sheet == &borrow_sheet) && (!game.debt) ) break;
      if ( (game.screen->menuitems[game.select].sheet == &withdraw_sheet) && (!game.bank) ) break;

      init_sheets();
      if (! game.in_transaction ) {
        // set initial ammount value to be shown on the sheet
        game.ammount = game.screen->menuitems[game.select].sheet->ammount;
        init_sheets();
      }
      init_screens();
     
      if ( game.screen == &jet ) {
        if (game.city == game.select) break;
        
        travel();

        // let's get a random event (high-low)+low
        n = (rand() % EVENT_COUNT);

        // it has a 50-50 chance of occurring
        if (! (rand() % 2)) {
          event_sheet = random_event(n);
          idw_draw_sheet(&event_sheet);
          init_screens();
        } else {
          init_screens();
          idw_do_draw();
        }
        
        check_over();
        break;
      }
            
      if ( game.in_transaction ) {
        // we're going to buy/sell
        if (game.screen == &buy) do_buy(game.select, game.ammount);
        if (game.screen == &sell) do_sell(game.select, game.ammount);
        if (game.screen->menuitems[game.select].sheet == &deposit_sheet) do_deposit();
        if (game.screen->menuitems[game.select].sheet == &withdraw_sheet) do_withdraw();
        if (game.screen->menuitems[game.select].sheet == &pay_sheet) do_pay();
        if (game.screen->menuitems[game.select].sheet == &borrow_sheet) do_borrow();
        
        // transaction finished
        game.in_transaction = 0;
        init_screens();
        idw_do_draw();
        break;
      }
      
      idw_draw_sheet(NULL);
      break;
      
    case 'd': /* Play/pause button */
      break;
    case 'w': /* Rewind button */
      if (game.in_transaction) break;
      if (!game.screen->prev) break;
      
      game.screen = game.screen->prev;
      game.select=0;
      idw_do_draw();
      break;
      
    case 'f': /* Fast forward button */
      if (game.in_transaction) break;
      if (!game.screen->next) break;
      
      game.screen = game.screen->next;
      game.select=0;
      idw_do_draw();
      break;
    case 'l': /* Wheel left */
      if (game.in_transaction) {
        if (game.ammount) game.ammount--;
        init_sheets();
        idw_draw_sheet(NULL);
        break;
      }
      if (game.select <= 0) break;
      
      game.select--;
      idw_do_draw();
      break;
      
    case 'r': /* Wheel right */
      if (game.in_transaction) {
        if (game.ammount < game.screen->menuitems[game.select].sheet->ammount) game.ammount++;
        init_sheets();
        idw_draw_sheet(NULL);
        break;
      }
      if (game.select >= game.screen->count-1) break;
      
      game.select++;
      idw_do_draw();
      break;
      
    case 'm': /* Menu button */
      //if (game.in_transaction) {
        // cancel transaction
     //   game.in_transaction = 0;
    //    game.ammount = 0;
    //    idw_do_draw();
    //    break;
   //   }
  //    pz_close_window (idw_wid);
    //  GrDestroyGC(idw_gc);
   //   break;
   // default:
   			GrDestroyGC( idw_gc );
			pz_close_window( idw_wid );
      break;
  }
  
  return 1;
}
Beispiel #2
0
/*
 * /money -
 *
 * Displays the amount of money a player has.
 *
 * Permissions:
 *   - command.info.money
 *       Needed to execute the command.
 *   - command.info.money.others
 *       Required to display the amount of money _other_ players have.
 *   - command.info.money.pay
 *       Whether the player is allowed to send money out of their own account.
 *   - command.info.money.give
 *       Whether the player is allowed to give money to players _wihout_
 *       taking it out of their own account.
 *   - command.info.money.set
 *       Required to modify a player's balance directly.
 */
void
c_money::execute (player *pl, command_reader& reader)
{
    if (!pl->perm (this->get_exec_permission ()))
        return;

    if (!reader.parse (this, pl))
        return;

    bool someone_else = false;
    std::string target_name;
    if (!reader.has_next ())
    {
        target_name.assign (pl->get_username ());
    }
    else
    {
        std::string& a = reader.next ();
        if (sutils::iequals (a, "pay"))
        {
            do_pay (pl, reader);
            return;
        }
        else if (sutils::iequals (a, "give"))
        {
            do_give (pl, reader);
            return;
        }
        else if (sutils::iequals (a, "take"))
        {
            do_take (pl, reader);
            return;
        }
        else if (sutils::iequals (a, "set"))
        {
            do_set (pl, reader);
            return;
        }
        else
        {
            target_name = a;
            someone_else = true;
        }
    }

    //
    // /money [player]
    //
    std::ostringstream ss;
    if (someone_else)
    {
        if (!pl->has ("command.info.money.others"))
        {
            pl->message ("§c * §7You are not allowed to do that§c.");
            return;
        }

        if (sutils::iequals (target_name, pl->get_username ()))
            ss << "§2Balance§8: §a$§f" << utils::format_number (pl->bal, 2);
        else
        {
            player *target = pl->get_server ().get_players ().find (target_name.c_str ());
            if (target)
                ss << target->get_colored_username () << "§e's balance§f: §a$§f" << utils::format_number (target->bal, 2);
            else
            {
                soci::session sql (pl->get_server ().sql_pool ());

                try
                {
                    if (!sqlops::player_exists (sql, target_name.c_str ()))
                    {
                        pl->message ("§c * §7No such player§f: §c" + target_name);
                        return;
                    }

                    ss << sqlops::player_colored_name (sql, target_name.c_str (), pl->get_server ())
                       << "§2's balance§f: §a$§f" << utils::format_number (sqlops::get_money (sql, target_name.c_str ()), 2);
                }
                catch (const std::exception& ex)
                {
                    pl->message ("§4 * §cAn error has occurred§4.");
                    return;
                }
            }
        }
    }
    else
        ss << "§2Balance§f: §a$§f" << utils::format_number (pl->bal, 2);

    pl->message (ss.str ());
}