public ActionCalculation(UInt64 parentPlotFragmentId, string varName, StoryData world)
     : base(parentPlotFragmentId, world)
 {
     _resultVar = new Trait(varName, TraitDataType.Number, world.getNewId(), world);
     _paramLeft = new Parameter("paramLeft", TraitDataType.Number, false, world);
     _paramRight = new Parameter("paramRight", TraitDataType.Number, false, world);
     _op = CalculationOperation.Add;
 }
Esempio n. 2
0
 public Constraint(UInt64 parentPlotFragmentId, UInt64 parentPrecondStatementId, bool allowedToSave, UInt64 matchingEntityTypeId, StoryData world)
 {
     _matchingEntityTypeId = matchingEntityTypeId;
     _constraintId = world.getNewId();
     _parentPrecondStmtId = parentPrecondStatementId;
     _allowedToSave = allowedToSave;
     _parentPlotFragmentId = parentPlotFragmentId;
     _constraintType = ConstraintComparisonType.Equals;
     _comparisonValue = new Parameter("", TraitDataType.Text, false, world);
     _saveAttribute = false;
     _savedVariable = new Trait("", TraitDataType.Text, "", 0, world);
     _mustAlwaysBeTrue = false;
 }
Esempio n. 3
0
 // Copy trait and keep trait type id to identify it as the same trait elsewhere in the program
 public Trait(Trait anotherTrait, StoryData world)
 {
     switch (anotherTrait.Type)
     {
         case TraitDataType.TrueFalse:
             Constructor(anotherTrait.Name, anotherTrait.Type, false, anotherTrait.TypeId, world);
             break;
         case TraitDataType.Number:
             Constructor(anotherTrait.Name, anotherTrait.Type, 0.0, anotherTrait.TypeId, world);
             break;
         case TraitDataType.Text:
             Constructor(anotherTrait.Name, anotherTrait.Type, "", anotherTrait.TypeId, world);
             break;
     }
 }
Esempio n. 4
0
        public static void SynchronizePlotPointWithType(PlotPointType ppType, PlotPoint pp, StoryData world)
        {
            List<Trait> properList = new List<Trait>();

            foreach (Trait newTrait in ppType.Traits)
            {
               // Trait oldTrait = pp.getTraitByTypeId(newTrait.TypeId);
               // if (oldTrait == null)
                //{

                    Trait convertedTrait = new Trait(newTrait, world);

                    Trait oldTrait = pp.findTraitByName(newTrait.Name);
                    if ((oldTrait != null) && (oldTrait.Type == newTrait.Type))
                    {
                        convertedTrait.Value = oldTrait.Value;
                    }

                    properList.Add(convertedTrait);

                   // properList.Add(new Trait(newTrait, world));

               // }
               // else
                //{
                   // oldTrait.Name = newTrait.Name;
                   // oldTrait.Type = newTrait.Type;
                    //properList.Add(oldTrait);
                //}
            }
            pp.Traits = properList;
        }
Esempio n. 5
0
        public static void SynchronizeGlobalPlotPointsWithType(PlotPointType type, StoryData world)
        {
            List<PlotPoint> globalPlotPoints = getGlobalPlotPointList(type, world);

            foreach (PlotPoint currEntity in globalPlotPoints)
            {
                List<Trait> properList = new List<Trait>();

                foreach (Trait newTrait in type.Traits)
                {
                   // Trait oldTrait = currEntity.getTraitByTypeId(newTrait.TypeId);
                   // if (oldTrait == null)
                   // {

                        Trait convertedTrait = new Trait(newTrait, world);

                        Trait oldTrait = currEntity.findTraitByName(newTrait.Name);
                        if ((oldTrait != null) && (oldTrait.Type == newTrait.Type))
                        {
                            convertedTrait.Value = oldTrait.Value;
                        }

                        properList.Add(convertedTrait);

                   // }
                   // else
                   // {
                      //  oldTrait.Name = newTrait.Name;
                       // oldTrait.Type = newTrait.Type;
                       // properList.Add(oldTrait);
                    //}
                }
                currEntity.Traits = properList;
            }
        }
