SHARE
TWEET

Untitled

a guest Sep 16th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Unifyed : Ability {
  6.  
  7.     GameManager GM;
  8.  
  9.     Vector2 ownerPos;
  10.  
  11.     void Start(){
  12.         GM = Field.gameManager.GetComponent<GameManager> ();
  13.         gameObject.GetComponent<Creature> ().abils.Add (this);
  14.     }
  15.  
  16.     public override void Activate(){
  17.         Creature creature = gameObject.GetComponent<Creature> ();
  18.         ownerPos = new Vector2 (creature.x, creature.y);
  19.         List<Vector2> targets = new List<Vector2>();
  20.  
  21.         Queue<Vector2> q = new Queue<Vector2> ();
  22.         q.Enqueue (new Vector2 (ownerPos.x, ownerPos.y));
  23.  
  24.         bool[,] was = new bool[10, 10];
  25.         for (int x = 0; x < 10; x++)
  26.             for (int y = 0; y < 10; y++)
  27.                 was [x, y] = false;
  28.  
  29.         while (q.Count > 0) {
  30.             Vector2 cur = q.Dequeue ();
  31.             int cx = (int)cur.x;
  32.             int cy = (int)cur.y;
  33.             for (int dx = -1; dx <= 1; dx++) {
  34.                 for (int dy = -1; dy <= 1; dy++) {
  35.                     if (dx == 0 || dy == 0) {
  36.                         int x = cx + dx;
  37.                         int y = cy + dy;
  38.                         if (x >= 0 && x <= 9 && y >= 0 && y <= 9) {
  39.                             if (Field.field [x, y] == null) {
  40.                                 if (!was [x, y]) {
  41.                                     if (Mathf.Abs (x - (int)ownerPos.x) + Mathf.Abs (y - (int)ownerPos.y) <= creature.AP) {
  42.                                         was [x, y] = true;
  43.                                         q.Enqueue (new Vector2 (x, y));
  44.                                         targets.Add (new Vector2 (x, y));
  45.                                     }
  46.                                 }
  47.                             }
  48.                         }
  49.                     }
  50.                 }
  51.             }
  52.         }
  53.  
  54.  
  55.         if(creature.AP >= 2)
  56.         for (int dx = -1; dx <= 1; dx++) {
  57.             for (int dy = -1; dy <= 1; dy++) {
  58.                 if (creature.x + dx >= 0 && creature.x + dx <= 9 && creature.y + dy >= 0 && creature.y + dy <= 9) {
  59.                     if (Field.field [creature.x + dx, creature.y + dy] != null) {
  60.                         Creature neighbour = Field.field [creature.x + dx, creature.y + dy];
  61.                         if (neighbour.owner != creature.owner) {
  62.                             targets.Add (new Vector2 (creature.x + dx, creature.y + dy));
  63.                         }
  64.                     }
  65.                 }
  66.             }
  67.         }
  68.        
  69.         GM.Choose ( targets, Chosen );
  70.     }
  71.  
  72.     void Chosen(Vector2 choose){
  73.         GM.Chosen -= Chosen;
  74.         if ((int)choose.x != -1) {
  75.             int x = (int)choose.x;
  76.             int y = (int)choose.y;
  77.             if (Field .field[x, y] == null) {
  78.                 int dx = Mathf.Abs ((int)ownerPos.x - x);
  79.                 int dy = Mathf.Abs ((int)ownerPos.y - y);
  80.                 gameObject.GetComponent<Creature> ().Pay (dx + dy, 0);
  81.                 Field.MoveCreature ((int)ownerPos.x, (int)ownerPos.y, (int)choose.x, (int)choose.y);
  82.                 GM.Select ((int)choose.x, (int)choose.y);
  83.             } else {
  84.                 Creature target = Field.field [(int)choose.x, (int)choose.y];
  85.  
  86.                 AttackEvent attack = new AttackEvent (GetComponent<Creature>(), target);
  87.                 EventManager.Preprocess (attack);
  88.                 if (attack.alive) {
  89.                     Creature src = attack.source;
  90.                     Creature tgt = attack.target;
  91.                     DealDamageEvent myDamage = new DealDamageEvent (this, tgt, src.attack);
  92.                     EventManager.Preprocess (myDamage);
  93.                     if (myDamage.alive)
  94.                     if (myDamage.damage > 0)
  95.                         myDamage.target.hp -= myDamage.damage;
  96.                     EventManager.Postprocess (myDamage);
  97.  
  98.                     DealDamageEvent hisDamage = new DealDamageEvent (this, src, tgt.attack);
  99.                     EventManager.Preprocess (hisDamage);
  100.                     if (hisDamage.alive)
  101.                     if (hisDamage.damage > 0)
  102.                         hisDamage.target.hp -= hisDamage.damage;
  103.                     EventManager.Postprocess (hisDamage);
  104.  
  105.                     gameObject.GetComponent<Creature> ().Pay (2, 0);
  106.                 }
  107.                 EventManager.Postprocess (attack);
  108.             }
  109.         }
  110.     }
  111. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top