Exemple #1
0
        public ExtractionModule Init(ItemProgress itemProgress, bool premium, MaterialResource extractionProportin)
        {
            if (itemProgress == null)
            {
                itemProgress = new ItemProgress {
                    Level = 1
                };
            }
            var level      = itemProgress.Level ?? 1;
            var property   = PropertyList(level, premium);
            var power      = property[0].CurrentValue;
            var extraction = new ExtractionResource();

            extraction.SetAndCalcEmpFromProportion(extractionProportin, power, BaseProportion.Ir, BaseProportion.Dm);

            ItemProgress        = itemProgress;
            Cost                = CalcPrice(level, premium);
            Images              = _images;
            Text                = _text;
            Properties          = property;
            ExtractionPerHour   = extraction.ExtractionPerHour;
            ExtractionProportin = extraction.ExtractionProportin;
            Power               = power;
            return(this);
        }
        public MaterialResource CalculateTransferedRes(bool sum, MaterialResource current, MaterialResource delta, bool premiumIsActive, int?storageLevel = null)
        {
            var    operation = (sum) ? 1 : -1;
            double mod       = 1;
            var    level     = storageLevel ?? 1;

            if (level == 0)
            {
                level = 1;
            }

            if (sum)
            {
                // Math.Pow(GetTransferLossesMod(level, premiumIsActive), (double) 1 / level);
                mod = GetTransferLossesMod(level, premiumIsActive); //1-0.3 30 -1
            }

            var m = (MaterialResource)current.Clone();
            var d = (MaterialResource)delta.Clone();

            d.Multiply(operation * mod);
            m.Sum(d);
            // m.ConvertToInt();
            return(m);
        }
Exemple #3
0
        public override void OnSelect(Player player)
        {
            // Use correct preview mesh
            MeshResource     shapeMesh = null;
            MaterialResource shapeMat  = null;

            switch (player.CurrentDiggingShape)
            {
            case Player.DiggingShape.Box:
                shapeMesh = Resources.UseMesh("::Debug/Box", null);
                shapeMat  = Resources.UseMaterial("Items/DigPreviewBox", UpvoidMiner.ModDomain);
                break;

            case Player.DiggingShape.Cylinder:
                shapeMesh = Resources.UseMesh("::Debug/Cylinder", null);
                shapeMat  = Resources.UseMaterial("Items/DigPreviewCylinder", UpvoidMiner.ModDomain);
                break;

            case Player.DiggingShape.Sphere:
                shapeMesh = Resources.UseMesh("::Debug/Sphere", null);
                shapeMat  = Resources.UseMaterial("Items/DigPreviewSphere", UpvoidMiner.ModDomain);
                break;

            default:
                throw new InvalidOperationException("Unknown digging shape");
            }

            // Create a transparent sphere as 'fill-indicator'.
            previewShape = new MeshRenderJob(Renderer.Transparent.Mesh, shapeMat, shapeMesh, mat4.Scale(0f));
            LocalScript.world.AddRenderJob(previewShape);
            // And a second one for indicating the center.
            previewShapeIndicator = new MeshRenderJob(Renderer.Transparent.Mesh, Resources.UseMaterial("Items/ResourcePreviewIndicator", UpvoidMiner.ModDomain), shapeMesh, mat4.Scale(0f));
            LocalScript.world.AddRenderJob(previewShapeIndicator);
        }
        private void _atackReport(IDbConnection connection, TmpAtackModel am)
        {
            _calcDangerLevel(UnixTime.ToTimestamp(am.DefendorPlanet.LastActive), am.BattleTime, am.DefendorPlanet);
            am.Battle = new BattleFleetsCalculator(am.SourceUser.Fleet, am.DefendorUser.Fleet);
            am.Battle.SetUnitMods(am.SourceUser.UnitMods, am.DefendorUser.UnitMods);
            am.BattleLog = am.Battle.Battle(am.DefendorPlanet.Turels.Level ?? 0);


            var status = am.BattleLog.Last().BattleResult;
            var isWin  = status == BattleResult.AtackerWin;

            am.SourceUser.Report   = am.Battle.Source;
            am.DefendorUser.Report = am.Battle.Target;

            am.ReportDataModel = _uReportService.AddOrUpdate(connection, new UserReportDataModel
            {
                TaskId     = am.TaskItem.Id,
                BattleTime = am.BattleTime,
                //todo Сбрасывать ресурсы?
                Resources             = MaterialResource.ConvertStorageToMaterial(am.DefendorPlanet.Resources).ConvertToInt(),
                RoundsLog             = am.BattleLog,
                DefenderUserId        = am.DefendorUser.User.Id,
                DefenderUserName      = am.DefendorUser.User.Nickname,
                DefenderDeleteReport  = !am.AtackerIsSkagry,
                DefenderSummaryReport = am.DefendorUser.Report,

                AtackerResultStatus  = status,
                AtackerWin           = isWin,
                AtackerUserId        = am.SourceUser.User.Id,
                AtackerUserName      = am.SourceUser.User.Nickname,
                AtackerSummaryReport = am.SourceUser.Report,
                AtackerIsSkagry      = am.AtackerIsSkagry,
                AtackerDeleteReport  = am.AtackerIsSkagry
            });
        }
Exemple #5
0
        private double processSingleMaterial(MaterialResource material)
        {
            Model model = Model.Instance;

            bool isUsedByThis = material.users.Contains(this.id);

            if (material.users.Count == 0)
            {
                material.isBusy = false;
            }

            if (material.isBusy && !material.isShared && !isUsedByThis)
            {
                return(Double.Epsilon);
            }

            double usersCount = material.users.Count > 0 ? material.users.Count : 1.0;

            if ((material.count - material.perTick / usersCount) > 0)
            {
                material.count -= material.perTick / usersCount;

                if (!isUsedByThis)
                {
                    material.users.Add(this.id);
                    material.isBusy = true;
                }
                return(1.0);
            }
            else
            {
                model.state = ProcessingState.RESOURCES_EMPTY;
                return(Double.Epsilon);
            }
        }
Exemple #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="extractionProportin"></param>
        /// <param name="calculatedPower"></param>
        /// <param name="second"></param>
        /// <param name="baseIr">ExtractionModule.BaseProportion.Ir</param>
        /// <param name="baseDm">ExtractionModule.BaseProportion.Dm</param>
        /// <returns></returns>
        public static MaterialResource CalculateExtractionBySeconds(MaterialResource extractionProportin, double calculatedPower, int second, double baseIr, double baseDm)
        {
            var eps = CalcExtractionPerSecond(extractionProportin, calculatedPower, baseIr, baseDm);

            eps.Multiply(second);
            return(eps);
        }
