]> git.seodisparate.com - TurnBasedMinecraftMod/commitdiff
Implement attack effects (as listed in config)
authorStephen Seo <seo.disparate@gmail.com>
Thu, 13 Sep 2018 04:52:22 +0000 (13:52 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 13 Sep 2018 04:52:22 +0000 (13:52 +0900)
src/main/java/com/seodisparate/TurnBasedMinecraft/common/Battle.java
src/main/java/com/seodisparate/TurnBasedMinecraft/common/EntityInfo.java
src/main/java/com/seodisparate/TurnBasedMinecraft/common/networking/PacketBattleMessage.java

index 5cc24852ab98c35b38ea0ac3e97cbc36bb032508..242cc8e9be8af496f752e49bb8b32908d0c28cee 100644 (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
                                 {
index bd6353252b89365638d3e45f709e333f4925515b..19286294de74e52f204e651d076b4c50c752ae86 100644 (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()
index 83e8bfd2ab12fed488f7f273300fa9659fa67234..d3898c9f95043948f4c545406998fead08d2410c 100644 (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;
         }