////////////////////////////////////////
// WCS - Warcraft:Source              //
// ---------------------------------- //
//  by kRypT0n!Te                     //
//      http://wcs.despo-clan.de      //
// ---------------------------------- //
// Content of this subscript          //
// - shop management                  //
////////////////////////////////////////
// say commands:
// shopmenu, shopinfo
//
// admin commands:
// wcs_shop_menu <userid>
// wcs_shop_menu2 <userid> <category>
// wcs_giveshopitem <userid> <itemid>
// wcs_showshopinfo <userid>
//
////////////////////////////////////////

block load
{
	// Change this, if you add a new shopmenu category (also change the language file wcs_lng_shopcats)
	es_xsetinfo wcs_numberoficats "5"
	es_xexists wcs_exists keygroup "WCSinfo"
  es es_xif (server_var(wcs_exists) = 0) then es_xkeygroupcreate WCSinfo
	es_xexists wcs_exists key "WCSinfo" "shopinfo"
  es es_xif (server_var(wcs_exists) = 0) do
  {
    es_xkeycreate "WCSinfo" "shopinfo"
  }
  es_xelse do
  {
    es_xkeydelete "WCSinfo" "shopinfo"
    es_xkeycreate "WCSinfo" "shopinfo"
  }
  es_xkeygroupload "WCSshop" "|wcs/WCSshop"
  alias wcs_checkshopalias "es es_xif (shopalias in server_var(wcs_val)) then es_xkeygetvalue wcs_tmp WCSshop server_var(wcs_key) server_var(wcs_val);es es_xif (shopalias in server_var(wcs_val)) then alias server_var(wcs_val) server_var(wcs_tmp)"
  alias wcs_checkshoplanguage "es es_xif (wcs_lng_s in server_var(wcs_name)) then wcs_getlanguage wcs_name server_var(wcs_name);es es_xkeysetvalue WCSshop server_var(wcs_key) name server_var(wcs_name);es es_xkeygetvalue wcs_descr WCSshop server_var(wcs_key) description;es es_xif (wcs_lng_s in server_var(wcs_descr)) then wcs_getlanguage wcs_descr server_var(wcs_descr);es es_xkeysetvalue WCSshop server_var(wcs_key) description server_var(wcs_descr)"
  es_xsetinfo wcs_numberofitems "0"
  es_xforeachkey wcs_key in "WCSshop" "es es_xkeygetvalue wcs_name WCSshop server_var(wcs_key) name;es es_xforeachval wcs_val in WCSshop server_var(wcs_key) wcs_checkshopalias;wcs_checkshoplanguage;es echo Loaded: server_var(wcs_name);es_xmath wcs_numberofitems + 1"
  es echo "Total : " server_var(wcs_numberofitems) " Items loaded"
  // create the shopinfo data
  es_xdoblock wcs/WCSshop/wcs_shopinfo
  es_xexists wcs_exists command wcs_shop_menu
  es es_xif (server_var(wcs_exists) = 0) then es_xregcmd wcs_shop_menu wcs/WCSshop/wcs_shop_menu "wcs_shop_menu - usage: wcs_shop_menu <userid>"
  es_xexists wcs_exists command wcs_shop_menu2
  es es_xif (server_var(wcs_exists) = 0) then es_xregcmd wcs_shop_menu2 wcs/WCSshop/wcs_shop_menu2 "wcs_shop_menu2 - usage: wcs_shop_menu2 <userid> <category>"
  es_xexists wcs_exists command wcs_giveshopitem
  es es_xif (server_var(wcs_exists) = 0) then es_xregcmd wcs_giveshopitem wcs/WCSshop/wcs_giveshopitem "wcs_giveshopitem - usage: wcs_giveshopitem <userid> <itemid>"
  es_xexists wcs_exists command wcs_showshopinfo
  es es_xif (server_var(wcs_exists) = 0) then es_xregcmd wcs_showshopinfo wcs/WCSshop/wcs_showshopinfo "Shows detail info about the shop items"
  es_xexists wcs_exists command shopmenu
  es es_xif (server_var(wcs_exists) = 0) then es_xregsaycmd shopmenu wcs/WCSshop/wcs_shopmenu "Opens the shopmenu"
  es_xexists wcs_exists command shopinfo
  es es_xif (server_var(wcs_exists) = 0) then es_xregsaycmd shopinfo wcs/WCSshop/wcs_showshopinfo "Shows detail info about the shop items"
}

