コード例 #1
0
 protected void OnParameterChange(Contract c, ContractParameter p)
 {
     if (c == Root)
     {
         CheckVessel(FlightGlobals.ActiveVessel);
     }
 }
コード例 #2
0
        public TitleTracker(ContractParameter parameter)
        {
            this.parameter = parameter;

            GameEvents.Contract.onParameterChange.Add(new EventData<Contract, ContractParameter>.OnEvent(OnParameterChange));
            GameEvents.onVesselRename.Add(new EventData<GameEvents.HostedFromToAction<Vessel, string>>.OnEvent(OnVesselRename));
        }
コード例 #3
0
        /// <summary>
        /// Call this any time the title text has changed - this will make an attempt to update
        /// the contract window title.  We do this because otherwise the window will only ever read
        /// the title once.
        /// </summary>
        /// <param name="newTitle">New title to display</param>
        public void UpdateContractWindow(ContractParameter param, string newTitle)
        {
            // Try to find the cascading list in the contracts window.  Note that we may pick up
            // the ones from the Engineer's report in the VAB/SPH instead - but we don't care about
            // title updates in those scenes anyway.
            if (cascadingList == null || !cascadingList.gameObject.activeSelf)
            {
                cascadingList = UnityEngine.Object.FindObjectOfType<GenericCascadingList>();
            }

            // Every time the clock ticks over, make an attempt to update the contract window
            // title.  We do this because otherwise the window will only ever read the title once,
            // so this is the only way to get our fancy timer to work.

            // Go through all the list items in the contracts window
            if (cascadingList != null)
            {
                UIScrollList list = cascadingList.ruiList.cascadingList;
                if (list != null)
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        // Try to find a rich text control that matches the expected text
                        UIListItemContainer listObject = (UIListItemContainer)list.GetItem(i);
                        SpriteTextRich richText = listObject.GetComponentInChildren<SpriteTextRich>();
                        if (richText != null)
                        {
                            // Check for any string in titleTracker
                            string found = null;
                            foreach (string title in titles)
                            {
                                if (richText.Text.EndsWith(title))
                                {
                                    found = title;
                                    break;
                                }
                            }

                            // Clear the titleTracker, and replace the text
                            if (found != null)
                            {
                                titles.Clear();
                                richText.Text = richText.Text.Replace(found, newTitle);
                                titles.Add(newTitle);
                            }
                        }
                    }

                    // Reposition items to account for items where the height increased or decreased
                    list.RepositionItems();
                }
            }

            // Contracts Window + update
            ContractsWindow.SetParameterTitle(param, newTitle);
        }
コード例 #4
0
 protected override void OnParameterStateChange(ContractParameter param)
 {
     ConditionDetail.Condition cond = param.State == ParameterState.Complete ?
         ConditionDetail.Condition.PARAMETER_COMPLETED :
         ConditionDetail.Condition.PARAMETER_FAILED;
     if (param.State == ParameterState.Incomplete)
     {
         return;
     }
     UnlockABase(cond, param.ID, param.State == ParameterState.Complete ? basename : basename);
 }
コード例 #5
0
        /// <summary>
        /// Set the parameter notes.
        /// </summary>
        /// <param name="param">ContractParameter object</param>
        /// <param name="notes">New notes</param>
        public static void SetParameterNotes(ContractParameter param, string notes)
        {
            if (!VerifyVersion())
            {
                return;
            }

            Type contractUtils = ContractsWindowAssembly.GetType("ContractsWindow.contractUtils");

            // Get and invoke the method
            MethodInfo method = contractUtils.GetMethod("setParameterNotes");
            method.Invoke(null, new object[] { param.Root, param, notes });
        }
コード例 #6
0
        protected override void OnParameterStateChange(ContractParameter param)
        {
            ConditionDetail.Condition cond = param.State == ParameterState.Complete ?
                ConditionDetail.Condition.PARAMETER_COMPLETED :
                ConditionDetail.Condition.PARAMETER_FAILED;
            if (param.State == ParameterState.Incomplete)
            {
                return;
            }

            DisplayMessages(cond, param.ID,param.State == ParameterState.Complete ?
                MessageSystemButton.MessageButtonColor.GREEN : MessageSystemButton.MessageButtonColor.RED);
        }
コード例 #7
0
		private void onParamChange(Contract c, ContractParameter p)
		{
			contractContainer cc = contractParser.getActiveContract(c.ContractGuid);

			if (cc == null)
				return;

			if (c.AllParameters.Count() > cc.ParameterCount)
			{
				cc.updateFullParamInfo();
				contractParser.onParameterAdded.Fire(c, p);
			}
		}
コード例 #8
0
        public bool CanRefactor(ContractParameter parameter)
        {
            if (IsBadDefaultValue(parameter.DefaultValue))
            {
                return(false);
            }

            if (parameter.Type.SpecialType.In(_numberTypes))
            {
                return(true);
            }

            return(false);
        }
