Deck manager works (except mass_disenchant and new_deck_bug )

This commit is contained in:
Michael Wain 2024-06-21 02:06:28 +03:00
parent 324432fba4
commit 08bc4b85f1
8 changed files with 200 additions and 6 deletions

View File

@ -0,0 +1,57 @@
package com.alterdekim.hearthhack.component.processor.client.request;
import com.alterdekim.Protocol;
import com.alterdekim.hearthhack.component.TcpConnection;
import com.alterdekim.hearthhack.entity.Deck;
import com.alterdekim.hearthhack.util.BattleNetPacket;
import com.alterdekim.hearthhack.util.ClientRequestBody;
import lombok.extern.slf4j.Slf4j;
import static com.alterdekim.hearthhack.util.GameUtilities.generateNotification;
@Slf4j
public class CreateDeck extends ClientRequestParser {
@Override
public void parse(BattleNetPacket packet, ClientRequestBody body, TcpConnection conn) throws Exception {
// DeckCreated 217
Protocol.CreateDeck request = Protocol.CreateDeck.parseFrom(body.getBody());
Deck d = conn.getUserService().createDeck(conn.getUserId(), request.getName(), request.getHero(), request.getHeroPremium() != 0);
Protocol.DeckCreated response = Protocol.DeckCreated.newBuilder()
.setInfo(Protocol.DeckInfo.newBuilder()
.setId(d.getId())
.setName(d.getName())
.setCardBack(conn.getUserService().getCardBackById(d.getCardBack()).getBackId())
.setHero(d.getHero())
.setDeckType(Protocol.DeckType.forNumber(d.getDeckType()))
.setValidity(767L)
.setHeroPremium(d.getHeroPremium() ? 1 : 0)
.setCardBackOverride(d.getCardBackOverride())
.setHeroOverride(d.getHeroOverride())
.setLastModified(d.getLastModified())
.setSortOrder(d.getSortOrder())
.setSourceType(Protocol.DeckSourceType.forNumber(d.getSourceType()))
.build()
).build();
Protocol.Notification n = generateNotification(217, response.toByteString(), response.getSerializedSize());
Protocol.Header header = Protocol.Header.newBuilder()
.setServiceId(4)
.setMethodId(1)
.setToken(conn.nextToken())
.setObjectId(0)
.setSize(n.getSerializedSize())
.setStatus(0)
.build();
conn.send(new BattleNetPacket(header, n.toByteArray()));
}
@Override
public int getId() {
return 209;
}
}

View File

@ -6,13 +6,24 @@ import com.alterdekim.hearthhack.util.BattleNetPacket;
import com.alterdekim.hearthhack.util.ClientRequestBody;
import lombok.extern.slf4j.Slf4j;
import java.util.stream.IntStream;
@Slf4j
public class DeckUpdate extends ClientRequestParser {
@Override
public void parse(BattleNetPacket packet, ClientRequestBody body, TcpConnection conn) throws Exception {
// 222 DeckSetData
Protocol.DeckSetData data = Protocol.DeckSetData.parseFrom(body.getBody());
log.info("DeckSetData: {}", data);
data.getCardsList().forEach(c -> {
IntStream.range(0, c.getQty()).forEach(i -> conn.getUserService().addCardToDeck(conn.getUserId(), data.getDeck(), (long) c.getDef().getAsset(), c.getDef().hasPremium() && c.getDef().getPremium() != 0));
});
if( data.hasCardBack() ) {
conn.getUserService().updateDeckCardBack(conn.getUserId(), data.getDeck(), data.getCardBack());
}
if( data.hasHero() ) {
conn.getUserService().updateDeckHero(conn.getUserId(), data.getDeck(), data.getHero().getAsset(), data.getHero().getPremium() != 0);
}
}
@Override

View File

@ -0,0 +1,37 @@
package com.alterdekim.hearthhack.component.processor.client.request;
import com.alterdekim.Protocol;
import com.alterdekim.hearthhack.component.TcpConnection;
import com.alterdekim.hearthhack.util.BattleNetPacket;
import com.alterdekim.hearthhack.util.ClientRequestBody;
import static com.alterdekim.hearthhack.util.GameUtilities.generateNotification;
public class DeleteDeck extends ClientRequestParser {
@Override
public void parse(BattleNetPacket packet, ClientRequestBody body, TcpConnection conn) throws Exception {
Protocol.DeleteDeck request = Protocol.DeleteDeck.parseFrom(body.getBody());
conn.getUserService().deleteDeck(conn.getUserId(), request.getDeck());
Protocol.DeckDeleted response = Protocol.DeckDeleted.newBuilder()
.setDeck(request.getDeck())
.build();
byte[] b = generateNotification(218, response.toByteString(), response.getSerializedSize()).toByteArray();
Protocol.Header header = Protocol.Header.newBuilder()
.setServiceId(4)
.setMethodId(1)
.setToken(conn.nextToken())
.setObjectId(0)
.setSize(b.length)
.setStatus(0)
.build();
conn.send(new BattleNetPacket(header, b));
}
@Override
public int getId() {
return 210;
}
}

View File

@ -3,8 +3,10 @@ package com.alterdekim.hearthhack.repository;
import com.alterdekim.hearthhack.entity.Deck;
import com.alterdekim.hearthhack.entity.DeckContent;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@ -12,4 +14,9 @@ public interface DeckContentRepository extends JpaRepository<DeckContent, Long>
@Query(value = "SELECT new DeckContent(d.id, d.userId, d.deckId, d.assetId, d.isPremium) FROM DeckContent d WHERE d.userId = :userId AND d.deckId = :deckId")
List<DeckContent> findCardsByDeckId(@Param("userId") Long userId, @Param("deckId") Long deckId);
@Transactional
@Modifying
@Query(value = "DELETE FROM DeckContent d WHERE d.userId = :userId AND d.deckId = :deckId")
void clearDeck(@Param("userId") Long userId, @Param("deckId") Long deckId);
}