block unload
{
  es_xkeygroupdelete "WCSshop"
  es_xkeydelete "WCSinfo" "shopinfo"
}

// >>>>>>>>>>>>>>>>> BEGIN SHOP BLOCKS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
block wcs_shopmenu
{
es es_xif (server_var(wcs_debug) = "1") then echo wcs_shopmenu start
  // who runned the command ?
  es_xgetcmduserid wcs_userid
  es es_xexists wcs_exists userid server_var(wcs_userid)
  es es_xif (server_var(wcs_exists) = "1") do
  {
  	es es_xif (server_var(wcs_cfg_noshopmenu) = "1") then es_xsetinfo wcs_exists 0
  	es es_xif (server_var(wcs_game) = server_var(wcs_game_dods)) then es_xif (server_var(wcs_cfg_dods_noshopmenu) = "1") then es_xsetinfo wcs_exists 0
  	es es_xif (server_var(wcs_exists) = "0") do
  	{
  		wcs_getlanguage "wcs_lng" "wcs_lng_noshopmenu"
      es es_xtell server_var(wcs_userid) #multi server_var(wcs_lng)
      es_xsetinfo wcs_exists 0
  	}
  }
  es_xelse do
  {
  	es_xsetinfo wcs_exists 0
  }
  es es_xif (server_var(wcs_exists) = "1") do
  {
    es wcs_menuzero server_var(wcs_userid)
    es es_xif (server_var(wcs_game) = server_var(wcs_game_dods)) then wcs_showcredits server_var(wcs_userid)
    es wcs_shop_menu server_var(wcs_userid)
  }
es es_xif (server_var(wcs_debug) = "1") then echo wcs_shopmenu end
}

block wcs_shop_menu
{
es es_xif (server_var(wcs_debug) = "1") then echo wcs_shop_menu start
  // a custom command
  es_xgetargv wcs_userid 1
  es_xexists wcs_exists keygroup "WCSshop"
  es es_xif (server_var(wcs_exists) = 1) do
  {
    es es_xkeysetvalue "WCSuserdata" server_var(wcs_userid) "menu" "shop1"
    es es_xkeysetvalue "WCSuserdata" server_var(wcs_userid) "page" "1"
    wcs_getlanguage "wcs_lng" "wcs_lng_choosecat"
    es es_xformat wcs_text "%1 :\n " server_var(wcs_lng)
    es_xsetinfo wcs_counter 1
    wcs_getlanguage "wcs_lng" "wcs_lng_shopcats"
    es_xsetinfo wcs_format "%1\n->%2. %3"
    while "server_var(wcs_counter) <= server_var(wcs_numberoficats)" "es es_xtoken wcs_tmp server_var(wcs_lng) server_var(wcs_counter) |;es es_xformat wcs_text server_var(wcs_format) server_var(wcs_text) server_var(wcs_counter) server_var(wcs_tmp);es_xmath wcs_counter + 1"
    // check if we need next page
    wcs_getlanguage "wcs_lng" "wcs_lng_shopmenuhint"
    es es_xformat wcs_text "\n %1 \n \n%2\n \n0. %3" server_var(wcs_text) server_var(wcs_lng) server_var(wcs_lng_exit)
    es es_xmenu 0 server_var(wcs_userid) server_var(wcs_text)
  }
es es_xif (server_var(wcs_debug) = "1") then echo wcs_shop_menu end
}

