Skip to content

Commit

Permalink
More tests and started adding faction loyalty
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKyle committed Dec 24, 2023
1 parent 6b1a4f9 commit b1c5c0d
Show file tree
Hide file tree
Showing 18 changed files with 294 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Game\Factions\FactionLoyalty\Controllers\Api;

use App\Flare\Models\Character;
use App\Game\Factions\FactionLoyalty\Services\FactionLoyaltyService;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;

class FactionLoyaltyController extends Controller {

/**
* @var FactionLoyaltyService $factionLoyaltyService
*/
private FactionLoyaltyService $factionLoyaltyService;

/**
* @param FactionLoyaltyService $factionLoyaltyService
*/
public function __construct(FactionLoyaltyService $factionLoyaltyService) {
$this->factionLoyaltyService = $factionLoyaltyService;
}

/**
* @param Character $character
* @return JsonResponse
*/
public function fetchLoyaltyInfo(Character $character): JsonResponse {
return response()->json($this->factionLoyaltyService->getLoyaltyInfoForPlane($character));
}
}
33 changes: 33 additions & 0 deletions app/Game/Factions/FactionLoyalty/Providers/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Game\Factions\FactionLoyalty\Providers;

use Illuminate\Support\ServiceProvider as ApplicationServiceProvider;
use App\Game\Factions\FactionLoyalty\Services\FactionLoyaltyService;

class ServiceProvider extends ApplicationServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register() {


$this->app->bind(FactionLoyaltyService::class, function($app) {
return new FactionLoyaltyService(
);
});
}

/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Game\Factions\FactionLoyalty\Services;


use App\Flare\Models\Character;
use App\Flare\Models\Npc;
use App\Game\Core\Traits\ResponseBuilder;

class FactionLoyaltyService {

use ResponseBuilder;

public function getLoyaltyInfoForPlane(Character $character): array {
$gameMap = $character->map->gameMap;

$npcNames = Npc::where('game_map_id', $gameMap->id)->get()->map(function($npc) {
return [
'id' => $npc->id,
'name' => $npc->real_name
];
});

return $this->successResult([
'npcs' => $npcNames,
'map_name' => $gameMap->name,
]);
}
}
5 changes: 1 addition & 4 deletions app/Game/Raids/Jobs/InitiateRaid.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use App\Game\Messages\Events\GlobalMessageEvent;
use Facades\App\Game\Core\Handlers\AnnouncementHandler;

class InitiateRaid implements ShouldQueue {
class InitiateRaid implements ShouldQueue {

use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

Expand Down Expand Up @@ -85,9 +85,6 @@ public function handle(
/**
* Initialize the raid
*
* @param Raid $raid
* @param LocationService $locationService
* @return void
*/
protected function initializeRaid(
Raid $raid,
Expand Down
2 changes: 1 addition & 1 deletion app/Game/Raids/Services/RaidEventService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RaidEventService {
*/
public function createRaid(Raid $raid): void {

$existingRaid = Event::where('type', EventType::RAID_EVENT)->first();
$existingRaid = Event::where('type', EventType::RAID_EVENT)->where('raid_id', $raid->id)->first();

if (!is_null($existingRaid)) {
return;
Expand Down
8 changes: 8 additions & 0 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public function map() {
$this->mapMercenariesApiRoutes();
$this->mapReincarnateApiRoutes();
$this->mapClassRanksApiRoutes();
$this->mapFactionLoyaltyApiRoutes();
}

/**
Expand Down Expand Up @@ -358,4 +359,11 @@ protected function mapEvents() {
->namespace('App\Game\Events\Controllers')
->group(base_path('routes/game/events/api.php'));
}

protected function mapFactionLoyaltyApiRoutes() {
Route::prefix('api')
->middleware('web')
->namespace('App\Game\Factions\FactionLoyalty\Controllers')
->group(base_path('routes/game/factions/faction-loyalty/api.php'));
}
}
1 change: 1 addition & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@
App\Game\NpcActions\QueenOfHeartsActions\Providers\ServiceProvider::class,
App\Game\NpcActions\WorkBench\Providers\ServiceProvider::class,
App\Game\Raids\Providers\ServiceProvider::class,
App\Game\Factions\FactionLoyalty\Providers\ServiceProvider::class,
],

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class PrimaryOutlineButton extends React.Component<ButtonProps, {
'dark:focus:ring-blue-800 disabled:bg-blue-600 disabled:bg-opacity-75 dark:disabled:bg-opacity-50 ' +
'dark:disabled:bg-blue-500 disabled:text-white ' +
'focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-200 dark:focus-visible:ring-white ' +
'focus-visible:ring-opacity-75' + this.props.additional_css}
'focus-visible:ring-opacity-75 ' + this.props.additional_css}
onClick={this.props.on_click}
disabled={this.props.disabled}
>
Expand Down
4 changes: 1 addition & 3 deletions resources/js/game/game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ import FetchGameData from "./lib/game/ajax/FetchGameData";
import CharacterSheet from "./sections/character-sheet/character-sheet";
import GameChat from "./sections/chat/game-chat";
import ForceNameChange from "./sections/force-name-change/force-name-change";
import SmallerActions from "./sections/game-actions-section/smaller-actions";
import QuestType from "./lib/game/types/quests/quest-type";
import ScreenRefresh from "./sections/screen-refresh/screen-refresh";
import KingdomsList from "./sections/kingdoms/kingdoms-list";
import Actions from "./sections/game-actions-section/actions";
import PositionType from "./sections/map/types/map/position-type";
import { removeCommas } from "./lib/game/format-number";
import CharacterCurrenciesType from "./lib/game/character/character-currencies-type";
Expand Down Expand Up @@ -297,7 +295,7 @@ export default class Game extends React.Component<GameProps, GameState> {
this.state.view_port < 1600,
})}
>
<ActionTabs use_tabs={true}>
<ActionTabs use_tabs={true} character_id={this.props.characterId}>
<ActionSection
character={this.state.character}
character_status={this.state.character_status}
Expand Down
117 changes: 89 additions & 28 deletions resources/js/game/sections/faction-loyalty/faction-fame.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,121 @@
import React from "react";
import OrangeProgressBar from "../../components/ui/progress-bars/orange-progress-bar";
import DropDown from "../../components/ui/drop-down/drop-down";
import LoadingProgressBar from "../../components/ui/progress-bars/loading-progress-bar";
import Ajax from "../../lib/ajax/ajax";
import {AxiosError, AxiosResponse} from "axios";
import FactionLoyaltyState, {FactionLoyaltyNpc} from "./types/faction-loyalty-state";
import FactionLoyaltyProps from "./types/faction-loyalty-props";
import DangerAlert from "../../components/ui/alerts/simple-alerts/danger-alert";
import PrimaryOutlineButton from "../../components/ui/buttons/primary-outline-button";

export default class FactionFame extends React.Component<any, any> {
export default class FactionFame extends React.Component<FactionLoyaltyProps, FactionLoyaltyState> {

constructor(props: any) {
constructor(props: FactionLoyaltyProps) {
super(props);

this.state = {
is_loading: true,
selected_npc: null,
error_message: null,
npcs: [],
game_map_name: null,
}
}

buildNpcList(handler: (type: string) => void) {
return [
{
name: 'NPC Name',
componentDidMount() {
(new Ajax()).setRoute('faction-loyalty/' + this.props.character_id).doAjaxCall('get', (result: AxiosResponse) => {
this.setState({
is_loading: false,
npcs: result.data.npcs,
selected_npc: result.data.npcs[0],
game_map_name: result.data.map_name,
})
}, (error: AxiosError) => {
this.setState({is_loading: false});

if (error.response) {
this.setState({
error_message: error.response.data.message,
});
}
});
}

buildNpcList(handler: (npc: any) => void) {
return this.state.npcs.map((npc: FactionLoyaltyNpc) => {
return {
name: npc.name,
icon_class: 'ra ra-aura',
on_click: () => handler('npc-name'),
},
];
on_click: () => handler(npc),
};
});
}

selectedNpc() {
return 'NPC Name';
selectedNpc(): string | undefined {
console.log(this.state.npcs?.find((npc: FactionLoyaltyNpc) => {
return npc.name === this.state.selected_npc?.name
}), this.state.selected_npc, this.state.npcs);
return this.state.npcs?.find((npc: FactionLoyaltyNpc) => {
return npc.name === this.state.selected_npc?.name
})?.name;
}

switchToNpc(type: string) {
switchToNpc(npc: FactionLoyaltyNpc) {
this.setState({
selected_npc: type,
selected_npc: npc,
});
}

render() {

if (this.state.is_loading) {
return (
<div className='w-1/2 m-auto'>
<LoadingProgressBar />
</div>
);
}

if (this.state.error_message !== null) {
return <DangerAlert additional_css={'my-4'}>
{this.state.error_message}
</DangerAlert>
}

return (
<div className='py-4'>
<h2>Surface Fame</h2>
<h2>{this.state.game_map_name} Loyalty</h2>
<p className='my-4'>
Here you can see your NPC Fame for this map. Completing the objectives will
earn points towards the NPC fame level. Leveling up the Fame for each NPC provides Bonus
defence to your kingdoms as well as currency, XP and Unique items.
</p>
<p className='my-4'>
<a href="/information/faction-loyalty" target="_blank" className='my-2'>
What is all this? <i
className="fas fa-external-link-alt"></i>
</a>
</p>
<div className='border-b-2 border-b-gray-300 dark:border-b-gray-600 my-3'></div>
<div className="my-4 flex flex-wrap md:flex-nowrap gap-4">
<div className='flex-none mt-[-25px]'>
<div className={'w-full md:w-1/3 relative left-0'}>
<DropDown
menu_items={this.buildNpcList(
this.switchToNpc.bind(this)
)}
button_title={"NPCs"}
selected_name={this.selectedNpc()}
/>
<div className='w-full md:w-2/3 relative left-0 flex flex-wrap'>
<div>
<DropDown
menu_items={this.buildNpcList(
this.switchToNpc.bind(this)
)}
button_title={"NPCs"}
selected_name={this.selectedNpc()}
/>
</div>
<div>
<PrimaryOutlineButton button_label={'Remember'} on_click={() => {}} additional_css={'mt-[34px] ml-4'}/>
</div>
</div>

<h4>Rewards</h4>
<h4>Rewards (per level)</h4>
<dl className='my-2'>
<dt>XP Per Level</dt>
<dd>500</dd>
Expand All @@ -58,11 +124,6 @@ export default class FactionFame extends React.Component<any, any> {
<dt>Item Reward</dt>
<dd>Medium Unique</dd>
</dl>

<a href="/information/faction-loyalty" target="_blank" className='my-2'>
What is all this? <i
className="fas fa-external-link-alt"></i>
</a>
</div>
<div className='flex-none md:flex-auto w-full md:w-3/4'>
<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default interface FactionLoyaltyProps {
character_id: number;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export type FactionLoyaltyNpc = {
name: string;
id: number;
}

export default interface FactionLoyaltyState {

is_loading: boolean;
selected_npc: FactionLoyaltyNpc | null;
error_message: string | null;
npcs: FactionLoyaltyNpc[]|[];
game_map_name: string | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class ActionTabs extends React.Component<ActionTabsProps, { }> {
<Tabs tabs={this.tabs} disabled={false}>
<TabPanel key={"actions"}>{this.props.children}</TabPanel>
<TabPanel key={"faction-loyalty"}>
<FactionFame />
<FactionFame character_id={this.props.character_id} />
</TabPanel>
</Tabs>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ export default interface ActionTabsProps {

children: React.ReactNode;

character_id: number;

use_tabs: boolean;
}
5 changes: 5 additions & 0 deletions routes/game/factions/faction-loyalty/api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

Route::group(['middleware' => ['is.character.who.they.say.they.are']], function() {
Route::get('/faction-loyalty/{character}', ['uses' => 'Api\FactionLoyaltyController@fetchLoyaltyInfo']);
});
2 changes: 1 addition & 1 deletion tests/Console/Events/EndScheduledEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function testEndRaidEvent() {
$event = $this->createEvent([
'type' => EventType::RAID_EVENT,
'started_at' => now(),
'ends_at' => now()->subMinute(10),
'ends_at' => now()->subMinutes(10),
'raid_id' => $raid->id,
]);

Expand Down
2 changes: 1 addition & 1 deletion tests/Console/Events/ProcessScheduledEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function testRaidEventTriggers() {
$this->createScheduledEvent([
'event_type' => EventType::RAID_EVENT,
'start_date' => now()->addMinutes(5),
'raid_id' => $raid,
'raid_id' => $raid->id,
]);

$this->artisan('process:scheduled-events');
Expand Down
Loading

0 comments on commit b1c5c0d

Please sign in to comment.