Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include("puny_bulb");
- //variables globales
- global chip = getChips();
- global lowest = 0;
- var nameChip = [];
- global closest;
- global melee = 0;
- global weapons = getWeapons();
- for (var i = 0; i < count(chip)-1; i++) {
- nameChip[i] = getChipName(chip[i]);
- }
- debug(nameChip);
- if (getTurn() <2) {
- var weaponsName = [getWeaponName(weapons[0]),getWeaponName(weapons[1])];
- debug("Weapons : "+weaponsName);
- debug(getFightType());
- debug(getFightContext());
- }
- //fonctions :
- // sélection du poireau ennemi avec le moins de vie
- function bestEnemy() {
- var best = getNearestEnemy();
- var distance = [];
- var alive = getAliveEnemies();
- for (var enemy in alive) {
- push(distance, getPathLength(getCell(), getCell(enemy)));
- }
- best = alive[search(distance, arrayMin(distance))];
- debug(getName(best));
- return best;
- }
- //tirer sur l'ennemi
- function shoot() {
- if (not getAliveEnemiesCount()) {
- say("My job is done here");
- }
- var enemy = bestEnemy();
- var counter = 0;
- selectWeapon(enemy);
- var weapon = getWeapon();
- var cost = getWeaponCost(weapon);
- if (not inArray(getCellsToUseWeapon(enemy), getCell()) and getTP() >= cost) {
- moveTowardCell(closest,1);
- useWeapon(enemy);
- } else {
- useWeapon(enemy);
- }
- while (getTP() > 0 and getTP() > cost and counter < 10) {
- useWeapon(enemy);
- counter++;
- }
- if (getTP() < cost and inArray(getCellsToUseWeapon(enemy), getCell()) and weapon != melee ) {
- moveAwayFrom(enemy, 1);
- }
- // On utilise le sort sinon
- spell(enemy);
- }
- function selectWeapon(leek) {
- var usable = [];
- var closestCell = [];
- var uCells = [];
- var change = true;
- melee = 0;
- var equiped = getWeapon();
- for (var weapon in weapons) {
- push(usable, getCellsToUseWeapon(weapon, leek));
- if (getWeaponMaxRange(weapon) == 1){
- melee = weapon;
- }
- }
- for (var cells in usable[0]) {
- push(uCells, getPathLength(getCell(), cells));
- }
- push(closestCell, usable[0][search(uCells, arrayMin(uCells))]);
- uCells = [];
- for (var cells in usable[1]) {
- push(uCells, getPathLength(getCell(), cells));
- }
- push(closestCell, usable[1][search(uCells, arrayMin(uCells))]);
- if (getPathLength(getCell(), leek) <= getMP() and equiped != melee) {
- setWeapon(melee);
- change = false;
- }
- if (getPathLength(getCell(), closestCell[0]) < getPathLength(getCell(), closestCell[1]) and change){
- if (equiped != weapons[0]) {
- setWeapon(weapons[0]);
- }
- closest = closestCell[0];
- } else {
- if (equiped != weapons[1]) {
- setWeapon(weapons[1]);
- }
- closest = closestCell[1];
- }
- }
- function spell(enemy){
- var equipedChip = getChips();
- if ( inArray(getCellsToUseChip(CHIP_STALACTITE, enemy), getCell())) {
- for (var i = 0; i < 6; i++) {
- useChip(CHIP_STALACTITE, enemy);
- }
- }
- if ( inArray(getCellsToUseChip(CHIP_SPARK, enemy), getCell())) {
- for (var i = 0; i < 6; i++) {
- useChip(CHIP_SPARK, enemy);
- }
- }
- if (getLife(enemy) >= 0.5*getTotalLife(enemy) and getTurn() >=50) {
- moveAwayFrom(enemy);
- }
- }
- function heal(ally){
- if (getLife(ally)<=0.93*getTotalLife(ally)) {
- debug("envoi message heal");
- sendAll(MESSAGE_HEAL, ally);
- useChip(CHIP_VACCINE, ally);
- if (getLife(ally)<getTotalLife(ally)) {
- if (getChipEffectiveArea(CHIP_BANDAGE, getCell(ally))) {
- useChip(CHIP_BANDAGE, ally);
- useChip(CHIP_BANDAGE, ally);
- useChip(CHIP_BANDAGE, ally);
- }
- }
- }
- }
- function protect() {
- if (getTurn() > 1) {
- var proche = true;
- var distanceD = getCellDistance(getCell(), getCell(getNearestEnemy()));
- if (distanceD <= 2){
- proche = false;
- }
- var invocBulb = true;
- if (getCooldown(CHIP_PUNY_BULB) == 0 ) {
- for (var entity in getAliveAllies()) {
- if ( isSummon(entity)) {
- invocBulb = false;
- break;
- }
- }
- if (invocBulb) {
- var cell = getCell();
- var X = getCellX(cell);
- var Y = getCellY(cell);
- for (var i = -1; i <= 1 ; i++) {
- for (var j = -1; j <= 1 ; j++) {
- summon(CHIP_PUNY_BULB, getCellFromXY( X+i, Y+j ), AI_puny_bulb );
- }
- }
- }
- }
- //casque
- if (getCooldown(CHIP_HELMET) == 0 and getTP()>= getChipCost(CHIP_HELMET) and proche) {
- useChip(CHIP_HELMET, getLeek());
- }
- //bouclier
- if (getCooldown(CHIP_SHIELD) == 0 and getTP()>= getChipCost(CHIP_SHIELD)) {
- useChip(CHIP_SHIELD, getLeek());
- }
- //force +50
- //if (getCooldown(CHIP_PROTEIN) == 0 and getTP()>= getChipCost(CHIP_PROTEIN) and proche) {
- //useChip(CHIP_PROTEIN, getLeek());
- //}
- //agilité
- if (getCooldown(CHIP_STRETCHING) == 0 and getTP()>= getChipCost(CHIP_STRETCHING) and proche) {
- useChip(CHIP_STRETCHING, getLeek());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement