Beispiel #1
0
 override public void LevelUp(bool returnToUI)
 {
     if (!GameMaster.realMaster.weNeedNoResources)
     {
         ResourceContainer[] cost = GetUpgradeCost();
         if (!colony.storage.CheckBuildPossibilityAndCollectIfPossible(cost))
         {
             GameLogUI.NotEnoughResourcesAnnounce();
             return;
         }
     }
     if (level > 3)
     {
         SetBlockers();
     }
     level++;
     nextStageConditionMet = CheckUpgradeCondition();
     SetModel();
     buildingObserver.CheckUpgradeAvailability();
     Quest.ResetHousingQuest();
     GameLogUI.MakeAnnouncement(Localization.LevelReachedString(level));
     if (GameMaster.soundEnabled)
     {
         GameMaster.audiomaster.Notify(NotificationSound.HQ_Upgraded);
     }
     GameMaster.realMaster.eventTracker?.BuildingUpgraded(this);
 }
Beispiel #2
0
    public float BuyResource(ResourceType rt, float volume)
    {
        if (availableVolume <= 0f)
        {
            return(0f);
        }
        if (volume > availableVolume)
        {
            volume = availableVolume;
        }
        var   colony = GameMaster.realMaster.colonyController;
        float p = ResourceType.prices[rt.ID], money = 0f;

        if (p != 0)
        {
            money  = colony.GetEnergyCrystals(volume * ResourceType.prices[rt.ID]);
            volume = money / ResourceType.prices[rt.ID];
            if (volume == 0)
            {
                return(0f);
            }
            else
            {
                GameLogUI.MakeAnnouncement(Localization.GetBuyMsg(rt, volume, money));
            }
        }
        colony.storage.AddResource(rt, volume);
        colony.gears_coefficient -= gearsDamage * volume;
        availableVolume          -= volume;
        return(volume);
    }
Beispiel #3
0
    public static Crew CreateNewCrew(ColonyController home, int membersCount)
    {
        if (crewsList.Count >= RecruitingCenter.GetCrewsSlotsCount())
        {
            return(null);
        }
        if (crewsList.Count > MAX_CREWS_COUNT)
        {
            GameLogUI.MakeImportantAnnounce(Localization.GetAnnouncementString(GameAnnouncements.CrewsLimitReached));
            GameMaster.LoadingFail();
            return(null);
        }
        Crew c = new GameObject(Localization.NameCrew()).AddComponent <Crew>();

        if (crewsContainer == null)
        {
            crewsContainer = new GameObject("crewsContainer");
        }
        c.transform.parent = crewsContainer.transform;

        c.ID     = nextID; nextID++;
        c.atHome = true;

        //normal parameters
        c.membersCount = (byte)membersCount;
        //attributes
        c.SetAttributes(home);
        //
        crewsList.Add(c);
        listChangesMarkerValue++;
        return(c);
    }
Beispiel #4
0
 public bool StartHiring()
 {
     if (finding)
     {
         return(true);
     }
     else
     {
         if (Crew.crewsList.Count < GetCrewsSlotsCount())
         {
             if (colony.energyCrystalsCount >= hireCost)
             {
                 colony.GetEnergyCrystals(hireCost);
                 finding = true;
                 return(true);
             }
             else
             {
                 GameLogUI.NotEnoughMoneyAnnounce();
                 return(false);
             }
         }
         else
         {
             GameLogUI.MakeImportantAnnounce(Localization.GetRefusalReason(RefusalReason.NotEnoughSlots));
             if (GameMaster.soundEnabled)
             {
                 GameMaster.audiomaster.Notify(NotificationSound.NotEnoughSlots);
             }
             return(false);
         }
     }
 }
Beispiel #5
0
 public void ReplenishButton()
 {
     if (showingCrew == null)
     {
         replenishButton.SetActive(false);
     }
     else
     {
         if (showingCrew.membersCount == Crew.MAX_MEMBER_COUNT)
         {
             replenishButton.SetActive(false);
         }
         else
         {
             var   colony   = GameMaster.realMaster.colonyController;
             float hireCost = RecruitingCenter.REPLENISH_COST;
             if (colony.energyCrystalsCount >= hireCost)
             {
                 colony.GetEnergyCrystals(hireCost);
                 showingCrew.AddMember();
                 PrepareButtons();
             }
             else
             {
                 GameLogUI.NotEnoughMoneyAnnounce();
             }
         }
     }
 }
 private static GameLogUI GetCurrent()
 {
     if (_currentLog == null)
     {
         _currentLog = Instantiate(Resources.Load <GameObject>("UIPrefs/logCanvas")).GetComponent <GameLogUI>();
     }
     return(_currentLog);
 }
    public void CostPanel_Build()
    {
        switch (costPanelMode)
        {
        case CostPanelMode.SurfaceMaterialChanging:
            ResourceType rt = ResourceType.GetResourceTypeById(costPanel_selectedButton.y);
            if (colony.storage.CheckBuildPossibilityAndCollectIfPossible(new ResourceContainer[] { new ResourceContainer(rt, PlaneExtension.INNER_RESOLUTION * PlaneExtension.INNER_RESOLUTION) }))
            {
                observingSurface.ChangeMaterial(rt.ID, true);
                costPanel.transform.GetChild(0).GetChild(costPanel_selectedButton.x).GetComponent <Image>().overrideSprite = null;
            }
            else
            {
                GameLogUI.NotEnoughResourcesAnnounce();
            }
            break;

        case CostPanelMode.ColumnBuilding:
        {
            if (colony.storage.CheckBuildPossibilityAndCollectIfPossible(ResourcesCost.GetCost(Structure.COLUMN_ID)))
            {
                // float supportPoints = observingSurface.myChunk.CalculateSupportPoints(observingSurface.pos.x, observingSurface.pos.y, observingSurface.pos.z);
                // if (supportPoints <= 1)
                // {
                Structure s = Structure.GetStructureByID(Structure.COLUMN_ID);
                s.SetBasement(observingSurface, new PixelPosByte(7, 7));
                PoolMaster.current.BuildSplash(s.transform.position);
                SetCostPanelMode(CostPanelMode.Disabled);

                Plane p;
                if ((s as IPlanable).TryGetPlane(observingSurface.faceIndex, out p) && !p.isTerminate)
                {
                    UIController.current.Select(p);
                }
                else
                {
                    ReturnButton();
                }
                // }
                //   else
                //  {
                //    observingSurface.myChunk.ReplaceBlock(observingSurface.pos, BlockType.Cave, observingSurface.material_id, ResourceType.CONCRETE_ID, false);
                // }
            }
            else
            {
                GameLogUI.NotEnoughResourcesAnnounce();
            }
        }
        break;

        case CostPanelMode.BlockBuilding:
            BlockBuildingSite bbs = new BlockBuildingSite(observingSurface, ResourceType.GetResourceTypeById(costPanel_selectedButton.y));
            SetCostPanelMode(CostPanelMode.Disabled);
            UIController.current.ShowWorksite(bbs);
            break;
        }
    }
