feat(world): add persistent citizen simulation with needs, jobs, and social features

- Adds Character model with survival needs (hunger, thirst, energy) and state machine
- Implements city:tick world ticker for offline progression every minute
- Adds city territory expansion and building construction system
- Introduces job economy, inventory, and transaction audit trail
- Adds social graph (friends, marriage, children) and character chat
- Implements admin approval workflow for new registrations
- Adds hospital admission system for traffic accidents
- Includes comprehensive feature tests and world seeders
This commit is contained in:
2026-10-17 21:46:23 -03:00
parent 79d12fa2f4
commit 79ce2a1825
132 changed files with 11809 additions and 1036 deletions
+72
View File
@@ -0,0 +1,72 @@
<?php
namespace App\Http\Controllers\Web;
use App\Http\Controllers\Controller;
use App\Models\Character;
use App\Models\CharacterMessage;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
/**
* Persistent chat between world characters.
*/
class CharacterChatController extends Controller
{
/**
* List messages exchanged with another character (newest last).
*/
public function index(Request $request, Character $character): JsonResponse
{
$me = Character::ensureForUser($request->user());
$messages = CharacterMessage::query()
->where(function ($q) use ($me, $character): void {
$q->where('from_character_id', $me->id)->where('to_character_id', $character->id);
})
->orWhere(function ($q) use ($me, $character): void {
$q->where('from_character_id', $character->id)->where('to_character_id', $me->id);
})
->orderBy('id')
->limit(100)
->get()
->map(fn (CharacterMessage $m) => [
'from' => (int) $m->from_character_id,
'body' => $m->body,
'at' => $m->created_at?->toIso8601String(),
]);
return response()->json([
'me' => $me->id,
'them' => $character->id,
'messages' => $messages,
]);
}
/**
* Send a chat message to another character.
*/
public function send(Request $request, Character $character): JsonResponse
{
$me = Character::ensureForUser($request->user());
if ((int) $character->id === (int) $me->id) {
return response()->json(['message' => __('city.social_self')], 422);
}
$data = $request->validate([
'body' => ['required', 'string', 'max:1000'],
]);
$message = CharacterMessage::create([
'from_character_id' => $me->id,
'to_character_id' => $character->id,
'body' => $data['body'],
]);
return response()->json([
'message' => __('city.chat_sent'),
'id' => $message->id,
]);
}
}