Exemple #1
0
 public static bool IsInvalidPoint(int chunkNumber, Vector3Int point)
 {
     return((point.z + 1 < ChunkManager.MaxGroundsLvls &&
             ChunkUtil.IsAnyEntity(chunkNumber, ChunkUtil.GetUpper(point))) ||
            ChunkUtil.IsGround(chunkNumber, point) ||
            ChunkUtil.IsEntity(chunkNumber, point));
 }
Exemple #2
0
        public static bool IsInvalidPath(Vector3Int point)
        {
            var chunkNumber = ChunkManager.CurrentChunk.ChunkNumber;

            return((point.z + 1 < ChunkManager.MaxGroundsLvls &&
                    ChunkUtil.IsAnyEntity(chunkNumber, ChunkUtil.GetUpper(point))) ||
                   ChunkUtil.IsMarkedIndex(chunkNumber, point) ||
                   ChunkUtil.IsEntity(chunkNumber, point));
        }
Exemple #3
0
        public static bool IsNearEnt(int chunkNumber, Vector3Int pos)
        {
            var neighbourPoints = new Vector3Int[8];

            neighbourPoints[0] = new Vector3Int(pos.x + 1, pos.y, pos.z);
            neighbourPoints[1] = new Vector3Int(pos.x - 1, pos.y, pos.z);
            neighbourPoints[2] = new Vector3Int(pos.x, pos.y + 1, pos.z);
            neighbourPoints[3] = new Vector3Int(pos.x, pos.y - 1, pos.z);

            var chunk = ChunkManager.GetChunkByNum(chunkNumber);

            return((from point in neighbourPoints
                    where chunk.IsMapPos(point) && ChunkUtil.IsEntity(chunkNumber, point)
                    select ChunkUtil.GetIndex(chunkNumber, point)).Any(
                       index => index > 0));
        }
Exemple #4
0
        public static List <GameUnit> GetNearUnits(int chunkNumber, GameEntity ent, Vector3Int pos)
        {
            var neighbourPoints = new Vector3Int[4];

            neighbourPoints[0] = new Vector3Int(pos.x + 1, pos.y, pos.z);
            neighbourPoints[1] = new Vector3Int(pos.x - 1, pos.y, pos.z);
            neighbourPoints[2] = new Vector3Int(pos.x, pos.y + 1, pos.z);
            neighbourPoints[3] = new Vector3Int(pos.x, pos.y - 1, pos.z);

            var chunk = ChunkManager.GetChunkByNum(chunkNumber);

            return((from point in neighbourPoints
                    where chunk.IsMapPos(point)
                    let index = ChunkUtil.GetIndex(chunkNumber, point)
                                where index > 0 && ChunkUtil.IsEntity(chunkNumber, point)
                                select chunk.GetGameObjectByIndex(point) as GameUnit
                                into obj
                                where obj != null
                                select obj).ToList());
        }
Exemple #5
0
        public static GameEntity GetNearFriendUnit(int chunkNumber, GameEntity ent, Vector3Int pos)
        {
            var neighbourPoints = new Vector3Int[4];

            neighbourPoints[0] = new Vector3Int(pos.x + 1, pos.y, pos.z);
            neighbourPoints[1] = new Vector3Int(pos.x - 1, pos.y, pos.z);
            neighbourPoints[2] = new Vector3Int(pos.x, pos.y + 1, pos.z);
            neighbourPoints[3] = new Vector3Int(pos.x, pos.y - 1, pos.z);

            var chunk = ChunkManager.GetChunkByNum(chunkNumber);

            return((from point in neighbourPoints
                    where chunk.IsMapPos(point)
                    let index = ChunkUtil.GetIndex(chunkNumber, point)
                                where index > 0 && ChunkUtil.IsEntity(chunkNumber, point)
                                select chunk.GetGameObjectByIndex(point)
                                into obj
                                where obj != null
                                select obj.GetComponent <GameEntity>()).FirstOrDefault(entEnemy =>
                                                                                       Equals(entEnemy.Owner, ent.Owner)));
        }
