Inheritance: MonoBehaviour
Ejemplo n.º 1
0
	public void Start() {
		Floor floor = Helper.Find<Floor>("Floor");
		gridManager = floor.GridManager;
		unit = GetComponent<BaseUnit>();

		soundEffectPLayer = GetComponentInChildren<SoundEffectPlayer>();

        LeaveSound = unit.GetComponent<BaseUnit>().LeaveSound;
        ArriveSound = unit.GetComponent<BaseUnit>().ArriveSound;

        if (LeaveSound.Any() || ArriveSound.Any())
	    {
            AudioSource audioSrc = gameObject.AddComponent<AudioSource>();
            LeaveArriveEffectPlayer = gameObject.GetComponent<AudioSource>();
	    }
        
	    if (unit is AvatarUnit)
	    {
	        isAvatarMover = true;
            currentAvatarUnit = (AvatarUnit)unit;
	    }
	    else
	    {
	        isAvatarMover = false;
	    }
	}
Ejemplo n.º 2
0
 public void _SetUpdeteCharacteristicsDelegate ( BaseUnit.UpdateBaseUnitCharacteristics updateBaseUnitCharacteristics, bool delete ) {
     if ( delete ) {
         this.updateBaseUnitCharacteristics -= updateBaseUnitCharacteristics;
     } else {
         this.updateBaseUnitCharacteristics += updateBaseUnitCharacteristics;
     }
 }
Ejemplo n.º 3
0
	public Vector2[] GetPathTo(Vector3 startPosition, Vector3 endPosition, BaseUnit unit, out int cost)
	{
		Vector2 startIndices = _gridManager.PositionToIndices(startPosition);
		Vector2 endIndices = _gridManager.PositionToIndices(endPosition);

		Node n = GoTo(startIndices, endIndices, unit);
		cost = n.GetTotalCost();

		bool foundTarget = n.Indices == endIndices;
		if (!foundTarget) 
			return null;
		
		List<Vector2> indices = new List<Vector2>();
		Node node = n; // Starts at the target and backtrace through parents back to beginning.
		while (node != null)
		{
			indices.Add(node.Indices);
			node = node.Parent;
		}

		// Construct a path where each entry is one move in some direction.
		Vector2[] path = new Vector2[indices.Count-1];
		int counter = 0;
		for (int i = indices.Count-1; i > 0; i--) {
			path[counter] = indices[i-1] - indices[i]; // The direction is the difference in indices.
			counter++;
		}

		return path;
	}
Ejemplo n.º 4
0
	private IEnumerator Explode(BaseUnit hitUnit) {
		Vector3 startPosition = transform.position;
		Vector3 endPosition = startPosition + transform.rotation * Vector3.forward * 0.5f;
		endPosition.y = startPosition.y;
		BaseTile.HandleOccupy(this, OccupiedTile, null);

		float t = 0;
		float moveSpeed = this.GetComponent<ProjectileMover>().moveSpeed;
		while (t < 1f)
		{
			t += Time.deltaTime*moveSpeed;
			transform.position = Vector3.Lerp(startPosition, endPosition, Mathf.Clamp01(t));
			yield return null;
		}

		if (onHitPfx) {
			GameObject.Instantiate(onHitPfx, transform.position, Quaternion.identity);
		}

		if (hitUnit is AvatarUnit) {
			hitUnit.SendMessage("KillAvatar");
		}

        if (hitUnit.BreaksByProjectileAndMedusa)
        {
            hitUnit.DestroyUnit();
        }
		DestroyUnit();
	}
Ejemplo n.º 5
0
    public override void DamageUnit(int damage, BaseUnit attacker) {
        AudioSource audio = GetComponent<AudioSource>();
        audio.Play();
        Animator anim = GetComponent<Animator>();
        _attackedBy = attacker;
        if (CarryUnit != null) {
            CarryUnit.GetComponent<BaseUnit>().DamageUnit(damage, null);
            anim.Play("Damage", 1);
            if (attacker != null)
                GameObject.Find("Board").GetComponent<GameController>().NextQueueItem = false;
            else
                GameObject.Find("Board").GetComponent<GameController>().NextQueueItem = true;
            return;
        }
		Health -= damage;
		if (Health > 0) {
			anim.Play ("Damage", 1);
            if (attacker != null)
                GameObject.Find("Board").GetComponent<GameController>().NextQueueItem = false;
            else
                GameObject.Find("Board").GetComponent<GameController>().NextQueueItem = true;
            return;
		}
        Health = 0;
		GetComponent<SpriteRenderer> ().color = Color.white;
		Animator a = GetComponent<Animator> ();
		a.SetInteger ("StackSize", 0);

		if (CarryUnit != null) {
			GameObject.Destroy (CarryUnit);
			CarryUnit = null;
		}
        GameObject.Destroy(gameObject, 2f);
    }
Ejemplo n.º 6
0
 void OnAttack(BaseUnit unit)
 {
     base.NavMeshAgent.Stop();
     Debug.Log(base.UnitName + " -> " + unit.UnitName);
     Turret.LookAt(unit.transform);
     AttackSystem.Play();
 }
Ejemplo n.º 7
0
	private Node GoTo(Vector2 start, Vector2 target, BaseUnit unit)
	{
		if (DEBUG) Debug.Log(start + " " + target);
		int h1 = GetManhattanDistance(start, target);
		
		_priorityQueue = new BinaryHeap<Node>(25);
		_priorityQueue.Enqueue(new Node(start, null, 0, h1));
		
		Node bestGuess = null;
		int heuristic = int.MaxValue;
		while (heuristic > 0 && !_priorityQueue.IsEmpty()) 
		{
			bestGuess = _priorityQueue.Dequeue();
			heuristic = bestGuess.Heuristic;
			if (DEBUG) Debug.Log("Heruistic " + heuristic + " " + bestGuess.GetTotalCost());
			if (heuristic == 0)
				break;
			
			Expand(bestGuess, ref target, unit);
			
			if (DEBUG) Debug.Log("Size " + _priorityQueue.IsEmpty());
		}
		_closedSet.Clear();
		_priorityQueue.Clear();
		return bestGuess;
	}
Ejemplo n.º 8
0
    protected override void OnArrived(BaseUnit unit, BaseTile previousTile)
    {
        base.OnArrived(unit, previousTile);

        if (redObjectsToNotify != null)
        {
            foreach (EventListener el in redObjectsToNotify)
            {
                el.ReceiveEvent(EventMessage.ToggleUpDown);
            }

            foreach (EventListener el in blueObjectsToNotify)
            {
                el.ReceiveEvent(EventMessage.ToggleUpDown);
            }

            foreach (EventListener el in RedBlueButtonTilesToNotify)
            {
                el.ReceiveEvent(EventMessage.ToggleColor);
            }
        }
        else
        {
            Debug.Log("redObjectsToNotify has not been set");
        }

        if (IsPortalTile)
        {
            TeleportUnit(unit, previousTile, DestinationTeleportTile);
        }
    }
Ejemplo n.º 9
0
	protected override void OnArrived(BaseUnit unit, BaseTile previousTile) 
	{
        base.OnArrived(unit, previousTile);
	    if ((_opened || debugOpen) && unit is AvatarUnit)
	    {
	        for (int i = 0; i < LevelSelectionAndUILogic.ListOfAllLevelJSON.Count; i++)
	        {
                if (LevelSelectionAndUILogic.ListOfAllLevelJSON[i].Name.Equals(Application.loadedLevelName))
	            {
                    LevelSelectionAndUILogic.ListOfAllLevelJSON[i].IsPassed = true;
                    //LevelSelectionAndUILogic.ListOfAllLevelJSON[i].IsActive = true;          //its sufficient with just setting the current map to "haspassed" true, as its just first the first level that uses is active, but if future changes need em its here...
                    //LevelSelectionAndUILogic.ListOfAllLevelJSON[i + 1].IsActive = true;      //same comment as above.
	                break;
	            }
	        }

	        LevelSelectionAndUILogic.SaveToJson();          //saves the level progression
            StartCoroutine(_sceneTransition.LoadLevelWithDelay(0.1f, "NEW_GameStartScene"));
	    }

        if (IsPortalTile && !_opened)
        {
            TeleportUnit(unit, previousTile, DestinationTeleportTile);
        }
	}
Ejemplo n.º 10
0
 protected void attackIfEnemy(BaseUnit otherUnit, DamagableEntity otherUnitDamage)
 {
     if (!checkTeam (otherUnit))//checks if its not on your team
     {
         //attack (otherUnitDamage);//passes it to the attack function
         attack(otherUnitDamage);
     }
 }
