예제 #1
0
        internal static ItemInstance FromXML(XElement xml, Game g)
        {
            ItemInstance i = new ItemInstance(new ItemRef {
                LinkedItemId = Guid.Parse(xml.Element("ItemId").Value)
            }.LinkedItem);

            if (xml.Element("Name").Value != null && xml.Element("Name").Value != "")
            {
                i.CurrentName = xml.Element("Name").Value;
            }
            if (xml.Element("IconPath").Value != null && xml.Element("IconPath").Value != "")
            {
                i.CurrentIconPath = new ImageRef {
                    Path = xml.Element("IconPath").Value
                };
            }
            if (xml.Element("CanBeDropped").Value != null && xml.Element("CanBeDropped").Value != "")
            {
                i.CanBeDropped = Convert.ToBoolean(xml.Element("IconPath").Value);
            }
            foreach (var property in xml.Element("Properties").Elements("Property").Where(a => i.Properties.ContainsKey(a.Element("Name").Value)))
            {
                var propObj = i.Properties[property.Element("Name").Value];
                var propVar = VariableWrapper.FromXML(property.Element("Value").Element("Variable"), g, propObj.VariableBase);
                propObj.CurrentCommonEventValue = propVar.CurrentCommonEventValue;
                propObj.CurrentStringValue      = propVar.CurrentStringValue;
                propObj.CurrentNumberValue      = propVar.CurrentNumberValue;
                propObj.CurrentItemValue        = propVar.CurrentItemValue;
            }

            return(i);
        }
예제 #2
0
 public ItemInstance(Item i)
 {
     item        = i;
     CurrentName = i.DefaultName;
     if (!string.IsNullOrWhiteSpace(i.Icon))
     {
         CurrentIconPath = new ImageRef {
             Path = Editor.MainViewModel.AbsolutePath(MainViewModel.GetMainViewModelStatic().Location, i.Icon)
         };
     }
     else
     {
         CurrentIconPath = new ImageRef {
             Path = ""
         };
     }
     foreach (var property in i.ItemProperties)
     {
         var baseVar = property.BaseVariable;
         var wrapper = new VariableWrapper(baseVar);
         if (!property.UseDefaultValue)
         {
             if (baseVar.IsDateTime)
             {
                 wrapper.CurrentDateTimeValue = Convert.ToDateTime(property.Value);
             }
             else if (baseVar.IsNumber)
             {
                 wrapper.CurrentNumberValue = Convert.ToInt32(property.Value);
             }
             else if (baseVar.IsString)
             {
                 wrapper.CurrentStringValue = Convert.ToString(property.Value);
             }
             this.Properties.Add(property.Name, wrapper);
         }
         else
         {
             wrapper.CurrentDateTimeValue = baseVar.DefaultDateTime;
             wrapper.CurrentNumberValue   = baseVar.DefaultNumber;
             wrapper.CurrentStringValue   = baseVar.DefaultString;
             this.Properties.Add(property.Name, wrapper);
         }
     }
     this.CanBeDropped = i.Removable;
 }
        public static StatusEffectWrapper FromXML(XElement xml, Game g)
        {
            var seRef = GenericRef <StatusEffect> .GetStatusEffectRef();

            seRef.Ref = Guid.Parse(xml.Element("LinkedStatusEffect").Value);
            StatusEffectWrapper wrapper = new StatusEffectWrapper(seRef, g);

            foreach (var tempVariableXml in xml.Element("TempVariables").Elements())
            {
                var tempVariable = VariableWrapper.FromXML(tempVariableXml, g, g.VarById[Guid.Parse(tempVariableXml.Element("Id").Value)].VariableBase);
                foreach (var a in wrapper.TempVariables)
                {
                    if (a.VariableBase.Id == tempVariable.VariableBase.Id)
                    {
                        a.CurrentCommonEventValue = tempVariable.CurrentCommonEventValue;
                        a.CurrentDateTimeValue    = tempVariable.CurrentDateTimeValue;
                        a.CurrentItemValue        = tempVariable.CurrentItemValue;
                        a.CurrentNumberValue      = tempVariable.CurrentNumberValue;
                        a.CurrentStringValue      = tempVariable.CurrentStringValue;
                    }
                }
            }
            foreach (var a in xml.Element("Arguments").Elements("Argument"))
            {
                Guid id = Guid.Parse(a.Element("Id").Value);

                if (a.Element("Type").Value == "number")
                {
                    wrapper.numberArguments.Add(new ScriptStatusEffectArgumentValue {
                        IsNumber = true, Id = id, NumberValue = Convert.ToInt32(a.Element("Value").Value)
                    });
                }
                else
                {
                    wrapper.stringArguments.Add(new ScriptStatusEffectArgumentValue {
                        IsString = true, Id = id, StringValue = a.Element("Value").Value
                    });
                }
            }

            return(wrapper);
        }
 public bool?Execute(bool dontCopyLocals = false)
 {
     TextResult.Clear();
     if (parent == null && !dontCopyLocals)
     {
         foreach (var a in MainViewModel.GetMainViewModelStatic().CurrentGame.VarById.Where(a => a.Value.VariableBase.Name.StartsWith("_")))
         {
             var wrapper = new VariableWrapper(a.Value.VariableBase);
             if (!localVars.ContainsKey(a.Key))
             {
                 localVars.Add(a.Key, wrapper);
                 localVarsByName.Add(a.Value.VariableBase.Name, a.Value);
             }
         }
     }
     foreach (var line in ScriptBase.ScriptLines.Where(a => a.GetType() != typeof(CommentWrapper)))
     {
         ScriptLineWrapper currentLine = ScriptLineWrapper.GetScriptLineWrapper(line, this);
         if (currentLine != null)
         {
             var result = currentLine.Execute();
             //Stop executing the script once a return statement has been triggered.
             if (result != null)
             {
                 return(result);
             }
         }
         if (StopExecution)
         {
             if (this.parent != null && !this.IsRootScript)
             {
                 this.parent.StopExecution = true;
             }
             break;
         }
         //currentLine.Dispose();
     }
     return(null);
 }
        public void DupeVars(ScriptWrapper s)
        {
            ScriptWrapper parent = s;

            while (parent != null && parent.localVars.Count() == 0)
            {
                parent = parent.parent;
            }
            if (parent != null)
            {
                foreach (var a in parent.localVars)
                {
                    VariableWrapper vw = new VariableWrapper(a.Value.VariableBase);
                    vw.CurrentCommonEventValue = a.Value.CurrentCommonEventValue;
                    vw.CurrentDateTimeValue    = a.Value.CurrentDateTimeValue;
                    vw.CurrentItemValue        = a.Value.CurrentItemValue;
                    vw.CurrentNumberValue      = a.Value.CurrentNumberValue;
                    vw.CurrentStringValue      = a.Value.CurrentStringValue;
                    localVars.Add(a.Key, vw);
                    localVarsByName.Add(a.Value.VariableBase.Name, vw);
                }
            }
        }