Esempio n. 1
0
    void Update()
    {
        //Check if any enemies in range
        if (targets.Count != 0)   //Active state

        //NOTE: should this part only run when current target dies?
        //Remove any dead enemies
        {
            targets = targets.Where(item => item != null).ToList();
            //Loop through possible targets and find the closest
            target = FindClosestHostile();
            //One last failsafe
            if (target == null)
            {
                return;
            }

            //Rotate to face target
            var lookPos = target.transform.position - transform.position;
            lookPos.y = 0;
            var endRot = Quaternion.LookRotation(lookPos);
            var newRot = Quaternion.RotateTowards(bitToRotate.transform.rotation, endRot, Time.deltaTime * rotationSpeed);
            bitToRotate.transform.rotation = newRot;

            //Fire every rateOfFire seconds, but only if enemy is in our sights
            timer += Time.deltaTime;
            if (Vector3.Angle(bitToRotate.transform.forward, lookPos) < maxFireAngle && timer > rateOfFire)
            {
                //Shoot out our raycast and apply damage to enemy
                StartCoroutine(ShotEffect());
                RaycastHit hit;
                shotLine.SetPosition(0, transform.InverseTransformPoint(barrelExit.position));
                if (Physics.Raycast(barrelExit.position, bitToRotate.transform.forward, out hit, range))
                {
                    shotLine.SetPosition(1, transform.InverseTransformPoint(hit.point));
                    Hostile hScript = hit.collider.GetComponent <Hostile>();
                    //Debug.Log("hit " + hit.collider.gameObject.name);
                    if (hScript != null)
                    {
                        hScript.Damage(damage);
                        //Make sure to remove from targets if dead
                        if (hit.collider.GetComponent <Hostile>().hp <= 0)
                        {
                            targets.Remove(hit.collider.gameObject);
                        }
                    }
                }
                else
                {
                    shotLine.SetPosition(1, bitToRotate.transform.InverseTransformPoint(bitToRotate.transform.forward * range));
                }
                timer = 0f;
            }
        }
        else     //Idle state
        {
            bitToRotate.transform.Rotate(0f, 0.1f, 0f, Space.Self);
        }
    }
Esempio n. 2
0
 protected void init()
 {
     attribute = new Attribute();
     hostile   = new Hostile();
     state     = new State();
     buff      = new Buff();
     skillList = new SkillList();
 }
Esempio n. 3
0
        public void Apply_NotACharacter_Test()
        {
            var entity  = Mock.Of <IEntity>();
            var hostile = new Hostile();

            hostile.Apply(entity);
            Assert.IsTrue(true); // If we made it here without exception then the test passed
        }
Esempio n. 4
0
    private void DessinerBoutonsTypeTroupeau()
    {
        GUILayoutOption[] options = new GUILayoutOption[2] {
            GUILayout.Width(150), GUILayout.Height(30)
        };

        GUILayout.Label("Type de troupeau");
        GUILayout.Space(10);

        ColorerSelection(troupeau.domesticable);
        if (GUILayout.Button("Domesticable", options))
        {
            troupeau.domesticable = true;
            troupeau.megaFaune    = false;
            troupeau.predateur    = false;


            if (troupeau.GetComponent <Hostile>())
            {
                DestroyImmediate(troupeau.GetComponent <Hostile>(), true);
            }
        }
        ColorerSelection(troupeau.megaFaune);
        if (GUILayout.Button("MegaFaune", options))
        {
            Hostile hostile = troupeau.GetComponent <Hostile>();

            troupeau.domesticable = false;
            troupeau.megaFaune    = true;
            troupeau.predateur    = false;


            if (!hostile)
            {
                hostile = troupeau.gameObject.AddComponent <Hostile>();
            }

            hostile.pion     = troupeau;
            troupeau.hostile = hostile;
        }
        ColorerSelection(troupeau.predateur);
        if (GUILayout.Button("Predateur", options))
        {
            Hostile hostile = troupeau.GetComponent <Hostile>();

            troupeau.domesticable = false;
            troupeau.megaFaune    = false;
            troupeau.predateur    = true;

            if (!hostile)
            {
                hostile = troupeau.gameObject.AddComponent <Hostile>();
            }

            hostile.pion     = troupeau;
            troupeau.hostile = hostile;
        }
    }
Esempio n. 5
0
        public void Apply_Character_WithExistingHostileCondition_Test()
        {
            var character = CreateMockCharacter();

            character.Conditions.Add(new Hostile());
            var hostile = new Hostile();

            hostile.Apply(character);
        }
Esempio n. 6
0
 public void MAJStats(Hostile hostile)
 {
     if (hostile.nbrCombattant != int.Parse(nombreCombattant.text))
     {
         nombreCombattant.text = "" + hostile.nbrCombattant;
     }
     AjouterPointAttaque(hostile.attaque - listePointsAttaque.Count);
     AjouterPointDefense(hostile.defense - listePointsDefense.Count);
 }
Esempio n. 7
0
        public void Remove_NoConditions_Test()
        {
            var character = CreateMockCharacter();
            var hostile   = new Hostile();

            hostile.Apply(character);
            hostile.Remove(character);
            Assert.AreEqual(0, character.Conditions.Count);
        }
Esempio n. 8
0
        public void Apply_Character_NoConditions_Test()
        {
            var character = CreateMockCharacter();
            var hostile   = new Hostile();

            hostile.Apply(character);
            Assert.AreEqual(EntityIds.HOSTILE_CONDITION_ID, character.Conditions[0].Id);
            Assert.AreSame(hostile, character.Conditions[0]);
            Assert.AreEqual(ConditionGroup.Attitude, character.Conditions[0].Group);
        }
Esempio n. 9
0
 void HostileDeath(Hostile hostile)
 {
     hostile.OnHostileDeath -= HostileDeath;
     hostile.OnHostileDeath -= player.OnHostileDeath;
     currentHostiles--;
     if (!spawning && currentHostiles == 0)
     {
         maxHostiles = Random.Range(2, 7);
         StartCoroutine(SpawnHostile());
     }
 }
Esempio n. 10
0
        private void CreateNewHostile(IList <IHostile> hostiles)
        {
            var rnd     = new Random();
            var x       = rnd.Next(2, (Settings.Environment.Width / 2) - 2) * 2;
            var y       = rnd.Next(2, Settings.Environment.Height - 2);
            var hostile = new Hostile(x, y);

            this.OverlapHandler += hostile.OnOverlap;

            hostiles.Add(hostile);
        }
Esempio n. 11
0
    // Update is called once per frame
    void Update()
    {
        if (!initialized && crest.gotRifter)
        {
            initialized = true;

            Hostile hostile = hostileObject.GetComponent <Hostile> ();
            hostile.set(crest.rifter);
            Health health = hostileObject.GetComponent <Health> ();
            health.setSlidersHostile();
        }
    }
Esempio n. 12
0
    public void attack(GameObject drone)
    {
        if (!drone)
        {
            return;
        }
        Health droneLife = drone.GetComponent <Health> ();

        Hostile rifter = gameObject.GetComponent <Hostile> ();

        droneLife.takeDamage(tmpDamage, tmpDamageType);
    }
Esempio n. 13
0
    void Start()
    {
        once   = true;
        outB.x = -26;
        outB.y = 12;
        outB.z = 0;

        turn            = 1;
        selected_ship   = null;
        selected_planet = null;

        spaces       = new Space[61];
        ships        = new ShipBehaviour[5];
        texts        = new TextBehaviour[5];
        planets      = new Planet[3];
        fleet        = new EnShip[2];
        productions  = new GameObject[3];
        prod_choices = new Dropdown[3];
        ddvalues     = new int[3];

        getShips();

        grid = transform.GetChild(1).gameObject.GetComponent <GridBehaviour>();

        et1 = transform.GetChild(2).gameObject.GetComponent <EndTurn>();

        getTexts();

        getPlanets();

        getDDMenus();

        getSpaces();

        highlight = transform.GetChild(6).gameObject;

        enSpawner = transform.GetChild(7).gameObject.GetComponent <Hostile>();

        arena = transform.GetChild(8).gameObject.GetComponent <BattleEnviro>();

        bank = transform.GetChild(9).gameObject.GetComponent <Resources>();

        cam = transform.GetChild(10).gameObject;

        ships[0].setPrev(spaces[1]);
        ships[1].setPrev(spaces[40]);
        planets[0].movement(spaces[11]);
        planets[1].movement(spaces[23]);
        planets[2].movement(spaces[58]);

        Select();
    }
