Advertisement
Guest User

Untitled

a guest
Apr 4th, 2024
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.14 KB | None | 0 0
  1. // new module script
  2.  
  3. int AbsInt(static Maths, int value) ///////////////////////////////////valeur absolue
  4. {
  5.   if (value < 0)
  6.     return -value;
  7.   return value;
  8. }
  9.  
  10. function ennemy_face(int k) {
  11.   ///correction for faciung the right direction-->to compensate the blank space below the character on the sprites and have a more accurate visual.
  12.   ///blancplayer is the one from the main character,ennemis[k].base is an int that is given to each type of monster at load.
  13.   float alfa2 = Maths.RadiansToDegrees(Maths.ArcTan2(-IntToFloat(player.y - character[k].y + ennemis[k].base - blancplayer), IntToFloat(player.x - character[k].x)));
  14.   if (alfa2 < 22.5 && alfa2 >= -22.5) {
  15.     character[k].FaceDirection(eDirectionRight);
  16.   } else if (alfa2 >= 22.5 && alfa2 < 67.5) {
  17.     character[k].FaceDirection(eDirectionUpRight);
  18.   } else if (alfa2 >= 67.5 && alfa2 < 112.5) {
  19.     character[k].FaceDirection(eDirectionUp);
  20.   } else if (alfa2 >= 112.5 && alfa2 < 157.5) {
  21.     character[k].FaceDirection(eDirectionUpLeft);
  22.   } else if (alfa2 >= 157.5 || alfa2 < -157.5) {
  23.     character[k].FaceDirection(eDirectionLeft);
  24.   } else if (alfa2 > -157.5 && alfa2 < -112.5) {
  25.     character[k].FaceDirection(eDirectionDownLeft);
  26.   } else if (alfa2 >= -112.5 && alfa2 < -67.5) {
  27.     character[k].FaceDirection(eDirectionDown);
  28.   } else if (alfa2 >= -67.5 && alfa2 < -22.5) {
  29.     character[k].FaceDirection(eDirectionDownRight);
  30.   }
  31.  
  32. }
  33.  
  34.  
  35.  
  36.  
  37. function Patrol(int k) {
  38.   if (ennemis[k].statut < 2 && ennemis[k].agro == 0) {
  39.     ///ennemis[k].statut=0 : idle, 1 chasing or fighting, 2 dead.
  40.     ///ennemis[k].agro=0 :patrolling, 1 chasing, 2 giving up chase
  41.     if (ennemis[k].cdpatrol > 0) {
  42.       ennemis[k].cdpatrol -= 1;
  43.     } else { ///cd over
  44.       ///50 de part et d autre  next position is claculated around an initial position set at firstload with position1_x,position1_y.
  45.       ///This way the next waypoint is in a random distance of 50px on each side of this base, 30px vertically
  46.       int suivantx = Random(200) + ennemis[k].position1_x - 100;
  47.       int suivanty = Random(120) + ennemis[k].position1_y - 60;
  48.  
  49.       character[k].Walk(suivantx, suivanty, eNoBlock, eWalkableAreas);
  50.       //resets the timer,with a bit of random so that everybody doesn't move at the same time
  51.       ennemis[k].cdpatrol = 400 + Random(200);
  52.     }
  53.   }
  54. }
  55.  
  56.  
  57. function Agrosuit(int k) {
  58.   character[k].SetWalkSpeed(6, 3); //accelerates when chasing
  59.   character[k].AnimationSpeed = 1;
  60.   character[k].FollowCharacter(player, ennemis[k].hitbox, 0); //ennemis{k].hitbox so that it isn't stuck to the player
  61. }
  62.  
  63.  
  64.  
  65. function Attack_ennemy(int k) {
  66.   //ennemis[k].agro=3;///combat mode
  67.  
  68.   if ((Maths.AbsInt(player.x - character[k].x) > ennemis[k].hitbox) || (Maths.AbsInt(player.y - blancplayer - character[k].y + ennemis[k].base) > ennemis[k].hitbox / 2)) ///not in range
  69.   {
  70.     //ennemis[k].agro=1;///follow mode
  71.     character[k].FollowCharacter(player, ennemis[k].hitbox, 0);
  72.   } else {
  73.     if (ennemis[k].cd == 0 && character[k].View != ennemis[k].skin + 2) { ///ennemis[k].skin+2.View =attack animation for ennemy k
  74.       character[k].FollowCharacter(null);
  75.       ennemis[k].agro = 4; ///autoattack mode
  76.       ennemy_face(k);
  77.       character[k].LockView(ennemis[k].skin + 2, eStopMoving);
  78.       character[k].Animate(character[k].Loop, 1, eOnce, eNoBlock);
  79.     }
  80.   }
  81.  
  82.  
  83. }
  84.  
  85. function ciblage2() { ///display infos about the selected ennemy, not really relevant I guess
  86.   LblEnnemyname.Text = String.Format("%s", ennemis[Target.ID].Nameennemy);
  87.   int diff = ennemis[Target.ID].niveau - Level;
  88.   if (diff > 4) {
  89.     Lbllvl.TextColor = 49152;
  90.   } //rouge
  91.   else if (diff < 5 && diff > 2) {
  92.     Lbllvl.TextColor = 64512;
  93.   } //orange
  94.   else if (diff < 3 && diff > -3) {
  95.     Lbllvl.TextColor = 65504;
  96.   } //jaune
  97.   else if (diff < -2 && diff > -5) {
  98.     Lbllvl.TextColor = 1536;
  99.   } //vert
  100.   else {
  101.     Lbllvl.TextColor = 33808;
  102.   } //gris
  103.   Lbllvl.Text = String.Format("%d", ennemis[Target.ID].niveau);
  104.  
  105.   if (ennemis[Target.ID].elite == true) {
  106.     gEnnemybar.BackgroundGraphic = 1870;
  107.   } ///graphique elite
  108.   else {
  109.     gEnnemybar.BackgroundGraphic = 1869;
  110.   }
  111.   if (ennemis[Target.ID].statut < 2) {
  112.     gLifebarennemy.Visible = true;
  113.   }
  114.   gEnnemybar.Visible = true;
  115. }
  116.  
  117.  
  118.  
  119. function Agro(int k) { //this one might be the most problematic
  120.   if (ennemis[k].statut < 2) { ///alive
  121.  
  122.     float x1 = IntToFloat(player.x);
  123.     float x2 = IntToFloat(character[k].x);
  124.     float y1 = IntToFloat(player.y - blancplayer);
  125.     float y2 = IntToFloat(character[k].y - ennemis[k].base);
  126.  
  127.     int dist = FloatToInt(Maths.RaiseToPower(Maths.RaiseToPower(x1 - x2, 2.0) + (Maths.RaiseToPower(y1 - y2, 2.0)), 0.5), eRoundDown);
  128.     if (dist < 200 && Maths.AbsInt(player.y - blancplayer - character[k].y + ennemis[k].base) < 100 && ennemis[k].agro == 0) { ///aggro range
  129.       gAnnonces.Visible = true;
  130.       Lblannonce.Text = "AGGRO";
  131.       Lblannonce.TextColor = 63488;
  132.       ///czonerouge is a character that displays a red circle at the feet of the selected ennemy
  133.       if (cZonerouge.Transparency == 100) {
  134.         cZonerouge.Transparency = 30;
  135.         Target = character[k];
  136.         ciblage2();
  137.       }
  138.  
  139.       encombat += 1; ///another variable for combat mode display
  140.       Game.AudioClips[ennemis[k].sonbase].Play(); //generic sound for ennemy k
  141.       //saves the last position for replacing
  142.       ennemis[k].position2_x = character[k].x;
  143.       ennemis[k].position2_y = character[k].y;
  144.       Agrosuit(k);
  145.       ennemis[k].agro = 1;
  146.       ennemis[k].cd = 0;
  147.     }
  148.     if (ennemis[k].agro == 1 || ennemis[k].agro == 3 || ennemis[k].agro == 4) { ///chasing
  149.       if ((Maths.AbsInt(character[k].x - ennemis[k].position2_x) > 400) || (Maths.AbsInt(character[k].y - ennemis[k].position2_y) > 200)) ////too far from initial position, so stop chasing
  150.       {
  151.         encombat -= 1;
  152.         ennemis[k].HP = ennemis[k].HPfull; //ennemy heals itself
  153.         Game.AudioClips[ennemis[k].sonbase + 4].Play();
  154.         ennemis[k].agro = 2;
  155.         character[k].FollowCharacter(null);
  156.         character[k].Walk(ennemis[k].position2_x, ennemis[k].position2_y, eNoBlock, eWalkableAreas);
  157.  
  158.       }
  159.  
  160.       if ((Maths.AbsInt(player.x - character[k].x) < ennemis[k].hitbox) && (Maths.AbsInt(player.y - blancplayer - character[k].y + ennemis[k].base) < ennemis[k].hitbox / 2)) ///range for attack
  161.       {
  162.         //character[k].StopMoving();
  163.         Attack_ennemy(k);
  164.       }
  165.  
  166.     }
  167.     if (ennemis[k].agro == 2 && character[k].x == ennemis[k].position2_x && character[k].y == ennemis[k].position2_y) { ///back in place after replacing
  168.       ennemis[k].agro = 0;
  169.       ennemis[k].HP = ennemis[k].HPfull;
  170.       //slows down when patrolling
  171.       character[k].SetWalkSpeed(3, 3);
  172.       character[k].AnimationSpeed = 4;
  173.       ennemis[k].cdpatrol = 200;
  174.     }
  175.  
  176.   }
  177. }
  178.  
  179.  
  180. function calcul_degat_ennemy(int k) { //calculates the damage the ennemy deals-->irrelevant for the issue!
  181.   int d1 = FloatToInt(ennemis[k].attack1 - ennemis[k].attack1 * 0.2, eRoundDown); ///borne min
  182.   int d2 = FloatToInt(ennemis[k].attack1 + ennemis[k].attack1 * 0.2, eRoundUp); ///bornemax
  183.   int d3 = d1 + Random(d2 - d1);
  184.   int dcrit = Random(99);
  185.   int desquive = Random(99);
  186.   int dbloc = Random(99);
  187.   float reduction = IntToFloat(Perso_armure) / (IntToFloat(Perso_armure + 400 + (ennemis[k].niveau * 85)));
  188.   if (dcrit < ennemis[k].crit) {
  189.     d3 = d3 * 2;
  190.     critsubi = true;
  191.   } ///coup critique
  192.   else {
  193.     critsubi = false;
  194.   }
  195.   if (desquive * 100 < FloatToInt(Perso_esquive * 100.0, eRoundDown)) {
  196.     d3 = 0;
  197.     esquive = 1;
  198.   } else if (dbloc * 100 < FloatToInt(Perso_blocage * 100.0, eRoundDown)) {
  199.     aShield1.Play();
  200.     d3 = d3 - Perso_degatsbloques;
  201.     if (d3 < 1) {
  202.       esquive = 2; ///bloquĂ© completement
  203.       d3 = 0;
  204.     } else {
  205.       esquive = 0;
  206.     }
  207.   } //fin blocage
  208.   else {
  209.     esquive = 0;
  210.     d3 = FloatToInt(((100.0 - (Perso_reduc * 100.0)) * IntToFloat(d3) / 100.0), eRoundUp);
  211.   }
  212.   return d3;
  213.  
  214. }
  215.  
  216.  
  217. function Damage_display_ennemy(int degats, bool special) { ///the animation that makes the damage numbers float up and fade. Not relevant here!
  218.   int g = 14;
  219.   while (gui[g].Visible == true) {
  220.     g++;
  221.   }
  222.   if (esquive == 1) {
  223.     gui[g].Controls[0].AsLabel.TextColor = 65535;
  224.     gui[g].Controls[0].AsLabel.Font = eFontSpeech;
  225.     gui[g].Controls[0].AsLabel.Text = "Esquive";
  226.     aDodge.Play();
  227.   } else if (esquive == 2) {
  228.     gui[g].Controls[0].AsLabel.TextColor = 65535;
  229.     gui[g].Controls[0].AsLabel.Font = eFontSpeech;
  230.     gui[g].Controls[0].AsLabel.Text = "Blocage";
  231.     //aDodge.Play();
  232.   } else {
  233.     //---------couleur
  234.     if (special == true) { ///changer pour enemy
  235.       gui[g].Controls[0].AsLabel.TextColor = 32799; ///violet
  236.     } else {
  237.       gui[g].Controls[0].AsLabel.TextColor = 63488; ///rouge
  238.     }
  239.     //---------------------
  240.  
  241.     if (critsubi == true) {
  242.       gui[g].Controls[0].AsLabel.Font = eFontCrit;
  243.       aCritiquemelee.Play();
  244.     } else {
  245.       gui[g].Controls[0].AsLabel.Font = eFontSpeech;
  246.  
  247.     }
  248.  
  249.     gui[g].Controls[0].AsLabel.Text = String.Format("%d", degats);
  250.   }
  251.   gui[g].Visible = true;
  252.   gui[g].X = 220;
  253.   gui[g].Y = 120;
  254. }
  255.  
  256.  
  257.  
  258. function Damage_ennemy(int k) { ///irrelevant
  259.   int dmg = calcul_degat_ennemy(k);
  260.   // String text = String.Format("%d", dmg);
  261.   Perso_currentlife -= dmg;
  262.   Damage_display_ennemy(dmg, false);
  263.  
  264. }
  265.  
  266.  
  267.  
  268. function atk_special_ennemy(int k, int n) { ///irrelevant, and still work in progress (uses some functions I removed to clarify for you)
  269.   if (n == 0) { //poison
  270.     Damage_Over_Time(n);
  271.   } else if (n == 1) { //debuff
  272.     Debuff(n);
  273.   }
  274. }
  275.  
  276. function coupanim_ennemy(int i, int j, int k) { //damages when hit
  277.   if (character[k].Frame == i && character[k].View == j) {
  278.     if (ennemis[k].speatkcd > 0) {
  279.       Game.AudioClips[ennemis[k].sonbase + 1].Play();
  280.       Damage_ennemy(k); //normal hit
  281.       ennemis[k].speatkcd -= 1;
  282.     } else { //special hit ennemy
  283.       atk_special_ennemy(k, ennemis[k].nomatkspe);
  284.       Game.AudioClips[ennemis[k].sonbase + 2].Play();
  285.       ennemis[k].speatkcd = ennemis[k].speatk; //reinitialise
  286.     }
  287.     ennemis[k].cd = ennemis[k].cdattaque;
  288.     character[k].Frame++;
  289.   }
  290. }
  291.  
  292.  
  293. function finanim_ennemy(int i, int j, int k) { ////unlocks the attack animation, and refreshes attack cooldown
  294.   if (character[k].Frame == i && character[k].View == j) {
  295.     character[k].UnlockView();
  296.     ennemis[k].agro = 3;
  297.   }
  298. }
  299.  
  300.  
  301.  
  302.  
  303.  
  304. void repeatedly_execute() {
  305.  
  306.  
  307.   //---------------------------------------------------------
  308.   for (int i = 0; i < 30; i++) ///30 character ennemies
  309.   {
  310.     if (Region.GetAtRoomXY(character[i].x, character[i].y - ennemis[i].base) == Region.GetAtRoomXY(player.x, player.y - blancplayer)) ////to not waste memory on distant ennemies
  311.     {
  312.       Patrol(i);
  313.       Agro(i);
  314.       coupanim_ennemy(ennemis[i].framecoup, ennemis[i].skin + 2, i);
  315.       finanim_ennemy(ennemis[i].framefin, ennemis[i].skin + 2, i);
  316.  
  317.       if (ennemis[i].cd > 0 && ennemis[i].agro > 0) { //-----------------------cd atk auto
  318.         ennemis[i].cd--;
  319.       }
  320.       if (ennemis[i].agro == 3) { //---------autoattack continues
  321.         Attack_ennemy(i);
  322.       }
  323.     }
  324.   }
  325.  
  326. }
  327.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement