:: relationship_scripts[script]
setup.relationshipModifiers ??= {};
setup.relationshipModifiers.dislike	= {effect:-1,text:' dislikes this'};
setup.relationshipModifiers.hate	= {effect:-3,text:' hates this'};
setup.relationshipModifiers.loathe	= {effect:-5,text:' loathes this'};

setup.relationshipModifiers.dissapointedPP	= {effect:-50,text:' is extremely dissapointed'};

setup.relationshipModifiers.like	= {effect:1,text:' likes this'};
setup.relationshipModifiers.love	= {effect:3,text:' loves this'};
setup.relationshipModifiers.adore	= {effect:5,text:' adores this'};

:: relationship_widgets[widget]
<<widget 'relationship'>>
	<<set [_relNPCId,_relValue,_relFlags] = _args>>

	<<if typeof _relValue == 'string'>>
		<<set _relModifier = setup.relationshipModifiers[_relValue] ?? {}>>
		<<set _relValue = _relModifier.effect ?? 0>>
		<<set _label = $npc(_relNPCId).usedname+(_relModifier.text ?? '')>>
	<</if>>

	<<set _relationshipStyleClass="relationshipModify">>
	<<if _relValue == 0>>
		<<set _relationshipStyleClass+=" neutral">>
	<<elseif _relValue < 0>>
		<<set _relationshipStyleClass+=" negative">>
	<<else>>
		<<set _relationshipStyleClass+=" positive">>
	<</if>>

	<<set _relCurrent = $npcs.rel(_relNPCId)>>
	<<set $npc(_relNPCId).rel = _relCurrent + _relValue>>

	<div @class="_relationshipStyleClass">
		<span class="effectStrength"><<if _relValue > 0>>+<</if>>_relValue → <<=$npc(_relNPCId).rel>></span>
		<span class="label">_label</span>
		<span class="symbols">
			<<textWithTooltip "🎭">>
				<h3>Relationship</h3>
				This is a relationship-effect. It affects your short-term-relationship with the NPC.<br/>
				Your short-term-relationship will quickly trend torwards your long-term-relationship. The opposite effect is way weaker.<br/>
				This way a small slight is quickly forgotten, while constantly annoying somebody else can have a lasting negative consequence.
			<</textWithTooltip>>
		</span>
	</div>
<</widget>>

:: npc_relationship
<<set _ts to Math.floor(Date.now() / 10000)>>
<<setinit $gt_history[_ts][$here] = 0>>
<!-- !{ Interface to the Relationship system.  This system determines the relationship or reputation that the NPC has for the PC
Methods are:
1) modify => adds value to this relationship.  Can be integer(positive or negative) or string with 'like', 'love', 'adore', 'dislike','hate','loathe'
params: NPCID, value
optional params: Number of times a day, string identifying the event.
Number of times a day can be any non negative numerical valuea, a value of 0 means no limit, else the times that a call for the same npc with the sting identifying the event can change relationship in a given day.
2) set => sets relationship to a specific value (used to initialize?)
params: NPCID, value
3) check => like willpower checks, this is used to see if the NPC passes a given threshhold.
params: value, NPCID1,NPCID2,NPCID3....
result: number of NPCs that passed the check
$larg(1) determines the Method being used:
'modify' =>
$larg(1) => NPCID - This is NPC identifier thisis acting one, for example 'A29' is the PC''s mother.
ARGS[2] => integer for how much to change the relationship  can be positive or negative
or
$larg(2) => if third value is a string, the writer doesn't need to know the numberic values, but can use generic amounts
'like'    => moves relationship positively a small amount
'love'    => moves relationship positively a moderate amount
'adore'   => moves relationship positively a large amount
'dislike' => moves relationship negatively a small amount
'hate'    => moves relationship negatively a moderate amount
'loathe'  => moves relationship negatively a large amount
examples:
gs 'npc_relationship', 'modify', 'A29', 2
gs 'npc_relationship', 'modify', 'A29', 'hate'
'set' =>
$larg(1) => NPCID - This is NPC identifier thisis acting one, for example 'A29' is the PC''s mother.
ARGS[2] => integer to set this NPC's relationship to a specific value.
or
$larg(2) => if third value is a string, the writer doesn't need to know the numberic values, but can use generic amounts
'unknown'     => NPC don't know PC
'aquaintance' => NPC knows PC, but not much else
'friend'      => NPC is friends and will probably react favorably
'bestie'      => NPC is a best friend
'loved'       => NPC will die to protect PC
examples:
gs 'npc_relationship', 'set', 'A29', 90
gs 'npc_relationship', 'set', 'A29', 'loved'
!The following will make it possible to only gain relationship with the npc A29 3 times a day for any call with $larg(4) 'disco'
gs 'npc_relationship', 'set', 'A29', 'loved', 3, 'disco'
'check' =>
ARGS[1] => Relationship level to check for.  Should be integer 1 - 100
$larg(2-9) => List of NPCIDs to check, , for example 'A29' is the PC''s mother.
examples:
!Check if one of Mother, Aunt Ludmilla, or Grandma have at least 50 relationship:
if setup.func('npc_relationship', 'check', 50, 'A29', 'A30', 'A31') > 0:
!Check if all of Mother, Aunt Ludmilla, or Grandma have at least 50 relationship:
if setup.func('npc_relationship', 'check', 50, 'A29', 'A30', 'A31') > 2:
!Also if you don't like a function, if sets variable npc_rel_check like WillPower
gs 'npc_relationship', 'check', 50, 'A29', 'A30', 'A31'
if npc_rel_check > 0:
} -->
<<if $location_var[$here][0] == 'modify'>>
	<!-- !Handle if value is numeric-->
	<<if $location_var[$here][2] == ''>>
		<<set $npcRelSetVal = $larg(2)>>
		<!-- !Handle cases where value is a string to be interpreted-->
	<<elseif $location_var[$here][2] == 'like'>>
		<<set $npcRelSetVal = rand(1,2)>>
	<<elseif $location_var[$here][2] == 'love'>>
		<<set $npcRelSetVal = rand(3,4)>>
	<<elseif $location_var[$here][2] == 'adore'>>
		<<set $npcRelSetVal = rand(5,6)>>
	<<elseif $location_var[$here][2] == 'dislike'>>
		<<set $npcRelSetVal = 0-rand(1,2)>>
	<<elseif $location_var[$here][2] == 'hate'>>
		<<set $npcRelSetVal = 0-rand(3,4)>>
	<<elseif $location_var[$here][2] == 'loathe'>>
		<<set $npcRelSetVal = 0-rand(5,6)>>
		<!-- !Handle default value-->
	<<else>>
		<<set $npcRelSetVal = 0>>
	<</if>>
	<!-- !Make sure the new value fits within correct range-->
	<<set $npcRelSetVal += $npc($location_var[$here][1]).rel>>

	<!-- !Make sure that daily limited calls are counted and relationship value only added the allowed times in a given day.-->
	<<if $location_var[$here][3] > 0>>
		<<if $location_var[$here][3] > $npcs.get($location_var[$here][1] ,'rel_daily'+ $location_var[$here][4])>>
			<<run $npcs.inc($location_var[$here][1] ,'rel_daily'+ $location_var[$here][4],1)>>
		<<else>>
			<<set $npcRelSetVal = $npc($location_var[$here][1]).rel>>
		<</if>>
	<</if>>
	<!-- !Checks that relatioship gain is not added to relationship locked npc''s-->
	<<if $location_var[$here][1] == 'A1' and (getvar("$dimaRevenge") == 6 and (getvar("$dimaRevChoice") == 3 or getvar("$dimaRevChoice") == 5 or getvar("$dimaRevChoice") == 6)) or (getvar("$dimaRevenge") == 7 and getvar("$dimaRevChoice") == 2) or (getvar("$dimaRevenge") == 8 and (getvar("$dimaRevChoice") == 1 or getvar("$dimaRevChoice") == 4))>>
		<<set $npcRelSetVal = $npc($location_var[$here][1]).rel>>
	<<elseif $location_var[$here][1] == 'A18' and $npc('a18').rel >= 20>>
		<<set $npcRelSetVal = 20>>
	<</if>>
	<!-- !Set to new value-->
	<<set $npc($location_var[$here][1]).rel = $npcRelSetVal>>
	<<set $npcRelSetVal to null>>
<</if>>
<<if $location_var[$here][0] == 'set'>>
	<!-- !Handle if value is numeric-->
	<<if $location_var[$here][2]>>
		<<set $npcRelSetVal = $larg(2)>>
		<!-- !Handle cases where value is a string to be interpreted-->
	<<elseif $location_var[$here][2] == 'unknown'>>
		<<set $npcRelSetVal = 0>>
	<<elseif $location_var[$here][2] == 'aquaintance'>>
		<<set $npcRelSetVal = 20>>
	<<elseif $location_var[$here][2] == 'friend'>>
		<<set $npcRelSetVal = 50>>
	<<elseif $location_var[$here][2] == 'bestie'>>
		<<set $npcRelSetVal = 70>>
	<<elseif $location_var[$here][2] == 'loved'>>
		<<set $npcRelSetVal = 90>>
		<!-- !Handle default value-->
	<<else>>
		<<set $npcRelSetVal = 0>>
	<</if>>
	<!-- !Make sure the new value fits within correct range-->
	<<if getvar("$npcRelSetVal") > 100>>
		<<set $npcRelSetVal = 100>>

	<</if>>
	<<if getvar("$npcRelSetVal") < 0>>
		<<set $npcRelSetVal = 0>>

	<</if>>
	<!-- !Set to new value-->
	<<set $npc($location_var[$here][1]).rel = $npcRelSetVal>>
	<<set $npcRelSetVal to null>>
<</if>>
<<if $location_var[$here][0] == 'check'>>
	<!-- !Value we are checking against-->
	<<set $npcRelSetVal = $larg(1)>>
	<<set $npc_rel_check = 0>>
	<!-- !Loop through remaining $ARGS entries and count up number of successful compares-->
	<<for $i = 2;$larg($i);$i += 1>>
		<<if $npc($larg($i)).rel >= $npcRelSetVal>>
			<<set $npc_rel_check += 1>>
		<</if>>
	<</for>>
	<<set $result = $npc_rel_check>>
	<<set $npcRelSetVal to null>>
<</if>>
<!-- !! ---------- default value setups ------------->
<!-- !! Family and friends-->
<<if $location_var[$here][0] == 'default_family_friends'>>
	<<gs 'npc_relationship' 'set' 'A28' 50>>
	<<gs 'npc_relationship' 'set' 'A29' 50>>
	<<gs 'npc_relationship' 'set' 'A30' 50>>
	<<gs 'npc_relationship' 'set' 'A31' 50>>
	<<gs 'npc_relationship' 'set' 'A32' 50>>
	<<gs "npc_relationship" "set" "A33" 70>>
	<<gs "npc_relationship" "set" "A34" 50>>
	<<gs "npc_relationship" "set" "A11" 60>>
	<!-- !! default friendship of 40 with Mitka 20 with Kolyamba and Vasyan in Gadukino-->
	<<gs 'npc_relationship' 'set' 'A63' 40>>
	<<gs 'npc_relationship' 'set' 'A62' 20>>
	<<gs 'npc_relationship' 'set' 'A61' 20>>
<</if>>
<!-- ! Adds relationship based on group types ass passed in-->
<!-- !-->
<!-- ! Variable 'sg_setting_gend' can be set for specific gender selection. 1=Male, 2=Female-->
<!-- ! Required Parameters, these are relationships for each of these groups:-->
<!-- !	ARGS[1] = coolkid-->
<!-- !	ARGS[2] = jock-->
<!-- !	ARGS[3] = nerd-->
<!-- !	ARGS[4] = gopnik-->
<!-- !	ARGS[5] = outcast-->
<!-- !	ARGS[6] = teacher-->
<<if $location_var[$here][0] == 'socialgroup_setting_internal'>>
	<<for $i = 1; $i <= 6; $i +=1>>
		<<set _filter = {grupTipe:$i}>>
		<<if $sg_setting_gend>>
			<<set _filter['gender'] = $sg_setting_gend - 1>>
		<</if>>
		<<run $npcs.incBulkByFilter(_filter,'rel',$larg($i))>>
	<</for>>
<</if>>
<<if $location_var[$here][0] == 'socialgroup_setting'>>
	<!-- !All Genders-->
	<<set $sg_setting_gend = 0>>
	<<gs 'npc_relationship' 'socialgroup_setting_internal' $larg(1) $larg(2) $larg(3) $larg(4) $larg(5) $larg(6) $larg(7) $larg(8)>>
<</if>>
<<if $location_var[$here][0] == 'socialgroup_setting_boys'>>
	<!-- !Males-->
	<<set $sg_setting_gend = 1>>
	<<gs 'npc_relationship' 'socialgroup_setting_internal' $larg(1) $larg(2) $larg(3) $larg(4) $larg(5) $larg(6) $larg(7) $larg(8)>>
<</if>>
<<if $location_var[$here][0] == 'socialgroup_setting_girls'>>
	<!-- !Females-->
	<<set $sg_setting_gend = 2>>
	<<gs 'npc_relationship' 'socialgroup_setting_internal' $larg(1) $larg(2) $larg(3) $larg(4) $larg(5) $larg(6) $larg(7) $larg(8)>>
<</if>>
