Ejemplo n.º 1
0
 public override void Use()
 {
     base.Use();
     if (this.activeSource.IsNull())
     {
         Log.Warning("[PlayAudio] No source found for -- " + this.gameObject.name);
         return;
     }
     this.activeSource.pitch  = this.pitch.Get() == -1 ? this.activeSource.pitch : this.pitch.Get();
     this.activeSource.volume = this.volume.Get() == -1 ? this.activeSource.volume : this.volume.Get();
     this.activeSource.Play();
     if (this.order == AudioOrder.PlaySequence)
     {
         int index = this.sources.IndexOf(this.activeSource) + 1;
         if (index > this.sources.Length - 1)
         {
             index = 0;
         }
         if (index < 0)
         {
             index = this.sources.Length - 1;
         }
         this.activeSource = this.sources[index];
     }
     if (this.order == AudioOrder.PlayRandom)
     {
         int index = (int)Random.Range(0, this.sources.Length - 1);
         this.activeSource = this.sources[index];
     }
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
            }