コード例 #9
0
        /// <summary>
        /// Set the parameter notes.
        /// </summary>
        /// <param name="param">ContractParameter object</param>
        /// <param name="notes">New notes</param>
        public static void SetParameterNotes(ContractParameter param, string notes)
        {
            if (!VerifyVersion())
            {
                return;
            }

            Type contractUtils = ContractsWindowAssembly.GetType("ContractsWindow.contractUtils");

            // Get and invoke the method
            MethodInfo method = contractUtils.GetMethod("setParameterNotes");

            method.Invoke(null, new object[] { param.Root, param, notes });
        }
コード例 #10
0
 protected override void OnParameterStateChange(ContractParameter contractParameter)
 {
     if (System.Object.ReferenceEquals(contractParameter.Parent, this))
     {
         if (AllChildParametersComplete())
         {
             SetState(ParameterState.Complete);
         }
         else if (AnyChildParametersFailed())
         {
             SetState(ParameterState.Failed);
         }
     }
 }
コード例 #11
0
        /// <summary>
        /// Process "invoke" command
        /// </summary>
        /// <param name="scriptHash">Script hash</param>
        /// <param name="operation">Operation</param>
        /// <param name="result">Result</param>
        /// <param name="verificable">Transaction</param>
        /// <param name="contractParameters">Contract parameters</param>
        /// <returns>Return true if it was successful</returns>
        private bool OnInvokeWithResult(UInt160 scriptHash, string operation, out StackItem result, IVerifiable verificable = null, JArray contractParameters = null, bool showStack = true)
        {
            List <ContractParameter> parameters = new List <ContractParameter>();

            if (contractParameters != null)
            {
                foreach (var contractParameter in contractParameters)
                {
                    parameters.Add(ContractParameter.FromJson(contractParameter));
                }
            }

            var           snapshot = Blockchain.Singleton.GetSnapshot();
            ContractState contract = NativeContract.ContractManagement.GetContract(snapshot, scriptHash);

            if (contract == null)
            {
                Console.WriteLine("Contract does not exist.");
                result = StackItem.Null;
                return(false);
            }
            else
            {
                if (contract.Manifest.Abi.GetMethod(operation) == null)
                {
                    Console.WriteLine("This method does not not exist in this contract.");
                    result = StackItem.Null;
                    return(false);
                }
            }

            byte[] script;

            using (ScriptBuilder scriptBuilder = new ScriptBuilder())
            {
                scriptBuilder.EmitDynamicCall(scriptHash, operation, parameters.ToArray());
                script = scriptBuilder.ToArray();
                Console.WriteLine($"Invoking script with: '{script.ToBase64String()}'");
            }

            if (verificable is Transaction tx)
            {
                tx.Script = script;
            }

            using ApplicationEngine engine = ApplicationEngine.Run(script, container: verificable);
            PrintExecutionOutput(engine, showStack);
            result = engine.State == VMState.FAULT ? null : engine.ResultStack.Peek();
            return(engine.State != VMState.FAULT);
        }
コード例 #12
0
        public static ScriptBuilder EmitPush(this ScriptBuilder sb, ContractParameter parameter)
        {
            switch (parameter.Type)
            {
            case ContractParameterType.Signature:
            case ContractParameterType.ByteArray:
                sb.EmitPush((byte[])parameter.Value);
                break;

            case ContractParameterType.Boolean:
                sb.EmitPush((bool)parameter.Value);
                break;

            case ContractParameterType.Integer:
                sb.EmitPush((BigInteger)parameter.Value);
                break;

            case ContractParameterType.Hash160:
                sb.EmitPush((UInt160)parameter.Value);
                break;

            case ContractParameterType.Hash256:
                sb.EmitPush((UInt256)parameter.Value);
                break;

            case ContractParameterType.PublicKey:
                sb.EmitPush((ECPoint)parameter.Value);
                break;

            case ContractParameterType.String:
                sb.EmitPush((string)parameter.Value);
                break;

            case ContractParameterType.Array:
            {
                IList <ContractParameter> parameters = (IList <ContractParameter>)parameter.Value;
                for (int i = parameters.Count - 1; i >= 0; i--)
                {
                    sb.EmitPush(parameters[i]);
                }
                sb.EmitPush(parameters.Count);
                sb.Emit(OpCode.PACK);
            }
            break;

            default:
                throw new ArgumentException();
            }
            return(sb);
        }