block wcs_shop_menu2
{
es es_xif (server_var(wcs_debug) = "1") then echo wcs_shop_menu2 start
  // a custom command
  es_xgetargv wcs_userid 1
  es_xgetargv wcs_page 2
  es es_xexists wcs_exists key "WCSuserdata" server_var(wcs_userid)
  es es_xif (server_var(wcs_page) < 1) then es_xsetinfo wcs_exists 0
  es es_xif (server_var(wcs_page) > server_var(wcs_numberoficats)) then es_xsetinfo wcs_exists 0
  es es_xif (server_var(wcs_exists) = 1) do
  {
  	es es_xkeysetvalue WCSuserdata server_var(wcs_userid) "page" server_var(wcs_page)
    es es_xkeysetvalue WCSuserdata server_var(wcs_userid) "menu" "shop2"
    // get the money (for DOD:S special handling)
    es_xsetinfo wcs_money 0
    es es_xif (server_var(wcs_game) = server_var(wcs_game_css)) then es_xgetmoney wcs_money server_var(wcs_userid)
    es es_xif (server_var(wcs_game) != server_var(wcs_game_css)) then es_xkeygetvalue wcs_money "WCSuserdata" server_var(wcs_userid) "credits"
    // get the level
    es es_xkeygetvalue wcs_level WCSuserdata server_var(wcs_userid) "level"
    // check dead or alive status
    es_xsetinfo wcs_dead "1"
    es es_xgetplayerprop wcs_dead server_var(wcs_userid) "CCSPlayer.baseclass.pl.deadflag"
    es es_xif (server_var(wcs_dead) = "0") then es_xsetinfo wcs_deadoralive "1"
    es es_xif (server_var(wcs_dead) = "1") then es_xsetinfo wcs_deadoralive "0"
  	wcs_getlanguage "wcs_lng" "wcs_lng_chooseitem"
    es es_xformat wcs_text "%1 :\n " server_var(wcs_lng)
  	es_xsetinfo wcs_counter 1
  	es_xsetinfo wcs_key 0
  	es_xforeachkey wcs_key in WCSshop "es es_xkeygetvalue wcs_category WCSshop server_var(wcs_key) category;es es_xif (server_var(wcs_category) = server_var(wcs_page)) then es_xdoblock wcs/WCSshop/wcs_shop_menu_init"
  	es es_xformat wcs_text "%1\n \n0. %2" server_var(wcs_text) server_var(wcs_lng_back)
    es es_xmenu 0 server_var(wcs_userid) server_var(wcs_text)
  }
es es_xif (server_var(wcs_debug) = "1") then echo wcs_shop_menu2 end
}

block wcs_shop_menu_init
{
es es_xif (server_var(wcs_debug) = "1") then echo wcs_shop_menu_init start
  es es_xkeygetvalue wcs_iname WCSshop server_var(wcs_key) "name"
  // check if user can buy item
  es es_xkeygetvalue wcs_icost WCSshop server_var(wcs_key) "cost"
  es es_xkeygetvalue wcs_ilevel WCSshop server_var(wcs_key) "level"
  es es_xkeygetvalue wcs_idab WCSshop server_var(wcs_key) "dab"
  es es_xkeygetvalue wcs_amount "WCSshop" server_var(wcs_key) "maxamount"
  es es_xformat wcs_tmp1 "item_%1" server_var(wcs_key)
  es es_xkeygetvalue wcs_tmp2 "WCSuserdata" server_var(wcs_userid) server_var(wcs_tmp1)
  es es_xif (server_var(wcs_tmp2) = "0") then es_xsetinfo wcs_tmp2 0
  es es_xif (server_var(wcs_amount) = "0") then es_xsetinfo wcs_tmp2 -1
  es_xsetinfo wcs_ok 0
  es es_xif (server_var(wcs_icost) <= server_var(wcs_money)) then es_xif (server_var(wcs_ilevel) <= server_var(wcs_level)) then es_xif (server_var(wcs_amount) > server_var(wcs_tmp2)) then es_xsetinfo wcs_ok "1"
  es es_xif (server_var(wcs_ok) = "1") do
  {
  	es_xsetinfo wcs_ok "0"
  	es es_xif (server_var(wcs_idab) = server_var(wcs_deadoralive)) then es_xsetinfo wcs_ok "1"
    es es_xif (server_var(wcs_idab) = "2") then es_xsetinfo wcs_ok "1"
  }
  es es_xif (server_var(wcs_ok) = "1") do
  {
    es es_xformat wcs_text "%1 \n->%2. %3 ($%4)" server_var(wcs_text) server_var(wcs_counter) server_var(wcs_iname) server_var(wcs_icost)
  }
  es_xelse do
  {
    // not selectable item
    es es_xif (server_var(wcs_ilevel) > 0) then es_xformat wcs_text "%1 \n%2. %3 ($%4) (lvl %5)" server_var(wcs_text) server_var(wcs_counter) server_var(wcs_iname) server_var(wcs_icost) server_var(wcs_ilevel)
    es es_xif (server_var(wcs_ilevel) = "0") then es_xformat wcs_text "%1 \n%2. %3 ($%4)" server_var(wcs_text) server_var(wcs_counter) server_var(wcs_iname) server_var(wcs_icost)
    wcs_getlanguage "wcs_lng" "wcs_lng_shopoutofstock"
    es es_xif (server_var(wcs_amount) != "0") then es_xif (server_var(wcs_amount) <= server_var(wcs_tmp2)) then es_xformat wcs_text "%1 (%2)" server_var(wcs_text) server_var(wcs_lng)
  }
  // IMPORTANT !!
  es_xmath wcs_counter + 1
es es_xif (server_var(wcs_debug) = "1") then echo wcs_shop_menu_init end
}

