Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global gChips = [CHIP_SPARK, CHIP_BANDAGE, CHIP_PROTEIN, CHIP_HELMET];
- global gChipsCooldown = [0, 0, 0, 0];
- global gAttkPos = 0;
- global gHealPos = 1;
- global gBuffPos = 2;
- global gHealPercent = 80;
- global gObstacle = getObstacle();
- global gWeapon = WEAPON_PISTOL;
- if (getWeapon() == null)
- setWeapon(gWeapon);
- var enemy = getNearestEnemy();
- getBuffed();
- if (getCellDistance(getCell(), getCell(enemy)) <= getWeaponMaxScope(gWeapon))
- {
- debug("Trame: Utilisation du pistolet.");
- if (!attackCellWithWeapon(gWeapon, getCell(enemy)))
- debug("[Main] - Ne peut attaquer la cible.");
- if (moveTowardCell(getHideFromTarget(enemy)) <= 0)
- debug("[hitAndRun] - Ne peut se cacher.");
- }
- else
- {
- debug("Trame: Utilisation de l'algorithm d'attaquer & reculer.");
- hitAndRun(enemy);
- }
- debug("Nombre d'instructions: " + getInstructionsCount());
- function getBuffed()
- {
- for (var i = gBuffPos; i < count(gChips); i++)
- if (getTurn() >= gChipsCooldown[i])
- gChipsCooldown[i] = 0;
- for (var i = gBuffPos; i < count(gChips); i++)
- {
- if (!gChipsCooldown[i])
- {
- if (!healTarget(gChips[i], getLeek()))
- debug("[getBuffed] - Ne peut être buff.");
- else
- {
- gChipsCooldown[i] = getTurn() + getChipCooldown(gChips[i]);
- debug("BUFF -> " + getChipName(gChips[i]) + " - Prochaine utilisation: Tour N°" + gChipsCooldown[i]);
- }
- }
- else
- debug("BUFF -> " + getChipName(gChips[i]) + " - Encore " + (gChipsCooldown[i]-getTurn()) + " tour(s)");
- }
- }
- function hitAndRun(target)
- {
- var limit = getChipMaxScope(gChips[gAttkPos]);
- if (needToHealPercent(target, gHealPercent))
- if (!healTarget(gChips[gHealPos], getLeek()))
- debug("[hitAndRun] - Le toon ne peut pas se soigner.");
- if (getTP() >= getChipCost(gChips[gAttkPos]))
- {
- if (getCellDistance(getCell(), getCell(target)))
- {
- var cell = getCellToUseChip(gChips[gAttkPos], target);
- if (needToApproach(target, limit))
- if (moveTowardCell(cell) <= 0)
- debug("[hitAndRun] - Ne peut rejoindre la cellule.");
- if (getCell() === cell)
- if (!attackCellWithChip(gChips[gAttkPos], getCell(target)))
- debug("[hitAndRun] - Ne peut attaquer la cible.");
- }
- else
- if (!attackCellWithChip(gChips[gAttkPos], getCell(target)))
- debug("[hitAndRun] - Ne peut attaquer la cible. (2)");
- }
- if (needToEscape(target, limit) && getMP())
- if (moveTowardCell(getHideFromTarget(target)) <= 0)
- debug("[hitAndRun] - Ne peut se cacher.");
- }
- function attackCellWithChip(chip, cell)
- {
- if (getDistance(getCell(), cell) > getChipMaxScope(chip) || getTP() < getChipCost(chip))
- return (false);
- while (getTP() >= getChipCost(chip))
- useChipOnCell(chip, cell);
- return (true);
- }
- function attackCellWithWeapon(weapon, cell)
- {
- if (getDistance(getCell(), cell) > getWeaponMaxScope(weapon) || getTP() < getWeaponCost(weapon))
- return (false);
- while (getTP() >= getWeaponCost(weapon))
- useWeaponOnCell(cell);
- return (true);
- }
- function needToEscape(enemy, limit)
- {
- var distance = getCellDistance(getCell(), getCell(enemy)) - getMP(enemy);
- if (distance <= limit && getMP())
- return ((limit - distance > getMP()) ? getMP() : limit - distance);
- return (0);
- }
- function needToApproach(enemy, limit)
- {
- return ((getCellDistance(getCell(), getCell(enemy))) > limit && getMP());
- }
- function needToHealPercent(target, value)
- {
- //if (value < 1) value *= 100;
- return (getLife(target) < (getTotalLife(target) * value / 100));
- }
- function healTarget(chip, target)
- {
- if (getDistance(getCell(), getCell(target)) > getChipMaxScope(chip) || getTP() < getChipCost(chip))
- return (false);
- return (useChip(chip, target) >= 0);
- }
- function getObstacle()
- {
- var array = [];
- for (var cell = 0; cell < 613; cell++)
- if (getCellContent(cell) === CELL_OBSTACLE)
- push(array, cell);
- return (array);
- }
- function getTopSideHidePositions(array)
- {
- var aTop = [];
- for (var cell = 0; cell < count(array); cell++)
- if (getCellContent(array[cell] - 18) === CELL_EMPTY)
- push(aTop, array[cell] - 18);
- return (aTop);
- }
- function getBotSideHidePositions(array)
- {
- var aBot = [];
- for (var cell = 0; cell < count(array); cell++)
- if (getCellContent(array[cell] + 18) === CELL_EMPTY)
- push(aBot, array[cell] + 18);
- return (aBot);
- }
- function getLeftSideHidePositions(array)
- {
- var aLeft = [];
- for (var cell = 0; cell < count(array); cell++)
- if (getCellContent(array[cell] + 17) === CELL_EMPTY)
- push(aLeft, array[cell] + 17);
- return (aLeft);
- }
- function getRightSideHidePositions(array)
- {
- var aRight = [];
- for (var cell = 0; cell < count(array); cell++)
- if (getCellContent(array[cell] - 17) === CELL_EMPTY)
- push(aRight, array[cell] - 17);
- return (aRight);
- }
- function getTargetCardinalPosition(target)
- {
- return (getCellCardinalPosition(getCell(target)));
- }
- function getCellCardinalPosition(cell)
- {
- var targetY = floor(cell/17.5);
- var targetX = floor(cell-(targetY*17.5));
- var myY = floor(getCell()/17.5);
- var myX = floor(getCell()-(myY*17.5));
- if (myY <= targetY && myX >= targetX)
- return (0); //Left
- else if (myY <= targetY && myX <= targetX)
- return (1); //Bot
- else if (myY >= targetY && myX >= targetX)
- return (2); //Top
- else if (myY >= targetY && myX <= targetX)
- return (3); //Right
- debug("[Cardinal Position] Une erreur est survenue.");
- }
- function getHidePositionsFromCardinalPosition(cardinal)
- {
- //var array = getObstacle();
- var array = gObstacle;
- if (cardinal === 3)
- return (getLeftSideHidePositions(array));
- if (cardinal === 2)
- return (getBotSideHidePositions(array));
- if (cardinal === 1)
- return (getTopSideHidePositions(array));
- if (cardinal === 0)
- return (getRightSideHidePositions(array));
- return (4); //Erreur
- }
- function getHideFromTarget(target)
- {
- var aDist = [];
- var pos = getTargetCardinalPosition(target);
- var aHide = getHidePositionsFromCardinalPosition(pos);
- var limit = getMP(target) + getWeaponMaxScope(getWeapon(target)) + 1;
- for (var cell = 0; cell < count(aHide); cell++)
- {
- if (getLife(target) > 0)
- {
- var enemypath = (getCellDistance(getCell(target), aHide[cell]) <= limit);
- push(aDist, getCellDistance(getCell(), aHide[cell] + (enemypath * 100)));
- }
- }
- return aHide[search(aDist, arrayMin(aDist))];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement