예제 #1
0
 private bool AoE()
 {
     if (areaEffect > 0)
     {
         List <Vector2Int> hexes;
         hexes = TerrainGen.GetHexInRange(TerrainGen.GetGridPosition2D(transform.position), Mathf.RoundToInt(1 + areaEffect));
         List <mobBase> mobs = new List <mobBase>();
         foreach (Vector2Int hex in hexes)
         {
             List <mobBase> mobHex = MobLister.GetMobList(hex);
             if (mobHex != null)
             {
                 foreach (mobBase mob in mobHex)
                 {
                     float distance = MyMath.calcDistance(transform.position, mob.transform.position);
                     if (distance < areaEffect * TerrainGen.hexSize && mob != target)
                     {
                         mobs.Add(mob);
                     }
                 }
             }
         }
         foreach (mobBase mob in mobs)
         {
             float distance = MyMath.calcDistance(transform.position, mob.transform.position);
             float dmgMult  = distance / (TerrainGen.hexSize * areaEffect);
             mob.DamageMob(damage);
         }
         return(true);
     }
     return(false);
 }
예제 #2
0
    void KillMob()
    {
        Player.player.GiveGold((int)gold);

        if (deathParticles != 0)
        {
            ParticleSystem newSystem = ParticleMaster.MakeSystem((DeathParticles)deathParticles);
            newSystem.transform.position = this.transform.position;
        }
        if (spawner != null)
        {
            spawner.RemoveMob(this);
        }
        MobLister.RemoveMob(this);
    }
예제 #3
0
    private void GetTargetList()
    {
        targets.Clear();

        foreach (Vector2Int hex in hexesInRange)
        {
            List <mobBase> mobs = MobLister.GetMobList(hex);
            if (mobs != null)
            {
                foreach (mobBase mob in mobs)
                {
                    targets.Add(mob);
                }
            }
        }
    }
예제 #4
0
    private bool Fork()
    {
        if (forkCount > 0 && forkProjectiles > 0)
        {
            List <Vector2Int> hexes;
            hexes = TerrainGen.GetHexInRange(TerrainGen.GetGridPosition2D(transform.position), (int)chainDistanceMax);
            List <mobBase> mobs = new List <mobBase>();
            foreach (Vector2Int hex in hexes)
            {
                List <mobBase> mobHex = MobLister.GetMobList(hex);
                if (mobHex != null)
                {
                    foreach (mobBase mob in MobLister.GetMobList(hex))
                    {
                        float distance = MyMath.calcDistance(transform.position, mob.transform.position);
                        if (distance > chainDistanceMin && distance < chainDistanceMax)
                        {
                            mobs.Add(mob);
                        }
                    }
                }
            }
            //
            forkCount      -= 1;
            forkProjectiles = Mathf.RoundToInt(forkProjectiles * 0.5f);
            damage         *= forkDamageLoss;

            if (mobs.Count > 0)
            {
                for (int i = 0; i < forkProjectiles; i++)
                {
                    ProjectileBase newProj = CopyProjectile(chainDamageLoss);
                    newProj.transform.position = this.transform.position;
                    int randomTarget = Random.Range(0, mobs.Count - 1);
                    newProj.target = mobs[randomTarget];
                    mobs.RemoveAt(randomTarget);
                    if (mobs.Count == 0)
                    {
                        break;
                    }
                }
            }
            //
            return(true);
        }
        return(false);
    }
