Skip to content

Commit

Permalink
Fixed issues with vampire attacks, allow characters to remove boons.
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKyle committed Nov 22, 2023
1 parent cf3181c commit d36e25c
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 42 deletions.
2 changes: 1 addition & 1 deletion app/Flare/ServerFight/Fight/Attack.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function attack(Character $character, ServerMonster $serverMonster, strin
$this->mergeBattleMessages($this->monsterAttack->getMessages());

$this->characterHealth = $this->monsterAttack->getCharacterHealth();
$this->monsterHealth = $this->getMonsterHealth();
$this->monsterHealth = $this->monsterAttack->getMonsterHealth();

if ($this->monsterHealth > $serverMonster->getHealth()) {
$this->monsterHealth = $serverMonster->getHealth();
Expand Down
22 changes: 19 additions & 3 deletions app/Game/Core/Controllers/Api/CharacterSheetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Game\Core\Controllers\Api;

use App\Flare\Models\User;
use App\Game\CharacterInventory\Services\UseItemService;
use League\Fractal\Manager;
use Illuminate\Http\Request;
use App\Flare\Models\Character;
Expand All @@ -14,7 +15,6 @@
use App\Game\Core\Jobs\EndGlobalTimeOut;
use App\Admin\Events\UpdateAdminChatEvent;
use App\Flare\Transformers\CharacterElementalAtonementTransformer;
use App\Game\Core\Services\UseItemService;
use App\Flare\Transformers\SkillsTransformer;
use App\Flare\Transformers\UsableItemTransformer;
use App\Game\Core\Services\CharacterPassiveSkills;
Expand Down Expand Up @@ -195,13 +195,29 @@ public function baseInventoryInfo(Character $character) {
], 200);
}

public function cancelBoon(Character $character, CharacterBoon $boon, UseItemService $useItemService) {
public function cancelBoon(Character $character, CharacterBoon $boon, UseItemService $useItemService, UsableItemTransformer $usableItemTransformer, Manager $manager) {
if ($character->id !== $boon->character_id) {
return response()->json(['message' => 'You cannot do that.'], 422);
}

$useItemService->removeBoon($character, $boon);

return response()->json(['message' => 'Boon has been deleted'], 200);
$character = $character->refresh();

$characterBoons = $character->boons->load('itemUsed');

$characterBoons = $characterBoons->transform(function($boon) use($usableItemTransformer, $manager) {
$item = new Item($boon->itemUsed, $usableItemTransformer);
$item = (new Manager())->createData($item)->toArray();

$item = $item['data'];
$item['name'] = $boon->itemUsed->name;

$boon->boon_applied = $item;

return $boon;
});

return response()->json(['message' => 'Boon has been deleted', 'boons' => $characterBoons], 200);
}
}
23 changes: 13 additions & 10 deletions app/Game/GuideQuests/Services/GuideQuestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,21 @@ protected function fetchNextGuideQuest(Character $character): GuideQuest | null

protected function fetchNextRegularGuideQuest(Character $character): GuideQuest | null {
$lastCompletedGuideQuest = $character->questsCompleted()
->whereNotNull('guide_quest_id')
->whereHas('guideQuest', function($query) {
$query->whereNull('only_during_event')
->whereNull('unlock_at_level');
})
->orderByDesc('guide_quest_id')
->first();

if (is_null($lastCompletedGuideQuest)) {
return GuideQuest::first();
}

$questId = GuideQuest::where('id', '>', $lastCompletedGuideQuest->guide_quest_id)->min('id');
$questId = GuideQuest::whereNull('only_during_event')
->whereNull('unlock_at_level')
->where('id', '>', $lastCompletedGuideQuest->guide_quest_id)
->min('id');

return GuideQuest::find($questId);
}
Expand All @@ -222,21 +228,18 @@ protected function fetchNextEventQuest(Character $character, GuideQuest $initial
return $initialEventGuideQuest;
}

$firstCompletedChildEventQuest = $character->questsCompleted()
->join('guide_quests', function($join) use($initialEventGuideQuest) {
$join->on('guide_quests.id', 'quests_completed.guide_quest_id')
->where('parent_id', $initialEventGuideQuest->id);
$firstCompletedEventQuest = $character->questsCompleted()
->whereHas('guideQuest', function($query) use($initialEventGuideQuest) {
$query->where('parent_id', $initialEventGuideQuest->id);
})
->orderByDesc('guide_quest_id')
->first();

if (is_null($firstCompletedChildEventQuest)) {
if (is_null($firstCompletedEventQuest)) {
return GuideQuest::where('parent_id', $initialEventGuideQuest->id)->orderBy('id')->first();
}

$questId = GuideQuest::where('id', '>', $firstCompletedChildEventQuest->guide_quest_id)->where('parent_id', $initialEventGuideQuest->id)->min('id');

return GuideQuest::find($questId);
return GuideQuest::where('parent_id', $firstCompletedEventQuest->guide_quest_id)->first();
}

protected function requiredAttributeNames(GuideQuest $quest): array {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import Table from "../../../components/ui/data-tables/table";
import {formatNumber} from "../../../lib/game/format-number";
import InventoryUseDetails from "./modals/inventory-use-details";
import LoadingProgressBar from "../../../components/ui/progress-bars/loading-progress-bar";
import DangerButton from "../../../components/ui/buttons/danger-button";
import SuccessAlert from "../../../components/ui/alerts/simple-alerts/success-alert";
import DangerAlert from "../../../components/ui/alerts/simple-alerts/danger-alert";

export default class CharacterActiveBoons extends React.Component<any, any> {

Expand All @@ -20,6 +23,9 @@ export default class CharacterActiveBoons extends React.Component<any, any> {
dark_tables: false,
show_usable_details: false,
item_to_use: null,
removing_boon: false,
error_message: null,
success_message: null,
}
}

Expand All @@ -34,7 +40,7 @@ export default class CharacterActiveBoons extends React.Component<any, any> {
boons: result.data.active_boons,
});
}, (error: AxiosError) => {
console.error(error);;
console.error(error);
})
}
}
Expand All @@ -46,6 +52,40 @@ export default class CharacterActiveBoons extends React.Component<any, any> {
});
}

removeBoon(boonId: number) {
this.setState({
removing_boon: true,
success_message: null,
error_message: null,
}, () => {
(new Ajax()).setRoute('character-sheet/'+this.props.character_id+'/remove-boon/' + boonId)
.doAjaxCall('post', (result: AxiosResponse) => {
this.setState({
removing_boon: false,
boons: result.data.boons,
success_message: result.data.message,
})
}, (error: AxiosError) => {

let message = 'UNKNOWN ERROR - CHECK CONSOLE!';

if (error.response !== undefined) {
const response: AxiosResponse = error.response;

message = response.data.message;
}

this.setState({
removing_boon: false,
error_message: message,
});

console.error(error.response);
});
});

}

buildColumns() {
return [
{
Expand All @@ -66,6 +106,15 @@ export default class CharacterActiveBoons extends React.Component<any, any> {
{this.getLabel(row.started, row.complete)}
</span>
},
{
name: 'Actions',
selector: (row: { id: number; boon_applied: { id: number; } }) => row.boon_applied.id,
sortable: true,
cell: (row: { id: number; boon_applied: { id: number; }}) => <span
key={row.boon_applied.id + '-' + (Math.random() + 1).toString(36).substring(7)}>
<DangerButton button_label={'Remove Boon'} on_click={() => this.removeBoon(row.id)} />
</span>
},
]
}

Expand Down Expand Up @@ -96,7 +145,7 @@ export default class CharacterActiveBoons extends React.Component<any, any> {
<LoadingProgressBar />
)
}

return (
<Fragment>

Expand All @@ -108,6 +157,25 @@ export default class CharacterActiveBoons extends React.Component<any, any> {
</InfoAlert>
: null
}
{
this.state.removing_boon ?
<LoadingProgressBar />
: null
}
{
this.state.success_message !== null ?
<SuccessAlert additional_css={'my-4'}>
<p>{this.state.success_message}</p>
</SuccessAlert>
: null
}
{
this.state.error_message !== null ?
<DangerAlert additional_css={'my-4'}>
<p>{this.state.error_message}</p>
</DangerAlert>
: null
}
<p className='my-4 text-center'>
<a href="/information/alchemy" target="_blank">
What are boons and how do I get them? <i
Expand Down

0 comments on commit d36e25c

Please sign in to comment.