예제 #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
    public void RecalcArea(PathType type, Vector2Int position, int radius)
    {
        List <Vector2Int> hexes;

        hexes = TerrainGen.GetHexInRange(position, radius);
        indexes[type]++;
        foreach (Vector2Int hex in hexes)
        {
            FindGoal(type, TerrainGen.GetGridPosition2D(goal), hex);
        }
    }
예제 #3
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);
    }
예제 #4
0
    public void SpawnFromOrb(SpawnOrb orb, float spawnPoints)
    {
        Vector2Int        hex   = TerrainGen.GetGridPosition2D(orb.transform.position);
        List <Vector2Int> hexes = TerrainGen.GetHexInRange(hex, 3);

        string mobType = Mobs.instance.getRandomMob();

        mobType = "slime";
        while (spawnPoints > 0)
        {
            hex = hexes[Random.Range(0, hexes.Count)];
            while (TerrainGen.GetHex(hex.x, hex.y) == null)
            {
                hex = hexes[Random.Range(0, hexes.Count)];
            }
            SpawnMob(ref spawnPoints, hex, mobType);
        }

        KillOrb(orb);
    }
예제 #5
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);
 }
예제 #6
0
    public static Dictionary <string, List <Vector2Int> > GetHexesInRange(Vector3 position, int range, bool arc = false, float offSet = 0.05f)
    {
        Dictionary <string, List <Vector2Int> > hexesInRange;

        hexesInRange = new Dictionary <string, List <Vector2Int> >();

        List <Vector2Int> hexInRange   = new List <Vector2Int>();
        List <Vector2Int> goodHexes    = new List <Vector2Int>();
        List <Vector2Int> blockedHexes = new List <Vector2Int>();
        Vector3Int        hexPos       = TerrainGen.GetGridPosition(position);
        Vector2Int        gridPos      = new Vector2Int(hexPos.x, hexPos.z);

        hexInRange = TerrainGen.GetHexInRange(gridPos, range);
        Vector3 towerPos = position;

        towerPos.y += offSet;

        foreach (Vector2Int newPos in hexInRange)
        {
            if (!MyMath.IsWithin(hexPos.x, -1, TerrainGen.gridX) || !MyMath.IsWithin(hexPos.y, -1, TerrainGen.gridZ))
            {
                continue;
            }
            RaycastHit[] hits;
            bool         good = false;
            BuildingBase building;
            Vector3      castPos = TerrainGen.GetHexPosition(newPos.x, newPos.y);
            if (position.y > TerrainGen.GetHexHeight(newPos))
            {
                castPos.y += 0.25f;
            }
            else
            {
                castPos.y += 0.05f;
            }
            if (!arc)
            {
                //Physics.RayC
                float   lineLenght = Vector3.Distance(towerPos, castPos);
                Vector3 faceDir    = MyMath.GetDirectionRatio(towerPos, castPos);
                hits = Physics.RaycastAll(towerPos, -faceDir, lineLenght);
                good = true;
                foreach (RaycastHit hit in hits)
                {
                    building = hit.transform.GetComponentInParent <BuildingBase>();
                    if (building != null)
                    {
                        if (!building.Ethereal)
                        {
                            good = false;
                        }
                    }
                    else
                    {
                        good = false;
                    }
                }
                if (good)
                {
                    goodHexes.Add(newPos);
                }
                else
                {
                    blockedHexes.Add(newPos);
                }
            }
            else
            {
                goodHexes.Add(newPos);
            }
        }
        hexesInRange.Add("good", goodHexes);
        hexesInRange.Add("bad", blockedHexes);

        return(hexesInRange);
    }