block wcs_shop_handle
{
es es_xif (server_var(wcs_debug) = "1") then echo wcs_shop_handle start
  es_xsetinfo wcs_ok "0"
  // shop1 or shop2
  es es_xif (server_var(wcs_menu) = "shop1") do
  {
  	es es_xif (event_var(commandstring) >= 1) then es_xif (event_var(commandstring) <= server_var(wcs_numberoficats)) then es_xsetinfo wcs_ok "1"
  	es es_xif (server_var(wcs_ok) = "0") then wcs_menuzero event_var(userid)
  	es es_xif (server_var(wcs_ok) = "1") then wcs_shop_menu2 event_var(userid) event_var(commandstring)
  }
  es es_xif (server_var(wcs_menu) = "shop2") do
  {
  	// handle back
  	es es_xif (event_var(commandstring) = "10") then wcs_shop_menu event_var(userid)
  	// handle buy
  	es es_xif (event_var(commandstring) <= 9) do
    {
      es es_xif (event_var(commandstring) > 0) do
      {
  	    // get the users data
  	    es es_xkeygetvalue wcs_page "WCSuserdata" event_var(userid) "page"
  	    es es_xkeygetvalue wcs_id "WCSuserdata" event_var(userid) "id"
        // find the item
        es_xsetinfo wcs_key 0
        es_xsetinfo wcs_counter 0
        es_xsetinfo wcs_itemid 0
        es_xforeachkey wcs_key in "WCSshop" "es es_xkeygetvalue wcs_category WCSshop server_var(wcs_key) category;es es_xif (server_var(wcs_category) = server_var(wcs_page)) then es_xmath wcs_counter + 1;es es_xif (server_var(wcs_counter) = event_var(commandstring)) then es_xsetinfo wcs_itemid server_var(wcs_key);es es_xif (server_var(wcs_counter) = event_var(commandstring)) then es_xsetinfo wcs_counter 9999999"
        // check item and user data
        es es_xif (server_var(wcs_itemid) != "0") do
        {
          // get the money (for DOD:S special handling)
          es_xsetinfo wcs_money 0
          es es_xif (server_var(wcs_game) = server_var(wcs_game_css)) then es_xgetmoney wcs_money event_var(userid)
          es es_xif (server_var(wcs_game) != server_var(wcs_game_css)) then es_xkeygetvalue wcs_money "WCSuserdata" event_var(userid) "credits"
          // get the level
          es es_xkeygetvalue wcs_level WCSuserdata event_var(userid) level
          // check dead or alive status
          es_xsetinfo wcs_dead "1"
          es es_xgetplayerprop wcs_dead event_var(userid) "CCSPlayer.baseclass.pl.deadflag"
          es es_xif (server_var(wcs_dead) = "0") then es_xsetinfo wcs_deadoralive "1"
          es es_xif (server_var(wcs_dead) = "1") then es_xsetinfo wcs_deadoralive "0"
          es es_xkeygetvalue wcs_iname "WCSshop" server_var(wcs_itemid) "name"
          es es_xkeygetvalue wcs_icost "WCSshop" server_var(wcs_itemid) "cost"
          es es_xkeygetvalue wcs_ilevel "WCSshop" server_var(wcs_itemid) "level"
          es es_xkeygetvalue wcs_idab "WCSshop" server_var(wcs_itemid) "dab"
          es es_xkeygetvalue wcs_amount "WCSshop" server_var(wcs_itemid) "maxamount"
          es es_xformat wcs_tmp1 "item_%1" server_var(wcs_itemid)
          es es_xkeygetvalue wcs_tmp2 "WCSuserdata" event_var(userid) server_var(wcs_tmp1)
          es es_xif (server_var(wcs_tmp2) = "0") then es_xsetinfo wcs_tmp2 "0"
          es es_xif (server_var(wcs_amount) = "0") then es_xsetinfo wcs_tmp2 -1
          es_xsetinfo wcs_ok 0
          es es_xif (server_var(wcs_icost) <= server_var(wcs_money)) then es_xif (server_var(wcs_ilevel) <= server_var(wcs_level)) then es_xif (server_var(wcs_amount) > server_var(wcs_tmp2)) then es_xsetinfo wcs_ok "1"
          es es_xif (server_var(wcs_ok) = "1") do
          {
  	        es_xsetinfo wcs_ok "0"
  	        es es_xif (server_var(wcs_idab) = server_var(wcs_deadoralive)) then es_xsetinfo wcs_ok "1"
            es es_xif (server_var(wcs_idab) = "2") then es_xsetinfo wcs_ok "1"
          }
          es es_xif (server_var(wcs_ok) = "1") do
          {
            es es_xformat wcs_text "%1 \n->%2. %3 ($%4)" server_var(wcs_text) server_var(wcs_counter) server_var(wcs_iname) server_var(wcs_icost)
            wcs_getlanguage "wcs_lng" "wcs_lng_purchased"
            es es_xformat wcs_text "#lightgreen%1: #green%2" server_var(wcs_lng) server_var(wcs_iname)
            es es_xtell event_var(userid) #multi server_var(wcs_text)
            // first pay, then give item :)
            es es_xif (server_var(wcs_game) = server_var(wcs_game_css)) do
            {
              es est_Cash event_var(userid) - server_var(wcs_icost)
            }
            es_xelse do
            {
              es es_xmath wcs_money - server_var(wcs_icost)
              es es_xkeysetvalue "WCSuserdata" server_var(wcs_id) "credits" server_var(wcs_money)
            }
            es wcs_giveshopitem event_var(userid) server_var(wcs_itemid)
          }
        }
      }
    }
    // set page to 0 if item selected
    es es_xif (event_var(commandstring) != "10") then wcs_menuzero event_var(userid)
  }
es es_xif (server_var(wcs_debug) = "1") then echo wcs_shop_handle end
}

