-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonsterInventory.cs
More file actions
56 lines (50 loc) · 1.79 KB
/
MonsterInventory.cs
File metadata and controls
56 lines (50 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using UnityEngine;
using Mirror;
namespace uMMORPG
{
[DisallowMultipleComponent]
public class MonsterInventory : Inventory
{
[Header("Components")]
public Monster monster;
[Header("Loot")]
public int lootGoldMin = 0;
public int lootGoldMax = 10;
public ItemDropChance[] dropChances;
public ParticleSystem lootIndicator;
// note: Items have a .valid property that can be used to 'delete' an item.
// it's better than .RemoveAt() because we won't run into index-out-of
// range issues
[ClientCallback]
void Update()
{
// show loot indicator on clients while it still has items
if (lootIndicator != null)
{
// only set active once. we don't want to reset the particle
// system all the time.
bool hasLoot = HasLoot();
if (hasLoot && !lootIndicator.isPlaying)
lootIndicator.Play();
else if (!hasLoot && lootIndicator.isPlaying)
lootIndicator.Stop();
}
}
// other scripts need to know if it still has valid loot (to show UI etc.)
public bool HasLoot()
{
// any gold or valid items?
return monster.gold > 0 || SlotsOccupied() > 0;
}
[Server]
public void OnDeath()
{
// generate gold
monster.gold = Random.Range(lootGoldMin, lootGoldMax);
// generate items (note: can't use Linq because of SyncList)
foreach (ItemDropChance itemChance in dropChances)
if (Random.value <= itemChance.probability)
slots.Add(new ItemSlot(new Item(itemChance.item)));
}
}
}