Commit 9b26426e authored by Melledy's avatar Melledy
Browse files

Merge branch 'development' into dev-quests

parents 12318021 8c32438b
...@@ -4,6 +4,7 @@ import java.io.*; ...@@ -4,6 +4,7 @@ import java.io.*;
import java.util.Calendar; import java.util.Calendar;
import emu.grasscutter.command.CommandMap; import emu.grasscutter.command.CommandMap;
import emu.grasscutter.game.managers.StaminaManager.StaminaManager;
import emu.grasscutter.plugin.PluginManager; import emu.grasscutter.plugin.PluginManager;
import emu.grasscutter.plugin.api.ServerHook; import emu.grasscutter.plugin.api.ServerHook;
import emu.grasscutter.scripts.ScriptLoader; import emu.grasscutter.scripts.ScriptLoader;
...@@ -111,6 +112,9 @@ public final class Grasscutter { ...@@ -111,6 +112,9 @@ public final class Grasscutter {
// Create plugin manager instance. // Create plugin manager instance.
pluginManager = new PluginManager(); pluginManager = new PluginManager();
// TODO: find a better place?
StaminaManager.initialize();
// Start servers. // Start servers.
var runMode = SERVER.runMode; var runMode = SERVER.runMode;
if (runMode == ServerRunMode.HYBRID) { if (runMode == ServerRunMode.HYBRID) {
......
...@@ -13,6 +13,7 @@ import com.google.gson.reflect.TypeToken; ...@@ -13,6 +13,7 @@ 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.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.common.ItemParamData;
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.avatar.Avatar; import emu.grasscutter.game.avatar.Avatar;
...@@ -127,15 +128,10 @@ public class GachaManager { ...@@ -127,15 +128,10 @@ public class GachaManager {
} }
// Spend currency // Spend currency
if (banner.getCostItem() > 0) { if (banner.getCostItem() > 0 && !player.getInventory().payItem(banner.getCostItem(), times)) {
GameItem costItem = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(banner.getCostItem());
if (costItem == null || costItem.getCount() < times) {
return; return;
} }
player.getInventory().removeItem(costItem, times);
}
// Roll // Roll
PlayerGachaBannerInfo gachaInfo = player.getGachaInfo().getBannerInfo(banner); PlayerGachaBannerInfo gachaInfo = player.getGachaInfo().getBannerInfo(banner);
IntList wonItems = new IntArrayList(times); IntList wonItems = new IntArrayList(times);
......
...@@ -7,6 +7,7 @@ import java.util.List; ...@@ -7,6 +7,7 @@ import java.util.List;
import emu.grasscutter.GameConstants; import emu.grasscutter.GameConstants;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.common.ItemParamData;
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;
...@@ -257,6 +258,64 @@ public class Inventory implements Iterable<GameItem> { ...@@ -257,6 +258,64 @@ public class Inventory implements Iterable<GameItem> {
} }
} }
private int getVirtualItemCount(int itemId) {
switch (itemId) {
case 201: // Primogem
return player.getPrimogems();
case 202: // Mora
return player.getMora();
case 203: // Genesis Crystals
return player.getCrystals();
default:
GameItem item = getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(itemId); // What if we ever want to operate on weapons/relics/furniture? :S
return (item == null) ? 0 : item.getCount();
}
}
public boolean payItem(int id, int count) {
return payItem(new ItemParamData(id, count));
}
public boolean payItem(ItemParamData costItem) {
return payItems(new ItemParamData[] {costItem}, 1, null);
}
public boolean payItems(ItemParamData[] costItems) {
return payItems(costItems, 1, null);
}
public boolean payItems(ItemParamData[] costItems, int quantity) {
return payItems(costItems, quantity, null);
}
public synchronized boolean payItems(ItemParamData[] costItems, int quantity, ActionReason reason) {
// Make sure player has requisite items
for (ItemParamData cost : costItems) {
if (getVirtualItemCount(cost.getId()) < (cost.getCount() * quantity)) {
return false;
}
}
// All costs are satisfied, now remove them all
for (ItemParamData cost : costItems) {
switch (cost.getId()) {
case 201 -> // Primogem
player.setPrimogems(player.getPrimogems() - (cost.getCount() * quantity));
case 202 -> // Mora
player.setMora(player.getMora() - (cost.getCount() * quantity));
case 203 -> // Genesis Crystals
player.setCrystals(player.getCrystals() - (cost.getCount() * quantity));
default ->
removeItem(getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(cost.getId()), cost.getCount() * quantity);
}
}
if (reason != null) { // Do we need these?
// getPlayer().sendPacket(new PacketItemAddHintNotify(changedItems, reason));
}
// getPlayer().sendPacket(new PacketStoreItemChangeNotify(changedItems));
return true;
}
public void removeItems(List<GameItem> items) { public void removeItems(List<GameItem> items) {
// TODO Bulk delete // TODO Bulk delete
for (GameItem item : items) { for (GameItem item : items) {
......
package emu.grasscutter.game.managers; package emu.grasscutter.game.managers;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -38,6 +39,8 @@ public class InventoryManager { ...@@ -38,6 +39,8 @@ public class InventoryManager {
private final static int RELIC_MATERIAL_1 = 105002; // Sanctifying Unction private final static int RELIC_MATERIAL_1 = 105002; // Sanctifying Unction
private final static int RELIC_MATERIAL_2 = 105003; // Sanctifying Essence private final static int RELIC_MATERIAL_2 = 105003; // Sanctifying Essence
private final static int RELIC_MATERIAL_EXP_1 = 2500; // Sanctifying Unction
private final static int RELIC_MATERIAL_EXP_2 = 10000; // Sanctifying Essence
private final static int WEAPON_ORE_1 = 104011; // Enhancement Ore private final static int WEAPON_ORE_1 = 104011; // Enhancement Ore
private final static int WEAPON_ORE_2 = 104012; // Fine Enhancement Ore private final static int WEAPON_ORE_2 = 104012; // Fine Enhancement Ore
...@@ -85,6 +88,7 @@ public class InventoryManager { ...@@ -85,6 +88,7 @@ public class InventoryManager {
int moraCost = 0; int moraCost = 0;
int expGain = 0; int expGain = 0;
List<GameItem> foodRelics = new ArrayList<GameItem>();
for (long guid : foodRelicList) { for (long guid : foodRelicList) {
// Add to delete queue // Add to delete queue
GameItem food = player.getInventory().getItemByGuid(guid); GameItem food = player.getInventory().getItemByGuid(guid);
...@@ -96,23 +100,21 @@ public class InventoryManager { ...@@ -96,23 +100,21 @@ public class InventoryManager {
expGain += food.getItemData().getBaseConvExp(); expGain += food.getItemData().getBaseConvExp();
// Feeding artifact with exp already // Feeding artifact with exp already
if (food.getTotalExp() > 0) { if (food.getTotalExp() > 0) {
expGain += (int) Math.floor(food.getTotalExp() * .8f); expGain += (food.getTotalExp() * 4) / 5;
} }
foodRelics.add(food);
} }
List<ItemParamData> payList = new ArrayList<ItemParamData>();
for (ItemParam itemParam : list) { for (ItemParam itemParam : list) {
GameItem food = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(itemParam.getItemId()); int amount = itemParam.getCount(); // Previously this capped to inventory amount, but rejecting the payment makes more sense for an invalid order
if (food == null || food.getItemData().getMaterialType() != MaterialType.MATERIAL_RELIQUARY_MATERIAL) { int gain = amount * switch(itemParam.getItemId()) {
continue; case RELIC_MATERIAL_1 -> RELIC_MATERIAL_EXP_1;
} case RELIC_MATERIAL_2 -> RELIC_MATERIAL_EXP_2;
int amount = Math.min(food.getCount(), itemParam.getCount()); default -> 0;
int gain = 0; };
if (food.getItemId() == RELIC_MATERIAL_2) {
gain = 10000 * amount;
} else if (food.getItemId() == RELIC_MATERIAL_1) {
gain = 2500 * amount;
}
expGain += gain; expGain += gain;
moraCost += gain; moraCost += gain;
payList.add(new ItemParamData(itemParam.getItemId(), itemParam.getCount()));
} }
// Make sure exp gain is valid // Make sure exp gain is valid
...@@ -120,28 +122,14 @@ public class InventoryManager { ...@@ -120,28 +122,14 @@ public class InventoryManager {
return; return;
} }
// Check mora // Confirm payment of materials and mora (assume food relics are payable afterwards)
if (player.getMora() < moraCost) { payList.add(new ItemParamData(202, moraCost));
if (!player.getInventory().payItems(payList.toArray(new ItemParamData[0]))) {
return; return;
} }
player.setMora(player.getMora() - moraCost);
// Consume food items // Consume food relics
for (long guid : foodRelicList) { player.getInventory().removeItems(foodRelics);
GameItem food = player.getInventory().getItemByGuid(guid);
if (food == null || !food.isDestroyable()) {
continue;
}
player.getInventory().removeItem(food);
}
for (ItemParam itemParam : list) {
GameItem food = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(itemParam.getItemId());
if (food == null || food.getItemData().getMaterialType() != MaterialType.MATERIAL_RELIQUARY_MATERIAL) {
continue;
}
int amount = Math.min(food.getCount(), itemParam.getCount());
player.getInventory().removeItem(food, amount);
}
// Implement random rate boost // Implement random rate boost
int rate = 1; int rate = 1;
...@@ -231,22 +219,16 @@ public class InventoryManager { ...@@ -231,22 +219,16 @@ public class InventoryManager {
} }
expGain += food.getItemData().getWeaponBaseExp(); expGain += food.getItemData().getWeaponBaseExp();
if (food.getTotalExp() > 0) { if (food.getTotalExp() > 0) {
expGain += (int) Math.floor(food.getTotalExp() * .8f); expGain += (food.getTotalExp() * 4) / 5;
} }
} }
for (ItemParam param : itemParamList) { for (ItemParam param : itemParamList) {
GameItem food = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(param.getItemId()); expGain += param.getCount() * switch(param.getItemId()) {
if (food == null || food.getItemData().getMaterialType() != MaterialType.MATERIAL_WEAPON_EXP_STONE) { case WEAPON_ORE_1 -> WEAPON_ORE_EXP_1;
continue; case WEAPON_ORE_2 -> WEAPON_ORE_EXP_2;
} case WEAPON_ORE_3 -> WEAPON_ORE_EXP_3;
int amount = Math.min(param.getCount(), food.getCount()); default -> 0;
if (food.getItemId() == WEAPON_ORE_3) { };
expGain += 10000 * amount;
} else if (food.getItemId() == WEAPON_ORE_2) {
expGain += 2000 * amount;
} else if (food.getItemId() == WEAPON_ORE_1) {
expGain += 400 * amount;
}
} }
// Try // Try
...@@ -288,65 +270,45 @@ public class InventoryManager { ...@@ -288,65 +270,45 @@ public class InventoryManager {
} }
// Get exp gain // Get exp gain
int expGain = 0, moraCost = 0; int expGain = 0, expGainFree = 0;
List<GameItem> foodWeapons = new ArrayList<GameItem>();
for (long guid : foodWeaponGuidList) { for (long guid : foodWeaponGuidList) {
GameItem food = player.getInventory().getItemByGuid(guid); GameItem food = player.getInventory().getItemByGuid(guid);
if (food == null || !food.isDestroyable()) { if (food == null || !food.isDestroyable()) {
continue; continue;
} }
expGain += food.getItemData().getWeaponBaseExp(); expGain += food.getItemData().getWeaponBaseExp();
moraCost += (int) Math.floor(food.getItemData().getWeaponBaseExp() * .1f);
if (food.getTotalExp() > 0) { if (food.getTotalExp() > 0) {
expGain += (int) Math.floor(food.getTotalExp() * .8f); expGainFree += (food.getTotalExp() * 4) / 5; // No tax :D
} }
foodWeapons.add(food);
} }
List<ItemParamData> payList = new ArrayList<ItemParamData>();
for (ItemParam param : itemParamList) { for (ItemParam param : itemParamList) {
GameItem food = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(param.getItemId()); int amount = param.getCount(); // Previously this capped to inventory amount, but rejecting the payment makes more sense for an invalid order
if (food == null || food.getItemData().getMaterialType() != MaterialType.MATERIAL_WEAPON_EXP_STONE) { int gain = amount * switch(param.getItemId()) {
continue; case WEAPON_ORE_1 -> WEAPON_ORE_EXP_1;
} case WEAPON_ORE_2 -> WEAPON_ORE_EXP_2;
int amount = Math.min(param.getCount(), food.getCount()); case WEAPON_ORE_3 -> WEAPON_ORE_EXP_3;
int gain = 0; default -> 0;
if (food.getItemId() == WEAPON_ORE_3) { };
gain = 10000 * amount;
} else if (food.getItemId() == WEAPON_ORE_2) {
gain = 2000 * amount;
} else if (food.getItemId() == WEAPON_ORE_1) {
gain = 400 * amount;
}
expGain += gain; expGain += gain;
moraCost += (int) Math.floor(gain * .1f); payList.add(new ItemParamData(param.getItemId(), amount));
} }
// Make sure exp gain is valid // Make sure exp gain is valid
int moraCost = expGain / 10;
expGain += expGainFree;
if (expGain <= 0) { if (expGain <= 0) {
return; return;
} }
// Mora check // Confirm payment of materials and mora (assume food weapons are payable afterwards)
if (player.getMora() >= moraCost) { payList.add(new ItemParamData(202, moraCost));
player.setMora(player.getMora() - moraCost); if (!player.getInventory().payItems(payList.toArray(new ItemParamData[0]))) {
} else {
return; return;
} }
player.getInventory().removeItems(foodWeapons);
// Consume weapon/items used to feed
for (long guid : foodWeaponGuidList) {
GameItem food = player.getInventory().getItemByGuid(guid);
if (food == null || !food.isDestroyable()) {
continue;
}
player.getInventory().removeItem(food);
}
for (ItemParam param : itemParamList) {
GameItem food = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(param.getItemId());
if (food == null || food.getItemData().getMaterialType() != MaterialType.MATERIAL_WEAPON_EXP_STONE) {
continue;
}
int amount = Math.min(param.getCount(), food.getCount());
player.getInventory().removeItem(food, amount);
}
// Level up // Level up
int maxLevel = promoteData.getUnlockMaxLevel(); int maxLevel = promoteData.getUnlockMaxLevel();
...@@ -393,7 +355,7 @@ public class InventoryManager { ...@@ -393,7 +355,7 @@ public class InventoryManager {
player.sendPacket(new PacketWeaponUpgradeRsp(weapon, oldLevel, leftovers)); player.sendPacket(new PacketWeaponUpgradeRsp(weapon, oldLevel, leftovers));
} }
private List<ItemParam> getLeftoverOres(float leftover) { private List<ItemParam> getLeftoverOres(int leftover) {
List<ItemParam> leftoverOreList = new ArrayList<>(3); List<ItemParam> leftoverOreList = new ArrayList<>(3);
if (leftover < WEAPON_ORE_EXP_1) { if (leftover < WEAPON_ORE_EXP_1) {
...@@ -401,11 +363,11 @@ public class InventoryManager { ...@@ -401,11 +363,11 @@ public class InventoryManager {
} }
// Get leftovers // Get leftovers
int ore3 = (int) Math.floor(leftover / WEAPON_ORE_EXP_3); int ore3 = leftover / WEAPON_ORE_EXP_3;
leftover = leftover % WEAPON_ORE_EXP_3; leftover = leftover % WEAPON_ORE_EXP_3;
int ore2 = (int) Math.floor(leftover / WEAPON_ORE_EXP_2); int ore2 = leftover / WEAPON_ORE_EXP_2;
leftover = leftover % WEAPON_ORE_EXP_2; leftover = leftover % WEAPON_ORE_EXP_2;
int ore1 = (int) Math.floor(leftover / WEAPON_ORE_EXP_1); int ore1 = leftover / WEAPON_ORE_EXP_1;
if (ore3 > 0) { if (ore3 > 0) {
leftoverOreList.add(ItemParam.newBuilder().setItemId(WEAPON_ORE_3).setCount(ore3).build()); leftoverOreList.add(ItemParam.newBuilder().setItemId(WEAPON_ORE_3).setCount(ore3).build());
...@@ -496,27 +458,16 @@ public class InventoryManager { ...@@ -496,27 +458,16 @@ public class InventoryManager {
return; return;
} }
// Make sure player has promote items // Pay materials and mora if possible
for (ItemParamData cost : nextPromoteData.getCostItems()) { ItemParamData[] costs = nextPromoteData.getCostItems(); // Can this be null?
GameItem feedItem = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(cost.getId()); if (nextPromoteData.getCoinCost() > 0) {
if (feedItem == null || feedItem.getCount() < cost.getCount()) { costs = Arrays.copyOf(costs, costs.length + 1);
return; costs[costs.length-1] = new ItemParamData(202, nextPromoteData.getCoinCost());
} }
} if (!player.getInventory().payItems(costs)) {
// Mora check
if (player.getMora() >= nextPromoteData.getCoinCost()) {
player.setMora(player.getMora() - nextPromoteData.getCoinCost());
} else {
return; return;
} }
// Consume promote filler items
for (ItemParamData cost : nextPromoteData.getCostItems()) {
GameItem feedItem = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(cost.getId());
player.getInventory().removeItem(feedItem, cost.getCount());
}
int oldPromoteLevel = weapon.getPromoteLevel(); int oldPromoteLevel = weapon.getPromoteLevel();
weapon.setPromoteLevel(nextPromoteLevel); weapon.setPromoteLevel(nextPromoteLevel);
weapon.save(); weapon.save();
...@@ -552,27 +503,16 @@ public class InventoryManager { ...@@ -552,27 +503,16 @@ public class InventoryManager {
return; return;
} }
// Make sure player has cost items // Pay materials and mora if possible
for (ItemParamData cost : nextPromoteData.getCostItems()) { ItemParamData[] costs = nextPromoteData.getCostItems(); // Can this be null?
GameItem feedItem = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(cost.getId()); if (nextPromoteData.getCoinCost() > 0) {
if (feedItem == null || feedItem.getCount() < cost.getCount()) { costs = Arrays.copyOf(costs, costs.length + 1);
return; costs[costs.length-1] = new ItemParamData(202, nextPromoteData.getCoinCost());
}
} }
if (!player.getInventory().payItems(costs)) {
// Mora check
if (player.getMora() >= nextPromoteData.getCoinCost()) {
player.setMora(player.getMora() - nextPromoteData.getCoinCost());
} else {
return; return;
} }
// Consume promote filler items
for (ItemParamData cost : nextPromoteData.getCostItems()) {
GameItem feedItem = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(cost.getId());
player.getInventory().removeItem(feedItem, cost.getCount());
}
// Update promote level // Update promote level
avatar.setPromoteLevel(nextPromoteLevel); avatar.setPromoteLevel(nextPromoteLevel);
...@@ -616,35 +556,26 @@ public class InventoryManager { ...@@ -616,35 +556,26 @@ public class InventoryManager {
return; return;
} }
GameItem feedItem = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(itemId);
if (feedItem == null || feedItem.getItemData().getMaterialType() != MaterialType.MATERIAL_EXP_FRUIT || feedItem.getCount() < count) {
return;
}
// Calc exp // Calc exp
int expGain = 0, moraCost = 0; int expGain = switch(itemId) {
case AVATAR_BOOK_1 -> AVATAR_BOOK_EXP_1 * count;
case AVATAR_BOOK_2 -> AVATAR_BOOK_EXP_2 * count;
case AVATAR_BOOK_3 -> AVATAR_BOOK_EXP_3 * count;
default -> 0;
};
// TODO clean up // Sanity check
if (itemId == AVATAR_BOOK_3) { if (expGain <= 0) {
expGain = AVATAR_BOOK_EXP_3 * count; return;
} else if (itemId == AVATAR_BOOK_2) {
expGain = AVATAR_BOOK_EXP_2 * count;
} else if (itemId == AVATAR_BOOK_1) {
expGain = AVATAR_BOOK_EXP_1 * count;
} }
moraCost = (int) Math.floor(expGain * .2f);
// Mora check // Payment check
if (player.getMora() >= moraCost) { int moraCost = expGain / 5;
player.setMora(player.getMora() - moraCost); ItemParamData[] costItems = new ItemParamData[] {new ItemParamData(itemId, count), new ItemParamData(202, moraCost)};
} else { if (!player.getInventory().payItems(costItems)) {
return; return;
} }
// Consume items
player.getInventory().removeItem(feedItem, count);
// Level up // Level up
upgradeAvatar(player, avatar, promoteData, expGain); upgradeAvatar(player, avatar, promoteData, expGain);
} }
...@@ -764,33 +695,15 @@ public class InventoryManager { ...@@ -764,33 +695,15 @@ public class InventoryManager {
return; return;
} }
// Make sure player has cost items // Pay materials and mora if possible
for (ItemParamData cost : proudSkill.getCostItems()) { List<ItemParamData> costs = new ArrayList<ItemParamData>(proudSkill.getCostItems()); // Can this be null?
if (cost.getId() == 0) { if (proudSkill.getCoinCost() > 0) {
continue; costs.add(new ItemParamData(202, proudSkill.getCoinCost()));
}
GameItem feedItem = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(cost.getId());
if (feedItem == null || feedItem.getCount() < cost.getCount()) {
return;
} }
} if (!player.getInventory().payItems(costs.toArray(new ItemParamData[0]))) {
// Mora check
if (player.getMora() >= proudSkill.getCoinCost()) {
player.setMora(player.getMora() - proudSkill.getCoinCost());
} else {
return; return;
} }
// Consume promote filler items
for (ItemParamData cost : proudSkill.getCostItems()) {
if (cost.getId() == 0) {
continue;
}
GameItem feedItem = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(cost.getId());
player.getInventory().removeItem(feedItem, cost.getCount());
}
// Upgrade skill // Upgrade skill
avatar.getSkillLevelMap().put(skillId, nextLevel); avatar.getSkillLevelMap().put(skillId, nextLevel);
avatar.save(); avatar.save();
...@@ -822,14 +735,11 @@ public class InventoryManager { ...@@ -822,14 +735,11 @@ public class InventoryManager {
return; return;
} }
GameItem costItem = player.getInventory().getInventoryTab(ItemType.ITEM_MATERIAL).getItemById(talentData.getMainCostItemId()); // Pay constellation item if possible
if (costItem == null || costItem.getCount() < talentData.getMainCostItemCount()) { if (!player.getInventory().payItem(talentData.getMainCostItemId(), 1)) {
return; return;
} }
// Consume item
player.getInventory().removeItem(costItem, talentData.getMainCostItemCount());
// Apply + recalc // Apply + recalc
avatar.getTalentIdList().add(talentData.getId()); avatar.getTalentIdList().add(talentData.getId());
avatar.setCoreProudSkillLevel(currentTalentLevel + 1); avatar.setCoreProudSkillLevel(currentTalentLevel + 1);
......
...@@ -8,5 +8,5 @@ public interface AfterUpdateStaminaListener { ...@@ -8,5 +8,5 @@ public interface AfterUpdateStaminaListener {
* @param reason Why updating stamina. * @param reason Why updating stamina.
* @param newStamina New Stamina value. * @param newStamina New Stamina value.
*/ */
void onAfterUpdateStamina(String reason, int newStamina); void onAfterUpdateStamina(String reason, int newStamina, boolean isCharacterStamina);
} }
...@@ -8,7 +8,7 @@ public interface BeforeUpdateStaminaListener { ...@@ -8,7 +8,7 @@ public interface BeforeUpdateStaminaListener {
* @param newStamina New ABSOLUTE stamina value. * @param newStamina New ABSOLUTE stamina value.
* @return true if you want to cancel this update, otherwise false. * @return true if you want to cancel this update, otherwise false.
*/ */
int onBeforeUpdateStamina(String reason, int newStamina); int onBeforeUpdateStamina(String reason, int newStamina, boolean isCharacterStamina);
/** /**
* onBeforeUpdateStamina() will be called before StaminaManager attempt to update the player's current stamina. * onBeforeUpdateStamina() will be called before StaminaManager attempt to update the player's current stamina.
* This gives listeners a chance to intercept this update. * This gives listeners a chance to intercept this update.
...@@ -16,5 +16,5 @@ public interface BeforeUpdateStaminaListener { ...@@ -16,5 +16,5 @@ public interface BeforeUpdateStaminaListener {
* @param consumption ConsumptionType and RELATIVE stamina change amount. * @param consumption ConsumptionType and RELATIVE stamina change amount.
* @return true if you want to cancel this update, otherwise false. * @return true if you want to cancel this update, otherwise false.
*/ */
Consumption onBeforeUpdateStamina(String reason, Consumption consumption); Consumption onBeforeUpdateStamina(String reason, Consumption consumption, boolean isCharacterStamina);
} }
\ No newline at end of file
...@@ -13,18 +13,19 @@ public enum ConsumptionType { ...@@ -13,18 +13,19 @@ public enum ConsumptionType {
// Slow swimming is handled per movement, not per second. // Slow swimming is handled per movement, not per second.
// Arm movement frequency depends on gender/age/height. // Arm movement frequency depends on gender/age/height.
// TODO: Instead of cost -80 per tick, find a proper way to calculate cost. // TODO: Instead of cost -80 per tick, find a proper way to calculate cost.
SKIFF(-300), // TODO: Get real value SKIFF_DASH(-204),
SPRINT(-1800), SPRINT(-1800),
SWIM_DASH_START(-20), SWIM_DASH_START(-2000),
SWIM_DASH(-204), // -10.2 per second, 5Hz = -204 each tick SWIM_DASH(-204), // -10.2 per second, 5Hz = -204 each tick
SWIMMING(-80), SWIMMING(-80),
TALENT_DASH(-300), // -1500 per second, 5Hz = -300 each tick TALENT_DASH(-300), // -1500 per second, 5Hz = -300 each tick
TALENT_DASH_START(-1000), TALENT_DASH_START(-1000),
// restore // restore
POWERED_FLY(500), // TODO: Get real value POWERED_FLY(500),
POWERED_SKIFF(2000), // TODO: Get real value POWERED_SKIFF(500),
RUN(500), RUN(500),
SKIFF(500),
STANDBY(500), STANDBY(500),
WALK(500); WALK(500);
......
...@@ -85,6 +85,8 @@ public class Player { ...@@ -85,6 +85,8 @@ public class Player {
private Set<Integer> flyCloakList; private Set<Integer> flyCloakList;
private Set<Integer> costumeList; private Set<Integer> costumeList;
private Integer widgetId;
@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;
...@@ -302,6 +304,14 @@ public class Player { ...@@ -302,6 +304,14 @@ public class Player {
this.updateProfile(); this.updateProfile();
} }
public Integer getWidgetId() {
return widgetId;
}
public void setWidgetId(Integer widgetId) {
this.widgetId = widgetId;
}
public Position getPos() { public Position getPos() {
return pos; return pos;
} }
...@@ -1170,6 +1180,8 @@ public class Player { ...@@ -1170,6 +1180,8 @@ public class Player {
session.send(new PacketFinishedParentQuestNotify(this)); session.send(new PacketFinishedParentQuestNotify(this));
session.send(new PacketQuestListNotify(this)); session.send(new PacketQuestListNotify(this));
session.send(new PacketServerCondMeetQuestListUpdateNotify(this)); session.send(new PacketServerCondMeetQuestListUpdateNotify(this));
session.send(new PacketAllWidgetDataNotify(this));
session.send(new PacketWidgetGadgetAllDataNotify());
getTodayMoonCard(); // The timer works at 0:0, some users log in after that, use this method to check if they have received a reward today or not. If not, send the reward. getTodayMoonCard(); // The timer works at 0:0, some users log in after that, use this method to check if they have received a reward today or not. If not, send the reward.
...@@ -1267,7 +1279,7 @@ public class Player { ...@@ -1267,7 +1279,7 @@ public class Player {
} else if (prop == PlayerProperty.PROP_IS_TRANSFERABLE) { // 10009 } else if (prop == PlayerProperty.PROP_IS_TRANSFERABLE) { // 10009
if (!(0 <= value && value <= 1)) { return false; } if (!(0 <= value && value <= 1)) { return false; }
} else if (prop == PlayerProperty.PROP_MAX_STAMINA) { // 10010 } else if (prop == PlayerProperty.PROP_MAX_STAMINA) { // 10010
if (!(value >= 0 && value <= StaminaManager.GlobalMaximumStamina)) { return false; } if (!(value >= 0 && value <= StaminaManager.GlobalCharacterMaximumStamina)) { return false; }
} else if (prop == PlayerProperty.PROP_CUR_PERSIST_STAMINA) { // 10011 } else if (prop == PlayerProperty.PROP_CUR_PERSIST_STAMINA) { // 10011
int playerMaximumStamina = getProperty(PlayerProperty.PROP_MAX_STAMINA); int playerMaximumStamina = getProperty(PlayerProperty.PROP_MAX_STAMINA);
if (!(value >= 0 && value <= playerMaximumStamina)) { return false; } if (!(value >= 0 && value <= playerMaximumStamina)) { return false; }
......
...@@ -18,7 +18,7 @@ import emu.grasscutter.server.packet.send.PacketBuyGoodsRsp; ...@@ -18,7 +18,7 @@ import emu.grasscutter.server.packet.send.PacketBuyGoodsRsp;
import emu.grasscutter.server.packet.send.PacketStoreItemChangeNotify; import emu.grasscutter.server.packet.send.PacketStoreItemChangeNotify;
import emu.grasscutter.utils.Utils; import emu.grasscutter.utils.Utils;
import java.util.HashMap; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
...@@ -56,36 +56,13 @@ public class HandlerBuyGoodsReq extends PacketHandler { ...@@ -56,36 +56,13 @@ public class HandlerBuyGoodsReq extends PacketHandler {
return; return;
} }
if (sg.getScoin() > 0 && session.getPlayer().getMora() < buyGoodsReq.getBoughtNum() * sg.getScoin()) { List<ItemParamData> costs = new ArrayList<ItemParamData>(sg.getCostItemList()); // Can this even be null?
costs.add(new ItemParamData(202, sg.getScoin()));
costs.add(new ItemParamData(201, sg.getHcoin()));
costs.add(new ItemParamData(203, sg.getMcoin()));
if (!session.getPlayer().getInventory().payItems(costs.toArray(new ItemParamData[0]), buyGoodsReq.getBoughtNum())) {
return; return;
} }
if (sg.getHcoin() > 0 && session.getPlayer().getPrimogems() < buyGoodsReq.getBoughtNum() * sg.getHcoin()) {
return;
}
if (sg.getMcoin() > 0 && session.getPlayer().getCrystals() < buyGoodsReq.getBoughtNum() * sg.getMcoin()) {
return;
}
HashMap<GameItem, Integer> itemsCache = new HashMap<>();
if (sg.getCostItemList() != null) {
for (ItemParamData p : sg.getCostItemList()) {
Optional<GameItem> invItem = session.getPlayer().getInventory().getItems().values().stream().filter(x -> x.getItemId() == p.getId()).findFirst();
if (invItem.isEmpty() || invItem.get().getCount() < p.getCount())
return;
itemsCache.put(invItem.get(), p.getCount() * buyGoodsReq.getBoughtNum());
}
}
session.getPlayer().setMora(session.getPlayer().getMora() - buyGoodsReq.getBoughtNum() * sg.getScoin());
session.getPlayer().setPrimogems(session.getPlayer().getPrimogems() - buyGoodsReq.getBoughtNum() * sg.getHcoin());
session.getPlayer().setCrystals(session.getPlayer().getCrystals() - buyGoodsReq.getBoughtNum() * sg.getMcoin());
if (!itemsCache.isEmpty()) {
for (GameItem gi : itemsCache.keySet()) {
session.getPlayer().getInventory().removeItem(gi, itemsCache.get(gi));
}
itemsCache.clear();
}
session.getPlayer().addShopLimit(sg.getGoodsId(), buyGoodsReq.getBoughtNum(), ShopManager.getShopNextRefreshTime(sg)); session.getPlayer().addShopLimit(sg.getGoodsId(), buyGoodsReq.getBoughtNum(), ShopManager.getShopNextRefreshTime(sg));
GameItem item = new GameItem(GameData.getItemDataMap().get(sg.getGoodsItem().getId())); GameItem item = new GameItem(GameData.getItemDataMap().get(sg.getGoodsItem().getId()));
......
package emu.grasscutter.server.packet.recv; package emu.grasscutter.server.packet.recv;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.packet.PacketHandler; import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketGetShopRsp;
import emu.grasscutter.server.packet.send.PacketGetWidgetSlotRsp;
@Opcodes(PacketOpcodes.GetWidgetSlotReq) @Opcodes(PacketOpcodes.GetWidgetSlotReq)
public class HandlerGetWidgetSlotReq extends PacketHandler { public class HandlerGetWidgetSlotReq extends PacketHandler {
@Override @Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
// Unhandled Player player = session.getPlayer();
session.send(new PacketGetWidgetSlotRsp(player));
} }
} }
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.SetWidgetSlotReqOuterClass;
import emu.grasscutter.net.proto.WidgetSlotOpOuterClass;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketSetWidgetSlotRsp;
import emu.grasscutter.server.packet.send.PacketWidgetSlotChangeNotify;
@Opcodes(PacketOpcodes.SetWidgetSlotReq)
public class HandlerSetWidgetSlotReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
SetWidgetSlotReqOuterClass.SetWidgetSlotReq req = SetWidgetSlotReqOuterClass.SetWidgetSlotReq.parseFrom(payload);
Player player = session.getPlayer();
player.setWidgetId(req.getMaterialId());
// WidgetSlotChangeNotify op & slot key
session.send(new PacketWidgetSlotChangeNotify(WidgetSlotOpOuterClass.WidgetSlotOp.DETACH));
// WidgetSlotChangeNotify slot
session.send(new PacketWidgetSlotChangeNotify(req.getMaterialId()));
// SetWidgetSlotRsp
session.send(new PacketSetWidgetSlotRsp(req.getMaterialId()));
}
}
...@@ -14,6 +14,7 @@ public class HandlerVehicleInteractReq extends PacketHandler { ...@@ -14,6 +14,7 @@ public class HandlerVehicleInteractReq extends PacketHandler {
@Override @Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
VehicleInteractReqOuterClass.VehicleInteractReq req = VehicleInteractReqOuterClass.VehicleInteractReq.parseFrom(payload); VehicleInteractReqOuterClass.VehicleInteractReq req = VehicleInteractReqOuterClass.VehicleInteractReq.parseFrom(payload);
session.getPlayer().getStaminaManager().handleVehicleInteractReq(session, req.getEntityId(), req.getInteractType());
session.send(new PacketVehicleInteractRsp(session.getPlayer(), req.getEntityId(), req.getInteractType())); session.send(new PacketVehicleInteractRsp(session.getPlayer(), req.getEntityId(), req.getInteractType()));
} }
} }
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.AllWidgetDataNotifyOuterClass.AllWidgetDataNotify;
import emu.grasscutter.net.proto.LunchBoxDataOuterClass;
import emu.grasscutter.net.proto.WidgetSlotDataOuterClass;
import emu.grasscutter.net.proto.WidgetSlotTagOuterClass;
import java.util.List;
import java.util.Map;
public class PacketAllWidgetDataNotify extends BasePacket {
public PacketAllWidgetDataNotify(Player player) {
super(PacketOpcodes.AllWidgetDataNotify);
// TODO: Implement this
AllWidgetDataNotify.Builder proto = AllWidgetDataNotify.newBuilder()
// If you want to implement this, feel free to do so. :)
.setLunchBoxData(
LunchBoxDataOuterClass.LunchBoxData.newBuilder().build()
)
// Maybe it's a little difficult, or it makes you upset :(
.addAllOneoffGatherPointDetectorDataList(List.of())
// So, goodbye, and hopefully sometime in the future o(* ̄▽ ̄*)ブ
.addAllCoolDownGroupDataList(List.of())
// I'll see your PR with a title that says (・∀・(・∀・(・∀・*)
.addAllAnchorPointList(List.of())
// "Complete implementation of widget functionality" b( ̄▽ ̄)d 
.addAllClientCollectorDataList(List.of())
// Good luck, my boy.
.addAllNormalCoolDownDataList(List.of());
if (player.getWidgetId() == null) {
proto.addAllSlotList(List.of());
} else {
proto.addSlotList(
WidgetSlotDataOuterClass.WidgetSlotData.newBuilder()
.setIsActive(true)
.setMaterialId(player.getWidgetId())
.build()
);
proto.addSlotList(
WidgetSlotDataOuterClass.WidgetSlotData.newBuilder()
.setTag(WidgetSlotTagOuterClass.WidgetSlotTag.WIDGET_SLOT_ATTACH_AVATAR)
.build()
);
}
AllWidgetDataNotify protoData = proto.build();
this.setData(protoData);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.GetWidgetSlotRspOuterClass;
import emu.grasscutter.net.proto.WidgetSlotDataOuterClass;
import emu.grasscutter.net.proto.WidgetSlotTagOuterClass;
import java.util.List;
public class PacketGetWidgetSlotRsp extends BasePacket {
public PacketGetWidgetSlotRsp(Player player) {
super(PacketOpcodes.GetWidgetSlotRsp);
GetWidgetSlotRspOuterClass.GetWidgetSlotRsp.Builder proto =
GetWidgetSlotRspOuterClass.GetWidgetSlotRsp.newBuilder();
if (player.getWidgetId() == null) {
proto.addAllSlotList(List.of());
} else {
proto.addSlotList(
WidgetSlotDataOuterClass.WidgetSlotData.newBuilder()
.setIsActive(true)
.setMaterialId(player.getWidgetId())
.build()
);
proto.addSlotList(
WidgetSlotDataOuterClass.WidgetSlotData.newBuilder()
.setTag(WidgetSlotTagOuterClass.WidgetSlotTag.WIDGET_SLOT_ATTACH_AVATAR)
.build()
);
}
GetWidgetSlotRspOuterClass.GetWidgetSlotRsp protoData = proto.build();
this.setData(protoData);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.SetWidgetSlotRspOuterClass;
public class PacketSetWidgetSlotRsp extends BasePacket {
public PacketSetWidgetSlotRsp(int materialId) {
super(PacketOpcodes.SetWidgetSlotRsp);
SetWidgetSlotRspOuterClass.SetWidgetSlotRsp proto = SetWidgetSlotRspOuterClass.SetWidgetSlotRsp.newBuilder()
.setMaterialId(materialId)
.build();
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.VehicleStaminaNotifyOuterClass.VehicleStaminaNotify;
public class PacketVehicleStaminaNotify extends BasePacket {
public PacketVehicleStaminaNotify(int vehicleId, float newStamina) {
super(PacketOpcodes.VehicleStaminaNotify);
VehicleStaminaNotify.Builder proto = VehicleStaminaNotify.newBuilder();
proto.setEntityId(vehicleId);
proto.setCurStamina(newStamina);
this.setData(proto.build());
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.WidgetGadgetAllDataNotifyOuterClass.WidgetGadgetAllDataNotify;
public class PacketWidgetGadgetAllDataNotify extends BasePacket {
public PacketWidgetGadgetAllDataNotify() {
super(PacketOpcodes.AllWidgetDataNotify);
WidgetGadgetAllDataNotify proto = WidgetGadgetAllDataNotify.newBuilder().build();
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.WidgetSlotChangeNotifyOuterClass;
import emu.grasscutter.net.proto.WidgetSlotDataOuterClass;
import emu.grasscutter.net.proto.WidgetSlotOpOuterClass;
public class PacketWidgetSlotChangeNotify extends BasePacket {
public PacketWidgetSlotChangeNotify(WidgetSlotChangeNotifyOuterClass.WidgetSlotChangeNotify proto) {
super(PacketOpcodes.WidgetSlotChangeNotify);
this.setData(proto);
}
public PacketWidgetSlotChangeNotify(WidgetSlotOpOuterClass.WidgetSlotOp op) {
super(PacketOpcodes.WidgetSlotChangeNotify);
WidgetSlotChangeNotifyOuterClass.WidgetSlotChangeNotify proto = WidgetSlotChangeNotifyOuterClass.WidgetSlotChangeNotify.newBuilder()
.setOp(op)
.setSlot(
WidgetSlotDataOuterClass.WidgetSlotData.newBuilder()
.setIsActive(true)
.build()
)
.build();
this.setData(proto);
}
public PacketWidgetSlotChangeNotify(int materialId) {
super(PacketOpcodes.WidgetSlotChangeNotify);
WidgetSlotChangeNotifyOuterClass.WidgetSlotChangeNotify proto = WidgetSlotChangeNotifyOuterClass.WidgetSlotChangeNotify.newBuilder()
.setSlot(
WidgetSlotDataOuterClass.WidgetSlotData.newBuilder()
.setIsActive(true)
.setMaterialId(materialId)
.build()
)
.build();
this.setData(proto);
}
}
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