コード例 #1
0
 private void OnOperationFinished(RunningOperation op)
 {
     if (op == operation)
     {
         Destroy(gameObject);
     }
 }
コード例 #2
0
    private void OnOperationAdded(RunningOperation op)
    {
        GameObject opButton = Instantiate(operationButtonPrefab, Vector3.zero, Quaternion.identity);

        opButton.transform.SetParent(container, false);

        opButton.GetComponent <OperationButtonBehaviour>().Setup(op);
    }
コード例 #3
0
        private void OnControlPlanCancel(object sender, ExecutorCommandEventArgs e)
        {
            if (RunningOperation == null || !RunningOperation.IsRunning)
            {
                Handler.Send(Commands.ReportError(0, "Can't cancel. Operation is not running"));
                return;
            }

            RunningOperation.Cancel();
        }
コード例 #4
0
    public void Setup(RunningOperation op)
    {
        operation = op;

        textName.text  = operation.Name;
        textDepth.text = $"{operation.Depth} meters";

        button.onClick.AddListener(() => GameManager.Singleton.LaunchMole(operation));

        GameManager.Singleton.OnOperationFinished += OnOperationFinished;
        GameManager.Singleton.OnOperationRemoved  += OnOperationFinished;
    }
コード例 #5
0
    public void Display(RunningOperation op)
    {
        operation = op;

        Refresh();
    }
コード例 #6
0
 private void OnOperationHovered(RunningOperation op)
 {
     Display(op);
 }
        public bool TryStartOperation(UpdateCascadeOperation operation, JsonDocument referencedDoc)
        {
            var services = Services.GetServices(this.db);

            if (services.IsShutDownInProgress)
            {
                log.Warn("Tried to start operation {0} while shuting down", operation.Id);
                return false;
            }

            RunningOperation ro = null;
            UpdateCascadeSetting setting;
            if (!services.SettingsCache.TryGetValue(operation.UpdateCascadeSettingId, out setting))
            {
                log.Error("Tried to add and run the operation {0}. But there is no corresponding setting {1}", operation.Id, operation.UpdateCascadeSettingId);
                return false;
            }

            lock (runningOperations)
            {
                if (runningOperations.TryGetValue(operation.ReferencedDocId, out ro))
                {
                    // the operation might be already here. This shouldn't occur
                    if (operation.Id == ro.Operation.Id)
                    {
                        log.Warn("Tried to start an operation that is already started. Operation Id = {0}", operation.Id);
                        return false;
                    }
                    // the operation might refer to an older entity. This is unprobable, I think
                    if (Buffers.Compare(operation.ReferencedDocEtag.ToByteArray(), ro.Operation.ReferencedDocEtag.ToByteArray()) < 0)
                    {
                        log.Warn("Tried to start an operation that refers to an entity which is older than the referenced by a running operation. Older operation id: {0}, existing operation id: {1}", operation.Id, ro.Operation.Id);
                        return false;
                    }

                    log.Warn("The same referenced entity {0} has been updated while a previous update cascade operation of that entity is in progress, that might indicate that the document is updated so often that referencing entities cannot be updated at time. Update cascade bundle is not recomended in this scenario", operation.ReferencedDocId);

                    // the same referenced entity has been updated while a previous update cascade operation of that entity is in progress
                    // we need to cancel that operation and span a new one.
                    var tokenSource = ro.TokenSource;
                    if (tokenSource != null) tokenSource.Cancel();
                    try
                    {
                        var task = ro.ExecutorTask;
                        if (task!= null) task.Wait();
                    }
                    catch (AggregateException ex)
                    {
                        ex.Handle(x => x is TaskCanceledException);
                    }
                }
                var runningOperation = new RunningOperation
                {
                    Operation = operation,
                    TokenSource =  new CancellationTokenSource(),
                    Executor = new UpdateCascadeOperationExecutor(db, setting, operation, referencedDoc),
                };
                runningOperations[operation.ReferencedDocId] = runningOperation;
                log.Trace("Starting operation: {0}", operation.Id);
                runningOperation.ExecutorTask = runningOperation.Executor.ExecuteAsync(runningOperation.TokenSource.Token);
                runningOperation.ExecutorTask.ContinueWith(t =>
                {
                    if (!services.IsShutDownInProgress)
                    {
                        lock (runningOperations)
                        {
                            RunningOperation rop;
                            if (runningOperations.TryGetValue(operation.ReferencedDocId, out rop))
                            {
                                if (rop.Operation.Id == operation.Id)
                                {
                                    runningOperations.Remove(operation.ReferencedDocId);
                                }
                            }
                            t.Dispose();
                        }
                    }

                }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);

                return true;
            }
        }
        public bool TryStartOperation(UpdateCascadeOperation operation, JsonDocument referencedDoc)
        {
            var services = Services.GetServices(this.db);

            if (services.IsShutDownInProgress)
            {
                log.Warn("Tried to start operation {0} while shuting down", operation.Id);
                return(false);
            }

            RunningOperation     ro = null;
            UpdateCascadeSetting setting;

            if (!services.SettingsCache.TryGetValue(operation.UpdateCascadeSettingId, out setting))
            {
                log.Error("Tried to add and run the operation {0}. But there is no corresponding setting {1}", operation.Id, operation.UpdateCascadeSettingId);
                return(false);
            }

            lock (runningOperations)
            {
                if (runningOperations.TryGetValue(operation.ReferencedDocId, out ro))
                {
                    // the operation might be already here. This shouldn't occur
                    if (operation.Id == ro.Operation.Id)
                    {
                        log.Warn("Tried to start an operation that is already started. Operation Id = {0}", operation.Id);
                        return(false);
                    }
                    // the operation might refer to an older entity. This is unprobable, I think
                    if (Buffers.Compare(operation.ReferencedDocEtag.ToByteArray(), ro.Operation.ReferencedDocEtag.ToByteArray()) < 0)
                    {
                        log.Warn("Tried to start an operation that refers to an entity which is older than the referenced by a running operation. Older operation id: {0}, existing operation id: {1}", operation.Id, ro.Operation.Id);
                        return(false);
                    }

                    log.Warn("The same referenced entity {0} has been updated while a previous update cascade operation of that entity is in progress, that might indicate that the document is updated so often that referencing entities cannot be updated at time. Update cascade bundle is not recomended in this scenario", operation.ReferencedDocId);

                    // the same referenced entity has been updated while a previous update cascade operation of that entity is in progress
                    // we need to cancel that operation and span a new one.
                    var tokenSource = ro.TokenSource;
                    if (tokenSource != null)
                    {
                        tokenSource.Cancel();
                    }
                    try
                    {
                        var task = ro.ExecutorTask;
                        if (task != null)
                        {
                            task.Wait();
                        }
                    }
                    catch (AggregateException ex)
                    {
                        ex.Handle(x => x is TaskCanceledException);
                    }
                }
                var runningOperation = new RunningOperation
                {
                    Operation   = operation,
                    TokenSource = new CancellationTokenSource(),
                    Executor    = new UpdateCascadeOperationExecutor(db, setting, operation, referencedDoc),
                };
                runningOperations[operation.ReferencedDocId] = runningOperation;
                log.Trace("Starting operation: {0}", operation.Id);
                runningOperation.ExecutorTask = runningOperation.Executor.ExecuteAsync(runningOperation.TokenSource.Token);
                runningOperation.ExecutorTask.ContinueWith(t =>
                {
                    if (!services.IsShutDownInProgress)
                    {
                        lock (runningOperations)
                        {
                            RunningOperation rop;
                            if (runningOperations.TryGetValue(operation.ReferencedDocId, out rop))
                            {
                                if (rop.Operation.Id == operation.Id)
                                {
                                    runningOperations.Remove(operation.ReferencedDocId);
                                }
                            }
                            t.Dispose();
                        }
                    }
                }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);

                return(true);
            }
        }
コード例 #9
0
    public void Display(RunningOperation operation, Mole mole)
    {
        _operation = operation;
        _mole      = mole;

        HideStuff();
        canvasGroup.alpha = 1;

        textOperationName.text = operation.Name;
        bool defSuccess      = true;
        bool atqSuccess      = true;
        int  digResult       = 0;
        int  newOperationDig = operation.Dig;

        if (mole.Def < operation.DefChallenge.RequiredValue)
        {
            float roll         = Random.Range(0f, 1f);
            float successRange = (float)mole.Def / operation.DefChallenge.RequiredValue;

            defSuccess = roll < successRange;
        }

        if (defSuccess)
        {
            if (mole.Atq < operation.AtqChallenge.RequiredValue)
            {
                float roll         = Random.Range(0f, 1f);
                float successRange = (float)mole.Atq / operation.AtqChallenge.RequiredValue;

                atqSuccess = roll < successRange;
            }
        }

        if (defSuccess)
        {
            digResult = atqSuccess
                ? mole.Dig
                : Mathf.FloorToInt((float)mole.Atq / operation.AtqChallenge.RequiredValue * mole.Dig);  // Embarassed by creature, digged less than expected
        }
        else
        {
            // Burried! We'll have to dig more next time.
            digResult = -Mathf.FloorToInt(0.5f * mole.Dig);
        }

        newOperationDig = Mathf.Clamp(_operation.Dig + digResult, 0, operation.DigTotal);

        ///////// NOW DISPLAY TO PLAYER

        textDefDetail.text = operation.DefChallenge.Name;
        textDefValue.text  = operation.DefChallenge.RequiredValue.ToString();
        textAtqDetail.text = operation.AtqChallenge.Name;
        textAtqValue.text  = operation.AtqChallenge.RequiredValue.ToString();
        textDig.text       = $"{operation.Dig}/{operation.DigTotal}";
        sliderDig.maxValue = operation.DigTotal;
        sliderDig.value    = operation.Dig;

        float timing = 0.3f;

        if (operation.CapsReward > 0 || operation.RootsReward > 0)
        {
            StartCoroutine(RevealDef(timing));
            timing += 0.3f;
            StartCoroutine(RevealDefResult(timing, defSuccess));
            timing += 0.4f;

            if (defSuccess)
            {
                StartCoroutine(RevealAtq(timing));
                timing += 0.3f;
                StartCoroutine(RevealAtqResult(timing, atqSuccess));
                timing += 0.4f;
            }
        }

        StartCoroutine(RevealDig(timing));
        timing += 0.2f;
        StartCoroutine(RevealDigAnimation(timing, newOperationDig));
    }
コード例 #10
0
 private void OnOperationLaunched(RunningOperation op)
 {
     ToggleVisibility(false);
 }