Exemple #7
0
        public UserMothershipDataModel CreateMother(IDbConnection connection, int userId, int startSystem = 1)
        {
            var r         = StorageResources.InitMotherResources();
            var curMother = GetMother(connection, userId, false);

            if (curMother != null)
            {
                return(curMother);
            }

            var teches = new BattleTeches();

            teches.CreateStartTeches();
            var userTeches = teches.ConvertToDbTeches();

            var newMother = new UserMothershipDataModel
            {
                Id                  = userId,
                StartSystemId       = startSystem,
                Resources           = r,
                Hangar              = UnitList.InitUnitsInOwn(),
                ExtractionProportin = MaterialResource.InitBaseOwnProportion(),
                UnitProgress        = new Dictionary <UnitType, TurnedUnit>(),
                TechProgress        = userTeches
            };

            return(AddOrUpdate(connection, newMother));
        }
        static public dynamic material(LispList args, LispEnvironment env)
        {
            IEnumerator <dynamic> arg = args.GetEnumerator();

            arg.MoveNext();
            var technique = arg.Current.Eval(env);

            arg.MoveNext();
            var effect = arg.Current.Eval(env);

            arg.MoveNext();
            List <KeyValuePair <string, ResourceHandle> > textures = arg.Current.Eval(env);

            arg.MoveNext();
            var constants = arg.Current.Eval(env);

            var mat = new MaterialResource(effect, technique);

            foreach (var texture in textures)
            {
                mat.AddTexture(texture.Key, texture.Value);
            }

            foreach (var constant in constants)
            {
                mat.AddConstant(constant.Key, constant.Value);
            }

            return(mat);

            //var material = new MaterialResource();
            throw new NotImplementedException();
        }
        /// <summary>
        /// Applies the given material to the renderer.
        /// </summary>
        /// <param name="resourceToApply">The material to apply.</param>
        /// <param name="instancingMode">The instancing mode for which to apply the material.</param>
        internal void ApplyMaterial(MaterialResource resourceToApply, MaterialApplyInstancingMode instancingMode)
        {
            // Use forced material if any set
            if ((m_forcedMaterial != null) &&
                (resourceToApply != m_forcedMaterial))
            {
                resourceToApply = m_forcedMaterial;
            }

            // Disable logic if given material is null
            if (resourceToApply == null)
            {
                m_lastAppliedMaterial = null;
                return;
            }

            if ((m_lastAppliedMaterial != resourceToApply) || (m_lastMaterialInstancingMode != instancingMode))
            {
                // Apply material (material or instancing mode has changed)
                resourceToApply.Apply(this, instancingMode, m_lastAppliedMaterial);

                m_lastAppliedMaterial        = resourceToApply;
                m_lastMaterialInstancingMode = instancingMode;
            }
        }
Exemple #10
0
        public SolidTerrainResource(string name, string renderMaterial, string particleMaterial, bool defaultPipeline = true) :
            base(name)
        {
            RenderMaterial      = Resources.UseMaterial(renderMaterial, UpvoidMiner.ModDomain);
            DigParticleMaterial = Resources.UseMaterial(particleMaterial, UpvoidMiner.ModDomain);

            if (Scripting.IsHost)
            {
                // Add a default pipeline. (Solid material with zPre and Shadow pass)
                if (defaultPipeline)
                {
                    { // LoD 0-4
                        int pipe = Material.AddPipeline(Resources.UseGeometryPipeline("ColoredRock", UpvoidMiner.ModDomain), "Input", "Decimate", 0, 4);
                        Material.AddDefaultShadowAndZPre(pipe);
                        Material.AddMeshMaterial(pipe, "Output", RenderMaterial, Renderer.Opaque.Mesh);
                    }

                    { // LoD 5-max
                        int pipe = Material.AddPipeline(Resources.UseGeometryPipeline("ColoredRockLow", UpvoidMiner.ModDomain), "Input", "Decimate", 5);
                        Material.AddDefaultShadowAndZPre(pipe);
                        Material.AddMeshMaterial(pipe, "Output", RenderMaterial, Renderer.Opaque.Mesh);
                    }
                }
            }
        }
Exemple #11
0
        private static GDetailPlanetDataModel _convertFromEntity(IGDetailPlanetDbItem data)
        {
            var result = new GDetailPlanetDataModel();

            if (data == null)
            {
                return(result);
            }
            result.Id                    = data.Id;
            result.Name                  = data.name;
            result.Description           = data.description.ToSpecificModel <L10N>();
            result.MoonCount             = data.moonCount;
            result.UserId                = data.userId;
            result.AllianceId            = data.allianceId;
            result.LastActive            = data.lastActive;
            result.DangerLevel           = data.dangerLevel;
            result.Resources             = data.resources.ToSpecificModel <StorageResources>();
            result.Hangar                = data.hangar.ToSpecificModel <Dictionary <UnitType, int> >();
            result.BuildSpaceShipyard    = data.buildSpaceShipyard.ToSpecificModel <ItemProgress>();
            result.BuildExtractionModule = data.buildExtractionModule.ToSpecificModel <ItemProgress>();
            result.BuildEnergyConverter  = data.buildEnergyConverter.ToSpecificModel <ItemProgress>();
            result.BuildStorage          = data.buildStorage.ToSpecificModel <ItemProgress>();
            result.Turels                = data.turels.ToSpecificModel <ItemProgress>();

            result.UnitProgress = data.unitProgress == null
                ? new Dictionary <UnitType, TurnedUnit>()
                : data.unitProgress.ToSpecificModel <Dictionary <UnitType, TurnedUnit> >();
            result.ExtractionProportin = data.extractionProportin == null
                ? MaterialResource.InitBaseOwnProportion()
                : data.extractionProportin.ToSpecificModel <MaterialResource>();

            result.LastUpgradeProductionTime = data.lastUpgradeProductionTime;
            return(result);
        }
        public static MaterialResource MaxMotherStorable(bool hasPremium)
        {
            var maxMod = MaxStorableMod(hasPremium);
            var m      = MaterialResource.MaxMotherResourses().Multiply(maxMod);//.ConvertToInt();

            return(m);
        }
Exemple #13
0
    public void mineResource(GameObject targetGameObject)
    {
        MaterialResource resource = targetGameObject.GetComponent <MaterialResource>();

        addItemToInventory(resource);
        destroyItemObject(targetGameObject);
    }
        public static BuildUpgrade SetUpgrade(BuildUpgrade bu, GameResource currentCost)
        {
            var curRes = bu.StorageResources.Current;

            var enoughtRes = MaterialResource.EnoughResourses(curRes, currentCost);

            if (!enoughtRes)
            {
                return(bu);
            }

            var newResourse = MaterialResource.CalcNewResoursesFromBuy(curRes, currentCost);

            var upgradedData = new BuildUpgrade
            {
                StorageResources =
                    bu.StorageResources.SetStorageResource(newResourse, bu.StorageResources.Max),
                Progress = new ItemProgress
                {
                    Level      = bu.Progress.Level,
                    IsProgress = true,
                    Duration   = currentCost.TimeProduction
                },
                NativeName = bu.NativeName
            };


            return(upgradedData);
        }
        public async Task <IActionResult> Create([FromBody] MaterialResource model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Material material         = _mapper.Map <MaterialResource, Material>(model);
            var      materialResponse = await _materialService.CreateAsync(material, model.Description);

            if (!materialResponse.Success)
            {
                return(BadRequest(materialResponse.Message));
            }

            var simplyResponse = new
            {
                materialResponse.Extra.Id,
                materialResponse.Extra.AnnouncementId,
                materialResponse.Extra.Announcement.Description,
                materialResponse.Extra.GivenClassroomId,
                materialResponse.Extra.Hint,
                materialResponse.Extra.MaterialScale,
                materialType = materialResponse.Extra.MaterialType.Description(),
                materialResponse.Extra.Question
            };

            return(Ok(simplyResponse));
        }
Exemple #16
0
 // GET: Resources/Details/5
 public ActionResult Details(int id)
 {
     try
     {
         MaterialResource   s  = new MaterialResource();
         SE_ProjectEntities db = new SE_ProjectEntities();
         foreach (MaterialResource b in db.MaterialResources)
         {
             if (b.id == id)
             {
                 s.Name    = b.Name;
                 s.Length  = b.Length;
                 s.Content = b.Content;
                 s.id      = b.id;
                 s.Type    = b.Type;
                 break;
             }
         }
         MemoryStream ms = new MemoryStream(s.Content, 0, 0, true, true);
         Response.ContentType = s.Type;
         Response.AddHeader("content-disposition", "attachment;filename=" + s.Name);
         Response.Buffer = true;
         Response.Clear();
         Response.OutputStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
         Response.OutputStream.Flush();
         Response.End();
         return(new FileStreamResult(Response.OutputStream, s.Type));
     }
     catch
     {
         return(View());
     }
 }
Exemple #17
0
        public static MaterialResource CalcExtractionPerSecond(MaterialResource extractionProportin, double calculatedPower, double baseIr, double baseDm)
        {
            var factor = UnixTime.OneHourInSecond;
            var rph    = CalculateExtractionPerHouer(extractionProportin, calculatedPower, baseIr, baseDm);

            rph.Multiply((double)1 / factor);
            return(rph);
        }