block wcs_giveshopitem
{
es es_xif (server_var(wcs_debug) = "1") then echo wcs_giveshopitem start
  es_xsetinfo wcs_userid 0
  es_xgetargv wcs_userid 1
  es_xsetinfo wcs_itemid 0
  es_xgetargv wcs_itemid 2
  es es_xexists wcs_exists userid server_var(wcs_userid)
  es es_xif (server_var(wcs_exists) = 1) do
  {
    es es_xexists wcs_exists key WCSshop server_var(wcs_itemid)
    es es_xif (server_var(wcs_exists) = 1) do
    {
      // get user id
      es_xsetinfo wcs_id 0
      es es_xkeygetvalue wcs_id WCSuserdata server_var(wcs_userid) id
      es_xsetinfo wcs_itype 0
      es es_xkeygetvalue wcs_itype WCSshop server_var(wcs_itemid) itemconfig

      es_xsetinfo wcs_validtypes "player_buy player_death player_attacker player_victim player_spawn player_say"
      es es_xif (server_var(wcs_itype) in server_var(wcs_validtypes)) do
      {
        // get item details
        es_xsetinfo wcs_iduration 0
        es es_xkeygetvalue wcs_iduration WCSshop server_var(wcs_itemid) duration
        es_xsetinfo wcs_ibuy 0
        es es_xkeygetvalue wcs_ibuy WCSshop server_var(wcs_itemid) cmdbuy
        es_xsetinfo wcs_iactivate 0
        es es_xkeygetvalue wcs_iactivate WCSshop server_var(wcs_itemid) cmdactivate
        // launch buy command
        es es_xif (server_var(wcs_ibuy) != "0") do
        {
          es alias wcs_cmd server_var(wcs_ibuy)
          wcs_cmd
        }
        // add the item to the player record
        es es_xkeygetvalue wcs_amount "WCSshop" server_var(wcs_itemid) "maxamount"
        es es_xif (server_var(wcs_amount) != "0") do
        {
          es es_xformat wcs_tmp1 "item_%1" server_var(wcs_itemid)
          es es_xkeygetvalue wcs_tmp2 "WCSuserdata" server_var(wcs_userid) server_var(wcs_tmp1)
          es es_xif (server_var(wcs_tmp2) = "0") then es_xsetinfo wcs_tmp2 "0"
          es_xmath wcs_tmp2 + 1
          es es_xkeysetvalue "WCSuserdata" server_var(wcs_userid) server_var(wcs_tmp1) server_var(wcs_tmp2)
        }
        // dont allow buy items to be activated
        es es_xif (server_var(wcs_itype) = "player_buy") then es_xsetinfo wcs_iactivate 0
        es es_xif (server_var(wcs_iduration) = "0") then es_xsetinfo wcs_iactivate 0
        // insert item in the launch keygroup
        es es_xif (server_var(wcs_iactivate) != "0") do
        {
          es_xsetinfo wcs_icat 0
          es es_xif (server_var(wcs_itype) = "player_death") then es_xsetinfo wcs_icat WCSpd
          es es_xif (server_var(wcs_itype) = "player_attacker") then es_xsetinfo wcs_icat WCSpha
          es es_xif (server_var(wcs_itype) = "player_victim") then es_xsetinfo wcs_icat WCSphv
          es es_xif (server_var(wcs_itype) = "player_spawn") then es_xsetinfo wcs_icat WCSps
          es es_xif (server_var(wcs_itype) = "player_say") then es_xsetinfo wcs_icat WCSpsay
          es_xsetinfo wcs_icmd1 0
          es_xsetinfo wcs_icmd2 0
          es_xsetinfo wcs_idescr 0
          es_xsetinfo wcs_islot "0"
          // refresh the steamid/ip
          es es_xkeycreate server_var(wcs_icat) server_var(wcs_userid)
          es es_xkeysetvalue server_var(wcs_icat) server_var(wcs_userid) id server_var(wcs_id)
          // check if second is free
          es es_xkeygetvalue wcs_icmd2 server_var(wcs_icat) server_var(wcs_userid) icmd2
          es es_xstrlen wcs_strlen server_var(wcs_icmd2)
          es es_xif (server_var(wcs_strlen) <= 1) then es_xsetinfo wcs_islot "2"
          // check if first is free
          es es_xkeygetvalue wcs_icmd1 server_var(wcs_icat) server_var(wcs_userid) icmd1
          es es_xstrlen wcs_strlen server_var(wcs_icmd1)
          es es_xif (server_var(wcs_strlen) <= 1) then es_xsetinfo wcs_islot "1"
          es es_xif (server_var(wcs_islot) = "0") do
          {
            // payback....
            wcs_getlanguage "wcs_lng" "wcs_lng_bagfull"
            es es_xtell server_var(wcs_userid) #multi server_var(wcs_lng)
            es_xsetinfo wcs_icost 0
            es es_xkeygetvalue wcs_icost WCSshop server_var(wcs_itemid) cost
            es es_xif (server_var(wcs_ibuy) = 0) then es_xdelayed 1 est_Cash server_var(wcs_userid) + server_var(wcs_icost)
          }
          es_xelse do
          {
          	wcs_getlanguage "wcs_lng" "wcs_lng_bagusage"
          	es es_xformat wcs_lng server_var(wcs_lng) server_var(wcs_islot)
            es es_xtell server_var(wcs_userid) #multi server_var(wcs_lng)
            // insert
            es es_xformat wcs_tmp "icmd%1" server_var(wcs_islot)
            es es_xkeysetvalue server_var(wcs_icat) server_var(wcs_userid) server_var(wcs_tmp) server_var(wcs_iactivate)
            // but dont notice on player_hurt event (too much spam)
            es es_xif (server_var(wcs_icat) != "player_attacker") do
            {
              es es_xif (server_var(wcs_icat) != "player_victim") do
              {
                es_xsetinfo wcs_iname 0
                es es_xkeygetvalue wcs_iname WCSshop server_var(wcs_itemid) name
                wcs_getlanguage "wcs_lng" "wcs_lng_activated"
                es es_xformat wcs_text "#lightgreen%1 #green%2" server_var(wcs_lng) server_var(wcs_iname)
                es es_xformat wcs_text "es es_xtell %1 #multi %2" server_var(wcs_userid) server_var(wcs_text)
                es es_xformat wcs_tmp "idescr%1" server_var(wcs_islot)
                es es_xkeysetvalue server_var(wcs_icat) server_var(wcs_userid) server_var(wcs_tmp) server_var(wcs_text)
              }
            }
          }
          // refresh skills
          es wcs_skillcheck server_var(wcs_userid)
        }
      }
    }
  }
es es_xif (server_var(wcs_debug) = "1") then echo wcs_giveshopitem end
}
// <<<<<<<<<<<<<<<<< END SHOP BLOCKS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

