private void Update()
    {
        //Removes units from the list if they have died
        for (int i = 0; i < enemies.Count;)
        {
            if (enemies[i] == null)
            {
                enemies.RemoveAt(i);
            }

            else
            {
                i++;
            }
        }

        //The targeted enemy is always the first enemy the unit sees
        if (enemies.Count > 0)
        {
            enemy = enemies[0];
        }

        //Stops the enemy from shooting and moving towards a target when there is no target
        if (enemy == null && offensivePlaceablesRef != null)
        {
            readyToShoot = false;
            offensivePlaceablesRef.moveToTarget = false;
        }
    }
Ejemplo n.º 2
0
    public void AddPlaceableData(PlaceableData placeableData)
    {
        placeableData.ID = totalCreatedObjects;

        Placeables.Add(placeableData);
        totalCreatedObjects++;
    }
Ejemplo n.º 3
0
        public Actor AddActor(Actor template, string name, Location location)
        {
            var actor = template.CreateActorInstance(name, location);

            Placeables.Add(actor);
            return(actor);
        }
Ejemplo n.º 4
0
        public override void CopyFrom(TactileDataContent other)
        {
            CheckSameClass(other);

            var item = (Data_Item)other;

            copy_traits(item);

            Heal_Val       = item.Heal_Val;
            Heal_Percent   = item.Heal_Percent;
            Door_Key       = item.Door_Key;
            Chest_Key      = item.Chest_Key;
            Dancer_Ring    = item.Dancer_Ring;
            Torch_Radius   = item.Torch_Radius;
            Placeable      = item.Placeable;
            Repair_Val     = item.Repair_Val;
            Repair_Percent = item.Repair_Percent;
            Boost_Text     = item.Boost_Text;
            Stat_Boost     = new int[item.Stat_Boost.Length];
            Array.Copy(item.Stat_Boost, Stat_Boost, Stat_Boost.Length);
            Growth_Boost = new int[item.Growth_Boost.Length];
            Array.Copy(item.Growth_Boost, Growth_Boost, Growth_Boost.Length);
            Stat_Buff = new int[item.Stat_Buff.Length];
            Array.Copy(item.Stat_Buff, Stat_Buff, Stat_Buff.Length);
            Promotes = new List <int>(item.Promotes);
        }
Ejemplo n.º 5
0
    /// <summary>
    /// Counts the amount of keys in Placeables and sets the value as keysRemaining
    /// </summary>
    public int GatherKeys()
    {
        int keys = Placeables.FindAll(isKey).Count;

        keysRemaining = keys;
        return(keys);
    }
Ejemplo n.º 6
0
    private void OnTriggerEnter(Collider other)
    {
        // Checks if the hit collider is a trigger
        if (other.isTrigger != true)
        {
            // Sets the arrow's parent to that of the hit object, so that it sticks.
            gravity  = 0;
            velocity = new Vector3(0, 0, 0);

            this.transform.parent = other.transform;
        }

        //Checks if the arrow has hit a bodypart and deals damage to the body part's parent.
        Placeables enemyUnit = null;

        if (other.CompareTag("BodyPart"))
        {
            enemyUnit = other.GetComponentInParent <Placeables>();
        }

        //Deals damage to the target it has hit if it is an enemy
        if (enemyUnit != null && enemyUnit.currentTeam != myUnit.currentTeam)
        {
            enemyUnit.DealDamage(myUnit.damage);
        }
    }
    public void OnTriggerEnter(Collider other)
    {
        if (other.tag == "CheckForEnemy" || other.tag == "Goldmine") //Goldmine doesn't use the CheckForEnemy collider so it has a different tag
        {
            targets = other.GetComponentsInParent <Placeables>();
        }

        if (targets != null)
        {
            for (int i = 0; i < targets.Length; i++)
            {
                if (targets[i].currentTeam != offensivePlaceablesRef.currentTeam && enemies.Contains(targets[i]) == false)
                {
                    enemy = targets[i];
                    enemies.Add(enemy);
                    enemy = enemies[0];
                }
            }

            if (enemy != null && offensivePlaceablesRef.currentTeam != enemy.currentTeam)
            {
                //If the unit isn't a turret, move towards the target (turrets cannot move ofcourse)
                if (offensivePlaceablesRef.turret == false)
                {
                    offensivePlaceablesRef.moveToTarget = true;
                }
                readyToShoot = true;
                offensivePlaceablesRef.target = enemy;
            }
        }
    }
Ejemplo n.º 8
0
 /// <summary>
 /// Checks that the level is prepared. Returns false if there is no spawner.
 /// </summary>
 public bool LevelReady()
 {
     if (Placeables.FirstOrDefault(placeable => placeable.ObstacleName == "Ball Spawner") != null)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 9
0
        public bool RemovePlaceable(Placeable placeable)
        {
            bool add = placeables.Remove(placeable);

            Placeables.Remove(placeable);

            return(add);
        }
Ejemplo n.º 10
0
 public AreaSpawn Clone()
 {
     return(new AreaSpawn
     {
         SecondsEmpty = SecondsEmpty,
         HasSpawned = HasSpawned,
         Placeables = Placeables.ToList(),
         Creatures = Creatures.ToList()
     });
 }
Ejemplo n.º 11
0
        private void LoadExistingData()
        {
            Placeables.Clear();

            foreach (var loaded in _moduleDataService.LoadAll <PlaceableData>())
            {
                PlaceableDataObservable placeable = _observableDataFactory.CreateAndMap <PlaceableDataObservable, PlaceableData>(loaded);
                Placeables.Add(placeable);
            }
        }
Ejemplo n.º 12
0
        private void New()
        {
            var placeable = _observableDataFactory.Create <PlaceableDataObservable>();

            placeable.Name = "Placeable" + (Placeables.Count + 1);
            Placeables.Add(placeable);

            _eventAggregator.GetEvent <PlaceableCreatedEvent>().Publish(placeable);
            RaiseValidityChangedEvent();
        }
Ejemplo n.º 13
0
        public bool AddPlaceable(Placeable placeable)
        {
            bool add = placeables.Add(placeable);

            if (add)
            {
                Placeables.Add(placeable);
            }

            return(add);
        }
Ejemplo n.º 14
0
        public void Run(TimeSpan t)
        {
            TimeSinceLastUpdate += t;
            if (TimeSinceLastUpdate.TotalSeconds >= UpdateRate)
            {
                TimeSinceLastUpdate.Add(TimeSpan.FromSeconds(-UpdateRate));

                foreach (var placeable in Placeables)
                {
                    placeable.Run(t);
                }

                Placeables.RemoveAll(p => p.Dead);
            }
        }
    //When an enemy gets away from a unit, delete that enemy from the enemies list
    public void OnTriggerExit(Collider other)
    {
        Placeables target = null;

        if (other.tag == "CheckForEnemy")
        {
            target = other.GetComponent <Placeables>();
        }

        if (target != null && target.currentTeam != offensivePlaceablesRef.currentTeam)
        {
            enemies.Remove(target);
            offensivePlaceablesRef.moveToTarget = false;
            enemy = null;
        }
    }
Ejemplo n.º 16
0
    public void FollowTarget(Placeables target)
    {
        if (target != null)
        {
            Vector3 targetPosition = target.transform.position;
            targetPosition.y = this.transform.position.y;
            transform.LookAt(targetPosition);

            float distance = Vector3.Distance(target.transform.position, this.transform.position);

            if (distance > 3 && target.currentHealth > 0 && currentHealth > 0)
            {
                agent.SetDestination(targetPosition);
                this.GetComponent <NavMeshAgent>().speed = 20;
            }
        }
    }
Ejemplo n.º 17
0
    //This function gets called every 15 seconds and has a 50% chance (determined by the r int) of creating an army that will attack one of the targets
    void GoingToAttack()
    {
        int r = Random.Range(1, 2);

        if (r == 1 && friendlyUnits.Count > 0)
        {
            Placeables        target = armyTarget(); //Gets a target for the army to attack
            List <Placeables> army   = CreateArmy(); //Creates an army out of the friendly units it has available

            //Gives each unit in the army the target
            foreach (Placeables unit in army)
            {
                unit.target = target;
                unit.GetComponent <OffensivePlaceables>().FollowTarget(unit.target);
            }
        }
    }
Ejemplo n.º 18
0
 private void Delete()
 {
     ConfirmDeleteRequest.Raise(
         new Confirmation
     {
         Title   = "Delete Placeable?",
         Content = "Are you sure you want to delete this placeable?"
     }, c =>
     {
         if (!c.Confirmed)
         {
             return;
         }
         _eventAggregator.GetEvent <PlaceableDeletedEvent>().Publish(SelectedPlaceable);
         Placeables.Remove(SelectedPlaceable);
         RaiseValidityChangedEvent();
     });
 }
Ejemplo n.º 19
0
        public override void Read(BinaryReader reader)
        {
            read_equipment(reader);

            Heal_Val       = reader.ReadInt32();
            Heal_Percent   = (float)reader.ReadDouble();
            Door_Key       = reader.ReadBoolean();
            Chest_Key      = reader.ReadBoolean();
            Dancer_Ring    = reader.ReadBoolean();
            Torch_Radius   = reader.ReadInt32();
            Placeable      = (Placeables)reader.ReadInt32();
            Repair_Val     = reader.ReadInt32();
            Repair_Percent = (float)reader.ReadDouble();
            Boost_Text     = reader.ReadString();
            Stat_Boost     = Stat_Boost.read(reader);
            Growth_Boost   = Growth_Boost.read(reader);
            Stat_Buff      = Stat_Buff.read(reader);
            Promotes.read(reader);
        }
 // Use this for initialization
 void Awake()
 {
     offensivePlaceablesRef = transform.root.GetComponent <Placeables>();
 }
Ejemplo n.º 21
0
 private void ModuleClosed()
 {
     Placeables.Clear();
 }
Ejemplo n.º 22
0
 public PlaceableData GetSpawnPoint()
 {
     return(Placeables.FirstOrDefault(placeable => placeable.typeStr == "Ball Spawner"));
 }
Ejemplo n.º 23
0
        private AttackableBuilding FindTarget()
        {
            var attackable = Placeables.GetComponentsInChildren <AttackableBuilding>();

            return(attackable.Length == 0 ? null : attackable[Random.Range(0, attackable.Length)]);
        }
Ejemplo n.º 24
0
 public IEnumerable <Placeable> GetPlaceables(int x, int y, int w, int h) => Placeables.Where(r => r.Intersects(x, y, w, h));
Ejemplo n.º 25
0
 public IEnumerable <Placeable> GetPlaceables(int x, int y) => Placeables.Where(r => r.ContainsPoint(x, y));
Ejemplo n.º 26
0
 public void RemovePlaceableData(PlaceableData placeableData)
 {
     Placeables.Remove(placeableData);
 }