void GameFlow::Shop() { ActionList actions; actions.AddAction("[B] Buy"); actions.AddAction("[S] Sell"); actions.AddAction("[X] Leave"); Map->GetCharacter()->PrintInfo(); actions.PrintActions(); char action=GetUserInput(actions); while(action!='X') { system("cls"); Map->GetCharacter()->PrintInfo(); //cout<<"Market:"<<endl; if(action=='B') { //set the level of the items available int highlevel=Map->GetCurrentTile()->GetLevel()+4; int lowlevel=Map->GetCurrentTile()->GetLevel()-4; if(lowlevel<1) lowlevel=1; double markup=3; if(Map->GetCurrentTile()->GetContainer()->GetType()==TOWN) { Town* t=(Town*)Map->GetCurrentTile()->GetContainer(); if(t->GetSpecialty()=="Market") { markup=1.5; if(Map->GetCharacter()->GetLevel()>highlevel) highlevel+=(Map->GetCharacter()->GetLevel()-highlevel)/2; } } else if(Map->GetCurrentTile()->GetContainer()->GetType()==CASTLE) { markup=2; if(Map->GetCharacter()->GetLevel()>highlevel) highlevel=Map->GetCharacter()->GetLevel(); } //get the items from the level, adding them to possible items map<string,Item> tempitemMap; for(int i=lowlevel;i<=highlevel;i+=1) { vector<string> items=Item::ItemLevelMap[i]; for(unsigned int j=0;j<items.size();j+=1) tempitemMap[items[j]]=Item::ItemMap[items[j]]; } //add them to a vector vector<Item> sellingItems; map<string,Item>::iterator it=tempitemMap.begin(); while(it!=tempitemMap.end()) { sellingItems.push_back(it->second); it++; } int tag=0; while(tag!=-1) { cout<<"Buying:"<<endl; //print the items for(unsigned int i=0;i<sellingItems.size();i+=1) { int price=(int)(sellingItems[i].GetWorth()*markup); cout<<i<<". "<<sellingItems[i].GetName()<<" - "<<price<<"Qulz"<<endl; } //select item string input; cout<<"Enter the item number you wish to buy(-1 to exit): "; cin>>input; tag=Printer::StringToInt(input); while((tag<(-1))||(tag>=(signed int)sellingItems.size())) { Printer::MoveBackLine(); Printer::ClearLine(); cout<<"Enter the item number you wish to buy(-1 to exit): "; cin>>input; tag=Printer::StringToInt(input); } //check to see if you can buy if(tag!=-1) { if(Map->GetCharacter()->GetQulz()>=sellingItems[tag].GetWorth()*markup) { if(Map->GetCharacter()->AddItem(sellingItems[tag])) { Map->GetCharacter()->AddQulz((int)(-sellingItems[tag].GetWorth()*markup)); Printer::pout<<"#014You've purchased the "<<sellingItems[tag].GetName()<<endl; } } else { Printer::pout<<"#014You don't have enough Qulz to purchase that item"<<endl; } system("pause"); system("cls"); Map->GetCharacter()->PrintInfo(); } }//end while system("cls"); Map->GetCharacter()->PrintInfo(); }//end buying if(action=='S') { cout<<"Selling:"<<endl; double markdown=0.5; if(Map->GetCurrentTile()->GetContainer()->GetType()==TOWN) { Town* t=(Town*)Map->GetCurrentTile()->GetContainer(); if(t->GetSpecialty()=="Market") markdown=1; } else if(Map->GetCurrentTile()->GetContainer()->GetType()==CASTLE) markdown=0.75; int tag=0; while(tag!=-1) { vector<Item> inv=Map->GetCharacter()->GetInventory(); for(unsigned int i=0;i<inv.size();i+=1) { cout<<i<<". "<<inv[i].GetName()<<" - "<<inv[i].GetWorth()*markdown<<"Qulz"<<endl; } cout<<"Enter the item number you wish to buy(-1 to exit): "; string input; cin>>input; tag=Printer::StringToInt(input); while((tag<(-1))||(tag>=(signed int)inv.size())) { Printer::MoveBackLine(); Printer::ClearLine(); cout<<"Enter the item number you wish to buy(-1 to exit): "; cin>>input; tag=Printer::StringToInt(input); } if(tag!=-1) { Item i=inv[tag]; int price=(int)(i.GetWorth()*markdown); Printer::pout<<"#014Sold "<<i.GetName()<<endl; Map->GetCharacter()->AddQulz(price); Map->GetCharacter()->RemoveItem(tag); } system("pause"); system("cls"); Map->GetCharacter()->PrintInfo(); }//end while }//end selling