Exemple #1
0
        // Places an object on the grid using floats
        public void PlaceOnGrid(float fxCo, float fyCo, Quaternion rot, MapResource objectCode)
        {
            int xCo = XToCo(fxCo, fyCo);
            int yCo = YToCo(fxCo, fyCo);

            PlaceOnGrid(xCo, yCo, rot, objectCode);
        }
 public void StartCollecting(MapResource resource)
 {
     currentCollecting = resource;
     currentResource   = resource;
     isCollecting      = true;
     collectResourcePopup.Show();
 }
Exemple #3
0
 private static EnemyCellViewModel[] CreateEnemyCells(
     MapInfo mi,
     IReadOnlyDictionary <MapInfo, Dictionary <MapCell, Dictionary <string, FleetData> > > mapEnemies,
     IReadOnlyDictionary <MapCell, CellType> cellTypes)
 {
     return(MapResource.HasMapSwf(mi)
         ? MapResource.GetMapCellPoints(mi) //マップSWFがあったらそれを元に作る
            //外部結合
            .GroupJoin(
                CreateMapCellViewModelsFromEnemiesData(mi, mapEnemies, cellTypes),
                outer => outer.Key,
                inner => inner.Key,
                (o, ie) => new { point = o, cells = ie })
            .SelectMany(
                x => x.cells.DefaultIfEmpty(),
                (x, y) => new { x.point, cells = y })
            //座標マージ
            .GroupBy(x => x.point.Value)
            .Select(x => new EnemyCellViewModel
     {
         Key = x.Min(y => y.point.Key),              //若い番号を採用
         EnemyFleets = x.Where(y => y.cells != null) //敵データをEnemyIdでマージ
                       .SelectMany(y => y.cells.EnemyFleets)
                       .SelectMany(y => y.Fleets)
                       .MergeEnemies(),
         ColorNo = x.Where(y => y.cells != null).Select(y => y.cells.ColorNo).FirstOrDefault(),
         CellType = x.Where(y => y.cells != null).Select(y => y.cells.CellType).FirstOrDefault(),
     })
            //敵データのないセルは除外
            .Where(x => x.EnemyFleets.Any())
            .ToArray()
         : CreateMapCellViewModelsFromEnemiesData(mi, mapEnemies, cellTypes).ToArray());  //なかったら敵データだけ(重複るが仕方ない)
 }
    public void SetResource(MapResource resource)
    {
        targetResource = resource;

        icon.sprite = resource.resourceObject.image;
        amount.text = resource.amount.ToString();

        //ResetFill();
        Show();
    }
Exemple #5
0
        // Places an object on the grid according to placement system of ints and map
        public void PlaceOnGrid(int xCo, int yCo, Quaternion rot, MapResource objectCode)
        {
            Vector3 objPos = new Vector3(mapGrid[xCo, yCo][0],
                                         mapGrid[xCo, yCo][1] + grassTopHeight,
                                         mapGrid[xCo, yCo][2]);

            objectGrid[xCo, yCo] = MonoBehaviour.Instantiate(HexMapController.resourceMap[objectCode],
                                                             objPos,
                                                             rot);
        }
Exemple #6
0
        public IActionResult Post([FromBody] CreateMapRequest newMap)
        {
            Player player      = (Player)this.HttpContext.Items["Player"];
            Map    map         = new Map(newMap.MapLayout, newMap.Name, player);
            bool   addedToRepo = mapRepo.Add(map);

            if (addedToRepo)
            {
                MapResource mapResource = new MapResource {
                    Id = map.Id
                };
                return(new ObjectResult(mapResource));
            }
            return(new BadRequestResult());
        }
 public EnemyWindowViewModel(
     Dictionary <MapInfo, Dictionary <MapCell, Dictionary <int, FleetData> > > mapEnemies,
     Dictionary <MapCell, CellType> cellTypes,
     Dictionary <int, List <MapCellData> > cellDatas)
 {
     this.EnemyMaps = Master.Current.MapInfos
                      .Select(mi => new EnemyMapViewModel
     {
         Info      = mi.Value,
         CellDatas = cellDatas.ContainsKey(mi.Key) ? cellDatas[mi.Key] : new List <MapCellData>(),
         //セルポイントデータに既知の敵データを外部結合して座標でマージ
         EnemyCells = MapResource.HasMapSwf(mi.Value)
                 ? MapResource.GetMapCellPoints(mi.Value) //マップSWFがあったらそれを元に作る
                                                          //外部結合
                      .GroupJoin(
             CreateMapCellViewModelsFromEnemiesData(mi, mapEnemies, cellTypes),
             outer => outer.Key,
             inner => inner.Key,
             (o, ie) => new { point = o, cells = ie })
                      .SelectMany(
             x => x.cells.DefaultIfEmpty(),
             (x, y) => new { x.point, cells = y })
                      //座標マージ
                      .GroupBy(x => x.point.Value)
                      .Select(x => new EnemyCellViewModel
         {
             Key         = x.Min(y => y.point.Key),      //若い番号を採用
             EnemyFleets = x.Where(y => y.cells != null) //敵データをEnemyIdでマージ
                           .SelectMany(y => y.cells.EnemyFleets)
                           .GroupBy(y => y.Key)
                           .OrderBy(y => y.Key)
                           .Select(y => y.First())
                           .Distinct(new FleetComparer())    //同一編成の敵を除去
                           .ToArray(),
             ColorNo  = x.Where(y => y.cells != null).Select(y => y.cells.ColorNo).FirstOrDefault(),
             CellType = x.Where(y => y.cells != null).Select(y => y.cells.CellType).FirstOrDefault(),
         })
                      //敵データのないセルは除外
                      .Where(x => x.EnemyFleets.Any())
                      .ToArray()
                 : CreateMapCellViewModelsFromEnemiesData(mi, mapEnemies, cellTypes) //なかったら敵データだけ(重複るが仕方ない)
                      .OrderBy(cell => cell.Key)
                      .ToArray(),
     })
                      .OrderBy(info => info.Info.Id)
                      .ToArray();
 }
Exemple #8
0
        public IActionResult Get(string id)
        {
            Map map = mapRepo.Get(id);

            if (map == null)
            {
                return(NotFound());
            }

            // Map the Domain Model to the Resource model.
            var mapResource = new MapResource {
                Id        = map.Id,
                Name      = map.Name,
                MapLayout = map.GetMapAsMatrix()
            };

            //mapResource.Relations.Add(Link.CreateLink(Url.Link("UserDetailsRoute", new {id = map.Creator.Id})));
            return(new OkObjectResult(mapResource));
        }
Exemple #9
0
//  // Called every frame. 'delta' is the elapsed time since the previous frame.
//  public override void _Process(float delta)
//  {
//
//  }

    public void OnItemPressed(int id)
    {
        //Console.WriteLine($"Item pressed: {id}");
        string itemName = GetPopup().GetItemText(id);

        switch (itemName)
        {
        case Normal:
            world.UpdateDisplayMode(DisplayMode.Normal);
            break;

        case Height:
            world.UpdateDisplayMode(DisplayMode.Height);
            break;

        case MoistureNoise:
            world.UpdateDisplayMode(DisplayMode.MoistureNoise);
            break;

        case LatTemperature:
            world.UpdateDisplayMode(DisplayMode.LatTemperature);
            break;

        case CellMoisture:
            world.UpdateDisplayMode(DisplayMode.CellMoisture);
            break;

        case Moisture:
            world.UpdateDisplayMode(DisplayMode.Moisture);
            break;

        case WalkingSpeed:
            world.UpdateDisplayMode(DisplayMode.WalkingSpeed);
            break;

        default:
            //should be a map resource
            MapResource mapResource = world.GetMapResource(itemName);
            world.DisplayMapResource(mapResource);
            break;
        }
    }
Exemple #10
0
            //constructor
            public FactionResources(MapResource[] mapResources, bool playerFaction, float needRatio)
            {
                if (playerFaction)            //if this is the player's faction
                {
                    Resources = mapResources; //because we want to keep the UI elements references
                    foreach (MapResource r in Resources)
                    {
                        r.ResetCurrAmount();
                    }
                }
                else //if not..
                {
                    //make a deep copy of the map resources
                    Resources = new MapResource[mapResources.Length];
                    for (int i = 0; i < Resources.Length; i++)
                    {
                        Resources[i] = new MapResource(mapResources[i].GetResourceType());
                    }
                }

                resourceNeedRatio = needRatio;
            }
 public void ClearMapResourceDisplay()
 {
     mapResource = null;
     Update();
 }
Exemple #12
0
        /// <summary>
        /// 绘制点缓冲
        /// </summary>
        private void DrawBufferByPoint(ESRI.ArcGIS.ADF.Web.Geometry.Point adfPt)
        {
            //1.连接服务器
            AGSServerConnection connection = new AGSServerConnection();

            connection.Host = "localhost";
            connection.Connect();

            //2.获得服务器
            IServerObjectManager pSom      = connection.ServerObjectManager;
            IServerContext       pSc       = pSom.CreateServerContext("china", "MapServer");//服务名和类型
            IMapServer           mapServer = pSc.ServerObject as IMapServer;

            //3.使用服务器对象 几何对象转换
            IMapServerObjects pMso = mapServer as IMapServerObjects;
            //ESRI.ArcGIS.Geometry.IGeometry comPt = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ValueObjectToComObject(adfPt, pSc)
            //    as ESRI.ArcGIS.Geometry.IGeometry;////ValueObjectToComObject(pnt, pSC);
            IPoint pt = new ESRI.ArcGIS.Geometry.PointClass();

            pt.X = adfPt.X;
            pt.Y = adfPt.Y;
            ESRI.ArcGIS.Geometry.IGeometry comPt = pt;

            ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment sre = new SpatialReferenceEnvironment();
            ISpatialReference pSR = sre.CreateGeographicCoordinateSystem(4326);

            comPt.SpatialReference = pSR;

            //绘制buffer
            ITopologicalOperator pTOPO = comPt as ITopologicalOperator;

            pTOPO.Simplify();//??
            double   bufDis  = Map1.Extent.Width / 2;
            IPolygon bufPoly = pTOPO.Buffer(10) as IPolygon;

            bufPoly.Densify(0, 0);
            ESRI.ArcGIS.ADF.ArcGISServer.PolygonN valuePolyN = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ComObjectToValueObject(bufPoly, pSc, typeof(ESRI.ArcGIS.ADF.ArcGISServer.PolygonN)) as ESRI.ArcGIS.ADF.ArcGISServer.PolygonN;
            ESRI.ArcGIS.ADF.Web.Geometry.Polygon  adfPoly    = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ToAdfPolygon(valuePolyN) as ESRI.ArcGIS.ADF.Web.Geometry.Polygon;


            #region Densify
            ////***Densify
            // ESRI.ArcGIS.Geometry.IPointCollection com_pointcollection = (ESRI.ArcGIS.Geometry.IPointCollection)bufPoly;
            // ESRI.ArcGIS.ADF.Web.Geometry.PointCollection new_adf_pointcollection = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.ComObjectToValueObject(com_pointcollection, pSc, typeof(ESRI.ArcGIS.ADF.ArcGISServer.poly));
            //ESRI.ArcGIS.ADF.Web.Geometry.PointCollection new_adf_pointcollection = new ESRI.ArcGIS.ADF.Web.Geometry.PointCollection();
            //for (int i = 0; i < com_pointcollection.PointCount - 1; i++)
            //{
            //    ESRI.ArcGIS.ADF.Web.Geometry.Point new_adf_pt = new ESRI.ArcGIS.ADF.Web.Geometry.Point();
            //    new_adf_pt.X = com_pointcollection.get_Point(i).X;
            //    new_adf_pt.Y = com_pointcollection.get_Point(i).Y;
            //    new_adf_pointcollection.Add(new_adf_pt);
            //}
            //ESRI.ArcGIS.ADF.Web.Geometry.Ring new_adf_ring = new ESRI.ArcGIS.ADF.Web.Geometry.Ring();
            //new_adf_ring.Points = new_adf_pointcollection;
            //ESRI.ArcGIS.ADF.Web.Geometry.RingCollection new_adf_ringcollection = new ESRI.ArcGIS.ADF.Web.Geometry.RingCollection();
            //new_adf_ringcollection.Add(new_adf_ring);
            //ESRI.ArcGIS.ADF.Web.Geometry.Polygon new_adf_polygon = new ESRI.ArcGIS.ADF.Web.Geometry.Polygon();
            //new_adf_polygon.Rings = new_adf_ringcollection;
            //ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom = new_adf_polygon as ESRI.ArcGIS.ADF.Web.Geometry.Geometry;
            ////*******Densify
            #endregion

            ESRI.ArcGIS.ADF.Web.Geometry.Geometry geom = adfPoly as ESRI.ArcGIS.ADF.Web.Geometry.Geometry;
            GraphicElement geoEle = new GraphicElement(geom, System.Drawing.Color.Red);
            try
            {
                Map1.Zoom(adfPoly);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            geoEle.Symbol.Transparency = 50;

            IEnumerable gfc = Map1.GetFunctionalities();

            MapResource gMap = null;
            foreach (IGISFunctionality gfunc in gfc)
            {
                if (gfunc.Resource.Name == "graph")
                {
                    gMap = (MapResource)gfunc.Resource;
                    break;
                }
            }
            if (gMap == null)
            {
                return;
            }
            ElementGraphicsLayer glayer = null;
            foreach (DataTable dt in gMap.Graphics.Tables)
            {
                if (dt is ElementGraphicsLayer)
                {
                    glayer = dt as ElementGraphicsLayer;
                    break;
                }
            }
            if (glayer == null)
            {
                glayer = new ElementGraphicsLayer();
                gMap.Graphics.Tables.Add(glayer);
            }

            glayer.Clear();//清除数据
            glayer.Add(geoEle);

            //4.释放服务器对象
            pSc.ReleaseContext();

            if (Map1.ImageBlendingMode == ImageBlendingMode.WebTier)
            {
                Map1.Refresh();
            }
            else if (Map1.ImageBlendingMode == ImageBlendingMode.Browser)
            {
                Map1.RefreshResource(gMap.Name);
            }
            return;
        }
Exemple #13
0
    void Start()
    {
        m_TerrainSprites = new List <List <Sprite> >();
        m_TerrainSprites.Add(m_DirtSprites);
        m_TerrainSprites.Add(m_SandSprites);
        m_TerrainSprites.Add(m_GrassSprites);
        m_TerrainSprites.Add(m_SnowSprites);
        m_TerrainSprites.Add(m_SwampSprites);
        m_TerrainSprites.Add(m_RoughSprites);
        m_TerrainSprites.Add(m_SubterraneanSprites);
        m_TerrainSprites.Add(m_LavaSprites);
        m_TerrainSprites.Add(new List <Sprite>());
        m_TerrainSprites.Add(m_RockSprites);

        m_RiverSprites = new List <List <Sprite> >();
        m_RiverSprites.Add(new List <Sprite>());
        m_RiverSprites.Add(m_IcyRiverSprites);
        m_RiverSprites.Add(m_MuddyRiverSprites);
        m_RiverSprites.Add(new List <Sprite>());

        m_RoadSprites = new List <List <Sprite> >();
        m_RoadSprites.Add(m_DirtRoadSprites);
        m_RoadSprites.Add(m_GravelRoadSprites);
        m_RoadSprites.Add(m_CobbleRoadSprites);

        if (m_GameSettings.Scenario.Version != Scenario.SHADOW_OF_DEATH)
        {
            Debug.Log($"This map isn't SoD, not supported yet");
            return;
        }

        int _Size = m_GameSettings.Scenario.Size;

        m_TerrainFrame.size = new Vector2(_Size + 2, _Size + 2);
        m_TerrainFrame.transform.localPosition = new Vector3(_Size / 2 - 0.5f, -_Size / 2 + 0.5f, 0);
        m_TerrainMask.localScale = new Vector3(_Size, _Size, 1);
        m_TerrainMask.transform.localPosition = new Vector3(_Size / 2 - 0.5f, -_Size / 2 + 0.5f, 0);

        // <><><><><> Above Ground Terrain

        List <TerrainTile> _Terrain = m_GameSettings.Scenario.Terrain;

        m_TerrainTileObjects = new List <TerrainTileObject>(_Terrain.Capacity);
        m_RiverTileObjects   = new List <TerrainTileObject>();
        m_RoadTileObjects    = new List <TerrainTileObject>();

        for (int x = 0; x < _Size; x++)
        {
            for (int y = 0; y < _Size; y++)
            {
                int _Index = x + y * _Size;

                // <><><><><> Terrain Tile

                TerrainTileObject _TileObject = Instantiate(m_TileObjectPrefab, new Vector2(x, -y), Quaternion.identity);

                _TileObject.Renderer.sortingOrder = -32768;

                if (_Terrain[_Index].TerrainType < m_TerrainSprites.Count)
                {
                    if (_Terrain[_Index].TerrainType == WATER_TILE_INDEX)
                    {
                        _TileObject.AnimationRenderer.SetSprites(m_WaterAnimations[_Terrain[_Index].TerrainSpriteID].Array);
                    }
                    else if (_Terrain[_Index].TerrainSpriteID < m_TerrainSprites[_Terrain[_Index].TerrainType].Count)
                    {
                        _TileObject.Renderer.sprite = m_TerrainSprites[_Terrain[_Index].TerrainType][_Terrain[_Index].TerrainSpriteID];
                    }
                    else
                    {
                        Debug.Log($"Failed ID {_Terrain[_Index].TerrainSpriteID}");
                    }
                }
                else
                {
                    Debug.Log($"Failed Type {_Terrain[_Index].TerrainType}");
                }

                _TileObject.Renderer.sortingLayerName = "Terrain";
                _TileObject.Renderer.flipX            = (_Terrain[_Index].Mirrored & 1) == 1;
                _TileObject.Renderer.flipY            = (_Terrain[_Index].Mirrored & 2) == 2;

                _TileObject.name = $"{_TileObject.Renderer.sprite.name}  Pos {_Index}  ID {_Terrain[_Index].TerrainSpriteID}";

                _TileObject.transform.parent = m_TerrainTileObjectParent;

                m_TerrainTileObjects.Add(_TileObject);

                // <><><><><> River Tile

                if (_Terrain[_Index].RiverType != 0)
                {
                    _TileObject = Instantiate(m_TileObjectPrefab, new Vector2(x, -y), Quaternion.identity);

                    if (_Terrain[_Index].RiverType - 1 < m_RiverSprites.Count)
                    {
                        if (_Terrain[_Index].RiverType == CLEAR_RIVER_INDEX)
                        {
                            _TileObject.AnimationRenderer.SetSprites(m_ClearRiverAnimations[_Terrain[_Index].RiverSpriteID].Array);
                        }
                        else if (_Terrain[_Index].RiverType == LAVA_RIVER_INDEX)
                        {
                            _TileObject.AnimationRenderer.SetSprites(m_LavaRiverAnimations[_Terrain[_Index].RiverSpriteID].Array);
                        }
                        else if (_Terrain[_Index].RiverSpriteID < m_RiverSprites[_Terrain[_Index].RiverType - 1].Count)
                        {
                            _TileObject.Renderer.sprite = m_RiverSprites[_Terrain[_Index].RiverType - 1][_Terrain[_Index].RiverSpriteID];
                        }
                        else
                        {
                            Debug.Log($"River Failed ID {_Terrain[_Index].RiverSpriteID}");
                        }
                    }
                    else
                    {
                        Debug.Log($"River Failed Type {_Terrain[_Index].RiverSpriteID}");
                    }

                    _TileObject.Renderer.sortingOrder     = 1;
                    _TileObject.Renderer.sortingLayerName = "Terrain";
                    _TileObject.Renderer.flipX            = (_Terrain[_Index].Mirrored & 4) == 4;
                    _TileObject.Renderer.flipY            = (_Terrain[_Index].Mirrored & 8) == 8;

                    _TileObject.name = $"{_TileObject.Renderer.sprite.name}  Pos {_Index}  ID {_Terrain[_Index].RiverSpriteID}";

                    _TileObject.transform.parent = m_RiverTileObjectParent;

                    m_RiverTileObjects.Add(_TileObject);
                }

                // <><><><><> Road Tile

                if (_Terrain[_Index].RoadType != 0)
                {
                    _TileObject = Instantiate(m_TileObjectPrefab, new Vector2(x, -y - 0.5f), Quaternion.identity);

                    if (_Terrain[_Index].RoadType - 1 < m_RoadSprites.Count)
                    {
                        if (_Terrain[_Index].RoadSpriteID < m_RoadSprites[_Terrain[_Index].RoadType - 1].Count)
                        {
                            _TileObject.Renderer.sprite = m_RoadSprites[_Terrain[_Index].RoadType - 1][_Terrain[_Index].RoadSpriteID];
                        }
                        else
                        {
                            Debug.Log($"Road Failed ID {_Terrain[_Index].RoadSpriteID}");
                        }
                    }
                    else
                    {
                        Debug.Log($"Road Failed Type {_Terrain[_Index].RoadSpriteID}");
                    }

                    _TileObject.Renderer.sortingOrder     = 2;
                    _TileObject.Renderer.sortingLayerName = "Terrain";
                    _TileObject.Renderer.flipX            = (_Terrain[_Index].Mirrored & 16) == 16;
                    _TileObject.Renderer.flipY            = (_Terrain[_Index].Mirrored & 32) == 32;

                    _TileObject.name = $"{_TileObject.Renderer.sprite.name}  Pos {_Index}  ID {_Terrain[_Index].RoadSpriteID}";

                    _TileObject.transform.parent = m_RoadTileObjectParent;

                    m_RoadTileObjects.Add(_TileObject);
                }
            }
        }

        if (m_GameSettings.Scenario.HasUnderground)
        {
            // <><><><><> Underground Terrain

            List <TerrainTile> _UndergroundTerrain = m_GameSettings.Scenario.UndergroundTerrain;

            m_UndergroundTerrainTileObjects = new List <TerrainTileObject>(_Terrain.Capacity);
            m_UndergroundRiverTileObjects   = new List <TerrainTileObject>();
            m_UndergroundRoadTileObjects    = new List <TerrainTileObject>();

            for (int x = 0; x < _Size; x++)
            {
                for (int y = 0; y < _Size; y++)
                {
                    int _Index = x + y * _Size;

                    // <><><><><> Terrain Tile

                    TerrainTileObject _TileObject = Instantiate(m_TileObjectPrefab, new Vector2(x, -y), Quaternion.identity);

                    _TileObject.Renderer.sortingOrder = -32768;

                    if (_UndergroundTerrain[_Index].TerrainType < m_TerrainSprites.Count)
                    {
                        if (_UndergroundTerrain[_Index].TerrainType == WATER_TILE_INDEX)
                        {
                            if (m_WaterAnimations[_UndergroundTerrain[_Index].TerrainSpriteID] != null)
                            {
                                _TileObject.AnimationRenderer.SetSprites(m_WaterAnimations[_UndergroundTerrain[_Index].TerrainSpriteID].Array);
                            }
                        }
                        else if (_UndergroundTerrain[_Index].TerrainSpriteID < m_TerrainSprites[_UndergroundTerrain[_Index].TerrainType].Count)
                        {
                            _TileObject.Renderer.sprite = m_TerrainSprites[_UndergroundTerrain[_Index].TerrainType][_UndergroundTerrain[_Index].TerrainSpriteID];
                        }
                        else
                        {
                            Debug.Log($"Failed ID {_UndergroundTerrain[_Index].TerrainSpriteID}");
                        }
                    }
                    else
                    {
                        Debug.Log($"Failed Type {_UndergroundTerrain[_Index].TerrainType}");
                    }

                    _TileObject.Renderer.sortingLayerName = "Terrain";
                    _TileObject.Renderer.flipX            = (_UndergroundTerrain[_Index].Mirrored & 1) == 1;
                    _TileObject.Renderer.flipY            = (_UndergroundTerrain[_Index].Mirrored & 2) == 2;

                    _TileObject.name = $"{_TileObject.Renderer.sprite.name}  Pos {_Index}  ID {_UndergroundTerrain[_Index].TerrainSpriteID}";

                    _TileObject.transform.parent = m_UndergroundTerrainTileObjectParent;

                    m_UndergroundTerrainTileObjects.Add(_TileObject);

                    // <><><><><> River Tile

                    if (_UndergroundTerrain[_Index].RiverType != 0)
                    {
                        _TileObject = Instantiate(m_TileObjectPrefab, new Vector2(x, -y), Quaternion.identity);

                        if (_UndergroundTerrain[_Index].RiverType == CLEAR_RIVER_INDEX)
                        {
                            _TileObject.AnimationRenderer.SetSprites(m_ClearRiverAnimations[_UndergroundTerrain[_Index].RiverSpriteID].Array);
                        }
                        else if (_UndergroundTerrain[_Index].RiverType == LAVA_RIVER_INDEX)
                        {
                            _TileObject.AnimationRenderer.SetSprites(m_LavaRiverAnimations[_UndergroundTerrain[_Index].RiverSpriteID].Array);
                        }
                        else if (_UndergroundTerrain[_Index].RiverSpriteID < m_RiverSprites[_UndergroundTerrain[_Index].RiverType - 1].Count)
                        {
                            _TileObject.Renderer.sprite = m_RiverSprites[_UndergroundTerrain[_Index].RiverType - 1][_UndergroundTerrain[_Index].RiverSpriteID];
                        }
                        else
                        {
                            Debug.Log($"River Failed ID {_UndergroundTerrain[_Index].RiverSpriteID}");
                        }

                        _TileObject.Renderer.sortingOrder     = 1;
                        _TileObject.Renderer.sortingLayerName = "Terrain";
                        _TileObject.Renderer.flipX            = (_UndergroundTerrain[_Index].Mirrored & 4) == 4;
                        _TileObject.Renderer.flipY            = (_UndergroundTerrain[_Index].Mirrored & 8) == 8;

                        _TileObject.name = $"{_TileObject.Renderer.sprite.name}  Pos {_Index}  ID {_UndergroundTerrain[_Index].RiverSpriteID}";

                        _TileObject.transform.parent = m_UndergroundRiverTileObjectParent;

                        m_UndergroundRiverTileObjects.Add(_TileObject);
                    }

                    // <><><><><> Road Tile

                    if (_UndergroundTerrain[_Index].RoadType != 0)
                    {
                        _TileObject = Instantiate(m_TileObjectPrefab, new Vector2(x, -y - 0.5f), Quaternion.identity);

                        if (_UndergroundTerrain[_Index].RoadType - 1 < m_RoadSprites.Count)
                        {
                            if (_UndergroundTerrain[_Index].RoadSpriteID < m_RoadSprites[_UndergroundTerrain[_Index].RoadType - 1].Count)
                            {
                                _TileObject.Renderer.sprite = m_RoadSprites[_UndergroundTerrain[_Index].RoadType - 1][_UndergroundTerrain[_Index].RoadSpriteID];
                            }
                            else
                            {
                                Debug.Log($"Road Failed ID {_UndergroundTerrain[_Index].RoadSpriteID}");
                            }
                        }
                        else
                        {
                            Debug.Log($"Road Failed Type {_UndergroundTerrain[_Index].RoadSpriteID}");
                        }

                        _TileObject.Renderer.sortingOrder     = 2;
                        _TileObject.Renderer.sortingLayerName = "Terrain";
                        _TileObject.Renderer.flipX            = (_UndergroundTerrain[_Index].Mirrored & 16) == 16;
                        _TileObject.Renderer.flipY            = (_UndergroundTerrain[_Index].Mirrored & 32) == 32;

                        _TileObject.name = $"{_TileObject.Renderer.sprite.name}  Pos {_Index}  ID {_UndergroundTerrain[_Index].RoadSpriteID}";

                        _TileObject.transform.parent = m_UndergroundRoadTileObjectParent;

                        m_UndergroundRoadTileObjects.Add(_TileObject);
                    }
                }
            }
        }

        // <><><><><> Objects

        m_OverworldObjects   = new List <GameObject>();
        m_UndergroundObjects = new List <GameObject>();

        List <ScenarioObject> _Objects    = m_GameSettings.Scenario.Objects;
        List <MapObjectBase>  _MapObjects = new List <MapObjectBase>(_Objects.Count);
        Dictionary <ScenarioObject, DynamicMapObstacle> _DynamicObstacles = new Dictionary <ScenarioObject, DynamicMapObstacle>();

        // Load map objects
        for (int i = 0; i < _Objects.Count; i++)
        {
            ScenarioObject _Object = _Objects[i];
            MapObjectBase  _MapObject;

            switch (_Object.Template.Type)
            {
            case ScenarioObjectType.Hero:
                MapHero _Hero = Instantiate(m_MapHeroPrefab, m_MapObjectParent);
                _Hero.Initialize(_Object, m_GameReferences);
                _MapObject = _Hero;
                _DynamicObstacles.Add(_Object, _Hero.DynamicObstacle);
                break;

            case ScenarioObjectType.Resource:
                MapResource _Resource = Instantiate(m_MapResourcePrefab, m_MapObjectParent);
                _Resource.Initialize(_Object, m_GameReferences);
                _MapObject = _Resource;
                _DynamicObstacles.Add(_Object, _Resource.DynamicObstacle);
                break;

            case ScenarioObjectType.Dwelling:
            case ScenarioObjectType.Mine:               // Temporary
            case ScenarioObjectType.AbandonedMine:      // Temporary
                MapDwelling _Dwelling = Instantiate(m_MapDwellingPrefab, m_MapObjectParent);
                _Dwelling.Initialize(_Object, m_GameReferences);
                _MapObject = _Dwelling;
                break;

            case ScenarioObjectType.Town:
                MapTown _Town = Instantiate(m_MapTownPrefab, m_MapObjectParent);

                // Determine if this town can build a shipyard, and where the ship will spawn
                Vector2Int _ShipyardSpot = Vector2Int.zero;

                Vector2Int _ShipyardSpot1 = new Vector2Int(_Object.PosX - 3, _Object.PosY + 2);
                Vector2Int _ShipyardSpot2 = new Vector2Int(_Object.PosX - 1, _Object.PosY + 2);

                int _ShipyardIndex1 = _ShipyardSpot1.x + _ShipyardSpot1.y * _Size;
                int _ShipyardIndex2 = _ShipyardSpot2.x + _ShipyardSpot2.y * _Size;

                if (_ShipyardIndex1 < _Size * _Size)
                {
                    if (_Terrain[_ShipyardIndex1].TerrainType == WATER_TILE_INDEX)
                    {
                        _ShipyardSpot = _ShipyardSpot1;
                    }
                    else if (_ShipyardIndex2 < _Size * _Size &&
                             _Terrain[_ShipyardIndex2].TerrainType == WATER_TILE_INDEX)
                    {
                        _ShipyardSpot = _ShipyardSpot2;
                    }
                }

                // If _ShipyardSpot is still Vector2Int.zero, there's no shipyard
                _Town.Initialize(_Object, m_GameReferences, _ShipyardSpot);
                _MapObject = _Town;
                break;

            case ScenarioObjectType.Monster:
                MapMonster _Monster = Instantiate(m_MapMonsterPrefab, m_MapObjectParent);
                _Monster.Initialize(_Object, m_GameReferences);
                _MapObject = _Monster;
                _DynamicObstacles.Add(_Object, _Monster.DynamicObstacle);
                break;

            case ScenarioObjectType.Garrison:
                MapGarrison _Garrison = Instantiate(m_MapGarrisonPrefab, m_MapObjectParent);
                _Garrison.Initialize(_Object, m_GameReferences);
                _MapObject = _Garrison;
                break;

            default:
                MapObject _Obj = Instantiate(m_MapObjectPrefab, m_MapObjectParent);
                _Obj.Initialize(_Object, m_GameReferences);
                _MapObject = _Obj;
                break;
            }

            _MapObject.transform.position = new Vector3(_Object.PosX + 0.5f, -_Object.PosY - 0.5f, 0);
            _MapObject.MouseCollision     = new byte[6];
            _MapObject.MouseCollision[0]  = (byte)(~_Object.Template.Passability[0] | _Object.Template.Interactability[0]);
            _MapObject.MouseCollision[1]  = (byte)(~_Object.Template.Passability[1] | _Object.Template.Interactability[1]);
            _MapObject.MouseCollision[2]  = (byte)(~_Object.Template.Passability[2] | _Object.Template.Interactability[2]);
            _MapObject.MouseCollision[3]  = (byte)(~_Object.Template.Passability[3] | _Object.Template.Interactability[3]);
            _MapObject.MouseCollision[4]  = (byte)(~_Object.Template.Passability[4] | _Object.Template.Interactability[4]);
            _MapObject.MouseCollision[5]  = (byte)(~_Object.Template.Passability[5] | _Object.Template.Interactability[5]);

            _MapObject.InteractionCollision = _Object.Template.Interactability;


            if (_Object.IsUnderground)
            {
                m_UndergroundObjects.Add(_MapObject.gameObject);
                _MapObject.transform.parent = m_UndergroundMapObjectParent;
            }
            else
            {
                m_OverworldObjects.Add(_MapObject.gameObject);
            }

            _MapObjects.Add(_MapObject);
        }

        m_Pathfinding.Generate(m_GameSettings.Scenario, _MapObjects, _DynamicObstacles);

        // Spawn starting heroes
        for (int i = 0; i < m_GameSettings.Players.Count; i++)
        {
            PlayerInfo _PlayerInfo = m_GameSettings.Scenario.PlayerInfo[i];
            if (_PlayerInfo.GenerateHeroAtMainTown)
            {
                MapHero _MapHero = Instantiate(m_MapHeroPrefab, m_MapObjectParent);

                // Spawn map object at main town coordinates
                if (_PlayerInfo.IsMainTownUnderground)
                {
                    _MapHero.transform.parent = m_UndergroundMapObjectParent;
                }

                Hero _Hero;

                if (_PlayerInfo.IsMainHeroRandom)
                {
                    _Hero = HeroPool.GetRandomHero(m_GameSettings.Players[i].Index, m_GameSettings.Players[i].Faction, true);
                    HeroPool.ClaimHero(_Hero);
                }
                else
                {
                    _Hero = m_GameSettings.Players[i].Hero;
                }

                _MapHero.Initialize
                (
                    _Hero,
                    m_GameSettings.Players[i].Index,
                    m_GameSettings.Scenario.PlayerInfo[i].MainTownXCoord + 1,
                    m_GameSettings.Scenario.PlayerInfo[i].MainTownYCoord,
                    m_GameSettings.Scenario.PlayerInfo[i].IsMainTownUnderground,
                    m_GameReferences
                );
            }
        }

        List <MapHero> _LocalOwnership = m_LocalOwnership.GetHeroes();

        if (_LocalOwnership.Count > 0)
        {
            m_LocalOwnership.SelectHero(_LocalOwnership[0]);
        }
    }
Exemple #14
0
 public void DisplayMapResource(MapResource mapResource)
 {
     this.mapResource = mapResource;
     Update();
 }
 public void StopCollecting()
 {
     isCollecting      = false;
     currentCollecting = null;
 }
    public void OnSelectResource(MapResource resource)
    {
        currentResource = resource;

        collectResourcePopup.SetResource(resource);
    }
Exemple #17
0
        public ReferenceStack(Construct scope, string id) : base(scope, id)
        {
            new EdgeProvider(this, "edge", new EdgeProviderConfig {
                Reqstr  = "reqstr",
                Reqnum  = 123,
                Reqbool = true
            });

            var res  = new OptionalAttributeResource(this, "test", new OptionalAttributeResourceConfig {
            });
            var list = new ListBlockResource(this, "list", new ListBlockResourceConfig {
                Req = new [] { new ListBlockResourceReq {
                                   Reqbool = true, Reqnum = 1, Reqstr = "reqstr"
                               }, new ListBlockResourceReq {
                                   Reqbool = false, Reqnum = 0, Reqstr = "reqstr2"
                               } },
                Singlereq = new ListBlockResourceSinglereq {
                    Reqbool = false, Reqnum = 1, Reqstr = "reqstr"
                }
            });
            var map = new MapResource(this, "map", new MapResourceConfig {
                OptMap = new Dictionary <string, string> {
                    ["Key1"] = "value1"
                },
                ReqMap = new Dictionary <string, object> {
                    ["Key1"] = true
                }
            });
            var set = new SetBlockResource(this, "set_block", new SetBlockResourceConfig {
                Set = new [] { new SetBlockResourceSet {
                                   Reqbool = true, Reqnum = 1, Reqstr = "reqstr"
                               }, new SetBlockResourceSet {
                                   Reqbool = false, Reqnum = 0, Reqstr = "reqstr2"
                               } }
            });

            // plain values
            new RequiredAttributeResource(this, "plain", new RequiredAttributeResourceConfig {
                Bool     = res.Bool,
                Str      = res.Str,
                Num      = res.Num,
                StrList  = res.StrList,
                NumList  = res.NumList,
                BoolList = res.BoolList
            });

            // required values FROM required single item lists
            new RequiredAttributeResource(this, "from_single_list", new RequiredAttributeResourceConfig {
                Bool     = list.Singlereq.Reqbool,
                Str      = list.Singlereq.Reqstr,
                Num      = list.Singlereq.Reqnum,
                StrList  = new [] { list.Singlereq.Reqstr },
                NumList  = new [] { list.Singlereq.Reqnum },
                BoolList = new [] { list.Singlereq.Reqbool }
            });

            // required values FROM required multi item lists
            new RequiredAttributeResource(this, "from_list", new RequiredAttributeResourceConfig {
                Bool     = Token.AsAny(Fn.Lookup(Fn.Element(list.Req, 0), "reqbool", false)),
                Str      = Token.AsString(Fn.Lookup(Fn.Element(list.Req, 0), "reqstr", "fallback")),
                Num      = Token.AsNumber(Fn.Lookup(Fn.Element(list.Req, 0), "reqnum", 0)),
                StrList  = new [] { Token.AsString(Fn.Lookup(Fn.Element(list.Req, 0), "reqstr", "fallback")) },
                NumList  = new [] { Token.AsNumber(Fn.Lookup(Fn.Element(list.Req, 0), "reqnum", 0)) },
                BoolList = new [] { Token.AsAny(Fn.Lookup(Fn.Element(list.Req, 0), "reqbool", false)) }
            });

            // passing a reference to a complete list
            // Not supported at this time.
            // Tricky to get working because of JSII interface limitations.
            // new ListBlockResource(this, "list_reference", new ListBlockResourceConfig {
            //     Req = list.Req,
            //     Singlereq = list.Singlereq
            // });

            // passing a literal array with references for a list
            // This doesn't work since the types of 'req' and 'singlereq' are different.
            // It works in TS/Python since the type definitions have the same properties.
            // new ListBlockResource(this, "list_literal", new ListBlockResourceConfig {
            //     Req = new [] { list.Singlereq },
            //     Singlereq = list.Singlereq
            // });

            // required values FROM map
            new RequiredAttributeResource(this, "from_map", new RequiredAttributeResourceConfig {
                Bool     = Token.AsAny(Fn.Lookup(map.ReqMap, "key1", false)),
                Str      = Token.AsString(Fn.Lookup(map.OptMap, "key1", "missing")),
                Num      = Token.AsNumber(Fn.Lookup(map.ComputedMap, "key1", 0)),
                StrList  = new [] { Token.AsString(Fn.Lookup(map.OptMap, "key1", "missing")) },
                NumList  = new [] { Token.AsNumber(Fn.Lookup(map.ComputedMap, "key1", 0)) },
                BoolList = new [] { Token.AsAny(Fn.Lookup(map.ReqMap, "key1", false)) }
            });

            // passing a reference to a complete map
            new MapResource(this, "map_reference", new MapResourceConfig {
                OptMap = map.OptMap,
                ReqMap = map.ReqMap
            });

            // passing a list ref into a set
            new SetBlockResource(this, "set_from_list", new SetBlockResourceConfig {
                Set = list.Req
            });

            // passing a set ref into a list
            new ListBlockResource(this, "list_from_set", new ListBlockResourceConfig {
                Req       = set.Set,
                Singlereq = new ListBlockResourceSinglereq {
                    Reqbool = true, Reqnum = 1, Reqstr = "reqstr"
                }
            });
        }