Skip to content

Commit

Permalink
no-battle flag, add alt field to Library view
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Jan 28, 2024
1 parent 8b7d9cc commit b897397
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 76 deletions.
44 changes: 25 additions & 19 deletions src/rs/server/src/handlews.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2457,32 +2457,38 @@ pub async fn handle_ws(
}
}
}
UserMessage::librarywant { f } => {
UserMessage::librarywant { f, a } => {
if let Some(user) = users.write().await.load(&*client, &f).await {
let user = user.lock().await;
if let Some(userdata) = user.data.get("") {
if let Some(userdata) = user.data.get(&a) {
let mut gold = userdata.gold;
let mut pool = userdata.pool.clone();
if let Ok(bids) = client
.query("select code, q, p from bazaar where user_id = $1", &[&user.id])
.await
{
for bid in bids.iter() {
let code = bid.get::<usize, i32>(0) as i16;
let q: i32 = bid.get(1);
let p: i32 = bid.get(2);
if p < 0 {
let amt = pool.0.entry(code).or_insert(0);
*amt = amt.saturating_add(q as u16);
} else {
gold += p * q;
}
}
let mut pool = None;
if a == "" {
if let Ok(bids) = client
.query("select code, q, p from bazaar where user_id = $1", &[&user.id])
.await
{
if bids.len() > 0 {
let mut bidpool = userdata.pool.clone();
for bid in bids.iter() {
let code = bid.get::<usize, i32>(0) as i16;
let q: i32 = bid.get(1);
let p: i32 = bid.get(2);
if p < 0 {
let amt = bidpool.0.entry(code).or_insert(0);
*amt = amt.saturating_add(q as u16);
} else {
gold += p * q;
}
}
pool = Some(bidpool);
}
}
}
sendmsg(
&tx,
&WsResponse::librarygive {
pool: &pool,
pool: if let Some(ref pool) = pool { pool } else { &userdata.pool },
bound: &userdata.accountbound,
gold,
pvpwins: userdata.pvpwins,
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 @@ -269,6 +269,8 @@ pub enum UserMessage {
codesmith,
librarywant {
f: String,
#[serde(default)]
a: String,
},
arenatop {
lv: u8,
Expand Down
1 change: 1 addition & 0 deletions src/views/Alts.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const flagNames = [
'no-up-pillar',
'no-up-merge',
'no-trade',
'no-battle',
'hardcore',
];

Expand Down
19 changes: 19 additions & 0 deletions src/views/Library.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ import Card from '../Components/Card.jsx';
import CardSelector from '../Components/CardSelector.jsx';
import ExitBtn from '../Components/ExitBtn.jsx';

function loadAlt(user, alt) {
sock.emit({ x: 'librarywant', f: user, a: alt });
}

export default function Library(props) {
const [data, setData] = createSignal({});
const [card, setCard] = createSignal(null);
const [showBound, setShowBound] = createSignal(false);
let altname;

onMount(() => {
sock.setCmds({ librarygive: setData });
Expand Down Expand Up @@ -122,6 +127,20 @@ export default function Library(props) {
style="position:absolute;left:5px;top:28px"
onClick={() => open('/collection/' + props.name, '_blank')}
/>
<input
style="position:absolute;left:5px;top:246px"
placeholder="Alt"
ref={altname}
onKeyDown={e => {
if (e.key === 'Enter') loadAlt(props.name, e.target.value);
}}
/>
<input
type="button"
value="Load Alt"
style="position:absolute;left:160px;top:246px"
onClick={() => loadAlt(props.name, altname.value)}
/>
<CardSelector
cards={Cards}
cardpool={showBound() ? memo().boundpool : memo().cardpool}
Expand Down
116 changes: 59 additions & 57 deletions src/views/MainMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,64 +352,66 @@ export default function MainMenu(props) {
/>
<div style="margin-top:4px">{leadc}</div>
</div>
<div style="position:absolute;left:308px;top:120px;width:288px;height:240px">
<div class="maintitle">Battle</div>
<div style="display:flex;padding-left:80px">
<div class="costcolumn">Cost</div>
<div class="costcolumn">Reward</div>
{!hasflag(rx.user, 'no-battle') && (
<div style="position:absolute;left:308px;top:120px;width:288px;height:240px">
<div class="maintitle">Battle</div>
<div style="display:flex;padding-left:80px">
<div class="costcolumn">Cost</div>
<div class="costcolumn">Reward</div>
</div>
<AiButton
name="Commoner"
lv={0}
onClick={() => store.navGame(mkAi(0))}
onMouseOver={[
setTip,
'Commoners have no upgraded cards & mostly common cards',
]}
/>
<AiButton
name="Mage"
lv={1}
onClick={() => store.navGame(mkPremade(1))}
onMouseOver={[
setTip,
'Mages have preconstructed decks with a couple rares',
]}
/>
<AiButton
name="Champion"
lv={2}
onClick={() => store.navGame(mkAi(2))}
onMouseOver={[setTip, 'Champions have some upgraded cards']}
/>
<AiButton
name="Demigod"
lv={3}
onClick={() => store.navGame(mkPremade(3))}
onMouseOver={[
setTip,
'Demigods are extremely powerful. Come prepared',
]}
/>
<AiButton
name="Arena 1"
onClick={arenaAi(0)}
onMouseOver={[
setTip,
'In the arena you will face decks from other players',
]}
lv={4}
/>
<AiButton
name="Arena 2"
onClick={arenaAi(1)}
onMouseOver={[
setTip,
'In the arena you will face upgraded decks from other players',
]}
lv={5}
/>
</div>
<AiButton
name="Commoner"
lv={0}
onClick={() => store.navGame(mkAi(0))}
onMouseOver={[
setTip,
'Commoners have no upgraded cards & mostly common cards',
]}
/>
<AiButton
name="Mage"
lv={1}
onClick={() => store.navGame(mkPremade(1))}
onMouseOver={[
setTip,
'Mages have preconstructed decks with a couple rares',
]}
/>
<AiButton
name="Champion"
lv={2}
onClick={() => store.navGame(mkAi(2))}
onMouseOver={[setTip, 'Champions have some upgraded cards']}
/>
<AiButton
name="Demigod"
lv={3}
onClick={() => store.navGame(mkPremade(3))}
onMouseOver={[
setTip,
'Demigods are extremely powerful. Come prepared',
]}
/>
<AiButton
name="Arena 1"
onClick={arenaAi(0)}
onMouseOver={[
setTip,
'In the arena you will face decks from other players',
]}
lv={4}
/>
<AiButton
name="Arena 2"
onClick={arenaAi(1)}
onMouseOver={[
setTip,
'In the arena you will face upgraded decks from other players',
]}
lv={5}
/>
</div>
)}
<div style="position:absolute;left:620px;top:92px;width:196px;height:176px">
<div class="maintitle">Cards</div>
<input
Expand Down

0 comments on commit b897397

Please sign in to comment.