Skip to content

Commit

Permalink
Fix library, hardcore puts bound cards at stake too
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Jan 31, 2024
1 parent 48d339f commit 07b6cd4
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/rs/server/src/handlews.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,7 @@ pub async fn handle_ws(
userdata.gold = userdata.gold.saturating_add(g as i32);
}
}
AuthMessage::addloss { pvp, l, g, c } => {
AuthMessage::addloss { pvp, l, g, c, bound } => {
let mut user = user.lock().await;
if let Some(userdata) = user.data.get_mut(&uname) {
if pvp {
Expand All @@ -1944,7 +1944,7 @@ pub async fn handle_ws(
if let Some(g) = g {
userdata.gold = userdata.gold.saturating_add(g as i32);
}
if let Some(q) = c.and_then(|c| userdata.pool.0.get_mut(&c)) {
if let Some(q) = c.and_then(|c| if bound { &mut userdata.accountbound } else { &mut userdata.pool }.0.get_mut(&c)) {
*q = q.saturating_sub(1);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/rs/server/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ pub enum AuthMessage {
g: Option<i16>,
#[serde(default)]
c: Option<i16>,
#[serde(default)]
bound: bool,
},
addwin {
pvp: bool,
Expand Down
5 changes: 4 additions & 1 deletion src/usercmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ export function addloss(data, user) {
result.streak[data.l] = 0;
}
if (data.g) result.gold = user.gold + (data.g | 0);
if (data.c) result.pool = etgutil.addcard(user.pool, data.c, -1);
if (data.c) {
const key = data.bound ? 'accountbound' : 'pool';
result[key] = etgutil.addcard(user[key], data.c, -1);
}
return result;
}
export function addwin(data, user) {
Expand Down
2 changes: 1 addition & 1 deletion src/views/Library.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function Library(props) {

onMount(() => {
sock.setCmds({ librarygive: setData });
sock.emit({ x: 'librarywant', f: props.name, a: props.alt });
sock.emit({ x: 'librarywant', f: props.name, a: props.alt ?? '' });
});

const memo = createMemo(() => {
Expand Down
28 changes: 19 additions & 9 deletions src/views/Match.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,8 @@ export default function Match(props) {
expectedDamageSamples = rx.opts.expectedDamageSamples | 0 || 4;
let aiDelay = 0,
streakback = 0,
hardcoreback = 0;
hardcoreback = 0,
hardcorebound = 0;
const [tempgame, setTempgame] = createSignal(null);
const [replayhistory, setReplayHistory] = createSignal([props.game]);
const [replayindex, setreplayindex] = createSignal(0);
Expand Down Expand Up @@ -1114,7 +1115,12 @@ export default function Match(props) {
}
}
if (game.Cards.cardSet === 'Open') {
store.doNav(import('./Result.jsx'), { game, streakback, hardcoreback });
store.doNav(import('./Result.jsx'), {
game,
streakback,
hardcoreback,
hardcorebound,
});
} else {
store.doNav(import('../vanilla/views/Result.jsx'), { game });
}
Expand Down Expand Up @@ -1336,13 +1342,17 @@ export default function Match(props) {
}
};
for (const [gsum, gcode] of groups) {
if (pick >= gsum && checkcard(gcode)) {
break;
}
}
if (!msg.c) {
for (const [_gsum, gcode] of groups) {
if (checkcard(gcode)) {
if (pick >= gsum) {
for (const [code, _count] of iterraw(rx.user.accountbound)) {
if (code === gcode) {
msg.c = hardcoreback = gcode;
msg.bound = hardcorebound = true;
break;
}
}
if (!msg.c) {
msg.c = hardcoreback = gcode;
msg.bound = hardcorebound = false;
break;
}
}
Expand Down
38 changes: 22 additions & 16 deletions src/views/Result.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ export default function Result(props) {
p1id = game.userId(rx.username);
const [tooltip, setTip] = createSignal(null);
let goldreward = game.data.goldreward,
cardreward = game.data.cardreward;
boundreward = game.data.cardreward ?? '',
poolreward = '',
spinreward = '';

const canRematch = () =>
game.data.rematch &&
Expand Down Expand Up @@ -295,19 +297,24 @@ export default function Result(props) {
if (level !== undefined) {
const foedecks = game.data.players.filter(pd => !pd.user),
foedeck = choose(foedecks);
if (cardreward === undefined && foedeck) {
if (foedeck) {
const foeDeck = etgutil.decodedeck(foedeck.deck);
// Chromatic Butterfly if nothing winnable
let winnable = foeDeck.filter(code => {
const card = game.Cards.Codes[code];
return card && card.rarity > 0 && card.rarity < 4;
}),
cardwon = winnable.length ? choose(winnable) : 5009;
cardreward = '01' + etgutil.encodeCode(etgutil.asShiny(cardwon, false));
poolreward = spinreward =
'01' + etgutil.encodeCode(etgutil.asShiny(cardwon, false));
}
if (props.hardcoreback) {
cardreward =
'01' + etgutil.encodeCode(props.hardcoreback) + (cardreward ?? '');
const hardreward = '01' + etgutil.encodeCode(props.hardcoreback);
if (props.hardcorebound) {
boundreward = hardreward + boundreward;
} else {
poolreward = hardreward + poolreward;
}
}
if (goldreward === undefined) {
if (level !== undefined) {
Expand Down Expand Up @@ -348,10 +355,11 @@ export default function Result(props) {
if (goldreward) {
sock.userExec('addgold', { g: goldreward });
}
if (cardreward) {
sock.userExec(`add${game.data.quest ? 'bound' : ''}cards`, {
c: cardreward,
});
if (boundreward) {
sock.userExec('addboundcards', { c: boundreward });
}
if (poolreward) {
sock.userExec('addcards', { c: poolreward });
}
}
if (
Expand All @@ -371,8 +379,8 @@ export default function Result(props) {
game.get(p1id, 'hp'),
game.get(p1id, 'maxhp'),
(goldreward | 0) - (game.data.cost | 0),
cardreward || '-',
calcWealth(Cards, cardreward),
spinreward || '-',
calcWealth(Cards, spinreward),
winner ? (props.streakback ?? 0) + 1 : 0,
streakrate,
];
Expand All @@ -395,7 +403,8 @@ export default function Result(props) {
}

const cards = () => {
const cards = [];
const cards = [],
cardreward = boundreward + poolreward;
if (cardreward) {
let x0 = 390 - etgutil.decklength(cardreward) * 20;
for (const code of etgutil.iterdeck(cardreward)) {
Expand Down Expand Up @@ -431,10 +440,7 @@ export default function Result(props) {
</div>
)}
{cards}
<div
style={`text-align:center;width:700px;position:absolute;left:100px;bottom:${
cardreward ? 444 : 180
}px`}>
<div style="text-align:center;width:700px;position:absolute;left:100px;bottom:444px">
<Text text={game.data.wintext ?? 'You won!'} />
</div>
</>
Expand Down

0 comments on commit 07b6cd4

Please sign in to comment.