-
Notifications
You must be signed in to change notification settings - Fork 2
/
fight_common.js
200 lines (193 loc) · 7.82 KB
/
fight_common.js
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
191
192
193
194
195
196
197
198
199
200
function fight_layout()
{
//New way to do things.
var hero,party,group,thisgroup,tag='',small;
for(party in fight.parties)
{
small=(party==player_party && get_party(party).monster);
for(group=0;group<get_party_length(party);group++)
{
//Get the object for this group
thisgroup=get_group(party,group);
//Get the group size
var count=get_group_length(party,group);
//Prepare x display offsets
var x_size=(party==player_party?160:get_picture_x(get_hero(party,group,0).html.pic));
var x_width=x_size;
if(thisgroup.characters.length>4)
x_size*=.75;
x_size=(x_size*count>720)?(720-x_width)/(count-1):x_size;
x_width=x_size*(count-1)+x_width;
var x_start=400-x_width/2.0;
//Position HTML
for(individual=0;individual<count;individual++)
{
//Get the hero
hero=get_hero(party,group,individual);
//Set the x display offest for this character
hero.x_offset=x_start+individual*x_size+(party==player_party?80-get_picture_x(hero.html.pic)/2:0);
if(small)//This IS the player's party.
{
if(hero.html.actionbox)
object_x(hero.html.actionbox,hero.x_offset);
if(x_width<160 && (individual & 1))
{
hero.y_offset=PIC_HERO_TOP;
}
else
{
hero.y_offset=PIC_HERO_BOTTOM;
}
}
else if(party==player_party) //This is a normal player party
{
hero.y_offset=PIC_HERO_BOTTOM;
}
else if(thisgroup.characters.length>4) //Large monster party
{
if(individual & 1)
{
hero.y_offset=PIC_ENEMY_TOP;
}
else
{
hero.y_offset=PIC_ENEMY_BOTTOM;
}
}
else
{
hero.y_offset=PIC_ENEMY_MID;
}
object_y_base(hero.html.pic,hero.y_offset);
object_z(hero.html.pic,find_z(hero.html.pic));
//Update the stats window
update_bar(hero.html.hp,hero.html.hpval,hero.current.HP,hero.base.HP,small);
if(hero.html.mp)
update_bar(hero.html.mp,hero.html.mpval,hero.current.MP,hero.base.MP,small);
if(hero.current.HP==0)
hide_cause_is_dead(party,group,individual);
else
show_cause_is_alive(party,group,individual);
}
}
monster_fix_hpbars(party);
}
hero_update_display();
}
function monster_fix_hpbars(party)
{
var group,character;
var object;
var x_size;
var hero;
for(group=0;group<get_party_length(party);++group)
{
object=get_hero(party,group,0).html.pic;
x_size=Math.floor(get_picture_x(object)/2)-50;
for(character=0;character<get_group_length(party,group);++character)
{
hero=get_hero(party,group,character).html.dmgbar;
if (hero)
object_x(hero,x_size);
show_hp(party,group,character);
hide_hp(party,group,character);
}
}
}
function hero_update_display()
{
var group,character;
for(group=0;group<get_party_length(player_party);++group)
for(character=0;character<get_group_length(player_party,group);++character)
{
display_action(group,character);
display_target(group,character);
}
}
function is_fight_html_loaded()
{
var count=0,hit=0,party,group,character;
for(party=0;party<get_fight_length();++party)
for(group=0;group<get_party_length(party);++group)
for(character=0;character<get_group_length(party,group);++character)
{
count++;
if(get_hero(party,group,character).html.img.complete)
hit++;
}
return [hit,count];
}
function synchronize_fight_data(fight_data)
{
var party,group,character,hero,new_hero,thisgroup,new_group;
//If the fight does not exist, then make a preliminary copy.
if(!fight)
fight=fight_data;
for(party=0;party<fight_data.parties.length;++party)
{
//If the party does not exist, then make a preliminary copy.
if(!get_party(party,true))
fight.parties[party]=fight_data.parties[party];
for(group=0;group<fight_data.parties[party].groups.length;++group)
{
//If the group does not exist, then make a preliminary copy.
if(!get_group(party,group,true))
fight.parties[party].groups[group]=fight_data.parties[party].groups[group];
for(character=0;character<fight_data.parties[party].groups[group].characters.length;++character)
{
//If the character does not exist, then make a preliminary copy.
if(!get_hero(party,group,character,true))
fight.parties[party].groups[group].characters[character]=
fight_data.parties[party].groups[group].characters[character];
hero=get_hero(party,group,character);
new_hero=fight_data.parties[party].groups[group].characters[character];
//Copy over the default stuff.
//If the character is not setup right, then setup.
if(!hero.html)
{
//Prepare the character html objects
hero.html={};
var stats=object_create_stats(party,group,character,fight_screen);
hero.html.stats=stats.stats;
hero.html.pic=stats.heropic;
hero.html.img=stats.heroimg;
hero.html.dmgbar=stats.dmgbar;
hero.html.hp=stats.hp;
hero.html.hpval=stats.hpval;
hero.html.mp=stats.mp;
hero.html.mpval=stats.mpval;
hero.html.action=stats.action;
hero.html.target=stats.target;
hero.html.actpic=stats.actpic;
hero.html.actionbox=stats.actionbox;
}
//Copy the html.
new_hero.html=hero.html;
//Set the HP and MP display variables
new_hero.HPD=new_hero.current.HP;
new_hero.HPDT=new_hero.current.HP;
new_hero.MPD=new_hero.current.MP;
new_hero.MPDT=new_hero.current.MP;
//Set the show HP gauge
new_hero.showhp=2;
new_hero.hpdisplay=null;
}
//Get the object for this group
thisgroup=get_group(party,group);
new_group=fight_data.parties[party].groups[group];
//Prepare the group html objects
if(!thisgroup.html)
{
tag=party.toString()+'-'+group.toString()
thisgroup.html={};
var group_objects=object_create_group(party,group,fight_screen);
thisgroup.html.box=group_objects.box;
thisgroup.html.group=group_objects.group;
thisgroup.html.group_text=group_objects.group_text;
}
//Copy HTML
new_group.html=thisgroup.html;
}
}
fight=fight_data;
}