Exemple #1
0
 public virtual void UpdateRequirements()
 {
     foreach (StateRow[] table in this.tables)
     {
         foreach (StateRow row in table)
         {
             if (this.controller.IsEnabled())
             {
                 foreach (StateRowData rowData in row.requirements)
                 {
                     var external = rowData.data.Where(x => x.name == "@External").FirstOrDefault();
                     if (external.IsNull())
                     {
                         external            = new StateRequirement("@External", this.controller, this);
                         external.requireOn  = table == this.tables[0];
                         external.requireOff = table == this.tables[1];
                         rowData.data        = rowData.data.Add(external);
                     }
                     external.target = this.controller;
                 }
             }
             foreach (StateRowData rowData in row.requirements)
             {
                 List <StateRequirement> requirements = new List <StateRequirement>(rowData.data);
                 this.RemoveDuplicates <StateRequirement>(ref requirements);
                 this.RepairUnmatched <StateRequirement>(ref requirements);
                 this.AddUpdate <StateRequirement>(ref requirements);
                 this.RemoveNull <StateRequirement>(ref requirements);
                 rowData.data = requirements.ToArray();
             }
         }
     }
 }
Exemple #2
0
        public static BlockType ReadBlockType(this StreamReader reader, int id, string name, string reference)
        {
            try
            {
                BlockType blockType = new BlockType(id, name, reference);
                reader.ReadAttributes(blockType, (key, value) =>
                {
                    EcfAttribute a = null;
                    switch (key)
                    {
                    // bool
                    case "AboveTerrainCheck":
                    case "IsAccessible":
                    case "IsIgnoreLC":
                    case "IsLockable":
                    case "ShowBlockName":
                    case "TurretTargetIgnore":
                        a = new AttributeBool(value == "true");
                        break;

                    // int
                    case "BlastDamage":
                    case "BlastRadius":
                    case "CPUIn":
                    case "CPUOut":
                    case "EnergyIn":
                    case "EnergyInIdle":
                    case "EnergyOut":
                    case "FuelCapacity":
                    case "HitPoints":
                    case "MaxCount":
                    case "O2Capacity":
                    case "PanelAngle":
                    case "RotSpeed":
                    case "ShieldCapacity":
                    case "ShieldCooldown":
                    case "ShieldPerCrystal":
                    case "ShieldRecharge":
                    case "StackSize":
                    case "Temperature":
                    case "TemperatureGain":
                    case "ThrusterForce":
                    case "Torque":
                    case "UnlockCost":
                    case "UnlockLevel":
                    case "XpFactor":
                        a = new AttributeInt(int.Parse(value));
                        break;

                    // colour
                    case "BlockColor":
                        Match cm = Regex.Match(value, "(?<red>\\d+)\\s*,\\s*(?<green>\\d+)\\s*,\\s*(?<blue>\\d+)");
                        if (cm.Success)
                        {
                            byte r = byte.Parse(cm.Groups["red"].Value);
                            byte g = byte.Parse(cm.Groups["green"].Value);
                            byte b = byte.Parse(cm.Groups["blue"].Value);
                            a      = new AttributeColour(r, g, b);
                        }
                        else
                        {
                            throw new Exception("Unable to parse BlockColor attribute.");
                        }
                        break;

                    // string
                    case "Category":
                    case "Group":
                    case "Info":
                    case "IsOxygenTight":
                    case "Material":
                    case "TechTreeParent":
                    case "TemplateRoot":
                    case "WeaponItem":
                        a = new AttributeString(value);
                        break;

                    // string[]
                    case "ChildBlocks":
                    case "FuelAccept":
                    case "O2Accept":
                    case "TechTreeNames":
                        a = new AttributeStringArray(value != null ? Regex.Split(value, "\\s*,\\s*") : null);
                        break;

                    // float
                    case "HVEngineDampCoef":
                    case "HVEngineDampPow":
                    case "Mass":
                    case "MaxVolumeCapacity":
                    case "Radiation":
                    case "ReturnFactor":
                    case "SolarPanelEfficiency":
                    case "Volume":
                    case "VolumeCapacity":
                    case "Zoom":
                        a = new AttributeFloat(float.Parse(value));
                        break;

                    default:
                        Console.WriteLine($"Unknown block attribute: {key}");
                        break;
                    }

                    return(a);
                }, null);

                return(blockType);
            }
            catch (System.Exception ex)
            {
                throw new Exception("Failed reading item", ex);
            }
        }
Exemple #3
0
        public static ItemType ReadItemType(this StreamReader reader, int id, string name, string reference)
        {
            try
            {
                ItemType itemType = new ItemType(id, name, reference);

                reader.ReadAttributes(itemType, (key, value) =>
                {
                    EcfAttribute a = null;
                    switch (key)
                    {
                    // int
                    case "Armor":
                    case "BlastDamage":
                    case "BlastRadius":
                    case "Cold":
                    case "Durability":
                    case "FoodDecayTime":
                    case "Heat":
                    case "NrSlots":
                    case "Oxygen":
                    case "Radiation":
                    case "StackSize":
                    case "UnlockCost":
                    case "UnlockLevel":
                        a = new AttributeInt(int.Parse(value));
                        break;

                    // string[]
                    case "AllowAt":
                    case "TechTreeNames":
                        a = new AttributeStringArray(value != null ? Regex.Split(value, "\\s*,\\s*") : null);
                        break;

                    // bool
                    case "PickupToToolbar":
                    case "RadialMenu":
                        a = new AttributeBool(value.ToLower() == "true");
                        break;

                    // string
                    case "Category":
                    case "TechTreeParent":
                        a = new AttributeString(value);
                        break;

                    // float
                    case "DegradationProb":
                    case "FallDamageFac":
                    case "FoodFac":
                    case "JetpackFac":
                    case "JumpFac":
                    case "Mass":
                    case "PowerFac":
                    case "Range":
                    case "SpeedFac":
                    case "StaminaFac":
                    case "Volume":
                    case "VolumeCapacity":
                        a = new AttributeFloat(float.Parse(value));
                        break;

                    default:
                        Console.WriteLine($"Unknown item attribute: {key}");
                        break;
                    }
                    return(a);
                }, (s, o) =>
                {
                    if (ParseChildNodeHeader(s, out string childType, out string childName))
                    {
                        // TODO: Verify that childType == "" and childName == ""
                        OperationMode child = reader.ReadOperationMode(-1, childName, null);
                        ((ItemType)o).OperationModes.Add(child);
                    }
                });

                return(itemType);
            }