62 lines
1.6 KiB
GDScript
62 lines
1.6 KiB
GDScript
class_name NewbieSeedGuide
|
||
extends RefCounted
|
||
|
||
const NEWBIE_SEED_ITEM_ID := 101018
|
||
const NEWBIE_CROP_ID := 18
|
||
|
||
var _show_toast: Callable
|
||
var _seed_tip_shown := false
|
||
var _crop_tip_shown := false
|
||
var _harvest_tip_shown := false
|
||
|
||
|
||
func setup(options: Dictionary) -> void:
|
||
_show_toast = options.get("show_toast", Callable())
|
||
|
||
|
||
func on_inventory_changed(seed_items: Array[Dictionary]) -> void:
|
||
if _seed_tip_shown:
|
||
return
|
||
for item in seed_items:
|
||
if int(item.get("item_id", 0)) != NEWBIE_SEED_ITEM_ID:
|
||
continue
|
||
if int(item.get("num", item.get("number", 0))) <= 0:
|
||
continue
|
||
_seed_tip_shown = true
|
||
_toast("已获得免费金豆种子,点击空地播种,5秒后收获10金豆")
|
||
return
|
||
|
||
|
||
func on_lands_changed(lands_by_position: Dictionary) -> void:
|
||
for land in lands_by_position.values():
|
||
if not land is Dictionary:
|
||
continue
|
||
_check_newbie_crop(land)
|
||
|
||
|
||
func _check_newbie_crop(land_data: Dictionary) -> void:
|
||
if int(land_data.get("crop_id", 0)) != NEWBIE_CROP_ID:
|
||
return
|
||
if int(land_data.get("has_gather", 0)) == 1:
|
||
return
|
||
if int(land_data.get("is_ripe", 0)) == 1 or _is_ripe_by_time(land_data):
|
||
if _harvest_tip_shown:
|
||
return
|
||
_harvest_tip_shown = true
|
||
_toast("金豆已成熟,点击作物收获10金豆")
|
||
return
|
||
if _crop_tip_shown:
|
||
return
|
||
_crop_tip_shown = true
|
||
_toast("金豆种子已种下,5秒后点击成熟作物收获10金豆")
|
||
|
||
|
||
func _is_ripe_by_time(land_data: Dictionary) -> bool:
|
||
var gather_time := int(land_data.get("crop_gather_time", 0))
|
||
return gather_time > 0 and int(Time.get_unix_time_from_system()) >= gather_time
|
||
|
||
|
||
func _toast(message: String) -> void:
|
||
if _show_toast.is_valid():
|
||
_show_toast.call(message)
|