public static Expression DataExpression(FactionTechDB factionTechs, TechSD tech) { string stringExpression = tech.DataFormula; Expression expression = new Expression(stringExpression); expression.Parameters.Add("Level", (double)factionTechs.LevelforTech(tech)); return(expression); }
/// <summary> /// adds research points to a scientists project. /// </summary> /// <param name="entity"></param> /// <param name="factionAbilities"></param> /// <param name="factionTechs"></param> internal void DoResearch(Entity entity) { Entity faction; entity.Manager.FindEntityByGuid(entity.FactionOwner, out faction); FactionAbilitiesDB factionAbilities = faction.GetDataBlob <FactionAbilitiesDB>(); FactionTechDB factionTechs = faction.GetDataBlob <FactionTechDB>(); Dictionary <Entity, int> labs = new Dictionary <Entity, int>(); //TODO: why am I doing this here instead of as a recalc. //foreach (var lab in entity.GetDataBlob<ComponentInstancesDB>().ComponentsByDesign.Keys.Where(inst => inst.HasDataBlob<ResearchPointsAtbDB>())) //{ // int points = lab.GetDataBlob<ResearchPointsAtbDB>().PointsPerEconTick; // labs.Add(lab, points); //} foreach (var scientist in entity.GetDataBlob <ColonyInfoDB>().Scientists) { var scientistDB = scientist.GetDataBlob <ScientistDB>(); if (scientistDB.ProjectQueue.Count == 0) { continue; } //(TechSD)scientist.GetDataBlob<TeamsDB>().TeamTask; Guid projectGuid = scientist.GetDataBlob <ScientistDB>().ProjectQueue[0]; TechSD project = Techs[projectGuid];//_staticData.Techs[projectGuid]; int numProjectLabs = scientist.GetDataBlob <TeamsDB>().TeamSize; float bonus = scientist.GetDataBlob <ScientistDB>().Bonuses[project.Category]; //bonus *= BonusesForType(factionEntity, colonyEntity, InstallationAbilityType.Research); int researchmax = CostFormula(factionTechs, project); int researchPoints = 0; foreach (var kvp in labs) { while (numProjectLabs > 0) { researchPoints += kvp.Value; numProjectLabs--; } } researchPoints = (int)(researchPoints * bonus); if (factionTechs.ResearchableTechs.ContainsKey(project)) { factionTechs.ResearchableTechs[project] += researchPoints; if (factionTechs.ResearchableTechs[project] >= researchmax) { ApplyTech(factionTechs, project); //apply effects from tech, and add it to researched techs scientist.GetDataBlob <TeamsDB>().TeamTask = null; //team task is now nothing. } } } }
/// <summary> /// adds research points to a scientists project. /// </summary> /// <param name="colonyEntity"></param> /// <param name="factionAbilities"></param> /// <param name="factionTechs"></param> internal static void DoResearch(Entity colonyEntity, Game game) { var Faction = colonyEntity.GetDataBlob <OwnedDB>().ObjectOwner; FactionAbilitiesDB factionAbilities = Faction.GetDataBlob <FactionAbilitiesDB>(); FactionTechDB factionTechs = Faction.GetDataBlob <FactionTechDB>(); Dictionary <Entity, int> labs = new Dictionary <Entity, int>(); //why am I doing this here instead of as a recalc. foreach (var lab in colonyEntity.GetDataBlob <ComponentInstancesDB>().SpecificInstances.Keys.Where(inst => inst.HasDataBlob <ResearchPointsAtbDB>())) { int points = lab.GetDataBlob <ResearchPointsAtbDB>().PointsPerEconTick; labs.Add(lab, points); } int labsused = 0; foreach (var scientist in colonyEntity.GetDataBlob <ColonyInfoDB>().Scientists) { var scientistDB = scientist.GetDataBlob <ScientistDB>(); if (scientistDB.ProjectQueue.Count == 0) { continue; } //(TechSD)scientist.GetDataBlob<TeamsDB>().TeamTask; Guid projectGuid = scientist.GetDataBlob <ScientistDB>().ProjectQueue[0]; TechSD project = game.StaticData.Techs[projectGuid]; int numProjectLabs = scientist.GetDataBlob <TeamsDB>().TeamSize; float bonus = scientist.GetDataBlob <ScientistDB>().Bonuses[project.Category]; //bonus *= BonusesForType(factionEntity, colonyEntity, InstallationAbilityType.Research); int researchmax = CostFormula(factionTechs, project); int researchPoints = 0; foreach (var kvp in labs) { while (numProjectLabs > 0) { researchPoints += kvp.Value; numProjectLabs--; } } researchPoints = (int)(researchPoints * bonus); if (factionTechs.ResearchableTechs.ContainsKey(project)) { factionTechs.ResearchableTechs[project] += researchPoints; if (factionTechs.ResearchableTechs[project] >= researchmax) { ApplyTech(factionTechs, project); //apply effects from tech, and add it to researched techs scientist.GetDataBlob <TeamsDB>().TeamTask = null; //team task is now nothing. } } } }
public int LevelforTech(TechSD techSD) { if (ResearchedTechs.ContainsKey(techSD.ID)) { return(ResearchedTechs[techSD.ID]); } else { return(0); } }
public static int CostFormula(FactionTechDB factionTechs, TechSD tech) { string stringExpression = tech.CostFormula; Expression expression = new Expression(stringExpression); expression.Parameters.Add("Level", factionTechs.LevelforTech(tech)); int result = (int)expression.Evaluate(); return(result); }
public static double DataFormula(FactionTechDB factionTechs, TechSD tech) { string stringExpression = tech.DataFormula; Expression expression = new Expression(stringExpression); expression.Parameters.Add("Level", (double)factionTechs.LevelforTech(tech)); object result = expression.Evaluate(); if (result is int) { return((double)(int)result); } return((double)result); }
public ComponentAbilityDesignVM(ComponentDesignVM designVM, ComponentDesignAttribute designAbility, StaticDataStore staticData) { _designAbility = designAbility; _staticData = staticData; _parentDesignVM = designVM; switch (designAbility.GuiHint) { case GuiHint.GuiTechSelectionList: foreach (var kvp in designAbility.GuidDictionary) { TechSD sd = _staticData.Techs[Guid.Parse((string)kvp.Key)]; TechList.Add(sd, sd.Name); } TechList.SelectedIndex = 0; TechList.SelectionChangedEvent += TechList_SelectionChangedEvent; break; case GuiHint.GuiSelectionMaxMin: { minMaxSliderVM = new MinMaxSliderVM(); designAbility.SetMax(); designAbility.SetMin(); designAbility.SetValue(); designAbility.SetStep(); minMaxSliderVM.Name = Name; minMaxSliderVM.MaxValue = MaxValue; minMaxSliderVM.MinValue = MinValue; minMaxSliderVM.StepValue = StepValue; minMaxSliderVM.Value = Value; //.PreLoadedValue = Value; //hack due to eto bug. MinMaxSlider.Value = Value; minMaxSliderVM.PropertyChanged += MinMaxSlider_PropertyChanged; } break; } }
public ResearchTechControlVM(FactionTechDB factionTech, Guid techID) { _factionTech = factionTech; _techSD = factionTech.ResearchableTechs.Keys.First(k => k.ID == techID); }
/// <summary> /// takes a ComponentSD staticData and turns it into a DesignDB /// </summary> /// <param name="component">the componentSD</param> /// <param name="factionTech">this factions TechDB</param> /// <param name="staticData">the game staticData</param> /// <returns></returns> public static ComponentDesign StaticToDesign(ComponentTemplateSD component, FactionTechDB factionTech, StaticDataStore staticData) { ComponentDesign design = new ComponentDesign(); design.RawName = component.Name; design.Name = component.Name; design.Description = component.Description; design.MassFormula = new ChainedExpression(component.MassFormula, design, factionTech, staticData); design.VolumeFormula = new ChainedExpression(component.VolumeFormula, design, factionTech, staticData); design.CrewFormula = new ChainedExpression(component.CrewReqFormula, design, factionTech, staticData); design.HTKFormula = new ChainedExpression(component.HTKFormula, design, factionTech, staticData); design.ResearchCostFormula = new ChainedExpression(component.ResearchCostFormula, design, factionTech, staticData); design.BuildCostFormula = new ChainedExpression(component.BuildPointCostFormula, design, factionTech, staticData); design.MineralCostFormulas = new Dictionary <Guid, ChainedExpression>(); design.CreditCostFormula = new ChainedExpression(component.CreditCostFormula, design, factionTech, staticData); design.ComponentMountType = component.MountType; design.ConstructionType = component.ConstructionType; design.CargoTypeID = component.CargoTypeID; foreach (var kvp in component.MineralCostFormula) { design.MineralCostFormulas.Add(kvp.Key, new ChainedExpression(kvp.Value, design, factionTech, staticData)); } design.ComponentDesignAttributes = new List <ComponentDesignAttribute>(); foreach (var abilitySD in component.ComponentAbilitySDs) { ComponentDesignAttribute designAttribute = new ComponentDesignAttribute(design); designAttribute.Name = abilitySD.Name; designAttribute.Description = abilitySD.Description; designAttribute.GuiHint = abilitySD.GuiHint; if (abilitySD.AbilityFormula != null) { designAttribute.Formula = new ChainedExpression(abilitySD.AbilityFormula, designAttribute, factionTech, staticData); } if (abilitySD.GuidDictionary != null) { designAttribute.GuidDictionary = new Dictionary <object, ChainedExpression>(); if (designAttribute.GuiHint == GuiHint.GuiTechSelectionList) { foreach (var kvp in abilitySD.GuidDictionary) { if (factionTech.ResearchedTechs.ContainsKey(Guid.Parse(kvp.Key.ToString()))) { TechSD techSD = staticData.Techs[Guid.Parse(kvp.Key.ToString())]; designAttribute.GuidDictionary.Add(kvp.Key, new ChainedExpression(ResearchProcessor.DataFormula(factionTech, techSD).ToString(), designAttribute, factionTech, staticData)); } } } else { foreach (var kvp in abilitySD.GuidDictionary) { designAttribute.GuidDictionary.Add(kvp.Key, new ChainedExpression(kvp.Value, designAttribute, factionTech, staticData)); } } } if (designAttribute.GuiHint == GuiHint.GuiSelectionMaxMin) { designAttribute.MaxValueFormula = new ChainedExpression(abilitySD.MaxFormula, designAttribute, factionTech, staticData); designAttribute.MinValueFormula = new ChainedExpression(abilitySD.MinFormula, designAttribute, factionTech, staticData); designAttribute.StepValueFormula = new ChainedExpression(abilitySD.StepFormula, designAttribute, factionTech, staticData); } if (abilitySD.AbilityDataBlobType != null) { designAttribute.DataBlobType = Type.GetType(abilitySD.AbilityDataBlobType); } design.ComponentDesignAttributes.Add(designAttribute); } design.MassFormula.Evaluate(); design.SetCrew(); design.SetHTK(); design.SetResearchCost(); design.SetBuildCost(); design.SetMineralCosts(); return(design); }
/// <summary> /// Creates Entity and blobs. /// </summary> /// <param name="globalEntityManager"></param> /// <param name="componentDesign"></param> /// <param name="factionTech"></param> /// <returns></returns> public static Entity DesignToDesignEntity(Game game, Entity factionEntity, ComponentDesign componentDesign) { EntityManager globalEntityManager = game.GlobalManager; StaticDataStore staticData = game.StaticData; FactionTechDB factionTech = factionEntity.GetDataBlob <FactionTechDB>(); FactionInfoDB faction = factionEntity.GetDataBlob <FactionInfoDB>(); //TODO probilby do checking to see if valid here? Entity component = new Entity(globalEntityManager, factionEntity); TechSD tech = new TechSD(); tech.ID = Guid.NewGuid(); tech.Name = componentDesign.Name + " Design Research"; tech.Description = "Research into building " + componentDesign.Name; tech.MaxLevel = 1; tech.CostFormula = componentDesign.ResearchCostValue.ToString(); factionTech.ResearchableTechs.Add(tech, 0); NameDB nameDB = new NameDB(componentDesign.RawName); nameDB.SetName(factionEntity.Guid, componentDesign.Name); Dictionary <Guid, int> mineralCosts = new Dictionary <Guid, int>(); Dictionary <Guid, int> materalCosts = new Dictionary <Guid, int>(); Dictionary <Guid, int> componentCosts = new Dictionary <Guid, int>(); foreach (var kvp in componentDesign.MineralCostValues) { if (staticData.CargoGoods.IsMaterial(kvp.Key)) { materalCosts.Add(kvp.Key, kvp.Value); } else if (staticData.ComponentTemplates.ContainsKey(kvp.Key)) { componentCosts.Add(kvp.Key, kvp.Value); } else if (staticData.CargoGoods.IsMineral(kvp.Key)) { mineralCosts.Add(kvp.Key, kvp.Value); } else { throw new Exception("GUID object {" + kvp.Key + "} not found in materialCosting for " + componentDesign.Name + " This object needs to be either a mineral, material or component defined in the Data folder"); } } ComponentInfoDB componentInfo = new ComponentInfoDB(component.Guid, componentDesign.MassValue, componentDesign.HTKValue, componentDesign.BuildCostValue, mineralCosts, materalCosts, componentCosts, tech.ID, componentDesign.CrewReqValue); componentInfo.ComponentMountType = componentDesign.ComponentMountType; componentInfo.ConstructionType = componentDesign.ConstructionType; CargoAbleTypeDB cargoType = new CargoAbleTypeDB(componentDesign.CargoTypeID); component.SetDataBlob(componentInfo); component.SetDataBlob(nameDB); component.SetDataBlob(cargoType); //note: MassVolumeDB stores mass in kg and volume in km^3, however we use kg and m^3 in the json data. component.SetDataBlob(MassVolumeDB.NewFromMassAndVolume(componentDesign.MassValue, componentDesign.VolumeValue * 1e-9)); foreach (var designAttribute in componentDesign.ComponentDesignAttributes) { if (designAttribute.DataBlobType != null) { if (designAttribute.DataBlobArgs == null) { designAttribute.SetValue(); //force recalc. } object[] constructorArgs = designAttribute.DataBlobArgs; dynamic datablob = (BaseDataBlob)Activator.CreateInstance(designAttribute.DataBlobType, constructorArgs); component.SetDataBlob(datablob); if (datablob is IComponentDesignAttribute) { componentInfo.DesignAttributes.Add(datablob); } } } faction.InternalComponentDesigns.Add(component.Guid, component); return(component); }
/// <summary> /// extra custom functinos go in here. /// </summary> /// <param name="name"></param> /// <param name="args"></param> private void NCalcPulsarFunctions(string name, FunctionArgs args) { if (name == "Ability") { int index = 0; try { index = (int)args.Parameters[0].Evaluate(); ChainedExpression result = _design.ComponentDesignAbilities[index].Formula; if (result.Result == null) { result.Evaluate(); } MakeThisDependant(result); args.Result = result.Result; } catch (InvalidCastException e) { throw new Exception("Parameter must be an intiger. " + e); } catch (IndexOutOfRangeException e) { throw new Exception("This component does not have an ComponentAbilitySD at index " + index + ". " + e); } } if (name == "SetAbilityValue") //I might remove this.. { int index = 0; try { index = (int)args.Parameters[0].Evaluate(); ChainedExpression expression = _design.ComponentDesignAbilities[index].Formula; expression.SetResult = args.Parameters[1].Evaluate(); } catch (InvalidCastException e) { throw new Exception("Parameter must be an intiger. " + e); } catch (IndexOutOfRangeException e) { throw new Exception("This component does not have an ComponentAbilitySD at index " + index + ". " + e); } } if (name == "EnumDict") { string typeAsString = (string)args.Parameters[0].Evaluate(); Type type = Type.GetType(typeAsString); Type dictType = typeof(Dictionary <,>).MakeGenericType(type, typeof(double)); dynamic dict = Activator.CreateInstance(dictType); Type enumDictType = typeof(Dictionary <,>).MakeGenericType(typeof(string), type); dynamic enumConstants = Activator.CreateInstance(enumDictType); foreach (dynamic value in Enum.GetValues(type)) { enumConstants.Add(Enum.GetName(type, value), value); } foreach (var kvp in _designAbility.GuidDictionary) { dynamic key = enumConstants[(string)kvp.Key]; dict.Add(key, kvp.Value.DResult); } args.Result = dict; } if (name == "TechData") { Guid techGuid = Guid.Parse((string)args.EvaluateParameters()[0]); TechSD techSD = _staticDataStore.Techs[techGuid]; args.Result = TechProcessor.DataFormula(_factionTechDB, techSD); } //Returns the tech level for the given guid if (name == "TechLevel") { Guid techGuid = Guid.Parse((string)args.EvaluateParameters()[0]); if (_factionTechDB.ResearchedTechs.ContainsKey(techGuid)) { args.Result = _factionTechDB.ResearchedTechs[techGuid]; } else { args.Result = 0; } } //currently not used, but an future experiment to pass the CargoTypeSD as a parameter if (name == "CargoType") { Guid typeGuid = Guid.Parse((string)args.EvaluateParameters()[0]); CargoTypeSD typeSD = _staticDataStore.CargoTypes[typeGuid]; args.Result = typeSD; } //used for datablob args for when a guid is required as a parameter if (name == "GuidString") { Guid typeGuid = Guid.Parse((string)args.EvaluateParameters()[0]); args.Result = typeGuid; } //This sets the DatablobArgs. it's up to the user to ensure the right number of args for a specific datablob //The datablob will be the one defined in designAbility.DataBlobType //TODO document blobs and what args they take!! if (name == "DataBlobArgs") { if (_designAbility.DataBlobType == null) { throw new Exception("This Ability does not have a DataBlob defined! define a datablob for this ability!"); } //_designAbility.DataBlobArgs = new List<double>(); List <object> argList = new List <object>(); foreach (var argParam in args.Parameters) { ChainedExpression argExpression = new ChainedExpression(argParam, _designAbility, _factionTechDB, _staticDataStore); _isDependant = false; argExpression.Evaluate(); argList.Add(argExpression.Result); } _designAbility.DataBlobArgs = argList.ToArray(); args.Result = argList; } }
/// <summary> /// extra custom functinos go in here. /// </summary> /// <param name="name"></param> /// <param name="args"></param> private void NCalcPulsarFunctions(string name, FunctionArgs args) { string key = "Unknown Key"; int index = -1; Guid techGuid; Guid typeGuid; switch (name) { case "Ability": try { //TODO: get rid of this once json data is rewritten to use names instead of indexes if (args.Parameters[0].Evaluate() is int) { index = (int)args.Parameters[0].Evaluate(); ChainedExpression result = _designer.ComponentDesignAttributeList[index].Formula; if (result.Result == null) { result.Evaluate(); } MakeThisDependant(result); args.Result = result.Result; } else { key = (string)args.Parameters[0].Evaluate(); ChainedExpression result = _designer.ComponentDesignAttributes[key].Formula; if (result.Result == null) { result.Evaluate(); } MakeThisDependant(result); args.Result = result.Result; } } //TODO: maybe log this catch and throw the component out. (instead of throwing) catch (KeyNotFoundException e) { throw new Exception("Cannot find an ability named " + key + ", in " + _designer.Name + " " + e); } //TODO: the two catches below will be unnesiary once ComponentDesignAttributeList is gone. catch (InvalidCastException e) { throw new Exception("Parameter must be an intiger. " + e); } catch (IndexOutOfRangeException e) { throw new Exception("This component does not have an ComponentAbilitySD at index " + index + ". " + e); } break; case "SetAbilityValue": //I might remove this.. try { //TODO: get rid of this once json data is rewritten to use names instead of indexes if (args.Parameters[0].Evaluate() is int) { index = (int)args.Parameters[0].Evaluate(); ChainedExpression expression = _designer.ComponentDesignAttributeList[index].Formula; expression.SetResult = args.Parameters[1].Evaluate(); } else { key = (string)args.Parameters[0].Evaluate(); ChainedExpression expression = _designer.ComponentDesignAttributes[key].Formula; expression.SetResult = args.Parameters[1].Evaluate(); } } //TODO: maybe log this catch and throw the component out. (instead of throwing) catch (KeyNotFoundException e) { throw new Exception("Cannot find an ability named " + key + ". " + e); } //TODO: the two catches below will be unnesiary once ComponentDesignAttributeList is gone. catch (InvalidCastException e) { throw new Exception("Parameter must be an intiger. " + e); } catch (IndexOutOfRangeException e) { throw new Exception("This component does not have an ComponentAbilitySD at index " + index + ". " + e); } break; case "EnumDict": string typeAsString = (string)args.Parameters[0].Evaluate(); Type type = Type.GetType(typeAsString); if (type == null) { throw new Exception("Type not found: " + typeAsString + " Check spelling and namespaces"); } Type dictType = typeof(Dictionary <,>).MakeGenericType(type, typeof(double)); dynamic dict = Activator.CreateInstance(dictType); Type enumDictType = typeof(Dictionary <,>).MakeGenericType(typeof(string), type); dynamic enumConstants = Activator.CreateInstance(enumDictType); foreach (dynamic value in Enum.GetValues(type)) { enumConstants.Add(Enum.GetName(type, value), value); } foreach (var kvp in _designAttribute.GuidDictionary) { dynamic keyd = enumConstants[(string)kvp.Key]; dict.Add(keyd, kvp.Value.DResult); } args.Result = dict; break; case "TechData": techGuid = Guid.Parse((string)args.EvaluateParameters()[0]); TechSD techSD = _staticDataStore.Techs[techGuid]; args.Result = ResearchProcessor.DataFormula(_factionTechDB, techSD); break; //Returns the tech level for the given guid case "TechLevel": techGuid = Guid.Parse((string)args.EvaluateParameters()[0]); if (_factionTechDB.ResearchedTechs.ContainsKey(techGuid)) { args.Result = _factionTechDB.ResearchedTechs[techGuid]; } else { args.Result = 0; } break; //currently not used, but an future experiment to pass the CargoTypeSD as a parameter case "CargoType": typeGuid = Guid.Parse((string)args.EvaluateParameters()[0]); CargoTypeSD typeSD = _staticDataStore.CargoTypes[typeGuid]; args.Result = typeSD; break; //used for datablob args for when a guid is required as a parameter case "GuidString": typeGuid = Guid.Parse((string)args.EvaluateParameters()[0]); args.Result = typeGuid; break; //This sets the DatablobArgs. it's up to the user to ensure the right number of args for a specific datablob //The datablob will be the one defined in designAbility.AttributeType //TODO document blobs and what args they take!! case "AtbConstrArgs": if (_designAttribute.AttributeType == null) { throw new Exception(_designAttribute.Name + " does not have a type defined! define an AttributeType for this Attribute!"); } //_designAbility.AtbConstrArgs = new List<double>(); List <object> argList = new List <object>(); foreach (var argParam in args.Parameters) { ChainedExpression argExpression = new ChainedExpression(argParam, _designAttribute, _factionTechDB, _staticDataStore); _isDependant = false; argExpression.Evaluate(); argList.Add(argExpression.Result); } _designAttribute.AtbConstrArgs = argList.ToArray(); args.Result = argList; break; } }
public ComponentDesignAttribute(ComponentDesigner parentComponent, ComponentTemplateAttributeSD templateAtb, FactionTechDB factionTech) { ParentComponent = parentComponent; _templateSD = templateAtb; var staticData = StaticRefLib.StaticData; if (_templateSD.AttributeFormula != null) { Formula = new ChainedExpression(_templateSD.AttributeFormula, this, factionTech, staticData); } if (!string.IsNullOrEmpty(_templateSD.DescriptionFormula)) { DescriptionFormula = new ChainedExpression(_templateSD.DescriptionFormula, this, factionTech, staticData); } if (_templateSD.GuidDictionary != null) { GuidDictionary = new Dictionary <object, ChainedExpression>(); if (GuiHint == GuiHint.GuiTechSelectionList) { foreach (var kvp in _templateSD.GuidDictionary) { if (factionTech.ResearchedTechs.ContainsKey(Guid.Parse(kvp.Key.ToString()))) { TechSD techSD = staticData.Techs[Guid.Parse(kvp.Key.ToString())]; GuidDictionary.Add(kvp.Key, new ChainedExpression(ResearchProcessor.DataFormula(factionTech, techSD).ToString(), this, factionTech, staticData)); } } } else { foreach (var kvp in _templateSD.GuidDictionary) { GuidDictionary.Add(kvp.Key, new ChainedExpression(kvp.Value, this, factionTech, staticData)); } } } if (GuiHint == GuiHint.GuiSelectionMaxMin) { MaxValueFormula = new ChainedExpression(_templateSD.MaxFormula, this, factionTech, staticData); MinValueFormula = new ChainedExpression(_templateSD.MinFormula, this, factionTech, staticData); StepValueFormula = new ChainedExpression(_templateSD.StepFormula, this, factionTech, staticData); } if (_templateSD.AttributeType != null) { AttributeType = Type.GetType(_templateSD.AttributeType); if (AttributeType == null) { throw new Exception("Attribute Type Error. Attribute type not found: " + _templateSD.AttributeType + ". Try checking the namespace."); } } if (GuiHint == GuiHint.GuiEnumSelectionList) { MaxValueFormula = new ChainedExpression(_templateSD.MaxFormula, this, factionTech, staticData); MinValueFormula = new ChainedExpression(_templateSD.MinFormula, this, factionTech, staticData); StepValueFormula = new ChainedExpression(_templateSD.StepFormula, this, factionTech, staticData); SetMax(); SetMin(); SetStep(); EnumType = Type.GetType(_templateSD.EnumTypeName); if (EnumType == null) { throw new Exception("EnumTypeName not found: " + _templateSD.EnumTypeName); } ListSelection = (int)Value; //string[] names = Enum.GetNames(EnumType); } if (_templateSD.GuiIsEnabledFormula != null) { IsEnabledFormula = new ChainedExpression(_templateSD.GuiIsEnabledFormula, this, factionTech, staticData); var ghint = GuiHint.GuiTextDisplay | GuiHint.GuiDisplayBool; } if (GuiHint == GuiHint.GuiOrdnanceSelectionList) { } }
public ResearchTechControlVM(FactionTechDB factionTech, Guid techID) { _factionTech = factionTech; _techSD = factionTech.GetResarchableTech(techID).tech; }
/// <summary> /// adds research points to a scientists project. /// </summary> /// <param name="entity"></param> /// <param name="factionAbilities"></param> /// <param name="factionTechs"></param> internal void DoResearch(Entity entity) { Entity faction; entity.Manager.FindEntityByGuid(entity.FactionOwner, out faction); FactionAbilitiesDB factionAbilities = faction.GetDataBlob <FactionAbilitiesDB>(); FactionTechDB factionTechs = faction.GetDataBlob <FactionTechDB>(); EntityResearchDB entityResearch = entity.GetDataBlob <EntityResearchDB>(); //Dictionary<ComponentInstance, int> labs = entityResearch.Labs; List <(ComponentInstance lab, int pnts)> allLabs = new List <(ComponentInstance lab, int pnts)>(); if (entity.GetDataBlob <ComponentInstancesDB>().TryGetComponentsByAttribute <ResearchPointsAtbDB>(out var labs)) { foreach (var labInstance in labs) { var points = labInstance.Design.GetAttribute <ResearchPointsAtbDB>().PointsPerEconTick; allLabs.Add((labInstance, points)); } } int labIndex = 0; int maxLabs = allLabs.Count; foreach (Scientist scientist in entity.GetDataBlob <TeamsHousedDB>().TeamsByType[TeamTypes.Science]) { if (scientist.ProjectQueue.Count == 0) { continue; } Guid projectGuid = scientist.ProjectQueue[0].techID; bool cycleProject = scientist.ProjectQueue[0].cycle; if (!factionTechs.IsResearchable(projectGuid)) { scientist.ProjectQueue.RemoveAt(0); continue; } int assignedLabs = scientist.AssignedLabs; //(TechSD)scientist.GetDataBlob<TeamsDB>().TeamTask; TechSD project = factionTechs.GetResarchableTech(projectGuid).tech;//_staticData.Techs[projectGuid]; //int numProjectLabs = scientist.TeamSize; float bonus = 1; if (scientist.Bonuses.ContainsKey(project.Category)) { bonus += scientist.Bonuses[project.Category]; } //bonus *= BonusesForType(factionEntity, colonyEntity, InstallationAbilityType.Research); int researchPoints = 0; var maxIndex = Math.Max(labIndex + assignedLabs, maxLabs); //shouldn't happen unless assigned labs is more than the labs availible. for (int i = labIndex; i < maxIndex; i++) { researchPoints += allLabs[i].pnts; } researchPoints = (int)(researchPoints * bonus); if (factionTechs.IsResearchable(project.ID)) { int currentLvl = factionTechs.GetLevelforTech(project); factionTechs.AddPoints(project.ID, researchPoints); if (factionTechs.GetLevelforTech(project) > currentLvl) { scientist.ProjectQueue.RemoveAt(0); if (cycleProject) { scientist.ProjectQueue.Add((project.ID, true)); } } } } }