Beispiel #8
0
 public void SubmitButton() // for save option only
 {
     if (terrainsLoading)
     {// ПЕРЕЗАПИСЬ СОХРАНЕНИЯ ТЕРРЕЙНА
         if (deleteSubmit)
         {
             File.Delete(GetTerrainsPath() + '/' + saveNames[lastSelectedIndex] + '.' + TERRAIN_FNAME_EXTENSION);
             Transform t = saveNamesContainer.GetChild(lastSelectedIndex + 1);
             t.GetComponent <Image>().color            = Color.white;
             t.GetChild(0).GetComponent <Text>().color = Color.white;
             lastSelectedIndex = -1;
             RefreshSavesList();
         }
         else
         {
             if (lastSelectedIndex != -1)
             {
                 GameMaster.realMaster.SaveTerrain(saveNames[lastSelectedIndex]);
             }
         }
     }
     else
     {   // ПЕРЕЗАПИСЬ СОХРАНЕНИЯ ИГРЫ
         if (deleteSubmit)
         {
             File.Delete(terrainsLoading ?
                         GetTerrainsPath() + '/' + saveNames[lastSelectedIndex] + '.' + TERRAIN_FNAME_EXTENSION
                 :
                         GetSavesPath() + '/' + saveNames[lastSelectedIndex] + '.' + SAVE_FNAME_EXTENSION);
             Transform t = saveNamesContainer.GetChild(lastSelectedIndex + 1);
             t.GetComponent <Image>().color            = Color.white;
             t.GetChild(0).GetComponent <Text>().color = Color.white;
             lastSelectedIndex = -1;
             RefreshSavesList();
         }
         else
         {
             if (lastSelectedIndex != -1)
             {
                 string s = saveNames[lastSelectedIndex];
                 if (GameMaster.realMaster.SaveGame(s))
                 {
                     GameLogUI.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.GameSaved));
                 }
                 else
                 {
                     GameLogUI.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.SavingFailed));
                     if (GameMaster.soundEnabled)
                     {
                         GameMaster.audiomaster.Notify(NotificationSound.SystemError);
                     }
                 }
             }
         }
     }
     submitWindow.SetActive(false);
 }
Beispiel #9
0
    override public void LevelUp(bool returnToUI)
    {
        if (upgradedIndex == -1)
        {
            return;
        }
        if (!GameMaster.realMaster.weNeedNoResources)
        {
            ResourceContainer[] cost = GetUpgradeCost();
            if (!colony.storage.CheckBuildPossibilityAndCollectIfPossible(cost))
            {
                GameLogUI.NotEnoughResourcesAnnounce();
                return;
            }
        }
        Factory upgraded = GetStructureByID(upgradedIndex) as Factory;

        upgraded.Prepare();
        PixelPosByte setPos = new PixelPosByte(surfaceRect.x, surfaceRect.z);

        if (upgraded.surfaceRect.size == 16)
        {
            setPos = new PixelPosByte(0, 0);
        }
        int workers = workersCount;

        workersCount = 0;
        if (upgraded.rotate90only & (modelRotation % 2 != 0))
        {
            upgraded.modelRotation = (byte)(modelRotation - 1);
        }
        else
        {
            upgraded.modelRotation = modelRotation;
        }
        //
        upgraded.SetRecipe(recipe);
        upgraded.productionMode        = productionMode;
        upgraded.productionModeValue   = productionModeValue;
        upgraded.workPaused            = workPaused;
        upgraded.workflow              = workflow;
        upgraded.inputResourcesBuffer  = inputResourcesBuffer; inputResourcesBuffer = 0;
        upgraded.outputResourcesBuffer = outputResourcesBuffer; outputResourcesBuffer = 0;
        //
        upgraded.SetBasement(basement, setPos);
        upgraded.AddWorkers(workers);
        if (isActive)
        {
            upgraded.SetActivationStatus(true, true);
        }
        if (returnToUI)
        {
            upgraded.ShowOnGUI();
        }
        GameMaster.realMaster.eventTracker?.BuildingUpgraded(this);
    }
Beispiel #10
0
    public void Dismiss() // экспедиция вернулась домой и распускается
    {
        //зависимость : Disappear()
        if (stage == ExpeditionStage.Disappeared | stage == ExpeditionStage.Dismissed)
        {
            return;
        }
        else
        {
            GameLogUI.MakeAnnouncement(Localization.GetCrewAction(LocalizedCrewAction.Returned, crew));
            if (crew != null)
            {
                crew.CountMission(missionCompleted);
                crew.SetCurrentExpedition(null);
                crew = null;
            }
            QuantumTransmitter.StopTransmission(transmissionID);
            Hangar.ReturnShuttle(shuttleID);
            if (destination != null)
            {
                destination.DeassignExpedition(this);
            }
            if (suppliesCount > 0)
            {
                GameMaster.realMaster.colonyController.storage.AddResource(ResourceType.Supplies, suppliesCount);
            }
            if (expeditionsList.Contains(this))
            {
                expeditionsList.Remove(this);
            }
            if (crystalsCollected > 0)
            {
                GameMaster.realMaster.colonyController.AddEnergyCrystals(crystalsCollected);
                crystalsCollected = 0;
            }
            stage = ExpeditionStage.Dismissed;
            if (missionCompleted)
            {
                expeditionsSucceed++;
                Knowledge.GetCurrent()?.ExpeditionsCheck(expeditionsSucceed);
            }

            expeditionsList.Remove(this);

            if (subscribedToUpdate & !GameMaster.sceneClearing)
            {
                GameMaster.realMaster.labourUpdateEvent -= this.LabourUpdate;
                subscribedToUpdate = false;
            }
            changesMarkerValue++;
        }
    }
