98 lines
3.8 KiB
GDScript
98 lines
3.8 KiB
GDScript
class_name ABGRecruitReviewPageController
|
|
extends RefCounted
|
|
|
|
const ContentRegistry = preload("res://p10_0/content_registry.gd")
|
|
const MarketPageController = preload("res://entry/market_page_controller.gd")
|
|
|
|
## UI-independent Recruit Review view-data assembly.
|
|
## Hire remains owned by GuildContractService; this controller only describes
|
|
## the stable offer and whether the Review boundary may expose that command.
|
|
|
|
var _market_controller := MarketPageController.new()
|
|
|
|
|
|
func snapshot(company: Dictionary, offer_id: String, locale := "zh_CN", content: Dictionary = {}) -> Dictionary:
|
|
if company.is_empty() or not company.get("active_contract", {}) is Dictionary:
|
|
return {"ok": false, "code": "MARKET_REQUIRED", "offer_id": offer_id}
|
|
var contract: Dictionary = Dictionary(company.get("active_contract", {})).duplicate(true)
|
|
if contract.is_empty() or String(contract.get("status", "")) != "market":
|
|
return {"ok": false, "code": "MARKET_REQUIRED", "offer_id": offer_id}
|
|
var catalog := content.duplicate(true) if not content.is_empty() else ContentRegistry.snapshot()
|
|
var offer := _market_controller.offer_by_id(contract, "recruit", offer_id)
|
|
if offer.is_empty():
|
|
return {"ok": false, "code": "RECRUIT_OFFER_UNAVAILABLE", "offer_id": offer_id}
|
|
var owned_before := Array(company.get("owned_recruits", [])).size()
|
|
var line_capacity := int(contract.get("line_capacity", 0))
|
|
var coin := int(contract.get("coin", 0))
|
|
var available_ids: Array = Array(contract.get("available_recruit_offer_ids", []))
|
|
var available := offer_id in available_ids
|
|
var hire_count := Array(contract.get("hire_receipts", [])).size()
|
|
var opening_hires_complete := hire_count >= 2
|
|
var price := int(offer.get("list_price", 0))
|
|
var hire_reason := "eligible"
|
|
if not available:
|
|
hire_reason = "already_hired"
|
|
elif opening_hires_complete:
|
|
hire_reason = "opening_hires_complete"
|
|
elif coin < price:
|
|
hire_reason = "insufficient_coin"
|
|
var facts := _facts(offer, locale, catalog)
|
|
return {
|
|
"ok": true,
|
|
"page_id": "recruit_review",
|
|
"offer_id": offer_id,
|
|
"offer": offer,
|
|
"facts": facts,
|
|
"availability": {
|
|
"available": available,
|
|
"reason": "available" if available else "already_hired",
|
|
},
|
|
"impact": {
|
|
"owned_before": owned_before,
|
|
"owned_after": owned_before + 1,
|
|
"line_capacity": line_capacity,
|
|
"opening_hires_complete": opening_hires_complete,
|
|
"hire_count": hire_count,
|
|
},
|
|
"hire": {
|
|
"eligible": available and not opening_hires_complete and coin >= price,
|
|
"reason": hire_reason,
|
|
"price": price,
|
|
"coin": coin,
|
|
},
|
|
"contract": {
|
|
"coin": coin,
|
|
"line_capacity": line_capacity,
|
|
"hire_count": hire_count,
|
|
},
|
|
"locale": String(locale),
|
|
"content": catalog,
|
|
}
|
|
|
|
|
|
func _facts(offer: Dictionary, locale: String, content: Dictionary) -> Dictionary:
|
|
var profession_id := String(offer.get("profession_id", ""))
|
|
var trait_id := String(offer.get("trait_id", ""))
|
|
var item_id := String(offer.get("starting_equipment_id", ""))
|
|
return {
|
|
"name": _market_controller.recruit_name(offer),
|
|
"profession_id": profession_id,
|
|
"profession_name": _market_controller.content_name(content, "professions", profession_id, locale),
|
|
"profession_job": _market_controller.profession_job(offer, locale, content),
|
|
"trait_id": trait_id,
|
|
"trait_name": _market_controller.content_name(content, "traits", trait_id, locale),
|
|
"trait_benefit": _market_controller.trait_value(content, trait_id, "benefit", locale),
|
|
"trait_cost": _market_controller.trait_value(content, trait_id, "cost", locale),
|
|
"attributes": _market_controller.attribute_summary(offer),
|
|
"starting_item_id": item_id,
|
|
"starting_item_name": _market_controller.content_name(content, "equipment", item_id, locale),
|
|
"starting_item_effect": _market_controller.equipment_value(content, item_id, "effect", locale),
|
|
"history": {
|
|
"level": 1,
|
|
"xp": 0,
|
|
"battles_entered": 0,
|
|
"knockouts": 0,
|
|
},
|
|
}
|
|
|