// vim:ts=2 sw=2
/**
* @class Action
* @brief Handles all actions to the server
* @author Sean Kasun
* @date 2000-2002
*/
/*****
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*****/
#include "uop.h"
#include <iostream>
#include <sstream>
#include "action.h"
#include "interfacehandler.h"
#include "cliloc.h"
#include "network.h"
#include "uopconfig.h"
#include "serverhandler.h"
extern InterfaceHandler *interfaceHandler;
extern vector<Cliloc *>intlocs;
extern vector<Cliloc *>clilocs;
extern Cliloc *profession;
extern Network *network;
extern UOPConfig *config;
extern ServerHandler *serverHandler;
static char *skills[]={
"Alchemy","Anatomy","AnimalLore","ItemIdentification","ArmsLore",
"Parrying","Begging","Blacksmith","Bowcraft","Peacemaking","Camping",
"Carpentry","Cartography","Cooking","DetectHidden","Enticement",
"EvaluateIntelligence","Healing","Fishing","ForensicEvaluation",
"Hearding","Hiding","Provocation","Inscription","Lockpicking",
"Magery","ResistingSpells","Tactics","Snooping","Musicianship",
"Poisoning","Archery","SpiritSpeak","Stealing","Tailoring",
"AnimalTaming","TasteIdentification","Tinkering","Tracking",
"Veterinary","Swordsmanship","MaceFighting","Fencing","Wrestling",
"Lumberjacking","Mining",NULL
};
/**
* Creates a new action class
* This also initializes charCreate and other variables
*/
Action::Action()
{
memset(createData,0,104);
createData[0]=0;
*(Uint32*)(createData+1)=0xedededed;
*(Uint32*)(createData+5)=0xffffffff;
walkDir=0;
walkSeq=0;
}
Action::~Action()
{
}
/**
* Signs on to the server.
* Switches to the verify screen, sends the login information to the
* server.
* @note if uoconfig->sphereCompat is set, it sends a blank key
*/
void Action::signOn(string &username,string &password)
{
string sip = config->serverIP();
interfaceHandler->removeAllGumps();
interfaceHandler->message(intlocs[0]->getString(3));
interfaceHandler->addGump("MessageBoxCancel",&Action::signOff);
network->connect(sip, config->serverPort());
if (network->uo)
serverHandler->pAcctLoginReq(username,password);
}
void Action::signOff()
{
interfaceHandler->removeAllGumps();
interfaceHandler->addGump("accountlogin");
network->disconnect();
}
void Action::selectServer(Uint8 server)
{
interfaceHandler->removeAllGumps();
interfaceHandler->message(intlocs[0]->getString(53));
interfaceHandler->addGump("MessageBoxCancel",&Action::signOff);
serverHandler->pBritanniaSelect(server);
}
void Action::selectCharacter(Uint8 chr)
{
interfaceHandler->removeAllGumps();
interfaceHandler->message(intlocs[0]->getString(1));
interfaceHandler->addGump("MessageBoxCancel",&Action::signOff);
serverHandler->pPreLogin(chr);
}
void Action::createCharacter(Uint8 chr)
{
createData[94]=chr>>8;
createData[95]=chr&0x255;
interfaceHandler->removeAllGumps();
interfaceHandler->addGump("loginmenu");
interfaceHandler->addGump("charcreation-appearance");
}
void Action::selectHair(Uint8 hair)
{
Uint16 id;
id=0;
switch (hair)
{
case 1: id=0x203b; break;
case 2: id=0x203c; break;
case 3: id=0x203d; break;
case 4: id=0x2044; break;
case 5: id=0x204a; break;
case 6: id=0x2045; break;
case 7: id=0x2047; break;
case 8: id=0x2048; break;
case 9: id=0x2049; break;
case 10: id=0x2046; break;
}
(*(Uint16 *)(createData+82))=SDL_SwapBE16(id);
}
void Action::selectBeard(Uint8 beard)
{
Uint16 id;
id=0;
switch (beard)
{
case 1: id=0x2040; break;
case 2: id=0x203e; break;
case 3: id=0x203f; break;
case 4: id=0x2041; break;
case 5: id=0x204b; break;
case 6: id=0x204c; break;
case 7: id=0x204d; break;
}
(*(Uint16 *)(createData+86))=SDL_SwapBE16(id);
}
void Action::selectSkinHue(Uint16 hue)
{
(*(Uint16 *)(createData+80))=SDL_SwapBE16(hue);
}
void Action::selectHairHue(Uint16 hue)
{
(*(Uint16 *)(createData+84))=SDL_SwapBE16(hue);
}
void Action::selectBeardHue(Uint16 hue)
{
(*(Uint16 *)(createData+88))=SDL_SwapBE16(hue);
}
void Action::selectShirtHue(Uint16 hue)
{
(*(Uint16 *)(createData+100))=SDL_SwapBE16(hue);
}
void Action::selectPantHue(Uint16 hue)
{
(*(Uint16 *)(createData+102))=SDL_SwapBE16(hue);
}
void Action::selectName(string &name)
{
strncpy((char *)createData+10,name.c_str(),30);
interfaceHandler->removeAllGumps();
interfaceHandler->addGump("loginmenu");
interfaceHandler->primeText(profession->getString(28));
interfaceHandler->addGump("charcreation-profession");
professions.clear();
loadProfessions();
GumpVList *vlist=interfaceHandler->getVList(110007);
map<string,Profession *>::iterator i;
for (i=professions.begin();i!=professions.end();i++)
if ((*i).second->topLevel)
vlist->add(new GumpVListChild((*i).second->desc+110007*100,
"professionoption",(*i).second->desc));
vlist->add(new GumpVListChild(0+110007*100,"advancedoption",0));
interfaceHandler->setProfession(profession->getString(28));
}
void Action::selectProfession(Uint8 prof)
{
if (prof==0) //advanced
{
showAdvanced();
return;
}
Profession *selected=NULL;
map<string,Profession *>::iterator i;
for (i=professions.begin();i!=professions.end();i++)
if ((*i).second->desc==prof)
selected=(*i).second;
if (!selected) return;
if (selected->category)
{
interfaceHandler->removeAllGumps();
interfaceHandler->addGump("loginmenu");
interfaceHandler->primeText(profession->getString(selected->desc+29));
interfaceHandler->addGump("charcreation-profession");
GumpVList *vlist=interfaceHandler->getVList(110007);
list<string>::iterator child;
for (child=selected->children.begin();child!=selected->children.end();
child++)
{
Profession *childProf=professions[*child];
if (childProf)
vlist->add(new GumpVListChild(childProf->desc+110007*100,
"professionoption",childProf->desc));
}
}
else
{
createData[71]=selected->str;
createData[72]=selected->dex;
createData[73]=selected->intl;
list<Uint8>::iterator skill;
int j=0;
for (skill=selected->skills.begin();skill!=selected->skills.end();skill++)
createData[74+(j++)*2]=*skill;
j=0;
for (skill=selected->skillVals.begin();skill!=selected->skillVals.end();skill++)
createData[75+(j++)*2]=*skill;
serverHandler->pLogin(createData);
}
}
void Action::showAdvanced()
{
interfaceHandler->removeAllGumps();
interfaceHandler->addGump("loginmenu");
interfaceHandler->primeText(profession->getString(29));
interfaceHandler->addGump("charcreation-profession");
interfaceHandler->addGump("charcreation-profadvanced");
}
void Action::loadProfessions()
{
Profession *curProf=NULL;
string profname=config->encapDatLoc("prof.txt");
ifstream prof;
prof.open(profname.c_str(),ios::in);
if (!prof.is_open())
{
cerr<<"Couldn't open "<<profname<<endl;
exit(1);
}
string key,line,val;
Uint8 vali;
while (std::getline(prof,line,'\n'))
{
istringstream s(line);
key="";
s>>key;
if (key=="Begin") curProf=new Profession();
if (key=="Name") s>>curProf->name;
if (key=="Desc")
{
s>>curProf->desc;
curProf->desc++;
}
if (key=="TopLevel")
{
s>>val;
if (val=="true") curProf->topLevel=true;
}
if (key=="Gump") s>>curProf->gump;
if (key=="Type")
{
s>>val;
if (val=="Category") curProf->category=true;
}
if (key=="Children")
while (std::getline(s,val,','))
{
istringstream ss(val);
ss>>val;
curProf->children.push_back(val);
}
if (key=="Skill")
{
s>>val>>vali;
for (int i=0;skills[i];i++)
if (val==skills[i]) curProf->skills.push_back(i);
curProf->skillVals.push_back(vali);
}
if (key=="Stat")
{
s>>val>>vali;
if (val=="Str") curProf->str=vali;
if (val=="Dex") curProf->dex=vali;
if (val=="Int") curProf->intl=vali;
}
if (key=="End")
professions[curProf->name]=curProf;
}
prof.close();
}
Profession::Profession()
{
desc=gump=str=dex=intl=0;
topLevel=category=false;
}