Beispiel #11
0
    public void StartEndQuest(byte routeIndex)
    {
        int endIndex = (int)QuestType.Endgame;

        if (activeQuests[endIndex] != Quest.NoQuest)
        {
            activeQuests[endIndex]   = new Quest(QuestType.Endgame, routeIndex);
            questAccessMap[endIndex] = true;
        }
        else
        {
            GameLogUI.MakeImportantAnnounce(Localization.GetAnnouncementString(GameAnnouncements.AlreadyHaveEndquest));
        }
    }
 public void LaunchButton()
 {
     if (showingExpedition == null)
     {
         if (selectedCrew != null && selectedCrew.atHome)
         {
             var storage = colony.storage;
             var res     = storage.standartResources;
             if (suppliesSlider.value <= res[ResourceType.SUPPLIES_ID] &&
                 crystalsSlider.value <= colony.energyCrystalsCount &&
                 res[ResourceType.FUEL_ID] >= FUEL_BASE_COST)
             {
                 int shID = Hangar.GetFreeShuttleID();
                 if (shID != Hangar.NO_SHUTTLE_VALUE)
                 {
                     var t = QuantumTransmitter.GetFreeTransmitter();
                     if (t != null)
                     {
                         if (storage.TryGetResources(ResourceType.Fuel, FUEL_BASE_COST))
                         {
                             var e = new Expedition(selectedDestination, selectedCrew, shID, t, storage.GetResources(ResourceType.Supplies, suppliesSlider.value), colony.GetEnergyCrystals(crystalsSlider.value));
                             if (workOnMainCanvas)
                             {
                                 showingExpedition = e;
                             }
                             else
                             {
                                 showingExpedition = null;
                                 selectedCrew      = null;
                                 GameMaster.realMaster.globalMap.observer.GetComponent <GlobalMapUI>().PreparePointDescription();
                                 gameObject.SetActive(false);
                             }
                         }
                         else
                         {
                             GameLogUI.MakeAnnouncement(Localization.GetExpeditionErrorText(ExpeditionComposingErrors.NotEnoughFuel));
                         }
                         RedrawWindow();
                     }
                 }
             }
         }
     }
     else
     {
         showingExpedition.EndMission();
     }
 }
Beispiel #13
0
 override public void LabourUpdate()
 {
     if (!isActive | !isEnergySupplied)
     {
         return;
     }
     if (workersCount > 0)
     {
         if (finding)
         {
             workSpeed = (FIND_SPEED * 0.8f * colony.workspeed + 0.2f * Random.value) * GameMaster.LABOUR_TICK / workflowToProcess;
             workflow += workSpeed;
             if (workflow >= workflowToProcess)
             {
                 int memCount = (int)((workersCount / (float)maxWorkers) * Crew.MAX_MEMBER_COUNT);
                 if (workersCount < memCount)
                 {
                     memCount = workersCount;
                 }
                 if (memCount > 0)
                 {
                     Crew c = Crew.CreateNewCrew(colony, memCount);
                     workersCount -= memCount;
                     workflow      = 0;
                     finding       = false;
                     GameLogUI.MakeAnnouncement(Localization.GetCrewAction(LocalizedCrewAction.Ready, c));
                     hireCost = hireCost * (1 + GameConstants.HIRE_COST_INCREASE);
                     hireCost = ((int)(hireCost * 100)) / 100f;
                     if (showOnGUI)
                     {
                         rcenterObserver.SelectCrew(c);
                     }
                 }
             }
         }
     }
     else
     {
         if (workflow > 0)
         {
             workflow -= backupSpeed * GameMaster.LABOUR_TICK;
             if (workflow < 0)
             {
                 workflow = 0;
             }
         }
     }
 }
Beispiel #14
0
 override protected void LabourResult()
 {
     shuttleID = nextShuttleID++;
     status    = HangarStatus.ShuttleInside;
     if (workersCount > 0)
     {
         FreeWorkers();
     }
     workflow = 0f;
     listChangesMarkerValue++;
     if (showOnGUI)
     {
         hangarObserver.PrepareHangarWindow();
     }
     GameLogUI.MakeAnnouncement(Localization.GetPhrase(LocalizedPhrase.ShuttleConstructed));
 }
Beispiel #15
0
    override public void LevelUp(bool returnToUI)
    {
        if (upgradedIndex == -1)
        {
            return;
        }
        if (!GameMaster.realMaster.weNeedNoResources)
        {
            ResourceContainer[] cost = GetUpgradeCost();
            if (!colony.storage.CheckBuildPossibilityAndCollectIfPossible(cost))
            {
                GameLogUI.NotEnoughResourcesAnnounce();
                return;
            }
        }
        WorkBuilding upgraded = GetStructureByID(upgradedIndex) as WorkBuilding;

        upgraded.Prepare();
        PixelPosByte setPos = new PixelPosByte(surfaceRect.x, surfaceRect.z);

        if (upgraded.surfaceRect.size == 16)
        {
            setPos = new PixelPosByte(0, 0);
        }
        int workers = workersCount;

        workersCount = 0;
        if (upgraded.rotate90only & (modelRotation % 2 != 0))
        {
            upgraded.modelRotation = (byte)(modelRotation - 1);
        }
        else
        {
            upgraded.modelRotation = modelRotation;
        }
        upgraded.AddWorkers(workers);
        upgraded.SetBasement(basement, setPos);
        GameMaster.realMaster.eventTracker?.BuildingUpgraded(this);
        if (returnToUI)
        {
            upgraded.ShowOnGUI();
        }
        //copied to factory.levelup
    }
Beispiel #16
0
    public void MakeQuestCompleted()
    {
        GameLogUI.MakeAnnouncement(Localization.AnnounceQuestCompleted(name));
        uint x = (uint)Mathf.Pow(2, subIndex);

        if ((questsCompletenessMask[(int)type] & x) == 0)
        {
            questsCompletenessMask[(int)type] += x;
        }
        if (type == QuestType.Endgame & subIndex != 2)
        {
            QuestUI.current.SetNewQuest((int)QuestSection.Endgame);
        }
        else
        {
            QuestUI.current.ResetQuestCell(this);
        }
        GameMaster.realMaster.colonyController.AddEnergyCrystals(reward);
    }
Beispiel #17
0
    /// ===============================
    public Expedition(PointOfInterest i_destination, Crew c, int i_shuttleID, QuantumTransmitter transmitter, float i_supplies, float i_crystals)
    {
        // СДЕЛАТЬ: проверка компонентов и вывод ошибок
        ID    = nextID++;
        stage = ExpeditionStage.WayIn;

        destination = i_destination; destination.AssignExpedition(this);
        crew        = c; c.SetCurrentExpedition(this);

        if (Hangar.OccupyShuttle(i_shuttleID))
        {
            shuttleID = i_shuttleID;
        }
        else
        {
            GameLogUI.MakeAnnouncement(Localization.GetExpeditionErrorText(ExpeditionComposingErrors.ShuttleUnavailable));
            Dismiss();
        }

        if (transmitter != null)
        {
            transmissionID = transmitter.StartTransmission();
            hasConnection  = true;
        }
        else
        {
            transmissionID = QuantumTransmitter.NO_TRANSMISSION_VALUE;
            hasConnection  = false;
        }
        suppliesCount     = (byte)i_supplies;
        crystalsCollected = (ushort)i_crystals;

        //#creating map marker
        GlobalMap gmap = GameMaster.realMaster.globalMap;

        mapMarker = new FlyingExpedition(this, gmap.cityPoint, destination, FLY_SPEED);
        gmap.AddPoint(mapMarker, true);
        //

        expeditionsList.Add(this);
        listChangesMarker++;
    }
Beispiel #18
0
    public void ShipLoading(Ship s)
    {
        if (loadingShip == null)
        {
            loadingTimer = LOADING_TIME;
            loadingShip  = s;
            if (announceNewShips)
            {
                GameLogUI.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.ShipArrived));
            }
            return;
        }
        availableVolume = workersCount * WORK_PER_WORKER;
        DockSystem.GetCurrent().HandleShip(this, s, colony);
        loadingShip     = null;
        maintainingShip = false;
        s.Undock();

        shipArrivingTimer = GameConstants.GetShipArrivingTimer();
    }
Beispiel #19
0
    public void SellResource(ResourceType rt, float volume)
    {
        if (availableVolume <= 0f)
        {
            return;
        }
        var colony = GameMaster.realMaster.colonyController;

        if (volume > availableVolume)
        {
            volume = availableVolume;
        }
        float vol   = colony.storage.GetResources(rt, volume);
        float money = vol * ResourceType.prices[rt.ID] * GameMaster.sellPriceCoefficient;

        colony.AddEnergyCrystals(money);
        colony.gears_coefficient -= gearsDamage * vol;
        availableVolume          -= vol;
        GameLogUI.MakeAnnouncement(Localization.GetSellMsg(rt, vol, money));
    }
Beispiel #20
0
    public void Charge()
    {
        ColonyController colony = GameMaster.realMaster.colonyController;

        if (colony.energyCrystalsCount >= 1)
        {
            if (colony.energyStored != colony.totalEnergyCapacity)
            {
                colony.GetEnergyCrystals(1);
                colony.AddEnergy(GameConstants.ENERGY_IN_CRYSTAL);
                if (GameMaster.soundEnabled)
                {
                    GameMaster.audiomaster.Notify(NotificationSound.BatteryCharged);
                }
            }
        }
        else
        {
            GameLogUI.NotEnoughMoneyAnnounce();
        }
    }
Beispiel #21
0
 public void StartConstructing()
 {
     if (observingHangar.status == Hangar.HangarStatus.ConstructingShuttle)
     {
         observingHangar.StopConstruction();
         PrepareHangarWindow();
     }
     else
     {
         ColonyController colony = GameMaster.realMaster.colonyController;
         if (colony.storage.CheckBuildPossibilityAndCollectIfPossible(ResourcesCost.GetCost(ResourcesCost.SHUTTLE_BUILD_COST_ID)))
         {
             observingHangar.StartConstruction();
             PrepareHangarWindow();
         }
         else
         {
             GameLogUI.NotEnoughResourcesAnnounce();
         }
     }
 }
Beispiel #22
0
    /*
     * override public bool IsLevelUpPossible(ref string refusalReason)
     * {
     *  if (workFinished && !awaitingElevatorBuilding)
     *  {
     *      //Block b = basement.myChunk.GetBlock(lastWorkObjectPos.x, lastWorkObjectPos.y - 1, lastWorkObjectPos.z);
     *      //if (b != null && b.type == BlockType.Cube) return true;
     *      else
     *      {
     *          refusalReason = Localization.GetRefusalReason(RefusalReason.NoBlockBelow);
     *          return false;
     *      }
     *  }
     *  else
     *  {
     *      refusalReason = Localization.GetRefusalReason(RefusalReason.WorkNotFinished);
     *      return false;
     *  }
     * }
     */

    override public void LevelUp(bool returnToUI)
    {
        //if (b != null && b.type == BlockType.Cube)
        {
            if (!GameMaster.realMaster.weNeedNoResources)
            {
                ResourceContainer[] cost = GetUpgradeCost();
                if (cost != null && cost.Length != 0)
                {
                    if (!colony.storage.CheckBuildPossibilityAndCollectIfPossible(cost))
                    {
                        GameLogUI.NotEnoughResourcesAnnounce();
                        return;
                    }
                }
            }
            //   workObject = b as CubeBlock;

            UpgradeMine((byte)(level + 1));
            GameMaster.realMaster.eventTracker?.BuildingUpgraded(this);
        }
    }