// >>>>>>>>>>>>>>>>> SHOP INFO >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
block wcs_showshopinfo
{
es es_xif (server_var(wcs_debug) = "1") then echo wcs_showshopinfo start
  // first, is it a custom command ?
  es_xgetargv wcs_userid 1
  es es_xexists wcs_exists userid server_var(wcs_userid)
  es es_xif (server_var(wcs_exists) = 0) do
  {
    // or a say command
    es_xgetcmduserid wcs_userid
    es es_xexists wcs_exists userid server_var(wcs_userid)
    es wcs_menuzero server_var(wcs_userid)
  }
  es es_xkeysetvalue "WCSuserdata" server_var(wcs_userid) "menu" "shopinfo"
  es_xsetinfo wcs_page 0
  es es_xkeygetvalue wcs_page "WCSuserdata" server_var(wcs_userid) "page"
  es_xmath wcs_page + 1
  es es_xkeysetvalue "WCSuserdata" server_var(wcs_userid) "page" server_var(wcs_page)
  es_xsetinfo wcs_infotext 0
  es es_xkeygetvalue wcs_infotext WCSinfo shopinfo server_var(wcs_page)
  es es_xstrlen wcs_strlen server_var(wcs_infotext)
  es es_xif (server_var(wcs_strlen) > 1) then es_xmenu 0 server_var(wcs_userid) server_var(wcs_infotext)
es es_xif (server_var(wcs_debug) = "1") then echo wcs_showshopinfo start
}

block wcs_shopinfo
{
es es_xif (server_var(wcs_debug) = "1") then echo wcs_shopinfo start
  es_xforeachkey wcs_key in WCSshop "es_xdoblock wcs/WCSshop/wcs_shopinfo_items"
es es_xif (server_var(wcs_debug) = "1") then echo wcs_shopinfo end
}

block wcs_shopinfo_items
{
  es es_xkeygetvalue wcs_name WCSshop server_var(wcs_key) name
  es es_xkeygetvalue wcs_descr WCSshop server_var(wcs_key) description
  es es_xkeygetvalue wcs_cost WCSshop server_var(wcs_key) cost
  es es_xkeygetvalue wcs_level WCSshop server_var(wcs_key) level
  es es_xkeygetvalue wcs_dab WCSshop server_var(wcs_key) dab
  es es_xkeygetvalue wcs_duration WCSshop server_var(wcs_key) duration
  es es_xkeygetvalue wcs_amount "WCSshop" server_var(wcs_key) "maxamount"
  es es_xformat wcs_text "\n->%1.     %2 \n ( $%3 | min. level %4 )" server_var(wcs_key) server_var(wcs_name) server_var(wcs_cost) server_var(wcs_level)
  wcs_getlanguage "wcs_lng" "wcs_lng_buywhen"
  es es_xformat wcs_text "%1\n%2 <" server_var(wcs_text) server_var(wcs_lng)
  wcs_getlanguage "wcs_lng" "wcs_lng_dab0"
  es es_xif (server_var(wcs_dab) = 0) then es_xformat wcs_text "%1%2>" server_var(wcs_text) server_var(wcs_lng)
  wcs_getlanguage "wcs_lng" "wcs_lng_dab1"
  es es_xif (server_var(wcs_dab) = 1) then es_xformat wcs_text "%1%2>" server_var(wcs_text) server_var(wcs_lng)
  wcs_getlanguage "wcs_lng" "wcs_lng_dab2"
  es es_xif (server_var(wcs_dab) = 2) then es_xformat wcs_text "%1%2>" server_var(wcs_text) server_var(wcs_lng)
  wcs_getlanguage "wcs_lng" "wcs_lng_duration"
  es es_xformat wcs_text "%1 %2 <" server_var(wcs_text) server_var(wcs_lng)
  wcs_getlanguage "wcs_lng" "wcs_lng_thisround"
  es es_xif (server_var(wcs_duration) = 0) then es_xformat wcs_text "%1%2>" server_var(wcs_text) server_var(wcs_lng)
  wcs_getlanguage "wcs_lng" "wcs_lng_untildeath"
  es es_xif (server_var(wcs_duration) = 1) then es_xformat wcs_text "%1%2>" server_var(wcs_text) server_var(wcs_lng)
  es es_xif (server_var(wcs_amount) > 0) do
  {
  	wcs_getlanguage "wcs_lng" "wcs_lng_itemstock"
  	es es_xformat wcs_tmp1 server_var(wcs_lng) server_var(wcs_amount)
    es es_xformat wcs_text "%1\n%2" server_var(wcs_text) server_var(wcs_tmp1)
  }
  wcs_getlanguage "wcs_lng" "wcs_lng_buy"
  es es_xformat wcs_text "%1\n \n%2\n \n->7. %3" server_var(wcs_text) server_var(wcs_descr) server_var(wcs_lng)
  es es_xif (server_var(wcs_key) > 1) then es_xformat wcs_text "%1\n->8. %2" server_var(wcs_text) server_var(wcs_lng_back)
  es es_xsetinfo wcs_keynext server_var(wcs_key)
  es_xmath wcs_keynext + 1
  es es_xexists wcs_exists key WCSshop server_var(wcs_keynext)
  es es_xif (server_var(wcs_exists) = 1) then es_xformat wcs_text "%1\n->9. %2" server_var(wcs_text) server_var(wcs_lng_next)
  es es_xkeysetvalue WCSinfo shopinfo server_var(wcs_key) server_var(wcs_text)
}
