Commit fa9d703d authored by BaiSugar's avatar BaiSugar Committed by GitHub
Browse files

Merge branch 'Grasscutters:development' into development

parents 6a5d97a3 d1fc8c1f
package emu.grasscutter.game.entity; package emu.grasscutter.game.entity;
import emu.grasscutter.data.GenshinData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.common.PropGrowCurve; import emu.grasscutter.data.common.PropGrowCurve;
import emu.grasscutter.data.def.MonsterCurveData; import emu.grasscutter.data.def.MonsterCurveData;
import emu.grasscutter.data.def.MonsterData; import emu.grasscutter.data.def.MonsterData;
import emu.grasscutter.game.GenshinScene;
import emu.grasscutter.game.World;
import emu.grasscutter.game.props.EntityIdType; import emu.grasscutter.game.props.EntityIdType;
import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.game.props.PlayerProperty; import emu.grasscutter.game.props.PlayerProperty;
import emu.grasscutter.game.world.Scene;
import emu.grasscutter.game.world.World;
import emu.grasscutter.net.proto.AbilitySyncStateInfoOuterClass.AbilitySyncStateInfo; import emu.grasscutter.net.proto.AbilitySyncStateInfoOuterClass.AbilitySyncStateInfo;
import emu.grasscutter.net.proto.AnimatorParameterValueInfoPairOuterClass.AnimatorParameterValueInfoPair; import emu.grasscutter.net.proto.AnimatorParameterValueInfoPairOuterClass.AnimatorParameterValueInfoPair;
import emu.grasscutter.net.proto.EntityAuthorityInfoOuterClass.EntityAuthorityInfo; import emu.grasscutter.net.proto.EntityAuthorityInfoOuterClass.EntityAuthorityInfo;
...@@ -27,7 +27,7 @@ import emu.grasscutter.utils.ProtoHelper; ...@@ -27,7 +27,7 @@ import emu.grasscutter.utils.ProtoHelper;
import it.unimi.dsi.fastutil.ints.Int2FloatMap; import it.unimi.dsi.fastutil.ints.Int2FloatMap;
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
public class EntityMonster extends GenshinEntity { public class EntityMonster extends GameEntity {
private final MonsterData monsterData; private final MonsterData monsterData;
private final Int2FloatOpenHashMap fightProp; private final Int2FloatOpenHashMap fightProp;
...@@ -41,7 +41,7 @@ public class EntityMonster extends GenshinEntity { ...@@ -41,7 +41,7 @@ public class EntityMonster extends GenshinEntity {
private int configId; private int configId;
private int poseId; private int poseId;
public EntityMonster(GenshinScene scene, MonsterData monsterData, Position pos, int level) { public EntityMonster(Scene scene, MonsterData monsterData, Position pos, int level) {
super(scene); super(scene);
this.id = getWorld().getNextEntityId(EntityIdType.MONSTER); this.id = getWorld().getNextEntityId(EntityIdType.MONSTER);
this.monsterData = monsterData; this.monsterData = monsterData;
...@@ -160,7 +160,7 @@ public class EntityMonster extends GenshinEntity { ...@@ -160,7 +160,7 @@ public class EntityMonster extends GenshinEntity {
this.setFightProperty(FightProperty.FIGHT_PROP_ICE_SUB_HURT, data.getIceSubHurt()); this.setFightProperty(FightProperty.FIGHT_PROP_ICE_SUB_HURT, data.getIceSubHurt());
// Level curve // Level curve
MonsterCurveData curve = GenshinData.getMonsterCurveDataMap().get(this.getLevel()); MonsterCurveData curve = GameData.getMonsterCurveDataMap().get(this.getLevel());
if (curve != null) { if (curve != null) {
for (PropGrowCurve growCurve : data.getPropGrowCurves()) { for (PropGrowCurve growCurve : data.getPropGrowCurves()) {
FightProperty prop = FightProperty.getPropByName(growCurve.getType()); FightProperty prop = FightProperty.getPropByName(growCurve.getType());
......
package emu.grasscutter.game.entity; package emu.grasscutter.game.entity;
import emu.grasscutter.game.GenshinScene;
import emu.grasscutter.game.World;
import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.game.props.LifeState; import emu.grasscutter.game.props.LifeState;
import emu.grasscutter.game.world.Scene;
import emu.grasscutter.game.world.SpawnDataEntry; import emu.grasscutter.game.world.SpawnDataEntry;
import emu.grasscutter.game.world.World;
import emu.grasscutter.net.proto.MotionInfoOuterClass.MotionInfo; import emu.grasscutter.net.proto.MotionInfoOuterClass.MotionInfo;
import emu.grasscutter.net.proto.MotionStateOuterClass.MotionState; import emu.grasscutter.net.proto.MotionStateOuterClass.MotionState;
import emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo; import emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo;
...@@ -12,16 +12,16 @@ import emu.grasscutter.net.proto.VectorOuterClass.Vector; ...@@ -12,16 +12,16 @@ import emu.grasscutter.net.proto.VectorOuterClass.Vector;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
public abstract class GenshinEntity { public abstract class GameEntity {
protected int id; protected int id;
private final GenshinScene scene; private final Scene scene;
private SpawnDataEntry spawnEntry; private SpawnDataEntry spawnEntry;
private MotionState moveState; private MotionState moveState;
private int lastMoveSceneTimeMs; private int lastMoveSceneTimeMs;
private int lastMoveReliableSeq; private int lastMoveReliableSeq;
public GenshinEntity(GenshinScene scene) { public GameEntity(Scene scene) {
this.scene = scene; this.scene = scene;
this.moveState = MotionState.MOTION_NONE; this.moveState = MotionState.MOTION_NONE;
} }
...@@ -34,7 +34,7 @@ public abstract class GenshinEntity { ...@@ -34,7 +34,7 @@ public abstract class GenshinEntity {
return this.getScene().getWorld(); return this.getScene().getWorld();
} }
public GenshinScene getScene() { public Scene getScene() {
return this.scene; return this.scene;
} }
......
...@@ -3,7 +3,7 @@ package emu.grasscutter.game.friends; ...@@ -3,7 +3,7 @@ package emu.grasscutter.game.friends;
import java.util.List; import java.util.List;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.proto.DealAddFriendResultTypeOuterClass.DealAddFriendResultType; import emu.grasscutter.net.proto.DealAddFriendResultTypeOuterClass.DealAddFriendResultType;
import emu.grasscutter.server.packet.send.PacketAskAddFriendNotify; import emu.grasscutter.server.packet.send.PacketAskAddFriendNotify;
import emu.grasscutter.server.packet.send.PacketAskAddFriendRsp; import emu.grasscutter.server.packet.send.PacketAskAddFriendRsp;
...@@ -14,20 +14,20 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap; ...@@ -14,20 +14,20 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public class FriendsList { public class FriendsList {
private final GenshinPlayer player; private final Player player;
private final Int2ObjectMap<Friendship> friends; private final Int2ObjectMap<Friendship> friends;
private final Int2ObjectMap<Friendship> pendingFriends; private final Int2ObjectMap<Friendship> pendingFriends;
private boolean loaded = false; private boolean loaded = false;
public FriendsList(GenshinPlayer player) { public FriendsList(Player player) {
this.player = player; this.player = player;
this.friends = new Int2ObjectOpenHashMap<Friendship>(); this.friends = new Int2ObjectOpenHashMap<Friendship>();
this.pendingFriends = new Int2ObjectOpenHashMap<Friendship>(); this.pendingFriends = new Int2ObjectOpenHashMap<Friendship>();
} }
public GenshinPlayer getPlayer() { public Player getPlayer() {
return player; return player;
} }
...@@ -83,7 +83,7 @@ public class FriendsList { ...@@ -83,7 +83,7 @@ public class FriendsList {
return; return;
} }
GenshinPlayer target = getPlayer().getSession().getServer().getPlayerByUid(targetUid, true); Player target = getPlayer().getSession().getServer().getPlayerByUid(targetUid, true);
if (target == null) { if (target == null) {
return; // Should never happen return; // Should never happen
} }
...@@ -143,7 +143,7 @@ public class FriendsList { ...@@ -143,7 +143,7 @@ public class FriendsList {
myFriendship.delete(); myFriendship.delete();
Friendship theirFriendship = null; Friendship theirFriendship = null;
GenshinPlayer friend = myFriendship.getFriendProfile().getPlayer(); Player friend = myFriendship.getFriendProfile().getPlayer();
if (friend != null) { if (friend != null) {
// Friend online // Friend online
theirFriendship = friend.getFriendsList().getFriendById(this.getPlayer().getUid()); theirFriendship = friend.getFriendsList().getFriendById(this.getPlayer().getUid());
...@@ -165,7 +165,7 @@ public class FriendsList { ...@@ -165,7 +165,7 @@ public class FriendsList {
} }
public synchronized void sendFriendRequest(int targetUid) { public synchronized void sendFriendRequest(int targetUid) {
GenshinPlayer target = getPlayer().getSession().getServer().getPlayerByUid(targetUid, true); Player target = getPlayer().getSession().getServer().getPlayerByUid(targetUid, true);
if (target == null || target == this.getPlayer()) { if (target == null || target == this.getPlayer()) {
return; return;
...@@ -220,7 +220,7 @@ public class FriendsList { ...@@ -220,7 +220,7 @@ public class FriendsList {
friendship.setOwner(getPlayer()); friendship.setOwner(getPlayer());
// Check if friend is online // Check if friend is online
GenshinPlayer friend = getPlayer().getSession().getServer().getPlayerByUid(friendship.getFriendProfile().getUid()); Player friend = getPlayer().getSession().getServer().getPlayerByUid(friendship.getFriendProfile().getUid());
if (friend != null) { if (friend != null) {
// Set friend to online mode // Set friend to online mode
friendship.setFriendProfile(friend); friendship.setFriendProfile(friend);
......
...@@ -5,7 +5,7 @@ import org.bson.types.ObjectId; ...@@ -5,7 +5,7 @@ import org.bson.types.ObjectId;
import dev.morphia.annotations.*; import dev.morphia.annotations.*;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.proto.FriendBriefOuterClass.FriendBrief; import emu.grasscutter.net.proto.FriendBriefOuterClass.FriendBrief;
import emu.grasscutter.net.proto.FriendOnlineStateOuterClass.FriendOnlineState; import emu.grasscutter.net.proto.FriendOnlineStateOuterClass.FriendOnlineState;
import emu.grasscutter.net.proto.HeadImageOuterClass.HeadImage; import emu.grasscutter.net.proto.HeadImageOuterClass.HeadImage;
...@@ -14,7 +14,7 @@ import emu.grasscutter.net.proto.HeadImageOuterClass.HeadImage; ...@@ -14,7 +14,7 @@ import emu.grasscutter.net.proto.HeadImageOuterClass.HeadImage;
public class Friendship { public class Friendship {
@Id private ObjectId id; @Id private ObjectId id;
@Transient private GenshinPlayer owner; @Transient private Player owner;
@Indexed private int ownerId; @Indexed private int ownerId;
@Indexed private int friendId; @Indexed private int friendId;
...@@ -26,7 +26,7 @@ public class Friendship { ...@@ -26,7 +26,7 @@ public class Friendship {
@Deprecated // Morphia use only @Deprecated // Morphia use only
public Friendship() { } public Friendship() { }
public Friendship(GenshinPlayer owner, GenshinPlayer friend, GenshinPlayer asker) { public Friendship(Player owner, Player friend, Player asker) {
this.setOwner(owner); this.setOwner(owner);
this.ownerId = owner.getUid(); this.ownerId = owner.getUid();
this.friendId = friend.getUid(); this.friendId = friend.getUid();
...@@ -34,11 +34,11 @@ public class Friendship { ...@@ -34,11 +34,11 @@ public class Friendship {
this.askerId = asker.getUid(); this.askerId = asker.getUid();
} }
public GenshinPlayer getOwner() { public Player getOwner() {
return owner; return owner;
} }
public void setOwner(GenshinPlayer owner) { public void setOwner(Player owner) {
this.owner = owner; this.owner = owner;
} }
...@@ -70,7 +70,7 @@ public class Friendship { ...@@ -70,7 +70,7 @@ public class Friendship {
return profile; return profile;
} }
public void setFriendProfile(GenshinPlayer character) { public void setFriendProfile(Player character) {
if (character == null || this.friendId != character.getUid()) return; if (character == null || this.friendId != character.getUid()) return;
this.profile = character.getProfile(); this.profile = character.getProfile();
} }
......
package emu.grasscutter.game.friends; package emu.grasscutter.game.friends;
import dev.morphia.annotations.*; import dev.morphia.annotations.*;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.player.Player;
import emu.grasscutter.utils.Utils; import emu.grasscutter.utils.Utils;
@Entity @Entity
public class PlayerProfile { public class PlayerProfile {
@Transient private GenshinPlayer player; @Transient private Player player;
@AlsoLoad("id") private int uid; @AlsoLoad("id") private int uid;
private int nameCard; private int nameCard;
...@@ -22,7 +22,7 @@ public class PlayerProfile { ...@@ -22,7 +22,7 @@ public class PlayerProfile {
@Deprecated // Morphia only @Deprecated // Morphia only
public PlayerProfile() { } public PlayerProfile() { }
public PlayerProfile(GenshinPlayer player) { public PlayerProfile(Player player) {
this.uid = player.getUid(); this.uid = player.getUid();
this.syncWithCharacter(player); this.syncWithCharacter(player);
} }
...@@ -31,11 +31,11 @@ public class PlayerProfile { ...@@ -31,11 +31,11 @@ public class PlayerProfile {
return uid; return uid;
} }
public GenshinPlayer getPlayer() { public Player getPlayer() {
return player; return player;
} }
public synchronized void setPlayer(GenshinPlayer player) { public synchronized void setPlayer(Player player) {
this.player = player; this.player = player;
} }
...@@ -83,7 +83,7 @@ public class PlayerProfile { ...@@ -83,7 +83,7 @@ public class PlayerProfile {
return this.getPlayer() != null; return this.getPlayer() != null;
} }
public void syncWithCharacter(GenshinPlayer player) { public void syncWithCharacter(Player player) {
if (player == null) { if (player == null) {
return; return;
} }
......
...@@ -12,13 +12,13 @@ import com.google.gson.reflect.TypeToken; ...@@ -12,13 +12,13 @@ import com.google.gson.reflect.TypeToken;
import com.sun.nio.file.SensitivityWatchEventModifier; import com.sun.nio.file.SensitivityWatchEventModifier;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GenshinData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.def.ItemData; import emu.grasscutter.data.def.ItemData;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.avatar.GenshinAvatar; import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.inventory.GenshinItem;
import emu.grasscutter.game.inventory.ItemType; import emu.grasscutter.game.inventory.ItemType;
import emu.grasscutter.game.inventory.MaterialType; import emu.grasscutter.game.inventory.MaterialType;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.proto.GachaItemOuterClass.GachaItem; import emu.grasscutter.net.proto.GachaItemOuterClass.GachaItem;
import emu.grasscutter.net.proto.GachaTransferItemOuterClass.GachaTransferItem; import emu.grasscutter.net.proto.GachaTransferItemOuterClass.GachaTransferItem;
import emu.grasscutter.net.proto.GetGachaInfoRspOuterClass.GetGachaInfoRsp; import emu.grasscutter.net.proto.GetGachaInfoRspOuterClass.GetGachaInfoRsp;
...@@ -89,7 +89,7 @@ public class GachaManager { ...@@ -89,7 +89,7 @@ public class GachaManager {
} }
} }
public synchronized void doPulls(GenshinPlayer player, int gachaType, int times) { public synchronized void doPulls(Player player, int gachaType, int times) {
// Sanity check // Sanity check
if (times != 10 && times != 1) { if (times != 10 && times != 1) {
return; return;
...@@ -108,7 +108,7 @@ public class GachaManager { ...@@ -108,7 +108,7 @@ public class GachaManager {
// Spend currency // Spend currency
if (banner.getCostItem() > 0) { if (banner.getCostItem() > 0) {
GenshinItem costItem = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(banner.getCostItem()); GameItem costItem = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(banner.getCostItem());
if (costItem == null || costItem.getCount() < times) { if (costItem == null || costItem.getCount() < times) {
return; return;
} }
...@@ -191,7 +191,7 @@ public class GachaManager { ...@@ -191,7 +191,7 @@ public class GachaManager {
int stardust = 0, starglitter = 0; int stardust = 0, starglitter = 0;
for (int itemId : wonItems) { for (int itemId : wonItems) {
ItemData itemData = GenshinData.getItemDataMap().get(itemId); ItemData itemData = GameData.getItemDataMap().get(itemId);
if (itemData == null) { if (itemData == null) {
continue; continue;
} }
...@@ -204,11 +204,11 @@ public class GachaManager { ...@@ -204,11 +204,11 @@ public class GachaManager {
// Const check // Const check
if (itemData.getMaterialType() == MaterialType.MATERIAL_AVATAR) { if (itemData.getMaterialType() == MaterialType.MATERIAL_AVATAR) {
int avatarId = (itemData.getId() % 1000) + 10000000; int avatarId = (itemData.getId() % 1000) + 10000000;
GenshinAvatar avatar = player.getAvatars().getAvatarById(avatarId); Avatar avatar = player.getAvatars().getAvatarById(avatarId);
if (avatar != null) { if (avatar != null) {
int constLevel = avatar.getCoreProudSkillLevel(); int constLevel = avatar.getCoreProudSkillLevel();
int constItemId = itemData.getId() + 100; int constItemId = itemData.getId() + 100;
GenshinItem constItem = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(constItemId); GameItem constItem = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(constItemId);
if (constItem != null) { if (constItem != null) {
constLevel += constItem.getCount(); constLevel += constItem.getCount();
} }
...@@ -249,7 +249,7 @@ public class GachaManager { ...@@ -249,7 +249,7 @@ public class GachaManager {
} }
// Create item // Create item
GenshinItem item = new GenshinItem(itemData); GameItem item = new GameItem(itemData);
gachaItem.setGachaItem(item.toItemParam()); gachaItem.setGachaItem(item.toItemParam());
player.getInventory().addItem(item); player.getInventory().addItem(item);
......
...@@ -4,26 +4,26 @@ import java.util.HashSet; ...@@ -4,26 +4,26 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
public class EquipInventoryTab implements InventoryTab { public class EquipInventoryTab implements InventoryTab {
private final Set<GenshinItem> items; private final Set<GameItem> items;
private final int maxCapacity; private final int maxCapacity;
public EquipInventoryTab(int maxCapacity) { public EquipInventoryTab(int maxCapacity) {
this.items = new HashSet<GenshinItem>(); this.items = new HashSet<GameItem>();
this.maxCapacity = maxCapacity; this.maxCapacity = maxCapacity;
} }
@Override @Override
public GenshinItem getItemById(int id) { public GameItem getItemById(int id) {
return null; return null;
} }
@Override @Override
public void onAddItem(GenshinItem item) { public void onAddItem(GameItem item) {
this.items.add(item); this.items.add(item);
} }
@Override @Override
public void onRemoveItem(GenshinItem item) { public void onRemoveItem(GameItem item) {
this.items.remove(item); this.items.remove(item);
} }
......
...@@ -13,13 +13,13 @@ import dev.morphia.annotations.Indexed; ...@@ -13,13 +13,13 @@ import dev.morphia.annotations.Indexed;
import dev.morphia.annotations.PostLoad; import dev.morphia.annotations.PostLoad;
import dev.morphia.annotations.Transient; import dev.morphia.annotations.Transient;
import emu.grasscutter.data.GenshinData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.GenshinDepot; import emu.grasscutter.data.GameDepot;
import emu.grasscutter.data.def.ItemData; import emu.grasscutter.data.def.ItemData;
import emu.grasscutter.data.def.ReliquaryAffixData; import emu.grasscutter.data.def.ReliquaryAffixData;
import emu.grasscutter.data.def.ReliquaryMainPropData; import emu.grasscutter.data.def.ReliquaryMainPropData;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.net.proto.AbilitySyncStateInfoOuterClass.AbilitySyncStateInfo; import emu.grasscutter.net.proto.AbilitySyncStateInfoOuterClass.AbilitySyncStateInfo;
import emu.grasscutter.net.proto.EquipOuterClass.Equip; import emu.grasscutter.net.proto.EquipOuterClass.Equip;
...@@ -35,7 +35,7 @@ import emu.grasscutter.net.proto.WeaponOuterClass.Weapon; ...@@ -35,7 +35,7 @@ import emu.grasscutter.net.proto.WeaponOuterClass.Weapon;
import emu.grasscutter.utils.WeightedList; import emu.grasscutter.utils.WeightedList;
@Entity(value = "items", useDiscriminator = false) @Entity(value = "items", useDiscriminator = false)
public class GenshinItem { public class GameItem {
@Id private ObjectId id; @Id private ObjectId id;
@Indexed private int ownerId; @Indexed private int ownerId;
private int itemId; private int itemId;
...@@ -62,23 +62,23 @@ public class GenshinItem { ...@@ -62,23 +62,23 @@ public class GenshinItem {
private int equipCharacter; private int equipCharacter;
@Transient private int weaponEntityId; @Transient private int weaponEntityId;
public GenshinItem() { public GameItem() {
// Morphia only // Morphia only
} }
public GenshinItem(int itemId) { public GameItem(int itemId) {
this(GenshinData.getItemDataMap().get(itemId)); this(GameData.getItemDataMap().get(itemId));
} }
public GenshinItem(int itemId, int count) { public GameItem(int itemId, int count) {
this(GenshinData.getItemDataMap().get(itemId), count); this(GameData.getItemDataMap().get(itemId), count);
} }
public GenshinItem(ItemData data) { public GameItem(ItemData data) {
this(data, 1); this(data, 1);
} }
public GenshinItem(ItemData data, int count) { public GameItem(ItemData data, int count) {
this.itemId = data.getId(); this.itemId = data.getId();
this.itemData = data; this.itemData = data;
...@@ -103,7 +103,7 @@ public class GenshinItem { ...@@ -103,7 +103,7 @@ public class GenshinItem {
this.level = 1; this.level = 1;
this.appendPropIdList = new ArrayList<>(); this.appendPropIdList = new ArrayList<>();
// Create main property // Create main property
ReliquaryMainPropData mainPropData = GenshinDepot.getRandomRelicMainProp(getItemData().getMainPropDepotId()); ReliquaryMainPropData mainPropData = GameDepot.getRandomRelicMainProp(getItemData().getMainPropDepotId());
if (mainPropData != null) { if (mainPropData != null) {
this.mainPropId = mainPropData.getId(); this.mainPropId = mainPropData.getId();
} }
...@@ -124,9 +124,9 @@ public class GenshinItem { ...@@ -124,9 +124,9 @@ public class GenshinItem {
return ownerId; return ownerId;
} }
public void setOwner(GenshinPlayer player) { public void setOwner(Player player) {
this.ownerId = player.getUid(); this.ownerId = player.getUid();
this.guid = player.getNextGenshinGuid(); this.guid = player.getNextGameGuid();
} }
public int getItemId() { public int getItemId() {
return itemId; return itemId;
...@@ -261,7 +261,7 @@ public class GenshinItem { ...@@ -261,7 +261,7 @@ public class GenshinItem {
} }
private void addNewAppendProp() { private void addNewAppendProp() {
List<ReliquaryAffixData> affixList = GenshinDepot.getRandomRelicAffixList(getItemData().getAppendPropDepotId()); List<ReliquaryAffixData> affixList = GameDepot.getRandomRelicAffixList(getItemData().getAppendPropDepotId());
if (affixList == null) { if (affixList == null) {
return; return;
...@@ -269,13 +269,13 @@ public class GenshinItem { ...@@ -269,13 +269,13 @@ public class GenshinItem {
// Build blacklist - Dont add same stat as main/sub stat // Build blacklist - Dont add same stat as main/sub stat
Set<FightProperty> blacklist = new HashSet<>(); Set<FightProperty> blacklist = new HashSet<>();
ReliquaryMainPropData mainPropData = GenshinData.getReliquaryMainPropDataMap().get(this.getMainPropId()); ReliquaryMainPropData mainPropData = GameData.getReliquaryMainPropDataMap().get(this.getMainPropId());
if (mainPropData != null) { if (mainPropData != null) {
blacklist.add(mainPropData.getFightProp()); blacklist.add(mainPropData.getFightProp());
} }
int len = Math.min(4, this.getAppendPropIdList().size()); int len = Math.min(4, this.getAppendPropIdList().size());
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
ReliquaryAffixData affixData = GenshinData.getReliquaryAffixDataMap().get((int) this.getAppendPropIdList().get(i)); ReliquaryAffixData affixData = GameData.getReliquaryAffixDataMap().get((int) this.getAppendPropIdList().get(i));
if (affixData != null) { if (affixData != null) {
blacklist.add(affixData.getFightProp()); blacklist.add(affixData.getFightProp());
} }
...@@ -299,7 +299,7 @@ public class GenshinItem { ...@@ -299,7 +299,7 @@ public class GenshinItem {
} }
private void upgradeRandomAppendProp() { private void upgradeRandomAppendProp() {
List<ReliquaryAffixData> affixList = GenshinDepot.getRandomRelicAffixList(getItemData().getAppendPropDepotId()); List<ReliquaryAffixData> affixList = GameDepot.getRandomRelicAffixList(getItemData().getAppendPropDepotId());
if (affixList == null) { if (affixList == null) {
return; return;
...@@ -309,7 +309,7 @@ public class GenshinItem { ...@@ -309,7 +309,7 @@ public class GenshinItem {
Set<FightProperty> whitelist = new HashSet<>(); Set<FightProperty> whitelist = new HashSet<>();
int len = Math.min(4, this.getAppendPropIdList().size()); int len = Math.min(4, this.getAppendPropIdList().size());
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
ReliquaryAffixData affixData = GenshinData.getReliquaryAffixDataMap().get((int) this.getAppendPropIdList().get(i)); ReliquaryAffixData affixData = GameData.getReliquaryAffixDataMap().get((int) this.getAppendPropIdList().get(i));
if (affixData != null) { if (affixData != null) {
whitelist.add(affixData.getFightProp()); whitelist.add(affixData.getFightProp());
} }
...@@ -331,7 +331,7 @@ public class GenshinItem { ...@@ -331,7 +331,7 @@ public class GenshinItem {
@PostLoad @PostLoad
public void onLoad() { public void onLoad() {
if (this.itemData == null) { if (this.itemData == null) {
this.itemData = GenshinData.getItemDataMap().get(getItemId()); this.itemData = GameData.getItemDataMap().get(getItemId());
} }
} }
......
...@@ -5,20 +5,22 @@ import java.util.Iterator; ...@@ -5,20 +5,22 @@ import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import emu.grasscutter.GenshinConstants; import emu.grasscutter.GameConstants;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GenshinData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.def.AvatarCostumeData; import emu.grasscutter.data.def.AvatarCostumeData;
import emu.grasscutter.data.def.AvatarData; import emu.grasscutter.data.def.AvatarData;
import emu.grasscutter.data.def.AvatarFlycloakData; import emu.grasscutter.data.def.AvatarFlycloakData;
import emu.grasscutter.data.def.ItemData; import emu.grasscutter.data.def.ItemData;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.avatar.AvatarStorage; import emu.grasscutter.game.avatar.AvatarStorage;
import emu.grasscutter.game.avatar.GenshinAvatar; import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam; import emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam;
import emu.grasscutter.server.packet.send.PacketAvatarEquipChangeNotify; import emu.grasscutter.server.packet.send.PacketAvatarEquipChangeNotify;
import emu.grasscutter.server.packet.send.PacketItemAddHintNotify;
import emu.grasscutter.server.packet.send.PacketStoreItemChangeNotify; import emu.grasscutter.server.packet.send.PacketStoreItemChangeNotify;
import emu.grasscutter.server.packet.send.PacketStoreItemDelNotify; import emu.grasscutter.server.packet.send.PacketStoreItemDelNotify;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
...@@ -26,13 +28,13 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; ...@@ -26,13 +28,13 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
public class Inventory implements Iterable<GenshinItem> { public class Inventory implements Iterable<GameItem> {
private final GenshinPlayer player; private final Player player;
private final Long2ObjectMap<GenshinItem> store; private final Long2ObjectMap<GameItem> store;
private final Int2ObjectMap<InventoryTab> inventoryTypes; private final Int2ObjectMap<InventoryTab> inventoryTypes;
public Inventory(GenshinPlayer player) { public Inventory(Player player) {
this.player = player; this.player = player;
this.store = new Long2ObjectOpenHashMap<>(); this.store = new Long2ObjectOpenHashMap<>();
this.inventoryTypes = new Int2ObjectOpenHashMap<>(); this.inventoryTypes = new Int2ObjectOpenHashMap<>();
...@@ -43,7 +45,7 @@ public class Inventory implements Iterable<GenshinItem> { ...@@ -43,7 +45,7 @@ public class Inventory implements Iterable<GenshinItem> {
this.createInventoryTab(ItemType.ITEM_FURNITURE, new MaterialInventoryTab(Grasscutter.getConfig().getGameServerOptions().InventoryLimitFurniture)); this.createInventoryTab(ItemType.ITEM_FURNITURE, new MaterialInventoryTab(Grasscutter.getConfig().getGameServerOptions().InventoryLimitFurniture));
} }
public GenshinPlayer getPlayer() { public Player getPlayer() {
return player; return player;
} }
...@@ -51,7 +53,7 @@ public class Inventory implements Iterable<GenshinItem> { ...@@ -51,7 +53,7 @@ public class Inventory implements Iterable<GenshinItem> {
return this.getPlayer().getAvatars(); return this.getPlayer().getAvatars();
} }
public Long2ObjectMap<GenshinItem> getItems() { public Long2ObjectMap<GameItem> getItems() {
return store; return store;
} }
...@@ -67,7 +69,7 @@ public class Inventory implements Iterable<GenshinItem> { ...@@ -67,7 +69,7 @@ public class Inventory implements Iterable<GenshinItem> {
this.getInventoryTypes().put(type.getValue(), tab); this.getInventoryTypes().put(type.getValue(), tab);
} }
public GenshinItem getItemByGuid(long id) { public GameItem getItemByGuid(long id) {
return this.getItems().get(id); return this.getItems().get(id);
} }
...@@ -76,19 +78,19 @@ public class Inventory implements Iterable<GenshinItem> { ...@@ -76,19 +78,19 @@ public class Inventory implements Iterable<GenshinItem> {
} }
public boolean addItem(int itemId, int count) { public boolean addItem(int itemId, int count) {
ItemData itemData = GenshinData.getItemDataMap().get(itemId); ItemData itemData = GameData.getItemDataMap().get(itemId);
if (itemData == null) { if (itemData == null) {
return false; return false;
} }
GenshinItem item = new GenshinItem(itemData, count); GameItem item = new GameItem(itemData, count);
return addItem(item); return addItem(item);
} }
public boolean addItem(GenshinItem item) { public boolean addItem(GameItem item) {
GenshinItem result = putItem(item); GameItem result = putItem(item);
if (result != null) { if (result != null) {
getPlayer().sendPacket(new PacketStoreItemChangeNotify(result)); getPlayer().sendPacket(new PacketStoreItemChangeNotify(result));
...@@ -98,34 +100,46 @@ public class Inventory implements Iterable<GenshinItem> { ...@@ -98,34 +100,46 @@ public class Inventory implements Iterable<GenshinItem> {
return false; return false;
} }
public void addItems(Collection<GenshinItem> items) { public boolean addItem(GameItem item, ActionReason reason) {
List<GenshinItem> changedItems = new LinkedList<>(); boolean result = addItem(item);
for (GenshinItem item : items) { if (result && reason != null) {
GenshinItem result = putItem(item); getPlayer().sendPacket(new PacketItemAddHintNotify(item, reason));
if (result != null) {
changedItems.add(result);
} }
return result;
} }
getPlayer().sendPacket(new PacketStoreItemChangeNotify(changedItems)); public void addItems(Collection<GameItem> items) {
this.addItems(items, null);
} }
public void addItemParams(Collection<ItemParam> items) { public void addItems(Collection<GameItem> items, ActionReason reason) {
List<GenshinItem> changedItems = new LinkedList<>(); List<GameItem> changedItems = new LinkedList<>();
for (ItemParam itemParam : items) { for (GameItem item : items) {
GenshinItem toAdd = new GenshinItem(itemParam.getItemId(), itemParam.getCount()); GameItem result = putItem(item);
GenshinItem result = putItem(toAdd);
if (result != null) { if (result != null) {
changedItems.add(result); changedItems.add(result);
} }
} }
if (changedItems.size() == 0) {
return;
}
if (reason != null) {
getPlayer().sendPacket(new PacketItemAddHintNotify(changedItems, reason));
}
getPlayer().sendPacket(new PacketStoreItemChangeNotify(changedItems)); getPlayer().sendPacket(new PacketStoreItemChangeNotify(changedItems));
} }
private synchronized GenshinItem putItem(GenshinItem item) { public void addItemParams(Collection<ItemParam> items) {
addItems(items.stream().map(param -> new GameItem(param.getItemId(), param.getCount())).toList(), null);
}
private synchronized GameItem putItem(GameItem item) {
// Dont add items that dont have a valid item definition. // Dont add items that dont have a valid item definition.
if (item.getItemData() == null) { if (item.getItemData() == null) {
return null; return null;
...@@ -149,23 +163,23 @@ public class Inventory implements Iterable<GenshinItem> { ...@@ -149,23 +163,23 @@ public class Inventory implements Iterable<GenshinItem> {
// Get avatar id // Get avatar id
int avatarId = (item.getItemId() % 1000) + 10000000; int avatarId = (item.getItemId() % 1000) + 10000000;
// Dont let people give themselves extra main characters // Dont let people give themselves extra main characters
if (avatarId == GenshinConstants.MAIN_CHARACTER_MALE || avatarId == GenshinConstants.MAIN_CHARACTER_FEMALE) { if (avatarId == GameConstants.MAIN_CHARACTER_MALE || avatarId == GameConstants.MAIN_CHARACTER_FEMALE) {
return null; return null;
} }
// Add avatar // Add avatar
AvatarData avatarData = GenshinData.getAvatarDataMap().get(avatarId); AvatarData avatarData = GameData.getAvatarDataMap().get(avatarId);
if (avatarData != null && !player.getAvatars().hasAvatar(avatarId)) { if (avatarData != null && !player.getAvatars().hasAvatar(avatarId)) {
this.getPlayer().addAvatar(new GenshinAvatar(avatarData)); this.getPlayer().addAvatar(new Avatar(avatarData));
} }
return null; return null;
} else if (item.getItemData().getMaterialType() == MaterialType.MATERIAL_FLYCLOAK) { } else if (item.getItemData().getMaterialType() == MaterialType.MATERIAL_FLYCLOAK) {
AvatarFlycloakData flycloakData = GenshinData.getAvatarFlycloakDataMap().get(item.getItemId()); AvatarFlycloakData flycloakData = GameData.getAvatarFlycloakDataMap().get(item.getItemId());
if (flycloakData != null && !player.getFlyCloakList().contains(item.getItemId())) { if (flycloakData != null && !player.getFlyCloakList().contains(item.getItemId())) {
getPlayer().addFlycloak(item.getItemId()); getPlayer().addFlycloak(item.getItemId());
} }
return null; return null;
} else if (item.getItemData().getMaterialType() == MaterialType.MATERIAL_COSTUME) { } else if (item.getItemData().getMaterialType() == MaterialType.MATERIAL_COSTUME) {
AvatarCostumeData costumeData = GenshinData.getAvatarCostumeDataItemIdMap().get(item.getItemId()); AvatarCostumeData costumeData = GameData.getAvatarCostumeDataItemIdMap().get(item.getItemId());
if (costumeData != null && !player.getCostumeList().contains(costumeData.getId())) { if (costumeData != null && !player.getCostumeList().contains(costumeData.getId())) {
getPlayer().addCostume(costumeData.getId()); getPlayer().addCostume(costumeData.getId());
} }
...@@ -176,7 +190,7 @@ public class Inventory implements Iterable<GenshinItem> { ...@@ -176,7 +190,7 @@ public class Inventory implements Iterable<GenshinItem> {
} }
return null; return null;
} else if (tab != null) { } else if (tab != null) {
GenshinItem existingItem = tab.getItemById(item.getItemId()); GameItem existingItem = tab.getItemById(item.getItemId());
if (existingItem == null) { if (existingItem == null) {
// Item type didnt exist before, we will add it to main inventory map if there is enough space // Item type didnt exist before, we will add it to main inventory map if there is enough space
if (tab.getSize() >= tab.getMaxCapacity()) { if (tab.getSize() >= tab.getMaxCapacity()) {
...@@ -199,7 +213,7 @@ public class Inventory implements Iterable<GenshinItem> { ...@@ -199,7 +213,7 @@ public class Inventory implements Iterable<GenshinItem> {
return item; return item;
} }
private synchronized void putItem(GenshinItem item, InventoryTab tab) { private synchronized void putItem(GameItem item, InventoryTab tab) {
// Set owner and guid FIRST! // Set owner and guid FIRST!
item.setOwner(getPlayer()); item.setOwner(getPlayer());
// Put in item store // Put in item store
...@@ -228,9 +242,9 @@ public class Inventory implements Iterable<GenshinItem> { ...@@ -228,9 +242,9 @@ public class Inventory implements Iterable<GenshinItem> {
} }
} }
public void removeItems(List<GenshinItem> items) { public void removeItems(List<GameItem> items) {
// TODO Bulk delete // TODO Bulk delete
for (GenshinItem item : items) { for (GameItem item : items) {
this.removeItem(item, item.getCount()); this.removeItem(item, item.getCount());
} }
} }
...@@ -240,7 +254,7 @@ public class Inventory implements Iterable<GenshinItem> { ...@@ -240,7 +254,7 @@ public class Inventory implements Iterable<GenshinItem> {
} }
public synchronized boolean removeItem(long guid, int count) { public synchronized boolean removeItem(long guid, int count) {
GenshinItem item = this.getItemByGuid(guid); GameItem item = this.getItemByGuid(guid);
if (item == null) { if (item == null) {
return false; return false;
...@@ -249,11 +263,11 @@ public class Inventory implements Iterable<GenshinItem> { ...@@ -249,11 +263,11 @@ public class Inventory implements Iterable<GenshinItem> {
return removeItem(item, count); return removeItem(item, count);
} }
public synchronized boolean removeItem(GenshinItem item) { public synchronized boolean removeItem(GameItem item) {
return removeItem(item, item.getCount()); return removeItem(item, item.getCount());
} }
public synchronized boolean removeItem(GenshinItem item, int count) { public synchronized boolean removeItem(GameItem item, int count) {
// Sanity check // Sanity check
if (count <= 0 || item == null) { if (count <= 0 || item == null) {
return false; return false;
...@@ -282,7 +296,7 @@ public class Inventory implements Iterable<GenshinItem> { ...@@ -282,7 +296,7 @@ public class Inventory implements Iterable<GenshinItem> {
return true; return true;
} }
private void deleteItem(GenshinItem item, InventoryTab tab) { private void deleteItem(GameItem item, InventoryTab tab) {
getItems().remove(item.getGuid()); getItems().remove(item.getGuid());
if (tab != null) { if (tab != null) {
tab.onRemoveItem(item); tab.onRemoveItem(item);
...@@ -290,8 +304,8 @@ public class Inventory implements Iterable<GenshinItem> { ...@@ -290,8 +304,8 @@ public class Inventory implements Iterable<GenshinItem> {
} }
public boolean equipItem(long avatarGuid, long equipGuid) { public boolean equipItem(long avatarGuid, long equipGuid) {
GenshinAvatar avatar = getPlayer().getAvatars().getAvatarByGuid(avatarGuid); Avatar avatar = getPlayer().getAvatars().getAvatarByGuid(avatarGuid);
GenshinItem item = this.getItemByGuid(equipGuid); GameItem item = this.getItemByGuid(equipGuid);
if (avatar != null && item != null) { if (avatar != null && item != null) {
return avatar.equipItem(item, true); return avatar.equipItem(item, true);
...@@ -301,7 +315,7 @@ public class Inventory implements Iterable<GenshinItem> { ...@@ -301,7 +315,7 @@ public class Inventory implements Iterable<GenshinItem> {
} }
public boolean unequipItem(long avatarGuid, int slot) { public boolean unequipItem(long avatarGuid, int slot) {
GenshinAvatar avatar = getPlayer().getAvatars().getAvatarByGuid(avatarGuid); Avatar avatar = getPlayer().getAvatars().getAvatarByGuid(avatarGuid);
EquipType equipType = EquipType.getTypeByValue(slot); EquipType equipType = EquipType.getTypeByValue(slot);
if (avatar != null && equipType != EquipType.EQUIP_WEAPON) { if (avatar != null && equipType != EquipType.EQUIP_WEAPON) {
...@@ -316,15 +330,15 @@ public class Inventory implements Iterable<GenshinItem> { ...@@ -316,15 +330,15 @@ public class Inventory implements Iterable<GenshinItem> {
} }
public void loadFromDatabase() { public void loadFromDatabase() {
List<GenshinItem> items = DatabaseHelper.getInventoryItems(getPlayer()); List<GameItem> items = DatabaseHelper.getInventoryItems(getPlayer());
for (GenshinItem item : items) { for (GameItem item : items) {
// Should never happen // Should never happen
if (item.getObjectId() == null) { if (item.getObjectId() == null) {
continue; continue;
} }
ItemData itemData = GenshinData.getItemDataMap().get(item.getItemId()); ItemData itemData = GameData.getItemDataMap().get(item.getItemId());
if (itemData == null) { if (itemData == null) {
continue; continue;
} }
...@@ -340,7 +354,7 @@ public class Inventory implements Iterable<GenshinItem> { ...@@ -340,7 +354,7 @@ public class Inventory implements Iterable<GenshinItem> {
// Equip to a character if possible // Equip to a character if possible
if (item.isEquipped()) { if (item.isEquipped()) {
GenshinAvatar avatar = getPlayer().getAvatars().getAvatarById(item.getEquipCharacter()); Avatar avatar = getPlayer().getAvatars().getAvatarById(item.getEquipCharacter());
boolean hasEquipped = false; boolean hasEquipped = false;
if (avatar != null) { if (avatar != null) {
...@@ -356,7 +370,7 @@ public class Inventory implements Iterable<GenshinItem> { ...@@ -356,7 +370,7 @@ public class Inventory implements Iterable<GenshinItem> {
} }
@Override @Override
public Iterator<GenshinItem> iterator() { public Iterator<GameItem> iterator() {
return this.getItems().values().iterator(); return this.getItems().values().iterator();
} }
} }
package emu.grasscutter.game.inventory; package emu.grasscutter.game.inventory;
public interface InventoryTab { public interface InventoryTab {
public GenshinItem getItemById(int id); public GameItem getItemById(int id);
public void onAddItem(GenshinItem item); public void onAddItem(GameItem item);
public void onRemoveItem(GenshinItem item); public void onRemoveItem(GameItem item);
public int getSize(); public int getSize();
......
...@@ -4,7 +4,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap; ...@@ -4,7 +4,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public class MaterialInventoryTab implements InventoryTab { public class MaterialInventoryTab implements InventoryTab {
private final Int2ObjectMap<GenshinItem> items; private final Int2ObjectMap<GameItem> items;
private final int maxCapacity; private final int maxCapacity;
public MaterialInventoryTab(int maxCapacity) { public MaterialInventoryTab(int maxCapacity) {
...@@ -13,17 +13,17 @@ public class MaterialInventoryTab implements InventoryTab { ...@@ -13,17 +13,17 @@ public class MaterialInventoryTab implements InventoryTab {
} }
@Override @Override
public GenshinItem getItemById(int id) { public GameItem getItemById(int id) {
return this.items.get(id); return this.items.get(id);
} }
@Override @Override
public void onAddItem(GenshinItem item) { public void onAddItem(GameItem item) {
this.items.put(item.getItemId(), item); this.items.put(item.getItemId(), item);
} }
@Override @Override
public void onRemoveItem(GenshinItem item) { public void onRemoveItem(GameItem item) {
this.items.remove(item.getItemId()); this.items.remove(item.getItemId());
} }
......
package emu.grasscutter.game.mail;
import dev.morphia.annotations.Entity;
import emu.grasscutter.game.player.Player;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
@Entity
public class Mail {
public MailContent mailContent;
public List<MailItem> itemList;
public long sendTime;
public long expireTime;
public int importance;
public boolean isRead;
public boolean isAttachmentGot;
public int stateValue;
public Mail() {
this(new MailContent(), new ArrayList<MailItem>(), (int) Instant.now().getEpochSecond() + 604800); // TODO: add expire time to send mail command
}
public Mail(MailContent mailContent, List<MailItem> itemList, long expireTime) {
this(mailContent, itemList, expireTime, 0);
}
public Mail(MailContent mailContent, List<MailItem> itemList, long expireTime, int importance) {
this(mailContent, itemList, expireTime, importance, 1);
}
public Mail(MailContent mailContent, List<MailItem> itemList, long expireTime, int importance, int state) {
this.mailContent = mailContent;
this.itemList = itemList;
this.sendTime = (int) Instant.now().getEpochSecond();
this.expireTime = expireTime;
this.importance = importance; // Starred mail, 0 = No star, 1 = Star.
this.isRead = false;
this.isAttachmentGot = false;
this.stateValue = state; // Different mailboxes, 1 = Default, 3 = Gift-box.
}
@Entity
public static class MailContent {
public String title;
public String content;
public String sender;
public MailContent() {
this.title = "";
this.content = "loading...";
this.sender = "loading";
}
public MailContent(String title, String content) {
this(title, content, "Server");
}
public MailContent(String title, String content, Player sender) {
this(title, content, sender.getNickname());
}
public MailContent(String title, String content, String sender) {
this.title = title;
this.content = content;
this.sender = sender;
}
}
@Entity
public static class MailItem {
public int itemId;
public int itemCount;
public int itemLevel;
public MailItem() {
this.itemId = 11101;
this.itemCount = 1;
this.itemLevel = 1;
}
public MailItem(int itemId) {
this(itemId, 1);
}
public MailItem(int itemId, int itemCount) { this(itemId, itemCount, 1); }
public MailItem(int itemId, int itemCount, int itemLevel) {
this.itemId = itemId;
this.itemCount = itemCount;
this.itemLevel = itemLevel;
}
}
}
package emu.grasscutter.game.managers; package emu.grasscutter.game.managers;
import emu.grasscutter.command.CommandMap; import emu.grasscutter.command.CommandMap;
import emu.grasscutter.game.GenshinPlayer; import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.GenshinPacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.server.game.GameServer; import emu.grasscutter.server.game.GameServer;
import emu.grasscutter.server.packet.send.PacketPlayerChatNotify; import emu.grasscutter.server.packet.send.PacketPlayerChatNotify;
import emu.grasscutter.server.packet.send.PacketPrivateChatNotify; import emu.grasscutter.server.packet.send.PacketPrivateChatNotify;
...@@ -23,7 +23,7 @@ public class ChatManager { ...@@ -23,7 +23,7 @@ public class ChatManager {
return server; return server;
} }
public void sendPrivateMessage(GenshinPlayer player, int targetUid, String message) { public void sendPrivateMessage(Player player, int targetUid, String message) {
// Sanity checks // Sanity checks
if (message == null || message.length() == 0) { if (message == null || message.length() == 0) {
return; return;
...@@ -36,35 +36,35 @@ public class ChatManager { ...@@ -36,35 +36,35 @@ public class ChatManager {
} }
// Get target // Get target
GenshinPlayer target = getServer().getPlayerByUid(targetUid); Player target = getServer().getPlayerByUid(targetUid);
if (target == null) { if (target == null) {
return; return;
} }
// Create chat packet // Create chat packet
GenshinPacket packet = new PacketPrivateChatNotify(player.getUid(), target.getUid(), message); BasePacket packet = new PacketPrivateChatNotify(player.getUid(), target.getUid(), message);
player.sendPacket(packet); player.sendPacket(packet);
target.sendPacket(packet); target.sendPacket(packet);
} }
public void sendPrivateMessage(GenshinPlayer player, int targetUid, int emote) { public void sendPrivateMessage(Player player, int targetUid, int emote) {
// Get target // Get target
GenshinPlayer target = getServer().getPlayerByUid(targetUid); Player target = getServer().getPlayerByUid(targetUid);
if (target == null) { if (target == null) {
return; return;
} }
// Create chat packet // Create chat packet
GenshinPacket packet = new PacketPrivateChatNotify(player.getUid(), target.getUid(), emote); BasePacket packet = new PacketPrivateChatNotify(player.getUid(), target.getUid(), emote);
player.sendPacket(packet); player.sendPacket(packet);
target.sendPacket(packet); target.sendPacket(packet);
} }
public void sendTeamMessage(GenshinPlayer player, int channel, String message) { public void sendTeamMessage(Player player, int channel, String message) {
// Sanity checks // Sanity checks
if (message == null || message.length() == 0) { if (message == null || message.length() == 0) {
return; return;
...@@ -80,7 +80,7 @@ public class ChatManager { ...@@ -80,7 +80,7 @@ public class ChatManager {
player.getWorld().broadcastPacket(new PacketPlayerChatNotify(player, channel, message)); player.getWorld().broadcastPacket(new PacketPlayerChatNotify(player, channel, message));
} }
public void sendTeamMessage(GenshinPlayer player, int channel, int icon) { public void sendTeamMessage(Player player, int channel, int icon) {
// Create and send chat packet // Create and send chat packet
player.getWorld().broadcastPacket(new PacketPlayerChatNotify(player, channel, icon)); player.getWorld().broadcastPacket(new PacketPlayerChatNotify(player, channel, icon));
} }
......
package emu.grasscutter.game.managers; package emu.grasscutter.game.managers;
import emu.grasscutter.game.CoopRequest; import emu.grasscutter.game.CoopRequest;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.GenshinPlayer.SceneLoadState;
import emu.grasscutter.game.props.EnterReason; import emu.grasscutter.game.props.EnterReason;
import emu.grasscutter.game.world.World;
import emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType; import emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType;
import emu.grasscutter.net.proto.PlayerApplyEnterMpReasonOuterClass.PlayerApplyEnterMpReason; import emu.grasscutter.net.proto.PlayerApplyEnterMpReasonOuterClass.PlayerApplyEnterMpReason;
import emu.grasscutter.game.World; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.player.Player.SceneLoadState;
import emu.grasscutter.net.proto.PlayerApplyEnterMpResultNotifyOuterClass; import emu.grasscutter.net.proto.PlayerApplyEnterMpResultNotifyOuterClass;
import emu.grasscutter.server.game.GameServer; import emu.grasscutter.server.game.GameServer;
import emu.grasscutter.server.packet.send.PacketPlayerApplyEnterMpNotify; import emu.grasscutter.server.packet.send.PacketPlayerApplyEnterMpNotify;
...@@ -24,8 +24,8 @@ public class MultiplayerManager { ...@@ -24,8 +24,8 @@ public class MultiplayerManager {
return server; return server;
} }
public void applyEnterMp(GenshinPlayer player, int targetUid) { public void applyEnterMp(Player player, int targetUid) {
GenshinPlayer target = getServer().getPlayerByUid(targetUid); Player target = getServer().getPlayerByUid(targetUid);
if (target == null) { if (target == null) {
player.sendPacket(new PacketPlayerApplyEnterMpResultNotify(targetUid, "", false, PlayerApplyEnterMpResultNotifyOuterClass.PlayerApplyEnterMpResultNotify.Reason.PLAYER_CANNOT_ENTER_MP)); player.sendPacket(new PacketPlayerApplyEnterMpResultNotify(targetUid, "", false, PlayerApplyEnterMpResultNotifyOuterClass.PlayerApplyEnterMpResultNotify.Reason.PLAYER_CANNOT_ENTER_MP));
return; return;
...@@ -59,7 +59,7 @@ public class MultiplayerManager { ...@@ -59,7 +59,7 @@ public class MultiplayerManager {
target.sendPacket(new PacketPlayerApplyEnterMpNotify(player)); target.sendPacket(new PacketPlayerApplyEnterMpNotify(player));
} }
public void applyEnterMpReply(GenshinPlayer hostPlayer, int applyUid, boolean isAgreed) { public void applyEnterMpReply(Player hostPlayer, int applyUid, boolean isAgreed) {
// Checks // Checks
CoopRequest request = hostPlayer.getCoopRequests().get(applyUid); CoopRequest request = hostPlayer.getCoopRequests().get(applyUid);
if (request == null || request.isExpired()) { if (request == null || request.isExpired()) {
...@@ -67,7 +67,7 @@ public class MultiplayerManager { ...@@ -67,7 +67,7 @@ public class MultiplayerManager {
} }
// Remove now that we are handling it // Remove now that we are handling it
GenshinPlayer requester = request.getRequester(); Player requester = request.getRequester();
hostPlayer.getCoopRequests().remove(applyUid); hostPlayer.getCoopRequests().remove(applyUid);
// Sanity checks - Dont let the requesting player join if they are already in multiplayer // Sanity checks - Dont let the requesting player join if they are already in multiplayer
...@@ -108,14 +108,14 @@ public class MultiplayerManager { ...@@ -108,14 +108,14 @@ public class MultiplayerManager {
requester.sendPacket(new PacketPlayerEnterSceneNotify(requester, hostPlayer, EnterType.ENTER_OTHER, EnterReason.TeamJoin, hostPlayer.getScene().getId(), hostPlayer.getPos())); requester.sendPacket(new PacketPlayerEnterSceneNotify(requester, hostPlayer, EnterType.ENTER_OTHER, EnterReason.TeamJoin, hostPlayer.getScene().getId(), hostPlayer.getPos()));
} }
public boolean leaveCoop(GenshinPlayer player) { public boolean leaveCoop(Player player) {
// Make sure player's world is multiplayer // Make sure player's world is multiplayer
if (!player.getWorld().isMultiplayer()) { if (!player.getWorld().isMultiplayer()) {
return false; return false;
} }
// Make sure everyone's scene is loaded // Make sure everyone's scene is loaded
for (GenshinPlayer p : player.getWorld().getPlayers()) { for (Player p : player.getWorld().getPlayers()) {
if (p.getSceneLoadState() != SceneLoadState.LOADED) { if (p.getSceneLoadState() != SceneLoadState.LOADED) {
return false; return false;
} }
...@@ -131,14 +131,14 @@ public class MultiplayerManager { ...@@ -131,14 +131,14 @@ public class MultiplayerManager {
return true; return true;
} }
public boolean kickPlayer(GenshinPlayer player, int targetUid) { public boolean kickPlayer(Player player, int targetUid) {
// Make sure player's world is multiplayer and that player is owner // Make sure player's world is multiplayer and that player is owner
if (!player.getWorld().isMultiplayer() || player.getWorld().getHost() != player) { if (!player.getWorld().isMultiplayer() || player.getWorld().getHost() != player) {
return false; return false;
} }
// Get victim and sanity checks // Get victim and sanity checks
GenshinPlayer victim = player.getServer().getPlayerByUid(targetUid); Player victim = player.getServer().getPlayerByUid(targetUid);
if (victim == null || victim == player) { if (victim == null || victim == player) {
return false; return false;
......
package emu.grasscutter.game; package emu.grasscutter.game.player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.proto.ForwardTypeOuterClass.ForwardType; import emu.grasscutter.net.proto.ForwardTypeOuterClass.ForwardType;
public class InvokeHandler<T> { public class InvokeHandler<T> {
private final List<T> entryListForwardAll; private final List<T> entryListForwardAll;
private final List<T> entryListForwardAllExceptCur; private final List<T> entryListForwardAllExceptCur;
private final List<T> entryListForwardHost; private final List<T> entryListForwardHost;
private final Class<? extends GenshinPacket> packetClass; private final Class<? extends BasePacket> packetClass;
public InvokeHandler(Class<? extends GenshinPacket> packetClass) { public InvokeHandler(Class<? extends BasePacket> packetClass) {
this.entryListForwardAll = new ArrayList<>(); this.entryListForwardAll = new ArrayList<>();
this.entryListForwardAllExceptCur = new ArrayList<>(); this.entryListForwardAllExceptCur = new ArrayList<>();
this.entryListForwardHost = new ArrayList<>(); this.entryListForwardHost = new ArrayList<>();
...@@ -28,7 +29,7 @@ public class InvokeHandler<T> { ...@@ -28,7 +29,7 @@ public class InvokeHandler<T> {
} }
} }
public synchronized void update(GenshinPlayer player) { public synchronized void update(Player player) {
if (player.getWorld() == null) { if (player.getWorld() == null) {
this.entryListForwardAll.clear(); this.entryListForwardAll.clear();
this.entryListForwardAllExceptCur.clear(); this.entryListForwardAllExceptCur.clear();
...@@ -38,17 +39,17 @@ public class InvokeHandler<T> { ...@@ -38,17 +39,17 @@ public class InvokeHandler<T> {
try { try {
if (entryListForwardAll.size() > 0) { if (entryListForwardAll.size() > 0) {
GenshinPacket packet = packetClass.getDeclaredConstructor(List.class).newInstance(this.entryListForwardAll); BasePacket packet = packetClass.getDeclaredConstructor(List.class).newInstance(this.entryListForwardAll);
player.getScene().broadcastPacket(packet); player.getScene().broadcastPacket(packet);
this.entryListForwardAll.clear(); this.entryListForwardAll.clear();
} }
if (entryListForwardAllExceptCur.size() > 0) { if (entryListForwardAllExceptCur.size() > 0) {
GenshinPacket packet = packetClass.getDeclaredConstructor(List.class).newInstance(this.entryListForwardAllExceptCur); BasePacket packet = packetClass.getDeclaredConstructor(List.class).newInstance(this.entryListForwardAllExceptCur);
player.getScene().broadcastPacketToOthers(player, packet); player.getScene().broadcastPacketToOthers(player, packet);
this.entryListForwardAllExceptCur.clear(); this.entryListForwardAllExceptCur.clear();
} }
if (entryListForwardHost.size() > 0) { if (entryListForwardHost.size() > 0) {
GenshinPacket packet = packetClass.getDeclaredConstructor(List.class).newInstance(this.entryListForwardHost); BasePacket packet = packetClass.getDeclaredConstructor(List.class).newInstance(this.entryListForwardHost);
player.getWorld().getHost().sendPacket(packet); player.getWorld().getHost().sendPacket(packet);
this.entryListForwardHost.clear(); this.entryListForwardHost.clear();
} }
......
package emu.grasscutter.game; package emu.grasscutter.game.player;
import java.time.Instant;
import java.util.*;
import dev.morphia.annotations.*; import dev.morphia.annotations.*;
import emu.grasscutter.GenshinConstants; import emu.grasscutter.GameConstants;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GenshinData; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.def.PlayerLevelData; import emu.grasscutter.data.def.PlayerLevelData;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.avatar.AvatarProfileData; import emu.grasscutter.game.avatar.AvatarProfileData;
import emu.grasscutter.game.avatar.AvatarStorage; import emu.grasscutter.game.avatar.AvatarStorage;
import emu.grasscutter.game.avatar.GenshinAvatar; import emu.grasscutter.game.Account;
import emu.grasscutter.game.CoopRequest;
import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.entity.EntityItem; import emu.grasscutter.game.entity.EntityItem;
import emu.grasscutter.game.entity.GenshinEntity; import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.game.friends.FriendsList; import emu.grasscutter.game.friends.FriendsList;
import emu.grasscutter.game.friends.PlayerProfile; import emu.grasscutter.game.friends.PlayerProfile;
import emu.grasscutter.game.gacha.PlayerGachaInfo; import emu.grasscutter.game.gacha.PlayerGachaInfo;
import emu.grasscutter.game.inventory.GenshinItem; import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.inventory.Inventory; import emu.grasscutter.game.inventory.Inventory;
import emu.grasscutter.game.player.PlayerBirthday; import emu.grasscutter.game.mail.Mail;
import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.game.props.PlayerProperty; import emu.grasscutter.game.props.PlayerProperty;
import emu.grasscutter.net.packet.GenshinPacket; import emu.grasscutter.game.world.Scene;
import emu.grasscutter.game.world.World;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry; import emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry;
import emu.grasscutter.net.proto.CombatInvokeEntryOuterClass.CombatInvokeEntry; import emu.grasscutter.net.proto.CombatInvokeEntryOuterClass.CombatInvokeEntry;
import emu.grasscutter.net.proto.HeadImageOuterClass.HeadImage; import emu.grasscutter.net.proto.HeadImageOuterClass.HeadImage;
...@@ -42,7 +50,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; ...@@ -42,7 +50,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.util.*; import java.util.*;
@Entity(value = "players", useDiscriminator = false) @Entity(value = "players", useDiscriminator = false)
public class GenshinPlayer { public class Player {
@Id private int id; @Id private int id;
@Indexed(options = @IndexOptions(unique = true)) private String accountId; @Indexed(options = @IndexOptions(unique = true)) private String accountId;
...@@ -63,7 +71,7 @@ public class GenshinPlayer { ...@@ -63,7 +71,7 @@ public class GenshinPlayer {
@Transient private long nextGuid = 0; @Transient private long nextGuid = 0;
@Transient private int peerId; @Transient private int peerId;
@Transient private World world; @Transient private World world;
@Transient private GenshinScene scene; @Transient private Scene scene;
@Transient private GameSession session; @Transient private GameSession session;
@Transient private AvatarStorage avatars; @Transient private AvatarStorage avatars;
@Transient private Inventory inventory; @Transient private Inventory inventory;
...@@ -72,10 +80,10 @@ public class GenshinPlayer { ...@@ -72,10 +80,10 @@ public class GenshinPlayer {
private TeamManager teamManager; private TeamManager teamManager;
private PlayerGachaInfo gachaInfo; private PlayerGachaInfo gachaInfo;
private PlayerProfile playerProfile; private PlayerProfile playerProfile;
private MpSettingType mpSetting = MpSettingType.MP_SETTING_ENTER_AFTER_APPLY;
private boolean showAvatar; private boolean showAvatar;
private ArrayList<AvatarProfileData> shownAvatars; private ArrayList<AvatarProfileData> shownAvatars;
private Set<Integer> rewardedLevels; private Set<Integer> rewardedLevels;
private ArrayList<Mail> mail;
private int sceneId; private int sceneId;
private int regionId; private int regionId;
...@@ -100,7 +108,7 @@ public class GenshinPlayer { ...@@ -100,7 +108,7 @@ public class GenshinPlayer {
@Deprecated @Deprecated
@SuppressWarnings({"rawtypes", "unchecked"}) // Morphia only! @SuppressWarnings({"rawtypes", "unchecked"}) // Morphia only!
public GenshinPlayer() { public Player() {
this.inventory = new Inventory(this); this.inventory = new Inventory(this);
this.avatars = new AvatarStorage(this); this.avatars = new AvatarStorage(this);
this.friendsList = new FriendsList(this); this.friendsList = new FriendsList(this);
...@@ -119,6 +127,8 @@ public class GenshinPlayer { ...@@ -119,6 +127,8 @@ public class GenshinPlayer {
this.flyCloakList = new HashSet<>(); this.flyCloakList = new HashSet<>();
this.costumeList = new HashSet<>(); this.costumeList = new HashSet<>();
this.mail = new ArrayList<>();
this.setSceneId(3); this.setSceneId(3);
this.setRegionId(1); this.setRegionId(1);
this.sceneState = SceneLoadState.NONE; this.sceneState = SceneLoadState.NONE;
...@@ -134,7 +144,7 @@ public class GenshinPlayer { ...@@ -134,7 +144,7 @@ public class GenshinPlayer {
} }
// On player creation // On player creation
public GenshinPlayer(GameSession session) { public Player(GameSession session) {
this(); this();
this.account = session.getAccount(); this.account = session.getAccount();
this.accountId = this.getAccount().getId(); this.accountId = this.getAccount().getId();
...@@ -153,7 +163,7 @@ public class GenshinPlayer { ...@@ -153,7 +163,7 @@ public class GenshinPlayer {
this.setProperty(PlayerProperty.PROP_PLAYER_RESIN, 160); this.setProperty(PlayerProperty.PROP_PLAYER_RESIN, 160);
this.getFlyCloakList().add(140001); this.getFlyCloakList().add(140001);
this.getNameCardList().add(210001); this.getNameCardList().add(210001);
this.getPos().set(GenshinConstants.START_POSITION); this.getPos().set(GameConstants.START_POSITION);
this.getRotation().set(0, 307, 0); this.getRotation().set(0, 307, 0);
} }
...@@ -165,7 +175,7 @@ public class GenshinPlayer { ...@@ -165,7 +175,7 @@ public class GenshinPlayer {
this.id = id; this.id = id;
} }
public long getNextGenshinGuid() { public long getNextGameGuid() {
long nextId = ++this.nextGuid; long nextId = ++this.nextGuid;
return ((long) this.getUid() << 32) + nextId; return ((long) this.getUid() << 32) + nextId;
} }
...@@ -203,11 +213,11 @@ public class GenshinPlayer { ...@@ -203,11 +213,11 @@ public class GenshinPlayer {
this.world = world; this.world = world;
} }
public synchronized GenshinScene getScene() { public synchronized Scene getScene() {
return scene; return scene;
} }
public synchronized void setScene(GenshinScene scene) { public synchronized void setScene(Scene scene) {
this.scene = scene; this.scene = scene;
} }
...@@ -262,6 +272,11 @@ public class GenshinPlayer { ...@@ -262,6 +272,11 @@ public class GenshinPlayer {
return this.getProperty(PlayerProperty.PROP_PLAYER_WORLD_LEVEL); return this.getProperty(PlayerProperty.PROP_PLAYER_WORLD_LEVEL);
} }
public void setWorldLevel(int level) {
this.setProperty(PlayerProperty.PROP_PLAYER_WORLD_LEVEL, level);
this.sendPacket(new PacketPlayerPropNotify(this, PlayerProperty.PROP_PLAYER_WORLD_LEVEL));
}
public int getPrimogems() { public int getPrimogems() {
return this.getProperty(PlayerProperty.PROP_PLAYER_HCOIN); return this.getProperty(PlayerProperty.PROP_PLAYER_HCOIN);
} }
...@@ -281,7 +296,7 @@ public class GenshinPlayer { ...@@ -281,7 +296,7 @@ public class GenshinPlayer {
} }
private int getExpRequired(int level) { private int getExpRequired(int level) {
PlayerLevelData levelData = GenshinData.getPlayerLevelDataMap().get(level); PlayerLevelData levelData = GameData.getPlayerLevelDataMap().get(level);
return levelData != null ? levelData.getExp() : 0; return levelData != null ? levelData.getExp() : 0;
} }
...@@ -374,7 +389,7 @@ public class GenshinPlayer { ...@@ -374,7 +389,7 @@ public class GenshinPlayer {
} }
public MpSettingType getMpSetting() { public MpSettingType getMpSetting() {
return mpSetting; return MpSettingType.MP_SETTING_ENTER_AFTER_APPLY; // TEMP
} }
public synchronized Int2ObjectMap<CoopRequest> getCoopRequests() { public synchronized Int2ObjectMap<CoopRequest> getCoopRequests() {
...@@ -393,10 +408,6 @@ public class GenshinPlayer { ...@@ -393,10 +408,6 @@ public class GenshinPlayer {
return clientAbilityInitFinishHandler; return clientAbilityInitFinishHandler;
} }
public void setMpSetting(MpSettingType mpSetting) {
this.mpSetting = mpSetting;
}
public AvatarStorage getAvatars() { public AvatarStorage getAvatars() {
return avatars; return avatars;
} }
...@@ -539,9 +550,9 @@ public class GenshinPlayer { ...@@ -539,9 +550,9 @@ public class GenshinPlayer {
} }
public void rechargeMoonCard() { public void rechargeMoonCard() {
LinkedList<GenshinItem> items = new LinkedList<GenshinItem>(); LinkedList<GameItem> items = new LinkedList<GameItem>();
for (int i = 0; i < 300; i++) { for (int i = 0; i < 300; i++) {
items.add(new GenshinItem(203)); items.add(new GameItem(203));
} }
inventory.addItems(items); inventory.addItems(items);
if (!moonCard) { if (!moonCard) {
...@@ -576,9 +587,8 @@ public class GenshinPlayer { ...@@ -576,9 +587,8 @@ public class GenshinPlayer {
} }
moonCardGetTimes.add(now); moonCardGetTimes.add(now);
addMoonCardDays(1); addMoonCardDays(1);
GenshinItem genshinItem = new GenshinItem(201, 90); GameItem item = new GameItem(201, 90);
getInventory().addItem(genshinItem); getInventory().addItem(item, ActionReason.BlessingRedeemReward);
session.send(new PacketItemAddHintNotify(genshinItem, ActionReason.BlessingRedeemReward));
session.send(new PacketCardProductRewardNotify(getMoonCardRemainDays())); session.send(new PacketCardProductRewardNotify(getMoonCardRemainDays()));
} }
...@@ -598,29 +608,19 @@ public class GenshinPlayer { ...@@ -598,29 +608,19 @@ public class GenshinPlayer {
this.hasSentAvatarDataNotify = hasSentAvatarDataNotify; this.hasSentAvatarDataNotify = hasSentAvatarDataNotify;
} }
public void addAvatar(GenshinAvatar avatar) { public void addAvatar(Avatar avatar) {
boolean result = getAvatars().addAvatar(avatar); boolean result = getAvatars().addAvatar(avatar);
if (result) { if (result) {
// Add starting weapon // Add starting weapon
getAvatars().addStartingWeapon(avatar); getAvatars().addStartingWeapon(avatar);
// Try adding to team if possible
//List<EntityAvatar> currentTeam = this.getTeamManager().getCurrentTeam();
boolean addedToTeam = false;
/*
if (currentTeam.size() <= GenshinConstants.MAX_AVATARS_IN_TEAM) {
addedToTeam = currentTeam
}
*/
// Done // Done
if (hasSentAvatarDataNotify()) { if (hasSentAvatarDataNotify()) {
// Recalc stats // Recalc stats
avatar.recalcStats(); avatar.recalcStats();
// Packet // Packet
sendPacket(new PacketAvatarAddNotify(avatar, addedToTeam)); sendPacket(new PacketAvatarAddNotify(avatar, false));
} }
} else { } else {
// Failed adding avatar // Failed adding avatar
...@@ -653,7 +653,7 @@ public class GenshinPlayer { ...@@ -653,7 +653,7 @@ public class GenshinPlayer {
} }
public void dropMessage(Object message) { public void dropMessage(Object message) {
this.sendPacket(new PacketPrivateChatNotify(GenshinConstants.SERVER_CONSOLE_UID, getUid(), message.toString())); this.sendPacket(new PacketPrivateChatNotify(GameConstants.SERVER_CONSOLE_UID, getUid(), message.toString()));
} }
/** /**
...@@ -662,12 +662,53 @@ public class GenshinPlayer { ...@@ -662,12 +662,53 @@ public class GenshinPlayer {
* @param sender The sender of the message. * @param sender The sender of the message.
* @param message The message to send. * @param message The message to send.
*/ */
public void sendMessage(GenshinPlayer sender, Object message) { public void sendMessage(Player sender, Object message) {
this.sendPacket(new PacketPrivateChatNotify(sender.getUid(), this.getUid(), message.toString())); this.sendPacket(new PacketPrivateChatNotify(sender.getUid(), this.getUid(), message.toString()));
} }
// ---------------------MAIL------------------------
public List<Mail> getAllMail() { return this.mail; }
public void sendMail(Mail message) {
this.mail.add(message);
this.save();
Grasscutter.getLogger().info("Mail sent to user [" + this.getUid() + ":" + this.getNickname() + "]!");
if(this.isOnline()) {
this.sendPacket(new PacketMailChangeNotify(this, message));
} // TODO: setup a way for the mail notification to show up when someone receives mail when they were offline
}
public boolean deleteMail(int mailId) {
Mail message = getMail(mailId);
if(message != null) {
int index = getMailId(message);
message.expireTime = (int) Instant.now().getEpochSecond(); // Just set the mail as expired for now. I don't want to implement a counter specifically for an account...
this.replaceMailByIndex(index, message);
return true;
}
return false;
}
public Mail getMail(int index) { return this.mail.get(index); }
public int getMailId(Mail message) {
return this.mail.indexOf(message);
}
public boolean replaceMailByIndex(int index, Mail message) {
if(getMail(index) != null) {
this.mail.set(index, message);
this.save();
return true;
} else {
return false;
}
}
public void interactWith(int gadgetEntityId) { public void interactWith(int gadgetEntityId) {
GenshinEntity entity = getScene().getEntityById(gadgetEntityId); GameEntity entity = getScene().getEntityById(gadgetEntityId);
if (entity == null) { if (entity == null) {
return; return;
...@@ -680,12 +721,11 @@ public class GenshinPlayer { ...@@ -680,12 +721,11 @@ public class GenshinPlayer {
if (entity instanceof EntityItem) { if (entity instanceof EntityItem) {
// Pick item // Pick item
EntityItem drop = (EntityItem) entity; EntityItem drop = (EntityItem) entity;
GenshinItem item = new GenshinItem(drop.getItemData(), drop.getCount()); GameItem item = new GameItem(drop.getItemData(), drop.getCount());
// Add to inventory // Add to inventory
boolean success = getInventory().addItem(item); boolean success = getInventory().addItem(item, ActionReason.SubfieldDrop);
if (success) { if (success) {
this.sendPacket(new PacketGadgetInteractRsp(drop, InteractType.INTERACT_PICK_ITEM)); this.sendPacket(new PacketGadgetInteractRsp(drop, InteractType.INTERACT_PICK_ITEM));
this.sendPacket(new PacketItemAddHintNotify(item, ActionReason.SubfieldDrop));
} }
} }
...@@ -700,7 +740,7 @@ public class GenshinPlayer { ...@@ -700,7 +740,7 @@ public class GenshinPlayer {
} }
public void sendPacket(GenshinPacket packet) { public void sendPacket(BasePacket packet) {
if (this.hasSentAvatarDataNotify) { if (this.hasSentAvatarDataNotify) {
this.getSession().send(packet); this.getSession().send(packet);
} }
...@@ -829,7 +869,7 @@ public class GenshinPlayer { ...@@ -829,7 +869,7 @@ public class GenshinPlayer {
// Check if player object exists in server // Check if player object exists in server
// TODO - optimize // TODO - optimize
GenshinPlayer exists = this.getServer().getPlayerByUid(getUid()); Player exists = this.getServer().getPlayerByUid(getUid());
if (exists != null) { if (exists != null) {
exists.getSession().close(); exists.getSession().close();
} }
......
package emu.grasscutter.game; package emu.grasscutter.game.player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import dev.morphia.annotations.Entity; import dev.morphia.annotations.Entity;
import emu.grasscutter.GenshinConstants; import emu.grasscutter.GameConstants;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.avatar.GenshinAvatar; import emu.grasscutter.game.avatar.Avatar;
@Entity @Entity
public class TeamInfo { public class TeamInfo {
...@@ -34,11 +34,11 @@ public class TeamInfo { ...@@ -34,11 +34,11 @@ public class TeamInfo {
return avatars.size(); return avatars.size();
} }
public boolean contains(GenshinAvatar avatar) { public boolean contains(Avatar avatar) {
return getAvatars().contains(avatar.getAvatarId()); return getAvatars().contains(avatar.getAvatarId());
} }
public boolean addAvatar(GenshinAvatar avatar) { public boolean addAvatar(Avatar avatar) {
if (size() >= Grasscutter.getConfig().getGameServerOptions().MaxAvatarsInTeam || contains(avatar)) { if (size() >= Grasscutter.getConfig().getGameServerOptions().MaxAvatarsInTeam || contains(avatar)) {
return false; return false;
} }
......
package emu.grasscutter.game; package emu.grasscutter.game.player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -10,16 +10,17 @@ import java.util.Set; ...@@ -10,16 +10,17 @@ import java.util.Set;
import dev.morphia.annotations.Entity; import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Transient; import dev.morphia.annotations.Transient;
import emu.grasscutter.GenshinConstants; import emu.grasscutter.GameConstants;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.def.AvatarSkillDepotData; import emu.grasscutter.data.def.AvatarSkillDepotData;
import emu.grasscutter.game.avatar.GenshinAvatar; import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.entity.EntityGadget; import emu.grasscutter.game.entity.EntityGadget;
import emu.grasscutter.game.props.ElementType; import emu.grasscutter.game.props.ElementType;
import emu.grasscutter.game.props.EnterReason; import emu.grasscutter.game.props.EnterReason;
import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.net.packet.GenshinPacket; import emu.grasscutter.game.world.World;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType; import emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType;
import emu.grasscutter.net.proto.MotionStateOuterClass.MotionState; import emu.grasscutter.net.proto.MotionStateOuterClass.MotionState;
...@@ -44,7 +45,7 @@ import it.unimi.dsi.fastutil.ints.IntSet; ...@@ -44,7 +45,7 @@ import it.unimi.dsi.fastutil.ints.IntSet;
@Entity @Entity
public class TeamManager { public class TeamManager {
@Transient private GenshinPlayer player; @Transient private Player player;
private Map<Integer, TeamInfo> teams; private Map<Integer, TeamInfo> teams;
private int currentTeamIndex; private int currentTeamIndex;
...@@ -65,18 +66,18 @@ public class TeamManager { ...@@ -65,18 +66,18 @@ public class TeamManager {
this.teamResonancesConfig = new IntOpenHashSet(); this.teamResonancesConfig = new IntOpenHashSet();
} }
public TeamManager(GenshinPlayer player) { public TeamManager(Player player) {
this(); this();
this.player = player; this.player = player;
this.teams = new HashMap<>(); this.teams = new HashMap<>();
this.currentTeamIndex = 1; this.currentTeamIndex = 1;
for (int i = 1; i <= GenshinConstants.MAX_TEAMS; i++) { for (int i = 1; i <= GameConstants.MAX_TEAMS; i++) {
this.teams.put(i, new TeamInfo()); this.teams.put(i, new TeamInfo());
} }
} }
public GenshinPlayer getPlayer() { public Player getPlayer() {
return player; return player;
} }
...@@ -84,7 +85,7 @@ public class TeamManager { ...@@ -84,7 +85,7 @@ public class TeamManager {
return player.getWorld(); return player.getWorld();
} }
public void setPlayer(GenshinPlayer player) { public void setPlayer(Player player) {
this.player = player; this.player = player;
} }
...@@ -207,7 +208,7 @@ public class TeamManager { ...@@ -207,7 +208,7 @@ public class TeamManager {
} }
} }
public void updateTeamEntities(GenshinPacket responsePacket) { public void updateTeamEntities(BasePacket responsePacket) {
// Sanity check - Should never happen // Sanity check - Should never happen
if (this.getCurrentTeamInfo().getAvatars().size() <= 0) { if (this.getCurrentTeamInfo().getAvatars().size() <= 0) {
return; return;
...@@ -287,9 +288,9 @@ public class TeamManager { ...@@ -287,9 +288,9 @@ public class TeamManager {
} }
// Set team data // Set team data
LinkedHashSet<GenshinAvatar> newTeam = new LinkedHashSet<>(); LinkedHashSet<Avatar> newTeam = new LinkedHashSet<>();
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
GenshinAvatar avatar = getPlayer().getAvatars().getAvatarByGuid(list.get(i)); Avatar avatar = getPlayer().getAvatars().getAvatarByGuid(list.get(i));
if (avatar == null || newTeam.contains(avatar)) { if (avatar == null || newTeam.contains(avatar)) {
// Should never happen // Should never happen
return; return;
...@@ -299,7 +300,7 @@ public class TeamManager { ...@@ -299,7 +300,7 @@ public class TeamManager {
// Clear current team info and add avatars from our new team // Clear current team info and add avatars from our new team
teamInfo.getAvatars().clear(); teamInfo.getAvatars().clear();
for (GenshinAvatar avatar : newTeam) { for (Avatar avatar : newTeam) {
teamInfo.addAvatar(avatar); teamInfo.addAvatar(avatar);
} }
...@@ -323,9 +324,9 @@ public class TeamManager { ...@@ -323,9 +324,9 @@ public class TeamManager {
TeamInfo teamInfo = this.getMpTeam(); TeamInfo teamInfo = this.getMpTeam();
// Set team data // Set team data
LinkedHashSet<GenshinAvatar> newTeam = new LinkedHashSet<>(); LinkedHashSet<Avatar> newTeam = new LinkedHashSet<>();
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
GenshinAvatar avatar = getPlayer().getAvatars().getAvatarByGuid(list.get(i)); Avatar avatar = getPlayer().getAvatars().getAvatarByGuid(list.get(i));
if (avatar == null || newTeam.contains(avatar)) { if (avatar == null || newTeam.contains(avatar)) {
// Should never happen // Should never happen
return; return;
...@@ -335,7 +336,7 @@ public class TeamManager { ...@@ -335,7 +336,7 @@ public class TeamManager {
// Clear current team info and add avatars from our new team // Clear current team info and add avatars from our new team
teamInfo.getAvatars().clear(); teamInfo.getAvatars().clear();
for (GenshinAvatar avatar : newTeam) { for (Avatar avatar : newTeam) {
teamInfo.addAvatar(avatar); teamInfo.addAvatar(avatar);
} }
...@@ -437,7 +438,7 @@ public class TeamManager { ...@@ -437,7 +438,7 @@ public class TeamManager {
getPlayer().sendPacket(new PacketAvatarDieAnimationEndRsp(deadAvatar.getId(), 0)); getPlayer().sendPacket(new PacketAvatarDieAnimationEndRsp(deadAvatar.getId(), 0));
} }
public boolean reviveAvatar(GenshinAvatar avatar) { public boolean reviveAvatar(Avatar avatar) {
for (EntityAvatar entity : getActiveTeam()) { for (EntityAvatar entity : getActiveTeam()) {
if (entity.getAvatar() == avatar) { if (entity.getAvatar() == avatar) {
if (entity.isAlive()) { if (entity.isAlive()) {
...@@ -476,14 +477,14 @@ public class TeamManager { ...@@ -476,14 +477,14 @@ public class TeamManager {
} }
// Teleport player // Teleport player
getPlayer().sendPacket(new PacketPlayerEnterSceneNotify(getPlayer(), EnterType.ENTER_SELF, EnterReason.Revival, 3, GenshinConstants.START_POSITION)); getPlayer().sendPacket(new PacketPlayerEnterSceneNotify(getPlayer(), EnterType.ENTER_SELF, EnterReason.Revival, 3, GameConstants.START_POSITION));
// Set player position // Set player position
player.setSceneId(3); player.setSceneId(3);
player.getPos().set(GenshinConstants.START_POSITION); player.getPos().set(GameConstants.START_POSITION);
// Packets // Packets
getPlayer().sendPacket(new GenshinPacket(PacketOpcodes.WorldPlayerReviveRsp)); getPlayer().sendPacket(new BasePacket(PacketOpcodes.WorldPlayerReviveRsp));
} }
public void saveAvatars() { public void saveAvatars() {
......
package emu.grasscutter.game; package emu.grasscutter.game.world;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
...@@ -12,9 +12,9 @@ import java.util.Set; ...@@ -12,9 +12,9 @@ import java.util.Set;
import org.danilopianini.util.SpatialIndex; import org.danilopianini.util.SpatialIndex;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GenshinData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.GenshinDepot; import emu.grasscutter.data.GameDepot;
import emu.grasscutter.data.GenshinResource; import emu.grasscutter.data.GameResource;
import emu.grasscutter.data.def.MonsterData; import emu.grasscutter.data.def.MonsterData;
import emu.grasscutter.data.def.SceneData; import emu.grasscutter.data.def.SceneData;
import emu.grasscutter.data.def.WorldLevelData; import emu.grasscutter.data.def.WorldLevelData;
...@@ -22,14 +22,15 @@ import emu.grasscutter.game.entity.EntityAvatar; ...@@ -22,14 +22,15 @@ import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.entity.EntityClientGadget; import emu.grasscutter.game.entity.EntityClientGadget;
import emu.grasscutter.game.entity.EntityGadget; import emu.grasscutter.game.entity.EntityGadget;
import emu.grasscutter.game.entity.EntityMonster; import emu.grasscutter.game.entity.EntityMonster;
import emu.grasscutter.game.entity.GenshinEntity; import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.player.TeamInfo;
import emu.grasscutter.game.props.ClimateType; import emu.grasscutter.game.props.ClimateType;
import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.game.props.LifeState; import emu.grasscutter.game.props.LifeState;
import emu.grasscutter.game.props.SceneType; import emu.grasscutter.game.props.SceneType;
import emu.grasscutter.game.world.SpawnDataEntry;
import emu.grasscutter.game.world.SpawnDataEntry.SpawnGroupEntry; import emu.grasscutter.game.world.SpawnDataEntry.SpawnGroupEntry;
import emu.grasscutter.net.packet.GenshinPacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.proto.AttackResultOuterClass.AttackResult; import emu.grasscutter.net.proto.AttackResultOuterClass.AttackResult;
import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType; import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType;
import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
...@@ -41,11 +42,11 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap; ...@@ -41,11 +42,11 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps; import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
public class GenshinScene { public class Scene {
private final World world; private final World world;
private final SceneData sceneData; private final SceneData sceneData;
private final List<GenshinPlayer> players; private final List<Player> players;
private final Int2ObjectMap<GenshinEntity> entities; private final Int2ObjectMap<GameEntity> entities;
private final Set<SpawnDataEntry> spawnedEntities; private final Set<SpawnDataEntry> spawnedEntities;
private final Set<SpawnDataEntry> deadSpawnedEntities; private final Set<SpawnDataEntry> deadSpawnedEntities;
...@@ -55,7 +56,7 @@ public class GenshinScene { ...@@ -55,7 +56,7 @@ public class GenshinScene {
private ClimateType climate; private ClimateType climate;
private int weather; private int weather;
public GenshinScene(World world, SceneData sceneData) { public Scene(World world, SceneData sceneData) {
this.world = world; this.world = world;
this.sceneData = sceneData; this.sceneData = sceneData;
this.players = Collections.synchronizedList(new ArrayList<>()); this.players = Collections.synchronizedList(new ArrayList<>());
...@@ -84,7 +85,7 @@ public class GenshinScene { ...@@ -84,7 +85,7 @@ public class GenshinScene {
return getSceneData().getSceneType(); return getSceneData().getSceneType();
} }
public List<GenshinPlayer> getPlayers() { public List<Player> getPlayers() {
return players; return players;
} }
...@@ -92,11 +93,11 @@ public class GenshinScene { ...@@ -92,11 +93,11 @@ public class GenshinScene {
return this.getPlayers().size(); return this.getPlayers().size();
} }
public Int2ObjectMap<GenshinEntity> getEntities() { public Int2ObjectMap<GameEntity> getEntities() {
return entities; return entities;
} }
public GenshinEntity getEntityById(int id) { public GameEntity getEntityById(int id) {
return this.entities.get(id); return this.entities.get(id);
} }
...@@ -140,11 +141,11 @@ public class GenshinScene { ...@@ -140,11 +141,11 @@ public class GenshinScene {
return deadSpawnedEntities; return deadSpawnedEntities;
} }
public boolean isInScene(GenshinEntity entity) { public boolean isInScene(GameEntity entity) {
return this.entities.containsKey(entity.getId()); return this.entities.containsKey(entity.getId());
} }
public synchronized void addPlayer(GenshinPlayer player) { public synchronized void addPlayer(Player player) {
// Check if player already in // Check if player already in
if (getPlayers().contains(player)) { if (getPlayers().contains(player)) {
return; return;
...@@ -163,7 +164,7 @@ public class GenshinScene { ...@@ -163,7 +164,7 @@ public class GenshinScene {
this.setupPlayerAvatars(player); this.setupPlayerAvatars(player);
} }
public synchronized void removePlayer(GenshinPlayer player) { public synchronized void removePlayer(Player player) {
// Remove player from scene // Remove player from scene
getPlayers().remove(player); getPlayers().remove(player);
player.setScene(null); player.setScene(null);
...@@ -182,7 +183,7 @@ public class GenshinScene { ...@@ -182,7 +183,7 @@ public class GenshinScene {
} }
} }
private void setupPlayerAvatars(GenshinPlayer player) { private void setupPlayerAvatars(Player player) {
// Clear entities from old team // Clear entities from old team
player.getTeamManager().getActiveTeam().clear(); player.getTeamManager().getActiveTeam().clear();
...@@ -199,7 +200,7 @@ public class GenshinScene { ...@@ -199,7 +200,7 @@ public class GenshinScene {
} }
} }
private void removePlayerAvatars(GenshinPlayer player) { private void removePlayerAvatars(Player player) {
Iterator<EntityAvatar> it = player.getTeamManager().getActiveTeam().iterator(); Iterator<EntityAvatar> it = player.getTeamManager().getActiveTeam().iterator();
while (it.hasNext()) { while (it.hasNext()) {
this.removeEntity(it.next(), VisionType.VISION_REMOVE); this.removeEntity(it.next(), VisionType.VISION_REMOVE);
...@@ -207,7 +208,7 @@ public class GenshinScene { ...@@ -207,7 +208,7 @@ public class GenshinScene {
} }
} }
public void spawnPlayer(GenshinPlayer player) { public void spawnPlayer(Player player) {
if (this.isInScene(player.getTeamManager().getCurrentAvatarEntity())) { if (this.isInScene(player.getTeamManager().getCurrentAvatarEntity())) {
return; return;
} }
...@@ -219,33 +220,33 @@ public class GenshinScene { ...@@ -219,33 +220,33 @@ public class GenshinScene {
this.addEntity(player.getTeamManager().getCurrentAvatarEntity()); this.addEntity(player.getTeamManager().getCurrentAvatarEntity());
} }
private void addEntityDirectly(GenshinEntity entity) { private void addEntityDirectly(GameEntity entity) {
getEntities().put(entity.getId(), entity); getEntities().put(entity.getId(), entity);
} }
public synchronized void addEntity(GenshinEntity entity) { public synchronized void addEntity(GameEntity entity) {
this.addEntityDirectly(entity); this.addEntityDirectly(entity);
this.broadcastPacket(new PacketSceneEntityAppearNotify(entity)); this.broadcastPacket(new PacketSceneEntityAppearNotify(entity));
} }
public synchronized void addEntities(Collection<GenshinEntity> entities) { public synchronized void addEntities(Collection<GameEntity> entities) {
for (GenshinEntity entity : entities) { for (GameEntity entity : entities) {
this.addEntityDirectly(entity); this.addEntityDirectly(entity);
} }
this.broadcastPacket(new PacketSceneEntityAppearNotify(entities, VisionType.VISION_BORN)); this.broadcastPacket(new PacketSceneEntityAppearNotify(entities, VisionType.VISION_BORN));
} }
private GenshinEntity removeEntityDirectly(GenshinEntity entity) { private GameEntity removeEntityDirectly(GameEntity entity) {
return getEntities().remove(entity.getId()); return getEntities().remove(entity.getId());
} }
public void removeEntity(GenshinEntity entity) { public void removeEntity(GameEntity entity) {
this.removeEntity(entity, VisionType.VISION_DIE); this.removeEntity(entity, VisionType.VISION_DIE);
} }
public synchronized void removeEntity(GenshinEntity entity, VisionType visionType) { public synchronized void removeEntity(GameEntity entity, VisionType visionType) {
GenshinEntity removed = this.removeEntityDirectly(entity); GameEntity removed = this.removeEntityDirectly(entity);
if (removed != null) { if (removed != null) {
this.broadcastPacket(new PacketSceneEntityDisappearNotify(removed, visionType)); this.broadcastPacket(new PacketSceneEntityDisappearNotify(removed, visionType));
} }
...@@ -258,11 +259,11 @@ public class GenshinScene { ...@@ -258,11 +259,11 @@ public class GenshinScene {
this.broadcastPacket(new PacketSceneEntityAppearNotify(newEntity, VisionType.VISION_REPLACE, oldEntity.getId())); this.broadcastPacket(new PacketSceneEntityAppearNotify(newEntity, VisionType.VISION_REPLACE, oldEntity.getId()));
} }
public void showOtherEntities(GenshinPlayer player) { public void showOtherEntities(Player player) {
List<GenshinEntity> entities = new LinkedList<>(); List<GameEntity> entities = new LinkedList<>();
GenshinEntity currentEntity = player.getTeamManager().getCurrentAvatarEntity(); GameEntity currentEntity = player.getTeamManager().getCurrentAvatarEntity();
for (GenshinEntity entity : this.getEntities().values()) { for (GameEntity entity : this.getEntities().values()) {
if (entity == currentEntity) { if (entity == currentEntity) {
continue; continue;
} }
...@@ -273,8 +274,8 @@ public class GenshinScene { ...@@ -273,8 +274,8 @@ public class GenshinScene {
} }
public void handleAttack(AttackResult result) { public void handleAttack(AttackResult result) {
//GenshinEntity attacker = getEntityById(result.getAttackerId()); //GameEntity attacker = getEntityById(result.getAttackerId());
GenshinEntity target = getEntityById(result.getDefenseId()); GameEntity target = getEntityById(result.getDefenseId());
if (target == null) { if (target == null) {
return; return;
...@@ -306,7 +307,7 @@ public class GenshinScene { ...@@ -306,7 +307,7 @@ public class GenshinScene {
} }
} }
public void killEntity(GenshinEntity target, int attackerId) { public void killEntity(GameEntity target, int attackerId) {
// Packet // Packet
this.broadcastPacket(new PacketLifeStateChangeNotify(attackerId, target, LifeState.LIFE_DEAD)); this.broadcastPacket(new PacketLifeStateChangeNotify(attackerId, target, LifeState.LIFE_DEAD));
this.removeEntity(target); this.removeEntity(target);
...@@ -321,10 +322,10 @@ public class GenshinScene { ...@@ -321,10 +322,10 @@ public class GenshinScene {
// TODO - Test // TODO - Test
public void checkSpawns() { public void checkSpawns() {
SpatialIndex<SpawnGroupEntry> list = GenshinDepot.getSpawnListById(this.getId()); SpatialIndex<SpawnGroupEntry> list = GameDepot.getSpawnListById(this.getId());
Set<SpawnDataEntry> visible = new HashSet<>(); Set<SpawnDataEntry> visible = new HashSet<>();
for (GenshinPlayer player : this.getPlayers()) { for (Player player : this.getPlayers()) {
int RANGE = 100; int RANGE = 100;
Collection<SpawnGroupEntry> entries = list.query( Collection<SpawnGroupEntry> entries = list.query(
new double[] {player.getPos().getX() - RANGE, player.getPos().getZ() - RANGE}, new double[] {player.getPos().getX() - RANGE, player.getPos().getZ() - RANGE},
...@@ -339,7 +340,7 @@ public class GenshinScene { ...@@ -339,7 +340,7 @@ public class GenshinScene {
} }
// World level // World level
WorldLevelData worldLevelData = GenshinData.getWorldLevelDataMap().get(getWorld().getWorldLevel()); WorldLevelData worldLevelData = GameData.getWorldLevelDataMap().get(getWorld().getWorldLevel());
int worldLevelOverride = 0; int worldLevelOverride = 0;
if (worldLevelData != null) { if (worldLevelData != null) {
...@@ -347,13 +348,13 @@ public class GenshinScene { ...@@ -347,13 +348,13 @@ public class GenshinScene {
} }
// Todo // Todo
List<GenshinEntity> toAdd = new LinkedList<>(); List<GameEntity> toAdd = new LinkedList<>();
List<GenshinEntity> toRemove = new LinkedList<>(); List<GameEntity> toRemove = new LinkedList<>();
for (SpawnDataEntry entry : visible) { for (SpawnDataEntry entry : visible) {
if (!this.getSpawnedEntities().contains(entry) && !this.getDeadSpawnedEntities().contains(entry)) { if (!this.getSpawnedEntities().contains(entry) && !this.getDeadSpawnedEntities().contains(entry)) {
// Spawn entity // Spawn entity
MonsterData data = GenshinData.getMonsterDataMap().get(entry.getMonsterId()); MonsterData data = GameData.getMonsterDataMap().get(entry.getMonsterId());
if (data == null) { if (data == null) {
continue; continue;
...@@ -373,7 +374,7 @@ public class GenshinScene { ...@@ -373,7 +374,7 @@ public class GenshinScene {
} }
} }
for (GenshinEntity entity : this.getEntities().values()) { for (GameEntity entity : this.getEntities().values()) {
if (entity.getSpawnEntry() != null && !visible.contains(entity.getSpawnEntry())) { if (entity.getSpawnEntry() != null && !visible.contains(entity.getSpawnEntry())) {
toRemove.add(entity); toRemove.add(entity);
} }
...@@ -407,7 +408,7 @@ public class GenshinScene { ...@@ -407,7 +408,7 @@ public class GenshinScene {
} }
public void onPlayerDestroyGadget(int entityId) { public void onPlayerDestroyGadget(int entityId) {
GenshinEntity entity = getEntities().get(entityId); GameEntity entity = getEntities().get(entityId);
if (entity == null || !(entity instanceof EntityClientGadget)) { if (entity == null || !(entity instanceof EntityClientGadget)) {
return; return;
...@@ -430,20 +431,20 @@ public class GenshinScene { ...@@ -430,20 +431,20 @@ public class GenshinScene {
// Broadcasting // Broadcasting
public void broadcastPacket(GenshinPacket packet) { public void broadcastPacket(BasePacket packet) {
// Send to all players - might have to check if player has been sent data packets // Send to all players - might have to check if player has been sent data packets
for (GenshinPlayer player : this.getPlayers()) { for (Player player : this.getPlayers()) {
player.getSession().send(packet); player.getSession().send(packet);
} }
} }
public void broadcastPacketToOthers(GenshinPlayer excludedPlayer, GenshinPacket packet) { public void broadcastPacketToOthers(Player excludedPlayer, BasePacket packet) {
// Optimization // Optimization
if (this.getPlayerCount() == 1 && this.getPlayers().get(0) == excludedPlayer) { if (this.getPlayerCount() == 1 && this.getPlayers().get(0) == excludedPlayer) {
return; return;
} }
// Send to all players - might have to check if player has been sent data packets // Send to all players - might have to check if player has been sent data packets
for (GenshinPlayer player : this.getPlayers()) { for (Player player : this.getPlayers()) {
if (player == excludedPlayer) { if (player == excludedPlayer) {
continue; continue;
} }
......
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