コード例 #13
0
        public new bool AnyChildParametersFailed()
        {
            for (int i = ParameterCount; i-- > 0;)
            {
                ContractParameter             param   = GetParameter(i);
                ContractConfiguratorParameter ccParam = param as ContractConfiguratorParameter;
                if (param.State == ParameterState.Failed && (ccParam == null || !ccParam.fakeFailures))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #14
0
        /// <summary>
        /// Process "invoke" command
        /// </summary>
        /// <param name="scriptHash">Script hash</param>
        /// <param name="operation">Operation</param>
        /// <param name="result">Result</param>
        /// <param name="verificable">Transaction</param>
        /// <param name="contractParameters">Contract parameters</param>
        /// <param name="showStack">Show result stack if it is true</param>
        /// <param name="gas">Max fee for running the script</param>
        /// <returns>Return true if it was successful</returns>
        private bool OnInvokeWithResult(UInt160 scriptHash, string operation, out StackItem result, IVerifiable verificable = null, JArray contractParameters = null, bool showStack = true, long gas = TestModeGas)
        {
            List <ContractParameter> parameters = new List <ContractParameter>();

            if (contractParameters != null)
            {
                foreach (var contractParameter in contractParameters)
                {
                    parameters.Add(ContractParameter.FromJson(contractParameter));
                }
            }

            ContractState contract = NativeContract.ContractManagement.GetContract(NeoSystem.StoreView, scriptHash);

            if (contract == null)
            {
                ConsoleHelper.Error("Contract does not exist.");
                result = StackItem.Null;
                return(false);
            }
            else
            {
                if (contract.Manifest.Abi.GetMethod(operation, parameters.Count) == null)
                {
                    ConsoleHelper.Error("This method does not not exist in this contract.");
                    result = StackItem.Null;
                    return(false);
                }
            }

            byte[] script;

            using (ScriptBuilder scriptBuilder = new ScriptBuilder())
            {
                scriptBuilder.EmitDynamicCall(scriptHash, operation, parameters.ToArray());
                script = scriptBuilder.ToArray();
                ConsoleHelper.Info("Invoking script with: ", $"'{script.ToBase64String()}'");
            }

            if (verificable is Transaction tx)
            {
                tx.Script = script;
            }

            using ApplicationEngine engine = ApplicationEngine.Run(script, NeoSystem.StoreView, container: verificable, settings: NeoSystem.Settings, gas: gas);
            PrintExecutionOutput(engine, showStack);
            result = engine.State == VMState.FAULT ? null : engine.ResultStack.Peek();
            return(engine.State != VMState.FAULT);
        }
コード例 #15
0
        internal static string paramTypeCheck(ContractParameter param)
        {
            if (param.GetType() == typeof(PartTest))
            {
                return("partTest");
            }

            if (contractAssembly.MCELoaded)
            {
                if (param.GetType() == contractAssembly._MCEType)
                {
                    return("MCEScience");
                }
            }

            if (contractAssembly.DMLoaded)
            {
                if (param.GetType() == contractAssembly._DMCType)
                {
                    return("DMcollectScience");
                }
            }

            if (contractAssembly.DMALoaded)
            {
                if (param.GetType() == contractAssembly._DMAType)
                {
                    return("DManomalyScience");
                }
                else
                {
                    return("");
                }
            }

            if (contractAssembly.DMAstLoaded)
            {
                if (param.GetType() == contractAssembly._DMAstType)
                {
                    return("DMasteroidScience");
                }
                else
                {
                    return("");
                }
            }

            return("");
        }
コード例 #16
0
 protected static IEnumerable <T> AllDescendents <T>(ContractParameter p) where T : ContractParameter
 {
     for (int i = 0; i < p.ParameterCount; i++)
     {
         ContractParameter child = p.GetParameter(i);
         if (child is T)
         {
             yield return(child as T);
         }
         foreach (ContractParameter grandChild in AllDescendents <T>(child))
         {
             yield return(grandChild as T);
         }
     }
 }
コード例 #17
0
        private ContractParameter[] ConvertToContractParameters(SimpleParameter[] parameters)
        {
            var neoParameter = new List <ContractParameter>();

            foreach (var simpleParameter in parameters)
            {
                var p = new ContractParameter(simpleParameter.ParameterType)
                {
                    Value = simpleParameter.Value
                };
                neoParameter.Add(p);
            }

            return(neoParameter.ToArray());
        }
コード例 #18
0
        protected override void OnParameterStateChange(ContractParameter p)
        {
            base.OnParameterStateChange(p);

            foreach (ContractParameter parameter in AllParameters)
            {
                if (parameter.State == ParameterState.Incomplete || parameter.State == ParameterState.Failed)
                {
                    return;
                }
            }

            //All parameters are complete
            SetState(State.Completed);
        }
コード例 #19
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedIndices.Count == 0)
            {
                return;
            }
            ContractParameter parameter = (ContractParameter)listView1.SelectedItems[0].Tag;

            using (ParametersEditor dialog = new ParametersEditor((IList <ContractParameter>)parameter.Value))
            {
                dialog.ShowDialog();
                listView1.SelectedItems[0].SubItems["value"].Text = parameter.ToString();
                textBox1.Text = listView1.SelectedItems[0].SubItems["value"].Text;
            }
        }