예제 #5
0
    public mobBase SpawnMob(ref float mobPoints, Vector2Int hex = new Vector2Int(), string nextMob = "")
    {
        Vector3 newPos;

        if (hex == new Vector2Int())
        {
            newPos = TerrainGen.GetHexPosition(spawnHexes[Random.Range(0, spawnHexes.Count)]);
        }
        else
        {
            newPos = TerrainGen.GetHexPosition(hex);
        }
        if (nextMob == "")
        {
            nextMob = Mobs.instance.getRandomMob();
        }
        mobBase newMob;

        newMob      = MobLister.GetDeadMob();
        newMob.goal = goal;
        newMob.gameObject.SetActive(true);
        mobPoints -= newMob.SetMob(nextMob);
        mobs.Add(newMob);
        newMob.SetSpawner(this);
        newMob.goal = goal;
        //newMob.transform.position = newPos;
        newMob.SetAgentPosition(newPos);
        //newMob.SetAgentDestination(TerrainGen.goal.transform.position);
        Vector2Int gridPos = TerrainGen.GetGridPosition2D(newPos);

        if (hexParticles.ContainsKey(gridPos))
        {
            ParticleSystem spawnSystem;
            spawnSystem = hexParticles[gridPos];
            ParticleSystem.Burst burst;
            burst = new ParticleSystem.Burst(0, (int)mobPoints);
            spawnSystem.emission.SetBurst(0, burst);
            spawnSystem.time = 0;
        }
        return(newMob);
    }
예제 #6
0
 private bool Chain()
 {
     if (chainCount > 0)
     {
         List <Vector2Int> hexes;
         hexes = TerrainGen.GetHexInRange(TerrainGen.GetGridPosition2D(transform.position), (int)chainDistanceMax);
         List <mobBase> mobs = new List <mobBase>();
         foreach (Vector2Int hex in hexes)
         {
             List <mobBase> mobHex = MobLister.GetMobList(hex);
             if (mobHex != null)
             {
                 foreach (mobBase mob in mobHex)
                 {
                     float distance = MyMath.calcDistance(transform.position, mob.transform.position);
                     if (distance > chainDistanceMin && distance < chainDistanceMax && mob != target)
                     {
                         mobs.Add(mob);
                     }
                 }
             }
         }
         chainCount -= 1;
         damage     *= chainDamageLoss;
         if (mobs.Count > 0)
         {
             Debug.Log("Chaining");
             ProjectileBase newProj = CopyProjectile(chainDamageLoss);
             newProj.SetParticleSystems(effect, explosion);
             newProj.transform.position = this.transform.position;
             newProj.target             = mobs[Random.Range(0, mobs.Count - 1)];
             Debug.DrawLine(newProj.transform.position, newProj.target.transform.position, Color.red, 1);
         }
         return(true);
         //
     }
     return(false);
 }
예제 #7
0
    // Update is called once per frame
    void Update()
    {
        if (mapGenState == MapGen.terrain)
        {
            Texture2D featureMap;
            foreach (NoiseMap noiseMap in noiseMaps)
            {
                noiseMap.offSet = new Vector2Int(Random.Range(0, 1000), Random.Range(0, 1000));
                CalcNoise(noiseMap);
            }
            featureMap = shapeGenerator.GenerateClipMap();
            shapeGenerator.GenerateLake(featureMap, 3);
            shapeGenerator.GenerateForests(featureMap, 7);
            noiseTex = new Texture2D(gridX, gridZ);
            CombineTextures(noiseTex, noiseMaps);
            ClipTexture(noiseTex, featureMap, Color.white);
            GenHexGrid(gridX, gridY, gridZ);
            CombineMeshes(20, 20);
            navMesh.BuildNavMesh();
            FillDoodads(featureMap);
            CalcEdgeHexes(25);
            SpreadOutterEdges(5);
            Vector3 camPos = GetHexPosition((int)(gridX / 2), (int)(gridZ / 2));
            camPos.y = 5f;
            camHandle.transform.position = camPos;
            mapGenState = MapGen.terrainCon;
            HexHighlighter.CreateGrid(gridX, gridZ, highlightFab, highlighters);
            ShowEdgeHexes();
            if (debug)
            {
                Vector3 goalPos = Vector3.zero;
                while (goalPos == Vector3.zero)
                {
                    Vector2Int gridPos = Vector2Int.zero;
                    gridPos.x = Random.Range(0, gridX - 1);
                    gridPos.y = Random.Range(0, gridZ - 1);
                    if (GetHex(gridPos.x, gridPos.y) != null)
                    {
                        goalPos = GetHexPosition(gridPos);
                    }
                }
                GameObject debugGoal = new GameObject();
                debugGoal.transform.position = goalPos;
                MobLister.MakeModGrid(gridX, gridZ);
                pathKeeper.GeneratePath(PathType.normal, TerrainGen.GetGridPosition(debugGoal.transform.position));
                PathKeeper.goal  = debugGoal.transform.position;
                mapGenState      = MapGen.done;
                terrainGenerated = true;
                MobSpawner.GetSpawners()[0].MakeReady(debugGoal);
            }

            //
            //
        }
        else if (mapGenState == MapGen.pathing)
        {
            MobLister.MakeModGrid(gridX, gridZ);
            pathKeeper.GeneratePath(PathType.normal, TerrainGen.GetGridPosition(goal.transform.position));
            mapGenState      = MapGen.done;
            terrainGenerated = true;
            MobSpawner.GetSpawners()[0].MakeReady(goal);
        }
    }