View File

@ -21,4 +21,20 @@ public interface DeckRepository extends JpaRepository<Deck, Long> {
@Transactional
@Modifying
void updateDeckName(@Param("userId") Long userId, @Param("deckId") Long deckId, @Param("deckName") String name);
@Transactional
@Modifying
@Query(value = "UPDATE Deck d SET d.cardBack = :cardBack WHERE d.userId = :userId AND d.id = :deckId")
void updateDeckCardBack(@Param("userId") Long userId, @Param("deckId") Long deckId, @Param("cardBack") Integer cardBack);
@Transactional
@Modifying
@Query(value = "UPDATE Deck d SET d.heroPremium = :isPremium, d.hero = :heroId WHERE d.userId = :userId AND d.id = :deckId")
void updateDeckHero(@Param("userId") Long userId, @Param("deckId") Long deckId, @Param("heroId") Integer heroId, @Param("isPremium") Boolean isPremium);
@Transactional
@Modifying
@Query(value = "DELETE FROM Deck d WHERE d.id = :deckId AND d.userId = :userId")
void deleteDeck(@Param("userId") Long userId, @Param("deckId") Long deckId);
}

View File

@ -50,14 +50,39 @@ public class UserService implements IService {
deckContentRepository.save(new DeckContent(user.getId(), d.getId(), 670L, false));
}
public Deck createDeck(Long userId, String name, Integer hero, Boolean isPremium) {
return deckRepository.save(new Deck(userId, name, 0L, hero, Protocol.DeckType.NORMAL_DECK.getNumber(), isPremium, false, false, System.currentTimeMillis(), 1461490210L, Protocol.DeckSourceType.DECK_SOURCE_TYPE_NORMAL_VALUE));
}
public void updateDeckName(Long userId, Long deckId, String name) {
deckRepository.updateDeckName(userId, deckId, name);
}
public void updateDeckHero(Long userId, Long deckId, Integer heroId, Boolean isPremium) {
deckRepository.updateDeckHero(userId, deckId, heroId, isPremium);
}
public void updateDeckCardBack(Long userId, Long deckId, Integer cardBack) {
deckRepository.updateDeckCardBack(userId, deckId, cardBack);
}
public void clearDeckData(Long userId, Long deckId) {
deckContentRepository.clearDeck(userId, deckId);
}
public void addCardToDeck(Long userId, Long deckId, Long assetId, Boolean isPremium) {
deckContentRepository.save(new DeckContent(userId, deckId, assetId, isPremium));
}
public List<Deck> getDecksForUser(Long userId) {
return deckRepository.findDecksByUserId(userId);
}
public void deleteDeck(Long userId, Long deckId) {
deckContentRepository.clearDeck(userId, deckId);
deckRepository.deleteDeck(userId, deckId);
}
public List<DeckContent> getDeckContentForDeckId(Long userId, Long deckId) {
return deckContentRepository.findCardsByDeckId(userId, deckId);
}

View File

@ -3409,6 +3409,52 @@ message DeckSetData {
optional bool tagged_standard = 5;
}
// ref: PegasusUtil.DeleteDeck
message DeleteDeck {
// ref: PegasusUtil.DeleteDeck/PacketID
enum PacketID {
system = 0;
ID = 210;
}
required int64 deck = 1;
}
// ref: PegasusUtil.DeckDeleted
message DeckDeleted {
// ref: PegasusUtil.DeckDeleted/PacketID
enum PacketID {
ID = 218;
}
required int64 deck = 1;
}
// ref: PegasusUtil.CreateDeck
message CreateDeck {
// ref: PegasusUtil.CreateDeck/PacketID
enum PacketID {
system = 0;
ID = 209;
}
required string name = 1;
required int32 hero = 2;
required int32 hero_premium = 3;
required DeckType deck_type = 4;
optional bool tagged_standard = 5;
}
// ref: PegasusUtil.DeckCreated
message DeckCreated {
// ref: PegasusUtil.DeckCreated/PacketID
enum PacketID {
ID = 217;
}
required DeckInfo info = 1;
}
// ref: PegasusUtil.BoughtSoldCard
message BoughtSoldCard {
// ref: PegasusUtil.BoughtSoldCard/PacketID