示例#1
0
        public ScientistControlVM(StaticDataStore staticData, FactionTechDB factionTech, Entity scientist)
        {
            _staticData     = staticData;
            _factionTech    = factionTech;
            ScientistEntity = scientist;

            _projectQueue = new ObservableCollection <ResearchTechControlVM>();
            Refresh();
        }
示例#2
0
        /// <summary>
        /// "Set" and returns the designdata
        /// this also sets up a research item for the design,
        /// and adds it to the factions designs.
        /// </summary>
        /// <returns></returns>
        public ComponentDesign CreateDesign(Entity factionEntity)
        {
            FactionInfoDB faction = factionEntity.GetDataBlob <FactionInfoDB>();

            //set up the research
            FactionTechDB factionTech = factionEntity.GetDataBlob <FactionTechDB>();
            TechSD        tech        = new TechSD();

            tech.ID          = Guid.NewGuid();
            tech.Name        = _design.Name + " Design Research";
            tech.Description = "Research into building " + _design.Name;
            tech.MaxLevel    = 1;
            tech.CostFormula = _design.ResearchCostValue.ToString();


            _design.TechID = tech.ID;
            factionTech.MakeResearchable(tech); //add it to researchable techs
            EvalAll();
            foreach (var designAttribute in ComponentDesignAttributes.Values)
            {
                if (designAttribute.AttributeType != null && designAttribute.IsEnabled)
                {
                    if (designAttribute.AtbConstrArgs == null)
                    {
                        designAttribute.SetValue();  //force recalc.
                    }
                    object[] constructorArgs = designAttribute.AtbConstrArgs;
                    try
                    {
                        dynamic attrbute = (IComponentDesignAttribute)Activator.CreateInstance(designAttribute.AttributeType, constructorArgs);
                        _design.AttributesByType[attrbute.GetType()] = attrbute;
                    }
                    catch (MissingMethodException e)
                    {
                        string argTypes = "";
                        int    i        = 0;
                        foreach (var arg in constructorArgs)
                        {
                            argTypes += arg.GetType() + ": " + constructorArgs[i].ToString() + ",\n";

                            i++;
                        }

                        string exstr = "The Attribute: " + designAttribute.AttributeType + " was found, but the arguments did not match any constructors.\nThe given arguments are:\n"
                                       + argTypes
                                       + "The full exception is as follows:\n" + e;
                        throw new Exception(exstr);
                    }
                }
            }

            faction.InternalComponentDesigns[_design.ID] = _design;
            faction.IndustryDesigns[_design.ID]          = _design;
            return(_design);
        }
示例#3
0
        public ComponentDesigner(ComponentTemplateSD componentSD, FactionTechDB factionTech)
        {
            var staticData = StaticRefLib.StaticData;

            TypeName = componentSD.Name;
            Name     = componentSD.Name;

            _design.ID          = Guid.NewGuid();
            MassFormula         = new ChainedExpression(componentSD.MassFormula, this, factionTech, staticData);
            VolumeFormula       = new ChainedExpression(componentSD.VolumeFormula, this, factionTech, staticData);
            CrewFormula         = new ChainedExpression(componentSD.CrewReqFormula, this, factionTech, staticData);
            HTKFormula          = new ChainedExpression(componentSD.HTKFormula, this, factionTech, staticData);
            ResearchCostFormula = new ChainedExpression(componentSD.ResearchCostFormula, this, factionTech, staticData);
            BuildCostFormula    = new ChainedExpression(componentSD.BuildPointCostFormula, this, factionTech, staticData);
            CreditCostFormula   = new ChainedExpression(componentSD.CreditCostFormula, this, factionTech, staticData);
            ComponentMountType  = componentSD.MountType;
            IndustryType        = componentSD.IndustryTypeID;
            CargoTypeID         = componentSD.CargoTypeID;
            _design.CargoTypeID = componentSD.CargoTypeID;
            if (componentSD.MountType.HasFlag(ComponentMountType.PlanetInstallation))
            {
                _design.GuiHints = ConstructableGuiHints.CanBeInstalled;
            }
            if (!string.IsNullOrEmpty(componentSD.DescriptionFormula))
            {
                DescriptionFormula = new ChainedExpression(componentSD.DescriptionFormula, this, factionTech, staticData);
            }

            Dictionary <Guid, ChainedExpression> resourceCostForulas = new Dictionary <Guid, ChainedExpression>();

            foreach (var kvp in componentSD.ResourceCostFormula)
            {
                if (staticData.CargoGoods.GetAny(kvp.Key) != null)
                {
                    resourceCostForulas.Add(kvp.Key, new ChainedExpression(kvp.Value, this, factionTech));
                }
                else //TODO: log don't crash.
                {
                    throw new Exception("GUID object {" + kvp.Key + "} not found in resourceCosting for " + this.TypeName + " This object needs to be either a mineral, material or component defined in the Data folder");
                }
            }

            ResourceCostFormulas = resourceCostForulas;

            foreach (ComponentTemplateAttributeSD attrbSD in componentSD.ComponentAtbSDs)
            {
                ComponentDesignAttribute designAttribute = new ComponentDesignAttribute(this, attrbSD, factionTech);
                ComponentDesignAttributes.Add(designAttribute.Name, designAttribute);
                ComponentDesignAttributeList.Add(designAttribute);
            }

            EvalAll();
        }
