Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/Helpers/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,23 @@ function current_route()
return Route::getCurrentRoute();
}
}

if ( !function_exists( 'float_rand' ) ) {
/**
* @param int $min
* @param int $max
* @param int $decimalPlaces
*
* @return float|int
*/
function float_rand( $min = 0, $max = 1, $decimalPlaces = 1 )
{
$decimal = '.';
for ( $i = 1; $i < $decimalPlaces; $i++ ) {
$decimal .= '0';
}
$decimal .= '1';

return number_format( rand( $min, $max ) * $decimal, $decimalPlaces );
}
}
133 changes: 120 additions & 13 deletions app/Models/Armor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ class Armor extends GameObject
{
use Wearable;

/**
* @var string
*/
protected $armorType;

/**
* The primary key for the model.
*
Expand Down Expand Up @@ -72,7 +77,6 @@ class Armor extends GameObject
protected $defaults = [
'int' => [
'16' => 1, //Always Usable
'18' => 1, //UI Effects
'27' => 8, //Armor Type???
'53' => 101, //Placement Position
'93' => 1044, //Physics State
Expand Down Expand Up @@ -122,35 +126,59 @@ public function mapData( Request $request )
{
parent::mapData( $request );

$armorType = $request->get( 'armor_type' );
$type = config( 'type.armor.' . $armorType );

$this->setAttribute( 'type', $type[ 'type' ] );
$this->setAttribute( 'weenieType', array_get( $this->stats, $this->type . '.weenieType' ) );

//Icon
$this->defaults[ 'did' ][ '8' ] = config( 'icons.' . $armorType );

//Set the item type
$this->stats[ $this->type ][ 'int' ][ '1' ] = config( $this->configKey( 'item-type' ) . '.id' );
$this->defaults[ 'int' ][ '1' ] = config( $this->configKey( 'item-type' ) . '.id' );

//Clothing Priority
$this->stats[ $this->type ][ 'int' ][ '4' ] = config( $this->configKey( 'clothing-priority' ) . '.id' );
$this->defaults[ 'int' ][ '4' ] = config( $this->configKey( 'clothing-priority' ) . '.id' );

$this->defaults[ 'int' ][ '5' ] = '';

//Set the body location
$this->stats[ $this->type ][ 'int' ][ '9' ] = config( $this->configKey( 'body-location' ) . '.id' );
$this->defaults[ 'int' ][ '9' ] = config( $this->configKey( 'body-location' ) . '.id' );

//Item Workmanship
$this->stats[ $this->type ][ 'int' ][ '105' ] = rand( 1, 10 );
//UI Effects
$this->defaults[ 'int' ][ '18' ] = 0;

//Pyreal Value
$this->defaults[ 'int' ][ '19' ] = rand(
config( $this->configKey( 'pyreal-value' ) . '.min' ),
config( $this->configKey( 'pyreal-value' ) . '.max' )
);

//Armor Level
$this->defaults[ 'int' ][ '28' ] = rand(
config( $this->configKey( 'armor-level' ) . '.min' ),
config( $this->configKey( 'armor-level' ) . '.max' )
);

//Bonded
if ( !$request->has( 'int.33' ) ) {
$this->stats[ $this->type ][ 'int' ][ '33' ] = 0;
$this->defaults[ 'int' ][ '33' ] = 0;
}

//Item Workmanship
$this->defaults[ 'int' ][ '105' ] = rand(
config( $this->configKey( 'workmanship' ) . '.min' ),
config( $this->configKey( 'workmanship' ) . '.max' )
);

//Attuned
if ( !$request->has( 'int.114' ) ) {
$this->stats[ $this->type ][ 'int' ][ '114' ] = 0;
$this->defaults[ 'int' ][ '114' ] = 0;
}

$this->setAttribute( 'int', $this->addDefaults( 'int' ) );
$this->setAttribute( 'bool', $this->addDefaults( 'bool' ) );
$this->setAttribute( 'float', $this->addDefaults( 'float' ) );
$this->setAttribute( 'did', $this->addDefaults( 'did' ) );
$this->setAttribute( 'string', $this->addDefaults( 'string' ) );
$this->addProtections();

$this->spells = $this->addDefaults( 'spells' );

$spellbook = [];
Expand All @@ -162,5 +190,84 @@ public function mapData( Request $request )
}

$this->setAttribute( 'spellbook', $spellbook );

if ( !empty( $spells ) ) {
//UI Effects
$this->defaults[ 'int' ][ '18' ] = 1;

//Spellcraft/Arcane Lore
$arcaneLore = rand(
config( $this->configKey( 'arcane-lore' ) . '.min' ),
config( $this->configKey( 'arcane-lore' ) . '.max' )
);

$this->defaults[ 'int' ][ '106' ] = $arcaneLore;
$this->defaults[ 'int' ][ '109' ] = $arcaneLore;

//Mana Usage Rate
$this->defaults[ 'float' ][ '5' ] = float_rand( 5, 33, 3 );
}

$this->setAttribute( 'int', $this->addDefaults( 'int' ) );
$this->setAttribute( 'bool', $this->addDefaults( 'bool' ) );
$this->setAttribute( 'float', $this->addDefaults( 'float' ) );
$this->setAttribute( 'did', $this->addDefaults( 'did' ) );
$this->setAttribute( 'string', $this->addDefaults( 'string' ) );
}

/**
* @return $this
*/
public function addProtections()
{
//Slashing Protection
$this->defaults[ 'float' ][ '13' ] = float_rand(
config( 'protection.slashing.min' ) * 10,
config( 'protection.slashing.max' ) * 10
);

//Piercing Protection
$this->defaults[ 'float' ][ '14' ] = float_rand(
config( 'protection.piercing.min' ) * 10,
config( 'protection.piercing.max' ) * 10
);

//Bludgeoning Protection
$this->defaults[ 'float' ][ '15' ] = float_rand(
config( 'protection.bludgeoning.min' ) * 10,
config( 'protection.bludgeoning.max' ) * 10
);

//Cold Protection
$this->defaults[ 'float' ][ '16' ] = float_rand(
config( 'protection.cold.min' ) * 10,
config( 'protection.cold.max' ) * 10
);

//Fire Protection
$this->defaults[ 'float' ][ '17' ] = float_rand(
config( 'protection.fire.min' ) * 10,
config( 'protection.fire.max' ) * 10
);

//Acid Protection
$this->defaults[ 'float' ][ '18' ] = float_rand(
config( 'protection.acid.min' ) * 10,
config( 'protection.acid.max' ) * 10
);

//Electrical Protection
$this->defaults[ 'float' ][ '19' ] = float_rand(
config( 'protection.electrical.min' ) * 10,
config( 'protection.electrical.max' ) * 10
);

//Nether Protection
$this->defaults[ 'float' ][ '165' ] = float_rand(
config( 'protection.nether.min' ) * 10,
config( 'protection.nether.max' ) * 10
);

return $this;
}
}
29 changes: 26 additions & 3 deletions app/Models/GameObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
abstract class GameObject extends Model
{
/**
* This is different than $casts, which is what laravel uses to cast eloquent values
*
* @var array
*/
protected $cast = [
Expand All @@ -17,6 +19,26 @@ abstract class GameObject extends Model
],
];

/**
* Mutate the spellbook attribute to use a specific json option when encoding
*
* @param $value
*/
public function setSpellbookAttribute( $value )
{
$this->attributes[ 'spellbook' ] = json_encode( $value, JSON_PRESERVE_ZERO_FRACTION );
}

/**
* Mutate the float attribute to use a specific json option when encoding
*
* @param $value
*/
public function setFloatAttribute( $value )
{
$this->attributes[ 'float' ] = json_encode( $value, JSON_PRESERVE_ZERO_FRACTION );
}

/**
* @param Request $request
*
Expand All @@ -42,7 +64,8 @@ public function mapData( Request $request )
$this->{$camelCase} = $value;
}

$this->setAttribute( 'tier', rand( 1, 9 ) );
/** @todo Change tier attribute from hard-coded to a random value between 1 and 9 */
$this->setAttribute( 'tier', 7 );

return $this;
}
Expand Down Expand Up @@ -85,10 +108,10 @@ public function convertToJson( $pretty = true )
];

if ( $pretty ) {
return json_encode( $json, JSON_PRETTY_PRINT );
return json_encode( $json, JSON_PRETTY_PRINT | JSON_PRESERVE_ZERO_FRACTION );
}

return json_encode( $json );
return json_encode( $json, JSON_PRESERVE_ZERO_FRACTION );
}

/**
Expand Down
51 changes: 42 additions & 9 deletions app/Models/Jewelry.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,36 @@ public function mapData( Request $request )
$this->setAttribute( 'weenieType', array_get( $this->stats, $this->type . '.weenieType' ) );

//Set the item type
$this->stats[ $this->type ][ 'int' ][ '1' ] = config( $this->configKey( 'item-type' ) . '.id' );
$this->defaults[ 'int' ][ '1' ] = config( $this->configKey( 'item-type' ) . '.id' );

//Set the body location
$this->stats[ $this->type ][ 'int' ][ '9' ] = config( $this->configKey( 'body-location' ) . '.id' );
$this->defaults[ 'int' ][ '9' ] = config( $this->configKey( 'body-location' ) . '.id' );

//UI Effects
$this->defaults[ 'int' ][ '18' ] = 0;

//Pyreal Value
$this->defaults[ 'int' ][ '19' ] = rand(
config( $this->configKey( 'pyreal-value' ) . '.min' ),
config( $this->configKey( 'pyreal-value' ) . '.max' )
);

//Bonded
if ( !$request->has( 'int.33' ) ) {
$this->stats[ $this->type ][ 'int' ][ '33' ] = 0;
$this->defaults[ 'int' ][ '33' ] = 0;
}

//Item Workmanship
$this->defaults[ 'int' ][ '105' ] = rand(
config( $this->configKey( 'workmanship' ) . '.min' ),
config( $this->configKey( 'workmanship' ) . '.max' )
);

//Attuned
if ( !$request->has( 'int.114' ) ) {
$this->stats[ $this->type ][ 'int' ][ '114' ] = 0;
$this->defaults[ 'int' ][ '114' ] = 0;
}

$this->setAttribute( 'int', $this->addDefaults( 'int' ) );
$this->setAttribute( 'bool', $this->addDefaults( 'bool' ) );
$this->setAttribute( 'float', $this->addDefaults( 'float' ) );
$this->setAttribute( 'did', $this->addDefaults( 'did' ) );
$this->setAttribute( 'string', $this->addDefaults( 'string' ) );
$this->spells = $this->addDefaults( 'spells' );

$spellbook = [];
Expand All @@ -160,5 +170,28 @@ public function mapData( Request $request )
}

$this->setAttribute( 'spellbook', $spellbook );

if ( !empty( $spells ) ) {
//UI Effects
$this->defaults[ 'int' ][ '18' ] = 1;

//Spellcraft/Arcane Lore
$arcaneLore = rand(
config( $this->configKey( 'arcane-lore' ) . '.min' ),
config( $this->configKey( 'arcane-lore' ) . '.max' )
);

$this->defaults[ 'int' ][ '106' ] = $arcaneLore;
$this->defaults[ 'int' ][ '109' ] = $arcaneLore;

//Mana Usage Rate
$this->defaults[ 'float' ][ '5' ] = float_rand( 5, 33, 3 );
}

$this->setAttribute( 'int', $this->addDefaults( 'int' ) );
$this->setAttribute( 'bool', $this->addDefaults( 'bool' ) );
$this->setAttribute( 'float', $this->addDefaults( 'float' ) );
$this->setAttribute( 'did', $this->addDefaults( 'did' ) );
$this->setAttribute( 'string', $this->addDefaults( 'string' ) );
}
}
7 changes: 6 additions & 1 deletion app/Traits/Wearable.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ protected function addDefaults( $statType )
*/
protected function configKey( $configType )
{
$configKeys = [];
$configKeys = [
'pyreal-value' => 'tiers.' . $this->getAttribute( 'tier' ) . 'pyreal-value',
'workmanship' => 'tiers.' . $this->getAttribute( 'tier' ) . '.workmanship',
];

switch ( $this->getAttribute( 'type' ) ) {
case 'bracelet':
Expand All @@ -129,6 +132,8 @@ protected function configKey( $configType )
$configKeys[ 'item-type' ] = 'item-type.armor';
$configKeys[ 'clothing-priority' ] = 'clothing-priority.armor.chest-ul-arms';
$configKeys[ 'body-location' ] = 'body-location.armor.chest-ul-arms';
$configKeys[ 'armor-level' ] = 'tiers.' . $this->getAttribute( 'tier' ) . '.armor-level';
$configKeys[ 'arcane-lore' ] = 'tiers.' . $this->getAttribute( 'tier' ) . '.arcane-lore';
break;
}

Expand Down
14 changes: 14 additions & 0 deletions config/burden.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* Created by PhpStorm.
* User: lisa
* Date: 12/29/17
* Time: 6:30 PM
*/

return [
'amuli-coat' => [
'min' => 1500,
'max' => 3200,
],
];
7 changes: 7 additions & 0 deletions config/colors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
/**
* Created by PhpStorm.
* User: lisa
* Date: 12/29/17
* Time: 4:45 PM
*/
Loading