コード例 #20
0
 protected void OnAnyContractParameterChange(Contract contract, ContractParameter contractParameter)
 {
     if (contract == Root)
     {
         LoggingUtil.LogVerbose(this, "OnAnyContractParameterChange");
         if (this.GetChildren().Where(p => p.State == ParameterState.Complete).Any())
         {
             SetState(ParameterState.Incomplete);
         }
         else
         {
             SetState(ParameterState.Complete);
         }
     }
 }
コード例 #21
0
ファイル: RpcInvokeResult.cs プロジェクト: slamj1/neo-modules
        public static RpcInvokeResult FromJson(JObject json)
        {
            RpcInvokeResult invokeScriptResult = new RpcInvokeResult();

            invokeScriptResult.Script      = json["script"].AsString();
            invokeScriptResult.State       = json["state"].TryGetEnum <VM.VMState>();
            invokeScriptResult.GasConsumed = json["gasconsumed"].AsString();
            try
            {
                invokeScriptResult.Stack = ((JArray)json["stack"]).Select(p => ContractParameter.FromJson(p)).ToArray();
            }
            catch { }
            invokeScriptResult.Tx = json["tx"]?.AsString();
            return(invokeScriptResult);
        }
コード例 #22
0
        public void TestInvokeScriptNull()
        {
            var nullExecutionEngine = new NullExecutionEngine();
            var stackItemStackMock  = new NullStack();

            nullExecutionEngine.PublicStackItemsStack = stackItemStackMock;

            var invocationProcess  = new InvocationProcess(nullExecutionEngine);
            var intParameter       = new IntegerContractParameter(1);
            var contractParameters = new ContractParameter[] { intParameter };

            var invocationResult = invocationProcess.Invoke(null, contractParameters);

            Assert.IsNotNull(invocationResult);
        }
コード例 #23
0
        private void onParamChange(Contract c, ContractParameter p)
        {
            contractContainer cc = contractParser.getActiveContract(c.ContractGuid);

            if (cc == null)
            {
                return;
            }

            if (c.AllParameters.Count() > cc.ParameterCount)
            {
                cc.updateFullParamInfo();
                contractParser.onParameterAdded.Fire(c, p);
            }
        }
コード例 #24
0
 protected void OnAnyContractParameterChange(Contract contract, ContractParameter contractParameter)
 {
     if (contract == Root)
     {
         LoggingUtil.LogVerbose(this, "OnAnyContractParameterChange");
         if (this.GetChildren().Where(p => p.State == ParameterState.Complete).Any())
         {
             SetState(ParameterState.Incomplete);
         }
         else
         {
             SetState(ParameterState.Complete);
         }
     }
 }
コード例 #25
0
        /// <summary>
        /// Method for generating ContractParameter objects.  This will call the Generate() method
        /// on the sub-class, load all common parameters and load child parameters.
        /// </summary>
        /// <param name="contract">Contract to generate for</param>
        /// <param name="contractParamHost">Parent object for the ContractParameter</param>
        /// <returns>Generated ContractParameter</returns>
        public virtual ContractParameter Generate(ConfiguredContract contract, IContractParameterHost contractParamHost)
        {
            // First check any requirements
            if (!ContractRequirement.RequirementsMet(contract, contract.contractType, requirements))
            {
                LoggingUtil.LogVerbose(typeof(ParameterFactory), "Returning null for " + contract.contractType.name + "." + name + ": requirements not met.");
                return(null);
            }

            // Generate a parameter using the sub-class logic
            ContractParameter parameter = Generate(contract);

            if (parameter == null)
            {
                LoggingUtil.LogWarning(this, GetType().FullName + ".Generate() returned a null ContractParameter!");
                return(null);
            }

            // Add ContractParameter to the host
            contractParamHost.AddParameter(parameter);

            // Set the funds/science/reputation parameters
            parameter.SetFunds(rewardFunds, failureFunds, targetBody);
            parameter.SetReputation(rewardReputation, failureReputation, targetBody);
            parameter.SetScience(rewardScience, targetBody);

            // Set other flags
            parameter.Optional = optional;
            if (disableOnStateChange != null)
            {
                parameter.DisableOnStateChange = (bool)disableOnStateChange;
            }
            parameter.ID = name;

            // Special stuff for contract configurator parameters
            ContractConfiguratorParameter ccParam = parameter as ContractConfiguratorParameter;

            if (ccParam != null)
            {
                ccParam.completeInSequence = completeInSequence;
                ccParam.notes            = notes;
                ccParam.completedMessage = completedMessage;
                ccParam.hidden           = hidden;
                ccParam.hideChildren     = hideChildren;
            }

            return(parameter);
        }
