public async Task <IActionResult> Edit(int id, [Bind("LocationMainId,Lat,Lon,PlaceId,UserMainId")] LocationMain locationMain)
        {
            if (id != locationMain.LocationMainId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(locationMain);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LocationMainExists(locationMain.LocationMainId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PlaceId"]    = new SelectList(_context.Place, "PlaceId", "PlaceId", locationMain.PlaceId);
            ViewData["UserMainId"] = new SelectList(_context.UserMain, "UserId", "UserId", locationMain.UserMainId);
            return(View(locationMain));
        }
        public async Task <IActionResult> Create([Bind("LocationMainId,Lat,Lon,PlaceId,UserMainId")] LocationMain locationMain)
        {
            if (ModelState.IsValid)
            {
                _context.Add(locationMain);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PlaceId"]    = new SelectList(_context.Place, "PlaceId", "PlaceId", locationMain.PlaceId);
            ViewData["UserMainId"] = new SelectList(_context.UserMain, "UserId", "UserId", locationMain.UserMainId);
            return(View(locationMain));
        }
Exemple #3
0
    void getLocation()
    {
        locMeta   = locations[0].GetComponent <LocationMain> ();
        locSprite = locations[0].GetComponent <SpriteRenderer> ().sprite;

        locationName = BaseSaver.getLocation();

        Debug.Log("locationName: " + locationName);
        sScreen = false;

        if (locationName.Length > 0)
        {
            GameObject qPanel = GameObject.Find("QuestPanel");
            qPanel.SetActive(false);
            TileInfo outsideTileInfo = BaseSaver.getLocationTile();
            BaseSaver.resetLocation();
            if (locationName.Equals("StartScreen"))
            {
                GameObject.Find("InfoGame").SetActive(false);
                locMeta   = startScreen.GetComponent <LocationMain> ();
                locSprite = startScreen.GetComponent <SpriteRenderer> ().sprite;
                sScreen   = true;
            }
            else
            {
                GameInfo game = gameState.Pop();
                Dictionary <string, int> rewards       = new Dictionary <string, int>();
                List <QuestInfo>         currentQuests = new List <QuestInfo> ();
                foreach (QuestInfo quest in game.quests)
                {
                    if (quest.rewardAtNext)
                    {
                        Debug.Log("Quest: " + quest.title + " completed!");
                        foreach (ResInfo res in quest.rewards)
                        {
                            addResource(game, res);
                            if (rewards.ContainsKey(res.name))
                            {
                                rewards [res.name] += res.value;
                            }
                            else
                            {
                                rewards.Add(res.name, res.value);
                            }
                        }
                    }
                    else
                    {
                        Debug.Log("Quest: " + quest.title + " ongoing...");
                        currentQuests.Add(quest);
                    }
                }

                if (rewards.Keys.Count > 0)
                {
                    qPanel.SetActive(true);

                    for (int i = 0; i < 4; i++)
                    {
                        if (rewards.Keys.Count > i)
                        {
                            GameObject.Find("QItem0" + (i + 1)).GetComponent <Text>().text = rewards.Keys.ToList()[i] + ": " + rewards[rewards.Keys.ToList()[i]].ToString();
                        }
                        else
                        {
                            GameObject.Find("QItem0" + (i + 1)).SetActive(false);
                        }
                    }

                    StartCoroutine(WaitPanel());
                }

                game.quests = currentQuests.ToArray();
                Debug.Log("Saving Game Post Quest");
                gameState.Push(game);


                //Quest rewards need to be checked right here
//        UnitInfo[] units = BaseSaver.getUnits();
//        if (units != null && units.Length > 0) {
//          for (int i = 0; i < units.Length; i++) {
//            if (units[i].human) {
//              QHexBoard qBoard = new QHexBoard(BaseSaver.getBoardInfo().width, BaseSaver.getBoardInfo().height, HexCellPrefab);
//              HexCell[] cells = qBoard.getCells();
//              List<QuestInfo> currentQuests = new List<QuestInfo> ();
//              foreach(QuestInfo quest in game.quests){
//                if (quest.startIdx.Equals(cells[i].coordinates) && quest.completed) {
//                  foreach (ResInfo res in quest.rewards) {
//                    addResource (game, res);
//                  }
//                } else {
//                  currentQuests.Add (quest);
//                }
//              }
//              game.quests = currentQuests.ToArray ();
//              BaseSaver.putGame (game);
//            }
//          }
//        }

                foreach (GameObject location in locations)
                {
                    LocationMain main = location.GetComponent <LocationMain> ();

                    Debug.Log("Loc: " + main.area.ToString());
                    Debug.Log("LocFind: " + locationName);

                    if (main.area.ToString().Equals(locationName))
                    {
                        locMeta   = location.GetComponent <LocationMain> ();
                        locSprite = location.GetComponent <SpriteRenderer> ().sprite;
                        if (outsideTileInfo != null)
                        {
                            Debug.Log("Changing Name to: " + outsideTileInfo.meta);
                            locMeta.info.header = outsideTileInfo.meta;
                        }
                    }
                }
            }
        }

        TraverseMeta(locMeta.info, true);
    }