예제 #8
0
    private void Move()
    {
        if (!isInstant)
        {
            if (speed == 0)
            {
                TowerBase.RemoveProjectile(this);
            }
            if (isHoming)
            {
                if (target.gameObject.activeInHierarchy)
                {
                    Vector3 pos = transform.position;

                    faceDir            = MyMath.GetDirectionRatio(transform.position, target.transform.position);
                    pos.x             -= speed * faceDir.x * Time.deltaTime;
                    pos.z             -= speed * faceDir.z * Time.deltaTime;
                    pos.y             -= speed * faceDir.y * Time.deltaTime;
                    transform.position = pos;
                    targetPos          = target.transform.position;
                    if (MyMath.calcDistance(pos, target.transform.position, new Vector3(1, 0, 1)) < speed * Time.deltaTime / 50)
                    {
                        transform.position = target.transform.position;
                        HitTarget();
                    }
                }
                else
                {
                    isHoming = false;
                }
            }
            if (!isHoming)
            {
                Vector3 pos = transform.position;
                faceDir = MyMath.GetDirectionRatio(transform.position, targetPos);

                pos.x -= speed / 100 * faceDir.x;
                pos.y -= speed / 100 * faceDir.y;
                pos.z -= speed / 100 * faceDir.z;

                transform.position = pos;

                if (MyMath.calcDistance(pos, targetPos) < 0.1f)
                {
                    if (areaEffect > 0)
                    {
                        List <mobBase> mobList = MobLister.GetMobsInRange(pos, areaEffect * TerrainGen.hexSize);
                        if (mobList.Count > 0)
                        {
                            foreach (mobBase mob in mobList)
                            {
                                mob.DamageMob(damage);
                            }
                        }
                    }
                    else
                    {
                        List <mobBase> mobList = MobLister.GetMobsInRange(pos, 0.1f);
                        if (mobList.Count > 0)
                        {
                            mobList[0].DamageMob(damage);
                        }
                    }
                    TowerBase.RemoveProjectile(this);
                }
            }
        }
        if (isInstant)
        {
            List <mobBase> findMobs = new List <mobBase>();
            chainList = new List <mobBase>();
            chainList.Add(target);
            if (chainCount > 0)
            {
                for (int i = 0; i < chainCount; i++)
                {
                    findMobs = MobLister.GetMobsInRange(transform.position, chainDistanceMax * TerrainGen.hexSize);
                    if (findMobs.Count > 0)
                    {
                        for (int o = 0; o < findMobs.Count; o++)
                        {
                            if (MyMath.calcDistance(transform.position, findMobs[o].transform.position) > chainDistanceMin * TerrainGen.hexSize)
                            {
                                if (!chainList.Contains(findMobs[o]))
                                {
                                    chainList.Add(findMobs[o]);
                                    transform.position = findMobs[o].transform.position;
                                    break;
                                }
                            }
                        }
                    }
                }
                float dmgMult     = 1;
                float chainDamage = damage;

                Lightning lightning;
                lightning = GetLightning();
                lightning.SetTower(tower);
                lightning.SetNumber(lightningNum);
                lightningNum++;
                lightning.setTargets(chainList);

                foreach (mobBase mob in chainList)
                {
                    chainDamage *= dmgMult;
                    mob.DamageMob(chainDamage);
                    mob.AddMobEffects(mobEffectList);
                    dmgMult *= 0.8f;
                }



                TowerBase.RemoveProjectile(this);
            }
        }
    }