from AoE2ScenarioParser.helper.datatype import DataType
from AoE2ScenarioParser.helper.retriever import Retriever
from AoE2ScenarioParser.pieces.structs.aoe2_struct import AoE2Struct


class EffectStruct(AoE2Struct):
    def __init__(self, parser_obj=None, data=None):
        retrievers = [
            Retriever("effect_type", DataType("s32"), save_as="effect_type"),
            Retriever("static_value_46", DataType("s32")),  # always 0x17, now 0x2e (46)?
            Retriever("ai_script_goal", DataType("s32")),
            Retriever("aa_quantity", DataType("u8"),
                      set_repeat="1 if {effect_type} == 31 or {effect_type} == 28 else 0"),
            Retriever("aa_armor_or_attack_type", DataType("s24"),
                      set_repeat="1 if {effect_type} == 31 or {effect_type} == 28 else 0"),
            Retriever("quantity", DataType("s32"),
                      set_repeat="1 if {effect_type} != 31 and {effect_type} != 28 else 0"),
            Retriever("tribute_list", DataType("s32")),
            Retriever("diplomacy", DataType("s32")),
            Retriever("number_of_units_selected", DataType("s32"), save_as="number_of_units_selected"),
            Retriever("unknown", DataType("s32")),
            Retriever("object_list_unit_id", DataType("s32")),
            Retriever("player_source", DataType("s32")),
            Retriever("player_target", DataType("s32")),
            Retriever("technology", DataType("s32")),
            Retriever("string_id", DataType("s32")),
            Retriever("unknown_2", DataType("s32")),
            Retriever("display_time", DataType("s32")),
            Retriever("trigger_id", DataType("s32")),
            Retriever("location_x", DataType("s32")),
            Retriever("location_y", DataType("s32")),
            Retriever("area_1_x", DataType("s32")),
            Retriever("area_1_y", DataType("s32")),
            Retriever("area_2_x", DataType("s32")),
            Retriever("area_2_y", DataType("s32")),
            Retriever("object_group", DataType("s32")),
            Retriever("object_type", DataType("s32")),
            Retriever("instruction_panel_position", DataType("s32")),
            Retriever("attack_stance", DataType("s32")),
            Retriever("time_unit", DataType("s32")),
            Retriever("enabled_or_victory", DataType("s32")),
            Retriever("food", DataType("s32")),
            Retriever("wood", DataType("s32")),
            Retriever("stone", DataType("s32")),
            Retriever("gold", DataType("s32")),
            Retriever("item_id", DataType("s32")),
            Retriever("flash_object", DataType("s32")),
            Retriever("force_research_technology", DataType("s32")),
            Retriever("visibility_state", DataType("s32")),
            Retriever("scroll", DataType("s32")),
            Retriever("operation", DataType("s32")),
            Retriever("object_list_unit_id_2", DataType("s32")),
            Retriever("button_location", DataType("s32")),
            Retriever("ai_signal_value", DataType("s32")),
            Retriever("unknown_3", DataType("s32")),
            Retriever("object_attributes", DataType("s32")),
            Retriever("from_variable", DataType("s32")),
            Retriever("variable_or_timer", DataType("s32")),
            Retriever("facet", DataType("s32")),
            Retriever("unknown_4", DataType("s32")),
            Retriever("play_sound", DataType("s32")),
            Retriever("message", DataType("str32")),
            Retriever("sound_name", DataType("str32")),
            Retriever("selected_object_id", DataType("s32"), set_repeat="{number_of_units_selected}"),
        ]

        super().__init__("Effect", retrievers, parser_obj, data)