コード例 #26
0
        protected void OnParameterChange(Contract c, ContractParameter p)
        {
            if (c != contract)
            {
                return;
            }

            if (p.ID == unlockParameter && unlockCriteria == UnlockCriteria.PARAMETER_COMPLETION)
            {
                UnlockParts();
            }
            if (p.ID == lockParameter && lockCriteria == LockCriteria.PARAMETER_COMPLETION)
            {
                LockParts();
            }
        }
コード例 #27
0
 void StockOnParameterChange(Contract c, ContractParameter p)
 {
     // Workaround for stock bug #18267
     if (p.State == ParameterState.Complete && p.FundsCompletion == 0 && p.ScienceCompletion == 0 && p.ReputationCompletion == 0)
     {
         Versioning v = Versioning.Instance as Versioning;
         if (v.versionMajor == 1 && v.versionMinor == 4 && v.revision == 2)
         {
             MessageSystem.Message message = MessageSystem.Instance.FindMessages(m => m.message.Contains(p.MessageComplete)).FirstOrDefault();
             if (message != null)
             {
                 MessageSystem.Instance.DiscardMessage(message.button);
             }
         }
     }
 }
コード例 #28
0
        protected override void OnParameterStateChange(ContractParameter param)
        {
            base.OnParameterStateChange(param);

            var matchingParameter = GetMatchingParameter(param);

            if (matchingParameter == null)
            {
                return;
            }

            if (matchingParameter.State == ParameterState.Complete)
            {
                DoShow();
            }
        }
コード例 #29
0
        protected override void OnParameterStateChange(ContractParameter param)
        {
            ConditionDetail.Condition cond = param.State == ParameterState.Complete ?
                                             ConditionDetail.Condition.PARAMETER_COMPLETED :
                                             ConditionDetail.Condition.PARAMETER_FAILED;
            if (param.State == ParameterState.Incomplete)
            {
                return;
            }

            foreach (ConditionDetail cd in conditions.Where(cd => !cd.disabled && cd.condition == cond && cd.parameter == param.ID))
            {
                DisplayMessage(title, message, param.State == ParameterState.Complete ? MessageSystemButton.MessageButtonColor.GREEN : MessageSystemButton.MessageButtonColor.RED);
                cd.disabled = true;
            }
        }
コード例 #30
0
 internal paramTypeContainer(Type PType)
 {
     paramType = PType;
     try
     {
         param = (ContractParameter)Activator.CreateInstance(PType);
     }
     catch (Exception e)
     {
         DMC_MBE.LogFormatted("This Parameter Type: {0} Does Not Have An Empty Constructor And Will Be Skipped: {1]", PType.Name, e);
         return;
     }
     name       = PType.Name;
     name       = Regex.Replace(name, "([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))", "$1 ");
     rewardFund = penaltyFund = rewardRep = penaltyRep = rewardScience = 1f;
 }
コード例 #31
0
ファイル: ParametersEditor.cs プロジェクト: xzlib/neo-gui-nel
 private void button1_Click(object sender, EventArgs e)
 {
     if (listView1.SelectedIndices.Count == 0) return;
     ContractParameter parameter = (ContractParameter)listView1.SelectedItems[0].Tag;
     try
     {
         parameter.SetValue(textBox2.Text);
         listView1.SelectedItems[0].SubItems["value"].Text = parameter.ToString();
         textBox1.Text = listView1.SelectedItems[0].SubItems["value"].Text;
         textBox2.Clear();
     }
     catch(Exception err)
     {
         MessageBox.Show(err.Message);
     }
 }
コード例 #32
0
        protected override void OnParameterStateChange(ContractParameter param)
        {
            ConditionDetail.Condition cond = param.State == ParameterState.Complete ?
                ConditionDetail.Condition.PARAMETER_COMPLETED :
                ConditionDetail.Condition.PARAMETER_FAILED;
            if (param.State == ParameterState.Incomplete)
            {
                return;
            }

            foreach (ConditionDetail cd in conditions.Where(cd => !cd.disabled && cd.condition == cond && cd.parameter == param.ID))
            {
                DisplayMessage(title, message, param.State == ParameterState.Complete ? MessageSystemButton.MessageButtonColor.GREEN : MessageSystemButton.MessageButtonColor.RED);
                cd.disabled = true;
            }
        }
コード例 #33
0
        protected void OnParameterChange(Contract c, ContractParameter p)
        {
            if (c != Root)
            {
                return;
            }

            if (p.ID == startParameter && startCriteria == StartCriteria.PARAMETER_COMPLETION && startTime == 0.0)
            {
                SetStartTime();
            }
            if (p.ID == endParameter && endCriteria == EndCriteria.PARAMETER_COMPLETION && endTime == 0.0)
            {
                SetEndTime();
            }
        }
