-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerNpcRevive.cs
More file actions
44 lines (42 loc) · 1.63 KB
/
PlayerNpcRevive.cs
File metadata and controls
44 lines (42 loc) · 1.63 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
using UnityEngine;
using Mirror;
namespace uMMORPG
{
[DisallowMultipleComponent]
public class PlayerNpcRevive : NetworkBehaviour
{
[Header("Components")]
public Player player;
[Command]
public void CmdRevive(int index)
{
// validate: close enough, npc alive and valid index and valid item?
// use collider point(s) to also work with big entities
if (player.state == "IDLE" &&
player.target != null &&
player.target.health.current > 0 &&
player.target is Npc npc &&
npc.revive != null && // only if Npc offers revive
Utils.ClosestDistance(player, npc) <= player.interactionRange &&
0 <= index && index < player.inventory.slots.Count)
{
ItemSlot slot = player.inventory.slots[index];
if (slot.amount > 0 && slot.item.data is SummonableItem summonable)
{
// verify the pet status
if (slot.item.summonedHealth == 0 && summonable.summonPrefab != null)
{
// enough gold?
if (player.gold >= summonable.revivePrice)
{
// pay for it, revive it
player.gold -= summonable.revivePrice;
slot.item.summonedHealth = summonable.summonPrefab.health.max;
player.inventory.slots[index] = slot;
}
}
}
}
}
}
}