Search in sources :

Example 1 with SkillLearnedEvent

use of am2.api.events.SkillLearnedEvent in project ArsMagica2 by Mithion.

the class SkillData method learn.

public void learn(int id, int type) {
    if (entity.worldObj.isRemote) {
        AMDataWriter writer = new AMDataWriter();
        writer.add(SPELL_LEARNED);
        writer.add(this.entity.getEntityId());
        writer.add(id);
        writer.add(type);
        AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.SYNC_SPELL_KNOWLEDGE, writer.generate());
        MinecraftForge.EVENT_BUS.post(new SkillLearnedEvent(player, SkillManager.instance.getSkill(id)));
    } else {
        SkillPointTypes skillType = SkillTreeManager.instance.getSkillPointTypeForPart(id);
        boolean learned = false;
        switch(type) {
            case 0:
                if (!isShapeKnown(id) && getSpellPoints(skillType) > 0) {
                    setShapeKnown(id);
                    decrementSpellPoints(skillType);
                    learned = true;
                }
                updateFlags |= KNOWN_SHAPE_UPDATE;
                break;
            case 1:
                if (!isComponentKnown(id) && getSpellPoints(skillType) > 0) {
                    setComponentKnown(id);
                    decrementSpellPoints(skillType);
                    learned = true;
                }
                updateFlags |= KNOWN_COMPONENT_UPDATE;
                break;
            case 2:
                if (!isModifierKnown(id) && getSpellPoints(skillType) > 0) {
                    setModifierKnown(id);
                    decrementSpellPoints(skillType);
                    learned = true;
                }
                updateFlags |= KNOWN_MODIFIER_UPDATE;
                break;
            case 3:
                if (!isTalentKnown(id) && getSpellPoints(skillType) > 0) {
                    setTalentKnown(id);
                    decrementSpellPoints(skillType);
                    learned = true;
                }
                updateFlags |= KNOWN_TALENTS_UPDATE;
                break;
        }
        if (entity instanceof EntityPlayerMP && learned && skillType == SkillPointTypes.SILVER) {
            AMNetHandler.INSTANCE.sendSilverSkillPointPacket((EntityPlayerMP) entity);
        }
    }
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SkillLearnedEvent(am2.api.events.SkillLearnedEvent) AMDataWriter(am2.network.AMDataWriter) SkillPointTypes(am2.api.spell.enums.SkillPointTypes)

Example 2 with SkillLearnedEvent

use of am2.api.events.SkillLearnedEvent in project ArsMagica2 by Mithion.

the class SkillData method learn.

@Override
public void learn(ISkillTreeEntry entry) {
    if (entity.worldObj.isRemote) {
        AMDataWriter writer = new AMDataWriter();
        writer.add(SPELL_LEARNED);
        writer.add(this.entity.getEntityId());
        int id = entry.getID();
        if (entry instanceof ISpellComponent)
            id += SkillManager.instance.COMPONENT_OFFSET;
        else if (entry instanceof ISpellModifier)
            id += SkillManager.instance.MODIFIER_OFFSET;
        else if (!(entry instanceof ISpellShape))
            id += SkillManager.instance.TALENT_OFFSET;
        writer.add(id);
        if (entry instanceof ISpellShape)
            writer.add(0);
        else if (entry instanceof ISpellComponent)
            writer.add(1);
        else if (entry instanceof ISpellModifier)
            writer.add(2);
        else
            writer.add(3);
        AMNetHandler.INSTANCE.sendPacketToServer(AMPacketIDs.SYNC_SPELL_KNOWLEDGE, writer.generate());
    } else {
        int id = entry.getID();
        if (entry instanceof ISpellComponent)
            id += SkillManager.instance.COMPONENT_OFFSET;
        else if (entry instanceof ISpellModifier)
            id += SkillManager.instance.MODIFIER_OFFSET;
        else if (!(entry instanceof ISpellShape))
            id += SkillManager.instance.TALENT_OFFSET;
        int type = 3;
        if (entry instanceof ISpellShape)
            type = 0;
        else if (entry instanceof ISpellComponent)
            type = 1;
        else if (entry instanceof ISpellModifier)
            type = 2;
        learn(id, type);
        MinecraftForge.EVENT_BUS.post(new SkillLearnedEvent(player, entry));
    }
}
Also used : ISpellComponent(am2.api.spell.component.interfaces.ISpellComponent) ISpellModifier(am2.api.spell.component.interfaces.ISpellModifier) SkillLearnedEvent(am2.api.events.SkillLearnedEvent) AMDataWriter(am2.network.AMDataWriter) ISpellShape(am2.api.spell.component.interfaces.ISpellShape)

Aggregations

SkillLearnedEvent (am2.api.events.SkillLearnedEvent)2 AMDataWriter (am2.network.AMDataWriter)2 ISpellComponent (am2.api.spell.component.interfaces.ISpellComponent)1 ISpellModifier (am2.api.spell.component.interfaces.ISpellModifier)1 ISpellShape (am2.api.spell.component.interfaces.ISpellShape)1 SkillPointTypes (am2.api.spell.enums.SkillPointTypes)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1