-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTML_Ship.cs
More file actions
201 lines (194 loc) · 8.7 KB
/
Copy pathHTML_Ship.cs
File metadata and controls
201 lines (194 loc) · 8.7 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
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
201
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OlyCommonClasses
{
public class HTML_Ship
{
public static void Write_Ship_HTML_File(Ship _myship, string path, List<Character> _characters, List<Itemz> _items, List<Location> _locations, List<Ship> _ships, List<Storm> _storms)
{
using (FileStream fs = new FileStream(System.IO.Path.Combine(path, _myship._ShipId + ".html"), FileMode.Create))
{
using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8))
{
w.WriteLine("<HTML>");
w.WriteLine("<HEAD>");
w.WriteLine("<TITLE>" + _myship._Name +
" [" + _myship._ShipId + "], " +
_myship._Ship_Type +
"</TITLE>");
w.WriteLine("</HEAD>");
w.WriteLine("<BODY>");
Write_Ship_Page_Header(_myship, w);
Write_Ship_Basic_Info(_myship, w, _characters, _items, _locations, _ships, _storms);
w.WriteLine("</BODY>");
w.WriteLine("</HTML>");
}
fs.Dispose();
}
}
private static void Write_Ship_Page_Header(Ship _myship, StreamWriter w)
{
StringBuilder outline3 = new StringBuilder();
outline3.Append("<H3>");
outline3.Append(_myship._Name);
outline3.Append(" [");
outline3.Append(_myship._ShipId);
outline3.Append("]");
outline3.Append(", " + _myship._Ship_Type);
outline3.Append("</H3>");
w.WriteLine(outline3);
}
private static void Write_Ship_Basic_Info(Ship _myship, StreamWriter w, List<Character> _characters, List<Itemz> _items, List<Location> _locations, List<Ship> _ships, List<Storm> _storms)
{
StringBuilder outline = new StringBuilder();
w.WriteLine("<table>");
Write_Ship_Location(_myship, w, _locations);
Write_Ship_Pct_Complete(_myship, w);
Write_Ship_Pct_Loaded(_myship, w, _characters, _items, _locations, _ships);
Write_Ship_Defense(_myship, w);
Write_Ship_Damaged(_myship, w);
Write_Ship_Owner(_myship, w, _characters);
Write_Ship_Seen_Here(_myship, w, _characters, _locations, _ships);
Write_Ship_Bound_Storm(_myship, w, _storms);
w.WriteLine("</table>");
}
private static void Write_Ship_Bound_Storm(Ship _myship, StreamWriter w, List<Storm> _storms)
{
if (_myship._SL_Bound_Storm != 0)
{
Storm _mystorm = _storms.Find(x => x._StormId == _myship._SL_Bound_Storm);
if (_mystorm != null)
{
w.WriteLine("<tr>");
w.WriteLine("<td>Bound Storm:</td>");
w.WriteLine("<td>" + _mystorm._Storm_Type + " [" + _myship._SL_Bound_Storm + "] (strength: " + _mystorm._Storm_Strength + ")</td>");
w.WriteLine("</tr>");
}
}
}
private static void Write_Ship_Seen_Here(Ship _myship, StreamWriter w, List<Character> _characters, List<Location> _locations, List<Ship> _ships)
{
List<Stack> ship_stack = new List<Stack>();
int level = 0;
ship_stack = Stack.Chase_Structure(_myship._ShipId, ship_stack, level, _characters, _locations, _ships);
if (ship_stack.Count > 1)
{
string label1 = "Seen Here:";
foreach (Stack stack_entry in ship_stack.Where(x => x._entity_type == "char"))
{
if (_characters.Find(x => x._CharId == stack_entry._entityid) != null)
{
Character _mychar = _characters.Find(x => x._CharId == stack_entry._entityid);
w.WriteLine("<tr>");
w.WriteLine("<td>" + label1 + "</td>");
label1 = "";
StringBuilder outline = new StringBuilder();
outline.Append("<td>");
for (int i = 0; i < (stack_entry._entity_level - 1); i++)
{
outline.Append("* ");
}
outline.Append(_mychar._Name + " " + Utilities.Format_Anchor(_mychar._CharId.ToString()));
outline.Append("</td>");
w.WriteLine(outline);
w.WriteLine("</tr>");
}
}
}
}
private static void Write_Ship_Owner(Ship _myship, StreamWriter w, List<Character> _characters)
{
StringBuilder outline = new StringBuilder();
w.WriteLine("<tr>");
w.WriteLine("<td>Owner:</td>");
outline.Append("<td>");
if (_myship._LI_Here_List != null)
{
if (_myship._LI_Here_List.Count > 0)
{
Character _mychar = _characters.Find(x => x._CharId == _myship._LI_Here_List[0]);
outline.Append(_mychar._Name + " " + Utilities.Format_Anchor(_mychar._CharId.ToString()));
}
else
{
outline.Append("unoccupied");
}
}
else
{
outline.Append("unoccupied");
}
outline.Append("</td>");
w.WriteLine(outline);
w.WriteLine("</tr>");
}
private static void Write_Ship_Damaged(Ship _myship, StreamWriter w)
{
w.WriteLine("<tr>");
w.WriteLine("<td>Damaged:</td>");
w.WriteLine("<td>" + _myship._SL_Damage + "%</td>");
w.WriteLine("</tr>");
}
private static void Write_Ship_Defense(Ship _myship, StreamWriter w)
{
w.WriteLine("<tr>");
w.WriteLine("<td>Defense:</td>");
w.WriteLine("<td>" + _myship._SL_Defense + "</td>");
w.WriteLine("</tr>");
}
private static void Write_Ship_Pct_Loaded(Ship _myship, StreamWriter w, List<Character> _characters, List<Itemz> _items, List<Location> _locations, List<Ship> _ships)
{
StringBuilder outline = new StringBuilder();
w.WriteLine("<td>Loaded:</td>");
outline.Append("<td>");
// calculate load of all passengers
List<Stack> ship_stack = new List<Stack>();
int level = 0;
ship_stack = Stack.Chase_Structure(_myship._ShipId, ship_stack, level, _characters, _locations, _ships);
if (ship_stack.Count > 1)
{
int total_weight = Ship.Determine_Ship_Weight(ship_stack, _characters, _items);
int actual_capacity = _myship._SL_Capacity - ((_myship._SL_Capacity * _myship._SL_Damage) / 100);
outline.Append(((total_weight * 100) / actual_capacity) + "%");
}
else
{
outline.Append("0%");
}
outline.Append("</td>");
w.WriteLine(outline);
w.WriteLine("</tr>");
}
private static void Write_Ship_Pct_Complete(Ship _myship, StreamWriter w)
{
if (_myship._SL_Effort_Given < _myship._SL_Effort_Required)
{
w.WriteLine("<tr>");
w.WriteLine("<td>Percent Complete:</td>");
w.WriteLine("<td>" + ((float)_myship._SL_Effort_Given / (float)_myship._SL_Effort_Required) * 100f + "%</td>");
w.WriteLine("</tr>");
}
w.WriteLine("<tr>");
}
private static void Write_Ship_Location(Ship _myship, StreamWriter w, List<Location> _locations)
{
StringBuilder outline = new StringBuilder();
w.WriteLine("<tr>");
w.WriteLine("<td>Location:</td>");
outline.Append("<td>");
Location _myloc = _locations.Find(x => x._LocId == Convert.ToInt32(_myship._LI_Where));
if (_myloc != null)
{
HTML_Char.Determine_Char_Location(outline, _myloc, _locations);
}
outline.Append("</td>");
w.WriteLine(outline);
outline.Clear();
w.WriteLine("</tr>");
}
}
}