Пример #1
0
        public void SetMapTile(PlayerMap map, PlayerMapTile tile)
        {
            if (tile.fightId == null)
            {
                return;
            }

            missionRequest.type  = $"C_{map.mapId}";
            missionRequest.mapId = map.mapId;
            missionRequest.posX  = tile.posX;
            missionRequest.posY  = tile.posY;
            fightTitle.text      = $"{map.name} {tile.posX}x{tile.posY}";
            fightService.GetFight((long)tile.fightId, data =>
            {
                fight   = data;
                loading = false;
                UpdateFight();
                CheckButton();
            });

            if (tile.fightRepeatable != true)
            {
                Destroy(missionBtn.gameObject);
                missionButtonVisible = false;
                missionPossible      = false;
            }

            missionPossible = tile.fightRepeatable == true && tile.victoriousFight == true;

            InitTeam();
        }
Пример #2
0
        public void DiscoverBuilding(long mapId, PlayerMapTile tile, Action <PlayerActionResponse> onSuccess = null)
        {
            var request = new MapTileRequest {
                mapId = mapId, posX = tile.posX, posY = tile.posY
            };

            serverAPI.DoPost("/map/new_building", request, onSuccess);
        }
Пример #3
0
        public void OpenChest(long mapId, PlayerMapTile tile, Action <PlayerActionResponse> onSuccess = null)
        {
            var request = new MapTileRequest {
                mapId = mapId, posX = tile.posX, posY = tile.posY
            };

            serverAPI.DoPost("/map/open_chest", request, onSuccess);
        }
        private static bool BottomRightEmpty(PlayerMap map, PlayerMapTile tile)
        {
            var posY          = tile.posY + 1;
            var posX          = tile.posY % 2 == 0 ? tile.posX : tile.posX + 1;
            var neighbourTile = map.tiles.Find(t => t.posY == posY && t.posX == posX);

            return(neighbourTile == null || neighbourTile.type == MapTileType.NONE);
        }
Пример #5
0
        private void JoinGame(GameCommand cmdReceived, Player player, PlayerGame playerGame, Game game)
        {
            if (playerGame != null)
            {
                new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "User already joined game").Save(this.FAppPrivate);
            }
            else
            {
                if (game == null)
                {
                    new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "Game not found").Save(this.FAppPrivate);
                }
                else
                {
                    if (game.PlayersInGame.Count >= game.MaxNumberOfPlayers)
                    {
                        new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "Already too many players in the game").Save(this.FAppPrivate);
                    }
                    else
                    {
                        PlayerGame newPlayerGame = new PlayerGame(game, cmdReceived.UserId, player.NickName);

                        foreach (MapTile tile in game.Map.MapTiles)
                        {
                            MapTile playerTile = new MapTile();
                            playerTile.TerrainType = -1;// tile.TerrainType;
                            playerTile.UserId      = newPlayerGame.UserId;
                            playerTile.Xpos        = tile.Xpos;
                            playerTile.Ypos        = tile.Ypos;

                            newPlayerGame.Map.MapTiles.Add(playerTile);

                            //set spawn, check if not occupied first
                            if (newPlayerGame.Spawn == null && tile.IsSpawningPoint)
                            {
                                if (game.PlayersInGame.Where(c => c.Spawn.Xpos == tile.Xpos && c.Spawn.Ypos == tile.Ypos).Count() == 0)
                                {
                                    //not used yet
                                    newPlayerGame.Spawn = playerTile;
                                    PlayerMapTile playerMapTile = new PlayerMapTile(game.Id, cmdReceived.UserId, playerTile);
                                    playerTile.TerrainType     = 100;
                                    playerTile.IsSpawningPoint = true;
                                    playerTile.IsAccessible    = true;
                                    playerMapTile.Save(this.FAppPrivate);
                                }
                            }
                        }


                        newPlayerGame.Save(this.FAppPrivate);
                        game.PlayersInGame.Add(newPlayerGame);
                        game.Save(this.FAppPublic);
                        new CommandFeedback(cmdReceived, enCommandStatus.Accepted, "Joined the game").Save(this.FAppPrivate);
                    }
                }
            }
        }