コード例 #34
0
        /// <summary>
        /// Checks the child conditions for each child parameter delegate in the given parent.
        /// </summary>
        /// <param name="param">The contract parameter that we are called from.</param>
        /// <param name="values">The values to enumerator over.</param>
        /// <param name="checkOnly">Only perform a check, don't change values.</param>
        /// <returns></returns>
        public static bool CheckChildConditions(ContractParameter param, T value, bool checkOnly = false)
        {
            bool conditionMet = true;
            int  count        = param.ParameterCount;

            for (int i = 0; i < param.ParameterCount; i++)
            {
                ParameterDelegate <T> delegateParam = param[i] as ParameterDelegate <T>;
                if (delegateParam != null)
                {
                    conditionMet &= delegateParam.SetState(value);
                }
            }

            return(conditionMet);
        }
コード例 #35
0
 /// <summary>
 /// A method for returning a parameterContainer object. The contract and parameter in question must be loaded by 
 /// Contracts Window + and may return null. All fields within the object are publicly accessible through properties.
 /// </summary>
 /// <param name="contract">Instance of the root contract (contractParameter.Root)</param>
 /// <param name="parameter">Instance of the contract parameter in question</param>
 /// <returns>parameterContainer object</returns>
 public static parameterContainer getParameterContainer(Contract contract, ContractParameter parameter)
 {
     try
     {
         contractContainer c = contractScenario.Instance.getContract(contract.ContractGuid);
         parameterContainer pC = null;
         if (c != null)
             pC = c.AllParamList.SingleOrDefault(a => a.CParam == parameter);
         return pC;
     }
     catch (Exception e)
     {
         Debug.LogWarning("[Contracts +] Something went wrong when attempting to get a Parameter Container object: " + e);
         return null;
     }
 }
コード例 #36
0
        /// <summary>
        /// Checks the child conditions for each child parameter delegate in the given parent.
        /// </summary>
        /// <param name="param">The contract parameter that we are called from.</param>
        /// <param name="values">The values to enumerator over.</param>
        /// <param name="checkOnly">Only perform a check, don't change values.</param>
        /// <returns></returns>
        protected static BitArray CheckChildConditions(ContractParameter param, IEnumerable <T> values, ref bool conditionMet, bool checkOnly = false)
        {
            int      count   = values.Count();
            BitArray current = null;

            int paramCount = param.ParameterCount;

            for (int i = 0; i < paramCount; i++)
            {
                ParameterDelegate <T> paramDelegate = param[i] as ParameterDelegate <T>;
                if (paramDelegate != null)
                {
                    LoggingUtil.LogVerbose(paramDelegate, "Checking condition for '{0}', conditionMet = {1}", paramDelegate.title, conditionMet);

                    paramDelegate.InitializeBitArrays(values, current);
                    paramDelegate.SetState(values, ref conditionMet, checkOnly);

                    LoggingUtil.LogVerbose(paramDelegate, "  after, conditionMet = {0}", conditionMet);

                    if (paramDelegate.matchType == ParameterDelegateMatchType.FILTER)
                    {
                        current = paramDelegate.dest;
                    }
                    int newCount = GetCount(values, paramDelegate.dest);
                    switch (paramDelegate.matchType)
                    {
                    case ParameterDelegateMatchType.FILTER:
                        count = newCount;
                        break;

                    case ParameterDelegateMatchType.VALIDATE:
                        conditionMet &= newCount > 0;
                        break;

                    case ParameterDelegateMatchType.VALIDATE_ALL:
                        conditionMet &= count == newCount;
                        break;

                    case ParameterDelegateMatchType.NONE:
                        conditionMet &= newCount == 0;
                        break;
                    }
                }
            }

            return(current);
        }
コード例 #37
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex < 0)
            {
                return;
            }
            if (listBox2.SelectedIndex < 0)
            {
                return;
            }
            ContractParameter parameter = (ContractParameter)listBox2.SelectedItem;

            parameter.SetValue(textBox2.Text);
            listBox2.Items[listBox2.SelectedIndex] = parameter;
            textBox1.Text   = textBox2.Text;
            button4.Visible = context.Completed;
        }
コード例 #38
0
ファイル: UT_Helper.cs プロジェクト: mohamadDev/neo
        private void TestEmitPush2Array()
        {
            ScriptBuilder             sb        = new ScriptBuilder();
            ContractParameter         parameter = new ContractParameter(ContractParameterType.Array);
            IList <ContractParameter> values    = new List <ContractParameter>();

            values.Add(new ContractParameter(ContractParameterType.Integer));
            values.Add(new ContractParameter(ContractParameterType.Integer));
            parameter.Value = values;
            sb.EmitPush(parameter);
            byte[] tempArray = new byte[4];
            tempArray[0] = 0x00;
            tempArray[1] = 0x00;
            tempArray[2] = 0x52;
            tempArray[3] = 0xC1;
            Assert.AreEqual(Encoding.Default.GetString(tempArray), Encoding.Default.GetString(sb.ToArray()));
        }
コード例 #39
0
        public ActionResult AjaxContractDelete(ContractParameter param)
        {
            var result = new JsonNetResult();
            var r      = new GeneralResponse();

            try
            {
                r.Code = ContractProvider.Delete(param).ToString(Section.Get.Common.Culture);
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message, ex);
                r.Code = "-11";
            }
            result.Data = r;
            return(result);
        }
コード例 #40
0
        /// <summary>
        /// Gets the text of all the child delegates in one big string.  Useful for printing out
        /// the full details for completed parameters.
        /// </summary>
        /// <param name="param">Th parent parameters.</param>
        /// <returns>The full delegate string</returns>
        public static string GetDelegateText(ContractParameter param)
        {
            string output = "";

            foreach (ContractParameter child in param.AllParameters)
            {
                if (child is ParameterDelegate <T> && !((ParameterDelegate <T>)child).trivial)
                {
                    if (!string.IsNullOrEmpty(output))
                    {
                        output += "; ";
                    }
                    output += ((ParameterDelegate <T>)child).title;
                }
            }
            return(output);
        }
コード例 #41
0
        protected override void OnParameterStateChange(ContractParameter param)
        {
            if (param.State == ParameterState.Complete && parameter.Contains(param.ID))
            {
                VesselParameterGroup vpg = param as VesselParameterGroup;
                SetCrew(vpg.TrackedVessel);

                // If the parameter is the last one to complete, then the events fire in the wrong
                // order.  So check for that condition.
                if (contract.ContractState == Contract.State.Completed)
                {
                    DoAwarding();
                }

                // Sometimes we can also get multiple events for the same parameter (even without
                // disableOnStateChange set to false).  So prevent duplicate experience rewards.
                parameter.Remove(param.ID);
            }
        }
コード例 #42
0
		public parameterContainer(contractContainer Root, ContractParameter cP, int Level)
		{
			root = Root;
			cParam = cP;

			try
			{
				title = cParam.Title;
			}
			catch (Exception e)
			{
				Debug.LogError("[Contract Parser] Contract Parameter Title not set, using type name...\n" + e);
				title = cParam.GetType().Name;
			}

			try
			{
				notes = cParam.Notes;
			}
			catch (Exception e)
			{
				Debug.LogError("[Contract Parser] Contract Parameter Notes not set, blank notes used...\n" + e);
				notes = "";
			}

			level = Level;	
			paramRewards();
			paramPenalties();

			waypoint = checkForWaypoint();

			customNotes = setCustomNotes();

			if (level < 4)
			{
				for (int i = 0; i < cParam.ParameterCount; i++)
				{
					ContractParameter param = cParam.GetParameter(i);
					addSubParam(param, level + 1);
				}
			}
		}
コード例 #43
0
        protected override void OnParameterStateChange(ContractParameter contractParameter)
        {
            if (System.Object.ReferenceEquals(contractParameter.Parent, this))
            {
                SetupChildParameters();

                bool foundNotComplete = false;
                for (int i = 0; i < ParameterCount; i++)
                {
                    ContractParameter param = GetParameter(i);
                    // Found an incomplete parameter
                    if (param.State != ParameterState.Complete)
                    {
                        foundNotComplete = true;

                        // If it's failed, just straight up fail the parameter
                        if (param.State == ParameterState.Failed)
                        {
                            SetState(ParameterState.Failed);
                            return;
                        }
                    }
                    // We found a complete parameter after finding an incomplete one - failure condition
                    else if (foundNotComplete && failWhenCompleteOutOfOrder)
                    {
                        SetState(ParameterState.Failed);
                        return;
                    }
                }

                // Everything we found was complete
                if (!foundNotComplete)
                {
                    SetState(ParameterState.Complete);
                }
            }
        }
コード例 #44
0
 protected void OnParameterChange(Contract c, ContractParameter p)
 {
     visitWaypoint.OnParameterChange(c, p);
 }