Exemple #6
0
        public static GameEntity GetNearEnemy(GameEntity ent, int radius)
        {
            var chunkNumber     = ent.ChunkNumber;
            var chunk           = ChunkManager.GetChunkByNum(chunkNumber);
            var pos             = ent.CurrentPos;
            var neighbourPoints = new Vector3Int[8];

            for (var i = 0; i < radius; i++)
            {
                neighbourPoints[0] = new Vector3Int(pos.x + i, pos.y, pos.z);
                neighbourPoints[1] = new Vector3Int(pos.x - i, pos.y, pos.z);
                neighbourPoints[2] = new Vector3Int(pos.x, pos.y + i, pos.z);
                neighbourPoints[3] = new Vector3Int(pos.x, pos.y - i, pos.z);

                neighbourPoints[4] = new Vector3Int(pos.x + i, pos.y + i, pos.z);
                neighbourPoints[5] = new Vector3Int(pos.x - i, pos.y - i, pos.z);
                neighbourPoints[6] = new Vector3Int(pos.x - i, pos.y + i, pos.z);
                neighbourPoints[7] = new Vector3Int(pos.x + i, pos.y - i, pos.z);


                var enemy = (from point in neighbourPoints
                             where chunk.IsMapPos(point)
                             let index = ChunkUtil.GetIndex(chunkNumber, point)
                                         where index > 0 && ChunkUtil.IsEntity(chunkNumber, point)
                                         select chunk.GetGameObjectByIndex(point)
                                         into obj
                                         where obj != null
                                         select obj.GetComponent <GameEntity>()).FirstOrDefault(entEnemy =>
                                                                                                !Equals(entEnemy.Owner, ent.Owner));

                if (enemy != null)
                {
                    return(enemy);
                }
            }
            return(null);
        }
Exemple #7
0
        public static void RecolorObject(GameEntity ent, bool trueCall)
        {
            if (ent == null || ((Recolor.IsHided(ent) && !trueCall) && ChunkManager.staticFogEnabled))
            {
                return;
            }


            var mod   = 3f;
            var upper = ChunkUtil.GetUpper(ent.CurrentPos);

            if ((ChunkUtil.IsAnyEntity(ent.ChunkNumber, upper) ||
                 !SecondaryGroundLvL.IsEmptyPos(ent.ChunkNumber, upper)) &&
                ent.CurrentPos.z + 1 != ChunkManager.MaxGroundsLvls)
            {
                mod += 2.5f;
            }


            var i     = 1f / ((ent.CurrentPos.z + mod) * 0.3f);
            var color = new Color(i, i, i);

            if (ChunkUtil.IsEntity(ent.ChunkNumber, upper) &&
                ent.CurrentPos.z + 1 != ChunkManager.MaxGroundsLvls)
            {
                var chunk    = ChunkManager.GetChunkByNum(ent.ChunkNumber);
                var upperEnt = chunk.GetGameObjectByIndex(upper);
                if (upperEnt != null)
                {
                    if (TreeGroup.IsTreeGroup(upperEnt.Group))
                    {
                        color.r = 0.5f;
                        color.b = 0.7f;
                        color.g = 0.3f;
                    }
                    else if (upperEnt.Group == "rock")
                    {
                        color.r = 0.3f;
                        color.b = 0.7f;
                        color.g = 0.2f;
                    }
                    else if (upperEnt is GameUnit)
                    {
                        var unit = upperEnt as GameUnit;
                        if (unit.IsEnemy(PlayersManager.GetMyPlayer()))
                        {
                            color.r = 1;
                            color.b = 0.3f;
                            color.g = 0.3f;
                        }
                        else
                        {
                            color.r = 0.1f;
                            color.b = 0.1f;
                            color.g = 0.6f;
                        }
                    }
                    else
                    {
                        color.r = 0.1f;
                        color.b = 0.1f;
                        color.g = 0.6f;
                    }
                }
            }

            if (!GroupUtil.isCreatureGroup(ent.Group) &&
                !GroupUtil.isBuilding(ent.Group))
            {
                var spriteRenderer = ent.GetComponent <SpriteRenderer>();
                spriteRenderer.color = color;
            }
        }