Commit ed98ab15 authored by Kengxxiao's avatar Kengxxiao Committed by Melledy
Browse files

fix exp drop issue

parent a5601e84
...@@ -7,6 +7,15 @@ public class DropData { ...@@ -7,6 +7,15 @@ public class DropData {
private int minCount; private int minCount;
private int maxCount; private int maxCount;
private boolean share = false; private boolean share = false;
private boolean give = false;
public boolean isGive() {
return give;
}
public void setGive(boolean give) {
this.give = give;
}
public int getItemId() { public int getItemId() {
return itemId; return itemId;
...@@ -43,15 +52,4 @@ public class DropData { ...@@ -43,15 +52,4 @@ public class DropData {
this.share = share; this.share = share;
} }
public boolean isGive() {
return give;
}
private boolean give = false;
public boolean isExp() {
return exp;
}
private boolean exp = false;
} }
...@@ -6,7 +6,11 @@ import emu.grasscutter.data.GameData; ...@@ -6,7 +6,11 @@ import emu.grasscutter.data.GameData;
import emu.grasscutter.data.def.ItemData; import emu.grasscutter.data.def.ItemData;
import emu.grasscutter.game.entity.EntityItem; import emu.grasscutter.game.entity.EntityItem;
import emu.grasscutter.game.entity.EntityMonster; import emu.grasscutter.game.entity.EntityMonster;
import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.inventory.ItemType;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.game.world.Scene;
import emu.grasscutter.server.game.GameServer; import emu.grasscutter.server.game.GameServer;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
import emu.grasscutter.utils.Utils; import emu.grasscutter.utils.Utils;
...@@ -53,31 +57,41 @@ public class DropManager { ...@@ -53,31 +57,41 @@ public class DropManager {
e.printStackTrace(); e.printStackTrace();
} }
} }
private void addDropEntity(DropData dd, Scene dropScene, ItemData itemData, Position pos, int num, Player target) {
if (!dd.isGive() && (itemData.getItemType() != ItemType.ITEM_VIRTUAL || itemData.getGadgetId() != 0)) {
EntityItem entity = new EntityItem(dropScene, target, itemData, pos, num, dd.isShare());
if (!dd.isShare())
dropScene.addEntityToSingleClient(target, entity);
else
dropScene.addEntity(entity);
} else {
if (target != null) {
target.getInventory().addItem(new GameItem(itemData, num), ActionReason.SubfieldDrop, true);
} else {
// target is null if items will be added are shared. no one could pick it up because of the combination(give + shared)
// so it will be sent to all players' inventories directly.
dropScene.getPlayers().forEach(x -> {
x.getInventory().addItem(new GameItem(itemData, num), ActionReason.SubfieldDrop, true);
});
}
}
}
private void processDrop(DropData dd, EntityMonster em, Player gp) { private void processDrop(DropData dd, EntityMonster em, Player gp) {
int target = Utils.randomRange(1, 10000); int target = Utils.randomRange(1, 10000);
if (target >= dd.getMinWeight() && target < dd.getMaxWeight()) { if (target >= dd.getMinWeight() && target < dd.getMaxWeight()) {
ItemData itemData = GameData.getItemDataMap().get(dd.getItemId()); ItemData itemData = GameData.getItemDataMap().get(dd.getItemId());
int num = Utils.randomRange(dd.getMinCount(), dd.getMaxCount()); int num = Utils.randomRange(dd.getMinCount(), dd.getMaxCount());
if (!dd.isGive()) {
if (itemData.isEquip()) { if (itemData.isEquip()) {
for (int i = 0; i < num; i++) { for (int i = 0; i < num; i++) {
float range = (5f + (.1f * num)); float range = (5f + (.1f * num));
Position pos = em.getPosition().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f).addZ((float) (Math.random() * range) - (range / 2)); Position pos = em.getPosition().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f).addZ((float) (Math.random() * range) - (range / 2));
EntityItem entity = new EntityItem(em.getScene(), gp, itemData, pos, num, dd.isShare()); addDropEntity(dd, em.getScene(), itemData, pos, num, gp);
if (!dd.isShare())
em.getScene().addEntityToSingleClient(gp, entity);
else
em.getScene().addEntity(entity);
} }
} else { } else {
Position pos = em.getPosition().clone().addY(3f); Position pos = em.getPosition().clone().addY(3f);
EntityItem entity = new EntityItem(em.getScene(), gp, itemData, pos, num, dd.isShare()); addDropEntity(dd, em.getScene(), itemData, pos, num, gp);
if (!dd.isShare())
em.getScene().addEntityToSingleClient(gp, entity);
else
em.getScene().addEntity(entity);
}
} }
} }
} }
......
...@@ -168,7 +168,7 @@ public class Inventory implements Iterable<GameItem> { ...@@ -168,7 +168,7 @@ public class Inventory implements Iterable<GameItem> {
} else if (type == ItemType.ITEM_VIRTUAL) { } else if (type == ItemType.ITEM_VIRTUAL) {
// Handle // Handle
this.addVirtualItem(item.getItemId(), item.getCount()); this.addVirtualItem(item.getItemId(), item.getCount());
return null; return item;
} else if (item.getItemData().getMaterialType() == MaterialType.MATERIAL_AVATAR) { } else if (item.getItemData().getMaterialType() == MaterialType.MATERIAL_AVATAR) {
// Get avatar id // Get avatar id
int avatarId = (item.getItemId() % 1000) + 10000000; int avatarId = (item.getItemId() % 1000) + 10000000;
...@@ -236,9 +236,7 @@ public class Inventory implements Iterable<GameItem> { ...@@ -236,9 +236,7 @@ public class Inventory implements Iterable<GameItem> {
private void addVirtualItem(int itemId, int count) { private void addVirtualItem(int itemId, int count) {
switch (itemId) { switch (itemId) {
case 101: // Character exp case 101: // Character exp
for (EntityAvatar entity : getPlayer().getTeamManager().getActiveTeam()) { getPlayer().getServer().getInventoryManager().upgradeAvatar(player, getPlayer().getTeamManager().getCurrentAvatarEntity().getAvatar(), count);
getPlayer().getServer().getInventoryManager().upgradeAvatar(player, entity.getAvatar(), count);
}
break; break;
case 102: // Adventure exp case 102: // Adventure exp
getPlayer().addExpDirectly(count); getPlayer().addExpDirectly(count);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment