Beispiel #1
0
 /*
  * Name: addLink
  * Parameters: ExternalWallLink linkEntity
  * Return: None
  * Description: Add a *new* entry to the list of ExternalWallLink(s).
  */
 public void addLink(ExternalWallLink linkEntity)
 {
     // If the variable links doesn't contain argument.
     if (this.links.Contains(linkEntity) == false)
     {
         // Add the ExternalWallLink to the list of ExternalWallLink(s).
         this.links.Add(linkEntity);
     }
 }
Beispiel #2
0
        /*
         * Name: CreateStackWall
         * Parameters: int amount, BaseEntity entity, BasePlayer player
         * Return: HashSet<ExternalWallLink>
         * Description: Creates the high external walls that stack on top of the first high external wall.
         */
        private HashSet <ExternalWallLink> CreateStackWall(int amount, BaseEntity entity, BasePlayer player)
        {
            // If the value of amount is less than 1 then set the value of amount to 1 else set the value of amount to the value of amount.
            amount = (amount < 1) ? 1 : amount;

            // Create an emply "list" that will contain ExternalWallLink(s).
            HashSet <ExternalWallLink> links = new HashSet <ExternalWallLink>();

            // If the configuration key "RequireMaterials" is set to true.
            if (this.configRequireMaterials == true)
            {
                // Find the item's definition for the type of high external wall that is being placed.
                ItemDefinition itemDefinition = ItemManager.FindItemDefinition(entity.ShortPrefabName);

                // Count how much high external walls the user has in their inventory.
                int canPlaceAmount = player.inventory.GetAmount(itemDefinition.itemid);

                // Subtract how much high external walls the user has in their inventory by one.
                canPlaceAmount = canPlaceAmount - 1;

                // If the amount of high external walls the user has in their inventory is less than one then return an empty list of ExternalWallLink(s).
                if (canPlaceAmount < 1)
                {
                    return(links);
                }

                // If the amount of high external walls the users has in their inventory is greater than the amount allowed to be placed then set the value of amount to the value of amount...
                // ...else set the value of amount to the value of how much high external walls the user has in their inventory.
                amount = (canPlaceAmount > amount) ? amount : canPlaceAmount;

                // Take # (based now the value of amount) of high external walls from the player.
                player.inventory.Take(new List <Item>(), itemDefinition.itemid, amount);
                // Notify the player of how much high external walls are being taken out of their inventory.
                player.Command("note.inv", itemDefinition.itemid, -amount);
            }

            // Create an emply ExternalWallLink.
            ExternalWallLink entityLink;

            // Loop until the value of index is greater than the value of amount plus one.
            for (int index = 1; index < amount + 1; index++)
            {
                // Create an high external wall.
                BaseEntity wall = GameManager.server.CreateEntity(entity.PrefabName, entity.transform.position + new Vector3(0f, 5.5f * (float)index, 0f), entity.transform.rotation, true);
                // Activate the high external wall game object.
                wall.gameObject.SetActive(true);
                // Spawn the high external wall game object.
                wall.Spawn();
                // Notify the server of the placement and rotation changes of the high external wall.
                wall.TransformChanged();

                // Get the BaseCombatEntity component of the high external wall.
                BaseCombatEntity combatEntity = wall.GetComponentInParent <BaseCombatEntity>();

                // If the component can be found.
                if (combatEntity != null)
                {
                    // Change the health of the high external wall to max health.
                    combatEntity.ChangeHealth(combatEntity.MaxHealth());
                }

                // Set the owner of the high external wall to the player.
                wall.OwnerID = player.userID;

                // Tell the server to to send a update to the players for the high external wall.
                wall.SendNetworkUpdate(BasePlayer.NetworkQueue.Update);

                // Set the ExternalWallLink's game object to the high external wall's game object.
                entityLink = new ExternalWallLink(wall.gameObject);

                // Add the ExternalWallLink to the list of ExternalWallLink(s).
                links.Add(entityLink);
            }

            // Return the list of ExternalWallLink(s).
            return(links);
        }
Beispiel #3
0
        /*
         * Name: OnEntityBuilt
         * Parameters: Planner planner, GameObject gameObject
         * Return: None
         * Description: Called when any structure is built (walls, ceilings, stairs, etc.).
         */
        void OnEntityBuilt(Planner planner, GameObject gameObject)
        {
            // If the argument for planner is null or the argument for gameObject is null then don't proceed any further.
            if (planner == null || gameObject == null)
            {
                return;
            }

            // Obtain the BaseEntity component from the game object a store it into the variable baseEntity.
            BaseEntity baseEntity = gameObject.GetComponent <BaseEntity>();

            // If the BaseEntity component was found or the planner doesn't have an owner then don't proceed any further.
            if (baseEntity == null || planner.GetOwnerPlayer() == null)
            {
                return;
            }

            // Obtain the owner of the planner.
            BasePlayer player = planner.GetOwnerPlayer();

            // If the entity is a High External Wall and the player has wall stacking enabled.
            if (baseEntity.ShortPrefabName.Contains("wall.external.high") == true && this.playerToggleCommand.Contains(player.userID))
            {
                // Declare empty variales.
                BaseEntity                 linkingEntity;
                ExternalWallController     linkingExternalController;
                HashSet <ExternalWallLink> externalLinks;

                // Set the value of the variable externalLinks to the return value of the function CreateStackWall.
                externalLinks = this.CreateStackWall(this.configStackHeight, baseEntity, player);

                // If the list of ExternalWallLink(s) is not empty.
                if (externalLinks.Count > 0)
                {
                    // Create a new ExternalWallLink for the game object and store it in the variable initialExternalLink.
                    ExternalWallLink initialExternalLink = new ExternalWallLink(gameObject);
                    // Add the value of the variable initialExternalLink to the list of ExternalWallLink(s).
                    externalLinks.Add(initialExternalLink);

                    // Go through the list of ExternalWallLink(s).
                    foreach (ExternalWallLink externalLink in externalLinks)
                    {
                        // Set the value of the variable linkingEntity to the current ExternalWallLink('s) BaseEntity.
                        linkingEntity = (BaseEntity)externalLink.entity();

                        // If the BaseEntity component was found.
                        if (linkingEntity != null)
                        {
                            // Add the ExternalWallController to the current game object.
                            linkingExternalController = linkingEntity.gameObject.AddComponent <ExternalWallController>();

                            // Go through the list of ExternalWallLink(s).
                            foreach (ExternalWallLink externalAddLinkage in externalLinks)
                            {
                                // If the current link is the parent current link then continue (skip it).
                                if (externalAddLinkage == externalLink)
                                {
                                    continue;
                                }

                                // Link the other ExternalWallLink(s) to the ExternalWallController.
                                linkingExternalController.addLink(externalAddLinkage);
                            }
                        }
                    }
                }
            }

            // Set the value of the variable baseEntity to null.
            baseEntity = null;
        }