// ==> This file will deal with lessons and learning skills


#include "../mud.h"
#include "../character.h"
#include "../account.h"
#include "../storage.h"
#include "../auxiliary.h"
#include "../handler.h"
#include "../socket.h"
#include "../utils.h"
#include "../save.h"
#include "../set_val/set_val.h"
#include "../bitvector.h"
#include "../room.h"
#include "../money/money.h"
#include "../world.h"
#include "../action.h"
#include "skills.h"
#include "skillpoints.h"
#include "religionskills.h"
#include "lessons.h"

/************************************************************************
*		       Lessons and checking for skill points 		      *
************************************************************************/
 void lesson_interrupt(CHAR_DATA *ch, void *data, bitvector_t where, char *arg) {
   send_to_char(ch, "{YYou are already learning!.{n\r\n");
 }
void do_sacrificelesson(CHAR_DATA *ch, int counter, char *nothing)
{
   int delay = 0;
   switch(counter)
   {
     case 1:
       send_to_char(ch, "You must separate the meat from the bones and entrails,' A teacher\r\n"
	"informs you. She demonstrates this using a small, fattened pig which\r\n"
        "has been butchered.\r\n");
       delay = 60;
       counter++;
       break;
     case 2:
       send_to_char(ch, "The gods appreciate the delicious aromas of food sent up through\r\n"
	"smoke. A teacher sets the unedible parts of the pig onto a burning\r\n"
	"fire. A teacher skewers remaining the chops roasts and sets them\r\n"
	"upon a spit.\r\n");
       delay = 40;
       counter++;
       break;
     case 3:
       send_to_char(ch, "A teacher elaborates, 'However, they do not like the actual taste of\r\n"
	"our foods.' She turns the spit, evenly cooking the pork.\r\n");
       delay = 30;
       counter++;
       break;
     case 4:
       send_to_char(ch, "When the meat is done, we may eat it as the gods have no use for it,'\r\n"
	"but the aroma will rise it's way to the sky, and waft to Olympus',\r\n"
	"she says.\r\n");
       delay = 25;
       counter++;
       break;
     case 5:
       send_to_char(ch, "A teacher adds, 'The gods find a sacrifice so pleasing, they may\r\n"
	"grant favour.'\r\n");
       delay = 15;
       counter++;
       return;
       break;
     default:
       send_to_char(ch, "Your lesson halts unexpectedly.\r\n");
       log_string("Error: bad counter in do_sacrificelesson: %d", counter);
       break;
   }
	start_action(ch, delay, 1, do_sacrificelesson, lesson_interrupt,(int*) counter, NULL);
}
void do_ceremonylesson(CHAR_DATA *ch, int counter, char *nothing)
{
   int delay = 0;
   switch(counter)
   {
     case 1:
       send_to_char(ch, "There are many, many different ceremonies performed throughout the year,'\r\n"
				"a teacher informs you, 'but each of them has a core of similarities that\r\n"
        			"we shall cover.'\r\n");
       delay = 60;
       counter++;
       break;
     case 2:
       send_to_char(ch, "'The date and time of many ceremonies are set by the motion of the stars.\r\n"
				"Most are held in honour of a major Olympian, a minor cult, or a seasonal\r\n"
				"event, such as the harvest,' a teacher states.\r\n");
       delay = 40;
       counter++;
       break;
     case 3:
       send_to_char(ch, "A teacher elaborates, 'You will use your powers granted by the gods to\r\n"
				"glorify them and bring divinity to their followers.'\r\n");
       delay = 30;
       counter++;
       break;
     case 4:
       send_to_char(ch, "'While many ceremonies are public events, specticles for all to see,\r\n"
				"some are more private matters, given only for the benefit of your\r\n"
				"patron god or goddess,' she says.\r\n");
       delay = 25;
       counter++;
       break;
     case 5:
       send_to_char(ch, "A teacher adds, 'Always be wary of violent ceremonies which may bring\r\n"
				"you harm.'\r\n");
       delay = 15;
       counter++;
       return;
       break;
     default:
       send_to_char(ch, "Your lesson halts unexpectedly.\r\n");
       log_string("Error: bad counter in do_sacrificelesson: %d", counter);
       break;
   }
	start_action(ch, delay, 1, do_ceremonylesson, lesson_interrupt,(int*) counter, NULL);
}

COMMAND(cmd_learn)
{
  ROOM_DATA *room = charGetRoom(ch);
  int skpoints;
  skpoints = (charGetSkillpoints(ch));

  if(bitIsOneSet(roomGetBits(room), "learnreligion"))
  {
    if(!*arg) 
    {
      send_to_char(ch, "{nA teacher informs you of the classes available:\r\n");
      send_to_char(ch, "{csacrifices {nand {cceremonies.{n\r\n");
    }else if(!strcasecmp(arg, "sacrifices")){
      int req_points_sacrifice;
      req_points_sacrifice = ((charGetSacrifice(ch) + 1) * 100);
      int next_lvl_sacrifice;
      next_lvl_sacrifice = (charGetSacrifice(ch) + 1);
      int point_diff_sacrifice;
      point_diff_sacrifice = (charGetSkillpoints(ch) - req_points_sacrifice);
      if(charGetSacrifice(ch) == 5){
        send_to_char(ch,"{nYou know as much about that subject as the teacher.");
      }else if(charGetBlessing(ch) < 3){
         send_to_char(ch, "{nYou must learn more about blessings first.\r\n");
      }else if(charGetSkillpoints(ch) < req_points_sacrifice){
         send_to_char(ch, "{nYou do not have enough patience to study right now.\r\n");
      }else{
        send_to_char(ch, "{nA teacher demonstrates how to perform sacrifices.\r\n");
        charSetSkillpoints(ch, point_diff_sacrifice);
        charSetSacrifice(ch, next_lvl_sacrifice);
	  do_sacrificelesson(ch, 1, NULL);
      }
    }else if(!strcasecmp(arg, "ceremonies")){
      int req_points_ceremonies;
      req_points_ceremonies = ((charGetCeremony(ch) + 1) * 100);
      int next_lvl_ceremonies;
      next_lvl_ceremonies = (charGetCeremony(ch) + 1);
      int point_diff_ceremonies;
      point_diff_ceremonies = (charGetSkillpoints(ch) - req_points_ceremonies);
      if(charGetCeremony(ch) == 5){
        send_to_char(ch,"{nYou know as much about that subject as the teacher.");
      }else if(charGetSacrifice(ch) < 5){
         send_to_char(ch, "{nYou must learn more about sacrifices first.\r\n");
      }else if(charGetSkillpoints(ch) < req_points_ceremonies){
         send_to_char(ch, "{nYou do not have enough patience to study right now.\r\n");
      }else{
        send_to_char(ch, "{nA teacher demonstrates how to hold ceremonies.\r\n");
        charSetSkillpoints(ch, point_diff_ceremonies);
        charSetCeremony(ch, next_lvl_ceremonies);
	  do_ceremonylesson(ch, 1, NULL);
      }
    }else{
      send_to_char(ch, "{nThat does not appear to be a valid lesson offered here.");  
    }
  }else{
      send_to_char(ch, "{nThere appears to be no one here offering lessons.");  
  }
}


/************************************************************************
	Below here are all of the init_ functions for this file.
*************************************************************************/
void init_lessons(void)
{
	add_cmd("learn", "learn", cmd_learn, POS_STANDING, POS_FLYING, "player", TRUE, FALSE);
      bitvectorAddBit("room_bits", "learnreligion");
}