Skip to content

Commit

Permalink
Removed Affix Damage and replaced it with damage_amount. There are fa…
Browse files Browse the repository at this point in the history
…iling tests.
  • Loading branch information
AdamKyle committed Jan 5, 2024
1 parent c7c616a commit 5fc7dab
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 56 deletions.
122 changes: 122 additions & 0 deletions app/Console/AfterDeployment/ChangeDamageAmountOnAffixes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php

namespace App\Console\AfterDeployment;

use App\Flare\ExponentialCurve\Curve\ExponentialAttributeCurve;
use App\Flare\Models\ItemAffix;
use App\Flare\Values\ItemAffixType;
use App\Flare\Values\RandomAffixDetails;
use Illuminate\Console\Command;

class ChangeDamageAmountOnAffixes extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'change:damage-amount-on-affixes';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Changes the damage amount on affixes';

/**
* Execute the console command.
*/
public function handle(ExponentialAttributeCurve $exponentialAttributeCurve) {
$regularStackingAffixes = ItemAffix::whereNotNull('damage')
->where('randomly_generated', false)
->where('affix_type', ItemAffixType::DAMAGE_STACKING)
->orderBy('skill_level_required', 'asc')
->get();

$damageAmounts = $this->generateFloats(
$exponentialAttributeCurve,
$regularStackingAffixes->count(),
0.02,
0.6,
0.5,
0.03,
);

$regularStackingAffixes->each(function($affix, $index) use($damageAmounts) {
$affix->update([
'damage_amount' => $damageAmounts[$index],
]);
});

$regularNonStackingAffixes = ItemAffix::whereNotNull('damage')
->where('randomly_generated', false)
->where('affix_type', ItemAffixType::DAMAGE_IRRESISTIBLE)
->orderBy('skill_level_required', 'asc')
->get();

$damageAmounts = $this->generateFloats(
$exponentialAttributeCurve,
$regularNonStackingAffixes->count(),
0.02,
1.25,
0.5,
0.03,
);

$regularNonStackingAffixes->each(function($affix, $index) use($damageAmounts) {
$affix->update([
'damage_amount' => $damageAmounts[$index],
]);
});

$affixCots = [
RandomAffixDetails::BASIC,
RandomAffixDetails::MEDIUM,
RandomAffixDetails::LEGENDARY,
RandomAffixDetails::MYTHIC,
];

foreach ($affixCots as $cost) {
$stackingUniqueAffixes = ItemAffix::whereNotNull('damage')
->where('randomly_generated', true)
->where('irresistible_damage', false)
->where('damage_can_stack', true)
->where('affix_type', ItemAffixType::RANDOMLY_GENERATED)
->where('cost', $cost)
->get();

$stackingUniqueAffixes->each(function($affix) use($cost) {
$damageValues = (new RandomAffixDetails($cost))->getDamageRange();

$affix->update([
'damage_amount' => rand($damageValues[0], $damageValues[1]) / 100,
]);
});

$nonStackingUniqueAffixes = ItemAffix::where('randomly_generated', true)
->where('affix_type', ItemAffixType::RANDOMLY_GENERATED)
->where('irresistible_damage', true)
->where('damage_can_stack', false)
->where('cost', $cost)
->get();

$nonStackingUniqueAffixes->each(function($affix) use($cost) {
$damageValues = (new RandomAffixDetails($cost))->getDamageRange();

$affix->update([
'damage_amount' => rand($damageValues[0], $damageValues[1]) / 100,
]);
});
}
}

