Expand fish catalog and add bait system

This commit is contained in:
Alexander Sellite 2026-08-06 01:00:52 -04:00
parent 43f57e56a0
commit 954042fd1d
134 changed files with 3134 additions and 127 deletions

View file

@ -168,14 +168,9 @@ func _state_matches_catalog(data: Dictionary) -> bool:
if fish == null or not fish.is_selectable():
return false
var weight_lb: float = float(data["weight_lb"])
var display_scale: float = float(data["display_scale"])
return (
weight_lb >= fish.get_minimum_weight()
and weight_lb <= fish.get_maximum_weight()
and is_equal_approx(
display_scale,
fish.get_display_scale_for_weight(weight_lb),
)
)
@ -190,7 +185,11 @@ func _apply_state(data: Dictionary) -> void:
var fish: FishDataType = _fish_catalog.get_fish_by_id(
StringName(str(data["fish_id"]))
)
avatar.set_held_fish(fish, float(data["display_scale"]), true)
avatar.set_held_fish(
fish,
fish.get_display_scale_for_weight(float(data["weight_lb"])),
true,
)
func _on_selected_assignment_changed(

View file

@ -21,6 +21,7 @@ var origin: Vector3
var target: Vector3
var bobber_position: Vector3
var fish_id: StringName
var bait_tags: Array[StringName] = []
var encounter_seed: int = 0
var bite_time_remaining: float = 0.0
var withdrawal_progress: float = 0.0

View file

@ -53,6 +53,8 @@ static func validate_cast_request(data: Variant) -> String:
or typeof(payload["capacity_available"]) != TYPE_BOOL
):
return "Malformed fishing request."
if payload.has("bait_id") and typeof(payload["bait_id"]) not in [TYPE_STRING, TYPE_STRING_NAME]:
return "Malformed fishing request."
var request_id: String = payload["request_id"]
var session_id: String = payload["session_id"]
var origin: Array = payload["origin"]

View file

@ -14,6 +14,7 @@ const PlayerExperienceType = preload(
const RemotePresentationType = preload(
"res://fishing/remote_fishing_presentation.gd"
)
const ItemDataType = preload("res://items/item_data.gd")
const MAX_LEDGER_ENTRIES_PER_PEER: int = 64
const CAST_ORIGIN_TOLERANCE: float = 2.5
@ -109,6 +110,7 @@ func request_local_cast(
"rarity_multipliers": evidence.get("rarity_multipliers", []),
"discovered_fish_ids": evidence.get("discovered_fish_ids", []),
"capacity_available": bool(evidence.get("capacity_available", false)),
"bait_id": str(evidence.get("bait_id", "")),
}
if _session.is_host():
_handle_cast_request(_session.get_local_peer_id(), data)
@ -292,6 +294,11 @@ func _handle_cast_request(peer_id: int, data: Dictionary) -> void:
):
_record_and_reject(peer_id, request_id, "Nothing is biting here.")
return
var bait_id: StringName = StringName(str(data.get("bait_id", "")))
var avatar_bag: PlayerBag = avatar.bag
if not bait_id.is_empty() and (avatar_bag == null or not avatar_bag.remove_item(bait_id, 1)):
_record_and_reject(peer_id, request_id, "No bait available.")
return
var attempt := NetworkFishingAttempt.new()
attempt.owner_peer_id = peer_id
attempt.request_id = request_id
@ -302,6 +309,7 @@ func _handle_cast_request(peer_id: int, data: Dictionary) -> void:
attempt.target = authoritative_target
attempt.bobber_position = authoritative_target
attempt.fish_id = selected_fish.id
attempt.bait_tags = _bait_tags_for_request(data)
attempt.reel_speed = float(data["reel_speed"]) * (
effects.get_reel_multiplier() if effects != null else 1.0
)
@ -413,6 +421,7 @@ func _select_authoritative_fish(
)
selector.begin_roll()
var context: FishingContextType = _fishing_spot.build_network_context(region)
context.active_bait_tags = _bait_tags_for_request(data)
var selected_fish := selector.select_fish(
region.fish_pool, context, evidence_log
)
@ -420,6 +429,14 @@ func _select_authoritative_fish(
return selected_fish
func _bait_tags_for_request(data: Dictionary) -> Array[StringName]:
var bait_id: StringName = StringName(str(data.get("bait_id", "")))
if bait_id.is_empty() or _item_catalog == null:
return []
var bait: ItemDataType = _item_catalog.get_item_by_id(bait_id)
return bait.bait_tags.duplicate() if bait != null and bait.is_bait() else []
func _start_bite(attempt: NetworkFishingAttempt) -> void:
if attempt.phase != NetworkFishingAttempt.Phase.WAITING_FOR_BITE:
return
@ -433,7 +450,7 @@ func _start_bite(attempt: NetworkFishingAttempt) -> void:
selector.use_deterministic_test_seed = true
selector.deterministic_test_seed = attempt.encounter_seed ^ 0x5F3759DF
selector.begin_roll()
var fish_catch: FishCatch = selector.create_catch(fish)
var fish_catch: FishCatch = selector.create_catch(fish, attempt.bait_tags)
if fish_catch == null or not fish_catch.is_valid():
_cancel_attempt(attempt.owner_peer_id, "Fishing attempt ended.")
return
@ -444,6 +461,8 @@ func _start_bite(attempt: NetworkFishingAttempt) -> void:
attempt.barrier_damage,
attempt.encounter_seed,
fish_catch.quality,
int(fish.rarity),
fish.get_weight_percentile(fish_catch.weight_lb),
)
var data: Dictionary = {
"attempt_id": attempt.attempt_id,

View file

@ -108,11 +108,13 @@ func is_local_purchase_pending() -> bool:
func request_supply(item_id: StringName) -> String:
var owned: int = _bag.get_quantity(item_id) if _bag != null else 0
var quantity: int = FishingShopStockType.get_purchase_quantity(item_id, owned)
return _request_purchase(
item_id,
NetworkShopProtocol.ProductCategory.SUPPLY,
1,
_bag.get_quantity(item_id) if _bag != null else 0
quantity,
owned
)
@ -307,7 +309,7 @@ func _build_authoritative_result(
var rejection: String = ""
if StringName(str(request["shop_id"])) != SHOP_ID:
rejection = "The shop is unavailable."
elif quantity != 1:
elif quantity < 1:
rejection = "Purchase could not be completed."
else:
match category:
@ -322,10 +324,11 @@ func _build_authoritative_result(
or product_id not in (
FishingShopStockType.get_stock_item_ids()
)
or item.category != ItemDataType.Category.CONSUMABLE
or (item.category != ItemDataType.Category.CONSUMABLE and not FishingShopStockType.is_bait_topoff(product_id))
or not item.stackable
or not item.usable
or (not item.usable and not FishingShopStockType.is_bait_topoff(product_id))
or current_state >= item.max_stack
or current_state + quantity > item.max_stack
):
rejection = (
"Your Bag is full."
@ -333,7 +336,11 @@ func _build_authoritative_result(
else "Purchase could not be completed."
)
else:
resulting_state = current_state + 1
if not FishingShopStockType.is_bait_topoff(product_id) and quantity != 1:
rejection = "Purchase could not be completed."
else:
cost *= quantity
resulting_state = current_state + quantity
NetworkShopProtocol.ProductCategory.ROD:
rejection = "This item is not sold here."
NetworkShopProtocol.ProductCategory.REEL_SPEED_UPGRADE:
@ -576,7 +583,7 @@ func _validate_local_result(data: Dictionary) -> String:
var resulting_state: int = int(data["resulting_state"])
if (
category != NetworkShopProtocol.ProductCategory.ART_UPGRADE
and resulting_state != expected_state + 1
and resulting_state != expected_state + int(data["quantity"])
):
return "Purchase could not be completed."
if not _wallet.can_afford(cost):
@ -585,6 +592,8 @@ func _validate_local_result(data: Dictionary) -> String:
NetworkShopProtocol.ProductCategory.SUPPLY:
if _bag.get_quantity(product_id) != expected_state:
return "Purchase could not be completed."
if cost != FishingShopStockType.get_price(product_id) * int(data["quantity"]):
return "Purchase could not be completed."
if not _bag.can_add_item(product_id, data["quantity"]):
return "Your Bag is full."
NetworkShopProtocol.ProductCategory.REEL_SPEED_UPGRADE: