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
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using System.Net;
using System.Threading.Tasks;
using RIMAPI.Core;
using RIMAPI.Http;
using RIMAPI.Models;
using RIMAPI.Services;

namespace RIMAPI.Controllers
{
public class PawnSocialController
{
private readonly IPawnSocialService _socialService;

public PawnSocialController(IPawnSocialService socialService)
{
_socialService = socialService;
}

[Get("/api/v1/game/defs/interactions")]
[EndpointMetadata("Retrieves a list of all valid InteractionDef names in the game.")]
public async Task GetInteractionDefs(HttpListenerContext context)
{
var result = _socialService.GetInteractionDefs();
await context.SendJsonResponse(result);
}

[Get("/api/v1/pawns/interactions")]
[EndpointMetadata("Gets the real-time interaction readiness of a specific pawn.")]
public async Task GetPawnInteractionStatus(HttpListenerContext context)
{
var pawnId = RequestParser.GetIntParameter(context, "pawn_id");
var result = _socialService.GetPawnInteractionStatus(pawnId);
await context.SendJsonResponse(result);
}

[Get("/api/v1/pawns/interactions/log")]
[EndpointMetadata("Retrieves the recent interaction history for a specific pawn.")]
public async Task GetPawnInteractionLog(HttpListenerContext context)
{
var pawnId = RequestParser.GetIntParameter(context, "pawn_id");
var limit = RequestParser.HasParameter(context, "limit") ? RequestParser.GetIntParameter(context, "limit") : 50;
var result = _socialService.GetPawnInteractionLog(pawnId, limit);
await context.SendJsonResponse(result);
}

[Get("/api/v1/pawns/relations")]
[EndpointMetadata("Retrieves all established familial and romantic relationships for this pawn.")]
public async Task GetPawnRelations(HttpListenerContext context)
{
var pawnId = RequestParser.GetIntParameter(context, "pawn_id");
var result = _socialService.GetPawnRelations(pawnId);
await context.SendJsonResponse(result);
}

[Get("/api/v1/pawns/opinions")]
[EndpointMetadata("Retrieves a list of this pawn's numerical opinion toward every other colonist on the map.")]
public async Task GetPawnOpinions(HttpListenerContext context)
{
var pawnId = RequestParser.GetIntParameter(context, "pawn_id");
var result = _socialService.GetPawnOpinions(pawnId);
await context.SendJsonResponse(result);
}

[Post("/api/v1/pawns/interactions/force")]
[EndpointMetadata("Forces a specific social interaction to occur immediately between two pawns.")]
public async Task ForceInteraction(HttpListenerContext context)
{
var request = await context.Request.ReadBodyAsync<ForceInteractionRequestDto>();
var result = _socialService.ForceInteraction(request);
await context.SendJsonResponse(result);
}

[Post("/api/v1/pawns/relations/add")]
[EndpointMetadata("Instantly creates a permanent social bond between two pawns.")]
public async Task AddRelation(HttpListenerContext context)
{
var request = await context.Request.ReadBodyAsync<AddRelationRequestDto>();
var result = _socialService.AddRelation(request);
await context.SendJsonResponse(result);
}

[Delete("/api/v1/pawns/relations/remove")]
[EndpointMetadata("Severs a specific social bond between two pawns.")]
public async Task RemoveRelation(HttpListenerContext context)
{
var pawn1Id = RequestParser.GetIntParameter(context, "pawn1_id");
var pawn2Id = RequestParser.GetIntParameter(context, "pawn2_id");
var relationDefName = RequestParser.GetStringParameter(context, "relation_def_name");

var request = new RemoveRelationRequestDto
{
Pawn1Id = pawn1Id,
Pawn2Id = pawn2Id,
RelationDefName = relationDefName
};

var result = _socialService.RemoveRelation(request);
await context.SendJsonResponse(result);
}
}
}
90 changes: 90 additions & 0 deletions Source/RIMAPI/RimworldRestApi/Models/Pawns/PawnSocialDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System.Collections.Generic;

namespace RIMAPI.Models
{
public class InteractionDefDto
{
public string DefName { get; set; }
public string Label { get; set; }
public string Description { get; set; }
}

public class PawnInteractionStatusDto
{
public bool CanInteract { get; set; }
public int CooldownTicks { get; set; }
public float CooldownDays { get; set; }
public string LastInteractionDef { get; set; }
public int LastInteractionTicks { get; set; }
}

public class PawnInteractionLogDto
{
public int PawnId { get; set; }
public List<InteractionLogEntryDto> Interactions { get; set; }
public int Count { get; set; }
}

public class InteractionLogEntryDto
{
public int InitiatorId { get; set; }
public string InitiatorName { get; set; }
public int RecipientId { get; set; }
public string RecipientName { get; set; }
public string InteractionDefName { get; set; }
public string InteractionLabel { get; set; }
public string Text { get; set; }
public int Ticks { get; set; }
public string TimeAgo { get; set; }
}

public class PawnOpinionDto
{
public int TargetPawnId { get; set; }
public string TargetPawnName { get; set; }
public int Opinion { get; set; }
public List<OpinionBreakdownDto> Breakdown { get; set; }
}

public class OpinionBreakdownDto
{
public string ThoughtDefName { get; set; }
public string Label { get; set; }
public float Score { get; set; }
}

public class ForceInteractionRequestDto
{
public int InitiatorId { get; set; }
public int RecipientId { get; set; }
public string InteractionDefName { get; set; }
}

public class AddRelationRequestDto
{
public int Pawn1Id { get; set; }
public int Pawn2Id { get; set; }
public string RelationDefName { get; set; }
}

public class RemoveRelationRequestDto
{
public int Pawn1Id { get; set; }
public int Pawn2Id { get; set; }
public string RelationDefName { get; set; }
}

public class PawnRelationsDto
{
public int PawnId { get; set; }
public List<PawnRelationEntryDto> Relations { get; set; }
}

public class PawnRelationEntryDto
{
public int OtherPawnId { get; set; }
public string OtherPawnName { get; set; }
public string RelationDefName { get; set; }
public string RelationLabel { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections.Generic;
using RIMAPI.Core;
using RIMAPI.Models;

namespace RIMAPI.Services
{
public interface IPawnSocialService
{
ApiResult<List<InteractionDefDto>> GetInteractionDefs();
ApiResult<PawnInteractionStatusDto> GetPawnInteractionStatus(int pawnId);
ApiResult<PawnInteractionLogDto> GetPawnInteractionLog(int pawnId, int limit = 50);
ApiResult<PawnRelationsDto> GetPawnRelations(int pawnId);
ApiResult<List<PawnOpinionDto>> GetPawnOpinions(int pawnId);
ApiResult ForceInteraction(ForceInteractionRequestDto request);
ApiResult AddRelation(AddRelationRequestDto request);
ApiResult RemoveRelation(RemoveRelationRequestDto request);
}
}
Loading