Implement attack effects (as listed in config)

This commit is contained in:
Stephen Seo 2018-09-13 13:52:22 +09:00
parent 9d5e830d3c
commit 24ca95cc99
3 changed files with 162 additions and 1 deletions

View file

@ -690,6 +690,16 @@ public class Battle
sendMessageToAllPlayers(PacketBattleMessage.MessageType.DEFENSE_DAMAGE, target.entity.getEntityId(), next.entity.getEntityId(), target.entityInfo.defenseDamage);
}
}
// attack effect
if(next.entityInfo.attackEffect != EntityInfo.Effect.UNKNOWN && next.entityInfo.attackEffectProbability > 0)
{
int effectChance = (int)(Math.random() * 100);
if(effectChance < next.entityInfo.attackEffectProbability)
{
next.entityInfo.attackEffect.applyEffectToEntity((EntityLivingBase)target.entity);
sendMessageToAllPlayers(PacketBattleMessage.MessageType.WAS_AFFECTED, next.entity.getEntityId(), target.entity.getEntityId(), 0, next.entityInfo.attackEffect.getAffectedString());
}
}
}
else
{

View file

@ -3,6 +3,10 @@ package com.seodisparate.TurnBasedMinecraft.common;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.MobEffects;
import net.minecraft.potion.PotionEffect;
public class EntityInfo
{
public Class classType;
@ -193,6 +197,148 @@ public class EntityInfo
return UNKNOWN;
}
}
public PotionEffect getPotionEffect()
{
return getPotionEffect(20 * 7, 0);
}
public PotionEffect getPotionEffect(int duration, int amplifier)
{
switch(this)
{
case SPEED:
return new PotionEffect(MobEffects.SPEED, duration, amplifier);
case SLOW:
return new PotionEffect(MobEffects.SLOWNESS, duration, amplifier);
case HASTE:
return new PotionEffect(MobEffects.HASTE, duration, amplifier);
case MINING_FATIGUE:
return new PotionEffect(MobEffects.MINING_FATIGUE, duration, amplifier);
case STRENGTH:
return new PotionEffect(MobEffects.STRENGTH, duration, amplifier);
case JUMP_BOOST:
return new PotionEffect(MobEffects.JUMP_BOOST, duration, amplifier);
case NAUSEA:
return new PotionEffect(MobEffects.NAUSEA, duration, amplifier);
case REGENERATION:
return new PotionEffect(MobEffects.REGENERATION, duration, amplifier);
case RESISTANCE:
return new PotionEffect(MobEffects.RESISTANCE, duration, amplifier);
case FIRE_RESISTANCE:
return new PotionEffect(MobEffects.FIRE_RESISTANCE, duration, amplifier);
case WATER_BREATHING:
return new PotionEffect(MobEffects.WATER_BREATHING, duration, amplifier);
case INVISIBILITY:
return new PotionEffect(MobEffects.INVISIBILITY, duration, amplifier);
case BLINDNESS:
return new PotionEffect(MobEffects.BLINDNESS, duration, amplifier);
case NIGHT_VISION:
return new PotionEffect(MobEffects.NIGHT_VISION, duration, amplifier);
case HUNGER:
return new PotionEffect(MobEffects.HUNGER, duration, amplifier);
case WEAKNESS:
return new PotionEffect(MobEffects.WEAKNESS, duration, amplifier);
case POISON:
return new PotionEffect(MobEffects.POISON, duration, amplifier);
case WITHER:
return new PotionEffect(MobEffects.WITHER, duration, amplifier);
case ABSORPTION:
return new PotionEffect(MobEffects.ABSORPTION, duration, amplifier);
case SATURATION:
return new PotionEffect(MobEffects.SATURATION, duration, amplifier);
case GLOWING:
return new PotionEffect(MobEffects.GLOWING, duration, amplifier);
case LEVITATION:
return new PotionEffect(MobEffects.LEVITATION, duration, amplifier);
case LUCK:
return new PotionEffect(MobEffects.LUCK, duration, amplifier);
case UNLUCK:
return new PotionEffect(MobEffects.UNLUCK, duration, amplifier);
case FIRE:
// FIRE is not a PotionEffect and must be applied directly to the Entity
return null;
default:
return null;
}
}
public void applyEffectToEntity(EntityLivingBase entity)
{
applyEffectToEntity(entity, 20 * 7, 0);
}
public void applyEffectToEntity(EntityLivingBase entity, int duration, int amplifier)
{
if(this == FIRE)
{
entity.setFire(duration / 20);
return;
}
else if(this != UNKNOWN)
{
entity.addPotionEffect(getPotionEffect(duration, amplifier));
}
}
public String getAffectedString()
{
switch(this)
{
case SPEED:
return "made faster";
case SLOW:
return "made slower";
case HASTE:
return "made hastier";
case MINING_FATIGUE:
return "fatigued";
case STRENGTH:
return "strengthened";
case JUMP_BOOST:
return "jump boosted";
case NAUSEA:
return "made nauseous";
case REGENERATION:
return "given regeneration";
case RESISTANCE:
return "given resistance";
case FIRE_RESISTANCE:
return "given fire resistance";
case WATER_BREATHING:
return "made able to breathe underwater";
case INVISIBILITY:
return "given invisibility";
case BLINDNESS:
return "made blind";
case NIGHT_VISION:
return "given night vision";
case HUNGER:
return "made hungry";
case WEAKNESS:
return "made weak";
case POISON:
return "poisoned";
case WITHER:
return "withered";
case ABSORPTION:
return "given absorption";
case SATURATION:
return "given saturation";
case GLOWING:
return "made to glow";
case LEVITATION:
return "made to levitate";
case LUCK:
return "given luck";
case UNLUCK:
return "made unlucky";
case FIRE:
return "set on fire";
default:
return "given unknown";
}
}
}
public EntityInfo()

View file

@ -34,7 +34,8 @@ public class PacketBattleMessage implements IMessage
USED_ITEM(10),
TURN_BEGIN(11),
TURN_END(12),
SWITCHED_ITEM(13);
SWITCHED_ITEM(13),
WAS_AFFECTED(14);
private int value;
private static Map<Integer, MessageType> map = new HashMap<Integer, MessageType>();
@ -334,6 +335,10 @@ public class PacketBattleMessage implements IMessage
to + " switched to a different item but failed because it was invalid!"));
}
break;
case WAS_AFFECTED:
Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(new TextComponentString(
from + " was " + message.custom + " by " + to + "!"));
break;
}
return null;
}