Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Unifyed : Ability {
- GameManager GM;
- Vector2 ownerPos;
- void Start(){
- GM = Field.gameManager.GetComponent<GameManager> ();
- gameObject.GetComponent<Creature> ().abils.Add (this);
- }
- public override void Activate(){
- Creature creature = gameObject.GetComponent<Creature> ();
- ownerPos = new Vector2 (creature.x, creature.y);
- List<Vector2> targets = new List<Vector2>();
- Queue<Vector2> q = new Queue<Vector2> ();
- q.Enqueue (new Vector2 (ownerPos.x, ownerPos.y));
- bool[,] was = new bool[10, 10];
- for (int x = 0; x < 10; x++)
- for (int y = 0; y < 10; y++)
- was [x, y] = false;
- while (q.Count > 0) {
- Vector2 cur = q.Dequeue ();
- int cx = (int)cur.x;
- int cy = (int)cur.y;
- for (int dx = -1; dx <= 1; dx++) {
- for (int dy = -1; dy <= 1; dy++) {
- if (dx == 0 || dy == 0) {
- int x = cx + dx;
- int y = cy + dy;
- if (x >= 0 && x <= 9 && y >= 0 && y <= 9) {
- if (Field.field [x, y] == null) {
- if (!was [x, y]) {
- if (Mathf.Abs (x - (int)ownerPos.x) + Mathf.Abs (y - (int)ownerPos.y) <= creature.AP) {
- was [x, y] = true;
- q.Enqueue (new Vector2 (x, y));
- targets.Add (new Vector2 (x, y));
- }
- }
- }
- }
- }
- }
- }
- }
- if(creature.AP >= 2)
- for (int dx = -1; dx <= 1; dx++) {
- for (int dy = -1; dy <= 1; dy++) {
- if (creature.x + dx >= 0 && creature.x + dx <= 9 && creature.y + dy >= 0 && creature.y + dy <= 9) {
- if (Field.field [creature.x + dx, creature.y + dy] != null) {
- Creature neighbour = Field.field [creature.x + dx, creature.y + dy];
- if (neighbour.owner != creature.owner) {
- targets.Add (new Vector2 (creature.x + dx, creature.y + dy));
- }
- }
- }
- }
- }
- GM.Choose ( targets, Chosen );
- }
- void Chosen(Vector2 choose){
- GM.Chosen -= Chosen;
- if ((int)choose.x != -1) {
- int x = (int)choose.x;
- int y = (int)choose.y;
- if (Field .field[x, y] == null) {
- int dx = Mathf.Abs ((int)ownerPos.x - x);
- int dy = Mathf.Abs ((int)ownerPos.y - y);
- gameObject.GetComponent<Creature> ().Pay (dx + dy, 0);
- Field.MoveCreature ((int)ownerPos.x, (int)ownerPos.y, (int)choose.x, (int)choose.y);
- GM.Select ((int)choose.x, (int)choose.y);
- } else {
- Creature target = Field.field [(int)choose.x, (int)choose.y];
- AttackEvent attack = new AttackEvent (GetComponent<Creature>(), target);
- EventManager.Preprocess (attack);
- if (attack.alive) {
- Creature src = attack.source;
- Creature tgt = attack.target;
- DealDamageEvent myDamage = new DealDamageEvent (this, tgt, src.attack);
- EventManager.Preprocess (myDamage);
- if (myDamage.alive)
- if (myDamage.damage > 0)
- myDamage.target.hp -= myDamage.damage;
- EventManager.Postprocess (myDamage);
- DealDamageEvent hisDamage = new DealDamageEvent (this, src, tgt.attack);
- EventManager.Preprocess (hisDamage);
- if (hisDamage.alive)
- if (hisDamage.damage > 0)
- hisDamage.target.hp -= hisDamage.damage;
- EventManager.Postprocess (hisDamage);
- gameObject.GetComponent<Creature> ().Pay (2, 0);
- }
- EventManager.Postprocess (attack);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement