Beispiel #1
0
        private static string StringifyState(ResearchState state)
        {
            switch (state)
            {
            case ResearchState.NotStarted:
                return("not started");

            case ResearchState.InProgress:
                return("in progress");

            case ResearchState.Completed:
                return("completed");

            case ResearchState.Failed:
                return("failed");

            case ResearchState.InProgressOrCompleted:
                return("in progress or completed");

            case ResearchState.FailedOrNotStarted:
                return("failed or not started");

            case ResearchState.NotFailed:
                return("not failed");

            default:
                return($"state unknown {state}");
            }
        }
Beispiel #2
0
    void Initializing()
    {
        TechTreeList      = new List <TechState>();
        FacilityList      = new List <TechRecipe.FacilityInfo>();
        ActorList         = new List <TechRecipe.ProcessActorInfo>();
        ResearchStateList = new List <ResearchState>();

        TechState newState;

        foreach (var Info in TechRecipeCall.TechInfoList)
        {
            newState           = new TechState();
            newState.Info      = Info;
            newState.Completed = false;
            newState.Possible  = false;

            TechTreeList.Add(newState);
        }

        ResearchState FirstResearch = new ResearchState();

        FirstResearch.LabatoryList = new List <GameObject>();
        FirstResearch.TargetState  = TechTreeList[0];
        ResearchStateList.Add(FirstResearch);
        CompleteResearch(FirstResearch);

        CheckTechPossible();
    }
Beispiel #3
0
 void ResearchPanelUpdate(ResearchState TargetResearch)
 {
     if (CompanyValueCall.CompanyName == CompanyManagerCall.PlayerCompanyName)
     {
         if (PanelControllerCall.CurrentSidePanel != null)
         {
             if (PanelControllerCall.CurrentSidePanel.name == "LabatoryResearchPanel")
             {
                 bool       Exist             = false;
                 GameObject PanelTargetObject = PanelControllerCall.CurrentSidePanel.GetComponent <LabatoryResearchPanelController>().TargetObject;
                 foreach (var Labatory in TargetResearch.LabatoryList)
                 {
                     if (Labatory == PanelTargetObject)
                     {
                         Exist = true;
                         break;
                     }
                 }
                 if (Exist)
                 {
                     PanelControllerCall.CurrentSidePanel.GetComponent <LabatoryResearchPanelController>().UpdateProgressInfo();
                 }
             }
         }
     }
 }
Beispiel #4
0
    public void StartResearch(string Name, GameObject TargetLabatory)
    {
        ResearchState TargetResearch = GetResearchState(Name);

        if (TargetResearch == null)
        {
            TargetResearch = new ResearchState();
            foreach (var TechState in TechTreeList)
            {
                if (TechState.Info.Name == Name)
                {
                    TargetResearch.TargetState = TechState;
                }
            }

            TargetResearch.GainedWorkLoad = 0;
            TargetResearch.LabatoryList   = new List <GameObject>();

            TargetResearch.StartTime = TimeManangerCall.TimeValue;
        }

        TargetResearch.LabatoryList.Add(TargetLabatory);

        SetResearchState(TargetResearch);
    }
 private void OnPlayerResearchStateChanged(PlayerResearchState research, ResearchState old, ResearchState @new)
 {
     UpdateStatefulStorage(research);
     foreach (var rd in Manager.Definitions.ResearchDepending(research.Definition.Id))
     {
         DependencyChangedState(research.Player, rd);
     }
 }
 internal void RaisePlayerResearchStateChanged(PlayerResearchState research, ResearchState old,
                                               ResearchState @new)
 {
     Logger.Debug(
         $"event {nameof(RaisePlayerResearchStateChanged)}({research.Player.Player.DisplayName}/{research.Definition.Id}, {old}, {@new})");
     Core.Logger.Flush();
     PlayerResearchStateChanged?.Invoke(research, old, @new);
 }
Beispiel #7
0
    public bool CompleteResearch(ResearchState TargetResearch)
    {
        TargetResearch.TargetState.Completed = true;

        CheckTechPossible();

        foreach (var FacilityName in TargetResearch.TargetState.Info.UnlockFacility)
        {
            if (FacilityName == "None")
            {
                break;
            }
            TechRecipe.FacilityInfo TargetFacility = TechRecipeCall.GetFacilityInfo(FacilityName);
            FacilityList.Add(TargetFacility);
        }

        foreach (var ActorName in TargetResearch.TargetState.Info.UnlockActor)
        {
            if (ActorName == "None")
            {
                break;
            }
            TechRecipe.ProcessActorInfo TargetActor = TechRecipeCall.GetProcessActorInfo(ActorName);
            ActorList.Add(TargetActor);
        }

        switch (TargetResearch.TargetState.Info.UpgradeValueType)
        {
        case "Work":
            CompanyValueCall.GetEmployeeValue().GetComponent <EmployeeValue>().WorkEifficiency = TargetResearch.TargetState.Info.UpgradeValueAmount;
            break;

        case "Energy":
            CompanyValueCall.GetElectricityValue().GetComponent <ElectricityValue>().EnergyEfficiency = TargetResearch.TargetState.Info.UpgradeValueAmount;
            break;

        case "Organize":
            CompanyValueCall.GetGoodsValue().GetComponent <GoodsValue>().OrganizeEfficiency = TargetResearch.TargetState.Info.UpgradeValueAmount;
            break;
        }

        ResearchPanelUpdate(TargetResearch);

        int limit = TargetResearch.LabatoryList.Count;

        for (int i = 0; i < limit; i++)
        {
            LabatoryAct TargetLabatoryAct = TargetResearch.LabatoryList[0].GetComponent <LabatoryAct>();

            TargetLabatoryAct.StopResearch();
        }

        ResearchStateList.Remove(TargetResearch);
        TargetResearch = null;

        return(true);
    }
Beispiel #8
0
        private void ResearchStateChanged(PlayerResearchState research, ResearchState old, ResearchState @new)
        {
            if (research.Player.Player != MyAPIGateway.Session.Player)
            {
                return;
            }
            string msg;

            switch (@new)
            {
            case ResearchState.NotStarted:
                msg = old == ResearchState.InProgress ? "aborted" : null;
                break;

            case ResearchState.InProgress:
                msg = "started";
                break;

            case ResearchState.Completed:
                msg = "completed";
                if (!HideMessages && research.Definition.ShowCompletionWindow)
                {
                    _futureDisplay.Enqueue(new FutureDisplay {
                        State = research, ShowDialog = ShowResearchComplete
                    });
                }
                break;

            case ResearchState.Failed:
                msg = "failed";
                break;

            default:
                throw new Exception($"State out of range {@new}");
            }

            if (msg == null || HideMessages)
            {
                return;
            }
            var resMsg = @new == ResearchState.Completed && !string.IsNullOrEmpty(research.Definition.CompletionMessage)
                ? research.Definition.CompletionMessage
                : $"You've {msg} {research.Definition.DisplayName}";

            if (research.Definition.UpdatesAsNotifications)
            {
                MyAPIGateway.Utilities.ShowNotification(resMsg);
            }
            else
            {
                MyAPIGateway.Utilities.ShowMessage("Research", resMsg);
            }
        }
Beispiel #9
0
    public bool RemoveResearchLabatory(string Name, GameObject TargetLabatory)
    {
        ResearchState TargetResearch = GetResearchState(Name);

        TargetResearch.LabatoryList.Remove(TargetLabatory);

        if (TargetResearch.LabatoryList.Count <= 0)
        {
            ResearchStateList.Remove(TargetResearch);
            return(true);
        }
        else
        {
            return(false);
        }
    }
Beispiel #10
0
        private void OnPlayerResearchStateChanged(PlayerResearchState research, ResearchState old, ResearchState @new)
        {
            var player = research.Player;

            if (player.Player.SteamUserId == MyAPIGateway.Multiplayer.MyId ||
                player.Player == MyAPIGateway.Session.Player)
            {
                return;
            }
            Manager.SendMessage(player.Player.SteamUserId, new ReplicationResearchMessage
            {
                ResearchId       = research.Definition.Id,
                StorageId        = null,
                State            = @new,
                StorageOperation = ReplicationResearchMessage.StorageOp.None
            });
        }
Beispiel #11
0
    public void ContributeResearchWork(string Name, float Amount)
    {
        ResearchState TargetResearch = GetResearchState(Name);

        if (TargetResearch == null)
        {
            Debug.Log("Cannot Find " + Name + " on ResearchStateList");
            return;
        }

        TargetResearch.GainedWorkLoad += Amount;

        if (TargetResearch.GainedWorkLoad >= TargetResearch.TargetState.Info.RequiredWorkLoad)
        {
            CompleteResearch(TargetResearch);
        }

        ResearchPanelUpdate(TargetResearch);
    }
Beispiel #12
0
    // ------
    protected void RecomputeState()
    {
        m_StateDirty         = false;
        m_CantBuyExplanation = "";
        m_RequiredRank       = 0;

        if (weaponID != E_WeaponID.None)
        {
            if (ResearchSupport.Instance.GetPPI().InventoryList.ContainsWeapon(weaponID))
            {
                m_State = ResearchState.Active;
                return;
            }
            m_RequiredRank = WeaponSettingsManager.Instance.Get(weaponID).MinRank;
        }
        else if (itemID != E_ItemID.None)
        {
            foreach (PPIItemData data in ResearchSupport.Instance.GetPPI().InventoryList.Items)
            {
                //Debug.Log(data.ID);
                if (data.ID == itemID)
                {
                    m_State = ResearchState.Active;
                    return;
                }
            }
            m_RequiredRank = ItemSettingsManager.Instance.Get(itemID).MinRank;
        }
        else if (upgradeID != E_UpgradeID.None)
        {
            foreach (PPIUpgradeList.UpgradeData data in ResearchSupport.Instance.GetPPI().Upgrades.Upgrades)
            {
                if (data.ID == upgradeID)
                {
                    m_State = ResearchState.Active;
                    return;
                }
            }
            m_RequiredRank = UpgradeSettingsManager.Instance.Get(upgradeID).MinRank;
        }
        else if (perkID != E_PerkID.None)
        {
            foreach (PPIPerkData data in ResearchSupport.Instance.GetPPI().InventoryList.Perks)
            {
                if (data.ID == perkID)
                {
                    m_State = ResearchState.Active;
                    return;
                }
            }
            m_RequiredRank = PerkSettingsManager.Instance.Get(perkID).MinRank;
        }
        else
        {
            Error("Data are not properly set!");
        }

        bool isGold;
        int  cost = GetPrice(out isGold);

        if (ResearchSupport.Instance.GetPPI().Rank < m_RequiredRank)
        {
            m_CantBuyExplanation = TextDatabase.instance[0113100];
            m_State = ResearchState.Unavailable;
            return;
        }
        else
        {
            m_RequiredRank = 0;
            if (m_Parent)
            {
                if (m_Parent.GetState() == ResearchState.Active)
                {
                    if (ResearchSupport.Instance.HasPlayerEnoughFunds(cost, isGold))
                    {
                        m_State = ResearchState.Available;
                    }
                    else
                    {
                        m_State = ResearchState.Unavailable;
                    }
                    return;
                }
                else
                {
                    m_CantBuyExplanation = TextDatabase.instance[0113090];
                    m_State = ResearchState.Unavailable;
                    return;
                }
            }
        }

        if (ResearchSupport.Instance.HasPlayerEnoughFunds(cost, isGold))
        {
            m_State = ResearchState.Available;
        }
        else
        {
            m_State = ResearchState.Unavailable;
        }
    }
Beispiel #13
0
    List <ItemDesc> CollectItems(PlayerPersistantInfo ppi, RoundFinalResult results)
    {
        int money  = ppi.Money;
        int gold   = ppi.Gold;
        var result = new List <ItemDesc>();
        var items  = ResearchSupport.Instance.GetItems();

        int currentRank = ppi.Rank;
        int minimalRank = currentRank - Mathf.RoundToInt(PlayerPersistantInfo.MAX_RANK * 0.4f);

        foreach (var item in items)
        {
            int desiredRank = item.GetRequiredRank();
            if (desiredRank > currentRank)
            {
                continue;
            }
            if (desiredRank < minimalRank)
            {
                continue;
            }
            if (CanOffer(item) == false)
            {
                continue;
            }

            ResearchState state = item.GetState();
            if (state == ResearchState.Unavailable)
            {
                continue;
            }

            bool isGold;
            int  price  = item.GetPrice(out isGold);
            bool canBuy = isGold ? price <= gold : price <= money;
            if (state == ResearchState.Available && canBuy == false)
            {
                continue;
            }

            //List<WeaponSettings.Upgrade> upgrades = CollectUpgrades(item, money);
            if (state == ResearchState.Active /*&& upgrades.Count == 0*/)
            {
                continue;
            }

            ItemSettings itemSettings = GetItem(item);
            if (itemSettings != null && itemSettings.Consumable == true)
            {
                continue;
            }

            result.Add(new ItemDesc()
            {
                Id    = GetId(item),
                Item  = item,
                Rank  = desiredRank,
                Owned = state == ResearchState.Active ? true : false,
                Used  = GetUsedTimes(item, ppi, results),
                Price = price,
                //Upgrades = upgrades
            });
        }

        return(result);
    }
 private void OnPlayerResearchStateChanged(PlayerResearchState research, ResearchState old, ResearchState @new)
 {
     Logger.Debug($"{research.Player.Player.DisplayName} / {research.Definition.Id} {old} -> {@new}");
 }
Beispiel #15
0
 public void SetResearchState(ResearchState targetResearch)
 {
     ResearchStateList.Add(targetResearch);
 }
Beispiel #16
0
    // ------
    public void SetState(ResearchState state, bool fullyUpgraded, int requiredRank)
    {
        m_Base.Show(true, true);

        switch (state)
        {
        // ----
        case ResearchState.Active:
            m_LockedByRank.Deactivate();
            m_ItemName.Widget.SetColor(ActiveNameColor);
            m_Price.Widget.Show(false, true);
            m_Researched.Widget.Show(true, true);
            m_Researched.Widget.Color = fullyUpgraded ? FullyResearchedIconColor : ResearchedIconColor;
            m_Finished.Widget.Color   = fullyUpgraded ? FullyResearchedIconColor : ResearchedIconColor;
            m_Enabled.Widget.Show(false, true);
            m_Disabled.Widget.Show(false, true);
            if (fullyUpgraded && m_FullyUpgraded)
            {
                m_Finished.Widget.Show(false, true);
                m_FullyUpgraded.Widget.Show(true, true);
            }
            else
            {
                m_Finished.Widget.Show(true, true);
                if (m_FullyUpgraded)
                {
                    m_FullyUpgraded.Widget.Show(false, true);
                }
            }
            break;

        // ----
        case ResearchState.Available:
            m_LockedByRank.Deactivate();
            m_Price.Widget.SetColor(m_PriceAvailable ? AvailablePriceColor : UnavailablePriceColor);
            m_ItemName.Widget.SetColor(AvailableNameColor);
            m_Price.Widget.Show(true, true);
            m_Finished.Widget.Show(false, true);
            m_Researched.Widget.Show(false, true);
            m_Enabled.Widget.Show(true, true);
            m_Disabled.Widget.Show(false, true);
            if (m_FullyUpgraded)
            {
                m_FullyUpgraded.Widget.Show(false, true);
            }
            break;

        // ----
        case ResearchState.Unavailable:
            if (requiredRank > 0)
            {
                m_LockedByRank.Activate(requiredRank);
            }
            else
            {
                m_LockedByRank.Deactivate();
            }
            m_Price.Widget.SetColor(m_PriceAvailable ? AvailablePriceColor : UnavailablePriceColor);
            m_ItemName.Widget.SetColor(AvailableNameColor);
            m_Price.Widget.Show(true, true);
            m_Finished.Widget.Show(false, true);
            m_Researched.Widget.Show(false, true);
            m_Enabled.Widget.Show(false, true);
            m_Disabled.Widget.Show(true, true);
            if (m_FullyUpgraded)
            {
                m_FullyUpgraded.Widget.Show(false, true);
            }
            break;

        // ----
        default:
            Debug.LogWarning("Unknown enum!");
            break;
        }

        if (m_UpgradeParent)
        {
            m_UpgradeParent.Show(m_UpgradesAvailable, true);
            int i = 0;
            foreach (UpgradeIcon upgIcon in m_UpgradeIcons)
            {
                if (upgIcon.IsVisible())
                {
                    if (upgIcon.GetStatus() == UpgradeIcon.Status.Inactive)
                    {
                        m_Stars[i].Color = UpgradeStarInactiveColor;
                    }
                    else
                    {
                        m_Stars[i].Color = UpgradeStarActiveColor;
                    }
                    m_Stars[i].Show(state == ResearchState.Active, true);
                    ++i;
                }
            }

            for (int j = i; j < ResearchItem.MAX_UPGRADES; j++)
            {
                m_Stars[j].Show(false, true);
            }
        }
    }
Beispiel #17
0
 //**********************************************************
 //* Обновление состояния исследования
 //**********************************************************
 public static void UpdateResearchState(Int32 researchId, ResearchState researchState)
 {
     using (SandBoxDataContext db = new SandBoxDataContext())
     {
         Research research = db.Researches.FirstOrDefault(x => x.Id == researchId);
         if (research == null) return;
         research.State = (Int32)researchState;
         db.SubmitChanges();
     }
 }
        private void FlattenResearch(Ob_Trigger trigger, ISet <ResearchBranch> branches,
                                     ResearchBranch currentBranch)
        {
            if (trigger is Ob_Trigger_Composite)
            {
                trigger = ((Ob_Trigger_Composite)trigger).Simplify();
            }
            if (trigger == null)
            {
                return;
            }
            trigger.UpdateKey();
            var all      = trigger as Ob_Trigger_All;
            var any      = trigger as Ob_Trigger_Any;
            var research = trigger as Ob_Trigger_ResearchState;
            var unlock   = trigger as Ob_Trigger_Unlocked;

            if (all != null)
            {
                foreach (var e in all.Elements.Distinct())
                {
                    FlattenResearch(e, branches, currentBranch);
                }
                return;
            }
            if (any != null)
            {
                foreach (var e in any.Elements.Distinct())
                {
                    FlattenResearch(e, branches, currentBranch.Fork());
                }
                return;
            }
            branches.Add(currentBranch);
            if (research != null)
            {
                ResearchState currentVal =
                    currentBranch.ResearchStates.GetValueOrDefault(research.Id, research.RequiredState);
                Utilities.Assert(currentVal == research.RequiredState,
                                 $"Research state mismatch: {currentVal} and {research.RequiredState}");
                currentBranch.ResearchStates[research.Id] = research.RequiredState;
                return;
            }
            if (unlock != null)
            {
                currentBranch.Unlocked.Add(unlock.DefinitionId);
                return;
            }
            var hasItem = trigger as Ob_Trigger_HasItem;

            if (hasItem != null && !Utilities.ValidateDefinition <MyPhysicalItemDefinition>(hasItem.DefinitionId))
            {
                return;
            }
            var interact = trigger as Ob_Trigger_Interact;

            if (interact != null)
            {
                var valid = true;
                foreach (var k in interact.HandItem)
                {
                    valid &= Utilities.ValidateDefinition <MyPhysicalItemDefinition>(k);
                }
                foreach (var k in interact.BlockInteractTarget)
                {
                    valid &= Utilities.ValidateDefinition <MyCubeBlockDefinition>(k);
                }
                if (!valid)
                {
                    return;
                }
            }
            var key = trigger.StateStorageKey;

            Utilities.Assert(key != null, $"Trigger type {trigger.GetType().FullName} must have a state storage key");
            Ob_Trigger existingTrigger;

            if (!_stateStorageProviders.TryGetValue(key, out existingTrigger))
            {
                _stateStorageProviders[key] = existingTrigger = trigger;
            }
            currentBranch.Triggers[key] = existingTrigger;
        }