Example #1
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         Vector3      mousePos    = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         Vector2      mousePos2d  = new Vector2(mousePos.x, mousePos.y);
         RaycastHit2D hit         = Physics2D.Raycast(mousePos2d, Vector2.zero);
         GameObject   selectedObj = null;
         if (hit.collider != null)
         {
             selectedObj = hit.collider.gameObject;
             selectedObj.GetComponent <BaseEntityManager>().ShowOutlines();
         }
         else
         {
             ShowOutlines(false);
             var gridpos = OutlineCreator.OutlineMap.WorldToCell(mousePos);
             var eq      = true;
             if (clickedBase != null)
             {
                 var pos = IlluminaConverter.ToCoordInt(this.GridPosition);
                 pos = IlluminaConverter.FlapTopSwitch(pos);
                 eq  = clickedBase.GridPosition == pos;
             }
             if (OutlinePositions.Contains(gridpos) && eq)
             {
                 world.AddNavigator(gridpos, clickedBase.owner, GridPosition);
             }
         }
     }
 }
Example #2
0
    public void ShowOutlines(bool show = true)
    {
        if (!show)
        {
            OutlineCreator.Tile = Blanktile;
        }
        else
        {
            var pos = IlluminaConverter.ToCoordInt(GridPosition);
            pos         = IlluminaConverter.FlapTopSwitch(pos);
            clickedBase = world.Map.Maps.BasesMap[pos];
        }
        var outlines = OutlineCreator.GetSurroundingPos(IlluminaConverter.ToFlatTopPos(this.GridPosition));

        for (int i = 0; i < outlines.Length; i++)
        {
            var _pos      = IlluminaConverter.ToCoordInt(outlines[i]);
            var available = true;
            if (show)
            {
                available = clickedBase.owner.navigators.Count < 3;
                if (((int)clickedBase.owner.tribe) != GamePlayManager.PlayerTurn)
                {
                    continue;
                }
            }
            if ((!world.Map.Maps.GeneralsMap.ContainsKey(_pos) && !world.Map.Maps.NavigatorsMap.ContainsKey(_pos)) && i != 3 && i != 0 && available)
            {
                OutlinePositions.Add(outlines[i]);
                OutlineCreator.SetTile(outlines[i]);
            }
        }
        OutlineCreator.Tile = (Tile)GameObject.FindGameObjectWithTag("ScriptsContainer").GetComponent <GameAssetsCollection>().Outline;
    }
Example #3
0
        public void GenerateRandomFloorPosition(Base playbase, CoordInt center, int max = 6, int i = 0)
        {
            Outline _outline = new Outline(world.Collection.Layers[0], world.Collection.GroundTiles[1]);

            var positions         = _outline.GetSurroundingPos(center.ToVector3Int());
            var scattering_center = new List <CoordInt>();
            var space_left        = 0;

            //Determines how many unoccupied sorrounding tile in the floormap
            foreach (var position in positions)
            {
                if (!world.Map.Maps.FloorMap.ContainsKey(IlluminaConverter.ToCoordInt(position)))
                {
                    space_left++;
                }
            }

            //If the space_left exceeds 3 use the minimum value which is 5, otherwise don't change the value
            space_left = space_left > 3 ? 5 : space_left;

            //Get the center of the next scattering positions
            for (int j = 0; j < space_left; j++)
            {
                var pos_index = 0;
                var pos       = IlluminaConverter.ToCoordInt(positions[pos_index]);
                do
                {
                    pos_index = Random.Range(0, 7);
                    pos       = IlluminaConverter.ToCoordInt(positions[pos_index]);
                } while (world.Map.Maps.FloorMap.ContainsKey(pos) || pos == center);
                scattering_center.Add(new CoordInt((int)pos.Y, (int)pos.X, (int)pos.Z));
                //FIXME : x becomes y, and y becomes xs
            }

            //Adds all the positions to the FloorMap
            for (int l = 0; l < positions.Length; l++)
            {
                var _position = IlluminaConverter.ToCoordInt(positions[l]);
                _position = ReturnSafePos(new int[] { 0, 24, 0, 24 }, _position);
                if (!world.Map.Maps.FloorMap.ContainsKey(_position))
                {
                    world.Map.Maps.FloorMap.Add(_position, new Floor(playbase.owner, positions[l]));
                }
            }

            //Recursion : ScatterAgain
            if (i < max && scattering_center.Count > 0)
            {
                for (int k = 0; k < scattering_center.Count; k++)
                {
                    i++;
                    GenerateRandomFloorPosition(playbase, scattering_center[k], max, i);
                }
            }
        }
Example #4
0
        public bool RemoveNavigator(Vector3Int pos)
        {
            var navigator_pos = IlluminaConverter.ToCoordInt(pos);

            if (Maps.NavigatorsMap.ContainsKey(navigator_pos))
            {
                Maps.NavigatorsMap.Remove(navigator_pos);
                Maps.EntitiesMap.Remove(navigator_pos);
                return(true);
            }

            return(false);
        }
Example #5
0
        public DestinationEntity PlaceNavigator(Vector3Int pos, Navigator navigator)
        {
            var destination = IlluminaConverter.ToCoordInt(pos);

            if (Maps.EntitiesMap.ContainsKey(destination))
            {
                return(DestinationEntity.NoDestination);
            }
            else
            {
                Maps.NavigatorsMap.Add(destination, navigator);
                Maps.EntitiesMap.Add(destination, navigator);
                return(DestinationEntity.None);
            }
        }