Beispiel #23
0
 public void AddArtifact(Artifact a, int slotIndex)
 {
     if (a != null && !a.destructed)
     {
         if (!a.researched)
         {
             GameMaster.audiomaster.Notify(NotificationSound.Disagree);
             GameLogUI.MakeImportantAnnounce(Localization.GetPhrase(LocalizedPhrase.ArtifactNotResearched));
             return;
         }
         else
         {
             if (affectionPath != Path.TechPath)
             {
                 GameMaster.audiomaster.Notify(NotificationSound.Disagree);
                 GameLogUI.MakeImportantAnnounce(Localization.GetPhrase(LocalizedPhrase.AffectionTypeNotMatch));
                 return;
             }
             else
             {
                 if (artifacts == null)
                 {
                     artifacts = new Artifact[4];
                 }
                 else
                 {
                     if (artifacts[slotIndex] != null)
                     {
                         artifacts[slotIndex].ChangeStatus(Artifact.ArtifactStatus.OnConservation);
                     }
                 }
                 artifacts[slotIndex] = a;
                 a.ChangeStatus(Artifact.ArtifactStatus.UsingInMonument);
                 RecalculateAffection();
             }
         }
     }
 }
Beispiel #24
0
    public virtual void LevelUp(bool returnToUI)
    {
        if (upgradedIndex == -1)
        {
            return;
        }
        if (!GameMaster.realMaster.weNeedNoResources)
        {
            ResourceContainer[] cost = GetUpgradeCost();
            if (!GameMaster.realMaster.colonyController.storage.CheckBuildPossibilityAndCollectIfPossible(cost))
            {
                GameLogUI.NotEnoughResourcesAnnounce();
                return;
            }
        }
        Building     upgraded = GetStructureByID(upgradedIndex) as Building;
        PixelPosByte setPos   = new PixelPosByte(surfaceRect.x, surfaceRect.z);

        if (upgraded.surfaceRect.size == 16)
        {
            setPos = new PixelPosByte(0, 0);
        }
        if (upgraded.rotate90only & (modelRotation % 2 != 0))
        {
            upgraded.modelRotation = (byte)(modelRotation - 1);
        }
        else
        {
            upgraded.modelRotation = modelRotation;
        }
        upgraded.SetBasement(basement, setPos);
        GameMaster.realMaster.eventTracker?.BuildingUpgraded(this);
        if (returnToUI)
        {
            upgraded.ShowOnGUI();
        }
    }
Beispiel #25
0
    public void Redraw()
    {
        var        carray = knowledge.colorCodesArray;
        var        colors = Knowledge.colors;
        GameObject b;
        Transform  bt;
        byte       code;
        int        i = 0;

        for (; i < 64; i++)
        {
            code = carray[i];
            b    = buttons[i];
            if (code != Knowledge.NOCOLOR_CODE)
            {
                bt = buttons[i].transform;
                bt.GetChild(0).GetComponent <RawImage>().color = colors[code];
                if (!b.activeSelf)
                {
                    b.SetActive(true);
                }
            }
            else
            {
                if (b.activeSelf)
                {
                    b.SetActive(false);
                }
            }
        }

        var parts = knowledge.puzzlePartsCount;

        ascensionPanel.GetChild(1).GetComponent <Text>().text  = ((int)(knowledge.completeness * 100f)).ToString() + '%';
        redpartsPanel.GetChild(1).GetComponent <Text>().text   = parts[Knowledge.REDCOLOR_CODE].ToString();
        greenpartsPanel.GetChild(1).GetComponent <Text>().text = parts[Knowledge.GREENCOLOR_CODE].ToString();
        bluepartsPanel.GetChild(1).GetComponent <Text>().text  = parts[Knowledge.BLUECOLOR_CODE].ToString();
        cyanpartsPanel.GetChild(1).GetComponent <Text>().text  = parts[Knowledge.CYANCOLOR_CODE].ToString();
        var t  = blackpartsPanel;
        var pc = parts[Knowledge.BLACKCOLOR_CODE];

        if (pc > 0)
        {
            t.GetChild(1).GetComponent <Text>().text = pc.ToString();
            if (!t.gameObject.activeSelf)
            {
                t.gameObject.SetActive(true);
            }
        }
        else
        {
            if (t.gameObject.activeSelf)
            {
                t.gameObject.SetActive(false);
            }
        }
        t  = whitepartsPanel;
        pc = parts[Knowledge.WHITECOLOR_CODE];
        if (pc > 0)
        {
            t.GetChild(1).GetComponent <Text>().text = pc.ToString();
            if (!t.gameObject.activeSelf)
            {
                t.gameObject.SetActive(true);
            }
        }
        else
        {
            if (t.gameObject.activeSelf)
            {
                t.gameObject.SetActive(false);
            }
        }

        var  cca = knowledge.colorCodesArray;
        var  ia  = Knowledge.routeButtonsIndexes;
        bool unblocked;
        var  nocode = Knowledge.NOCOLOR_CODE;

        for (i = 0; i < Knowledge.ROUTES_COUNT; i++)
        {
            unblocked = true;
            for (int j = 0; j < Knowledge.STEPS_COUNT; j++)
            {
                if (cca[ia[i, j]] != nocode)
                {
                    unblocked = false;
                    break;
                }
            }
            if (unblocked)
            {
                var           g        = new GameObject();
                RectTransform eqButton = g.AddComponent <RectTransform>();
                eqButton.transform.parent = routeBackgrounds[i].transform;
                eqButton.anchorMax        = Vector2.zero;
                eqButton.anchorMin        = Vector2.zero;
                eqButton.localPosition    = Vector3.zero;
                float s = Screen.height / 10f;
                eqButton.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, s);
                eqButton.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, s);
                var ri = g.AddComponent <RawImage>();
                ri.texture = UIController.current.iconsTexture;
                ri.uvRect  = UIController.GetIconUVRect(Icons.GuidingStar);
                var  btn   = g.AddComponent <Button>();
                byte index = (byte)i;
                btn.onClick.AddListener(() => GameLogUI.EnableDecisionWindow(
                                            Localization.GetPhrase(LocalizedPhrase.Ask_StartFinalQuest),
                                            () => QuestUI.current.StartEndQuest(index), Localization.GetWord(LocalizedWord.Yes),
                                            GameLogUI.DisableDecisionPanel, Localization.GetWord(LocalizedWord.No)
                                            ));
            }
        }

        lastChMarkerValue = knowledge.changesMarker;
    }
