Skip to content

Commit

Permalink
Merge pull request Interkarma#2087 from KABoissonneault/feat/loot-eve…
Browse files Browse the repository at this point in the history
…nt-handlers

Added two event handlers for loot spawning
  • Loading branch information
Interkarma committed Apr 27, 2021
2 parents f3391f9 + 52d91ac commit ce11e06
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Assets/Scripts/Game/Entities/EnemyEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,36 @@

namespace DaggerfallWorkshop.Game.Entity
{
/// <summary>
/// The parameters involved in creating an enemy loot pile
/// </summary>
public class EnemyLootSpawnedEventArgs : System.EventArgs
{
/// <summary>
/// The Mobile object used for the enemy
/// </summary>
public MobileEnemy MobileEnemy { get; set; }

/// <summary>
/// The Career template of the enemy
/// </summary>
public DFCareer EnemyCareer { get; set; }

/// <summary>
/// The collection containing all the items of the loot pile. New items can be added
/// </summary>
public ItemCollection Items { get; set; }
}

/// <summary>
/// Implements DaggerfallEntity with properties specific to enemies.
/// </summary>
public class EnemyEntity : DaggerfallEntity
{
#region Fields

public static System.EventHandler<EnemyLootSpawnedEventArgs> OnLootSpawned;

int careerIndex = -1;
EntityTypes entityType = EntityTypes.None;
MobileEnemy mobileEnemy;
Expand Down Expand Up @@ -346,6 +369,8 @@ public void SetEnemyCareer(MobileEnemy mobileEnemy, EntityTypes entityType)
DaggerfallLoot.RandomlyAddPotionRecipe(2, items);
}

OnLootSpawned?.Invoke(this, new EnemyLootSpawnedEventArgs { MobileEnemy = mobileEnemy, EnemyCareer = career, Items = items });

FillVitalSigns();
}

Expand Down
29 changes: 29 additions & 0 deletions Assets/Scripts/Game/Items/LootTables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@

namespace DaggerfallWorkshop.Game.Items
{
/// <summary>
/// The parameters involved in creating a loot pile from a loot table.
/// </summary>
public class TabledLootSpawnedEventArgs : System.EventArgs
{
/// <summary>
/// The index of the location.
/// For Dungeons, this corresponds to DFRegion.DungeonTypes.
/// For Interiors, this corresponds to DFRegion.LocationTypes.
/// </summary>
public int LocationIndex { get; set; }

/// <summary>
/// The Key used to spawn the loot pile (ex: "K" for Crypt loot).
/// </summary>
public string Key { get; set; }

/// <summary>
/// The collection containing all the items of the loot pile. New items can be added.
/// </summary>
public ItemCollection Items { get; set; }
}

/// <summary>
/// Built-in loot tables.
/// Currently just for testing during early implementation.
Expand All @@ -25,6 +48,9 @@ namespace DaggerfallWorkshop.Game.Items
/// </summary>
public static class LootTables
{
// When a Loot pile is generated from a loot table
public static System.EventHandler<TabledLootSpawnedEventArgs> OnLootSpawned;

/// <summary>
/// Default loot table chance matrices.
/// Note: Temporary implementation. Will eventually be moved to an external file and loaded as keyed dict.
Expand Down Expand Up @@ -133,6 +159,9 @@ public static bool GenerateLoot(DaggerfallLoot loot, int locationIndex)
DaggerfallLoot.RandomlyAddPotion(4, loot.Items);
DaggerfallLoot.RandomlyAddPotionRecipe(2, loot.Items);
}

OnLootSpawned?.Invoke(null, new TabledLootSpawnedEventArgs { LocationIndex = locationIndex, Key = lootTableKeys[locationIndex], Items = loot.Items });

return true;
}
return false;
Expand Down

0 comments on commit ce11e06

Please sign in to comment.