Esempio n. 14
0
    private void TrouverHostilsAPortee()
    {
        hostilesAPortee.Clear();
        foreach (Revendication cible in tribu.revendication.TrouverRevendicateursAPortee())
        {
            Hostile hostileObserve = cible.GetComponent <Hostile>();

            if (hostileObserve)
            {
                hostilesAPortee.Add(hostileObserve);
            }
        }
    }
Esempio n. 15
0
    public void setSlidersHostile()
    {
        Hostile hostile = GetComponent <Hostile> ();

        Debug.Log("Hostile HP" + hostile.hp);

        shieldSlider.maxValue = hostile.shieldCapacity;
        shieldSlider.value    = hostile.shieldCapacity;
        shield = hostile.shieldCapacity;

        armorSlider.maxValue = hostile.armorHp;
        armorSlider.value    = hostile.armorHp;
        armor = hostile.armorHp;

        hullSlider.maxValue = hostile.hp;
        hullSlider.value    = hostile.hp;
        hull = hostile.hp;
    }
Esempio n. 16
0
    IEnumerator getRifterSpecs(string rifterId, Action onComplete)
    {
        string rifterUrl = url + "/types/" + rifterId + "/";

        Debug.Log(rifterUrl);
        www = new WWW(rifterUrl);
        yield return(www);

        JSONNode   response = JSON.Parse(www.text);
        GameObject prefab   = Instantiate(RifterPrefab);
        Hostile    rifter   = prefab.GetComponent <Hostile> ();

        Destroy(prefab);
        rifter.eveId = int.Parse(rifterId);
        //rifter.set (response);
        this.rifter = response;
        Debug.Log(rifter.name + " hp: " + rifter.hp);

        onComplete();
    }
Esempio n. 17
0
    IEnumerator SpawnHostile()
    {
        if (currentHostiles < maxHostiles)
        {
            spawning = true;
            yield return(new WaitForSeconds(Random.Range(1, 4)));

            Vector3    spawnPosition = new Vector3(15, Random.Range(-4.5f, 4.5f), 0);
            GameObject newHostile    = Instantiate(hostile, spawnPosition, Quaternion.identity);
            Hostile    hostileScript = newHostile.GetComponent <Hostile>();
            hostileScript.OnHostileDeath += HostileDeath;
            hostileScript.OnHostileDeath += player.OnHostileDeath;
            hostileScript.AssignRelativeMotion(relativeMotion);
            currentHostiles++;
            StartCoroutine(SpawnHostile());
        }
        else
        {
            spawning = false;
        }
        yield return(null);
    }
Esempio n. 18
0
        private void ProcessEvents(Hostile hostile)
        {
            for (int i = 0; i < events.Count; i++)
            {
                if (events[i].Y == this.protagonist.Y && this.events[i].X == this.protagonist.X)
                {
                    this.game.AddScore(this.events[i].Points);
                    this.currentScore    += this.events[i].Points;
                    this.events[i].Points = 0;
                    Sound.Event();
                }

                if (this.events[i].Points <= Settings.Game.PointDeathThreshold)
                {
                    this.events.RemoveAt(i);
                }
                else
                {
                    this.events[i].Deduct();
                }
            }

            if (this.protagonist.Y == hostile.Y && this.protagonist.X == hostile.X)
            {
                if (this.game.Lives > 0)
                {
                    this.game.DecreaseLive();
                    this.game.AddScore(Settings.Game.LoseLifePenalty);
                    this.currentScore -= Settings.Game.LoseLifePenalty;
                    ResetHostile(hostile);
                }
                else
                {
                    this.game.End();
                }
            }
        }
Esempio n. 19
0
 private static void ResetHostile(Hostile hostile)
 {
     hostile.RandomReset();
 }
Esempio n. 20
0
 public IdleStateH(Hostile e) : base(e)
 {
     name = "idle (Hostile)";
 }
Esempio n. 21
0
    public void SpawnPillard()
    {
        GameObject pillard = ListeAnimaux.Defaut.pillard;

        TuileManager[] tuilesFront = DamierGen.Actuel.RecupTuilesFrontalieres();

        List <TuileManager> piocheTuile = new List <TuileManager>();

        foreach (TuileManager tuile in tuilesFront)
        {
            if (!tuile.estOccupee)
            {
                piocheTuile.Add(tuile);
            }
        }

        if (piocheTuile.Count > 0)
        {
            TuileManager tuileSpawn = piocheTuile[Random.Range(0, piocheTuile.Count - 1)];

            Vector3 positionSpawn = tuileSpawn.transform.position;
            positionSpawn.z = -3.5f;

            Pillard nvPillard = Instantiate(pillard, positionSpawn, new Quaternion()).GetComponent <Pillard>();

            Hostile    pillardHost = nvPillard.GetComponent <Hostile>();
            int        min;
            int        max;
            Guerrier[] guerriers = FindObjectsOfType <Guerrier>();
            int        ptAtt     = 0;
            int        ptDef     = 0;

            for (int i = 0; i < guerriers.Length; i++)
            {
                ptAtt += guerriers[i].attaque;
                ptDef += guerriers[i].defense;
            }

            if (pillardHost.attaqueMin == -1)
            {
                min = ptAtt / guerriers.Length;
            }
            else
            {
                min = pillardHost.attaqueMin;
            }
            if (pillardHost.attaqueMax == -1)
            {
                max = ptAtt / guerriers.Length + 2;
            }
            else
            {
                max = pillardHost.attaqueMax;
            }

            pillardHost.attaque = Random.Range(min, max);

            if (pillardHost.defenseMin == -1)
            {
                min = ptDef / guerriers.Length;
            }
            else
            {
                min = pillardHost.defenseMin;
            }
            if (pillardHost.defenseMax == -1)
            {
                max = ptDef / guerriers.Length + 1;
            }
            else
            {
                max = pillardHost.defenseMax;
            }

            pillardHost.defense = Random.Range(min, max);

            Tribu[]            tribus       = FindObjectsOfType <Tribu>();
            List <Demographie> demographies = new List <Demographie>();

            foreach (Tribu tribu in tribus)
            {
                demographies.Add(tribu.demographie);
            }

            int popTotale = 0;

            for (int i = 0; i < demographies.Count; i++)
            {
                popTotale += demographies[i].taillePopulation;
            }

            if (pillardHost.nbrCombattantMin == -1)
            {
                min = popTotale / demographies.Count;
            }
            else
            {
                min = pillardHost.nbrCombattantMin;
            }
            if (pillardHost.nbrCombattantMax == -1)
            {
                max = popTotale / demographies.Count + 2;
            }
            else
            {
                max = pillardHost.nbrCombattantMax;
            }

            pillardHost.nbrCombattant = Random.Range(min, max);
            nvPillard.name            = "Pillard";

            CameraControle.Actuel.CentrerCamera(nvPillard.transform.position);
        }
    }