Beispiel #26
0
    private void Overloading()
    {
        if (announcementTimer <= 0)
        {
            GameLogUI.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.StorageOverloaded));
            if (GameMaster.soundEnabled)
            {
                GameMaster.audiomaster.Notify(NotificationSound.StorageOverload);
            }
            announcementTimer = 10f;
        }
        else
        {
            // storage dumping
            var      chunk = GameMaster.realMaster.mainChunk;
            ChunkPos cpos;
            bool     secondTry = false;
            if (warehouses.Count > 0)
            {
                cpos = warehouses[Random.Range(0, warehouses.Count)].GetBlockPosition();
            }
            else
            {
                cpos = GameMaster.realMaster.colonyController.hq.GetBlockPosition();
            }
            var sblock = chunk.GetNearestUnoccupiedSurface(cpos);
SECOND_TRY:
            if (sblock != null)
            {
                int   maxIndex = 0, sid = 0;
                float maxValue   = 0;
                var   bmaterials = ResourceType.blockMaterials;
                for (int j = 0; j < bmaterials.Length; j++)
                {
                    sid = bmaterials[j].ID;
                    if (standartResources[sid] > maxValue)
                    {
                        maxValue = standartResources[sid];
                        maxIndex = sid;
                    }
                }
                int dumpingVal = 1000;
                if (dumpingVal > maxValue)
                {
                    dumpingVal = (int)maxValue;
                }

                dumpingVal -= sblock.FORCED_GetExtension().ScatterResources(SurfaceRect.full, ResourceType.GetResourceTypeById(maxIndex), dumpingVal);

                if (dumpingVal != 0)
                {
                    standartResources[maxIndex] -= dumpingVal;
                    totalVolume -= dumpingVal;
                }
                else
                {
                    if (!secondTry)
                    {
                        secondTry = true;
                        sblock    = chunk.GetRandomSurface(Block.UP_FACE_INDEX);
                        goto SECOND_TRY;
                    }
                }
            }
        }
    }
Beispiel #27
0
 private static void InitializeCurrent()
 {
     current = Instantiate(Resources.Load <GameObject>("UIPrefs/logCanvas")).GetComponent <GameLogUI>();
 }
Beispiel #28
0
    public void PrepareList()
    {
        if (observingMonument == null)
        {
            SelfShutOff();
            return;
        }
        else
        {
            if (selectedSlotIndex == -1)
            {
                listHolder.SetActive(false);
                return;
            }
            if (Artifact.artifactsList.Count == 0)
            {
                GameLogUI.MakeImportantAnnounce(Localization.GetPhrase(LocalizedPhrase.NoArtifacts));
                return;
            }
            var arts = new List <Artifact>();
            ids = new List <int>()
            {
                -1
            };
            var  selectedArtifact = observingMonument.artifacts[selectedSlotIndex];
            bool slotWithArtifact = selectedArtifact != null;
            foreach (var a in Artifact.artifactsList)
            {
                if (a.researched)
                {
                    if (a.affectionPath != Path.NoPath
                        &
                        (observingMonument.affectionPath == Path.NoPath | (a.affectionPath == observingMonument.affectionPath))
                        )
                    {
                        if (a.status == Artifact.ArtifactStatus.OnConservation | (slotWithArtifact && selectedArtifact.ID == a.ID))
                        {
                            arts.Add(a);
                            ids.Add(a.ID);
                        }
                    }
                }
            }
            int artsCount = arts.Count;
            if (artsCount > 0)
            {
                // подготовка списка

                int newSelectedItem = -1;

                if (artsCount + 1 > items.Length)
                {
                    // артефакты не помещаются в одну страницу
                    if (!scrollbar.gameObject.activeSelf)
                    {
                        scrollbar.value = 0;
                        scrollbar.gameObject.SetActive(true);
                    }
                    float rsize = items.Length;
                    rsize /= artsCount;
                    if (scrollbar.size != rsize)
                    {
                        scrollbar.size = rsize;
                    }

                    //#preparePositionedList
                    int sindex = GetListStartIndex();
                    int i      = 0;
                    if (sindex == 0)
                    {
                        items[0].transform.GetChild(0).GetComponent <Text>().text = slotWithArtifact ? Localization.GetPhrase(LocalizedPhrase.ClearSlot) : '<' + Localization.GetPhrase(LocalizedPhrase.NoArtifact) + '>';
                        i = 1;
                    }
                    for (; i < items.Length; i++)
                    {
                        items[i].transform.GetChild(0).GetComponent <Text>().text = '"' + arts[i + sindex - 1].name + '"';
                        items[i].SetActive(true);
                    }


                    if (selectedArtifact != null)
                    {
                        for (int j = 0; j < items.Length; j++)
                        {
                            if (ids[j + sindex] == selectedArtifact.ID)
                            {
                                newSelectedItem = j;
                                break;
                            }
                        }
                    }
                    else
                    {
                        if (sindex != 0)
                        {
                            newSelectedItem = -1;
                        }
                        else
                        {
                            newSelectedItem = 0;
                        }
                    }
                    //
                }
                else
                {
                    // артефактов меньше, чем позиций списка
                    items[0].transform.GetChild(0).GetComponent <Text>().text = slotWithArtifact ? Localization.GetPhrase(LocalizedPhrase.ClearSlot) : '<' + Localization.GetPhrase(LocalizedPhrase.NoArtifact) + '>';
                    if (scrollbar.gameObject.activeSelf)
                    {
                        scrollbar.gameObject.SetActive(false);
                    }
                    int i = 0;
                    for (; i < arts.Count; i++)
                    {
                        items[i + 1].transform.GetChild(0).GetComponent <Text>().text = '"' + arts[i].name + '"';
                        items[i + 1].SetActive(true);
                    }
                    i++;
                    if (i < items.Length)
                    {
                        for (; i < items.Length; i++)
                        {
                            items[i].SetActive(false);
                        }
                    }

                    if (selectedArtifact != null)
                    {
                        for (int j = 1; j < items.Length; j++)
                        {
                            if (ids[j] == selectedArtifact.ID)
                            {
                                newSelectedItem = j;
                                break;
                            }
                        }
                    }
                    else
                    {
                        newSelectedItem = 0;
                    }
                }

                if (newSelectedItem != listSelectedItem)
                {
                    if (listSelectedItem != -1)
                    {
                        items[listSelectedItem].GetComponent <Image>().overrideSprite = null;
                    }
                    if (newSelectedItem != -1)
                    {
                        items[newSelectedItem].GetComponent <Image>().overrideSprite = PoolMaster.gui_overridingSprite;
                    }
                    listSelectedItem = newSelectedItem;
                }
                if (!listHolder.activeSelf)
                {
                    listHolder.SetActive(true);
                }
            }
            else
            {
                if (listHolder.activeSelf)
                {
                    if (ids != null)
                    {
                        ids.Clear();
                    }
                    listHolder.SetActive(false);
                }
                GameLogUI.MakeImportantAnnounce(Localization.GetPhrase(LocalizedPhrase.NoSuitableArtifacts));
                return;
            }
        }
    }