コード例 #45
0
        public void OnParameterChange(Contract c, ContractParameter p)
        {
            if (c != Root)
            {
                return;
            }

            // Hide the waypoint if we are done with it
            if (hideOnCompletion && waypoint != null && waypoint.visible)
            {
                for (IContractParameterHost paramHost = this; paramHost != Root; paramHost = paramHost.Parent)
                {
                    if (state == ParameterState.Complete)
                    {
                        ContractParameter param = paramHost as ContractParameter;
                        if (param != null && !param.Enabled)
                        {
                            waypoint.visible = false;
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
コード例 #46
0
 protected void OnParameterStateChange(Contract contract, ContractParameter param)
 {
     if (contract == this)
     {
         OnParameterStateChange(param);
     }
 }
コード例 #47
0
        protected override void OnParameterStateChange(ContractParameter param)
        {
            base.OnParameterStateChange(param);
            foreach (ContractBehaviour behaviour in behaviours)
            {
                behaviour.ParameterStateChange(param);
            }

            // Check for completion - stock ignores the optional flag
            bool completed = true;
            foreach (ContractParameter child in this.GetChildren())
            {
                if (child.State != ParameterState.Complete && !child.Optional)
                {
                    completed = false;
                }
            }
            if (completed)
            {
                SetState(Contract.State.Completed);
            }
        }
コード例 #48
0
 internal static string DMagicAsteroidSciencePartName(ContractParameter cParam)
 {
     return _DMAst(cParam);
 }
コード例 #49
0
 protected override void OnParameterStateChange(ContractParameter param)
 {
     if (param.State == ParameterState.Complete && onParameterComplete.ContainsKey(param.ID))
     {
         ExecuteExpressions(onParameterComplete[param.ID]);
         onParameterComplete[param.ID].Clear();
     }
 }
コード例 #50
0
 internal static string FPPartName(ContractParameter cParam)
 {
     return _FP(cParam);
 }
コード例 #51
0
 protected override void OnParameterStateChange(ContractParameter param)
 {
     if (param.State == ParameterState.Complete)
     {
         foreach (WaypointData wpData in waypoints)
         {
             if (wpData.waypoint.visible && wpData.parameter == param.ID)
             {
                 AddWayPoint(wpData.waypoint);
             }
         }
     }
 }
コード例 #52
0
 protected void OnParameterChange(Contract c, ContractParameter p)
 {
     if (c == Root && p.ID == parameter && timerType == TimerType.PARAMETER_COMPLETION && endTime == 0.0)
     {
         SetEndTime();
     }
 }
コード例 #53
0
        protected override void OnParameterStateChange(ContractParameter param)
        {
            LoggingUtil.LogVerbose(this, "OnParameterStateChange");

            // Just call OnOffered to add any missing waypoints
            OnOffered();
        }
コード例 #54
0
 /// <summary>
 /// A method for manually resetting a locally cached contract parameter title.
 /// </summary>
 /// <param name="contract">Instance of the root contract (contractParameter.Root)</param>
 /// <param name="parameter">Instance of the contract parameter in question</param>
 /// <param name="name">The new contract parameter title</param>
 public static void setParameterTitle(Contract contract, ContractParameter parameter, string name)
 {
     try
     {
         contractContainer c = contractScenario.Instance.getContract(contract.ContractGuid);
         if (c != null)
         {
             parameterContainer pC = c.AllParamList.SingleOrDefault(a => a.CParam == parameter);
             if (pC != null)
             {
                 pC.Title = name;
             }
         }
     }
     catch (Exception e)
     {
         Debug.LogWarning("[Contracts +] Something went wrong when attempting to assign a new Parameter Title: " + e);
     }
 }
コード例 #55
0
		private void addContractParam(ContractParameter param, int Level)
		{
			parameterContainer cc = new parameterContainer(this, param, Level);
			paramList.Add(cc);
			allParamList.Add(cc);
		}
コード例 #56
0
		internal static string paramTypeCheck(ContractParameter param)
		{
			if (param.GetType() == typeof(PartTest))
				return "partTest";

			if (contractAssembly.FPLoaded)
			{
				if (param.GetType() == contractAssembly._FPType)
					return "FinePrint";
			}

			if (contractAssembly.MCELoaded)
			{
				if (param.GetType() == contractAssembly._MCEType)
					return "MCEScience";
			}

			if (contractAssembly.DMLoaded)
			{
				if (param.GetType() == contractAssembly._DMCType)
					return "DMcollectScience";
			}

			if (contractAssembly.DMALoaded)
			{
				if (param.GetType() == contractAssembly._DMAType)
					return "DManomalyScience";
				else
					return "";
			}

			if (contractAssembly.DMAstLoaded)
			{
				if (param.GetType() == contractAssembly._DMAstType)
					return "DMasteroidScience";
				else
					return "";
			}

			return "";
		}
コード例 #57
0
        private void OnParameterChange(Contract contract, ContractParameter parameter)
        {
            if (contract != Root || parameter == this)
            {
                return;
            }

            TestConditions();
        }
コード例 #58
0
 internal static string MCEPartName(ContractParameter cParam)
 {
     return _MCE(cParam);
 }
コード例 #59
0
 internal static string DMagicAnomalySciencePartName(ContractParameter cParam)
 {
     return _DMAnomaly(cParam);
 }
コード例 #60
0
 internal static string DMagicSciencePartName(ContractParameter cParam)
 {
     return _DMCollect(cParam);
 }