Exemple #18
0
 internal RenderingChunk(
     RenderingChunkTemplate template,
     D3D11.ID3D11InputLayout inputLayout,
     MaterialResource material)
 {
     this.Template    = template;
     this.InputLayout = inputLayout;
     this.Material    = material;
 }
Exemple #19
0
        public static MaterialResource CalculateExtractionPerHouer(MaterialResource extractionProportin,
                                                                   double calculatedPower, double baseIr, double baseDm)
        {
            var valE  = calculatedPower * extractionProportin.E / 100;
            var valIr = (calculatedPower * extractionProportin.Ir / 100) / baseIr;
            var valDm = (calculatedPower * extractionProportin.Dm / 100) / baseDm;

            return(new MaterialResource(valE, valIr, valDm));
        }
        public RenderingChunk CreateChunk(EngineDevice device, MaterialResource material)
        {
            var result = new RenderingChunk(
                this,
                material.GetInputLayout(device, InputElements),
                material);

            return(result);
        }
        private void RemoveNotAddedAdditions(MaterialResource materialResource, Material material)
        {
            var removedAdditions = material.MaterialAdditions.Where(ma =>
                                                                    !materialResource.Additions.Select(a => a.Id).Contains(ma.AdditionId)).ToList();

            foreach (var addition in removedAdditions)
            {
                material.MaterialAdditions.Remove(addition);
            }
        }
Exemple #22
0
        public void GivenTheCurrentSceneContainsAMaterialResourceListWithAResourceNamed(string materialName)
        {
            IDTFScene currentScene = ScenarioContext.Current.Get<IDTFScene>();

            MaterialResource m1 = new MaterialResource();
            m1.Name = materialName;

            currentScene.MaterialResources.Add(materialName, m1);

            ScenarioContext.Current.Set<MaterialResource>(m1, materialName);
        }
Exemple #23
0
        private static int CalculateMaxCount(MaterialResource bp, MaterialResource res)
        {
            var counts = new List <double>
            {
                res.E / ((bp.E == 0) ? 1 : bp.E),
                res.Ir / ((bp.Ir == 0) ? 1 : bp.Ir),
                res.Dm / ((bp.Dm == 0) ? 1 : bp.Dm)
            };

            return((int)Math.Floor(counts.Min()));
        }
Exemple #24
0
        public void FixProportion(MaterialResource proportion)
        {
            const int fullPersent = 100;
            var       sum         = proportion.E + proportion.Ir + proportion.Dm;

            var k = sum / fullPersent;

            proportion.E  = proportion.E / k;
            proportion.Ir = proportion.Ir / k;
            proportion.Dm = proportion.Dm / k;
        }
Exemple #25
0
        public GDetailPlanetDataModel SetInitialHangarAndResource(IDbConnection connection,
                                                                  GDetailPlanetDataModel planet, bool premium = false)
        {
            planet.Hangar = UnitList.InitUnitsInOwn(true);

            planet.Resources = new StorageResources
            {
                Current = MaterialResource.InitStartResourses(),
                Max     = Storage.MaxStorable(1, premium)
            };
            return(planet);
        }
        private void AddNewAdditions(MaterialResource materialResource, Material material)
        {
            var addedAdditions = materialResource.Additions.Where(a =>
                                                                  !material.MaterialAdditions.Any(ma => ma.AdditionId == a.Id))
                                 .Select(a => new MaterialAddition {
                AdditionId = a.Id
            }).ToList();

            foreach (var addition in addedAdditions)
            {
                material.MaterialAdditions.Add(addition);
            }
        }
Exemple #27
0
        protected override void CustomFileExport(ExportParameters exportParameters)
        {
            var Material = MaterialResource.Create();

            Material.InitFromRecord(exportParameters.BagStream, exportParameters.FileRecord);

            var outputPath = Path.GetFullPath(Path.Combine(exportParameters.OutputDirectory, exportParameters.FileRecord.Name + exportParameters.FileExtension));

            var text = JsonConvert.SerializeObject(Material, Formatting.Indented);

            File.WriteAllText(outputPath, text);

            exportParameters.OnProgressReport?.Invoke(exportParameters.FileRecord, 0);
        }
Exemple #28
0
        public void Init(NpcUser npc, StorageResources sr = null, Dictionary <UnitType, int> hangar = null,
                         MaterialResource extraction      = null)
        {
            Id                        = npc.Id;
            Resources                 = sr ?? StorageResources.InitPlanetResources();
            Hangar                    = hangar ?? UnitList.InitUnitsInOwn(true);
            ExtractionProportin       = extraction ?? MaterialResource.InitBaseOwnProportion();
            StartSystemId             = 1;
            LastUpgradeProductionTime = 0;
            LaboratoryProgress        = new ItemProgress();
            var teches = new BattleTeches();

            teches.CreateStartTeches();
            TechProgress = teches.ConvertToDbTeches();
        }
        /// <summary>
        /// Creates a log.
        /// </summary>
        private static Tree.Log CreateLog(Tree t,
                                          vec3 start, vec3 dir, vec3 front, float height, float radius,
                                          MaterialResource material, string meshName)
        {
            Tree.Log log = new Tree.Log();

            vec3 left      = vec3.cross(dir, front);
            mat4 transform = new mat4(left, dir, front, start) * mat4.Scale(new vec3(radius, height, radius));
            var  mesh      = Resources.UseMesh(meshName, UpvoidMiner.ModDomain);

            log.RenderComps.Add(new RenderComponent(new MeshRenderJob(Renderer.Opaque.Mesh, material, mesh, mat4.Identity), transform));
            log.RenderComps.Add(new RenderComponent(new MeshRenderJob(Renderer.Shadow.Mesh, Resources.UseMaterial("::Shadow", null), mesh, mat4.Identity), transform));
            log.RenderComps.Add(new RenderComponent(new MeshRenderJob(Renderer.zPre.Mesh, Resources.UseMaterial("::ZPre", null), mesh, mat4.Identity), transform));

            return(log);
        }
        /// <summary>
        ///     Основной метод работы между  запросом к бд и записью в бд для новой очереди.
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="unitType"></param>
        /// <param name="count"></param>
        /// <param name="userId"></param>
        /// <param name="ownId"></param>
        /// <param name="dbResource"></param>
        /// <param name="dbTurns"></param>
        /// <param name="setData"></param>
        private void GetTurnResultData(IDbConnection connection, UnitType unitType, int count, int userId, int ownId, StorageResources dbResource, Dictionary <UnitType, TurnedUnit> dbTurns, Action <UnitModel, StorageResources> setData)
        {
            var resource = _storageResourcesService.Execute(connection, userId, dbResource, ownId);
            var unit     = UnitHelper.GetBaseUnit(unitType);
            MaterialResource resultPrice;
            TurnedUnit       unitTurnModel;

            InitializeUnitTurn(unitType, count, resource, unit, out resultPrice, out unitTurnModel);

            AddUnitToCurrenUnitTurn(ref dbTurns, unitTurnModel);
            // подсчитываем новые ресурсы
            var newResources = resource;

            newResources.Current = MaterialResource.CalcNewResoursesFromBuy(resource.Current, resultPrice);
            setData(unit, newResources);
        }
Exemple #31
0
        public GDetailPlanetDataModel SetInitialPlanetBuilds(GDetailPlanetDataModel planet, int userId = 1)
        {
            var intiData = ItemProgress.InitBuildingProgress();
            var turel    = ItemProgress.InitBuildingProgress();

            turel.Level = 0;

            planet.BuildEnergyConverter  = intiData;
            planet.BuildExtractionModule = intiData;
            planet.BuildStorage          = intiData;
            planet.BuildSpaceShipyard    = intiData;
            planet.Turels = turel;
            planet.ExtractionProportin = MaterialResource.InitBaseOwnProportion();
            planet.UserId = userId;
            return(planet);
        }