Beispiel #29
0
    public bool LoadGame(string fullname)
    {
        bool       debug_noresource = weNeedNoResources;
        FileStream fs          = File.Open(fullname, FileMode.Open);
        double     realHashSum = GetHashSum(fs, true);
        var        data        = new byte[8];

        fs.Read(data, 0, 8);
        double readedHashSum = System.BitConverter.ToDouble(data, 0);
        string errorReason   = "reason not stated";

        if (realHashSum == readedHashSum)
        {
            fs.Position = 0;
            SetPause(true);
            loading = true;
            // ОЧИСТКА
            StopAllCoroutines();
            if (Zeppelin.current != null)
            {
                Destroy(Zeppelin.current);
            }
            if (mainChunk != null)
            {
                mainChunk.ClearChunk();
            }
            // очистка подписчиков на ивенты невозможна, сами ивенты к этому моменту недоступны
            Crew.Reset();
            Expedition.GameReset();
            Structure.ResetToDefaults_Static(); // все наследуемые resetToDefaults внутри
            if (colonyController != null)
            {
                colonyController.ResetToDefaults();                           // подчищает все списки
            }
            else
            {
                colonyController = gameObject.AddComponent <ColonyController>();
                colonyController.Prepare();
            }
            //UI.current.Reset();


            // НАЧАЛО ЗАГРУЗКИ
            if (gameStarted)
            {
                SetDefaultValues();
            }
            #region gms mainPartLoading
            data = new byte[4];
            fs.Read(data, 0, 4);
            uint saveSystemVersion = System.BitConverter.ToUInt32(data, 0); // может пригодиться в дальнейшем
            //start writing
            data = new byte[65];
            fs.Read(data, 0, data.Length);
            gameSpeed                      = System.BitConverter.ToSingle(data, 0);
            lifeGrowCoefficient            = System.BitConverter.ToSingle(data, 4);
            demolitionLossesPercent        = System.BitConverter.ToSingle(data, 8);
            lifepowerLossesPercent         = System.BitConverter.ToSingle(data, 12);
            LUCK_COEFFICIENT               = System.BitConverter.ToSingle(data, 16);
            sellPriceCoefficient           = System.BitConverter.ToSingle(data, 20);
            tradeVesselsTrafficCoefficient = System.BitConverter.ToSingle(data, 24);
            upgradeDiscount                = System.BitConverter.ToSingle(data, 28);
            upgradeCostIncrease            = System.BitConverter.ToSingle(data, 32);
            warProximity                   = System.BitConverter.ToSingle(data, 36);

            difficulty    = (Difficulty)data[40];
            startGameWith = (GameStart)data[41];
            prevCutHeight = data[42];
            day           = data[43];
            month         = data[44];

            year              = System.BitConverter.ToUInt32(data, 45);
            timeGone          = System.BitConverter.ToSingle(data, 49);
            gearsDegradeSpeed = System.BitConverter.ToSingle(data, 53);
            labourTimer       = System.BitConverter.ToSingle(data, 57);
            RecruitingCenter.SetHireCost(System.BitConverter.ToSingle(data, 61));
            #endregion

            DockSystem.LoadDockSystem(fs);
            globalMap.Load(fs);
            if (loadingFailed)
            {
                errorReason = "global map error";
                goto FAIL;
            }

            environmentMaster.Load(fs);
            if (loadingFailed)
            {
                errorReason = "environment error";
                goto FAIL;
            }

            Artifact.LoadStaticData(fs); // crews & monuments
            if (loadingFailed)
            {
                errorReason = "artifacts load failure";
                goto FAIL;
            }

            Crew.LoadStaticData(fs);
            if (loadingFailed)
            {
                errorReason = "crews load failure";
                goto FAIL;
            }

            if (mainChunk == null)
            {
                GameObject g = new GameObject("chunk");
                mainChunk = g.AddComponent <Chunk>();
            }
            mainChunk.LoadChunkData(fs);
            if (loadingFailed)
            {
                errorReason = "chunk load failure";
                goto FAIL;
            }
            else
            {
                if (blockersRestoreEvent != null)
                {
                    blockersRestoreEvent();
                }
            }


            Settlement.TotalRecalculation(); // Totaru Annihirationu no imoto-chan
            if (loadingFailed)
            {
                errorReason = "settlements load failure";
                goto FAIL;
            }

            colonyController.Load(fs); // < --- COLONY CONTROLLER
            if (loadingFailed)
            {
                errorReason = "colony controller load failure";
                goto FAIL;
            }

            if (loadingFailed)
            {
                errorReason = "dock load failure";
                goto FAIL;
            }
            QuestUI.current.Load(fs);
            if (loadingFailed)
            {
                errorReason = "quest load failure";
                goto FAIL;
            }
            Expedition.LoadStaticData(fs);
            Knowledge.Load(fs);
            fs.Close();

            FollowingCamera.main.WeNeedUpdate();
            loading  = false;
            savename = fullname;

            if (afterloadRecalculationEvent != null)
            {
                afterloadRecalculationEvent();
                afterloadRecalculationEvent = null;
            }
            SetPause(false);
            colonyController.FORCED_PowerGridRecalculation();

            return(true);
        }
        else
        {
            GameLogUI.MakeImportantAnnounce(Localization.GetAnnouncementString(GameAnnouncements.LoadingFailed) + " : hashsum incorrect");
            if (soundEnabled)
            {
                audiomaster.Notify(NotificationSound.SystemError);
            }
            SetPause(true);
            fs.Close();
            return(false);
        }
FAIL:
        GameLogUI.MakeImportantAnnounce(Localization.GetAnnouncementString(GameAnnouncements.LoadingFailed) + " : data corruption");
        if (soundEnabled)
        {
            audiomaster.Notify(NotificationSound.SystemError);
        }
        print(errorReason);
        SetPause(true);
        fs.Close();
        if (debug_noresource)
        {
            weNeedNoResources = true;
        }
        return(false);
    }