Esempio n. 22
0
        private List <Configuration.Menu> UpdateEnemy(string path, List <Configuration.Menu> oldList)
        {
            string prefabDir = Application.dataPath + "/Prefabs";

            if (!Directory.Exists(prefabDir))
            {
                Directory.CreateDirectory(prefabDir);
                Debug.Log("Directory created at: " + prefabDir);
            }

            string pathFiles = Application.dataPath + "/Prefabs/Dungeon/" + path;

            if (!Directory.Exists(pathFiles))
            {
                Directory.CreateDirectory(pathFiles);
                Debug.Log("Directory created at: " + pathFiles);
            }

            List <Configuration.Menu> result = new List <Configuration.Menu>();

            if (Directory.Exists(pathFiles))
            {
                Directory.GetFiles(pathFiles)
                .ToList()
                .FindAll(file => Path.GetExtension(file) == ".prefab")
                .ForEach(filePath =>
                {
                    string dirOfTiles = "Assets/Prefabs/Dungeon/" + path;
                    if (!Directory.Exists(dirOfTiles))
                    {
                        Directory.CreateDirectory(dirOfTiles);
                        Debug.Log("Directory created at: " + dirOfTiles);
                    }

                    string objPath = "Assets/Prefabs/Dungeon/" + path + "/" + Path.GetFileName(filePath);
                    GameObject obj = (GameObject)AssetDatabase.LoadAssetAtPath(objPath, typeof(GameObject));

                    if (obj.GetComponent <Hostile>())
                    {
                        if (oldList.Any(i => i.Prefab == obj.GetComponent <Hostile>().Prefab))
                        {
                            Configuration.Menu decoMenu = oldList.Find(i => i.Prefab == obj.GetComponent <Hostile>().Prefab);
                            result.Add(decoMenu);

                            Hostile deco    = obj.GetComponent <Hostile>();
                            deco.Prefab     = decoMenu.Prefab;
                            deco.BoxToSpawn = decoMenu.BoxToSpawn;
                            deco.MinToSpawn = decoMenu.MinToSpawn;
                            deco.MaxToSpawn = decoMenu.MaxToSpawn;

                            return;
                        }
                        else
                        {
                            Configuration.Menu decoMenu = new Configuration.Menu();
                            Hostile deco = obj.GetComponent <Hostile>();

                            decoMenu.Prefab     = deco.Prefab;
                            decoMenu.BoxToSpawn = deco.BoxToSpawn;
                            decoMenu.MinToSpawn = deco.MinToSpawn;
                            decoMenu.MaxToSpawn = deco.MaxToSpawn;

                            result.Add(decoMenu);
                        }
                    }
                });
            }

            if (result.Count <= 0)
            {
                Debug.LogError("Directory of dungeon is empty: " + "Assets/Prefabs/Dungeon/" + path);
            }

            return(result);
        }
Esempio n. 23
0
    public void RemoveTarget(GameObject lostTarget)
    {
        if ((AIStates)CurrentState == AIStates.pursuit)
        {
            if (ThreatTable.Remove(lostTarget))
            {
                if (target == lostTarget)
                {
                    if (ThreatTable.Count == 0)
                    {
                        target = Group.GetNewTarget();

                        if (target != null)
                        {
                            Hostile newTargetObject = new Hostile(target);
                            ThreatTable.Add(target, newTargetObject);
                        }
                    }

                    else
                    {
                        GameObject highestThreatTarget = ThreatTable.Keys.First();

                        foreach (GameObject targetInTable in ThreatTable.Keys)
                        {
                            if (ThreatTable[targetInTable].Threat > ThreatTable[highestThreatTarget].Threat)
                            {
                                highestThreatTarget = targetInTable;
                            }
                        }

                        target = highestThreatTarget;
                    }

                    PursuitFSM.Pursue(target);
                }
            }
        }
    }
Esempio n. 24
0
 private void ChaseRight(Hostile hostile)
 {
     hostile.Move(1, 0);
     Drawing.Draw(hostile, this.protagonist);
 }