protected function generateFloats(ExponentialAttributeCurve $exponentialAttributeCurve, float $size, float $min, float $max, float $increase, float $range): array {
$curve = $exponentialAttributeCurve->setMin($min)
->setMax($max)
->setIncrease($increase)
->setRange($range);

return $curve->generateValues($size, false);
}
}
2 changes: 1 addition & 1 deletion app/Flare/Builders/AffixAttributeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function setCoreModifiers(): array {

public function setDamageDetails(): array {
return [
'damage' => rand($this->damageRange[0], $this->damageRange[1]),
'damage_amount' => rand($this->damageRange[0], $this->damageRange[1]) / 100,
'irresistible_damage' => $this->canHave(),
'damage_can_stack' => $this->canHave(),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ protected function baseAttack(string $attackType, bool $voided = false): array {
'affixes' => [
'cant_be_resisted' => $this->characterStatBuilder->canAffixesBeResisted(),
'stacking_damage' => $this->characterStatBuilder->buildAffixDamage('affix-stacking-damage', $voided),
$this->characterStatBuilder->buildAffixDamage('affix-irresistible-damage-stacking', $voided),
'non_stacking_damage' => $this->characterStatBuilder->buildAffixDamage('affix-non-stacking', $voided),
$this->characterStatBuilder->buildAffixDamage('affix-irresistible-damage-non-stacking', $voided),
'stacking_life_stealing' => $this->characterStatBuilder->buildAffixDamage('life-stealing', $voided),
'life_stealing' => $this->characterStatBuilder->buildAffixDamage('life-stealing', $voided),
'entrancing_chance' => $this->characterStatBuilder->buildEntrancingChance($voided)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ public function buildAffixStackingDamage(bool $voided = false): int {
return 0;
}

$itemSuffix = $this->inventory->where('item.itemSuffix.damage_can_stack', true)->sum('item.itemSuffix.damage');
$itemPrefix = $this->inventory->where('item.itemPrefix.damage_can_stack', true)->sum('item.itemPrefix.damage');
$itemSuffix = $this->inventory->where('item.itemSuffix.damage_can_stack', true)->sum('item.itemSuffix.damage_amount');
$itemPrefix = $this->inventory->where('item.itemPrefix.damage_can_stack', true)->sum('item.itemPrefix.damage_amount');

return $itemSuffix + $itemPrefix;
}
Expand All @@ -158,8 +158,8 @@ public function buildAffixNonStackingDamage(bool $voided = false): int {
return 0;
}

$itemSuffix = $this->inventory->where('item.itemSuffix.damage_can_stack', false)->sum('item.itemSuffix.damage');
$itemPrefix = $this->inventory->where('item.itemPrefix.damage_can_stack', false)->sum('item.itemPrefix.damage');
$itemSuffix = $this->inventory->where('item.itemSuffix.damage_can_stack', false)->sum('item.itemSuffix.damage_amount');
$itemPrefix = $this->inventory->where('item.itemPrefix.damage_can_stack', false)->sum('item.itemPrefix.damage_amount');

$amounts = array_filter([$itemPrefix, $itemSuffix]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function handle() {

// Handle importing things in a custom format.
Artisan::call('import:game-data Skills');
Artisan::call('change:damage-amount-on-affixes');

$this->importInformationSection();
}
Expand Down
4 changes: 2 additions & 2 deletions app/Flare/Models/ItemAffix.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ItemAffix extends Model {
'reduces_enemy_stats',
'steal_life_amount',
'entranced_chance',
'damage',
'damage_amount',
'irresistible_damage',
'damage_can_stack',
'cost',
Expand Down Expand Up @@ -89,11 +89,11 @@ class ItemAffix extends Model {
'skill_reduction' => 'float',
'resistance_reduction' => 'float',
'devouring_light' => 'float',
'damage_amount' => 'float',
'cost' => 'integer',
'int_required' => 'integer',
'skill_level_required' => 'integer',
'skill_level_trivial' => 'integer',
'damage' => 'integer',
'affix_type' => 'integer',
'can_drop' => 'boolean',
'irresistible_damage' => 'boolean',
Expand Down
31 changes: 19 additions & 12 deletions app/Flare/ServerFight/Fight/Affixes.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,40 @@ public function __construct(CharacterCacheData $characterCacheData) {
}

public function getCharacterAffixDamage(array $attackData, bool $isPvp, float $monsterResistance = 0.0): int {
$totalDamage = $attackData['affixes']['stacking_damage'] - $attackData['affixes']['stacking_damage'] * $attackData['damage_deduction'];
$nonStackingDamage = ($attackData['affixes']['non_stacking_damage'] - $attackData['affixes']['stacking_damage'] * $attackData['damage_deduction']) + $totalDamage;

dump($attackData['affixes']);

$totalDamage = $attackData['affixes']['stacking_damage'] - $attackData['damage_deduction'];
$nonStackingDamage = ($attackData['affixes']['non_stacking_damage'] - $attackData['damage_deduction']) + $totalDamage;
$cantBeResisted = $attackData['affixes']['cant_be_resisted'];

$weaponDamage = $attackData['weapon_damage'] + ($attackData['weapon_damage'] * ($totalDamage + $nonStackingDamage));
$nonStackingWeaponDamage = $attackData['weapon_damage'] + ($attackData['weapon_damage'] * $nonStackingDamage);

if ($totalDamage > 0 || $nonStackingDamage > 0) {

if ($cantBeResisted) {
$this->addMessage('The enemy cannot resist your enchantments! They are so glowy!', 'regular', $isPvp);

$this->addMessage('Your enchantments glow with rage. Your enemy cowers. (non resisted dmg): ' . number_format($totalDamage + $nonStackingDamage), 'player-action', $isPvp);
$this->addMessage('Your enchantments glow with rage. Your enemy cowers. (non resisted dmg): ' . number_format($weaponDamage), 'player-action', $isPvp);

if ($isPvp) {
$this->addDefenderMessage('The enemy lashes out with fury. Their enchantments wash over you for: ' . number_format($totalDamage + $nonStackingDamage), 'enemy-action');
$this->addDefenderMessage('The enemy lashes out with fury. Their enchantments wash over you for: ' . number_format($weaponDamage), 'enemy-action');
}

return $totalDamage + $nonStackingDamage;
return $weaponDamage;
} else {

if ($nonStackingDamage > 0) {
return $this->doAffixDamage($nonStackingDamage, $totalDamage, $monsterResistance);
if ($nonStackingWeaponDamage > 0) {
return $this->doAffixDamage($nonStackingWeaponDamage, $weaponDamage, $monsterResistance);
} else {
$this->addMessage('Your (non resistible) enchantments glow with rage. Your enemy cowers: ' . number_format($totalDamage), 'player-action', $isPvp);
$this->addMessage('Your (non resistible) enchantments glow with rage. Your enemy cowers: ' . number_format($weaponDamage), 'player-action', $isPvp);

if ($isPvp) {
$this->addDefenderMessage('The enemy lashes out with rage (non resistible damage). Their enchantments bathe you in hate doing: ' . number_format($totalDamage + $nonStackingDamage), 'enemy-action');
$this->addDefenderMessage('The enemy lashes out with rage (non resistible damage). Their enchantments bathe you in hate doing: ' . number_format($weaponDamage), 'enemy-action');
}

return $totalDamage;
return $weaponDamage;
}
}
}
Expand Down Expand Up @@ -100,7 +107,7 @@ public function getAffixLifeSteal(Character $character, array $attackData, int $
return 0;
}

protected function doAffixDamage(int $nonStackingDamage, int $totalDamage, float $resistance = 0.0, bool $isPvp = false) {
protected function doAffixDamage(int $totalDamage, int $nonStackingDamage, float $resistance = 0.0, bool $isPvp = false) {
$dc = 100 - 100 * $resistance;

if ($dc <= 0 || rand(1, 100) > $dc) {
Expand All @@ -118,7 +125,7 @@ protected function doAffixDamage(int $nonStackingDamage, int $totalDamage, float
$this->addMessage('Your enchantments glow with rage. Your enemy cowers: ' . number_format($nonStackingDamage), 'player-action', $isPvp);

if ($isPvp) {
$this->addDefenderMessage('You cower in awe of the enemies artifacts taking: ' . number_format($totalDamage) . ' damage.', 'player-action');
$this->addDefenderMessage('You cower in awe of the enemies artifacts taking: ' . number_format($nonStackingDamage) . ' damage.', 'player-action');
}

return $nonStackingDamage;
Expand Down
8 changes: 4 additions & 4 deletions app/Flare/Values/RandomAffixDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ public function getPercentageRange(): array {
public function getDamageRange(): array {
switch ($this->value) {
case self::MEDIUM:
return [750, 1000];
return [35, 85];
case self::LEGENDARY:
return [10000, 50000];
return [50, 150];
case self::MYTHIC:
return [1000000, 10000000];
return [150, 300];
case self::BASIC:
default:
return [250, 500];
return [25, 75];
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Console\AfterDeployment\AddHolyStacksToItems;
use App\Console\AfterDeployment\AssignNewSkillsToPlayers;
use App\Console\AfterDeployment\ChangeDamageAmountOnAffixes;
use App\Console\AfterDeployment\CreateCharacterAttackDataCache;
use App\Console\AfterDeployment\CreateMonsterCache;
use App\Console\AfterDeployment\GivePhaseRewardsForCharacters;
Expand Down Expand Up @@ -50,6 +51,7 @@ public function register(): void {
RebalanceQuestCurrencyCostsAndRewards::class,
KickOffEventGoalForWinterEvent::class,
GivePhaseRewardsForCharacters::class,
ChangeDamageAmountOnAffixes::class,

// Development Commands:
CreateCharacter::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('item_affixes', function (Blueprint $table) {
$table->float('damage_amount', 12, 8)->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('item_affixes', function (Blueprint $table) {
//
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('item_affixes', function (Blueprint $table) {
$table->dropColumn('damage');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('item_affixes', function (Blueprint $table) {
//
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,15 @@ export default class ItemAffixDetails extends React.Component<any, any> {
<div className='border-b-2 border-b-gray-300 dark:border-b-gray-600 my-3'></div>
<dl>
<dt>Damage:</dt>
<dd>{formatNumber(this.props.affix.damage)}</dd>
<dd>{this.props.affix.damage_amount * 100}%</dd>
<dt>Is Damage Irresistible?:</dt>
<dd>{this.props.affix.irresistible_damage ? 'Yes' : 'No'}</dd>
<dt>Can Stack:</dt>
<dd>{this.props.affix.damage_can_stack ? 'Yes' : 'No'}</dd>
</dl>
<p className="my-4">
Damage is a % of your total weapon damage after all modifiers.
</p>

<div className='border-b-2 border-b-gray-300 dark:border-b-gray-600 my-3'></div>
<h4 className='text-sky-600 dark:text-sky-500'>Stat Reduction</h4>
Expand Down
Loading

0 comments on commit 5fc7dab

Please sign in to comment.