00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <Parse.h>
00021 #include <Utility.h>
00022
00023 #include "Create.h"
00024 #include "InSocket.h"
00025 #include "Player.h"
00026 #include "Terrain.h"
00027 #include "Area.h"
00028 #include "Chunk.h"
00029 #include "Editor.h"
00030 #include "Race.h"
00031
00032
00033 void Create::Execute(InSocket *from,const std::string& param,Parse& pa)
00034 {
00035 Player pl(from -> GetDatabase(),from -> GetAccountName());
00036 if (param == "terrain" && pl.IsWizard() )
00037 {
00038 Database& db = from -> GetDatabase();
00039 Area area(db, pl.GetArea());
00040 std::string rest = pa.getrest();
00041 if (!rest.size())
00042 {
00043 from -> SetPrompt(this, 0, "Enter terrain character to create/modify: ");
00044 }
00045 else
00046 {
00047 OnLine(from, rest, 0);
00048 }
00049 }
00050 else
00051 if (param == "area")
00052 {
00053 std::string rest = pa.getrest();
00054 if (!rest.size())
00055 {
00056 from -> SetPrompt(this, 10, "Name of new area? ");
00057 }
00058 else
00059 {
00060 OnLine(from, rest, 10);
00061 }
00062 }
00063 else
00064 if (param == "description")
00065 {
00066 Editor *e = new Editor(from, Editor::EDIT_ROOM_DESCRIPTION);
00067 e -> Init();
00068 }
00069 else
00070 if (param == "race")
00071 {
00072 int n = Race::DisplayRaces(from);
00073 from -> SetPrompt(this, 20, "Enter a race to edit (1-" + Utility::l2string(n) + ") or 0 to create: ");
00074 }
00075 else
00076 {
00077 from -> Send("Create what?\n");
00078 from -> SetPrompt();
00079 }
00080 }
00081
00082
00083 void Create::OnLine(InSocket *from,const std::string& line,int state)
00084 {
00085 Database& db = from -> GetDatabase();
00086 Player pl(db, from -> GetAccountName());
00087 Area area(db, pl.GetArea());
00088 switch (state)
00089 {
00090 case 0:
00091 if (!line.size())
00092 {
00093 from -> SetPrompt();
00094 }
00095 else
00096 if (line.size() == 1)
00097 {
00098 Terrain t(db, area, line[0]);
00099 from -> Send("Terrain character: " + line + "\n");
00100 from -> SetCommandData(line);
00101 if (t.Exists())
00102 {
00103 from -> SetPrompt(this, 1, "Modify (Y/n)? ");
00104 }
00105 else
00106 {
00107 from -> SetPrompt(this, 1, "Create (y/N)? ");
00108 }
00109 }
00110 else
00111 {
00112 from -> Send("Only one character allowed.\n");
00113 from -> SetPrompt();
00114 }
00115 break;
00116 case 1:
00117 {
00118 std::string tchar = from -> GetCommandData();
00119 Terrain t(db, area, tchar[0]);
00120 if (t.Exists())
00121 {
00122 if (!line.size() || (line[0] != 'n' && line[0] != 'N'))
00123 {
00124 from -> SetPrompt(this, 2, "Color string (" + t.GetColor() + ")? ", false);
00125 }
00126 else
00127 {
00128 from -> SetPrompt();
00129 }
00130 }
00131 else
00132 {
00133 if (line.size() && (line[0] == 'y' || line[0] == 'Y'))
00134 {
00135 t.SetChar(tchar[0]);
00136 t.Save();
00137 from -> SetPrompt(this, 2, "Color string? ");
00138 }
00139 else
00140 {
00141 from -> SetPrompt();
00142 }
00143 }
00144 }
00145 break;
00146 case 2:
00147 {
00148 std::string tchar = from -> GetCommandData();
00149 Terrain t(db, area, tchar[0]);
00150 if (line.size())
00151 {
00152 t.SetColor(line);
00153 t.Save();
00154 }
00155 if (t.GetName().size())
00156 from -> SetPrompt(this, 3, "Terrain name (" + t.GetName() + ")? ");
00157 else
00158 from -> SetPrompt(this, 3, "Terrain name? ");
00159 }
00160 break;
00161 case 3:
00162 {
00163 std::string tchar = from -> GetCommandData();
00164 Terrain t(db, area, tchar[0]);
00165 if (line.size())
00166 {
00167 t.SetName(line);
00168 t.Save();
00169 }
00170 if (t.IsImpassable())
00171 {
00172 from -> SetPrompt(this, 4, "Impassable (Y/n)? ");
00173 }
00174 else
00175 {
00176 from -> SetPrompt(this, 4, "Impassable (y/N)? ");
00177 }
00178 }
00179 break;
00180 case 4:
00181 {
00182 std::string tchar = from -> GetCommandData();
00183 Terrain t(db, area, tchar[0]);
00184 if (t.IsImpassable())
00185 {
00186 if (line.size() && (line[0] == 'n' || line[0] == 'N'))
00187 {
00188 t.SetImpassable(false);
00189 t.Save();
00190 }
00191 }
00192 else
00193 {
00194 if (line.size() && (line[0] == 'y' || line[0] == 'Y'))
00195 {
00196 t.SetImpassable();
00197 t.Save();
00198 }
00199 }
00200 if (t.Exists())
00201 {
00202 char slask[100];
00203 sprintf(slask, "Delay (%.2f sec)? ", t.GetDelay());
00204 from -> SetPrompt(this, 5, slask);
00205 }
00206 else
00207 {
00208 from -> SetPrompt(this, 5, "Delay (seconds)? ");
00209 }
00210 }
00211 break;
00212 case 5:
00213 {
00214 if (line.size())
00215 {
00216 std::string tchar = from -> GetCommandData();
00217 Terrain t(db, area, tchar[0]);
00218 t.SetDelay(atof(line.c_str()));
00219 t.Save();
00220 }
00221 from -> Send("Ok.\n");
00222 from -> SetPrompt();
00223 }
00224 break;
00225 case 10:
00226 {
00227 Area area(db, line);
00228 if (area.Exists())
00229 {
00230 from -> Sendf("An area named '%s' already exists.\n", line.c_str());
00231 from -> SetPrompt();
00232 }
00233 else
00234 {
00235 from -> SetCommandData(line);
00236 from -> SetPrompt(this, 11, "New area width (3..19)? ");
00237 }
00238 }
00239 break;
00240 case 11:
00241 {
00242 int width = atoi(line.c_str());
00243 if (width > 2 && width < 20)
00244 {
00245 from -> SetCommandData2(line);
00246 from -> SetPrompt(this, 12, "New area height (3..19)? ");
00247 }
00248 else
00249 {
00250 from -> Send("Aborted. Allowed width = 3..19\n");
00251 from -> SetPrompt();
00252 }
00253 }
00254 break;
00255 case 12:
00256 {
00257 int height = atoi(line.c_str());
00258 if (height > 2 && height < 20)
00259 {
00260 Area narea(db, from -> GetCommandData());
00261 narea.SetWidth(atoi(from -> GetCommandData2().c_str()));
00262 narea.SetHeight(height);
00263 narea.Save();
00264 narea.VerifyTerrain();
00265 Chunk nchunk(db, narea, 1000, 1000, 0);
00266 nchunk.Init(from, 1000, 1000, 0, ' ');
00267 nchunk.Save();
00268 int nx = narea.GetWidth() / 2;
00269 int ny = narea.GetHeight() / 2;
00270 Chunk chunk(db, area, pl.GetChunk());
00271 chunk.AddPortal(pl.GetChunkX(),
00272 pl.GetChunkY(),
00273 narea, nchunk, nx, ny);
00274 nchunk.AddPortal(nx, ny, area, chunk,
00275 pl.GetChunkX(),
00276 pl.GetChunkY());
00277 from -> Send("Area created.\n");
00278 from -> SetPrompt();
00279 }
00280 else
00281 {
00282 from -> Send("Aborted. Allowed height = 3..19\n");
00283 from -> SetPrompt();
00284 }
00285 }
00286 break;
00287 case 20:
00288 {
00289 long num = atol(line.c_str());
00290 if (!num && line.size() == 1 && line[0] == '0')
00291 {
00292 from -> SetCommandData(line);
00293 from -> SetPrompt(this, 21, "New race name: ");
00294 return;
00295 }
00296 Race r(db, num);
00297 if (r.Exists())
00298 {
00299 from -> SetCommandData(line);
00300 from -> SetPrompt(this, 21, "Name (" + r.GetName() + ")? ");
00301 }
00302 else
00303 {
00304 from -> Send("Race does not exist\n");
00305 from -> SetPrompt();
00306 }
00307 }
00308 break;
00309 case 21:
00310 {
00311 long num = atol(from -> GetCommandData().c_str());
00312 std::string name;
00313 if (num)
00314 {
00315 Race r(db, num);
00316 if (line.size())
00317 {
00318 r.SetName(line);
00319 r.Save();
00320 }
00321 from -> SetCommandData(r.GetName());
00322 name = r.GetName();
00323 }
00324 else
00325 if (!line.size())
00326 {
00327 from -> Send("Name required.\n");
00328 from -> SetPrompt();
00329 return;
00330 }
00331 else
00332 {
00333 Race r(db, line);
00334 r.Save();
00335 from -> SetCommandData(line);
00336 name = line;
00337 }
00338 char slask[100];
00339 Race r(db, name);
00340 sprintf(slask, "SightRange (%.1f)? ", r.GetSightRange());
00341 from -> SetPrompt(this, 22, slask);
00342 }
00343 break;
00344 case 22:
00345 {
00346 Race r(db, from -> GetCommandData());
00347 if (line.size())
00348 {
00349 r.SetSightRange(atof(line.c_str()));
00350 r.Save();
00351 }
00352 char slask[100];
00353 sprintf(slask, "Hearing (%.1f)? ", r.GetHearing());
00354 from -> SetPrompt(this, 23, slask);
00355 }
00356 break;
00357 case 23:
00358 {
00359 Race r(db, from -> GetCommandData());
00360 if (line.size())
00361 {
00362 r.SetHearing(atof(line.c_str()));
00363 r.Save();
00364 }
00365 from -> Send("Ok.\n");
00366 from -> SetPrompt();
00367 }
00368 break;
00369 }
00370 }
00371
00372