Пример #6
0
        public void object_added(IFireObject fireObject)
        {
            if (fireObject.Path == "PlayerMapTile")
            {
                //redraw game
                // this.redrawMap();
                PlayerMapTile gameMapTile = (PlayerMapTile)fireObject;
                PlayerGame    playerGame  = this.flPlayerGames.TypedItems <PlayerGame>().Where(c => c.UserId == me.Id).FirstOrDefault();
                if (playerGame != null)
                {
                    MapTile mapTile = playerGame.Map.MapTiles.Where(c => c.Xpos == gameMapTile.Tile.Xpos && c.Ypos == gameMapTile.Tile.Ypos).FirstOrDefault();
                    if (mapTile != null)
                    {
                        mapTile = gameMapTile.Tile;
                        RedrawMapTile(mapTile);
                    }
                }
            }
            else if (fireObject.Path == "PlayerUnit")
            {
                updateMap();
            }
            else if (fireObject.Path == "CommandFeedback")
            {
                SpeechSynthesizer synthesizer = new SpeechSynthesizer();
                synthesizer.Volume = 100;  // 0...100
                synthesizer.Rate   = -2;   // -10...10

                // Asynchronous
                CommandFeedback feedback = (CommandFeedback)fireObject;

                //foreach (InstalledVoice voice in synthesizer.GetInstalledVoices())
                //{
                //    Debug.Print(voice.VoiceInfo.Name);
                //}
                //synthesizer.SelectVoice(synthesizer.GetInstalledVoices()[1].VoiceInfo.Name);
                synthesizer.SpeakAsync(feedback.Feedback);
            }
            else if (fireObject.Path == "PlayerGame")
            {
                //All visible player units (both own and enemy)
                PlayerGame pg = (PlayerGame)fireObject;
                this.flPlayerUnits = new FireList(this.FAppPrivate, typeof(PlayerUnit), this, new FireListBox(lbxPlayerUnits), userId: pg.GameId, userIDKey: "GameId");
            }

            Debug.Print("Object added : " + fireObject.Revision);
        }
Пример #7
0
        private void UpdateRadarRange(PlayerGame playerGame, Game game, Unit newUnit)
        {
            //update tiles in radar range for user
            List <MapTile> radarRange = playerGame.Map.MapTiles.Where(c => c.Xpos >= newUnit.Position.Xpos - newUnit.RadarRange && c.Xpos <= newUnit.Position.Xpos + newUnit.RadarRange && c.Ypos >= newUnit.Position.Ypos - newUnit.RadarRange && c.Ypos <= newUnit.Position.Ypos + newUnit.RadarRange).ToList();

            foreach (MapTile mt in radarRange)
            {
                MapTile motherTile = game.Map.MapTiles.Where(c => c.Xpos == mt.Xpos && c.Ypos == mt.Ypos).First();
                mt.TerrainType     = motherTile.TerrainType;
                mt.IsAccessible    = motherTile.IsAccessible;
                mt.IsSpawningPoint = motherTile.IsSpawningPoint;
                mt.UserId          = playerGame.UserId;
                PlayerMapTile pmt = this.flPlayerTiles.TypedItems <PlayerMapTile>().Where(c => c.Tile.Xpos == mt.Xpos && c.Tile.Ypos == mt.Ypos && c.UserId == playerGame.UserId).FirstOrDefault();
                if (pmt == null)
                {
                    PlayerMapTile playerMapTile = new PlayerMapTile(game.Id, playerGame.UserId, mt);
                    playerMapTile.Save(this.FAppPrivate);
                }
            }
        }
        public void SetPlayerTile(PlayerMap map, PlayerMapTile tile, MapTileConfig mapTileConfig)
        {
            PosX = tile.posX;
            PosY = tile.posY;

            transform.localPosition = HexGridUtils.ConvertOffsetToWorldCoordinates(new Vector2Int(tile.posX, tile.posY));
            gameObject.name         = $"X{tile.posX} Y{tile.posY} {tile.type}";

            background.sprite = mapTileConfig.MapTileTypeConfig[tile.type];
            var baseLayer = 10 * tile.posY;

            background.sortingOrder = baseLayer;

            var bottomLeftEmpty  = tile.discovered && BottomLeftEmpty(map, tile);
            var bottomRightEmpty = tile.discovered && BottomRightEmpty(map, tile);

            if (bottomLeftEmpty && bottomRightEmpty)
            {
                AddIcon(mapTileConfig.bottomLeftAndRightEmpty, baseLayer + LAYER_FAKE_3D, 1f, Vector2.zero);
            }
            else if (bottomLeftEmpty)
            {
                AddIcon(mapTileConfig.bottomLeftEmpty, baseLayer + LAYER_FAKE_3D, 1f, Vector2.zero);
            }
            else if (bottomRightEmpty)
            {
                AddIcon(mapTileConfig.bottomRightEmpty, baseLayer + LAYER_FAKE_3D, 1f, Vector2.zero);
            }

            if (tile.discovered)
            {
                if (tile.structure != null || (tile.fightIcon != null && (tile.fightRepeatable == true || tile.victoriousFight == false)))
                {
                    AddIcon(mapTileConfig.whiteTile, baseLayer + LAYER_WHITE, 1f, Vector2.zero, new Color {
                        a = 0.35f, b = 1f, g = 1f, r = 1f
                    });
                }

                if (tile.structure != null)
                {
                    var tileToSprite = mapTileConfig.MapStructureConfig[(MapTileStructure)tile.structure];
                    AddIcon(tileToSprite.sprite, baseLayer + LAYER_STRUCTURE, tileToSprite.scale, tileToSprite.offset);
                }

                if (tile.fightIcon != null && (tile.fightRepeatable == true || tile.victoriousFight == false))
                {
                    var fightToSprite = mapTileConfig.MapFightConfig[(FightIcon)tile.fightIcon];
                    AddIcon(fightToSprite.sprite, baseLayer + LAYER_FIGHT, fightToSprite.scale, fightToSprite.offset);
                }
            }
            else if (tile.discoverable)
            {
                AddIcon(mapTileConfig.whiteTile, baseLayer + LAYER_WHITE, 1f, Vector2.zero, new Color {
                    a = 0.75f, b = 1f, g = 1f, r = 1f
                });
                AddIcon(mapTileConfig.discoverIcon, baseLayer + LAYER_STRUCTURE, mapTileConfig.discoverScale, mapTileConfig.discoverOffset, text: map.discoverySteamCost.ToString());
                someText.text = map.discoverySteamCost.ToString();
                someText.gameObject.SetActive(true);
                someText.gameObject.GetComponent <MeshRenderer>().sortingOrder = baseLayer + LAYER_STRUCTURE_TEXT;
                var locPos = someText.transform.localPosition;
                locPos.y += mapTileConfig.discoverOffset.y;
                someText.transform.localPosition = locPos;
            }

            progress.sortingOrder           = baseLayer + LAYER_PROGRESS;
            progressBackground.sortingOrder = baseLayer + LAYER_PROGRESS_BACKGROUND;
            progressBar.sortingOrder        = baseLayer + LAYER_PROGRESS_BAR;
        }
