﻿[color=blue][size=18]NPC-Chatsystem[/size][/color]
Nachdem ja nun längere Zeit nichts wirklich neues mehr von mir hier erschienen ist, gibt es jetzt das frisch überarbeitet NPC-Chatsystem.
[color=blue]Nur um gleich Missverständnisse auszuschließen: Es handelt sich hier [b]nicht[/b] um Chatbots öder ähnliches, sondern von Usern per Chat-Kommando gesteuerte Figuren.[/color]
Doch zunächst die [b]Vorraussetzungen:[/b]
[list]
	PHP Version 5 oder höher
	[url=http://anpera.homeip.net/forum/viewtopic.php?t=2646]Eliwoods OOP-Commentary Much-in-One Bundle (PHP 5 Version)[/url]
	RPG-Belohnungssystem von mir (optional)
	Grundlegende Kenntnisse über LotgD für den Einbau
[/list]

Im Gegenzug auch gleich die [b]Features:[/b]
[i](Texte in [color=blue]blau[/color] sind in erster Linie für den Admin interessant)[/i]
[list]
	[b]Chatten über andere Figuren als den eigenen Charaker durch NPCs[/b]
	Eigene Bio mit Name, Spielern, Avatar und Beschreibung für jeden NPC
	Erschaffen von NPC-Figuren gegen [i]Punkte[/i]
	Jederzeit mögliches Abändern der Werte des NPCs gegen [i]Punkte[/i]
	Gemeinsame Nutzung der NPCs von mehreren Spielern (share)
	[color=blue][i]Punkte[/i] sind Wahlweise RP-Punkte oder Donation-Points[/color]
	[color=blue]Frei wählbare Preise für die Änderung von Name, Bscheibung, Avatar und Share der NPCs[/color]
[/list]

Und schlussendlich noch ausstehende [b]ToDos:[/b]
[list][color=red]
	Automatische Generierung von NPCs als Kinder in -Doms Kindermod
	Cheatschutz-Systeme gegen Namenstäuschung
	Standard Chat-Farben auch für NPCs
	Unterstüttzung der NPC-Anzeige schon im JS-Preview
[/color][/list]

[size=12]Installation[/size]
Nachdem alle Vorrausstzungen erfüllt sind, geht es nun an die Installation.
Zunächst die Datei npc.class.php in das lib-Verzeichnis hochgeladen werden, die npc.php kommt ins LotgD-Root.
Nun muss noch folgender SQL-Query ausgeführt ...

[code]ALTER TABLE `accounts` ADD npc BOOLEAN NOT NULL;
ALTER TABLE `commentary` ADD control TINYINT NOT NULL;[/code]

...Und ein paar Dateien verändert werden:

[b]prefs.php[/b]
[php]// Suche:
$form=array(
		"Einstellungen,title"
		...
	);
	// Füge danach ein:
	if($session['user']['npc']) {
		require_once "lib/npc.class.php";
		//$npcs = getUsrNPCsData($session['user']['acctid']);
		$npcs = npc::getAllOf($session['user']['acctid'],false);
		$text = "Der NPC den du im moment verwenden möchtest,enum";
		foreach($npcs as $npc) {
			$text .= ",".$npc->getId().",".$npc->getName();
		}
	} else {
		$text = "Leider hast du noch keine NPCs,viewonly";
	}
	$form['akt_npc'] = $text;
[/php]

[b]lib/commentary.php[/b]
[php]// Suche:
# Einstellungen
	
	// Füge danach ein:
require_once 'npc.class.php';
function beginsWith($in,$with) {
		// Kleine Funktion für netteren Code by Auric
	return (strtolower(substr($in,0,strlen($with)))===$with?true:false);
}


	// Suche: [function Add()]

// Emotecheck
$emote = 0;
if(substr($commentary,0,2) === '::') {
		$commentary = $this->coloremote.substr($commentary,2);
		$emote = 1;
}
elseif(substr($commentary,0,1) === ':') {
		$commentary = $this->coloremote.substr($commentary,1);
		$emote = 1;
}
elseif(strtolower(substr($commentary,0,3)) === '/me') {
		$commentary = $this->coloremote.substr($commentary,3);
		$emote = 1;
}
elseif(strtolower(substr($commentary,0,3)) === '/em') {
		$commentary = $this->color3person.substr($commentary,3);
		$emote = 2;
}
elseif(strtolower(substr($commentary,0,2)) === '/x') {
		$commentary = $this->color3person.substr($commentary,2);
		$emote = 2;
}
elseif(strtolower(substr($commentary,0,3)) === '/ms') {
		$commentary = $this->coloremote.substr($commentary,3);
		$emote = 3;
}
else {
		$commentary = $this->colorspeak.$commentary;
}

	// Ersetze mit:

// Emotecheck
$emote = 0;
if(beginsWith($commentary,'::')) {
	$commentary = $this->coloremote.substr($commentary,2);
	$emote = 1;
}	elseif(beginsWith($commentary,':')) {
	$commentary = $this->coloremote.substr($commentary,1);
	$emote = 1;
}	elseif(beginsWith($commentary,'/me')) {
	$commentary = $this->coloremote.substr($commentary,3);
	$emote = 1;
}	elseif(beginsWith($commentary,'/em')) {
	$commentary = $this->color3person.substr($commentary,3);
	$emote = 2;
}	elseif(beginsWith($commentary,'/x')) {
	$commentary = $this->color3person.substr($commentary,2);
	$emote = 2;
}	elseif(beginsWith($commentary,'/ms')) {
	$commentary = $this->coloremote.substr($commentary,3);
	$emote = 3;
		// Erweiterte Überprüfung für NPCs by Auric:
}	elseif(beginsWith($commentary,'/npc')) {
	$commentary = $this->colornpc.substr($commentary,5);
	$emote = 5;
} else {
	$commentary = $this->colorspeak.$commentary;
}


	// Suche: [function Insert()]
$sql = 'INSERT INTO `commentary` (`author`,`comment`,`section`,`emote`,`postdate`) '
	
	// Ersetze mit:
$sql = 'INSERT INTO `commentary` (`author`,`comment`,`section`,`emote`,`postdate`'.($this->emote==5?',`control`':'').') '


	// Suche: [function Insert()]
.'"'.$this->emote.'",'

	// Füge danach ein:
.($this->emote==5?", '".npc::getActOf($author)."'":'')


	// Suche:
if(NOBIO === false) {
	$linktemplate = '`0<a href="bio.php?char={$LOGIN}&ret={$REQUESTURI}" style="text-decoration: none">'.endl.'`&{$NAME}`0</a>'.endl;
}
else {
	$linktemplate = '{$NAME}';
}	
	// Ersetze mit:
if(NOBIO === false) {
	$linktemplate = '`0<a href="bio.php?char={$LOGIN}&ret={$REQUESTURI}" style="text-decoration: none" title="{$STATUSRP}">'.endl.'`&{$NAME}`0</a>'.endl;
	$npclinktemplate = '`0<a href="npc.php?op=bio&id={$ID}&ret={$REQUESTURI}" style="text-decoration: none">'.endl.'`&{$NPC}`0</a>'.endl;
} else {
	$linktemplate = '{$NAME}';
	$npclinktemplate = '{$NPC}';
}
$sea4linktemplateN = array('{$ID}','{$REQUESTURI}','{$NPC}');


	// Suche:
switch($row['emote']) {

	// Füge Danach ein:
case 5:	// NPC-Erweiterung von Auric
	$npcsql = "SELECT `id`, `name` FROM `npc` WHERE `id`=".$row["control"]." LIMIT 1";
	$npcres = db_query($npcsql) or die(db_error(LINK));
	$npc = db_fetch_assoc($npcres);

	$rep4linktemplateN = array($npc['id'],RawURLEncode($REQUEST_URI),$npc['name']);
	$row['npc'] = str_replace($sea4linktemplateN,$rep4linktemplateN,$npclinktemplate);
	$npclink = str_replace($sea4linktemplateN,$rep4linktemplateN,'npc.php?op=bio&id={$ID}&ret={$REQUESTURI}');
	addnav('',$npclink);
	$comments[] = $prefix.str_replace($search,$replace,'`&'.$row['npc'].' '.$this->nl2paragraph($row['comment'])."`0\r\n");
	break;
[/php]

[b]configuration.php[/b]
[php]	// Suche:
"oldmail"=>"Alte Nachrichten automatisch löschen nach x Tagen. x =,int",

	// Füge danach ein: 
	
	'NPC-Settings (NPC-System by Auric),title',
	'NPC_CURRENCY' => 'Währung zum Kauf von NPCs,enum,dp,Donationpoints,rp,RP-Punkte',
	'NPC_COST_ACTIVATE' => 'Kosten zum Freischalten des NPC-Modus (Standard RP:20; DP:100),int',
	'NPC_COST_BUY' => 'Kaufpreis eines NPCs (Standard RP:20; DP:100),int',
	'NPC_COST_NAME' => 'Preis zum Umbenennen eines NPCs (Standard RP:10; DP:50),int',
	'NPC_COST_TEXT' => 'Preis zum Ändern der NPC-Beschreibung (Standard RP:3; DP:15),int',
	'NPC_COST_AVATAR' => 'Preis zum Ändern des NPC-Avatars (Standard: 0),int',
	'NPC_COST_GRANT' => 'Preis für eine NPC-Freigabe (Standard RP:12; DP:60),int',
	'NPC_GRANT_MAX' => 'Maximale Anzahl von Spielern pro NPC (Standard: 5),int',
[/php]
[b]Speichern und Hochladen[/b]

So, nun müsst ihr noch einmal in den Spieleinstellungen vorbeischauen und dort in den soeben angelegten Konfigurationsfeldern eure gewünschten Preise für die einzelnen Operationen angeben.

Das Wärs dann auch, euer NPC-System sollte nun lauffähig sein.
Bedenkt, das sich eure Spieler noch für einen gewissen Betrag für den NPC-Modus freischalten müssen.