Skip to content
Snippets Groups Projects
Unverified Commit 2fc6c97e authored by Jeffrey Phillips Freeman's avatar Jeffrey Phillips Freeman :boom:
Browse files

fix: fixed looting.

parent be35ec37
No related branches found
No related tags found
No related merge requests found
...@@ -98,23 +98,7 @@ public class LoadNpcCommand extends Command { ...@@ -98,23 +98,7 @@ public class LoadNpcCommand extends Command {
try( GraphStorageFactory.AetherMudTx tx = this.gameManager.getGraphStorageFactory().beginTransaction() ) { try( GraphStorageFactory.AetherMudTx tx = this.gameManager.getGraphStorageFactory().beginTransaction() ) {
AetherMudStorage storage = tx.getStorage(); AetherMudStorage storage = tx.getStorage();
NpcData npcData = storage.newNpcData(); NpcData npcData = storage.newNpcData();
try { NpcData.copyNpc(npcData, npc);
PropertyUtils.copyProperties(npcData, npc);
PropertyUtils.copyProperties(npcData.createStatsData(), npc.getStats());
PropertyUtils.copyProperties(npcData.createLootData(), npc.getLoot());
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException ex) {
throw new IllegalStateException("Could not copy properties for stats", ex);
}
npc.getSpawnRules().forEach(new Consumer<SpawnRule>() {
@Override
public void accept(SpawnRule spawnRule) {
try {
PropertyUtils.copyProperties(npcData.createSpawnRuleData(), spawnRule);
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException ex) {
throw new IllegalStateException("Could not copy properties for stats", ex);
}
}
});
tx.success(); tx.success();
write("NPC Saved. - " + npc.getName() + "\r\n"); write("NPC Saved. - " + npc.getName() + "\r\n");
} }
......
...@@ -85,12 +85,7 @@ public class NpcBuilder { ...@@ -85,12 +85,7 @@ public class NpcBuilder {
this.criticalAttackMessages = Sets.newHashSet(npc.getCriticalAttackMessages()); this.criticalAttackMessages = Sets.newHashSet(npc.getCriticalAttackMessages());
this.battleMessages = Sets.newHashSet(npc.getBattleMessages()); this.battleMessages = Sets.newHashSet(npc.getBattleMessages());
this.idleMessages = Sets.newHashSet(npc.getIdleMessages()); this.idleMessages = Sets.newHashSet(npc.getIdleMessages());
this.loot = new Loot(); this.loot = npc.getLoot();
try {
PropertyUtils.copyProperties(this.loot, npc.getLoot());
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException("Could not copy properties");
}
} }
public NpcBuilder setGameManager(GameManager gameManager) { public NpcBuilder setGameManager(GameManager gameManager) {
......
...@@ -75,7 +75,12 @@ public class GraphDbAetherMudStorage implements AetherMudStorage { ...@@ -75,7 +75,12 @@ public class GraphDbAetherMudStorage implements AetherMudStorage {
@Override @Override
public ItemData saveItem(Item item) { public ItemData saveItem(Item item) {
ItemData itemData = framedGraph.addFramedVertex(ItemData.class); Optional<ItemData> existing = this.getItemEntity(item.getItemId());
ItemData itemData;
if(existing.isPresent())
itemData = existing.get();
else
itemData = framedGraph.addFramedVertex(ItemData.class);
ItemData.copyItem(itemData, item); ItemData.copyItem(itemData, item);
return itemData; return itemData;
} }
......
...@@ -19,6 +19,8 @@ import com.google.common.collect.Sets; ...@@ -19,6 +19,8 @@ import com.google.common.collect.Sets;
import com.syncleus.aethermud.core.service.TimeTracker; import com.syncleus.aethermud.core.service.TimeTracker;
import com.syncleus.aethermud.items.*; import com.syncleus.aethermud.items.*;
import com.syncleus.aethermud.storage.graphdb.DataUtils; import com.syncleus.aethermud.storage.graphdb.DataUtils;
import com.syncleus.ferma.TEdge;
import com.syncleus.ferma.VertexFrame;
import com.syncleus.ferma.annotations.Adjacency; import com.syncleus.ferma.annotations.Adjacency;
import com.syncleus.ferma.annotations.GraphElement; import com.syncleus.ferma.annotations.GraphElement;
import com.syncleus.ferma.annotations.Property; import com.syncleus.ferma.annotations.Property;
...@@ -223,7 +225,7 @@ public abstract class ItemData extends AbstractInterceptingVertexFrame { ...@@ -223,7 +225,7 @@ public abstract class ItemData extends AbstractInterceptingVertexFrame {
return stats; return stats;
} }
@Adjacency(label = "Loot", direction = Direction.OUT) @Adjacency(label = "loot", direction = Direction.OUT)
public abstract <N extends LootData> Iterator<? extends N> getLootDatasIterator(Class<? extends N> type); public abstract <N extends LootData> Iterator<? extends N> getLootDatasIterator(Class<? extends N> type);
public LootData getLootData() { public LootData getLootData() {
...@@ -234,17 +236,17 @@ public abstract class ItemData extends AbstractInterceptingVertexFrame { ...@@ -234,17 +236,17 @@ public abstract class ItemData extends AbstractInterceptingVertexFrame {
return null; return null;
} }
@Adjacency(label = "Loot", direction = Direction.OUT) @Adjacency(label = "loot", direction = Direction.OUT)
public abstract LootData addLootData(LootData loot); public abstract LootData addLootData(LootData loot);
@Adjacency(label = "Loot", direction = Direction.OUT) @Adjacency(label = "loot", direction = Direction.OUT)
public abstract void removeLootData(LootData loot); public abstract void removeLootData(LootData loot);
public void setLootData(LootData loot) { public void setLootData(LootData loot) {
DataUtils.setAllElements(Collections.singletonList(loot), () -> this.getLootDatasIterator(LootData.class), lootData -> this.addLootData(lootData), () -> createLoottData() ); DataUtils.setAllElements(Collections.singletonList(loot), () -> this.getLootDatasIterator(LootData.class), lootData -> this.addLootData(lootData), () -> createLootData() );
} }
public LootData createLoottData() { public LootData createLootData() {
if( this.getLootData() != null ) if( this.getLootData() != null )
throw new IllegalStateException("Already has loot, can't create another"); throw new IllegalStateException("Already has loot, can't create another");
final LootData loot = this.getGraph().addFramedVertex(LootData.class); final LootData loot = this.getGraph().addFramedVertex(LootData.class);
...@@ -258,14 +260,17 @@ public abstract class ItemData extends AbstractInterceptingVertexFrame { ...@@ -258,14 +260,17 @@ public abstract class ItemData extends AbstractInterceptingVertexFrame {
try { try {
PropertyUtils.copyProperties(dest, src); PropertyUtils.copyProperties(dest, src);
if( src.getItemApplyStats() != null ) if( src.getItemApplyStats() != null )
StatData.copyStats(dest.createItemApplyStatData(), src.getItemApplyStats()); StatData.copyStats((dest.getItemApplyStatData() != null ? dest.getItemApplyStatData() : dest.createItemApplyStatData()), src.getItemApplyStats());
if(src.getLoot() != null ) if(src.getLoot() != null )
LootData.copyLoot(dest.createLoottData(), src.getLoot()); LootData.copyLoot((dest.getLootData() != null ? dest.getLootData() : dest.createLootData()), src.getLoot());
if( src.getEquipment() != null ) if( src.getEquipment() != null )
EquipmentData.copyEquipment(dest.createEquipmentData(), src.getEquipment()); EquipmentData.copyEquipment((dest.getEquipmentData() != null ? dest.getEquipmentData() :dest.createEquipmentData()), src.getEquipment());
if( src.getEffects() != null ) if( src.getEffects() != null ) {
for(Effect effect : src.getEffects()) for(EffectData data : dest.getEffectDatas())
data.remove();
for (Effect effect : src.getEffects())
EffectData.copyEffect(dest.createEffectData(), effect); EffectData.copyEffect(dest.createEffectData(), effect);
}
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException("Could not copy properties", e); throw new IllegalStateException("Could not copy properties", e);
} }
......
...@@ -15,10 +15,8 @@ ...@@ -15,10 +15,8 @@
*/ */
package com.syncleus.aethermud.storage.graphdb.model; package com.syncleus.aethermud.storage.graphdb.model;
import com.syncleus.aethermud.items.Effect; import com.syncleus.aethermud.items.Item;
import com.syncleus.aethermud.items.Loot; import com.syncleus.aethermud.items.Loot;
import com.syncleus.aethermud.stats.Stats;
import com.syncleus.ferma.AbstractVertexFrame;
import com.syncleus.ferma.annotations.GraphElement; import com.syncleus.ferma.annotations.GraphElement;
import com.syncleus.ferma.annotations.Property; import com.syncleus.ferma.annotations.Property;
import com.syncleus.ferma.ext.AbstractInterceptingVertexFrame; import com.syncleus.ferma.ext.AbstractInterceptingVertexFrame;
......
...@@ -102,10 +102,10 @@ public abstract class NpcData extends AbstractInterceptingVertexFrame { ...@@ -102,10 +102,10 @@ public abstract class NpcData extends AbstractInterceptingVertexFrame {
} }
@Adjacency(label = "loot", direction = Direction.OUT) @Adjacency(label = "loot", direction = Direction.OUT)
public abstract <N extends LootData> Iterator<? extends N> getAllLootDatas(Class<? extends N> type); public abstract <N extends LootData> Iterator<? extends N> getLootDataIterator(Class<? extends N> type);
public LootData getLootData() { public LootData getLootData() {
Iterator<? extends LootData> allLoots = this.getAllLootDatas(LootData.class); Iterator<? extends LootData> allLoots = this.getLootDataIterator(LootData.class);
if( allLoots.hasNext() ) if( allLoots.hasNext() )
return allLoots.next(); return allLoots.next();
else else
...@@ -119,7 +119,7 @@ public abstract class NpcData extends AbstractInterceptingVertexFrame { ...@@ -119,7 +119,7 @@ public abstract class NpcData extends AbstractInterceptingVertexFrame {
public abstract void removeLootData(LootData loot); public abstract void removeLootData(LootData loot);
public void setLootData(LootData loot) { public void setLootData(LootData loot) {
DataUtils.setAllElements(Collections.singletonList(loot), () -> this.getAllLootDatas(LootData.class), lootData -> this.addLootData(lootData), () -> this.createLootData() ); DataUtils.setAllElements(Collections.singletonList(loot), () -> this.getLootDataIterator(LootData.class), lootData -> this.addLootData(lootData), () -> this.createLootData() );
} }
public LootData createLootData() { public LootData createLootData() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment