Esempio n. 1
0
    public static bool CheckFeatureStatus(string strClass, string strFeature)
    {
        BlockValue ConfigurationFeatureBlock = Block.GetBlockValue("ConfigFeatureBlock");

        if (ConfigurationFeatureBlock.type == 0)
        {
            return(false);
        }

        bool result = false;

        if (ConfigurationFeatureBlock.Block.Properties.Classes.ContainsKey(strClass))
        {
            DynamicProperties dynamicProperties3 = ConfigurationFeatureBlock.Block.Properties.Classes[strClass];
            foreach (System.Collections.Generic.KeyValuePair <string, object> keyValuePair in dynamicProperties3.Values.Dict.Dict)
            {
                if (string.Equals(keyValuePair.Key, strFeature, System.StringComparison.CurrentCultureIgnoreCase))
                {
                    result = StringParsers.ParseBool(dynamicProperties3.Values[keyValuePair.Key]);
                }
            }
        }

        return(result);
    }
Esempio n. 2
0
    public static bool CheckFeatureStatus(string strClass, string strFeature)
    {
        BlockValue ConfigurationFeatureBlock = Block.GetBlockValue("ConfigFeatureBlock");

        if (ConfigurationFeatureBlock.type == 0)
        {
            // AdvLogging.DisplayLog("Configuration", "Feature: " + strFeature + " No Configuration Block");
            return(false);
        }



        bool result = false;

        if (ConfigurationFeatureBlock.Block.Properties.Classes.ContainsKey(strClass))
        {
            DynamicProperties dynamicProperties3 = ConfigurationFeatureBlock.Block.Properties.Classes[strClass];
            foreach (System.Collections.Generic.KeyValuePair <string, object> keyValuePair in dynamicProperties3.Values.Dict.Dict)
            {
                if (string.Equals(keyValuePair.Key, strFeature, System.StringComparison.CurrentCultureIgnoreCase))
                {
                    result = StringParsers.ParseBool(dynamicProperties3.Values[keyValuePair.Key]);
                }
            }
        }

        //  UnityEngine.Debug.Log(" Configuration:  " + strClass + " : " + strFeature + " : Result: " + result);
        //ConsoleCmdAIDirectorDebug.("Configuration", "Feature: " + strFeature + " Result: " + result);
        return(result);
    }
Esempio n. 3
0
 // don't open the loot container.
 public override bool OnBlockActivated(WorldBase _world, int _cIdx, Vector3i _blockPos, BlockValue _blockValue, EntityAlive _player)
 {
     if (_blockValue.Block.Properties.Values.ContainsKey("IsContainer"))
     {
         bool IsContainer = StringParsers.ParseBool(_blockValue.Block.Properties.Values["IsContainer"], 0, -1, true);
         if (IsContainer)
         {
             base.OnBlockActivated(_world, _cIdx, _blockPos, _blockValue, _player);
             return(true);
         }
     }
     return(true);
 }
