private static CampaignTime?GetTimeOfLastAnnexDecisionAgainstClan(Clan clan) { return(KingdomDecisionHistory.Where(d => d.Key is SettlementClaimantPreliminaryDecision otherPreliminaryDecision && otherPreliminaryDecision.Kingdom == clan.Kingdom && FieldAccessHelper.annexDecisionInitialOwnerByRef(otherPreliminaryDecision) == clan) .OrderByDescending(d => d.Value.ConclusionTime).FirstOrDefault().Value?.ConclusionTime); }
internal void InitializeAOHeroRelations() { Dictionary <long, int> nativeRelations = new Dictionary <long, int>(FieldAccessHelper.heroRelationsByRef(FieldAccessHelper.heroRelationsInstanceByRef(CharacterRelationManager.Instance))); Dictionary <ulong, int> heroRelations = new Dictionary <ulong, int>(); foreach (Hero baseHero in Hero.All.Where(h => (h.IsNoble || h.IsWanderer) && h != Hero.MainHero)) { foreach (Hero otherHero in Hero.All.Where(h => (h.IsNoble || h.IsWanderer) && h != baseHero)) { heroRelations.Add(ElegantPairHelper.Pair(baseHero.Id, otherHero.Id), nativeRelations.TryGetValue(MBGUID.GetHash2(baseHero.Id, otherHero.Id), out int relation) ? relation : 0); } } _AOHeroRelations = heroRelations; }
private float GetGeneralSupportScore(Clan clan, DeclareWarDecision declareWarDecision, DecisionOutcome possibleOutcome) { int valueForClan = new DeclareWarBarterable(declareWarDecision.Kingdom, declareWarDecision.FactionToDeclareWarOn).GetValueForFaction(clan); float situationalFactorValue = 0; if (Settings.Instance.WarSupportCalculationMethod.SelectedValue.EnumValue.HasFlag(PeaceAndWarConsideration.SituationalFactor)) { situationalFactorValue = ApplySituationalFactor(declareWarDecision, ref valueForClan); } return(FieldAccessHelper.ShouldWarBeDeclaredByRef(possibleOutcome) ? valueForClan * Campaign.Current.Models.DiplomacyModel.DenarsToInfluence() + situationalFactorValue : -valueForClan *Campaign.Current.Models.DiplomacyModel.DenarsToInfluence() - situationalFactorValue); }
//GetGeneralSupportScore internal - per decision type private float GetGeneralSupportScore(Clan clan, MakePeaceKingdomDecision makePeaceDecision, DecisionOutcome possibleOutcome) { int valueForClan = new PeaceBarterable(makePeaceDecision.Kingdom, makePeaceDecision.FactionToMakePeaceWith, CampaignTime.Years(1f)).GetValueForFaction(clan) - Campaign.Current.Models.DiplomacyModel.GetValueOfDailyTribute(makePeaceDecision.DailyTributeToBePaid); float situationalFactorValue = 0; if (Settings.Instance.PeaceSupportCalculationMethod.SelectedValue.EnumValue.HasFlag(PeaceAndWarConsideration.SituationalFactor)) { situationalFactorValue = ApplySituationalFactor(makePeaceDecision, ref valueForClan); } return(FieldAccessHelper.ShouldPeaceBeDeclaredByRef(possibleOutcome) ? valueForClan * Campaign.Current.Models.DiplomacyModel.DenarsToInfluence() + situationalFactorValue : -valueForClan *Campaign.Current.Models.DiplomacyModel.DenarsToInfluence() - situationalFactorValue); }
private double GetSupportScoreOfDecisionMaker(DecisionMaker decisionMaker, DeclareWarDecision declareWarDecision, DecisionOutcome possibleOutcome) { double traitScore = decisionMaker.Hero.GetTraitLevel(DefaultTraits.Valor) * 20 - decisionMaker.Hero.GetTraitLevel(DefaultTraits.Mercy) * 10; double relationshipFactorValue = Settings.Instance.WarSupportCalculationMethod.SelectedValue.EnumValue.HasFlag(PeaceAndWarConsideration.RelationshipFactor) ? CalculateRelationshipFactor(decisionMaker, declareWarDecision.FactionToDeclareWarOn) * Settings.Instance.DeclareWarRelationshipFactorStrength : 0; double tributeFactorValue = Settings.Instance.WarSupportCalculationMethod.SelectedValue.EnumValue.HasFlag(PeaceAndWarConsideration.TributeFactor) ? CalculateTributeFactor(decisionMaker, declareWarDecision.FactionToDeclareWarOn) * Settings.Instance.DeclareWarTributeFactorStrength : 0; return(FieldAccessHelper.ShouldWarBeDeclaredByRef(possibleOutcome) ? traitScore - relationshipFactorValue + tributeFactorValue : -traitScore + relationshipFactorValue - tributeFactorValue); }
//GetSupportScoreOfDecisionMaker internal - per decision type private double GetSupportScoreOfDecisionMaker(DecisionMaker decisionMaker, MakePeaceKingdomDecision makePeaceDecision, DecisionOutcome possibleOutcome) { double traitScore = decisionMaker.Hero.GetTraitLevel(DefaultTraits.Mercy) * 10; double relationshipFactorValue = Settings.Instance.PeaceSupportCalculationMethod.SelectedValue.EnumValue.HasFlag(PeaceAndWarConsideration.RelationshipFactor) ? CalculateRelationshipFactor(decisionMaker, makePeaceDecision.FactionToMakePeaceWith) * Settings.Instance.MakePeaceRelationshipFactorStrength : 0; double tributeFactorValue = Settings.Instance.PeaceSupportCalculationMethod.SelectedValue.EnumValue.HasFlag(PeaceAndWarConsideration.TributeFactor) ? CalculateTributeFactor(decisionMaker, makePeaceDecision.FactionToMakePeaceWith, makePeaceDecision.DailyTributeToBePaid) * Settings.Instance.MakePeaceTributeFactorStrength : 0; return(FieldAccessHelper.ShouldPeaceBeDeclaredByRef(possibleOutcome) ? traitScore + relationshipFactorValue - tributeFactorValue : -traitScore - relationshipFactorValue + tributeFactorValue); }
public virtual void ReadProcessData(XmlElement xmlElement, ProcessDefinitionBuildContext creationContext) { String attributeName = xmlElement.GetProperty("attribute"); creationContext.Check(((Object)attributeName != null), "attribute is a required property in element field : " + xmlElement); log.Debug("parsing field for attribute '" + attributeName); creationContext.AddUnresolvedReference(this, attributeName, creationContext.ProcessBlock, "attribute", typeof(IAttribute)); this._state = creationContext.State; String accessText = xmlElement.GetProperty("access"); creationContext.Check(((Object)accessText != null), "access is a required property in element field : " + xmlElement); this._access = FieldAccessHelper.fromText(accessText); }
//private const String queryFieldsByState = "select f from f in class NetBpm.Workflow.Definition.Impl.FieldImpl " + // "where f.State.Id = ? " + // "order by f.Index"; public IActivityForm GetStartForm(String authenticatedActorId, Int64 processDefinitionId, DbSession dbSession, IOrganisationService organisationComponent) { IActivityForm activityForm = null; // First check if the actor is allowed to get this form authorizationHelper.CheckGetStartForm(authenticatedActorId, processDefinitionId, dbSession); ProcessDefinitionImpl processDefinition = (ProcessDefinitionImpl)dbSession.Load(typeof(ProcessDefinitionImpl), processDefinitionId); StartStateImpl startState = (StartStateImpl)processDefinition.StartState; // create a convenient map from the attribute-names to the fields IList fields = fieldRepository.FindFieldsByState(startState.Id, dbSession); IDictionary attributeValues = new Hashtable(); IEnumerator iter = fields.GetEnumerator(); while (iter.MoveNext()) { FieldImpl field = (FieldImpl)iter.Current; // if the attribute has an initial value AttributeImpl attribute = (AttributeImpl)field.Attribute; String attributeName = attribute.Name; String initialValue = attribute.InitialValue; if ((Object)initialValue != null && (FieldAccessHelper.IsReadable(field.Access) || FieldAccessHelper.IsWritable(field.Access))) { // start form contains only fields that are readable or writable // get it and store it in the attributeValues AttributeInstanceImpl attributeInstance = new AttributeInstanceImpl(); attributeInstance.Attribute = attribute; attributeInstance.ValueText = initialValue; attributeValues[attributeName] = attributeInstance.GetValue(); } } activityForm = new ActivityFormImpl(processDefinition, fields, attributeValues); return(activityForm); }
//CalculateNativeForSettlementClaimantDecision private double CalculateNativeForSettlementClaimantDecision(DecisionMaker decisionMaker, SettlementClaimantDecision claimantDecision, DecisionOutcome possibleOutcome) { float initialMeritScore = possibleOutcome.InitialMerit * MathF.Clamp(1f + decisionMaker.Hero.GetTraitLevel(DefaultTraits.Honor), 0f, 2f); float basicScoreForOutcome; int calculatingTraitLevel = MBMath.ClampInt(decisionMaker.Hero.GetTraitLevel(DefaultTraits.Calculating), -2, 2); bool outcomeIsClanOfDM = FieldAccessHelper.ClanAsDecisionOutcomeByRef(possibleOutcome) == decisionMaker.Hero.Clan; if (outcomeIsClanOfDM) { float settlementValueForFaction = claimantDecision.Settlement.GetSettlementValueForFaction(decisionMaker.Hero.Clan); basicScoreForOutcome = initialMeritScore + 0.2f * settlementValueForFaction * Campaign.Current.Models.DiplomacyModel.DenarsToInfluence(); } else { float relationBetweenClans = !outcomeIsClanOfDM?FactionManager.GetRelationBetweenClans(FieldAccessHelper.ClanAsDecisionOutcomeByRef(possibleOutcome), decisionMaker.Hero.Clan) : 100f; basicScoreForOutcome = initialMeritScore * MathF.Clamp(1f + calculatingTraitLevel, 0f, 2f) + relationBetweenClans * 0.2f * calculatingTraitLevel; } double calculatingModifier = (1.0 - (calculatingTraitLevel > 0 ? 0.4 - Math.Min(2f, calculatingTraitLevel) * 0.1 : 0.4 + Math.Min(2f, Math.Abs(calculatingTraitLevel)) * 0.1) * 1.5); return(basicScoreForOutcome * calculatingModifier * (outcomeIsClanOfDM ? 2f : 1f)); }
public static void Postfix(Clan clan, DecisionOutcome possibleOutcome, ref float __result, MakePeaceKingdomDecision __instance) { try { float newResult = Campaign.Current.GetAOGameModels().DecisionSupportScoringModel.DetermineSupport(clan, __instance, possibleOutcome); if (SettingsHelper.SystemDebugEnabled(AOSystems.PoliticsRebalance, DebugType.Technical, clan)) { MessageHelper.TechnicalMessage(string.Format("Support of {0} for {1} making peace with {2}.\nNative result = {3}. Rebalanced result = {4}", clan.Name, FieldAccessHelper.ShouldPeaceBeDeclaredByRef(possibleOutcome) ? "accepting" : "denying", __instance.FactionToMakePeaceWith, __result, newResult)); } if (SettingsHelper.SubSystemEnabled(SubSystemType.MakePeaceSupportRebalance, clan)) { __result = newResult; } } catch (Exception ex) { MethodInfo methodInfo = MethodBase.GetCurrentMethod() as MethodInfo; DebugHelper.HandleException(ex, methodInfo, "Harmony patch for MakePeaceKingdomDecision. DetermineSupport"); } }
public IActivityForm GetActivityForm(String authenticatedActorId, Int64 flowId, DbSession dbSession, IOrganisationService organisationComponent) { IActivityForm activityForm = null; // First check if the actor is allowed to get this form authorizationHelper.CheckGetActivityForm(authenticatedActorId, flowId, dbSession); FlowImpl flow = (FlowImpl)dbSession.Load(typeof(FlowImpl), flowId); StateImpl state = (StateImpl)flow.Node; // create an executionContext for easy attributeValue retrieval ExecutionContextImpl executionContext = new ExecutionContextImpl(null, flow, dbSession, organisationComponent); // create a convenient map from the attribute-names to the fields IList fields = fieldRepository.FindFieldsByState(state.Id, dbSession); IDictionary attributeValues = new Hashtable(); IEnumerator iter = fields.GetEnumerator(); while (iter.MoveNext()) { FieldImpl field = (FieldImpl)iter.Current; if (FieldAccessHelper.IsReadable(field.Access) || FieldAccessHelper.IsWritable(field.Access)) { // activity form contains only readable or writeable fields String attributeName = field.Attribute.Name; if (executionContext.GetAttribute(attributeName) != null) { // attribute might not exist (this will cause a warning already being logged previusly) attributeValues[attributeName] = executionContext.GetAttribute(attributeName); } } } activityForm = new ActivityFormImpl(flow, fields, attributeValues); return(activityForm); }
public void CheckAccess(IDictionary attributeValues, StateImpl state) { IDictionary fields = new Hashtable(); // first we check if a value is supplied for all required fields IEnumerator iter = state.Fields.GetEnumerator(); log.Debug(iter); while (iter.MoveNext()) { FieldImpl field = (FieldImpl)iter.Current; String attributeName = field.Attribute.Name; fields[attributeName] = field; // if a field is found required and no attribute value is supplied throw // RequiredFieldException log.Debug(field); log.Debug(field.Access); if ((FieldAccessHelper.IsRequired(field.Access)) && (attributeValues == null)) { throw new RequiredFieldException(field); } // OR // if field is found required and attribute value of it is not available // throw RequiredFieldException if ((FieldAccessHelper.IsRequired(field.Access)) && (attributeValues != null) && (!attributeValues.Contains(attributeName))) { throw new RequiredFieldException(field); } } // then we check if the access of all supplied values is writable IList attributeNamesToBeRemoved = new ArrayList(); // store attribute name of attribute to be removed if (attributeValues != null) { iter = attributeValues.GetEnumerator(); while (iter.MoveNext()) { DictionaryEntry entry = (DictionaryEntry)iter.Current; String attributeName = (String)entry.Key; FieldImpl field = (FieldImpl)fields[attributeName]; if ((field != null) && (!FieldAccessHelper.IsWritable(field.Access))) { log.Warn("ignoring attributeValue for unwritable attribute '" + attributeName + "'"); // commented out cause will result in ConcurrentModificationException // instead copy its attribute name and remove later OR do a deep copy of the // attributeValues so there is one set that gets iterated and another that //gets deleted??? //attributeValues.remove( attributeName ); attributeNamesToBeRemoved.Add(attributeName); } } // now removed collected to be removed attribute IEnumerator itr = attributeNamesToBeRemoved.GetEnumerator(); while (itr.MoveNext()) { String an = (String)itr.Current; attributeValues.Remove(an); } } }
public ActionResult ActivityForm(string aa) { IDictionary userInputFields = new Hashtable(); IActivityForm activityForm = (IActivityForm)HttpContext.Session["activityForm"]; IList fields = activityForm.Fields; IEnumerator fildEnumer = fields.GetEnumerator(); while (fildEnumer.MoveNext()) { IField field = (IField)fildEnumer.Current; // Construct a meaningfull name that is http-compliant String attributeName = field.Attribute.Name; String parameterName = convertToHttpCompliant(attributeName); String parameterValue = HttpContext.Request.Params[parameterName]; if (FieldAccessHelper.IsRequired(field.Access) && (parameterValue == null || "".Equals(parameterValue))) { //AddMessage("Field "+field.Name+" is required. Please, provide a value"); } else { try { Object parsedParameter = null; IHtmlFormatter htmlFormatter = field.GetHtmlFormatter(); if (htmlFormatter != null) { // TODO: Test if there is the possibility to simplify the interface, see null parsedParameter = htmlFormatter.ParseHttpParameter(parameterValue, null); if (parsedParameter != null) { userInputFields.Add(attributeName, parsedParameter); } } else { //log.Warn("No htmlformatter defined for field:"+field.Name); } } catch (Exception ex) { //log.Debug( "error parsing user-input-field " + field.Name + " : " + parameterValue,ex); //AddMessage("error parsing user-input-field " + field.Name + " with value: " + parameterValue); } } } if (false) { //log.Debug( "submitted activity-form has messages, redirecting to activityFormPage..." ); HttpContext.Session.Add("userInputFields", userInputFields); if (activityForm.Flow == null) { return(RedirectToAction("ActivityForm", "Form", new RouteValueDictionary() { { "flowId", activityForm.ProcessDefinition.Id } })); //StartProcessInstance(activityForm.ProcessDefinition.Id); } else { return(RedirectToAction("ActivityForm", "Form", new RouteValueDictionary())); //ShowActivityForm(activityForm.Flow.Id); } } else { // remove the old inputvalues HttpContext.Session.Remove("userInputFields"); //log.Debug( "submitting the form..." ); IList activatedFlows = null; IFlow flow = activityForm.Flow; // if there is no flow in the activityForm IExecutionSessionLocal executionComponent = null; try { executionComponent = ServiceLocator.Instance.GetService(typeof(IExecutionSessionLocal)) as IExecutionSessionLocal; if (flow == null) { // this means that it is a start-activity being performed so we have to // start a new process instance IProcessDefinition processDefinition = activityForm.ProcessDefinition; IProcessInstance processInstance = executionComponent.StartProcessInstance(processDefinition.Id, userInputFields); activatedFlows = new ArrayList(); //AddAllActiveFlows(processInstance.RootFlow,activatedFlows); //activatedFlows.Add(processInstance.RootFlow); } else { activatedFlows = executionComponent.PerformActivity(flow.Id, userInputFields); } } finally { ServiceLocator.Instance.Release(executionComponent); } if (activatedFlows.Count > 0) { System.Text.StringBuilder feedbackBuffer = new System.Text.StringBuilder(); for (int i = 0; i < activatedFlows.Count; ++i) { IFlow activatedFlow = (IFlow)activatedFlows[i]; if (activatedFlow.GetActor() != null) { feedbackBuffer.Append(activatedFlow.GetActor().Name); } else { // when flow's node is start-state no actor is assigned to it, this is to handle the NPE thrown feedbackBuffer.Append("Nobody"); } if (i + 1 < activatedFlows.Count) { feedbackBuffer.Append(", "); } } if (activatedFlows.Count > 1) { //AddMessage("Now, following people are handling this process :"+feedbackBuffer.ToString()); } else { //AddMessage("Now, "+ feedbackBuffer.ToString() +" is handling this process"); } return(Redirect("/User/ShowHome")); } else { //AddMessage("This flow in the process finished"); return(Redirect("/User/ShowHome")); } } }
public bool IsRequired() { return(FieldAccessHelper.IsRequired(_field.Access)); }