Beispiel #30
0
    void Start()
    {
        if (gameStarted)
        {
            return;
        }

        if (gameMode != GameMode.Editor)
        {
            difficulty = gameStartSettings.difficulty;
            SetDefaultValues();
            //byte chunksize = gss.chunkSize;
            byte chunksize;
            chunksize = gameStartSettings.chunkSize;
            if (testMode && savenameToLoad != string.Empty)
            {
                gameStartSettings = new GameStartSettings(ChunkGenerationMode.GameLoading);
                savename          = savenameToLoad;
            }
            if (gameStartSettings.generationMode != ChunkGenerationMode.GameLoading)
            {
                if (gameStartSettings.generationMode != ChunkGenerationMode.DontGenerate)
                {
                    if (gameStartSettings.generationMode != ChunkGenerationMode.TerrainLoading)
                    {
                        Constructor.ConstructChunk(chunksize, gameStartSettings.generationMode);
                        // Constructor.ConstructBlock(chunksize);
                        if (gameStartSettings.generationMode == ChunkGenerationMode.Peak)
                        {
                            environmentMaster.PrepareIslandBasis(ChunkGenerationMode.Peak);
                        }
                    }
                    else
                    {
                        LoadTerrain(SaveSystemUI.GetTerrainsPath() + '/' + savename + '.' + SaveSystemUI.TERRAIN_FNAME_EXTENSION);
                    }
                }
                FollowingCamera.main.ResetTouchRightBorder();
                FollowingCamera.main.CameraRotationBlock(false);
                warProximity   = 0.01f;
                layerCutHeight = Chunk.chunkSize; prevCutHeight = layerCutHeight;
                switch (startGameWith)
                {
                case GameStart.Zeppelin:
                    Instantiate(Resources.Load <GameObject>("Prefs/Zeppelin"));
                    if (needTutorial)
                    {
                        GameLogUI.EnableDecisionWindow(null, Localization.GetTutorialHint(LocalizedTutorialHint.Landing));
                    }
                    else
                    {
                        GameLogUI.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.SetLandingPoint));
                    }
                    break;

                case GameStart.Headquarters:
                    var   sblocks = mainChunk.surfaces;
                    Plane sb      = sblocks[Random.Range(0, sblocks.Length)];
                    int   xpos    = sb.pos.x;
                    int   zpos    = sb.pos.z;

                    Structure s;
                    if (testMode)
                    {
                        s = HeadQuarters.GetHQ(6);
                        weNeedNoResources = true;
                    }
                    else
                    {
                        weNeedNoResources = false;
                        s = HeadQuarters.GetHQ(1);
                    }

                    Plane b = mainChunk.GetHighestSurfacePlane(xpos, zpos);
                    s.SetBasement(b, PixelPosByte.zero);


                    sb = mainChunk.GetHighestSurfacePlane(xpos - 1, zpos + 1);
                    if (sb == null)
                    {
                        sb = mainChunk.GetHighestSurfacePlane(xpos, zpos + 1);
                        if (sb == null)
                        {
                            sb = mainChunk.GetHighestSurfacePlane(xpos + 1, zpos + 1);
                            if (sb == null)
                            {
                                sb = mainChunk.GetHighestSurfacePlane(xpos - 1, zpos);
                                if (sb == null)
                                {
                                    sb = mainChunk.GetHighestSurfacePlane(xpos + 1, zpos);
                                    if (sb == null)
                                    {
                                        sb = mainChunk.GetHighestSurfacePlane(xpos - 1, zpos - 1);
                                        if (sb == null)
                                        {
                                            sb = mainChunk.GetHighestSurfacePlane(xpos, zpos - 1);
                                            if (sb == null)
                                            {
                                                sb = mainChunk.GetHighestSurfacePlane(xpos + 1, zpos - 1);
                                                if (sb == null)
                                                {
                                                    print("bad generation, do something!");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    StorageHouse firstStorage = Structure.GetStructureByID(Structure.STORAGE_0_ID) as StorageHouse;
                    firstStorage.SetBasement(sb, PixelPosByte.zero);
                    SetStartResources();
                    break;
                }
                FollowingCamera.main.WeNeedUpdate();
            }
            else
            {
                LoadGame(SaveSystemUI.GetSavesPath() + '/' + savename + ".sav");
            }
        }
        else
        {
            gameObject.AddComponent <PoolMaster>().Load();
            mainChunk = new GameObject("chunk").AddComponent <Chunk>();
            int size = Chunk.chunkSize;
            int[,,] blocksArray = new int[size, size, size];
            size /= 2;
            blocksArray[size, size, size] = ResourceType.STONE_ID;
            mainChunk.CreateNewChunk(blocksArray);
        }

        { // set look point
            FollowingCamera.camBasisTransform.position = sceneCenter;
        }
        gameStarted = true;
    }