source: AE/packages/31000GlassBreakingMoves/patches/common/level0_Final/TRAM-getupfront-.oni-patch@ 971

Last change on this file since 971 was 965, checked in by iritscen, 11 years ago

Latest version of glass-breaking patch (this ONCC patch does not work, though). Removed DangerousGlass as it is now a package on Depot.

File size: 5.1 KB
Line 
1@XML_TOOLS Version "2.0"
2
3@CUSTOM_CODE
4<code>
5 // |———————————————————————————————————Code best viewed at this width————————————————————————————————————————|
6
7 // Load XML data
8 var myBuilder = new JSXMLBuilder();
9 myBuilder.load($xmlData);
10 var elements = myBuilder.elements[0];
11
12 // If there are no attacks in this TRAM, ignore it
13 if (!elements.childElement("Animation").childElement("Attacks"))
14 return;
15
16 // Gather all the necessary info
17 var particles = elements.childElement("Animation").childElement("Particles");
18 var attack = elements.childElement("Animation").childElement("Attacks").childElement("Attack");
19 var hit_start = attack.childElement("Start").text;
20 var hit_end = attack.childElement("End").text;
21 var array_bones = attack.childElement("Bones").text.split(" ");
22
23 // Remove glass_break if it is already assigned to any bones, because it's probably not been assigned the
24 // way we want it to be
25 for (var i = 0; (particles.childElement(i)); i++)
26 {
27 var particle = particles.childElement(i);
28 if (particle.childElement("Name").text == "glass_break")
29 myBuilder.removeElement(particle.index);
30 }
31
32 // Find the outermost bone of each type
33 // The "type" in bone_type[] refers to the extremity of the body to which a bone belongs ("mid" counts as
34 // as an extremity because the head is part of "mid"); this is a "parallel array" with array_bones[]
35 var bone_type = new Array(19);
36 // The "ext" in bone_ext[] refers to the "outermostness" of the bone, that is, how far out on the extremity
37 // this bone is; this is a parallel array with array_bones[]
38 var bone_ext = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
39 // The extremity_ arrays are parallel arrays which store the highest "outermostness" value found for each
40 // extremity, among all the bones in that extremity that are listed in the attack
41 var extremity_name = ["mid", "left_arm", "right_arm", "left_leg", "right_leg"];
42 var extremity_max = [0, 0, 0, 0, 0];
43 for (var i = 0; i < array_bones.length; i++)
44 {
45 var bone = array_bones[i];
46 if (bone == "Head" || bone == "Neck" || bone == "Chest" || bone == "Mid" || bone == "Pelvis")
47 {
48 bone_type[i] = "mid";
49 if (bone == "Neck")
50 bone_ext[i] = 1;
51 else if (bone == "Head")
52 bone_ext[i] = 2;
53 // The rest of these bones are extremity '0'
54 }
55 else if (bone == "LeftShoulder" || bone == "LeftArm" || bone == "LeftWrist" || bone == "LeftFist")
56 {
57 bone_type[i] = "left_arm";
58 if (bone == "LeftShoulder")
59 bone_ext[i] = 1;
60 else if (bone == "LeftArm")
61 bone_ext[i] = 2;
62 else if (bone == "LeftWrist")
63 bone_ext[i] = 3;
64 else if (bone == "LeftFist")
65 bone_ext[i] = 4;
66 }
67 else if (bone == "RightShoulder" || bone == "RightArm" || bone == "RightWrist" || bone == "RightFist")
68 {
69 bone_type[i] = "right_arm";
70 if (bone == "RightShoulder")
71 bone_ext[i] = 1;
72 else if (bone == "RightArm")
73 bone_ext[i] = 2;
74 else if (bone == "RightWrist")
75 bone_ext[i] = 3;
76 else if (bone == "RightFist")
77 bone_ext[i] = 4;
78 }
79 else if (bone == "LeftThigh" || bone == "LeftCalf" || bone == "LeftFoot")
80 {
81 bone_type[i] = "left_leg";
82 if (bone == "LeftThigh")
83 bone_ext[i] = 1;
84 else if (bone == "LeftCalf")
85 bone_ext[i] = 2;
86 else if (bone == "LeftFoot")
87 bone_ext[i] = 3;
88 }
89 else if (bone == "RightThigh" || bone == "RightCalf" || bone == "RightFoot")
90 {
91 bone_type[i] = "right_leg";
92 if (bone == "RightThigh")
93 bone_ext[i] = 1;
94 else if (bone == "RightCalf")
95 bone_ext[i] = 2;
96 else if (bone == "RightFoot")
97 bone_ext[i] = 3;
98 }
99 }
100
101 // Find outermost bone for each extremity, among the bones listed in the Attack
102 for (var a = 0; a < array_bones.length; a++)
103 {
104 for (var b = 0; b < extremity_name.length; b++)
105 {
106 if (extremity_name[b] == bone_type[a])
107 {
108 if (bone_ext[a] > extremity_max[b])
109 extremity_max[b] = bone_ext[a];
110 }
111 }
112 }
113
114 // Add a glass_break particle for every outermost bone in the attack
115 for (var a = 0; a < array_bones.length; a++)
116 {
117 // Move to next bone if this is not the outermost attacking bone on this extremity
118 var add_this_bone = false;
119 for (var b = 0; b < extremity_name.length; b++)
120 {
121 if (bone_type[a] == extremity_name[b])
122 {
123 if (bone_ext[a] == extremity_max[b])
124 add_this_bone = true;
125 }
126 }
127 if (!add_this_bone)
128 continue;
129
130 // Exit if we are past Oni's limit on TRAM particles
131 if (particles.length >= 16)
132 {
133 echo("Reached maximum of 16 particles for this TRAM, exiting…");
134 return;
135 }
136
137 echo("Adding glass_break to " + array_bones[a]);
138 var par_string = "<Start>" + hit_start + "</Start><End>" + hit_end + "</End><Bone>" + array_bones[a] + "</Bone><Name>glass_break</Name>";
139
140 // Add glass_break to bone for time period that bone has collision status
141 myBuilder.addElementAt("Particle",
142 "",
143 par_string,
144 particles.index + 1,
145 particles.level + 1);
146 }
147
148 // Update the global variable with the new XML
149 $xmlData = myBuilder.generateXML();
150</code>
Note: See TracBrowser for help on using the repository browser.