-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSelector.as
190 lines (170 loc) · 5.21 KB
/
Selector.as
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// Select and return character objects for use in other programs
import com.GameInterface.CharacterCreation.CharacterCreation;
import com.GameInterface.Game.Character;
import com.GameInterface.Game.Dynel;
import com.Utils.ID32;
import mx.data.types.Int;
class Selector
{
private var m_PlayField:Number;
private var m_X:Number;
private var m_Y:Number;
private var m_Z:Number;
private var m_Distance:Number; // distance from X,Z
private var m_yDistance:Number; // distance from Y
private var m_Gender:Number;
public function Selector()
{
}
// If set, objects must be at the specified location
public function SetLocation(playField:Number, x:Number, y:Number, z:Number, distance:Number, yDistance:Number, waypointName:String)
{
//ULog.Info("Selector.SetLocation(): playField=" + playField.toString() + ", x=" + x.toString() + ", y=" + y.toString() + ", z=" + z.toString());
m_PlayField = playField;
m_X = x;
m_Y = y;
m_Z = z;
m_Distance = distance;
m_yDistance = yDistance;
}
// Not used: API doesn't return gender of NPC
// If specified, character must be the specified gender
/* public function SetGender(gender:String)
{
gender = gender.toLowerCase();
if (gender == "male") {
m_Gender = _global.Enums.BreedSex.e_Sex_Male;
} else {
m_Gender = _global.Enums.BreedSex.e_Sex_Female;
}
}
*/
// Select player character
public function SelectPlayer() : Character
{
var player:Character = Character.GetClientCharacter();
return player;
}
// Select friendly target
public function SelectFriendlyTarget() : Character
{
var player:Character = this.SelectPlayer();
var targetID:ID32 = player.GetDefensiveTarget();
var target:Character = Character.GetCharacter(targetID);
return target;
}
// Select enemy target
public function SelectEnemyTarget() : Character
{
var player:Character = this.SelectPlayer();
var targetID:ID32 = player.GetOffensiveTarget();
var target:Character = Character.GetCharacter(targetID);
return target;
}
// Select a single NPC by name
public function SelectNPC(npcNames:String) : Character
{
var npc:Character;
// Call SelectNPCs() and get first object from collection
var npcs:Object = this.SelectNPCs(npcNames, 1);
for (var prop in npcs) {
npc = npcs[prop];
break;
}
return npc;
}
// Select NPCs by name
public function SelectNPCs(npcNames:String, qty:Number) : Object
{
var npcs:Object = new Object();
if (qty == undefined || qty == NaN || qty < 1) {
qty = 1;
}
// Split names into array and make lower case
var names:Array = npcNames.split(",");
for (var i:Number = 0; i < names.length; i++)
{
names[i] = names[i].toLowerCase();
}
// Search nearby Dynels for NPCs
ULog.Info("SelectNPCS -- qty: " + qty + " npcNames: " + npcNames);
var qtyFound = 0;
var nearDynels:Object = _root.interactioncontroller.m_InteractionDynels;
var npc:Character;
var npcName:String;
for (var prop in nearDynels) {
// Old dynels may stay in collection as undefined
// Make sure valid first, or there could be performance delays
if (nearDynels[prop]) {
npcName = nearDynels[prop].GetName().toLowerCase();
//ULog.Info("SelectNPCS -- npcName: " + npcName);
for (var i:Number = 0; i < names.length; i++)
{
if (names[i] == "*" || npcName == names[i]) {
ULog.Info("SelectNPCS -- Name Match: " + npcName);
npc = Character.GetCharacter(nearDynels[prop].GetID());
if (this.CheckLocation(npc) == true) {
npcs[prop] = npc;
qtyFound++;
break;
}
}
}
// If quantity met, stop searching
if (qtyFound >= qty)
{
break;
}
}
}
ULog.Info("SelectNPCS -- qtyFound: " + qtyFound);
ULog.Info("SelectNPCS -- npcs: " + npcs);
return npcs;
}
// Check if object is within specified location
public function CheckLocation(dynel:Dynel) : Boolean
{
// If no location set, return
//_root.fifo.SlotShowFIFOMessage("m_PlayField: " + m_PlayField);
if (m_PlayField == undefined || m_PlayField == NaN)
{
return true;
}
// Check if object is in correct playfield and location
var inLocation = false;
var currentField = dynel.GetPlayfieldID();
//_root.fifo.SlotShowFIFOMessage("currentField: " + currentField);
if (currentField == m_PlayField) {
var position = dynel.GetPosition();
var currentX = position.x;
var currentY = position.y;
var currentZ = position.z;
var xDist = Math.abs(currentX - m_X);
var yDist = Math.abs(currentY - m_Y);
var zDist = Math.abs(currentZ - m_Z);
// See if we are in range of coordinates
if (Math.abs(currentX - m_X) <= m_Distance && Math.abs(currentZ - m_Z) <= m_Distance && Math.abs(currentY - m_Y) <= m_yDistance) {
inLocation = true;
}
}
//_root.fifo.SlotShowFIFOMessage("inLocation: " + inLocation);
return inLocation;
}
// Not Used: API doesn't return gender for NPCs
// Check if character is specified gender
/* public function CheckGender(character:Character) : Boolean
{
if (m_Gender == undefined)
{
return true;
}
var sex_YesPlease:Number = character.GetStat(_global.Enums.Stat.e_Sex);
ULog.Info("CheckGender -- sex_YesPlease=" + sex_YesPlease + " m_Gender=" + m_Gender);
if (sex_YesPlease == m_Gender) {
return true;
} else {
return false;
}
}
*/
}