Goods purchasing fixed
This commit is contained in:
parent
dd2fafd05f
commit
cd5c4779c7
@ -285,14 +285,15 @@ public class GameServer {
|
||||
|
||||
private void buyOne(int playerId, AMFObject item, UserMessage message) {
|
||||
Map<String, AMFObject> obj = (Map<String, AMFObject>) item.getRaw();
|
||||
long goodId = obj.get("GoodId").getLong();
|
||||
boolean isMagic = obj.get("Currency").getLong() == 2;
|
||||
obj = (Map<String, AMFObject>) obj.get("item").getRaw();
|
||||
long goodId = obj.get("id").getLong();
|
||||
Optional<Good> tGood = this.goodsService.findById(goodId);
|
||||
if( tGood.isEmpty() ) {
|
||||
this.sendResult(playerId, message.getTransactionId(), new BuyGoodResult(new ArrayList<>()));
|
||||
return;
|
||||
}
|
||||
Good good = tGood.get();
|
||||
boolean isMagic = good.getMagicTickets() != 0;
|
||||
AvatarInventoryType invType = AvatarInventoryType.fromGoodType(good.getGoodTypeId());
|
||||
if( isMagic ) {
|
||||
if( !subtractMagicTickets(playerId, good.getMagicTickets()) ) {
|
||||
@ -300,7 +301,7 @@ public class GameServer {
|
||||
return;
|
||||
}
|
||||
this.users.pushToInventory(playerId, invType, goodId);
|
||||
this.sendResult(playerId, message.getTransactionId(), new BuyGoodResultGood(true, new ArrayList<>()));
|
||||
this.sendResult(playerId, message.getTransactionId(), new BuyGoodResultGood(new BuyGoodResultGood.BuyGoodBody(false, new ArrayList<>())));
|
||||
return;
|
||||
}
|
||||
if( !subtractUsualTickets(playerId, good.getUsualTickets()) ) {
|
||||
@ -308,7 +309,7 @@ public class GameServer {
|
||||
return;
|
||||
}
|
||||
this.users.pushToInventory(playerId, invType, goodId);
|
||||
this.sendResult(playerId, message.getTransactionId(), new BuyGoodResultGood(true, new ArrayList<>()));
|
||||
this.sendResult(playerId, message.getTransactionId(), new BuyGoodResultGood(new BuyGoodResultGood.BuyGoodBody(false, new ArrayList<>())));
|
||||
}
|
||||
|
||||
private boolean subtractUsualTickets(int userId, int amount) {
|
||||
|
@ -7,9 +7,14 @@ import java.util.List;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class BuyGoodResultGood {
|
||||
@AMFKey(name = "Error")
|
||||
private Boolean error;
|
||||
private BuyGoodBody body;
|
||||
|
||||
@AMFKey(name = "GoodInfo")
|
||||
private List<Integer> goodInfo;
|
||||
@AllArgsConstructor
|
||||
public static class BuyGoodBody {
|
||||
@AMFKey(name = "Error")
|
||||
private Boolean error;
|
||||
|
||||
@AMFKey(name = "GoodInfo")
|
||||
private List<Integer> goodInfo;
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,10 @@ public class AMFDeserializer {
|
||||
Map<String, AMFObject> map = new HashMap<>();
|
||||
boolean endMarker = false;
|
||||
while(!endMarker) {
|
||||
if( bytes.size() < 2 ) {
|
||||
bytes.clear();
|
||||
break;
|
||||
}
|
||||
var a = bytes.subList(0, 2);
|
||||
int keyLen = BinaryMessageSerializer.deserializeInteger(a);
|
||||
a.clear();
|
||||
@ -75,9 +79,13 @@ public class AMFDeserializer {
|
||||
String key = new String(SerializerUtils.bytesToPrimitive(a));
|
||||
a.clear();
|
||||
AMFObject object = new AMFObject();
|
||||
object.setType(AMFValueType.toValueType(bytes.remove()));
|
||||
object.setValue(processSingle(object.getType()));
|
||||
map.put(key, object);
|
||||
if(!bytes.isEmpty()) {
|
||||
object.setType(AMFValueType.toValueType(bytes.remove()));
|
||||
object.setValue(processSingle(object.getType()));
|
||||
map.put(key, object);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
@ -87,6 +95,10 @@ public class AMFDeserializer {
|
||||
bytes.subList(0, 4).clear();
|
||||
boolean endMarker = false;
|
||||
while(!endMarker) {
|
||||
if( bytes.size() < 2 ) {
|
||||
bytes.clear();
|
||||
break;
|
||||
}
|
||||
var a = bytes.subList(0, 2);
|
||||
int keyLen = BinaryMessageSerializer.deserializeInteger(a);
|
||||
a.clear();
|
||||
|
@ -27,7 +27,7 @@ public interface AvatarInventoryRepository extends JpaRepository<AvatarInventory
|
||||
List<AvatarInventory> findUsedItemsByUserIdAndType(@Param("uid") Integer userId, @Param("type") AvatarInventoryType type);
|
||||
|
||||
@Query(value = "SELECT a FROM AvatarInventory a WHERE a.user.id = :uid AND a.type = :type AND a.goodId = :good_id")
|
||||
Optional<AvatarInventory> findSpecificitem(@Param("uid") Integer userId, @Param("type") AvatarInventoryType type, @Param("good_id") Long goodId);
|
||||
List<AvatarInventory> findSpecificitem(@Param("uid") Integer userId, @Param("type") AvatarInventoryType type, @Param("good_id") Long goodId);
|
||||
|
||||
@Transactional
|
||||
@Modifying
|
||||
|
@ -75,7 +75,7 @@ public class AvatarInventoryService {
|
||||
}
|
||||
|
||||
public boolean isSpecificItemExists(Integer userId, AvatarInventoryType type, Long goodId) {
|
||||
return this.inventoryRepository.findSpecificitem(userId, type, goodId).isPresent();
|
||||
return !this.inventoryRepository.findSpecificitem(userId, type, goodId).isEmpty();
|
||||
}
|
||||
|
||||
public InventoryGroup getBodyPartInventoryGroup(Integer userId, BodyPartType type, boolean addEmpty) {
|
||||
|
@ -354,6 +354,8 @@ public class UserService {
|
||||
}
|
||||
|
||||
public void pushToInventory(int userId, AvatarInventoryType type, long goodId) {
|
||||
this.inventoryService.addGoodToInventory(new AvatarInventory(userRepository.getReferenceById(userId), goodId, false, type));
|
||||
if( !this.inventoryService.isSpecificItemExists(userId, type, goodId) ) {
|
||||
this.inventoryService.addGoodToInventory(new AvatarInventory(userRepository.getReferenceById(userId), goodId, false, type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user