Esempio n. 6
0
        public static void SynchronizeEntityTraits(List<Environment> entities, List<Trait> newList, StoryData world)
        {
            foreach (Environment currEntity in entities)
            {
                List<Trait> properList = new List<Trait>();

                foreach (Trait newTrait in newList)
                {
                   // Trait oldTrait = currEntity.getTraitByTypeId(newTrait.TypeId);
                    //if (oldTrait == null)
                   // {
                        Trait convertedTrait = new Trait(newTrait, world);

                        Trait oldTrait = currEntity.findTraitByName(newTrait.Name);
                        if ((oldTrait != null) && (oldTrait.Type == newTrait.Type))
                        {
                            convertedTrait.Value = oldTrait.Value;
                        }

                        properList.Add(convertedTrait);

                    //}
                   // else
                   // {
                       // oldTrait.Name = newTrait.Name;
                       // oldTrait.Type = newTrait.Type;
                        //properList.Add(oldTrait);
                    //}
                }
                currEntity.Traits = properList;
            }
        }
Esempio n. 7
0
        public static void SavePPTypeTraits(PlotPointType currPPType, List<Trait> newList, StoryData world)
        {
            List<Trait> properList = new List<Trait>();

            foreach (Trait newTrait in newList)
            {
               // Trait oldTrait = currPPType.getTraitByTypeId(newTrait.TypeId);
               // if (oldTrait == null)
               // {

                    Trait convertedTrait = new Trait(newTrait, world);

                    Trait oldTrait = currPPType.findTraitByName(newTrait.Name);
                    if ((oldTrait != null) && (oldTrait.Type == newTrait.Type))
                    {
                        convertedTrait.Value = oldTrait.Value;
                    }

                    properList.Add(convertedTrait);

                   // properList.Add(new Trait(newTrait, world));

               // }
               // else
               // {
                   // oldTrait.Name = newTrait.Name;
                    //oldTrait.Type = newTrait.Type;
                    //properList.Add(oldTrait);
                //}
            }
            currPPType.Traits = properList;
        }