示例#4
0
        public ComponentDesignVM(GameVM gameVM)
        {
            _gameVM        = gameVM;
            _staticData    = gameVM.Game.StaticData;
            _factionEntity = gameVM.CurrentFaction;
            _factionTech   = gameVM.CurrentFaction.GetDataBlob <FactionTechDB>();


            foreach (var componentSD in gameVM.Game.StaticData.ComponentTemplates.Values)
            {
                ComponentTypes.Add(componentSD.Name, componentSD.ID);
            }
            ComponentTypes.SelectedIndex = 0;
        }
示例#5
0
        public ColonyResearchVM(StaticDataStore staticData, Entity colonyEntity)
        {
            _factionEntity = colonyEntity.GetDataBlob <OwnedDB>().ObjectOwner;
            _colonyEntity  = colonyEntity;
            _factionTech   = _factionEntity.GetDataBlob <FactionTechDB>();
            Scientists     = new List <ScientistControlVM>();
            if (_factionTech.ResearchableTechs.Count > 0)
            {
                //ResearchableTechs = new ObservableCollection<TechSD>(_factionTech.ResearchableTechs.Keys);
                ResearchableTechs = new DictionaryVM <TechSD, string>(DisplayMode.Value);
                foreach (var tech in _factionTech.ResearchableTechs.Keys)
                {
                    ResearchableTechs.Add(tech, tech.Name);
                }
                SelectedTechIndex = 0;
            }

            foreach (var scientist in _colonyEntity.GetDataBlob <ColonyInfoDB>().Scientists)
            {
                Scientists.Add(new ScientistControlVM(staticData, _factionTech, scientist));
            }
            SelectedScientist = Scientists[0];
            Refresh();
        }
示例#6
0
        /// <summary>
        /// "Set" and returns the designdata
        /// this also sets up a research item for the design,
        /// and adds it to the factions designs.
        /// </summary>
        /// <returns></returns>
        public ComponentDesign CreateDesign(Entity factionEntity)
        {
            FactionInfoDB faction = factionEntity.GetDataBlob <FactionInfoDB>();

            //set up the research
            FactionTechDB factionTech = factionEntity.GetDataBlob <FactionTechDB>();
            TechSD        tech        = new TechSD();

            tech.ID          = Guid.NewGuid();
            tech.Name        = _design.Name + " Design Research";
            tech.Description = "Research into building " + _design.Name;
            tech.MaxLevel    = 1;
            tech.CostFormula = _design.ResearchCostValue.ToString();


            _design.TechID = tech.ID;
            factionTech.MakeResearchable(tech); //add it to researchable techs

            SetAttributes();

            faction.InternalComponentDesigns[_design.ID] = _design;
            faction.IndustryDesigns[_design.ID]          = _design;
            return(_design);
        }
示例#7
0
        /// <summary>
        /// "Set" and returns the designdata
        /// this also sets up a research item for the design,
        /// and adds it to the factions designs.
        /// </summary>
        /// <returns></returns>
        public ComponentDesign CreateDesign(Entity factionEntity)
        {
            FactionInfoDB faction = factionEntity.GetDataBlob <FactionInfoDB>();

            //set up the research
            FactionTechDB factionTech = factionEntity.GetDataBlob <FactionTechDB>();
            TechSD        tech        = new TechSD();

            tech.ID          = Guid.NewGuid();
            tech.Name        = _design.Name + " Design Research";
            tech.Description = "Research into building " + _design.Name;
            tech.MaxLevel    = 1;
            tech.CostFormula = _design.ResearchCostValue.ToString();


            _design.TechID = tech.ID;
            factionTech.MakeResearchable(tech); //add it to researchable techs
            EvalAll();
            foreach (var designAttribute in ComponentDesignAttributes.Values)
            {
                if (designAttribute.DataBlobType != null)
                {
                    if (designAttribute.DataBlobArgs == null)
                    {
                        designAttribute.SetValue();  //force recalc.
                    }
                    object[] constructorArgs = designAttribute.DataBlobArgs;

                    dynamic attrbute = (IComponentDesignAttribute)Activator.CreateInstance(designAttribute.DataBlobType, constructorArgs);
                    _design.AttributesByType.Add(attrbute.GetType(), attrbute);
                }
            }

            faction.InternalComponentDesigns.Add(_design.Guid, _design);
            return(_design);
        }
示例#8
0
 public ResearchTechControlVM(FactionTechDB factionTech, Guid techID)
 {
     _factionTech = factionTech;
     _techSD      = factionTech.ResearchableTechs.Keys.First(k => k.ID == techID);
 }
示例#9
0
        public ComponentDesigner(ComponentTemplateSD componentSD, FactionTechDB factionTech)
        {
            var staticData = StaticRefLib.StaticData;

            TypeName            = componentSD.Name;
            Name                = componentSD.Name;
            Description         = componentSD.Description;
            _design.ID          = Guid.NewGuid();
            MassFormula         = new ChainedExpression(componentSD.MassFormula, this, factionTech, staticData);
            VolumeFormula       = new ChainedExpression(componentSD.VolumeFormula, this, factionTech, staticData);
            CrewFormula         = new ChainedExpression(componentSD.CrewReqFormula, this, factionTech, staticData);
            HTKFormula          = new ChainedExpression(componentSD.HTKFormula, this, factionTech, staticData);
            ResearchCostFormula = new ChainedExpression(componentSD.ResearchCostFormula, this, factionTech, staticData);
            BuildCostFormula    = new ChainedExpression(componentSD.BuildPointCostFormula, this, factionTech, staticData);
            CreditCostFormula   = new ChainedExpression(componentSD.CreditCostFormula, this, factionTech, staticData);
            ComponentMountType  = componentSD.MountType;
            IndustryType        = componentSD.IndustryTypeID;
            CargoTypeID         = componentSD.CargoTypeID;
            _design.CargoTypeID = componentSD.CargoTypeID;
            if (componentSD.MountType.HasFlag(ComponentMountType.PlanetInstallation))
            {
                _design.GuiHints = ConstructableGuiHints.CanBeInstalled;
            }

            Dictionary <Guid, ChainedExpression> resourceCostForulas = new Dictionary <Guid, ChainedExpression>();

            //Dictionary<Guid, ChainedExpression> mineralCostFormulas = new Dictionary<Guid, ChainedExpression>();
            //Dictionary<Guid, ChainedExpression> materalCostFormulas = new Dictionary<Guid, ChainedExpression>();
            //Dictionary<Guid, ChainedExpression> componentCostForulas = new Dictionary<Guid, ChainedExpression>();
            foreach (var kvp in componentSD.ResourceCostFormula)
            {
                /*
                 * if (staticData.CargoGoods.IsMaterial(kvp.Key))
                 * {
                 *  materalCostFormulas.Add(kvp.Key, new ChainedExpression(kvp.Value, this, factionTech, staticData));
                 * }
                 * else if (staticData.ComponentTemplates.ContainsKey(kvp.Key))
                 * {
                 *  componentCostForulas.Add(kvp.Key, new ChainedExpression(kvp.Value, this, factionTech, staticData));
                 * }
                 * else if (staticData.CargoGoods.IsMineral(kvp.Key))
                 * {
                 *  mineralCostFormulas.Add(kvp.Key, new ChainedExpression(kvp.Value, this, factionTech, staticData));
                 * }
                 * else //TODO: log don't crash.
                 *  throw new Exception("GUID object {" + kvp.Key + "} not found in materialCosting for " + this.TypeName + " This object needs to be either a mineral, material or component defined in the Data folder");
                 *
                 */
                if (staticData.CargoGoods.GetAny(kvp.Key) != null)
                {
                    resourceCostForulas.Add(kvp.Key, new ChainedExpression(kvp.Value, this, factionTech));
                }
                else //TODO: log don't crash.
                {
                    throw new Exception("GUID object {" + kvp.Key + "} not found in resourceCosting for " + this.TypeName + " This object needs to be either a mineral, material or component defined in the Data folder");
                }
            }

            ResourceCostFormulas = resourceCostForulas;
            //MineralCostFormulas = mineralCostFormulas;
            // MaterialCostFormulas = materalCostFormulas;
            //ComponentCostFormulas = componentCostForulas;

            foreach (ComponentTemplateAbilitySD abilitySD in componentSD.ComponentAbilitySDs)
            {
                ComponentDesignAttribute designAttribute = new ComponentDesignAttribute(this);

                if (abilitySD.Name == null) //TODO: Log this, and don't use this component instead of throwing.
                {
                    throw new Exception("Bad Static Data. Ability name is null");
                }

                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);
                }

                ComponentDesignAttributes.Add(designAttribute.Name, designAttribute);

                //TODO: get rid of this once json data is rewritten to use names instead of indexes
                ComponentDesignAttributeList.Add(designAttribute);
            }

            EvalAll();
        }
示例#10
0
        public void HardRefresh()
        {
            var designs          = _uiState.Faction.GetDataBlob <FactionInfoDB>().MissileDesigns;
            var componentDesigns = _uiState.Faction.GetDataBlob <FactionInfoDB>().ComponentDesigns;

            _faction     = _uiState.Faction;
            _factionTech = _uiState.Faction.GetDataBlob <FactionTechDB>();

            foreach (var des in componentDesigns)
            {
            }

            _currentDesigns     = designs.Values.ToArray();
            _currentDesignNames = new string[_currentDesigns.Length];
            int i = 0;

            foreach (var mdesign in _currentDesigns)
            {
                _currentDesignNames[i] = mdesign.Name;
                i++;
            }



            _payloadTypes   = new List <ComponentDesign>();
            _eleccPackTypes = new List <ComponentDesign>();
            foreach (ComponentDesign cdes in componentDesigns.Values)
            {
                if ((cdes.ComponentMountType & ComponentMountType.Missile) == ComponentMountType.Missile)
                {
                    if (cdes.AttributesByType.ContainsKey(typeof(OrdnancePayloadAtb)))
                    {
                        _payloadTypes.Add(cdes);
                    }
                    if (cdes.AttributesByType.ContainsKey(typeof(OrdnanceExplosivePayload)))
                    {
                        _payloadTypes.Add(cdes);
                    }
                    if (cdes.AttributesByType.ContainsKey(typeof(OrdnanceShapedPayload)))
                    {
                        _payloadTypes.Add(cdes);
                    }
                    if (cdes.AttributesByType.ContainsKey(typeof(OrdnanceLaserPayload)))
                    {
                        _payloadTypes.Add(cdes);
                    }
                    if (cdes.AttributesByType.ContainsKey(typeof(OrdnanceSubmunitionsPayload)))
                    {
                        _payloadTypes.Add(cdes);
                    }
                    if (cdes.AttributesByType.ContainsKey(typeof(SensorReceverAtbDB)))
                    {
                        _eleccPackTypes.Add(cdes);
                    }
                }
            }

            _payload = new string[_payloadTypes.Count];
            i        = 0;
            foreach (var des in _payloadTypes)
            {
                _payload[i] = des.Name;
            }
            _electronicsPackage = new string[_eleccPackTypes.Count];
            i = 0;
            foreach (var des in _eleccPackTypes)
            {
                _electronicsPackage[i] = des.Name;
            }

            _selectedComponentDesigns[_payloadTypes[_payloadSelectedIndex]]       = _payloadCount;
            _selectedComponentDesigns[_eleccPackTypes[_electronicsSelectedIndex]] = 1;


            var allDesignables = StaticRefLib.StaticData.ComponentTemplates.Values.ToArray();
            List <ComponentTemplateSD> engineTemplates = new List <ComponentTemplateSD>();

            foreach (var designable in allDesignables)
            {
                foreach (var atbSD in designable.ComponentAtbSDs)
                {
                    if (atbSD.AttributeType == typeof(NewtonionThrustAtb).ToString())
                    {
                        engineTemplates.Add(designable);
                    }
                }
            }

            _engineTemplates = engineTemplates.ToArray();
            _engineTypeNames = new string[_engineTemplates.Length];
            for (int j = 0; j < _engineTemplates.Length; j++)
            {
                _engineTypeNames[j] = engineTemplates[j].Name;
            }


            RefreshMass();
        }