From c7930f8281a5b92379c2683ac9789ba31afeafde Mon Sep 17 00:00:00 2001 From: Ziggeh Date: Thu, 17 Apr 2014 00:25:54 +0200 Subject: [PATCH] Implemented elemental particle effects, #434 --- src/resources/datatables/Elemental.java | 52 +++++++++++++++++++ .../objects/weapon/WeaponMessageBuilder.java | 11 ++-- 2 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 src/resources/datatables/Elemental.java diff --git a/src/resources/datatables/Elemental.java b/src/resources/datatables/Elemental.java new file mode 100644 index 00000000..aea57628 --- /dev/null +++ b/src/resources/datatables/Elemental.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2013 + * + * This File is part of NGECore2. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Using NGEngine to work with NGECore2 is making a combined work based on NGEngine. + * Therefore all terms and conditions of the GNU Lesser General Public License cover the combination. + ******************************************************************************/ +package resources.datatables; + +import org.apache.commons.collections.BidiMap; +import org.apache.commons.collections.bidimap.DualHashBidiMap; + +public final class Elemental { + + + static BidiMap map = new DualHashBidiMap(); + + static { + map.put("kinetic", 1); + map.put("energy", 2); + map.put("blast", 4); + map.put("stun", 8); + map.put("heat", 32); + map.put("cold", 64); + map.put("acid", 128); + map.put("electricity", 256); + } + + + public static int getElementalNum(String elementalName) { + return (int) map.get(elementalName); + } + + public static String getElementalName(int elementalNum) { + return (String) map.getKey(elementalNum); + } + +} diff --git a/src/resources/objects/weapon/WeaponMessageBuilder.java b/src/resources/objects/weapon/WeaponMessageBuilder.java index 8e2e5afc..5084b9cf 100644 --- a/src/resources/objects/weapon/WeaponMessageBuilder.java +++ b/src/resources/objects/weapon/WeaponMessageBuilder.java @@ -26,14 +26,14 @@ import java.nio.ByteOrder; import org.apache.mina.core.buffer.IoBuffer; import resources.objects.ObjectMessageBuilder; - +import resources.datatables.Elemental; public class WeaponMessageBuilder extends ObjectMessageBuilder { public WeaponMessageBuilder(WeaponObject weaponObject) { setObject(weaponObject); } - + public IoBuffer buildBaseline3() { WeaponObject weapon = (WeaponObject) object; IoBuffer buffer = bufferPool.allocate(100, false).order(ByteOrder.LITTLE_ENDIAN); @@ -68,11 +68,12 @@ public class WeaponMessageBuilder extends ObjectMessageBuilder { buffer.putInt(0); buffer.putFloat(weapon.getMaxRange()); buffer.putInt(0); - + if( weapon.getElementalType() != null) // Weapon particle effect + buffer.putInt(Elemental.getElementalNum(weapon.getElementalType())); + else + buffer.putInt(Elemental.getElementalNum(weapon.getDamageType())); buffer.putInt(0); - buffer.putInt(0); // those 2 ints have something to do with particle color - int size = buffer.position(); buffer = bufferPool.allocate(size, false).put(buffer.array(), 0, size);