-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrapController.cs
141 lines (121 loc) · 5.03 KB
/
TrapController.cs
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
///This script will get the info sent by each trap to keep a list of traps
///in the escene. Every x second, it will check distance with trap with each
///PC and if within distance -> do a dice roll to detect traps.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using PixelCrushers.DialogueSystem;
public class TrapController : MonoBehaviour {
public List<GameObject> traps = new List<GameObject>();
public List<GameObject> secrets = new List<GameObject>();
void Start ()
{
//We need to add players, but from LoadGame!!
foreach (GameObject go in traps)
{
Debug.Log(go);
}
}
public void CheckPerPlayer (GameObject player)
{
foreach (GameObject trap in traps)
{
if (trap.GetComponent<Trap>().discovered == false)
{
float distance = Vector3.Distance(player.transform.position, trap.transform.position);
if (distance <= 12.0f)
{
CheckSkill(player, trap);
}
}
}
foreach (GameObject secret in secrets)
{
if (secret.GetComponent<SecretDoor>().discovered == false)
{
float distance = Vector3.Distance(player.transform.position, secret.transform.position);
if (distance <= 12.0f)
{
CheckSkillSecret(player, secret);
}
}
}
}
void CheckSkill (GameObject player, GameObject trap)
{
if (trap.GetComponent<Trap>() != null)
{
if (trap.GetComponent<Trap>().numberAttempt > 16)
{
return;
}
else
{
CheckDificulty(trap);
trap.GetComponent<Trap>().numberAttempt++;
int skill = player.GetComponent<PlayerStats>().totDetect;
if (skill <= 0)
{
skill = -20;
}
int difficulty = trap.GetComponent<Trap>().detectDifficulty;
int dice = Random.Range(1, 101);
if (dice < (skill - difficulty))
{
// disarmed = true;
string nameObj = trap.name + "Trap";
string scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
// DialogueLua.SetActorField(scene, nameObj, "No");
if (trap.GetComponent<Trap>().discovered == false)
{
trap.GetComponent<Trap>().Discover();
GetComponent<DisplayInfo>().AddText(player.name + " discovered a trap! Skill :" + skill + "/dice roll : " + dice + "/Difficulty: " + difficulty);
if (player.name == "Player")
{
string nameToDisplay = DialogueLua.GetActorField("Player", "playerName").AsString;
DialogueManager.ShowAlert(nameToDisplay + " discovered a trap!");
}
else
{
DialogueManager.ShowAlert(player.name + " discovered a trap!");
}
}
}
}
}
else if (trap.GetComponent<TrapFloor>() != null)
{
}
}
void CheckSkillSecret (GameObject player, GameObject secret)
{
int skill = player.GetComponent<PlayerStats>().totDetect;
int difficulty = secret.GetComponent<SecretDoor>().detectDifficulty;
int dice = Random.Range(1, 101);
// GetComponent<DisplayInfo>().AddText("Skill :" + skill + "/dice roll : " + dice + "/Difficulty: " + difficulty);
if (dice < (skill - difficulty))
{
// disarmed = true;
string nameObj = secret.name + "Secret";
string scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
DialogueManager.ShowAlert(player.name + " discovered a secret!");
GetComponent<DisplayInfo>().AddText(player.name + " discovered a secret! Skill :" + skill + "/dice roll : " + dice + "/Difficulty: " + difficulty);
DialogueLua.SetActorField(scene, nameObj, "Revealed");
if (secret.GetComponent<SecretDoor>().discovered == false)
{
secret.GetComponent<SecretDoor>().Discover();
}
}
}
void CheckDificulty(GameObject trap)
{
if (trap.GetComponent<Trap>().numberAttempt == 6)
{
trap.GetComponent<Trap>().difficulty = trap.GetComponent<Trap>().difficulty - 5;
}
else if (trap.GetComponent<Trap>().numberAttempt == 11)
{
trap.GetComponent<Trap>().difficulty = trap.GetComponent<Trap>().difficulty - 5;
}
}
}