Esempio n. 4
0
    public override string GetActivationText(WorldBase _world, BlockValue _blockValue, int _clrIdx, Vector3i _blockPos, EntityAlive _entityFocusing)
    {
        if (_blockValue.Block.Properties.Values.ContainsKey("ActivateOnLook"))
        {
            bool ActivateOnLook = StringParsers.ParseBool(_blockValue.Block.Properties.Values["ActivateOnLook"], 0, -1, true);
            if (ActivateOnLook)
            {
                AdvLogging.DisplayLog(AdvFeatureClass, _blockValue.Block.GetBlockName() + ": Activating Block on GetActivationText");

                TriggerOnly = true;
                ActivateBlock(_world, _clrIdx, _blockPos, _blockValue, true, true);
                TriggerOnly = false;
            }
        }
        return("");
    }
        public static bool Prefix(Mod __instance, string _path)
        {
            string text     = _path + "/ModInfo.xml";
            string fileName = Path.GetFileName(_path);

            if (!File.Exists(text))
            {
                return(false);
            }

            string _content = File.ReadAllText(text);
            PositionXmlDocument positionXmlDocument = new PositionXmlDocument();

            try
            {
                using (Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(_content ?? "")))
                {
                    positionXmlDocument.Load(XmlReader.Create(stream));
                }
            }
            catch (XmlException e)
            {
                return(true);  // Let vanilla deal with it.
            }

            // Scan for Enabled XML property and decided to enable or disable it.
            XmlNode documentElement = positionXmlDocument.DocumentElement;
            XmlNode enabledNode     = documentElement.SelectSingleNode("//Enabled");

            if (enabledNode != null)
            {
                XmlElement _elem = enabledNode as XmlElement;
                if (_elem != null)
                {
                    if (_elem.HasAttribute("value"))
                    {
                        bool enabled = StringParsers.ParseBool(_elem.GetAttribute("value"));
                        if (enabled == false)
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
    public override bool ParseXmlAttribute(XmlAttribute _attribute)
    {
        bool flag = base.ParseXmlAttribute(_attribute);

        if (!flag)
        {
            string name = _attribute.Name;
            if (name != null)
            {
                if (name == "hide")
                {
                    hide = StringParsers.ParseBool(_attribute.Value);
                }
            }
        }
        return(flag);
    }
Esempio n. 7
0
        public static bool AllowedRandomSize(EntityAlive entity)
        {
            bool bRandomSize = false;

            if (entity is EntityZombie)
            {
                bRandomSize = true;
            }

            EntityClass entityClass = EntityClass.list[entity.entityClass];

            if (entityClass.Properties.Values.ContainsKey("RandomSize"))
            {
                bRandomSize = StringParsers.ParseBool(entityClass.Properties.Values["RandomSize"], 0, -1, true);
            }

            return(bRandomSize);
        }
Esempio n. 8
0
        public static bool AllowedRandomSize(EntityAlive entity)
        {
            bool bRandomSize = false;

            if (entity is EntityZombie)
            {
                AdvLogging.DisplayLog(AdvFeatureClass, " Random Size: Is A Zombie. Random size is true");
                bRandomSize = true;
            }
            EntityClass entityClass = EntityClass.list[entity.entityClass];

            if (entityClass.Properties.Values.ContainsKey("RandomSize"))
            {
                bRandomSize = StringParsers.ParseBool(entityClass.Properties.Values["RandomSize"], 0, -1, true);
            }

            AdvLogging.DisplayLog(AdvFeatureClass, "Entity: " + entity.DebugNameInfo + " Random Size:  " + bRandomSize);
            return(bRandomSize);
        }
Esempio n. 9
0
        public static bool Postfix(bool __result, TileEntity __instance)
        {
            // if it's already active, don't check.
            if (__result)
            {
                return(__result);
            }

            BlockValue block          = GameManager.Instance.World.GetBlock(__instance.ToWorldPos());
            Block      block2         = Block.list[block.type];
            bool       isAlwaysActive = false;

            if (block2.Properties.Values.ContainsKey("AlwaysActive"))
            {
                isAlwaysActive = StringParsers.ParseBool(block2.Properties.Values["AlwaysActive"], 0, -1, true);
                if (isAlwaysActive)
                {
                    return(true);
                }
            }

            return(__result);
        }
Esempio n. 10
0
    public override bool ParseXmlAttribute(XmlAttribute _attribute)
    {
        bool flag = base.ParseXmlAttribute(_attribute);

        if (!flag)
        {
            string name = _attribute.Name;
            if (name != null)
            {
                if (name == "cameraName")
                {
                    Camera = _attribute.Value;
                    return(true);
                }
                if (name == "value")
                {
                    CameraStatus = StringParsers.ParseBool(_attribute.Value, 0, -1, true);
                    return(true);
                }
            }
        }
        return(flag);
    }
Esempio n. 11
0
        public static bool Postfix(bool ___result, TileEntity __instance, World world)
        {
            BlockValue block          = GameManager.Instance.World.GetBlock(__instance.ToWorldPos());
            Block      block2         = Block.list[block.type];
            bool       isAlwaysActive = false;

            if (block2.Properties.Values.ContainsKey("AlwaysActive"))
            {
                isAlwaysActive = StringParsers.ParseBool(block2.Properties.Values["AlwaysActive"], 0, -1, true);
                if (isAlwaysActive)
                {
                    ___result = true;
                    AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": TileEntity is Active.");
                    bool blCanTrigger = false;

                    int Bounds = 6;
                    if (block2.Properties.Values.ContainsKey("ActivationDistance"))
                    {
                        Bounds = StringParsers.ParseSInt32(block2.Properties.Values["ActivationDistance"].ToString());
                    }

                    // Scan for the player in the radius as defined by the Activation distance of the block
                    List <Entity> entitiesInBounds = GameManager.Instance.World.GetEntitiesInBounds(null, new Bounds(__instance.ToWorldPos().ToVector3(), (Vector3.one * 20)));
                    if (entitiesInBounds.Count > 0)
                    {
                        AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": TileEntity has Entities in Bound of " + Bounds);
                        for (int i = 0; i < entitiesInBounds.Count; i++)
                        {
                            EntityPlayer player = entitiesInBounds[i] as EntityPlayer;
                            if (player)
                            {
                                float distance = (player.position - __instance.ToWorldPos().ToVector3()).sqrMagnitude;
                                if (distance > block2.GetActivationDistanceSq())
                                {
                                    continue;
                                }

                                AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": Player: " + player.EntityName + " is in bounds");

                                if (block2.Properties.Values.ContainsKey("ActivationBuffs"))
                                {
                                    foreach (String strbuff in block2.Properties.Values["ActivationBuffs"].Split(','))
                                    {
                                        AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": Checking ActivationBuffs: " + strbuff);
                                        String strBuffName = strbuff;
                                        float  CheckValue  = -1f;

                                        // Check if there's a ( ) at the end of the buff; this will be used as a cvar hook.
                                        int start = strbuff.IndexOf('(');
                                        int end   = strbuff.IndexOf(')');
                                        if (start != -1 && end != -1 && end > start + 1)
                                        {
                                            CheckValue  = StringParsers.ParseFloat(strbuff.Substring(start + 1, end - start - 1), 0, -1, NumberStyles.Any);
                                            strBuffName = strbuff.Substring(0, start);
                                            AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": Actviation Buff is a cvar: " + strBuffName + ". Requires value: " + CheckValue);
                                        }

                                        // If the player has a buff by this name, trigger it.
                                        if (player.Buffs.HasBuff(strBuffName))
                                        {
                                            AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": Buff has been found: " + strBuffName);
                                            blCanTrigger = true;
                                        }

                                        // If the player has a cvar, then do some extra checks
                                        if (player.Buffs.HasCustomVar(strBuffName))
                                        {
                                            AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": Cvar has been found: " + strBuffName);
                                            // If there's no cvar value specified, just allow it.
                                            if (CheckValue == -1)
                                            {
                                                AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": Cvar found, and does not require a specific value.");
                                                blCanTrigger = true;
                                            }
                                            // If a cvar is set, then check to see if it matches
                                            if (CheckValue > -1)
                                            {
                                                AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": Cvar found, and requires a value of " + CheckValue + " Player has: " + player.Buffs.GetCustomVar(strBuffName));
                                                if (player.Buffs.GetCustomVar(strBuffName) == CheckValue)
                                                {
                                                    blCanTrigger = true;
                                                }
                                            }

                                            // If any of these conditions match, trigger the Activate block
                                            if (blCanTrigger)
                                            {
                                                AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ":  Checks successfully passed for player: " + player.EntityName);
                                                break;
                                            }
                                            else
                                            {
                                                AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": Checks were NOT success for player: " + player.EntityName);
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    blCanTrigger = true;
                                }

                                if (blCanTrigger)
                                {
                                    break;
                                }
                            }
                        }
                    }

                    if (blCanTrigger)
                    {
                        AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": TileEntity can call ActivateBlock. Calling it...");
                        Block.list[block.type].ActivateBlock(world, __instance.GetClrIdx(), __instance.ToWorldPos(), block, true, true);
                    }
                    else
                    {
                        AdvLogging.DisplayLog(AdvFeatureClass, block2.GetBlockName() + ": TileEntity is Active but is not Activating.");
                        Block.list[block.type].ActivateBlock(world, __instance.GetClrIdx(), __instance.ToWorldPos(), block, false, true);
                    }
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 12
0
        public static bool CheckWorkstationForPower(TileEntity myTileEntity)
        {
            AdvLogging.DisplayLog(AdvFeatureClass, "Does Workstation have access to Fuel?");
            bool blNeedsPower = false;

            // Read the block properties whenever we check, since we don't really persists whether or not we need power.
            BlockValue block = GameManager.Instance.World.GetBlock(myTileEntity.ToWorldPos());
            Block block2 = Block.list[block.type];
            blNeedsPower = false;
            if (block2.Properties.Values.ContainsKey("RequirePower"))
                blNeedsPower = StringParsers.ParseBool(block2.Properties.Values["RequirePower"], 0, -1, true);

            AdvLogging.DisplayLog(AdvFeatureClass, "Require Power? : " + blNeedsPower);

            // Doesn't need any power, so don't check.
            if (blNeedsPower == false)
                return true;

            AdvLogging.DisplayLog(AdvFeatureClass, "Workstation requires power. Checking near by tile entities.");

            // Check the nearby chunks for Power source tile entities, and check if they are on.
            Vector3i blockPosition = myTileEntity.ToWorldPos();
            World world = GameManager.Instance.World;
            int num = World.toChunkXZ(blockPosition.x);
            int num2 = World.toChunkXZ(blockPosition.z);
            for (int i = -1; i < 2; i++)
            {
                for (int j = -1; j < 2; j++)
                {
                    Chunk chunk = (Chunk)world.GetChunkSync(num + j, num2 + i);
                    if (chunk != null)
                    {
                        DictionaryList<Vector3i, TileEntity> tileEntities = chunk.GetTileEntities();
                        for (int k = 0; k < tileEntities.list.Count; k++)
                        {
                            AdvLogging.DisplayLog(AdvFeatureClass, "\tDetected Tile Entity: " + tileEntities.list[k].ToString());
                            TileEntityPowerSource tileEntity = tileEntities.list[k] as TileEntityPowerSource;
                            if (tileEntity != null)
                            {
                                if (tileEntity.IsActive(world))
                                    AdvLogging.DisplayLog(AdvFeatureClass, "\tEntity is Avtive " + tileEntities.list[k].ToString());
                                if (tileEntity.IsOn)
                                {
                                    AdvLogging.DisplayLog(AdvFeatureClass, "\tTile Entity is On: " + tileEntities.list[k].ToString());
                                    float distanceSq = (blockPosition.ToVector3() - tileEntity.ToWorldPos().ToVector3()).sqrMagnitude;
                                    if (distanceSq <= 20 * 20)
                                    {
                                        AdvLogging.DisplayLog(AdvFeatureClass, myTileEntity.ToString() + " Found Power Source as Fuel with " + tileEntity.ToString());
                                        //myTileEntity.HasPowerSDX = true;
                                        return true;
                                    }
                                }
                                else
                                    AdvLogging.DisplayLog(AdvFeatureClass, "\tTile Entity is off: " + tileEntities.list[k].ToString());
                            }
                        }
                    }
                }
            }
            return false;
        }