Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // new module script
- int AbsInt(static Maths, int value) ///////////////////////////////////valeur absolue
- {
- if (value < 0)
- return -value;
- return value;
- }
- function ennemy_face(int k) {
- ///correction for faciung the right direction-->to compensate the blank space below the character on the sprites and have a more accurate visual.
- ///blancplayer is the one from the main character,ennemis[k].base is an int that is given to each type of monster at load.
- float alfa2 = Maths.RadiansToDegrees(Maths.ArcTan2(-IntToFloat(player.y - character[k].y + ennemis[k].base - blancplayer), IntToFloat(player.x - character[k].x)));
- if (alfa2 < 22.5 && alfa2 >= -22.5) {
- character[k].FaceDirection(eDirectionRight);
- } else if (alfa2 >= 22.5 && alfa2 < 67.5) {
- character[k].FaceDirection(eDirectionUpRight);
- } else if (alfa2 >= 67.5 && alfa2 < 112.5) {
- character[k].FaceDirection(eDirectionUp);
- } else if (alfa2 >= 112.5 && alfa2 < 157.5) {
- character[k].FaceDirection(eDirectionUpLeft);
- } else if (alfa2 >= 157.5 || alfa2 < -157.5) {
- character[k].FaceDirection(eDirectionLeft);
- } else if (alfa2 > -157.5 && alfa2 < -112.5) {
- character[k].FaceDirection(eDirectionDownLeft);
- } else if (alfa2 >= -112.5 && alfa2 < -67.5) {
- character[k].FaceDirection(eDirectionDown);
- } else if (alfa2 >= -67.5 && alfa2 < -22.5) {
- character[k].FaceDirection(eDirectionDownRight);
- }
- }
- function Patrol(int k) {
- if (ennemis[k].statut < 2 && ennemis[k].agro == 0) {
- ///ennemis[k].statut=0 : idle, 1 chasing or fighting, 2 dead.
- ///ennemis[k].agro=0 :patrolling, 1 chasing, 2 giving up chase
- if (ennemis[k].cdpatrol > 0) {
- ennemis[k].cdpatrol -= 1;
- } else { ///cd over
- ///50 de part et d autre next position is claculated around an initial position set at firstload with position1_x,position1_y.
- ///This way the next waypoint is in a random distance of 50px on each side of this base, 30px vertically
- int suivantx = Random(200) + ennemis[k].position1_x - 100;
- int suivanty = Random(120) + ennemis[k].position1_y - 60;
- character[k].Walk(suivantx, suivanty, eNoBlock, eWalkableAreas);
- //resets the timer,with a bit of random so that everybody doesn't move at the same time
- ennemis[k].cdpatrol = 400 + Random(200);
- }
- }
- }
- function Agrosuit(int k) {
- character[k].SetWalkSpeed(6, 3); //accelerates when chasing
- character[k].AnimationSpeed = 1;
- character[k].FollowCharacter(player, ennemis[k].hitbox, 0); //ennemis{k].hitbox so that it isn't stuck to the player
- }
- function Attack_ennemy(int k) {
- //ennemis[k].agro=3;///combat mode
- 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
- {
- //ennemis[k].agro=1;///follow mode
- character[k].FollowCharacter(player, ennemis[k].hitbox, 0);
- } else {
- if (ennemis[k].cd == 0 && character[k].View != ennemis[k].skin + 2) { ///ennemis[k].skin+2.View =attack animation for ennemy k
- character[k].FollowCharacter(null);
- ennemis[k].agro = 4; ///autoattack mode
- ennemy_face(k);
- character[k].LockView(ennemis[k].skin + 2, eStopMoving);
- character[k].Animate(character[k].Loop, 1, eOnce, eNoBlock);
- }
- }
- }
- function ciblage2() { ///display infos about the selected ennemy, not really relevant I guess
- LblEnnemyname.Text = String.Format("%s", ennemis[Target.ID].Nameennemy);
- int diff = ennemis[Target.ID].niveau - Level;
- if (diff > 4) {
- Lbllvl.TextColor = 49152;
- } //rouge
- else if (diff < 5 && diff > 2) {
- Lbllvl.TextColor = 64512;
- } //orange
- else if (diff < 3 && diff > -3) {
- Lbllvl.TextColor = 65504;
- } //jaune
- else if (diff < -2 && diff > -5) {
- Lbllvl.TextColor = 1536;
- } //vert
- else {
- Lbllvl.TextColor = 33808;
- } //gris
- Lbllvl.Text = String.Format("%d", ennemis[Target.ID].niveau);
- if (ennemis[Target.ID].elite == true) {
- gEnnemybar.BackgroundGraphic = 1870;
- } ///graphique elite
- else {
- gEnnemybar.BackgroundGraphic = 1869;
- }
- if (ennemis[Target.ID].statut < 2) {
- gLifebarennemy.Visible = true;
- }
- gEnnemybar.Visible = true;
- }
- function Agro(int k) { //this one might be the most problematic
- if (ennemis[k].statut < 2) { ///alive
- float x1 = IntToFloat(player.x);
- float x2 = IntToFloat(character[k].x);
- float y1 = IntToFloat(player.y - blancplayer);
- float y2 = IntToFloat(character[k].y - ennemis[k].base);
- int dist = FloatToInt(Maths.RaiseToPower(Maths.RaiseToPower(x1 - x2, 2.0) + (Maths.RaiseToPower(y1 - y2, 2.0)), 0.5), eRoundDown);
- if (dist < 200 && Maths.AbsInt(player.y - blancplayer - character[k].y + ennemis[k].base) < 100 && ennemis[k].agro == 0) { ///aggro range
- gAnnonces.Visible = true;
- Lblannonce.Text = "AGGRO";
- Lblannonce.TextColor = 63488;
- ///czonerouge is a character that displays a red circle at the feet of the selected ennemy
- if (cZonerouge.Transparency == 100) {
- cZonerouge.Transparency = 30;
- Target = character[k];
- ciblage2();
- }
- encombat += 1; ///another variable for combat mode display
- Game.AudioClips[ennemis[k].sonbase].Play(); //generic sound for ennemy k
- //saves the last position for replacing
- ennemis[k].position2_x = character[k].x;
- ennemis[k].position2_y = character[k].y;
- Agrosuit(k);
- ennemis[k].agro = 1;
- ennemis[k].cd = 0;
- }
- if (ennemis[k].agro == 1 || ennemis[k].agro == 3 || ennemis[k].agro == 4) { ///chasing
- 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
- {
- encombat -= 1;
- ennemis[k].HP = ennemis[k].HPfull; //ennemy heals itself
- Game.AudioClips[ennemis[k].sonbase + 4].Play();
- ennemis[k].agro = 2;
- character[k].FollowCharacter(null);
- character[k].Walk(ennemis[k].position2_x, ennemis[k].position2_y, eNoBlock, eWalkableAreas);
- }
- 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
- {
- //character[k].StopMoving();
- Attack_ennemy(k);
- }
- }
- if (ennemis[k].agro == 2 && character[k].x == ennemis[k].position2_x && character[k].y == ennemis[k].position2_y) { ///back in place after replacing
- ennemis[k].agro = 0;
- ennemis[k].HP = ennemis[k].HPfull;
- //slows down when patrolling
- character[k].SetWalkSpeed(3, 3);
- character[k].AnimationSpeed = 4;
- ennemis[k].cdpatrol = 200;
- }
- }
- }
- function calcul_degat_ennemy(int k) { //calculates the damage the ennemy deals-->irrelevant for the issue!
- int d1 = FloatToInt(ennemis[k].attack1 - ennemis[k].attack1 * 0.2, eRoundDown); ///borne min
- int d2 = FloatToInt(ennemis[k].attack1 + ennemis[k].attack1 * 0.2, eRoundUp); ///bornemax
- int d3 = d1 + Random(d2 - d1);
- int dcrit = Random(99);
- int desquive = Random(99);
- int dbloc = Random(99);
- float reduction = IntToFloat(Perso_armure) / (IntToFloat(Perso_armure + 400 + (ennemis[k].niveau * 85)));
- if (dcrit < ennemis[k].crit) {
- d3 = d3 * 2;
- critsubi = true;
- } ///coup critique
- else {
- critsubi = false;
- }
- if (desquive * 100 < FloatToInt(Perso_esquive * 100.0, eRoundDown)) {
- d3 = 0;
- esquive = 1;
- } else if (dbloc * 100 < FloatToInt(Perso_blocage * 100.0, eRoundDown)) {
- aShield1.Play();
- d3 = d3 - Perso_degatsbloques;
- if (d3 < 1) {
- esquive = 2; ///bloqué completement
- d3 = 0;
- } else {
- esquive = 0;
- }
- } //fin blocage
- else {
- esquive = 0;
- d3 = FloatToInt(((100.0 - (Perso_reduc * 100.0)) * IntToFloat(d3) / 100.0), eRoundUp);
- }
- return d3;
- }
- function Damage_display_ennemy(int degats, bool special) { ///the animation that makes the damage numbers float up and fade. Not relevant here!
- int g = 14;
- while (gui[g].Visible == true) {
- g++;
- }
- if (esquive == 1) {
- gui[g].Controls[0].AsLabel.TextColor = 65535;
- gui[g].Controls[0].AsLabel.Font = eFontSpeech;
- gui[g].Controls[0].AsLabel.Text = "Esquive";
- aDodge.Play();
- } else if (esquive == 2) {
- gui[g].Controls[0].AsLabel.TextColor = 65535;
- gui[g].Controls[0].AsLabel.Font = eFontSpeech;
- gui[g].Controls[0].AsLabel.Text = "Blocage";
- //aDodge.Play();
- } else {
- //---------couleur
- if (special == true) { ///changer pour enemy
- gui[g].Controls[0].AsLabel.TextColor = 32799; ///violet
- } else {
- gui[g].Controls[0].AsLabel.TextColor = 63488; ///rouge
- }
- //---------------------
- if (critsubi == true) {
- gui[g].Controls[0].AsLabel.Font = eFontCrit;
- aCritiquemelee.Play();
- } else {
- gui[g].Controls[0].AsLabel.Font = eFontSpeech;
- }
- gui[g].Controls[0].AsLabel.Text = String.Format("%d", degats);
- }
- gui[g].Visible = true;
- gui[g].X = 220;
- gui[g].Y = 120;
- }
- function Damage_ennemy(int k) { ///irrelevant
- int dmg = calcul_degat_ennemy(k);
- // String text = String.Format("%d", dmg);
- Perso_currentlife -= dmg;
- Damage_display_ennemy(dmg, false);
- }
- function atk_special_ennemy(int k, int n) { ///irrelevant, and still work in progress (uses some functions I removed to clarify for you)
- if (n == 0) { //poison
- Damage_Over_Time(n);
- } else if (n == 1) { //debuff
- Debuff(n);
- }
- }
- function coupanim_ennemy(int i, int j, int k) { //damages when hit
- if (character[k].Frame == i && character[k].View == j) {
- if (ennemis[k].speatkcd > 0) {
- Game.AudioClips[ennemis[k].sonbase + 1].Play();
- Damage_ennemy(k); //normal hit
- ennemis[k].speatkcd -= 1;
- } else { //special hit ennemy
- atk_special_ennemy(k, ennemis[k].nomatkspe);
- Game.AudioClips[ennemis[k].sonbase + 2].Play();
- ennemis[k].speatkcd = ennemis[k].speatk; //reinitialise
- }
- ennemis[k].cd = ennemis[k].cdattaque;
- character[k].Frame++;
- }
- }
- function finanim_ennemy(int i, int j, int k) { ////unlocks the attack animation, and refreshes attack cooldown
- if (character[k].Frame == i && character[k].View == j) {
- character[k].UnlockView();
- ennemis[k].agro = 3;
- }
- }
- void repeatedly_execute() {
- //---------------------------------------------------------
- for (int i = 0; i < 30; i++) ///30 character ennemies
- {
- 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
- {
- Patrol(i);
- Agro(i);
- coupanim_ennemy(ennemis[i].framecoup, ennemis[i].skin + 2, i);
- finanim_ennemy(ennemis[i].framefin, ennemis[i].skin + 2, i);
- if (ennemis[i].cd > 0 && ennemis[i].agro > 0) { //-----------------------cd atk auto
- ennemis[i].cd--;
- }
- if (ennemis[i].agro == 3) { //---------autoattack continues
- Attack_ennemy(i);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement