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) {
|
private void buyOne(int playerId, AMFObject item, UserMessage message) {
|
||||||
Map<String, AMFObject> obj = (Map<String, AMFObject>) item.getRaw();
|
Map<String, AMFObject> obj = (Map<String, AMFObject>) item.getRaw();
|
||||||
long goodId = obj.get("GoodId").getLong();
|
obj = (Map<String, AMFObject>) obj.get("item").getRaw();
|
||||||
boolean isMagic = obj.get("Currency").getLong() == 2;
|
long goodId = obj.get("id").getLong();
|
||||||
Optional<Good> tGood = this.goodsService.findById(goodId);
|
Optional<Good> tGood = this.goodsService.findById(goodId);
|
||||||
if( tGood.isEmpty() ) {
|
if( tGood.isEmpty() ) {
|
||||||
this.sendResult(playerId, message.getTransactionId(), new BuyGoodResult(new ArrayList<>()));
|
this.sendResult(playerId, message.getTransactionId(), new BuyGoodResult(new ArrayList<>()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Good good = tGood.get();
|
Good good = tGood.get();
|
||||||
|
boolean isMagic = good.getMagicTickets() != 0;
|
||||||
AvatarInventoryType invType = AvatarInventoryType.fromGoodType(good.getGoodTypeId());
|
AvatarInventoryType invType = AvatarInventoryType.fromGoodType(good.getGoodTypeId());
|
||||||
if( isMagic ) {
|
if( isMagic ) {
|
||||||
if( !subtractMagicTickets(playerId, good.getMagicTickets()) ) {
|
if( !subtractMagicTickets(playerId, good.getMagicTickets()) ) {
|
||||||
@ -300,7 +301,7 @@ public class GameServer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.users.pushToInventory(playerId, invType, goodId);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if( !subtractUsualTickets(playerId, good.getUsualTickets()) ) {
|
if( !subtractUsualTickets(playerId, good.getUsualTickets()) ) {
|
||||||
@ -308,7 +309,7 @@ public class GameServer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.users.pushToInventory(playerId, invType, goodId);
|
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) {
|
private boolean subtractUsualTickets(int userId, int amount) {
|
||||||
|
@ -7,9 +7,14 @@ import java.util.List;
|
|||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class BuyGoodResultGood {
|
public class BuyGoodResultGood {
|
||||||
@AMFKey(name = "Error")
|
private BuyGoodBody body;
|
||||||
private Boolean error;
|
|
||||||
|
|
||||||
@AMFKey(name = "GoodInfo")
|
@AllArgsConstructor
|
||||||
private List<Integer> goodInfo;
|
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<>();
|
Map<String, AMFObject> map = new HashMap<>();
|
||||||
boolean endMarker = false;
|
boolean endMarker = false;
|
||||||
while(!endMarker) {
|
while(!endMarker) {
|
||||||
|
if( bytes.size() < 2 ) {
|
||||||
|
bytes.clear();
|
||||||
|
break;
|
||||||
|
}
|
||||||
var a = bytes.subList(0, 2);
|
var a = bytes.subList(0, 2);
|
||||||
int keyLen = BinaryMessageSerializer.deserializeInteger(a);
|
int keyLen = BinaryMessageSerializer.deserializeInteger(a);
|
||||||
a.clear();
|
a.clear();
|
||||||
@ -75,9 +79,13 @@ public class AMFDeserializer {
|
|||||||
String key = new String(SerializerUtils.bytesToPrimitive(a));
|
String key = new String(SerializerUtils.bytesToPrimitive(a));
|
||||||
a.clear();
|
a.clear();
|
||||||
AMFObject object = new AMFObject();
|
AMFObject object = new AMFObject();
|
||||||
object.setType(AMFValueType.toValueType(bytes.remove()));
|
if(!bytes.isEmpty()) {
|
||||||
object.setValue(processSingle(object.getType()));
|
object.setType(AMFValueType.toValueType(bytes.remove()));
|
||||||
map.put(key, object);
|
object.setValue(processSingle(object.getType()));
|
||||||
|
map.put(key, object);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
@ -87,6 +95,10 @@ public class AMFDeserializer {
|
|||||||
bytes.subList(0, 4).clear();
|
bytes.subList(0, 4).clear();
|
||||||
boolean endMarker = false;
|
boolean endMarker = false;
|
||||||
while(!endMarker) {
|
while(!endMarker) {
|
||||||
|
if( bytes.size() < 2 ) {
|
||||||
|
bytes.clear();
|
||||||
|
break;
|
||||||
|
}
|
||||||
var a = bytes.subList(0, 2);
|
var a = bytes.subList(0, 2);
|
||||||
int keyLen = BinaryMessageSerializer.deserializeInteger(a);
|
int keyLen = BinaryMessageSerializer.deserializeInteger(a);
|
||||||
a.clear();
|
a.clear();
|
||||||
|
@ -27,7 +27,7 @@ public interface AvatarInventoryRepository extends JpaRepository<AvatarInventory
|
|||||||
List<AvatarInventory> findUsedItemsByUserIdAndType(@Param("uid") Integer userId, @Param("type") AvatarInventoryType type);
|
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")
|
@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
|
@Transactional
|
||||||
@Modifying
|
@Modifying
|
||||||
|
@ -75,7 +75,7 @@ public class AvatarInventoryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSpecificItemExists(Integer userId, AvatarInventoryType type, Long goodId) {
|
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) {
|
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) {
|
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