Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* /!\ ATTENTION; Ici on random sur toutes les maps n'ayant pas pour get_placesStr() "-1", si vous voulez faire en sorte que ce système ne soit actif que sur certaines maps il faut faire une condition supplémentaire! /!\ */
- //Dans la classe CryptManager on remplace la fonction parseStartCell() par celle là
- public static ArrayList<Case> parseStartCell(Carte map,int num)
- {
- ArrayList<Case> list = null;
- String infos = null;
- String placesStr = map.get_placesStr();
- if(!placesStr.equalsIgnoreCase("-1"))
- {
- placesStr = map.randomizeFightCell();
- infos = placesStr.split("\\|")[num];
- int a = 0;
- list = new ArrayList<Case>();
- while(a < infos.length())
- {
- list.add(map.getCase((getIntByHashedValue(infos.charAt(a))<<6) + getIntByHashedValue(infos.charAt (a+1))));
- a = a+2;
- }
- }
- return list;
- }
- // Et on ajoute:
- public static Map<Integer, LinkedList<Integer>> generateCellFight(Carte map)
- {
- ArrayList<Integer> possibleCells = new ArrayList<Integer>(map.GetCases().size());
- for(int cellID = 0; cellID < 1024; cellID++)//Pour chaque cellID compris entre 0 et 1024
- {
- if(map.getCase(cellID) == null) continue; // On vérifie si la cellule existe
- if(map.getCase(cellID).isWalkable(false)) // On vérifie qu'elle est walkable
- {
- possibleCells.add(cellID); // On l'ajoute à la liste des cellules possibles
- }
- }
- if(possibleCells.size() < 20) return null; // Si la liste des cellules possibles contient moins de cellule on retourne null
- Map<Integer, LinkedList<Integer>> Cells = new TreeMap<Integer, LinkedList<Integer>>();
- int team = 0; // Fighter Team
- LinkedList<Integer> cellsList = new LinkedList<Integer>();
- while(team <= 1) // On boucle jusqu'à ce que team == 1
- {
- do
- {
- switch((team == 0 && cellsList.size() == 0) ? 1 : Formulas.getRandomValue(1, 3))
- {
- case 1:
- //On retourne une cellule aléatoirement
- int cell = possibleCells.get(Formulas.getRandomValue(0, possibleCells.size() - 1));
- if(!cellsList.contains(cell)) cellsList.add(cell); //Si elle ne figure pas déjà dans la liste on l'ajoute
- break;
- default:
- int lastCell = 0;
- if(team == 1 && cellsList.size() == 0) //Si team == 1 et que la liste ne contient aucune cellule alors on prends la dernière valeur de la liste totale
- {
- lastCell = Cells.get(0).getLast();
- } else
- {
- lastCell = cellsList.getLast(); //Sinon on prends la derniere valeur de la liste temporaire
- }
- int cellNext = -1;
- switch(Formulas.getRandomValue(1, 4))
- {
- case 1:
- cellNext = Pathfinding.GetCaseIDFromDirrection(lastCell, 'a', map, true);
- if(possibleCells.contains(cellNext) && !cellsList.contains(cellNext)) cellsList.add(cellNext);
- break;
- case 2:
- cellNext = Pathfinding.GetCaseIDFromDirrection(lastCell, 'c', map, true);
- if(possibleCells.contains(cellNext) && !cellsList.contains(cellNext)) cellsList.add(cellNext);
- break;
- case 3:
- cellNext = Pathfinding.GetCaseIDFromDirrection(lastCell, 'e', map, true);
- if(possibleCells.contains(cellNext) && !cellsList.contains(cellNext)) cellsList.add(cellNext);
- break;
- case 4:
- cellNext = Pathfinding.GetCaseIDFromDirrection(lastCell, 'g', map, true);
- if(possibleCells.contains(cellNext) && !cellsList.contains(cellNext)) cellsList.add(cellNext);
- break;
- }
- break;
- }
- }while(cellsList.size() < 8);
- Cells.put(team, cellsList); // On ajoute toutes les cellules à la LinkedList
- team += 1; // On incrémente de team pour crée les cellules des deux équipes
- }
- return Cells;
- }
- //Dans la classe Carte on ajoute la méthode:
- public String randomizeFightCell()
- {
- StringBuilder toReturn = new StringBuilder();
- ArrayList<Integer> cellListTeam0 = new ArrayList<Integer>();
- ArrayList<Integer> cellListTeam1 = new ArrayList<Integer>();
- int team = 0;
- if(this != null)
- {
- for(Entry<Integer, LinkedList<Integer>> cellLists : CryptManager.generateCellFight(this).entrySet())
- {
- if(team == 0 && team == cellLists.getKey())
- {
- cellListTeam0.addAll(cellLists.getValue());
- for(int cell : cellListTeam0)
- {
- toReturn.append(CryptManager.cellID_To_Code(cell));
- }
- }
- }
- team = 1;
- toReturn.append("|");
- for(Entry<Integer, LinkedList<Integer>> cellLists : CryptManager.generateCellFight(this).entrySet())
- {
- if(team == 1 && team == cellLists.getKey())
- {
- cellListTeam1.addAll(cellLists.getValue());
- for(int cell : cellListTeam1)
- {
- toReturn.append(CryptManager.cellID_To_Code(cell));
- }
- }
- }
- }
- return toReturn.toString();
- }
Advertisement
Add Comment
Please, Sign In to add comment