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 Objective LoadObjective(ObjectiveData objectiveData)
        {
            ObjectiveDefinition objectiveDefinition = _objectiveDefinitions.FirstOrDefault(x => x.ObjectiveType == objectiveData.Type);

            if (objectiveDefinition != null)
            {
                return(objectiveDefinition.LoadObjective(objectiveData));
            }
            return(null);
        }
Beispiel #3
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);
        }
Beispiel #4
0
 public Objective(ObjectiveData data)
 {
     _data = data;
 }
Beispiel #5
0
 public GatherResourcesObjective(ObjectiveData data, TileType tileType, GameEvent playerResourcesGathered) : base(data)
 {
     _tileType = tileType;
     _playerResourcesGathered = playerResourcesGathered;
     _playerResourcesGathered.RegisterEvent(this);
 }
Beispiel #6
0
 public abstract Objective LoadObjective(ObjectiveData data);