Pass $playerSample as parameter to hook

This commit is contained in:
slawkens 2024-05-30 10:09:31 +02:00
parent 3844ad0d71
commit 968899ef77

View File

@ -149,9 +149,9 @@ class CreateCharacter
if(empty($errors)) if(empty($errors))
{ {
$char_to_copy_name = config('character_samples')[$vocation]; $char_to_copy_name = config('character_samples')[$vocation];
$char_to_copy = new \OTS_Player(); $playerSample = new \OTS_Player();
$char_to_copy->find($char_to_copy_name); $playerSample->find($char_to_copy_name);
if(!$char_to_copy->isLoaded()) if(!$playerSample->isLoaded())
$errors[] = 'Wrong characters configuration. Try again or contact with admin. ADMIN: Go to Admin Panel -> Settings -> Create Character and set valid characters to copy names. Character to copy: <b>'.$char_to_copy_name.'</b> doesn\'t exist.'; $errors[] = 'Wrong characters configuration. Try again or contact with admin. ADMIN: Go to Admin Panel -> Settings -> Create Character and set valid characters to copy names. Character to copy: <b>'.$char_to_copy_name.'</b> doesn\'t exist.';
} }
@ -162,72 +162,72 @@ class CreateCharacter
global $db; global $db;
if($sex == "0") if($sex == "0")
$char_to_copy->setLookType(136); $playerSample->setLookType(136);
$player = new \OTS_Player(); $player = new \OTS_Player();
$player->setName($name); $player->setName($name);
$player->setAccount($account); $player->setAccount($account);
$player->setGroupId(1); $player->setGroupId(1);
$player->setSex($sex); $player->setSex($sex);
$player->setVocation($char_to_copy->getVocation()); $player->setVocation($playerSample->getVocation());
if($db->hasColumn('players', 'promotion')) if($db->hasColumn('players', 'promotion'))
$player->setPromotion($char_to_copy->getPromotion()); $player->setPromotion($playerSample->getPromotion());
if($db->hasColumn('players', 'direction')) if($db->hasColumn('players', 'direction'))
$player->setDirection($char_to_copy->getDirection()); $player->setDirection($playerSample->getDirection());
$player->setConditions($char_to_copy->getConditions()); $player->setConditions($playerSample->getConditions());
$rank = $char_to_copy->getRank(); $rank = $playerSample->getRank();
if($rank->isLoaded()) { if($rank->isLoaded()) {
$player->setRank($char_to_copy->getRank()); $player->setRank($playerSample->getRank());
} }
if($db->hasColumn('players', 'lookaddons')) if($db->hasColumn('players', 'lookaddons'))
$player->setLookAddons($char_to_copy->getLookAddons()); $player->setLookAddons($playerSample->getLookAddons());
$player->setTownId($town); $player->setTownId($town);
$player->setExperience($char_to_copy->getExperience()); $player->setExperience($playerSample->getExperience());
$player->setLevel($char_to_copy->getLevel()); $player->setLevel($playerSample->getLevel());
$player->setMagLevel($char_to_copy->getMagLevel()); $player->setMagLevel($playerSample->getMagLevel());
$player->setHealth($char_to_copy->getHealth()); $player->setHealth($playerSample->getHealth());
$player->setHealthMax($char_to_copy->getHealthMax()); $player->setHealthMax($playerSample->getHealthMax());
$player->setMana($char_to_copy->getMana()); $player->setMana($playerSample->getMana());
$player->setManaMax($char_to_copy->getManaMax()); $player->setManaMax($playerSample->getManaMax());
$player->setManaSpent($char_to_copy->getManaSpent()); $player->setManaSpent($playerSample->getManaSpent());
$player->setSoul($char_to_copy->getSoul()); $player->setSoul($playerSample->getSoul());
for($skill = \POT::SKILL_FIRST; $skill <= \POT::SKILL_LAST; $skill++) { for($skill = \POT::SKILL_FIRST; $skill <= \POT::SKILL_LAST; $skill++) {
$value = 10; $value = 10;
if (setting('core.use_character_sample_skills')) { if (setting('core.use_character_sample_skills')) {
$value = $char_to_copy->getSkill($skill); $value = $playerSample->getSkill($skill);
} }
$player->setSkill($skill, $value); $player->setSkill($skill, $value);
} }
$player->setLookBody($char_to_copy->getLookBody()); $player->setLookBody($playerSample->getLookBody());
$player->setLookFeet($char_to_copy->getLookFeet()); $player->setLookFeet($playerSample->getLookFeet());
$player->setLookHead($char_to_copy->getLookHead()); $player->setLookHead($playerSample->getLookHead());
$player->setLookLegs($char_to_copy->getLookLegs()); $player->setLookLegs($playerSample->getLookLegs());
$player->setLookType($char_to_copy->getLookType()); $player->setLookType($playerSample->getLookType());
$player->setCap($char_to_copy->getCap()); $player->setCap($playerSample->getCap());
$player->setBalance(0); $player->setBalance(0);
$player->setPosX(0); $player->setPosX(0);
$player->setPosY(0); $player->setPosY(0);
$player->setPosZ(0); $player->setPosZ(0);
if($db->hasColumn('players', 'stamina')) { if($db->hasColumn('players', 'stamina')) {
$player->setStamina($char_to_copy->getStamina()); $player->setStamina($playerSample->getStamina());
} }
if($db->hasColumn('players', 'loss_experience')) { if($db->hasColumn('players', 'loss_experience')) {
$player->setLossExperience($char_to_copy->getLossExperience()); $player->setLossExperience($playerSample->getLossExperience());
$player->setLossMana($char_to_copy->getLossMana()); $player->setLossMana($playerSample->getLossMana());
$player->setLossSkills($char_to_copy->getLossSkills()); $player->setLossSkills($playerSample->getLossSkills());
} }
if($db->hasColumn('players', 'loss_items')) { if($db->hasColumn('players', 'loss_items')) {
$player->setLossItems($char_to_copy->getLossItems()); $player->setLossItems($playerSample->getLossItems());
$player->setLossContainers($char_to_copy->getLossContainers()); $player->setLossContainers($playerSample->getLossContainers());
} }
$player->save(); $player->save();
@ -245,7 +245,7 @@ class CreateCharacter
for($skill = \POT::SKILL_FIRST; $skill <= \POT::SKILL_LAST; $skill++) { for($skill = \POT::SKILL_FIRST; $skill <= \POT::SKILL_LAST; $skill++) {
$value = 10; $value = 10;
if (setting('core.use_character_sample_skills')) { if (setting('core.use_character_sample_skills')) {
$value = $char_to_copy->getSkill($skill); $value = $playerSample->getSkill($skill);
} }
$skillExists = $db->query('SELECT `skillid` FROM `player_skills` WHERE `player_id` = ' . $player->getId() . ' AND `skillid` = ' . $skill); $skillExists = $db->query('SELECT `skillid` FROM `player_skills` WHERE `player_id` = ' . $player->getId() . ' AND `skillid` = ' . $skill);
if($skillExists->rowCount() <= 0) { if($skillExists->rowCount() <= 0) {
@ -255,7 +255,7 @@ class CreateCharacter
} }
if ($db->hasTable('player_items') && $db->hasColumn('player_items', 'pid') && $db->hasColumn('player_items', 'sid') && $db->hasColumn('player_items', 'itemtype')) { if ($db->hasTable('player_items') && $db->hasColumn('player_items', 'pid') && $db->hasColumn('player_items', 'sid') && $db->hasColumn('player_items', 'itemtype')) {
$loaded_items_to_copy = $db->query("SELECT * FROM player_items WHERE player_id = ".$char_to_copy->getId().""); $loaded_items_to_copy = $db->query("SELECT * FROM player_items WHERE player_id = ".$playerSample->getId()."");
foreach($loaded_items_to_copy as $save_item) { foreach($loaded_items_to_copy as $save_item) {
$blob = $db->quote($save_item['attributes']); $blob = $db->quote($save_item['attributes']);
$db->query("INSERT INTO `player_items` (`player_id` ,`pid` ,`sid` ,`itemtype`, `count`, `attributes`) VALUES ('".$player->getId()."', '".$save_item['pid']."', '".$save_item['sid']."', '".$save_item['itemtype']."', '".$save_item['count']."', $blob);"); $db->query("INSERT INTO `player_items` (`player_id` ,`pid` ,`sid` ,`itemtype`, `count`, `attributes`) VALUES ('".$player->getId()."', '".$save_item['pid']."', '".$save_item['sid']."', '".$save_item['itemtype']."', '".$save_item['count']."', $blob);");
@ -267,6 +267,7 @@ class CreateCharacter
[ [
'account' => $account, 'account' => $account,
'player' => $player, 'player' => $player,
'samplePlayer' => $playerSample,
'name' => $name, 'name' => $name,
'sex' => $sex, 'sex' => $sex,
'vocation' => $vocation, 'vocation' => $vocation,