Exemplo n.º 1
0
    private void Update()
    {
        if (!freezer.IsInteractionFreeze)
        {
            if (Utils.IntersectionMouseRayWithXOZPlane(mainCamera, out Vector3 enter))
            {
                highlighter.SetActive(true);

                Vector3 hexCenter = worldMap.GetHexCenterPosition(enter);
                HandlingMouseInput(enter);

                bool isHexContainsLand     = worldMap.IsHexContainsLand(enter);
                bool isHexContainsResource = worldMap.IsHexContainsResource(enter);
                bool isHexMainBase         = worldMap.GetHexType(enter) == WorldMap.HexType.ColonyMainBase;

                if ((isOverMainBase && !isHexMainBase) || (!isOverMainBase && isHexMainBase))
                {
                    if (isOverMainBase && !isHexMainBase)
                    {
                        colonyTeritoryUnderMouse.Unhighlight();
                        colonyTeritoryUnderMouse = null;
                        isOverMainBase           = false;
                    }
                    else
                    {
                        colonyTeritoryUnderMouse = worldMap.GetColonyMainBase(enter).GetComponent <ColonyTeritory>();
                        colonyTeritoryUnderMouse.Highlight();
                        isOverMainBase = true;
                    }
                }

                Color hexColor;
                if (isHexContainsLand)
                {
                    hexColor = emptyHexColor;
                }
                else if (isHexContainsResource || isHexMainBase)
                {
                    hexColor = resourceHexColor;
                }
                else
                {
                    hexColor = noneHexColor;
                }

                previousColor = Color.Lerp(previousColor, hexColor, Time.deltaTime * colorChangeSpeed);
                currentMaterial.SetColor("Color_Highlight", previousColor);

                transform.position = Vector3.SmoothDamp(transform.position, hexCenter, ref currentVelocity, moveSmoothTime);
            }
            else
            {
                if (isShowingInfo)
                {
                    isShowingInfo = false;
                    hexCellInfoMenu.Hide();
                }
                highlighter.SetActive(false);
            }
        }
    }
Exemplo n.º 2
0
    private void SetResourcePrefabs(int aIForNPCSeed)
    {
        LimitedMinedResourceInfo[] hexTypeToLimitedMinedResourceInfo = new LimitedMinedResourceInfo[(int)WorldMap.HexType.AllResources];

        foreach (LimitedMinedResourceInfo resourceInfo in limitedMinedResourceInfoList.resourceInfos)
        {
            WorldMap.HexType hexType = WorldMap.GameResourceTypeToHexType(resourceInfo.gameResourceType);
            hexTypeToLimitedMinedResourceInfo[(int)hexType] = resourceInfo;
        }

        int currentAIForNPCOffset = aIForNPCSeed;

        for (int x = 0; x < cellColumns; ++x)
        {
            for (int y = 0; y < cellRows; ++y)
            {
                WorldMap.HexCell hexCell = worldMap.worldAreaInfo.area[x, y];
                if (WorldMap.IsResourceOnlyType(hexCell.hexType))
                {
                    GameResourceType gameResourceType = WorldMap.HexTypeToGameResourceType(hexCell.hexType);

                    GameObject resourceDeposit = Instantiate(resourceDepositPrefab,
                                                             worldMap.GetHexPosition(new Vector2Int(x, y)),
                                                             Quaternion.identity,
                                                             resourcesTransform);

                    ResourceSprite resourceSprite = resourceDeposit.GetComponent <ResourceSprite>();
                    resourceSprite.InitWithGameResourceType(gameResourceType);

                    ResourceDeposit resourceDepositScript = resourceDeposit.GetComponent <ResourceDeposit>();

                    LimitedMinedResourceInfo limitedMinedResourceInfo = hexTypeToLimitedMinedResourceInfo[(int)hexCell.hexType];
                    float resourceAmount = limitedMinedResourceInfo.minAmount +
                                           Mathf.Pow(hexCell.resourceAmount / maxPossibleResourceValuePerCell, limitedMinedResourceInfo.power) *
                                           (limitedMinedResourceInfo.maxAmount - limitedMinedResourceInfo.minAmount);
                    resourceDepositScript.SetResourceType(gameResourceType, resourceAmount);

                    hexCell.indexInResourceArray      = (short)worldMap.resourceDepositArray.Count;
                    worldMap.worldAreaInfo.area[x, y] = hexCell;
                    worldMap.resourceDepositArray.Add(resourceDepositScript);
                    worldMap.resourceDepositIndicesArray.Add(new Vector2Int(x, y));
                }
                else if (hexCell.hexType == WorldMap.HexType.Mountain)
                {
                    GameObject mountain = Instantiate(mountainPrefab,
                                                      worldMap.GetHexPosition(new Vector2Int(x, y)),
                                                      Quaternion.identity,
                                                      mountainsTransform);

                    EnvironmentHeightParameter environmentHeightParameter =
                        mountain.GetComponent <EnvironmentHeightParameter>();
                    environmentHeightParameter.InitHeight(hexCell.resourceAmount / maxPossibleResourceValuePerCell);
                }
                else if (hexCell.hexType == WorldMap.HexType.Crater)
                {
                    GameObject crater = Instantiate(craterPrefab,
                                                    worldMap.GetHexPosition(new Vector2Int(x, y)),
                                                    Quaternion.identity,
                                                    cratersTransform);

                    EnvironmentHeightParameter environmentHeightParameter =
                        crater.GetComponent <EnvironmentHeightParameter>();
                    environmentHeightParameter.InitHeight(hexCell.resourceAmount / maxPossibleResourceValuePerCell);
                }
                else if (hexCell.hexType == WorldMap.HexType.ColonyMainBase)
                {
                    GameObject mainBaseLocation = Instantiate(mainBaseLocationPrefab,
                                                              worldMap.GetHexPosition(new Vector2Int(x, y)),
                                                              Quaternion.identity,
                                                              mainBaseLocationsTransform);

                    ColonyTeritory colonyTeritory = mainBaseLocation.GetComponent <ColonyTeritory>();
                    Vector3[]      positions      = worldMap.GetHexRings(worldMap.GetHexPosition(new Vector2Int(x, y)), 1, colonyRaduis);
                    bool           isPlayer       = worldMap.colonyMainBaseArray.Count == 0;
                    colonyTeritory.InitAvailableHexes(new List <Vector3>(positions), isPlayer);

                    if (!isPlayer)
                    {
                        AIForNPC aIForNPC = mainBaseLocation.GetComponent <AIForNPC>();
                        aIForNPC.worldMap     = worldMap;
                        aIForNPC.freezer      = freezer;
                        aIForNPC.colonyRaduis = colonyRaduis;
                        aIForNPC.seed         = currentAIForNPCOffset;
                        aIForNPC.enabled      = true;

                        ++currentAIForNPCOffset;
                    }

                    hexCell.indexInColonyMainBaseArray = (short)worldMap.colonyMainBaseArray.Count;
                    worldMap.worldAreaInfo.area[x, y]  = hexCell;
                    worldMap.colonyMainBaseArray.Add(mainBaseLocation);
                    worldMap.colonyMainBaseIndicesArray.Add(new Vector2Int(x, y));
                }
            }
        }
    }