// Oskom: ultima.com.ru

// 16.10.2001, Eidolon: String matching and automatization

//==============================================
// Charades
//==============================================


[function f_create_letters]

src.newitem i_charade_rune
src.act.morex = <morex>
src.act.more = <uid>
src.act.more2 = <more2>
src.act.link=<link>
src.act.bounce
link = <src.act.uid>
morey = <morey>-1
morex = <morex>*2
if <morey>
	f_create_letters
endif
return 1


[function f_letters_remove]

morey=0
if <link> != 04fffffff
	f_remove_letter
endif
if <morey> != <morez>
	name=/error/
	color=0486
endif
update
return 1


[function f_remove_letter]

if <link.type> == t_charadeletter
	if <link.link> != 04fffffff
		link.f_remove_letter
	endif
	morey=<link.morey>+1
	link.remove
endif
link = 04fffffff
return 1



[ITEMDEF i_hat_mage_red]
NAME=Stoic's hat
ID=i_hat_wizards
WEIGHT=3
//VALUE=1000

RESOURCES=i_hat_wizards, i_reag_serpent_scale, i_hides_cut_dragon_red

On=@Create
	color = color_o_bloodrock
	hitpoints = 100

On=@Equip
	src.meditation = <src.meditation> + 10.0
	src.sfx 01fb
	src.effect 3,i_fx_heal_effect,6,15,1

On=@Unequip
	src.meditation = (<src.meditation> - 10.0)

CATEGORY=Quests and legends
SUBSECTION=Charades
DESCRIPTION=Mage's hat (red)

[ITEMDEF i_hat_mage_black]
NAME=Stoic's hat
ID=i_hat_wizards
WEIGHT=3
//VALUE=1000

RESOURCES=i_hat_wizards, i_reag_serpent_scale, i_hides_cut_dragon_black

On=@Create
	color = color_o_obsidian
	hitpoints = 100

On=@Equip
	src.meditation = <src.meditation> + 10.0
	src.sfx 020c
	src.effect 3,i_fx_sparkle,6,15,1

On=@Unequip
	src.meditation = (<src.meditation> - 10.0)

CATEGORY=Quests and legends
SUBSECTION=Charades
DESCRIPTION=Mage's hat (black)

[SPEECH spk_new_words]

On=*hi*
On=*hello*
On=*hail*
	face
	timer = 10
	if (<tag.busy>) || (!<findtype(t_word_item).more>)
		say Sorry, I'm not ready to play Charades. I thinking about New Secret for you...
		return 1
	endif
	if <src.plot1> & plotmask_dwarf
		say Hail, master of caves and dungeons! Da you wanna talking... about Charade game?
	elseif <src.plot1> & plotmask_elf
		say Greetings, Elven being! Wilt thou play with me and say me... some kind of word?
	elseif <src.plot1> & plotmask_orc
		say Well Hello... Do you realy think that you can understand the meaning of 'charade'?
	else
		say Hello, <src.sex Milord/Milady> <src.name>! I am Charade Master and I want to hear one Word. Do you know this Word?
	endif
	return 1

On=*charade*
On=*word*
On=*quest*
	face
	timer = 10
	if <findtype(t_word_item).more>
		say There are Seven Runes in Seven Towns of Sossaria. Find these Runes and try to guess the Word that is my Great Secret.
	else
		say Sorry, I'm not ready to play Charades. I thinking about New Secret for you...
	endif
	return 1

On=*	
	face
	timer = 10
	if (<tag.busy>) || (!<findtype(t_word_item).more>)
		say Sorry, I'm not ready to play Charades. I thinking about New Secret for you...
	elseif (<src.findid(i_letters_flags).morex> != <src.findid(i_letters_flags).morey>) || (!<src.restest 1 i_letters_flags>) || (<findtype(t_word_item).more2> != <src.findid(i_letters_flags).more2>)
		dorand 2
			say Are you shure you thou find all Runes?
			say You must find all Runes to play Charades with me!
		enddo
	elseif !(strcmp(<findtype(t_word_item).name>,<args>))
		say Yes, yes. You guessed my Great Secret, <src.name>!
		tag.busy = 1
		dorand 2
			src.newitem i_hat_mage_red
			src.newitem i_hat_mage_black
		enddo
		src.act.timer = -1
		src.act.bounce
		say Take this <src.act.name>, <src.name>! //and farewell!
		findtype(t_word_item).trigger=@Dclick
		src.consume 1000 i_letters_flags
		tag.busy = 0
	else
		say I don't understand thee but I can talk about charades.
	endif
	return 1

[CHARDEF c_h_charademaster]
NAME=#NAMES_HUMANMALE, the Charade Master
ID=c_man

TSPEECH=spk_new_words
TSPEECH=spk_human_prime
TSPEECH=spk_rehello
TSPEECH=spk_human_default

TEVENTS=e_Human_HearUnk
TEVENTS=e_Human_Needs
TEVENTS=e_Human_ConvInit
TEVENTS=e_Human_Greet
TEVENTS=e_Human_Space
TEVENTS=e_Human_Refuse
TEVENTS=e_Human_Environ

ON=@Create
	title=the Charade Master
	COLOR=colors_skin
	STR={400 500}
	DEX={86 99}
	INT={96 49}

	SWORDSMANSHIP={15.0 38.0}
	TACTICS={15.0 38.0}

	NPC=BRAIN_HUMAN
	NEED=i_gold

	ITEM=i_pants_short
	color = { color_o_verite 1 color_o_valorite 1 color_o_gold 1 color_o_silver 1 color_o_obsidian 1 color_o_bloodrock 1 }
	attr=08010
	ITEM=i_tunic
	color = { color_o_verite 1 color_o_valorite 1 color_o_gold 1 color_o_silver 1 color_o_obsidian 1 color_o_bloodrock 1 }
	attr=08010
	ITEM=i_boots_calf
	attr=08010
	ITEM=i_hat_wizards
	attr=08010
	color = { color_o_verite 1 color_o_valorite 1 color_o_gold 1 color_o_silver 1 color_o_obsidian 1 color_o_bloodrock 1 }
	ITEM=i_robe
	attr=08010
	color = { color_o_verite 1 color_o_valorite 1 color_o_gold 1 color_o_silver 1 color_o_obsidian 1 color_o_bloodrock 1 }
	ITEM=i_staff_black
	attr=08010
	name=Mage's staff
	color = { color_o_verite 1 color_o_valorite 1 color_o_gold 1 color_o_silver 1 color_o_obsidian 1 color_o_bloodrock 1 }
	ITEM=i_word_item
	attr=08094

	ITEM=loot_cityman

On=@Death
	hits = <str>
	flags = <flags> & ~statf_dead
	return 1

CATEGORY=Quests and legends
SUBSECTION=Charades
DESCRIPTION=Charade Master


[ITEMDEF i_charade_rune]
//more - serial of word item
//more2 - server time
//morex - rune flag
//morey - temp letter counter
//morez - word length

ID=i_rune_alchem_5
type=t_charadeletter

On=@Create
	attr=08010
	timer=-1


[TYPEDEF t_charadeletter] 
On=@Click 

	if (<src.uid.<more>.type> != t_word_item) || (!<src.uid.<more>.more>) //game over (any problems with rune deleting)
		message You find the Rune! But the game is over, so try again next time.
		src.sysmessage Please report the GM about this rune.
		src.consume 1000 i_letters_flags
		return 1
	endif

	message <name> 

	if (<src.findid(i_letters_flags).timer> < 0) || (<src.restest 2 i_letters_flags>) //if >= 2 items or timer = -1 - delete broken items
		src.consume 1000 i_letters_flags
	endif

	if !(<src.restest 1 i_letters_flags>)
		src.newitem i_letters_flags
		src.act.equip
	endif

	if (<src.findid(i_letters_flags).more> != <more>) || (<src.findid(i_letters_flags).more2> != <more2>)
		src.findid(i_letters_flags).more = <more>
		src.findid(i_letters_flags).more2 = <more2>
		src.findid(i_letters_flags).morex = 0
	endif

	src.findid(i_letters_flags).morey = <src.uid.<more>.morex>-1
	src.findid(i_letters_flags).morex = <src.findid(i_letters_flags).morex> | <morex>
	src.findid(i_letters_flags).timer = 1800
	return 1 

On=@Step 
	return 0 

On=@Pickup_pack 
	if !<src.isgm> 
		return 1 
	endif 

On=@Pickup_ground 
	if !<src.isgm> 
		return 1 
	endif


[ITEMDEF i_letters_flags]
//more - serial of word item
//more2 - server time
//morex - current flags
//morey - flags mask

ID=i_memory
WEIGHT=0
TYPE=t_eq_script
LAYER=30

On=@Create
	attr=08014
	NAME=Charade flags

On=@Equip
	timer = 1800

On=@Timer
	if (<src.uid.<more>.type> != t_word_item) || (!<src.uid.<more>.more>) // game is over
		remove
	else
		timer = 1800
	endif
	return 1

[ITEMDEF i_word_item]
//more - 1 if active
//morex - flags mask
//morey - letters counter
//morez - word length
//more2 - server time

ID=i_deed
TYPE=t_word_item

On=@Create
	color=0
	attr=08094
	timer=-1
	name=/empty/


[TYPEDEF t_word_item]
On=@Dclick
	if <color> == 0486
		src.sysmessage <morey> of <morez> runes has been deleted.
		return 1
	endif

	if !<more>
		name=<strtoupper <name>>
		morez = strlen(<name>)
		morey = <morez>
		morex = 1
		more2 = <serv.time>
		f_create_letters
		color = 0487
		update
	else
		name =/empty/
		color = 0
		f_letters_remove
	endif
	more = !<more>
	return 1

On=@Click
	if !<src.isgm>
		message What's this?
	return 1
	endif


[EOF]