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);
}
}
}
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));
}
}
Aggregations