Example #6
0
        public DestinationEntity PlaceGeneral(Vector3Int pos, General general)
        {
            var destination = IlluminaConverter.ToCoordInt(pos);

            if (Maps.EntitiesMap.ContainsKey(destination))
            {
                return(DestinationEntity.NoDestination);
            }
            else
            {
                Maps.GeneralsMap.Add(destination, general);
                Maps.EntitiesMap.Add(destination, general);
                return(DestinationEntity.None);
            }
        }
Example #7
0
        public DestinationEntity PlaceBase(Vector3Int pos, Base baseEntity)
        {
            var destination = IlluminaConverter.ToCoordInt(pos);

            if (Maps.EntitiesMap.ContainsKey(destination))
            {
                return(DestinationEntity.NoDestination);
            }
            else
            {
                Maps.BasesMap.Add(destination, baseEntity);
                Maps.EntitiesMap.Add(destination, baseEntity);
                return(DestinationEntity.None);
            }
        }
Example #8
0
        public DestinationEntity PlaceTrap(Vector3Int pos, Trap trap)
        {
            var trap_pos = IlluminaConverter.ToCoordInt(pos);

            if (Maps.EntitiesMap.ContainsKey(trap_pos))
            {
                return(CheckDestinationEntity(trap_pos));
            }
            else
            {
                Maps.TrapsMap.Add(trap_pos, trap);
                Maps.EntitiesMap.Add(trap_pos, trap);
                return(DestinationEntity.None);
            }
        }
Example #9
0
 public void PlaceBaseStructures()
 {
     foreach (var item in Map.Maps.BasesMap)
     {
         var tribeIndex = (int)item.Value.owner.tribe;
         var pos        = IlluminaConverter.ToFlatTopPos(item.Key.ToVector3Int());
         var worldPos   = Collection.Layers[0].CellToWorld(pos);
         worldPos.z = 0;
         var basesParent   = Collection.EntitiesParent[0].transform;
         var baseStructure = Collection.BasePrefabs[tribeIndex];
         var baseObject    = Object.Instantiate(baseStructure, worldPos, Quaternion.identity, basesParent);
         var p             = baseObject.transform.position;
         baseObject.GetComponent <BaseEntityManager>().GridPosition = pos;
         baseObject.GetComponent <BaseEntityManager>().BasePosition = baseObject.transform.position;
     }
 }
Example #10
0
        public Trap RemoveTrap(Vector3Int pos)
        {
            var trap_pos = IlluminaConverter.ToCoordInt(pos);

            if (Maps.TrapsMap.ContainsKey(trap_pos))
            {
                var trap = Maps.TrapsMap[trap_pos];
                Maps.TrapsMap.Remove(trap_pos);
                Maps.EntitiesMap.Remove(trap_pos);
                return(trap);
            }
            else
            {
                return(new Trap(new Player(new User()), pos));
                //TODO: must send the actual player
            }
        }
Example #11
0
        public void AddNavigator(Vector3Int pos, Player owner, Vector3Int gridpos)
        {
            var vacantSlot = !Map.Maps.NavigatorsMap.ContainsKey(IlluminaConverter.ToCoordInt(pos));
            var hasRights  = (int)owner.tribe == GamePlayManager.PlayerTurn;

            if (vacantSlot && hasRights && owner.navigators.Count < 3)
            {
                var flipX = false;
                if (pos.y < gridpos.y)
                {
                    flipX = true;
                }
                var navigator = new Navigator(owner, pos, flipX);
                Map.PlaceNavigator(pos, navigator);
                PlaceNavigator(navigator, flipX);
                PlayDataController.SavePlayData();
            }
        }
Example #12
0
        // ChangeNavigatorPosition(,) == DestinationEntity.None;
        public DestinationEntity ChangeNavigatorPosition(Vector3Int oldPos, Vector3Int newPos)
        {
            var old_pos = IlluminaConverter.ToCoordInt(oldPos);
            var new_pos = IlluminaConverter.ToCoordInt(newPos);

            if (Maps.EntitiesMap.ContainsKey(new_pos))
            {
                return(CheckDestinationEntity(new_pos));
            }

            if (Maps.NavigatorsMap.ContainsKey(old_pos))
            {
                var navigator = Maps.NavigatorsMap[old_pos];
                Maps.NavigatorsMap.Remove(old_pos);
                Maps.EntitiesMap.Remove(old_pos);
                Maps.NavigatorsMap.Add(new_pos, navigator);
                Maps.EntitiesMap.Add(new_pos, navigator);
                return(DestinationEntity.None);
            }

            return(DestinationEntity.NoDestination);
        }
Example #13
0
        public void PlaceBases(List <Player> players)
        {
            var BasesPos = GetBasesPosition();

            for (int i = 0; i < players.Count; i++)
            {
                Base player_base = new Base(players[i], BasesPos[i]);
                world.Map.PlaceBase(BasesPos[i], player_base);
                Outline _outline  = new Outline(world.Collection.Layers[0], world.Collection.GroundTiles[1]);
                var     positions = _outline.GetSurroundingPos(BasesPos[i]);
                var     pos_index = Random.Range(0, 7);
                while (pos_index == 3 || pos_index == 0)
                {
                    pos_index = Random.Range(0, 7);
                }
                var position = positions[pos_index];
                Debug.Log(players[i].tribe + " , " + position);
                var general = new General(players[i], BasesPos[i]);
                world.Map.PlaceGeneral(position, general);
                GenerateRandomFloorPosition(player_base, IlluminaConverter.ToCoordInt(BasesPos[i]));
            }
        }
 public WorldEntity(Player owner, Vector3Int pos)
 {
     this.owner        = owner;
     this.GridPosition = IlluminaConverter.ToCoordInt(pos);
     this.key          = Keys.RandomKey(7);
 }