Beispiel #1
0
        public override Objective LoadObjective(ObjectiveData data)
        {
            int requiredResourceId          = data.GetFieldValue("RequiredResourceId");
            GatherResourcesObjective result = new GatherResourcesObjective(data, _tileTypes.GetTileType(requiredResourceId), _playerResourcesGathered);

            return(result);
        }
Beispiel #2
0
        public override Objective CreateObjective()
        {
            ObjectiveData objectiveData = new ObjectiveData();
            List <GroundLayer.Element> collectibleResources = new List <GroundLayer.Element>(_groundLayers[_playerMaxAchievedLayer.Value].Resources.Count);

            foreach (GroundLayer.Element elem in _groundLayers[_playerMaxAchievedLayer.Value].Resources)
            {
                if (elem.Type.IsCollectible)
                {
                    collectibleResources.Add(elem);
                }
            }

            if (collectibleResources.Count == 0)
            {
                Management.Log.Instance.WriteException(new ExecutionException());
                return(null);
            }

            GroundLayer.Element selectedResource = collectibleResources[Random.Range(0, collectibleResources.Count)];

            float difficultyCoefficient = 1f;

            if (selectedResource.Probability != 0f)
            {
                difficultyCoefficient /= selectedResource.Probability;
            }

            int requiredAmount = (int)Mathf.Clamp(Random.Range(0.8f, 1.2f) * 10 * difficultyCoefficient / 100f, 1, MAX_RESOURCE_STACK);

            objectiveData.AddField("RequiredResourceId", selectedResource.Type.Id);
            objectiveData.AddField("CollectedResourceAmount", 0);
            objectiveData.AddField("RequiredResourceAmount", requiredAmount);
            objectiveData.Name = "Collect resources";
            GatherResourcesObjective result = new GatherResourcesObjective(objectiveData, selectedResource.Type, _playerResourcesGathered);

            return(result);
        }