Пример #9
0
        private void HandleTileTap(PlayerMapTile tile)
        {
            if (tile.discoverable)
            {
                if (resourcesService.EnoughResources(ResourceType.STEAM, currentMap.discoverySteamCost))
                {
                    mapService.DiscoverTile(currentMap.mapId, tile);
                }
                else
                {
                    var error = popupCanvasController.OpenPopup(errorPopupPrefab);
                    error.SetError("Insufficient resources", "Not enough steam to discover map tile");
                }

                return;
            }

            if (tile.discovered)
            {
                if (tile.fightId != null && (tile.victoriousFight == false || tile.fightRepeatable == true))
                {
                    var mission = missionService.GetMission(currentMap.mapId, tile.posX, tile.posY);
                    if (mission != null)
                    {
                        var missionPopup = popupCanvasController.OpenPopup(missionDetailPrefab);
                        missionPopup.SetMission(mission);
                    }
                    else
                    {
                        var fightPopup = popupCanvasController.OpenPopup(startFightPrefab);
                        fightPopup.SetMapTile(currentMap, tile);
                    }
                }
                else if (tile.structure != null)
                {
                    if (tile.portalToMapId != null)
                    {
                        mapService.ChangeMapTo((long)tile.portalToMapId);
                    }
                    else if (tile.buildingType != null)
                    {
                        var building = buildingService.Building((BuildingType)tile.buildingType);
                        if (building != null)
                        {
                            metagameManager.OpenBuilding(building.type);
                        }
                        else
                        {
                            Debug.Log($"discover new building: {tile.buildingType}");
                        }
                    }
                    else if (!tile.chestOpened)
                    {
                        mapService.OpenChest(currentMap.mapId, tile, data =>
                        {
                            if (data.looted != null)
                            {
                                var lootedPopup = popupCanvasController.OpenPopup(lootedPrefab);
                                lootedPopup.SetLooted(data.looted);
                            }
                        });
                    }
                }
            }
        }