Esempio n. 1
0
        public float GetValue(int prefabVariantIndex, bool useExpectedValue = false)
        {
            if (prefabVariantValueMappings == null || prefabVariantValueMappings.Count == 0)
            {
                return(useExpectedValue ? defaultValueCurve.ExpectedValue() : defaultValueCurve.EvalRandom());
            }

            PrefabVariantValueMapping valueMapping = prefabVariantValueMappings.Find(x => x.prefabVariantIndex == prefabVariantIndex);

            if (valueMapping == null)
            {
                return(useExpectedValue ? defaultValueCurve.ExpectedValue() : defaultValueCurve.EvalRandom());
            }

            return(useExpectedValue ? valueMapping.valueCurve.ExpectedValue() : valueMapping.valueCurve.EvalRandom());
        }
Esempio n. 2
0
        public override bool MakeChange(Agent agent, Entity target, OutputChange outputChange, Mapping mapping, float actualAmount, out bool forceStop)
        {
            forceStop = false;

            Entity entityToThrow = mapping.inventoryTargets[outputChange.inventoryTypeGroupMatchIndex];

            if (entityToThrow == null)
            {
                Debug.LogError(agent.name + ": ThrowEntityOCT - No entity to throw found.");
                return(false);
            }

            // Remove from inventory
            InventoryType.Item item = agent.inventoryType.Remove(agent, entityToThrow);
            if (item == null)
            {
                Debug.LogError(agent.name + ": ThrowEntityOCT - No entity to throw found in agent's inventory.");
                return(false);
            }

            Vector3 targetPosition = target.transform.position;

            if (outputChange.unityObject != null)
            {
                // Move direction by random degrees
                MinMaxCurve minMaxCurve = outputChange.unityObject as MinMaxCurve;
                float       degrees     = minMaxCurve.EvalRandom();

                // Rotate targetPosition relative to agent.position by degrees
                Vector3 forceVector = Quaternion.Euler(0, 0, degrees) * ((Vector2)(targetPosition - agent.transform.position)).normalized;
                Debug.DrawRay(agent.transform.position, forceVector, Color.white, 5f);
                targetPosition = forceVector + agent.transform.position;
            }

            agent.inventoryType.Thrown(entityToThrow, agent, item.inventorySlot, targetPosition, outputChange.floatValue);
            return(true);
        }
        // Returns PositiveInfinity if the curve is null
        public float GetValue(int prefabVariantIndex, ChangeType changeType, bool useExpectedValue = false)
        {
            if (modifierType == ModifierType.OnAction)
            {
                MinMaxCurve minMaxCurve = defaultLevelCurveChange;
                if (prefabVariantValueMappings != null && prefabVariantValueMappings.Count > 0)
                {
                    PrefabVariantValueMapping valueMapping = prefabVariantValueMappings.Find(x => x.prefabVariantIndex == prefabVariantIndex);
                    if (valueMapping != null)
                    {
                        minMaxCurve = valueMapping.levelCurveChange;
                    }
                }

                if (minMaxCurve == null)
                {
                    return(float.PositiveInfinity);
                }
                return(useExpectedValue ? minMaxCurve.ExpectedValue() : minMaxCurve.EvalRandom());
            }

            // Always Modifier Type - does not use curves
            float changeValue = 0f;

            if (prefabVariantValueMappings != null && prefabVariantValueMappings.Count > 0)
            {
                PrefabVariantValueMapping valueMapping = prefabVariantValueMappings.Find(x => x.prefabVariantIndex == prefabVariantIndex);
                if (valueMapping != null)
                {
                    switch (changeType)
                    {
                    case ChangeType.Level:
                        changeValue = valueMapping.levelChange;
                        break;

                    case ChangeType.Min:
                        changeValue = valueMapping.minChange;
                        break;

                    case ChangeType.Max:
                        changeValue = valueMapping.maxChange;
                        break;
                    }
                    return(changeValue);
                }
            }
            switch (changeType)
            {
            case ChangeType.Level:
                changeValue = defaultLevelChange;
                break;

            case ChangeType.Min:
                changeValue = defaultMinChange;
                break;

            case ChangeType.Max:
                changeValue = defaultMaxChange;
                break;
            }
            return(changeValue);
        }