falyptus

AncestraR - Breed Codes

May 17th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.20 KB | None | 0 0
  1. // Dans la classe SQLManager:
  2.  
  3.     public static void LOAD_BREED_SPELLS()
  4.     {
  5.         try {
  6.             ResultSet RS = SQLManager.executeQuery("SELECT * from breed_spells;", Faith.STATIC_DB_NAME);
  7.             while (RS.next())
  8.             {
  9.                 World.addRaceSpell(new BreedSpell(
  10.                         RS.getInt("Breed"),
  11.                         RS.getInt("Level"),
  12.                         RS.getInt("SpellId"),
  13.                         RS.getInt("Pos")));
  14.             }
  15.             closeResultSet(RS);
  16.         } catch (SQLException e) {
  17.             System.out.println("Game: SQL ERROR: " + e.getMessage());
  18.             System.exit(1);
  19.         }
  20.     }
  21.    
  22.     public static void LOAD_BREEDS() {
  23.         try {
  24.             ResultSet RS = SQLManager.executeQuery("SELECT * from breed_data;", Faith.STATIC_DB_NAME);
  25.             while (RS.next())
  26.             {
  27.                 World.addBreed(new Breed(
  28.                         RS.getInt("Breed"),
  29.                         RS.getInt("StartLife"),
  30.                         RS.getInt("StartPA"),
  31.                         RS.getInt("StartPM"),
  32.                         RS.getInt("StartInitiative"),
  33.                         RS.getInt("StartProspecting"),
  34.                         RS.getInt("StartMap"),
  35.                         RS.getInt("StartCell"),
  36.                         RS.getString("Intelligence"),
  37.                         RS.getString("Wisdom"),
  38.                         RS.getString("Chance"),
  39.                         RS.getString("Agility"),
  40.                         RS.getString("Strenght"),
  41.                         RS.getString("Vitality")));
  42.             }
  43.             closeResultSet(RS);
  44.         } catch (SQLException e) {
  45.             System.out.println("Game: SQL ERROR: " + e.getMessage());
  46.             System.exit(1);
  47.         }
  48.     }
  49.  
  50. // Dans la classe World:
  51.  
  52.     private static Map<Integer, Breed> Breeds = new TreeMap<Integer, Breed>();
  53.     private static ArrayList<BreedSpell> BreedSpells = new ArrayList<BreedSpell>();
  54.  
  55.     public static ArrayList<BreedSpell> getBreedSpells()
  56.     {
  57.         return BreedSpells;
  58.         }
  59.    
  60.     public static void addRaceSpell(BreedSpell breedSpell)
  61.     {
  62.         BreedSpells.add(breedSpell);
  63.     }
  64.  
  65.     public static Breed getBreed(int breed)
  66.     {
  67.         return Breeds.get(breed);
  68.     }
  69.  
  70.     public static void addBreed(Breed breed)
  71.     {
  72.         Breeds.put(breed.getId(), breed);
  73.     }
  74.  
  75.     //Dans createWorld:
  76.     System.out.print("Loading breed data: ");
  77.     SQLManager.LOAD_BREEDS();
  78.     System.out.println("breed data were loaded");
  79.  
  80.     System.out.print("Loading breed spells: ");
  81.     SQLManager.LOAD_BREED_SPELLS();
  82.     System.out.println("breed spells were loaded");
  83.  
  84. // Dans la classe Personnage:
  85.  
  86.     public void spellPlacement()
  87.     {
  88.         Map<Integer, Character> toPlace = new TreeMap<Integer, Character>();
  89.         for(SortStats spell : _sorts.values())
  90.         {
  91.             for(BreedSpell breedSpell : World.getBreedSpells())
  92.             {
  93.                 if(breedSpell.getSpellId() == spell.getSpellID() && breedSpell.getBreed() == _classe)
  94.                 {
  95.                     char pos = CryptManager.getHashedValueByInt(breedSpell.getPos());
  96.                     for(Entry<Integer, Character> entry : _sortsPlaces.entrySet())
  97.                     {
  98.                         if(entry != null && entry.getValue() == pos)
  99.                         {
  100.                             continue;
  101.                         }
  102.                         toPlace.put(spell.getSpellID(), pos);
  103.                     }
  104.                 }
  105.             }
  106.         }
  107.     }
  108.    
  109.     public void learnBreedSpell()
  110.     {
  111.         List<BreedSpell> toLearn = new ArrayList<BreedSpell>();
  112.         for(BreedSpell breedSpell : World.getBreedSpells())
  113.         {
  114.             if(breedSpell.getBreed() == _classe && breedSpell.getLvl() <= _lvl && !hasSpell(breedSpell.getSpellId()))
  115.             {
  116.                 toLearn.add(breedSpell);
  117.             }
  118.         }
  119.         for(BreedSpell breedSpell : toLearn)
  120.         {
  121.             addSpell(breedSpell.getSpellId(), 1);
  122.         }
  123.     }
  124.  
  125.     public synchronized void addSpell(int spellId, int lvl)
  126.     {
  127.         if(!hasSpell(spellId))
  128.         {
  129.             if(World.getSort(spellId).getStatsByLevel(lvl)==null)
  130.             {
  131.                 GameServer.addToLog("[ERROR]Sort "+spellId+" lvl "+lvl+" non trouvé.");
  132.                 return;
  133.             }
  134.             _sorts.put(spellId, World.getSort(spellId).getStatsByLevel(lvl));
  135.         }
  136.     }
  137.    
  138.     public boolean hasSpell(int spellId)
  139.     {
  140.         return (getSortStatBySortIfHas(spellId) == null ? false : true);
  141.         }
  142.  
  143.     /*Dans CREATE_PERSONNAGE():
  144.     On retire:*/
  145.     perso._sorts = Constants.getStartSorts(classe);
  146.     for (int a = 1; a <= perso.get_lvl(); a++)
  147.     {
  148.         Constants.onLevelUpSpells(perso, a);
  149.     }
  150.     perso._sortsPlaces = Constants.getStartSortsPlaces(classe);
  151.     //Et on ajoute:
  152.     perso.learnBreedSpell();
  153.     perso.spellPlacement();
  154.  
  155.     /*Ensuite on replace les occurences de: Constants.onLevelUpSpells(this,_lvl); en: learnBreedSpell();, celles de Constants.getStartMap(_classe) en World.getBreed(classe).getStartMap(), celles de Constants.getStartCell(_classe) en World.getBreed(classe).getStartCell()*/
Advertisement
Add Comment
Please, Sign In to add comment