Esempio n. 8
0
        override public void checkAndUpdateDependences(List <Trait> previouslyBoundVars, StoryData world)
        {
            PlotFragment parentFrag = world.findPlotFragmentById(_parentPlotFragmentId);

            if (parentFrag == null)
            {
                throw new Exception("Delete Object Action not have parent Plot Fragment");
            }

            //check for variables bound to object references
            List <string> names            = null;
            string        objectTypeString = "";

            if (_varObjectTypeId == world.CharTypeId)
            {
                names            = parentFrag.getPreviouslyBoundCharacterVarNames(this);
                objectTypeString = "Character";
            }
            else if (_varObjectTypeId == world.EnvTypeId)
            {
                names            = parentFrag.getPreviouslyBoundEnvironmentVarNames(this);
                objectTypeString = "Environment";
            }
            else
            {
                PlotPointType currType = world.findPlotPointTypeById(_varObjectTypeId);
                if (currType != null)
                {
                    names            = parentFrag.getPreviouslyBoundPlotPointTypeVarNames(currType, this);
                    objectTypeString = currType.Description;
                }
                else
                {
                    throw new Exception("Edit Plot Point Action in Plot Fragment \"" + parentFrag.Name + "\" " +
                                        "uses a Plot Point Type which no longer exists.");
                }
            }
            if (!(names.Contains(_varObjectName)))
            {
                throw new Exception("Edit Object Action in Plot Fragment \"" +
                                    parentFrag.Name + "\" refers to saved " + objectTypeString + " \"" + _varObjectName +
                                    "\", \nwhich has a different type or does not exist in any previous Author Goal parameters, precondition statements, or actions .");
            }

            //make sure variable for relationship target edit exists
            if ((_mode == ObjectEditingMode.RelationshipTarget) && !(names.Contains((string)_newTarget.LiteralValueOrBoundVarName)))
            {
                throw new Exception("Edit Object Action in Plot Fragment \"" +
                                    parentFrag.Name + "\" refers to saved " + objectTypeString + " \"" + (string)_newTarget.LiteralValueOrBoundVarName +
                                    "\", \nwhich has a different type or does not exist in any previous Author Goal parameters, precondition statements, or actions .");
            }



            //Check for bound primitive variables when saving trait or relationship strength
            if (
                ((_mode == ObjectEditingMode.RelationshipStrength) || (_mode == ObjectEditingMode.Trait)) &&
                (_newValue.ValueIsBoundToVariable == true)
                )
            {
                bool foundIt = false;
                foreach (Trait traitItem in previouslyBoundVars)
                {
                    if (
                        (traitItem.Name == (string)_newValue.LiteralValueOrBoundVarName) &&
                        (traitItem.Type == _newValue.Type)
                        )
                    {
                        foundIt = true;
                        break;
                    }
                }

                if (!foundIt)
                {
                    throw new Exception("Edit Object Action in Plot Fragment \"" +
                                        parentFrag.Name + "\" refers to variable \"" + (string)_newValue.LiteralValueOrBoundVarName +
                                        "\", \nwhich has a different type or does not exist in any previous Author Goal parameters, precondition statements, or actions .");
                }
            }

            //Check to make sure all trait or relationships exist on the object to be edited
            List <Trait>        traitListToCompare = new List <Trait>();
            List <Relationship> relListToCompare   = new List <Relationship>();

            if (_varObjectTypeId == world.CharTypeId)
            {
                if (world.Characters.Count > 0)
                {
                    traitListToCompare = world.Characters[0].Traits;
                    relListToCompare   = world.Characters[0].Relationships;
                }
            }
            else if (_varObjectTypeId == world.EnvTypeId)
            {
                if (world.Environments.Count > 0)
                {
                    traitListToCompare = world.Environments[0].Traits;
                    relListToCompare   = world.Environments[0].Relationships;
                }
            }
            else
            {
                PlotPointType currType = world.findPlotPointTypeById(_varObjectTypeId);
                if (currType != null)
                {
                    traitListToCompare = currType.Traits;
                }
                else
                {
                    throw new Exception("Edit Object Action in Plot Fragment \"" +
                                        parentFrag.Name + "\" refers to a Plot Point type that no longer exists.");
                }
            }

            if (_mode == ObjectEditingMode.Trait)
            {
                //look for trait we are editing
                if (null == Utilities.findTraitByNameAndType(traitListToCompare, _newValue.Name, _newValue.Type))
                {
                    throw new Exception("Edit Object Action in Plot Fragment \"" +
                                        parentFrag.Name + "\" refers to a trait with name \"" +
                                        _newValue.Name + "\" and type \"" +
                                        Trait.TraitDataTypeToString(_newValue.Type) +
                                        "\" that no longer exists.");
                }
            }
            else
            {
                //look for relationship we are editing
                if (null == Utilities.findRelationshipByName(relListToCompare, _newValue.Name))
                {
                    throw new Exception("Edit Object Action in Plot Fragment \"" +
                                        parentFrag.Name + "\" refers to a relationship with name \"" +
                                        _newValue.Name + " that no longer exists.");
                }
            }

            //No new variables to add to the binding list, so we can just exit after all the error checks
        }
        private static string generateJavaValueString(Trait input)
        {
            switch (input.Type)
            {
                case TraitDataType.TrueFalse:
                    bool val = (bool)input.Value;
                    if (val) { return "true"; } else { return "false"; }
                    break;
                case TraitDataType.Number:
                    return ((double)input.Value).ToString() + "f";
                case TraitDataType.Text:
                    return generateValidLiteralString((string)input.Value);
            }

            return "";
        }