Exemplo n.º 1
0
 public synchronized void addSalesMoney(int town_id, int salesMoney) {
   Connection con = null;
   PreparedStatement pstm = null;
   L1Town town = TownTable.getInstance().getTownTable(town_id);
   int townTaxRate = town.getTaxRate();
   int townTax = salesMoney / 100 * townTaxRate;
   int townFixTax = salesMoney / 100 * 2;
   if (townTax <= 0 && townTaxRate > 0) {
     townTax = 1;
   }
   if (townFixTax <= 0 && townTaxRate > 0) {
     townFixTax = 1;
   }
   try {
     con = L1DatabaseFactory.getInstance().getConnection();
     pstm =
         con.prepareStatement(
             "UPDATE towns SET sales_money = sales_money + ?, town_tax = town_tax + ?, town_fix_tax = town_fix_tax + ? WHERE id = ?");
     pstm.setInt(1, salesMoney);
     pstm.setInt(2, townTax);
     pstm.setInt(3, townFixTax);
     pstm.setInt(4, town_id);
     pstm.execute();
     town.setSalesMoney(town.getSalesMoney() + salesMoney);
     town.setTownTax(town.getTownTax() + townTax);
     town.setTownFixTax(town.getTownFixTax() + townFixTax);
   } catch (SQLException e) {
     _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
   } finally {
     SqlUtil.close(pstm);
     SqlUtil.close(con);
   }
 }
Exemplo n.º 2
0
 public void load() {
   Connection con = null;
   PreparedStatement pstm = null;
   ResultSet rs = null;
   _towns.clear();
   try {
     con = L1DatabaseFactory.getInstance().getConnection();
     pstm = con.prepareStatement("SELECT * FROM towns");
     int townid;
     rs = pstm.executeQuery();
     while (rs.next()) {
       L1Town town = new L1Town();
       townid = rs.getInt("id");
       town.setTownId(townid);
       town.setName(rs.getString("name"));
       town.setLeaderId(rs.getInt("leader_id"));
       town.setLeaderName(CharacterTable.getInstance().getCharName(town.getLeaderId()));
       town.setTaxRate(rs.getInt("tax_rate"));
       town.setTaxRateReserved(rs.getInt("tax_rate_reserved"));
       town.setSalesMoney(rs.getInt("sales_money"));
       town.setSalesMoneyYesterday(rs.getInt("sales_money_yesterday"));
       town.setTownTax(rs.getInt("town_tax"));
       town.setTownFixTax(rs.getInt("town_fix_tax"));
       _towns.put(new Integer(townid), town);
     }
   } catch (SQLException e) {
     _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
   } finally {
     SqlUtil.close(rs);
     SqlUtil.close(pstm);
     SqlUtil.close(con);
   }
 }
Exemplo n.º 3
0
 public void updateTaxRate() {
   Connection con = null;
   PreparedStatement pstm = null;
   try {
     con = L1DatabaseFactory.getInstance().getConnection();
     pstm = con.prepareStatement("UPDATE towns SET tax_rate = tax_rate_reserved");
     pstm.execute();
   } catch (SQLException e) {
     _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
   } finally {
     SqlUtil.close(pstm);
     SqlUtil.close(con);
   }
 }
Exemplo n.º 4
0
 public void updateSalesMoneyYesterday() {
   Connection con = null;
   PreparedStatement pstm = null;
   try {
     con = L1DatabaseFactory.getInstance().getConnection();
     pstm =
         con.prepareStatement(
             "UPDATE towns SET sales_money_yesterday = sales_money, sales_money = 0");
     pstm.execute();
   } catch (SQLException e) {
     _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
   } finally {
     SqlUtil.close(pstm);
     SqlUtil.close(con);
   }
 }
 private void loadWeaponSkills(HashMap<Integer, L1WeaponSkill> weaponSkills) {
   Connection con = null;
   PreparedStatement pstm = null;
   ResultSet rs = null;
   try {
     PerformanceTimer timer = new PerformanceTimer();
     con = L1DatabaseFactory.getInstance().getConnection();
     pstm = con.prepareStatement("SELECT * FROM weapon_skills");
     rs = pstm.executeQuery();
     while (rs.next()) {
       int weaponId = rs.getInt("item_id");
       int skillId = rs.getInt("skill_id");
       boolean isErr = false;
       if (ItemTable.getInstance().getTemplate(weaponId) == null) {
         System.out.println(String.format(I18N_DOES_NOT_EXIST_ITEM_LIST, weaponId));
         // %s はアイテムリストに存在しません。
         isErr = true;
       }
       if (SkillTable.getInstance().findBySkillId(skillId) == null) {
         System.out.println(String.format(I18N_DOES_NOT_EXIST_SKILL_LIST, skillId));
         // %s はスキルリストに存在しません。
         isErr = true;
       }
       if (isErr) {
         continue;
       }
       int probability = rs.getInt("probability");
       int probEnchant = rs.getInt("prob_enchant");
       int fixDamage = rs.getInt("fix_damage");
       int randomDamage = rs.getInt("random_damage");
       boolean isArrowType = rs.getBoolean("arrow_type");
       boolean enableMr = rs.getBoolean("enable_mr");
       boolean enableAttrMr = rs.getBoolean("enable_attr_mr");
       L1WeaponSkill weaponSkill =
           new L1WeaponSkill(
               weaponId,
               probability,
               probEnchant,
               fixDamage,
               randomDamage,
               skillId,
               isArrowType,
               enableMr,
               enableAttrMr);
       weaponSkills.put(weaponId, weaponSkill);
     }
     _log.fine("Loaded weapon skill: " + weaponSkills.size() + "records");
     System.out.println("loading weapon skills...OK! " + timer.elapsedTimeMillis() + "ms");
   } catch (SQLException e) {
     _log.log(Level.SEVERE, "error while creating weapon_skills table", e);
   } finally {
     SqlUtil.close(rs, pstm, con);
   }
 }