/*
 * Bird Thief, Jidoor mission
 * player must go to yozrath and steal
 * the shiek's birds by capturing them
 * in a birdcage, then return to jidoor.
 * mahkefel 7/2010
 */

// Stolen by Torak for a quest to bring lightning bugs //
// in a jar back to a mother who's toddler won't sleep //
// because it's scared of the dark. //
// steal from the best : 4/24/12 //

#include <lib.h>       
inherit LIB_MISSION;   

static void create() {
  ::create();         
  SetMissionName("Afraid of the Dark");
  SetTown("baria");           
  SetMissionDescription(       
    "Oh, my poor child won't sleep!  When the lights go out "
    "and darkness surrounds, all I hear are cries and tears!  "
    "My poor baby.  If only a brave warrior would go to the top "
    "of the Minaret in Yozrath Desert and bring back a jar of "
    "fireflies to keep my baby from being scared, I could finally "
    "get some sleep."           
  );                                                                    
  SetMissionLevel(200, 500);                                              
  SetMissionPriority(90);                                               
  SetReward("1000000 XP");                                                 
  SetTitle("the Returner of Dreams");                                                
}                                                                                


int CheckCompletedMission(object who) {
  object *correctBirds = ({ });                           
  object *birds = ({ });                                  
  object *cage = ({ });                                   
  object *rumpel = ({ });                                 
  if (base_name(environment(who)) == "/domains/valley/towns/jidoor/room/twnsquare") {
    cage = filter(all_inventory(who), (: $1->GetKeyName() == "birdcage" :) );        
    rumpel = filter(all_inventory(environment(who)),                                 
      (: $1->GetKeyName() == "rumpel" :) );                                          
    if (sizeof(cage) < 1) return 0;                                                  
    if (sizeof(rumpel) < 1) return 0;                                                
    birds = cage[0]->GetCaptives();                                                  
    if (sizeof(birds) < 1) return 0;                                                 
    correctBirds = filter(birds,                                                     
      (: $1->GetKeyName() == "bustard" :) );                                         
    correctBirds += filter(birds,                                                    
      (: $1->GetKeyName() == "roller" :) );                                          
    correctBirds += filter(birds,                                                    
      (: $1->GetKeyName() == "waxbill" :) );                                         
    if (sizeof(correctBirds) < 1) return 0;                                          
    cage[0]->eventMove(rumpel[0]);                                                   
    //cage[0]->eventDest();Cage doesn't dest and I don't care.
    rumpel[0]->eventForce(
      "speak Excellent! Our scholars of natural philosophy will be pleased."
      " You should accept a small reward for your work. 2000 rupies for each"
      " living bird should be acceptable, I think."
    );
    rumpel[0]->eventForce("emote beams with pride.");
    who->eventPrint("You have returned from the desert with rare fauna!");
    who->eventPrint("You have been dubbed \"The Returner of Dreams\" for your efforts.");
    who->AddExperience(1000);
    who->AddCurrency("rupies",2000*sizeof(correctBirds));
    return 1;
  }
  return 0;
}

void AssignMission(object who) {
  object cage = new("/std/mission_obj/birdcage");
  if (!cage->eventMove(who)) {
    cage->eventMove(who);
  }
  who->eventPrint("Rumpel hands you a gilded birdcage");
}

int CanGetMission(object who) {
  if (who->GetQuestCompleted("Afraid of the Dark")) {
    return 1;
  } else {
    return 0;
  }
}
