示例#1
0
        /*
         * Name: OnEntityDeath
         * Parameters: BaseCombatEntity entity, HitInfo info
         * Return: None
         * Description: Called when any thing is killed.
         */
        void OnEntityDeath(BaseCombatEntity entity, HitInfo info)
        {
            // If the BaseCombatEntity is null then don't proceed any further.
            if (entity == null)
            {
                return;
            }

            // If BaseCombatEntity is an High External Wall.
            if (entity.ShortPrefabName.Contains("wall.external.high") == true)
            {
                // Obtain the ExternalWallController component from the BaseCombatEntity.
                ExternalWallController controller = entity.gameObject.GetComponent <ExternalWallController>();

                // Declare an empty variable.
                ExternalWallController controllerLink;

                // If the ExternalWallController component can't be found in the BaseCombatEntity then don't proceed any further.
                if (controller == null)
                {
                    return;
                }

                // Declare an empty variable.
                BaseEntity linkEntity;

                // Go through the list of ExternalWallLink(s) in the ExternalWallController component.
                foreach (ExternalWallLink externalLink in controller.entityLinks())
                {
                    // Get the BaseEntity that owns the ExternalWallLink component.
                    linkEntity = externalLink.entity();

                    // If the BaseEntity is null then move to the next ExternalWallLink.
                    if (linkEntity == null)
                    {
                        continue;
                    }

                    // Obtain the ExternalWallController component from the current BaseEntity
                    controllerLink = linkEntity.gameObject.GetComponent <ExternalWallController>();

                    // If the ExternalWallController component couldn't be found then move to the next ExternalWallLink.
                    if (controllerLink == null)
                    {
                        continue;
                    }

                    // Sever link between the BaseCombatEntity and the current BaseEntity.
                    controllerLink.entityLinks().RemoveWhere(link => link.entity() == null || link.entity().gameObject == entity.gameObject);
                }
            }
        }
示例#2
0
        /*
         * Name: OnRemovedEntity
         * Parameters: BaseEntity entity
         * Return: None
         * Description: Called when any structure is removed by the removal tool.
         */
        void OnRemovedEntity(BaseEntity entity)
        {
            // If the BaseEntity is null then don't proceed any further.
            if (entity == null)
            {
                return;
            }

            // If the BaseEntity is an High External Wall.
            if (entity.ShortPrefabName.Contains("wall.external.high") == true)
            {
                // If the entity is being removed.
                if (this.removingEntity.Contains(entity) == true)
                {
                    // Remove the entity from the list of BaseEntity(s).
                    this.removingEntity.Remove(entity);
                    // Don't proceed any further.
                    return;
                }
                else
                {
                    // If the entity isn't being removed then add it to the list of BaseEntity(s).
                    this.removingEntity.Add(entity);
                }

                // Obtain the ExternalWallController component from the BaseEntity('s) game object.
                ExternalWallController controller = entity.gameObject.GetComponent <ExternalWallController>();

                // If the ExternalWallController component wasn't found then don't proceed any further.
                if (controller == null)
                {
                    return;
                }

                // Declare empty variable.
                BaseEntity linkEntity;

                // Get the owner of the BaseEntity.
                BasePlayer player = BasePlayer.Find(entity.OwnerID.ToString());

                // Go through the list of ExternalWallLink(s) in the ExternalWallController component.
                foreach (ExternalWallLink externalLink in controller.entityLinks())
                {
                    // If the ExternalWallLink isn't being removed.
                    if (externalLink.isRemoving == false)
                    {
                        // Remove the ExternalWallLink.
                        externalLink.isRemoving = true;

                        // Get the BaseEntity that owns the ExternalWallLink component.
                        linkEntity = externalLink.entity();

                        // If the BaseEntity is null then move to the next ExternalWallLink.
                        if (linkEntity == null)
                        {
                            continue;
                        }

                        // If the player is required to use materials.
                        if (this.configRequireMaterials == true)
                        {
                            // Create the High External Wall and give it to the player.
                            Item item = ItemManager.CreateByName(entity.ShortPrefabName, 1);
                            player.inventory.GiveItem(item, null);
                            player.Command("note.inv", item.info.itemid, item.amount);
                        }

                        // Kill the BaseEntity.
                        linkEntity.Kill(BaseNetworkable.DestroyMode.Gib);
                    }
                }
            }
        }