//****************************************************************************
//SPHERE by : Menasoft ©1997-2007
//www.sphereserver.net
// All SPHERE script files and formats are copyright Menasoft & Partners.
// This file may be freely edited for personal use, but may not be distributed
// in whole or in part, in any format without express written permission from
// Menasoft & Partners.  All donations and contributions
// become the property of Menasoft & Partners.
//****************************************************************************
// FILE LAST UPDATED: 14-March-2007
VERSION=0.56b

// ------------------------------------------------------
// ------------------------------------------------------
// ------------------------------------------------------
[FUNCTION TRANSFERSTONE]
src.targetf f_stonesys_transfer <args>
src.sysmessage Who do you wish to transfer the <f_stonesys_gettypename <args>> to?

[FUNCTION f_stonesys_transfer]
// args = stone uid
// argo = future owner
ref1 = <args>
local.typename = <f_stonesys_gettypename <ref1.uid>>

If (<argo.isitem>)
  sysmessage You cannot transfer a <local.typename> to that.
elif (<argo.npc>)
  sysmessage You cannot transfer a <local.typename> to an npc.
elif (<argo> == <ref1.masteruid>)
  sysmessage You are already the master of <ref1.name>.
elif (<argo.memoryfindtype.memory_guild.link.uid> != <ref1.uid>) && (<argo.memoryfindtype.memory_town.link.uid> != <ref1.uid>)
  sysmessage That player is not a member of the <local.typename>.
elif (!<argo.npc>)
  ref1.masteruid = <argo.uid>
  serv.log <name> (<uid>) transferred <sex his/her> <local.typename> (<ref1.name>) to <argo.name> (<argo.uid>)
  sysmessage @038A You have transfered the <local.typename> to <argo.name>.
  argo.sysmessage @038A You are now the master of <ref1.name>.
else
  sysmessage You cannot transfer a <local.typename> to that.
endif
return 1

// ------------------------------------------------------
[FUNCTION f_stonesys_isnameused]
local.stoneuid=<argv[0]>
local.typeid=<qval (<uid.<local.stoneuid>.type> == t_stone_guild) ? 1 : 0>
local.name=<strsub <eval (strlen(<local.stoneuid>) + 1)> <eval strlen(<args>)> <args>>


local.index=0
local.return=0
local.totalstones=<qval (<local.typeid>) ? <serv.guildstones.count> : <serv.townstones.count>>

while (<local.index> < <local.totalstones>)
  local.currentstoneuid=<qval (<local.typeid>) ? <serv.guildstones.<local.index>.uid> : <serv.townstones.<local.index>.uid>>
  If (<local.currentstoneuid>)
    If (!strcmpi(<uid.<local.currentstoneuid>.name>,<local.name>))
      local.return=1
      local.index=<local.totalstones> + 1
    endif
  endif
  
  local.index += 1
endwhile

return <local.return>

// ------------------------------------------------------
[FUNCTION f_stonesys_isabbrevused]
local.stoneuid=<argv[0]>
local.typeid=<qval (<uid.<local.stoneuid>.type> == t_stone_guild) ? 1 : 0>
local.abbrev=<strsub <eval (strlen(<local.stoneuid>) + 1)> <eval strlen(<args>)> <args>>

local.index=0
local.return=0
local.totalstones=<qval (<local.typeid>) ? <serv.guildstones.count> : <serv.townstones.count>>

while (<local.index> < <local.totalstones>)
  local.currentstoneuid=<qval (<local.typeid>) ? <serv.guildstones.<local.index>.uid> : <serv.townstones.<local.index>.uid>>
  If (<local.currentstoneuid>)
    If (!strcmpi(<uid.<local.currentstoneuid>.abbrev>,<local.abbrev>))
      local.return=1
      local.index=<local.totalstones> + 1
    endif
  endif
  
  local.index += 1
endwhile

return <local.return>

// ------------------------------------------------------
[FUNCTION f_stonesys_sendsmsg]
ref1=<argv[0]>
local.message=<StrEat <args>>

If ((<ref1.type>!=t_stone_guild) && (<ref1.type>!=t_stone_town))
  return 0
endif

If (!strlen(<local.message>))
  return 0
endif

ref1.allmembers -1,sysmessage @68,0,0 <f_stonesys_gettypename <ref1.uid>> Message: <local.message>

// ------------------------------------------------------
[FUNCTION f_stonesys_speech_sendsmsg]
ref1=<argv[0]>
local.message=<StrEat <args>>

If ((<ref1.type>!=t_stone_guild) && (<ref1.type>!=t_stone_town))
  return 0
endif

If (!strlen(<local.message>))
  return 0
endif

ref1.allmembers -1,sysmessage @68,0,0 <f_stonesys_gettypename <ref1.uid>> Message[<name>]: <local.message>

// ------------------------------------------------------
[FUNCTION f_stonesys_determine_timeleft]
local.sec=<eval (<argn>-<serv.time>)/10>
If (<eval <local.sec>/86400>)
  local.timeleft=<eval <local.sec>/86400> day(s)
elif (<eval <local.sec>/3600>)
  local.timeleft=<eval <local.sec>/3600> hour(s)
elif (<eval <local.sec>/60>)
  local.timeleft=<eval <local.sec>/60> min(s)
else
  local.timeleft=<eval <local.sec>> second(s).
endif
return <local.timeleft>

// ------------------------------------------------------
[FUNCTION f_stonesys_gettypename]
ref1 = <argv[0]> // The stone

local.typename = <DEF.STONECONFIG_TYPENAME_UNK>
if ( !<ref1.isitem> )
elif ( <ref1.type> == t_stone_guild )
	local.typename = <DEF.STONECONFIG_TYPENAME_GUILD>
elif ( <ref1.type> == t_stone_town )
	local.typename = <DEF.STONECONFIG_TYPENAME_TOWN>
endif

return <local.typename>

// ------------------------------------------------------

[function f_stonesys_updatenoto]
ref1 = <argv[0]> // The stone
if (<ref1.IsChar>)
	return 0
endif
If ((<ref1.type>!=t_stone_guild) && (<ref1.type>!=t_stone_town))
  return 0
endif
for member 0 <eval <ref1.member.count> - 1>
	ref10 = <ref1.member.<dlocal.member>>
	if (<ref10.IsOnline>)
		ref10.NotoUpdate
	endif
endfor

// ------------------------------------------------------
// -------   Hardcoded functions called by Sphere  -------
// ------------------------------------------------------

// Called to check If a stone is at war (If commented sphere will use its internal check)
// I -> Stone
// ARGO -> Stone to check against
// return -> 0: not an enemy
//           1: an enemy
//           2: use sphere internal check
[COMMENT FUNCTION f_stonesys_internal_isatwarwith]
If ((<type> == t_stone_guild) && (<argo.type> == t_stone_guild))
	If (<align> && <argo.align>)
	  return (<align>!=<argo.align>)
	endif
	
	If (<guildfromuid.<argo.uid>.isenemy> && <argo.guildfromuid.<uid>.isenemy>)
	  return 1
	endif
	
	return 0
else If ((<type> == t_stone_town) && (<argo.type> == t_stone_town))
	If (<guildfromuid.<argo.uid>.isenemy> && <argo.guildfromuid.<uid>.isenemy>)
	  return 1
	endif
	
	return 0
endif

return 2


// Called to check If a stone is allied (If commented sphere will use its internal check)
// I -> Stone
// ARGO -> Stone to check against
// return -> 0: not an ally
//           1: an ally
//           2: use sphere internal check
[COMMENT FUNCTION f_stonesys_internal_isalliedwith]
If ((<type> == t_stone_guild) && (<argo.type> == t_stone_guild))
	If (<guildfromuid.<argo.uid>.isally> && <argo.guildfromuid.<uid>.isally>)
	  return 1
	endif

	return 0
endif

return 2

[EOF]