from toee import *
from utilities import *
from InventoryRespawn import *

def san_dialog( attachee, triggerer ):
	if ( game.quests[11].state != qs_botched and game.global_vars[996] == 0):
		triggerer.begin_dialog( attachee, 1 )
	elif ( game.global_vars[996] == 2 and game.quests[90].state == qs_unknown):
		triggerer.begin_dialog( attachee, 210 )
	elif ( game.global_vars[996] == 2 and game.quests[90].state != qs_unknown):
		triggerer.begin_dialog( attachee, 280 )
	else:
		triggerer.begin_dialog( attachee, 30 )
	return SKIP_DEFAULT

def san_first_heartbeat(attachee, triggerer):
	game.timevent_add(respawn, (attachee), 86400000 ) #86400000ms is 24 hours
	game.new_sid = 0
	return RUN_DEFAULT

def	san_spell_cast( attachee, triggerer, spell ):
	if ( spell.spell == spell_heal ):
		if ( game.quests[11].state == qs_mentioned or game.quests[11].state == qs_accepted ):
			game.global_vars[996] = 1
			triggerer.begin_dialog( attachee, 60 )
		else:
			game.quests[11].state = qs_botched
			game.global_vars[996] = 2
			triggerer.begin_dialog( attachee, 70 )
	return RUN_DEFAULT

	##Removed this groovy little script by Ted as 1 week delay for masterwork items needs the script breaking down into separate parts - Zeb
#def respawn(attachee):
	#for box in game.obj_list_vicinity( attachee.location, OLC_CONTAINER ): 
		#if box.name == 1001 and box.obj_get_int(obj_f_container_inventory_source) == 342:
			#RespawnInventory(box)
			#game.timevent_add(respawn, (attachee), 86400000 ) #86400000ms is 24 hours
	#return

def masterwork_timer(npc, pc):
	game.global_vars[996] = 3
	game.timevent_add(masterwork, (npc), 604800000) #604800000ms is one week
	return
	
def masterwork(attachee):
	box = find_container_near(attachee,1001)
	box.obj_set_int( obj_f_container_inventory_source, 342 )
	game.global_vars[996] = 4
	RespawnInventory(box)
	return
	
def respawn(attachee):
	for box in game.obj_list_vicinity( attachee.location, OLC_CONTAINER ): 
		if (box.name == 1001 and box.obj_get_int(obj_f_container_inventory_source) == 342):
			RespawnInventory(box)
			game.timevent_add(respawn, (attachee), 86400000 ) #86400000ms is 24 hours
	return
	