Advertisement
Zoellingam

toioupylol

Oct 31st, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.25 KB | None | 0 0
  1.  
  2. global gChips = [CHIP_SPARK, CHIP_BANDAGE, CHIP_PROTEIN, CHIP_HELMET];
  3. global gChipsCooldown = [0, 0, 0, 0];
  4. global gAttkPos = 0;
  5. global gHealPos = 1;
  6. global gBuffPos = 2;
  7. global gHealPercent = 80;
  8. global gObstacle = getObstacle();
  9. global gWeapon = WEAPON_PISTOL;
  10.  
  11. if (getWeapon() == null)
  12. setWeapon(gWeapon);
  13.  
  14. var enemy = getNearestEnemy();
  15.  
  16. getBuffed();
  17.  
  18. if (getCellDistance(getCell(), getCell(enemy)) <= getWeaponMaxScope(gWeapon))
  19. {
  20. debug("Trame: Utilisation du pistolet.");
  21. if (!attackCellWithWeapon(gWeapon, getCell(enemy)))
  22. debug("[Main] - Ne peut attaquer la cible.");
  23. if (moveTowardCell(getHideFromTarget(enemy)) <= 0)
  24. debug("[hitAndRun] - Ne peut se cacher.");
  25. }
  26. else
  27. {
  28. debug("Trame: Utilisation de l'algorithm d'attaquer & reculer.");
  29. hitAndRun(enemy);
  30. }
  31.  
  32. debug("Nombre d'instructions: " + getInstructionsCount());
  33.  
  34. function getBuffed()
  35. {
  36. for (var i = gBuffPos; i < count(gChips); i++)
  37. if (getTurn() >= gChipsCooldown[i])
  38. gChipsCooldown[i] = 0;
  39. for (var i = gBuffPos; i < count(gChips); i++)
  40. {
  41. if (!gChipsCooldown[i])
  42. {
  43. if (!healTarget(gChips[i], getLeek()))
  44. debug("[getBuffed] - Ne peut être buff.");
  45. else
  46. {
  47. gChipsCooldown[i] = getTurn() + getChipCooldown(gChips[i]);
  48. debug("BUFF -> " + getChipName(gChips[i]) + " - Prochaine utilisation: Tour N°" + gChipsCooldown[i]);
  49. }
  50. }
  51. else
  52. debug("BUFF -> " + getChipName(gChips[i]) + " - Encore " + (gChipsCooldown[i]-getTurn()) + " tour(s)");
  53. }
  54. }
  55.  
  56. function hitAndRun(target)
  57. {
  58. var limit = getChipMaxScope(gChips[gAttkPos]);
  59.  
  60. if (needToHealPercent(target, gHealPercent))
  61. if (!healTarget(gChips[gHealPos], getLeek()))
  62. debug("[hitAndRun] - Le toon ne peut pas se soigner.");
  63. if (getTP() >= getChipCost(gChips[gAttkPos]))
  64. {
  65. if (getCellDistance(getCell(), getCell(target)))
  66. {
  67. var cell = getCellToUseChip(gChips[gAttkPos], target);
  68.  
  69. if (needToApproach(target, limit))
  70. if (moveTowardCell(cell) <= 0)
  71. debug("[hitAndRun] - Ne peut rejoindre la cellule.");
  72. if (getCell() === cell)
  73. if (!attackCellWithChip(gChips[gAttkPos], getCell(target)))
  74. debug("[hitAndRun] - Ne peut attaquer la cible.");
  75. }
  76. else
  77. if (!attackCellWithChip(gChips[gAttkPos], getCell(target)))
  78. debug("[hitAndRun] - Ne peut attaquer la cible. (2)");
  79. }
  80. if (needToEscape(target, limit) && getMP())
  81. if (moveTowardCell(getHideFromTarget(target)) <= 0)
  82. debug("[hitAndRun] - Ne peut se cacher.");
  83. }
  84.  
  85. function attackCellWithChip(chip, cell)
  86. {
  87. if (getDistance(getCell(), cell) > getChipMaxScope(chip) || getTP() < getChipCost(chip))
  88. return (false);
  89. while (getTP() >= getChipCost(chip))
  90. useChipOnCell(chip, cell);
  91. return (true);
  92. }
  93.  
  94. function attackCellWithWeapon(weapon, cell)
  95. {
  96. if (getDistance(getCell(), cell) > getWeaponMaxScope(weapon) || getTP() < getWeaponCost(weapon))
  97. return (false);
  98. while (getTP() >= getWeaponCost(weapon))
  99. useWeaponOnCell(cell);
  100. return (true);
  101. }
  102.  
  103. function needToEscape(enemy, limit)
  104. {
  105. var distance = getCellDistance(getCell(), getCell(enemy)) - getMP(enemy);
  106. if (distance <= limit && getMP())
  107. return ((limit - distance > getMP()) ? getMP() : limit - distance);
  108. return (0);
  109. }
  110.  
  111. function needToApproach(enemy, limit)
  112. {
  113. return ((getCellDistance(getCell(), getCell(enemy))) > limit && getMP());
  114. }
  115.  
  116. function needToHealPercent(target, value)
  117. {
  118. //if (value < 1) value *= 100;
  119. return (getLife(target) < (getTotalLife(target) * value / 100));
  120. }
  121.  
  122. function healTarget(chip, target)
  123. {
  124. if (getDistance(getCell(), getCell(target)) > getChipMaxScope(chip) || getTP() < getChipCost(chip))
  125. return (false);
  126. return (useChip(chip, target) >= 0);
  127. }
  128.  
  129. function getObstacle()
  130. {
  131. var array = [];
  132.  
  133. for (var cell = 0; cell < 613; cell++)
  134. if (getCellContent(cell) === CELL_OBSTACLE)
  135. push(array, cell);
  136. return (array);
  137. }
  138.  
  139. function getTopSideHidePositions(array)
  140. {
  141. var aTop = [];
  142.  
  143. for (var cell = 0; cell < count(array); cell++)
  144. if (getCellContent(array[cell] - 18) === CELL_EMPTY)
  145. push(aTop, array[cell] - 18);
  146. return (aTop);
  147. }
  148.  
  149. function getBotSideHidePositions(array)
  150. {
  151. var aBot = [];
  152.  
  153. for (var cell = 0; cell < count(array); cell++)
  154. if (getCellContent(array[cell] + 18) === CELL_EMPTY)
  155. push(aBot, array[cell] + 18);
  156. return (aBot);
  157. }
  158.  
  159. function getLeftSideHidePositions(array)
  160. {
  161. var aLeft = [];
  162.  
  163. for (var cell = 0; cell < count(array); cell++)
  164. if (getCellContent(array[cell] + 17) === CELL_EMPTY)
  165. push(aLeft, array[cell] + 17);
  166. return (aLeft);
  167. }
  168.  
  169. function getRightSideHidePositions(array)
  170. {
  171. var aRight = [];
  172.  
  173. for (var cell = 0; cell < count(array); cell++)
  174. if (getCellContent(array[cell] - 17) === CELL_EMPTY)
  175. push(aRight, array[cell] - 17);
  176. return (aRight);
  177. }
  178.  
  179. function getTargetCardinalPosition(target)
  180. {
  181. return (getCellCardinalPosition(getCell(target)));
  182. }
  183.  
  184. function getCellCardinalPosition(cell)
  185. {
  186. var targetY = floor(cell/17.5);
  187. var targetX = floor(cell-(targetY*17.5));
  188. var myY = floor(getCell()/17.5);
  189. var myX = floor(getCell()-(myY*17.5));
  190.  
  191. if (myY <= targetY && myX >= targetX)
  192. return (0); //Left
  193. else if (myY <= targetY && myX <= targetX)
  194. return (1); //Bot
  195. else if (myY >= targetY && myX >= targetX)
  196. return (2); //Top
  197. else if (myY >= targetY && myX <= targetX)
  198. return (3); //Right
  199. debug("[Cardinal Position] Une erreur est survenue.");
  200. }
  201.  
  202. function getHidePositionsFromCardinalPosition(cardinal)
  203. {
  204. //var array = getObstacle();
  205. var array = gObstacle;
  206.  
  207. if (cardinal === 3)
  208. return (getLeftSideHidePositions(array));
  209. if (cardinal === 2)
  210. return (getBotSideHidePositions(array));
  211. if (cardinal === 1)
  212. return (getTopSideHidePositions(array));
  213. if (cardinal === 0)
  214. return (getRightSideHidePositions(array));
  215. return (4); //Erreur
  216. }
  217.  
  218. function getHideFromTarget(target)
  219. {
  220. var aDist = [];
  221. var pos = getTargetCardinalPosition(target);
  222. var aHide = getHidePositionsFromCardinalPosition(pos);
  223. var limit = getMP(target) + getWeaponMaxScope(getWeapon(target)) + 1;
  224.  
  225. for (var cell = 0; cell < count(aHide); cell++)
  226. {
  227. if (getLife(target) > 0)
  228. {
  229. var enemypath = (getCellDistance(getCell(target), aHide[cell]) <= limit);
  230. push(aDist, getCellDistance(getCell(), aHide[cell] + (enemypath * 100)));
  231. }
  232. }
  233. return aHide[search(aDist, arrayMin(aDist))];
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement