Add antidote status cure item
This commit is contained in:
@@ -776,8 +776,10 @@ func get_item_preview(user_id: String, item_id: String, target_cell: Vector2i) -
|
||||
|
||||
var hp_heal_amount := _item_hp_heal_amount(target, item)
|
||||
var mp_heal_amount := _item_mp_heal_amount(target, item)
|
||||
var cured_statuses := _item_curable_status_names(target, item)
|
||||
preview["heal"] = hp_heal_amount
|
||||
preview["mp_heal"] = mp_heal_amount
|
||||
preview["cure_statuses"] = cured_statuses
|
||||
preview["target_hp_after"] = min(int(target.get("max_hp", 1)), int(target.get("hp", 0)) + hp_heal_amount)
|
||||
preview["target_mp_after"] = min(int(target.get("max_mp", 0)), int(target.get("mp", 0)) + mp_heal_amount)
|
||||
return preview
|
||||
@@ -1740,6 +1742,12 @@ func _apply_item_effects(user: Dictionary, target: Dictionary, item: Dictionary)
|
||||
applied = true
|
||||
_emit_log("%s recovers %d MP." % [target["name"], restored])
|
||||
_emit_combat_feedback(target, "+%d MP" % restored, "mp")
|
||||
elif effect_type == "cure_status":
|
||||
var cured_statuses := _apply_item_status_cure(target, str(effect.get("status", "")))
|
||||
if not cured_statuses.is_empty():
|
||||
applied = true
|
||||
_emit_log("%s is cured of %s." % [target["name"], _join_strings(cured_statuses, ", ")])
|
||||
_emit_combat_feedback(target, "CURE", "support")
|
||||
if not applied:
|
||||
_emit_log("%s has no effect on %s." % [item.get("name", "Item"), target["name"]])
|
||||
return applied
|
||||
@@ -1763,6 +1771,29 @@ func _apply_item_mp_heal(target: Dictionary, amount: int) -> int:
|
||||
return restored
|
||||
|
||||
|
||||
func _apply_item_status_cure(target: Dictionary, status: String) -> Array:
|
||||
var cured_statuses := []
|
||||
if typeof(target.get("status_effects", [])) != TYPE_ARRAY:
|
||||
return cured_statuses
|
||||
var normalized_status := status.strip_edges().to_lower()
|
||||
var kept_effects := []
|
||||
for effect in _active_status_effects(target):
|
||||
var effect_status := str(effect.get("status", "")).strip_edges().to_lower()
|
||||
var effect_type := str(effect.get("type", ""))
|
||||
var should_cure := (
|
||||
effect_type == "damage_over_time"
|
||||
and (normalized_status.is_empty() or effect_status == normalized_status)
|
||||
)
|
||||
if should_cure:
|
||||
var display_name := _status_display_name(str(effect.get("status", normalized_status)))
|
||||
if not cured_statuses.has(display_name):
|
||||
cured_statuses.append(display_name)
|
||||
continue
|
||||
kept_effects.append(effect)
|
||||
target["status_effects"] = kept_effects
|
||||
return cured_statuses
|
||||
|
||||
|
||||
func _item_hp_heal_amount(target: Dictionary, item: Dictionary) -> int:
|
||||
var total := 0
|
||||
for effect in item.get("effects", []):
|
||||
@@ -1785,6 +1816,28 @@ func _item_mp_heal_amount(target: Dictionary, item: Dictionary) -> int:
|
||||
return max(0, min(total, missing_mp))
|
||||
|
||||
|
||||
func _item_curable_status_names(target: Dictionary, item: Dictionary) -> Array:
|
||||
var result := []
|
||||
if target.is_empty():
|
||||
return result
|
||||
for effect in item.get("effects", []):
|
||||
if typeof(effect) != TYPE_DICTIONARY:
|
||||
continue
|
||||
if str(effect.get("type", "")) != "cure_status":
|
||||
continue
|
||||
var status := str(effect.get("status", "")).strip_edges().to_lower()
|
||||
for active_effect in _active_status_effects(target):
|
||||
if str(active_effect.get("type", "")) != "damage_over_time":
|
||||
continue
|
||||
var active_status := str(active_effect.get("status", "")).strip_edges().to_lower()
|
||||
if not status.is_empty() and active_status != status:
|
||||
continue
|
||||
var display_name := _status_display_name(str(active_effect.get("status", status)))
|
||||
if not result.has(display_name):
|
||||
result.append(display_name)
|
||||
return result
|
||||
|
||||
|
||||
func _equipment_slot_for_item(item: Dictionary) -> String:
|
||||
var kind := str(item.get("kind", ""))
|
||||
if kind == "weapon" or kind == "armor" or kind == "accessory":
|
||||
|
||||
Reference in New Issue
Block a user