Drop System - AlexisBliesener/Bewitched GitHub Wiki

Overview

The Drop System is an upgrade system that allows enemies to drop collectible items when defeated. Players can pick up these drops to receive random upgrade choices. Refer to upgrades details for more details.

Designer Guide

Setting Up the Drop System

  1. Add Drop System to Scene:

    • Add the DropSystem prefab to the scene
      • DropSystem prefab can be found in /Assets/Prefabs/DropSystem/DropSystem.prefab
    • The DropSystem is a singleton - only one should exist per scene
    • Configure the drop chance percentage
      • Drop Chance % -> chance an enemy drops an item.
      • Salvage Amount -> amount of health restored if the player salvages a drop.
    • Assign the drop pickup prefab (the spinning 3D model)
  2. Creating New Rarities:

    • Open the DropSystem in the inspector.
    • Add a new entry under Available Rarities.
    • Set display name ("Common", "Rare", "Ultra Rare", etc...)
    • Set drop chance percentage (1-100%)
    • Higher percentages = more likely to drop
  3. Creating New Drop Items:

    • Add a new entry to Available Drops in the DropSystem.
    • Fill in:
      • Drop Name
      • Description
      • Icon
      • Rarity -> chosen from a dropdown (shown from the available rarities)
      • Drop Script -> a prefab of GameObject that implements IDrop.

Enemy Integration

This code runs when an enemy is defeated:

DropSystem.Instance.TryDropItem(transform.position);

The system will:

  1. Check the drop chance percentage
  2. If successful, spawn a pickup at the enemy position
  3. The pickup will spin and wait for player interaction

Developer Guide

Classes

DropData (Serializable Class)

  • Metadata for each drop:
    • Name
    • Description
    • Icon
    • Rarity (via index lookup in DropSystem)
    • Drop Script (GameObject implementing IDrop)

ItemRarity (Serializable Class)

  • Defines rarity tiers.
  • Display Name
  • Drop Chance %

DropPickup (Pickup Behavior)

  • Handle the spinning 3D model behavior
  • Detect player collision
  • Trigger drop selection event

IDrop (Interface)

  • Every drop must implement this interface:
public interface IDrop
{
    void Activate();
}

Creating Custom Drops

  1. Create a new script and implement IDrop.
  2. Override the Activate() method to apply the effect.
using UnityEngine;

/// <summary>
/// HealthBoost drop implementation
/// </summary>
public class HealthBoost : MonoBehaviour, IDrop
{
    /// <summary>
    /// Implement the drop's functionality
    /// </summary>
    public void Activate()
    {
        base.Activate();
        
        
    }
}

Event System

The Drop System use events to notify the UI when a drop is picked up:

public class UIDropHandler : MonoBehaviour
{
    private void OnEnable()
    {
        // Subscribe to drop pickup events
        DropSystem.Instance.OnDropRandomDrop += HandleDropPickup;
    }

    private void OnDisable()
    {
        // Unsubscribe from events
        DropSystem.Instance.OnDropRandomDrop -= HandleDropPickup;
    }

    private void HandleDropPickup(DropData option1, DropData option2)
    {
        // Show UI with both options
        ShowDropSelectionUI(option1, option2);
    }
    
    private void ShowDropSelectionUI(DropData option1, DropData option2)
    {
        // Display UI showing both drop options
        // Call DropSystem.Instance.SelectDropsOption(chosenOption);
        // Or call DropSystem.Instance.SalvageDrop(); to skip both
        // Name of the drop? option1.GetDropName();
        // Description of the drop? option1.GetDescription();
        // etc..
    }
}

Drop Selection Flow

  1. Enemy is defeated -> TryDropItem() called
  2. System checks drop chance -> spawns pickup if successful
  3. Player touch pickup -> ShowDropSelection() triggered
  4. System selects 2 random drops based on rarity
  5. OnDropRandomDrop event fired with both options
  6. UI displays options to player
  7. Player chooses -> UI calls SelectDropsOption() or SalvageDrop()
  8. Finally, the chosen drop's Activate() method is called
⚠️ **GitHub.com Fallback** ⚠️