Esempio n. 25
0
    public void SpawnLoup()
    {
        GameObject Loup = null;

        foreach (GameObject predateur in ListeAnimaux.Defaut.Predateurs)
        {
            if (predateur.name == "Loup")
            {
                Loup = predateur;
                break;
            }
        }

        TuileManager[] tuilesFront = DamierGen.Actuel.RecupTuilesFrontalieres();

        List <TuileManager> piocheTuile = new List <TuileManager>();

        foreach (TuileManager tuile in tuilesFront)
        {
            if (!tuile.estOccupee)
            {
                piocheTuile.Add(tuile);
            }
        }

        if (piocheTuile.Count > 0)
        {
            TuileManager tuileSpawn = piocheTuile[Random.Range(0, piocheTuile.Count - 1)];
            if (Loup)
            {
                Vector3 positionSpawn = tuileSpawn.transform.position;
                positionSpawn.z = -3.5f;

                Hostile nvHostile = Instantiate(Loup, positionSpawn, new Quaternion()).GetComponent <Hostile>();

                int        min;
                int        max;
                Guerrier[] guerriers = FindObjectsOfType <Guerrier>();
                int        ptAtt     = 0;
                int        ptDef     = 0;

                for (int i = 0; i < guerriers.Length; i++)
                {
                    ptAtt += guerriers[i].attaque;
                    ptDef += guerriers[i].defense;
                }

                if (nvHostile.attaqueMin == -1)
                {
                    min = ptAtt / guerriers.Length;
                }
                else
                {
                    min = nvHostile.attaqueMin;
                }
                if (nvHostile.attaqueMax == -1)
                {
                    max = ptAtt / guerriers.Length + 1;
                }
                else
                {
                    max = nvHostile.attaqueMax;
                }

                nvHostile.attaque = Random.Range(min, max);

                if (nvHostile.defenseMin == -1)
                {
                    min = ptDef / guerriers.Length;
                }
                else
                {
                    min = nvHostile.defenseMin;
                }
                if (nvHostile.defenseMax == -1)
                {
                    max = ptDef / guerriers.Length + 1;
                }
                else
                {
                    max = nvHostile.defenseMax;
                }

                nvHostile.defense = Random.Range(min, max);

                Tribu[]            tribus       = FindObjectsOfType <Tribu>();
                List <Demographie> demographies = new List <Demographie>();

                foreach (Tribu tribu in tribus)
                {
                    demographies.Add(tribu.demographie);
                }

                int popTotale = 0;

                for (int i = 0; i < demographies.Count; i++)
                {
                    popTotale += demographies[i].taillePopulation;
                }

                if (nvHostile.nbrCombattantMin == -1)
                {
                    min = popTotale / demographies.Count;
                }
                else
                {
                    min = nvHostile.nbrCombattantMin;
                }
                if (nvHostile.nbrCombattantMax == -1)
                {
                    max = popTotale / demographies.Count + 2;
                }
                else
                {
                    max = nvHostile.nbrCombattantMax;
                }

                nvHostile.nbrCombattant = Random.Range(min, max);
                nvHostile.name          = "Loup";
                CameraControle.Actuel.CentrerCamera(nvHostile.transform.position);
            }
            else
            {
                Debug.LogError("Y a pas de Loup dans la liste des animaux !!!");
            }
        }
    }
Esempio n. 26
0
 private void ChaseUp(Hostile hostile)
 {
     hostile.Move(0, -1);
     Drawing.Draw(hostile, this.protagonist);
 }
Esempio n. 27
0
 public PatrolStateH(Hostile e) : base(e)
 {
     name = "patrol (Hostile)";
 }
Esempio n. 28
0
    /// <summary>
    /// Apply threat to the individual enemy. The enemy always attacks the
    /// target with the highest threat.
    /// </summary>
    /// <param name="source">The source of the threat.</param>
    /// <param name="magnitude">The amount of threat to apply.</param>
    public void Threat(GameObject source, float magnitude = 0)
    {
        if ((AIStates)CurrentState != AIStates.dead && (AIStates)CurrentState != AIStates.reset && source != null)
        {
            if (source.tag == "Player")
            {
                if (!ThreatTable.ContainsKey(source))
                {
                    Hostile newTargetObject = new Hostile(source);

                    ThreatTable.Add(source, newTargetObject);
                    Group.Threat(source);

                    if ((AIStates)CurrentState == AIStates.idle)
                    {
                        target = source;
                        Transition(AIStates.pursuit);
                    }
                }

                ThreatTable[source].Threaten(magnitude);

                if (ThreatTable[source].Threat > ThreatTable[target].Threat)
                {
                    target = source;
                    PursuitFSM.Pursue(target);
                }

            }

            else
            {
                throw new InvalidOperationException("Threat cannot be applied by a non-player GameObject. Dumbass.");
            }
        }
    }
Esempio n. 29
0
 public HostileState(Hostile e)
 {
     owner   = e;
     gravity = owner.gameController.gravity;
 }
Esempio n. 30
0
 /// <summary>
 /// Checks this Alliance is hostile towards the given Alliance.
 /// </summary>
 /// <param name="allianceID">Alliance ID to check against.</param>
 /// <returns>True if hostile towards the given Alliance, else false.</returns>
 public bool IsHostile(AllianceID allianceID)
 {
     return(Hostile.Contains(allianceID));
 }
Esempio n. 31
0
 public void OnHostileDeath(Hostile hostile)
 {
     hostilesKilled++;
     killCount.text = "Hostiles Killed: " + hostilesKilled;
 }