Ejemplo n.º 11
0
	public override void OnCollided(BaseUnit unit) {
		if (unit is ProjectileUnit)
			return;

		if (unit is AvatarUnit || (unit is BaseUnit && !canPassThroughUnits)) {
			StartCoroutine(Explode(unit));
		}
	}
Ejemplo n.º 12
0
 void TestMovement()
 {
     BaseUnit spaceMarine = new BaseUnit();
     //spaceMarine.setMovementType(MovementType.NORMAL);
     MovementPath movementPath = new MovementPath();
     //TODO: mock movementPath
     MovementEngine.getInstance().move(spaceMarine, movementPath);
 }
Ejemplo n.º 13
0
	public override void OnArrivedToMe(BaseUnit unit) {
		if (unit is AvatarUnit) {
			foreach (EventListener el in _objectsToNotify)
				el.ReceiveEvent(EventMessage.Unregister);

			DestroyUnit();
		}
	}
Ejemplo n.º 14
0
 public static void Attack(BaseUnit unit)
 {
     foreach (var item in FriendlyUnits.Where(x => x.IsSelected))
     {
         //item.NavMeshAgent.Stop();
         item.SendMessage("OnAttack", unit);
     }
 }
Ejemplo n.º 15
0
	public static void TeleportTo(BaseUnit unit, BaseTile sourceTile, BaseTile destinationTile) {
		Vector3 position = destinationTile.transform.position;
		position.y = unit.transform.position.y;
		unit.transform.position = position;

		HandleOccupy(unit, sourceTile, destinationTile);
		HandleArrive(unit, sourceTile, destinationTile);
	}
Ejemplo n.º 16
0
 protected Product(string name, BaseUnit measure, bool isVegetarian, FoodType type, ShoppingUnit unit, decimal price)
 {
     this.Name = name;
     this.BaseUnit = measure;
     this.IsVegetarian = isVegetarian;
     this.ShoppingUnit = unit;
     this.PricePerShoppingUnit = price;
     this.FoodType = type;
 }
Ejemplo n.º 17
0
    protected override void OnArrived(BaseUnit unit, BaseTile previousTile)
    {
        base.OnArrived(unit, previousTile);

        if (IsPortalTile)
        {
            TeleportUnit(unit, previousTile, DestinationTeleportTile);
        }
    }
Ejemplo n.º 18
0
	public override bool CanWalkOn(BaseUnit unit) {
		bool canWalkOn = base.CanWalkOn(unit);
		if (!canWalkOn)
			return false;

		Vector3 direction = Vector3.Normalize(unit.transform.position - transform.position);
		Vector3 forward = transform.rotation * Vector3.forward;
		return Vector3.Dot(direction, forward) <= 0;
	}
Ejemplo n.º 19
0
 public void ShowUnitInfo(BaseUnit unit)
 {
     gameObject.SetActive(true);
     UnitName.text = unit.UnitName;
     UnitHp.maxValue = unit.MaxHp;
     UnitHp.value = unit.Hp;
     UnitEnergy.maxValue = unit.MaxEnergy;
     UnitEnergy.value = unit.Energy;
     UnitType.text = unit.Type.ToString();
 }
Ejemplo n.º 20
0
 private LineRenderDisplay GetLineRenderOf(BaseUnit targetBaseUnit)
 {
     for (int i = 0; i < lineRenderDisplays.Count; i++)
     {
         LineRenderDisplay lineRender = lineRenderDisplays[i];
         if (lineRender.BaseUnit == targetBaseUnit)
             return lineRender;
     }
     return null;
 }
Ejemplo n.º 21
0
    public override IEnumerator DoEffectCoroutine(BaseUnit target, GameObject source, Vector3 attackPosition)
    {
        // THIS IS VISUAL ONLY! :)
        GameObject splash = (GameObject) GameObject.Instantiate(Resources.Load("Splash"), target.transform.position, Quaternion.Euler(Vector3.up));
        splash.transform.localScale = new Vector3(splashRadius, splash.transform.localScale.y, splashRadius);

        yield return new WaitForSeconds(0.2f);
        UnityEngine.Object.Destroy(splash);

        yield return null;
    }
Ejemplo n.º 22
0
    public bool TryAddUnit(BaseUnit unit)
    {
        Debug.Log ("Count " + units.Count + ". Limit " + roomLimit);
        if (units.Count < roomLimit) {
            units.Add (unit);
            unit.unitRoom = this;
            return true;
        }

        return false;
    }
Ejemplo n.º 23
0
 public void ShowActionButtons( BaseUnit.UnitType unitType, HeroUnit.ActionSpell actionSpell )
 {
     switch ( unitType ) {
         case BaseUnit.UnitType.hero:
             cuiv.AddHeroActionButton( actionSpell );
             break;
         default:
             cuiv.HideActionButton();
             break;
     }
 }
Ejemplo n.º 24
0
    public override void DoEffect(BaseUnit target, GameObject source, Vector3 attackPosition, ref float damage)
    {
        Debug.Log("Stunning");
        timeout = Time.time + duration;

        if (target.stunTimeout < timeout)
        {
            target.stunned = true;
            target.stunTimeout = timeout;
        }
    }
Ejemplo n.º 25
0
    public override void Merge(BaseUnit unit) {
        if (CarryUnit == null) {
            CarryUnit = unit.gameObject;
            CarryUnit.SetActive(false);
            TraversableEnvironments = _defaultEnvironments.Concat(unit.TraversableEnvironments).ToArray();
        }
        else {
            CarryUnit.GetComponent<BaseUnit>().StackSize += unit.StackSize;
            GameObject.Destroy(unit.gameObject);
        }

    }
Ejemplo n.º 26
0
    public bool isSaveableAgainstWeapon(BaseUnit defender, Weapon attackingWeapon)
    {
        //TODO check invunerable save & special rules
        //Check special rules for saves
        bool hasCoverOrInvunerableSave = false;
        if(hasCoverOrInvunerableSave)
            return true;

        if(attackingWeapon.getArmorPierce() <= defender.getSavingThrow())
            return false;

        return true;
    }
Ejemplo n.º 27
0
	private void Occupy(BaseUnit unit) {
		int mask = unit.LayerMask;
		foreach (Layer l in Enum.GetValues(typeof(Layer))) {
			int layerMask = (int)l;
			if ((layerMask & mask) == layerMask) {
				BaseUnit u;
				if (_occupyingUnits.TryGetValue(l, out u))
					_previousUnits.Add(u);

				_occupyingUnits[l] = unit;
			}
		}
		unit.OccupiedTile = this;
	}
Ejemplo n.º 28
0
 void changeTarget(Collider other)
 {
     BaseUnit newAgro = other.gameObject.GetComponent <BaseUnit>();//Store the baseUnit on other
     if (newAgro != null)// check if its null
     {
         if (agrodUnit == null)// check if im attacking something
         {
             if (!myBase.checkTeam (newAgro)) // check if its on the enemy team
             {
                 agrodUnit = newAgro; // store agroed unit into the new agro
             }
         }
     }
 }
Ejemplo n.º 29
0
    public override IEnumerator DoEffectCoroutine(BaseUnit target, GameObject source, Vector3 attackPosition)
    {
        var cc = target.GetComponent<CharacterController>();
        var direction = (target.transform.position - attackPosition).normalized;
        for (int i = 0; i < _framesToKnockbackOver; i++) {
            yield return new WaitForFixedUpdate();
            if (target.dead)
                break;

            float move = EasedMove(i/(float)_framesToKnockbackOver);
            cc.Move(direction * (move * (knockbackPower/_framesToKnockbackOver)));
        }
        yield return null;
    }
Ejemplo n.º 30
0
	private void OnItemEquip(BaseUnit unit, EUnitEqupmentSlot slot, EItemKey oldItemKey, EItemKey newItemKey) {
		if (UnitsConfig.Instance.IsHero(unit.Data.Key) && Global.Instance.Player.Heroes.HaveHero(unit.Data.Key)) {
			PlayerItem oldItem = GetItem(oldItemKey);
			if (oldItem != null) {
				oldItem.ItemCarrier = EUnitKey.Idle;
				oldItem.ItemSlot = EUnitEqupmentSlot.None;
			}

			PlayerItem newItem = GetItem(newItemKey);
			if (newItem != null) {
				newItem.ItemCarrier = unit.Data.Key;
				newItem.ItemSlot = slot;
			}
		}
	}