// • ▌ ▄ ·.  ▄▄▄·  ▄▄ • ▪   ▄▄· ▄▄▄▄·  ▄▄▄·  ▐▄▄▄  ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀  █▪▀▀▀ ▀  ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀  ▀  ▀ ▀▀  █▪ ▀▀▀
//      Magicbane Emulator Project © 2013 - 2022
//                www.magicbane.com


package engine.powers.poweractions;

import engine.gameManager.DbManager;
import engine.math.Vector3fImmutable;
import engine.mbEnums;
import engine.objects.AbstractCharacter;
import engine.objects.AbstractWorldObject;
import engine.objects.CharacterItemManager;
import engine.objects.Item;
import engine.powers.ActionsBase;
import engine.powers.PowersBase;

import java.sql.ResultSet;
import java.sql.SQLException;


public class SetItemFlagPowerAction extends AbstractPowerAction {

    public SetItemFlagPowerAction(ResultSet rs) throws SQLException {
        super(rs);
    }

    @Override
    protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) {

        if (source == null || awo == null || !(awo.getObjectType().equals(mbEnums.GameObjectType.Item)))
            return;

        Item item = (Item) awo;

        if (item.containerType != mbEnums.ItemContainerType.INVENTORY)
            return; //Send an error here?

        //until this is shown to do something else, just use it as item identify spell.

        item.flags.add(mbEnums.ItemFlags.Identified);
        ;

        if (!DbManager.ItemQueries.UPDATE_FLAGS(item))
            item.flags.remove(mbEnums.ItemFlags.Identified);
        ; //update failed, reset

        //update inventory
        CharacterItemManager cim = source.charItemManager;
        if (cim != null)
            cim.updateInventory();
    }

    @Override
    protected void _handleChant(AbstractCharacter source, AbstractWorldObject target, Vector3fImmutable targetLoc, int trains, ActionsBase ab, PowersBase pb) {
    }

    @Override
    protected void _startAction(AbstractCharacter source, AbstractWorldObject awo, Vector3fImmutable targetLoc,
                                int numTrains, ActionsBase ab, PowersBase pb, int duration) {
        // TODO Auto-generated method stub

    }
}
