From c4e42457be6f904b85b8f105bbd1f35f9678df67 Mon Sep 17 00:00:00 2001 From: Mashy Date: Tue, 5 Nov 2019 10:00:40 +1000 Subject: [PATCH 1/3] equip items from vbox --- WORKLOG.md | 2 -- client/src/components/instance.constructs.jsx | 15 +++++++++++++++ client/src/socket.jsx | 11 +++++------ server/src/instance.rs | 4 ++-- server/src/player.rs | 8 ++++++-- server/src/rpc.rs | 6 +++++- server/src/vbox.rs | 10 +++++----- 7 files changed, 38 insertions(+), 18 deletions(-) diff --git a/WORKLOG.md b/WORKLOG.md index cdfa63f6..d8ff9e55 100644 --- a/WORKLOG.md +++ b/WORKLOG.md @@ -36,7 +36,6 @@ - Strike + SpeedRR -> StrikeSpeed (strike has Y% more speed) - Strike + LifeRR -> StrikeLife (Strike recharges X% of damage as red life) -* equip from shop (buy and equip without putting in your inventory) for bases * move item from one construct to another * ACP @@ -89,7 +88,6 @@ $$$ * Highlight (dota) colour * fx colours + styles -* ??? (PROBS NOT) drag and drop buy / equip / unequip items ??? * modules * troll life -> dmg * prince of peace diff --git a/client/src/components/instance.constructs.jsx b/client/src/components/instance.constructs.jsx index a8cd5ff2..cd6e4b3d 100644 --- a/client/src/components/instance.constructs.jsx +++ b/client/src/components/instance.constructs.jsx @@ -20,9 +20,14 @@ const addState = connect( itemInfo, itemEquip, navInstance, + vboxSelected, tutorial, } = state; + function sendVboxAcceptEquip(constructId) { + return ws.sendVboxAcceptEquip(instance.id, vboxSelected[0], vboxSelected[1], constructId); + } + function sendVboxApply(constructId, i) { return ws.sendVboxApply(instance.id, constructId, i); } @@ -35,11 +40,13 @@ const addState = connect( instance, player, account, + sendVboxAcceptEquip, sendVboxApply, itemInfo, itemEquip, navInstance, sendUnequip, + vboxSelected, tutorial, }; }, @@ -79,11 +86,13 @@ function Construct(props) { instance, mobileVisible, player, + vboxSelected, tutorial, // Static Info itemInfo, // Function Calls sendVboxApply, + sendVboxAcceptEquip, sendUnequip, setActiveConstruct, setItemUnequip, @@ -104,6 +113,7 @@ function Construct(props) { e.stopPropagation(); e.preventDefault(); if (duplicateSkill || tutorialDisableEquip) return true; + if (vboxSelected[0]) sendVboxAcceptEquip(construct.id); if (itemEquip !== null) sendVboxApply(construct.id, itemEquip); setItemEquip(null); return setActiveConstruct(construct); @@ -254,6 +264,7 @@ class InstanceConstructs extends preact.Component { // JSON or Array objects if (newProps.player !== this.props.player) return true; if (newProps.instance !== this.props.instance) return true; + if (newProps.vboxSelected !== this.props.vboxSelected) return true; return false; } @@ -265,12 +276,14 @@ class InstanceConstructs extends preact.Component { navInstance, player, tutorial, + vboxSelected, // Static data itemInfo, // Function calls setInfo, setActiveConstruct, sendVboxApply, + sendVboxAcceptEquip, setVboxHighlight, setItemUnequip, setItemEquip, @@ -293,11 +306,13 @@ class InstanceConstructs extends preact.Component { setItemEquip, player, sendVboxApply, + sendVboxAcceptEquip, setInfo, setActiveConstruct, itemInfo, setVboxHighlight, sendUnequip, + vboxSelected, tutorial, mobileVisible: navInstance === i + 1, }); diff --git a/client/src/socket.jsx b/client/src/socket.jsx index 340310b8..f25f6fa1 100644 --- a/client/src/socket.jsx +++ b/client/src/socket.jsx @@ -79,32 +79,30 @@ function createSocket(events) { function sendVboxAccept(instanceId, group, index) { send(['VboxAccept', { instance_id: instanceId, group, index }]); - events.clearInstance(); + } + + function sendVboxAcceptEquip(instanceId, group, index, constructId) { + send(['VboxAcceptEquip', { instance_id: instanceId, group, index, construct_id: constructId }]); } function sendVboxApply(instanceId, constructId, index) { send(['VboxApply', { instance_id: instanceId, construct_id: constructId, index }]); - events.clearInstance(); } function sendVboxUnequip(instanceId, constructId, target) { send(['VboxUnequip', { instance_id: instanceId, construct_id: constructId, target }]); - events.clearInstance(); } function sendVboxDiscard(instanceId) { send(['VboxDiscard', { instance_id: instanceId }]); - events.clearInstance(); } function sendVboxCombine(instanceId, indices) { send(['VboxCombine', { instance_id: instanceId, indices }]); - events.clearCombiner(); } function sendVboxReclaim(instanceId, index) { send(['VboxReclaim', { instance_id: instanceId, index }]); - events.clearInstance(); } function sendItemInfo() { @@ -382,6 +380,7 @@ function createSocket(events) { sendInstanceChat, sendVboxAccept, + sendVboxAcceptEquip, sendVboxApply, sendVboxReclaim, sendVboxCombine, diff --git a/server/src/instance.rs b/server/src/instance.rs index 2e65b9d6..174b225b 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -473,10 +473,10 @@ impl Instance { Ok(self) } - pub fn vbox_accept(mut self, account: Uuid, group: usize, index: usize) -> Result { + pub fn vbox_accept(mut self, account: Uuid, group: usize, index: usize, construct_id: Option) -> Result { self.vbox_action_allowed(account)?; self.account_player(account)? - .vbox_accept(group, index)?; + .vbox_accept(group, index, construct_id)?; Ok(self) } diff --git a/server/src/player.rs b/server/src/player.rs index 994d7f4c..fe62846e 100644 --- a/server/src/player.rs +++ b/server/src/player.rs @@ -256,8 +256,12 @@ impl Player { Ok(self) } - pub fn vbox_accept(&mut self, group: usize, index: usize) -> Result<&mut Player, Error> { - self.vbox.accept(group, index)?; + pub fn vbox_accept(&mut self, group: usize, index: usize, construct_id: Option) -> Result<&mut Player, Error> { + self.vbox.accept(group, index, construct_id)?; + if construct_id.is_some() { + let equip_index = self.vbox.bound.len() - 1; + self.vbox_apply(equip_index, construct_id.expect("no construct"))?; + } Ok(self) } diff --git a/server/src/rpc.rs b/server/src/rpc.rs index 29d89d34..90a4320e 100644 --- a/server/src/rpc.rs +++ b/server/src/rpc.rs @@ -113,6 +113,7 @@ pub enum RpcRequest { InstanceChat { instance_id: Uuid, index: usize }, VboxAccept { instance_id: Uuid, group: usize, index: usize }, + VboxAcceptEquip { instance_id: Uuid, group: usize, index: usize, construct_id: Uuid }, VboxDiscard { instance_id: Uuid }, VboxCombine { instance_id: Uuid, indices: Vec }, VboxApply { instance_id: Uuid, construct_id: Uuid, index: usize }, @@ -235,7 +236,10 @@ impl Connection { Ok(instance_abandon(&mut tx, account, instance_id)?), RpcRequest::VboxAccept { instance_id, group, index } => - Ok(RpcMessage::InstanceState(vbox_accept(&mut tx, account, instance_id, group, index)?)), + Ok(RpcMessage::InstanceState(vbox_accept(&mut tx, account, instance_id, group, index, None)?)), + + RpcRequest::VboxAcceptEquip { instance_id, group, index, construct_id } => + Ok(RpcMessage::InstanceState(vbox_accept(&mut tx, account, instance_id, group, index, Some(construct_id))?)), RpcRequest::VboxApply { instance_id, construct_id, index } => Ok(RpcMessage::InstanceState(vbox_apply(&mut tx, account, instance_id, construct_id, index)?)), diff --git a/server/src/vbox.rs b/server/src/vbox.rs index 162f48de..73356c13 100644 --- a/server/src/vbox.rs +++ b/server/src/vbox.rs @@ -99,8 +99,8 @@ impl Vbox { self } - pub fn accept(&mut self, i: usize, j: usize) -> Result<&mut Vbox, Error> { - if self.bound.len() >= 9 { + pub fn accept(&mut self, i: usize, j: usize, construct_id: Option) -> Result<&mut Vbox, Error> { + if self.bound.len() >= 9 && !construct_id.is_some() { return Err(err_msg("too many items bound")); } @@ -130,7 +130,7 @@ impl Vbox { pub fn bot_accept(&mut self, i: usize) -> Result<&mut Vbox, Error> { let buy_index = self.free[i].iter().position(|item| item.is_some()); - self.accept(i, buy_index.expect("no valid buys")) + self.accept(i, buy_index.expect("no valid buys"), None) } pub fn reclaim(&mut self, i: usize) -> Result<&mut Vbox, Error> { @@ -181,9 +181,9 @@ pub fn vbox_discard(tx: &mut Transaction, account: &Account, instance_id: Uuid) return instance_update(tx, instance); } -pub fn vbox_accept(tx: &mut Transaction, account: &Account, instance_id: Uuid, group: usize, index: usize) -> Result { +pub fn vbox_accept(tx: &mut Transaction, account: &Account, instance_id: Uuid, group: usize, index: usize, construct_id: Option) -> Result { let instance = instance_get(tx, instance_id)? - .vbox_accept(account.id, group, index)?; + .vbox_accept(account.id, group, index, construct_id)?; return instance_update(tx, instance); } From 165c0b82a3d1437c14704918d1bece96d5bbe15b Mon Sep 17 00:00:00 2001 From: Mashy Date: Tue, 5 Nov 2019 10:39:12 +1000 Subject: [PATCH 2/3] vboxUnequipApply aka swap construct items --- client/src/components/instance.constructs.jsx | 22 +++++++++++++++---- client/src/socket.jsx | 5 +++++ server/src/instance.rs | 4 ++-- server/src/player.rs | 11 +++++++--- server/src/rpc.rs | 6 ++++- server/src/vbox.rs | 4 ++-- 6 files changed, 40 insertions(+), 12 deletions(-) diff --git a/client/src/components/instance.constructs.jsx b/client/src/components/instance.constructs.jsx index cd6e4b3d..b69e69bd 100644 --- a/client/src/components/instance.constructs.jsx +++ b/client/src/components/instance.constructs.jsx @@ -19,6 +19,7 @@ const addState = connect( account, itemInfo, itemEquip, + itemUnequip, navInstance, vboxSelected, tutorial, @@ -36,14 +37,20 @@ const addState = connect( return ws.sendVboxUnequip(instance.id, constructId, item); } + function sendVboxUnequipApply(targetConstructId) { + return ws.sendVboxUnequipApply(instance.id, itemUnequip[0], itemUnequip[1], targetConstructId); + } + return { instance, player, account, sendVboxAcceptEquip, + sendVboxUnequipApply, sendVboxApply, itemInfo, itemEquip, + itemUnequip, navInstance, sendUnequip, vboxSelected, @@ -83,6 +90,7 @@ function Construct(props) { construct, iter, itemEquip, + itemUnequip, instance, mobileVisible, player, @@ -93,13 +101,13 @@ function Construct(props) { // Function Calls sendVboxApply, sendVboxAcceptEquip, + sendVboxUnequipApply, sendUnequip, setActiveConstruct, setItemUnequip, setItemEquip, setInfo, } = props; - const { vbox } = player; const duplicateSkill = construct.skills.length !== 0 && construct.skills.every(sk => { @@ -108,15 +116,16 @@ function Construct(props) { return sk.skill === vbox.bound[itemEquip]; }); const tutorialDisableEquip = tutorialShouldDisableEquip(tutorial, iter, instance, construct); - function onClick(e) { e.stopPropagation(); e.preventDefault(); if (duplicateSkill || tutorialDisableEquip) return true; - if (vboxSelected[0]) sendVboxAcceptEquip(construct.id); if (itemEquip !== null) sendVboxApply(construct.id, itemEquip); + if (vboxSelected[0]) sendVboxAcceptEquip(construct.id); + if (itemUnequip.length && itemUnequip[0] !== construct.id) sendVboxUnequipApply(construct.id); setItemEquip(null); - return setActiveConstruct(construct); + setItemUnequip([]); + return true; } function hoverInfo(e, info) { @@ -259,6 +268,7 @@ function Construct(props) { class InstanceConstructs extends preact.Component { shouldComponentUpdate(newProps) { if (newProps.itemEquip !== this.props.itemEquip) return true; + if (newProps.itemUnequip !== this.props.itemUnequip) return true; if (newProps.tutorial !== this.props.tutorial) return true; if (newProps.navInstance !== this.props.navInstance) return true; // JSON or Array objects @@ -272,6 +282,7 @@ class InstanceConstructs extends preact.Component { const { // Changing state variables itemEquip, + itemUnequip, instance, navInstance, player, @@ -284,6 +295,7 @@ class InstanceConstructs extends preact.Component { setActiveConstruct, sendVboxApply, sendVboxAcceptEquip, + sendVboxUnequipApply, setVboxHighlight, setItemUnequip, setItemEquip, @@ -301,12 +313,14 @@ class InstanceConstructs extends preact.Component { iter: i, construct: player.constructs[i], itemEquip, + itemUnequip, instance, setItemUnequip, setItemEquip, player, sendVboxApply, sendVboxAcceptEquip, + sendVboxUnequipApply, setInfo, setActiveConstruct, itemInfo, diff --git a/client/src/socket.jsx b/client/src/socket.jsx index f25f6fa1..af3ece81 100644 --- a/client/src/socket.jsx +++ b/client/src/socket.jsx @@ -93,6 +93,10 @@ function createSocket(events) { send(['VboxUnequip', { instance_id: instanceId, construct_id: constructId, target }]); } + function sendVboxUnequipApply(instanceId, constructId, target, targetConstructId) { + send(['VboxUnequipApply', { instance_id: instanceId, construct_id: constructId, target, target_construct_id: targetConstructId }]); + } + function sendVboxDiscard(instanceId) { send(['VboxDiscard', { instance_id: instanceId }]); } @@ -386,6 +390,7 @@ function createSocket(events) { sendVboxCombine, sendVboxDiscard, sendVboxUnequip, + sendVboxUnequipApply, sendItemInfo, diff --git a/server/src/instance.rs b/server/src/instance.rs index 174b225b..5dc79652 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -501,10 +501,10 @@ impl Instance { Ok(self) } - pub fn vbox_unequip(mut self, account: Uuid, target: Item, construct_id: Uuid) -> Result { + pub fn vbox_unequip(mut self, account: Uuid, target: Item, construct_id: Uuid, target_construct_id: Option) -> Result { self.vbox_action_allowed(account)?; self.account_player(account)? - .vbox_unequip(target, construct_id)?; + .vbox_unequip(target, construct_id, target_construct_id)?; Ok(self) } } diff --git a/server/src/player.rs b/server/src/player.rs index fe62846e..0e0baf56 100644 --- a/server/src/player.rs +++ b/server/src/player.rs @@ -324,8 +324,8 @@ impl Player { Ok(self) } - pub fn vbox_unequip(&mut self, target: Item, construct_id: Uuid) -> Result<&mut Player, Error> { - if self.vbox.bound.len() >= 9 { + pub fn vbox_unequip(&mut self, target: Item, construct_id: Uuid, target_construct_id: Option) -> Result<&mut Player, Error> { + if self.vbox.bound.len() >= 9 && !target_construct_id.is_some() { return Err(err_msg("too many items bound")); } @@ -358,7 +358,12 @@ impl Player { } self.vbox.bound.push(target); - self.vbox.bound.sort_unstable(); + + if target_construct_id.is_some() { + let equip_index = self.vbox.bound.len() - 1; + self.vbox_apply(equip_index, target_construct_id.expect("no construct"))?; + } + // self.vbox.bound.sort_unstable(); Ok(self) } diff --git a/server/src/rpc.rs b/server/src/rpc.rs index 90a4320e..253f6bcb 100644 --- a/server/src/rpc.rs +++ b/server/src/rpc.rs @@ -118,6 +118,7 @@ pub enum RpcRequest { VboxCombine { instance_id: Uuid, indices: Vec }, VboxApply { instance_id: Uuid, construct_id: Uuid, index: usize }, VboxUnequip { instance_id: Uuid, construct_id: Uuid, target: Item }, + VboxUnequipApply { instance_id: Uuid, construct_id: Uuid, target: Item, target_construct_id: Uuid }, VboxReclaim { instance_id: Uuid, index: usize }, } @@ -254,7 +255,10 @@ impl Connection { Ok(RpcMessage::InstanceState(vbox_reclaim(&mut tx, account, instance_id, index)?)), RpcRequest::VboxUnequip { instance_id, construct_id, target } => - Ok(RpcMessage::InstanceState(vbox_unequip(&mut tx, account, instance_id, construct_id, target)?)), + Ok(RpcMessage::InstanceState(vbox_unequip(&mut tx, account, instance_id, construct_id, target, None)?)), + + RpcRequest::VboxUnequipApply { instance_id, construct_id, target, target_construct_id } => + Ok(RpcMessage::InstanceState(vbox_unequip(&mut tx, account, instance_id, construct_id, target, Some(target_construct_id))?)), RpcRequest::MtxConstructSpawn {} => Ok(RpcMessage::ConstructSpawn(mtx::new_construct(&mut tx, account)?)), diff --git a/server/src/vbox.rs b/server/src/vbox.rs index 73356c13..3488b14d 100644 --- a/server/src/vbox.rs +++ b/server/src/vbox.rs @@ -205,9 +205,9 @@ pub fn vbox_apply(tx: &mut Transaction, account: &Account, instance_id: Uuid, co return instance_update(tx, instance); } -pub fn vbox_unequip(tx: &mut Transaction, account: &Account, instance_id: Uuid, construct_id: Uuid, target: Item) -> Result { +pub fn vbox_unequip(tx: &mut Transaction, account: &Account, instance_id: Uuid, construct_id: Uuid, target: Item, target_construct_id: Option) -> Result { let instance = instance_get(tx, instance_id)? - .vbox_unequip(account.id, target, construct_id)?; + .vbox_unequip(account.id, target, construct_id, target_construct_id)?; return instance_update(tx, instance); } From 6809e2016b118eb475c86b8295f8282b78fb28c5 Mon Sep 17 00:00:00 2001 From: Mashy Date: Tue, 5 Nov 2019 11:01:52 +1000 Subject: [PATCH 3/3] add clear instance back --- client/src/components/instance.constructs.jsx | 6 +++--- client/src/events.jsx | 1 + client/src/socket.jsx | 8 ++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/client/src/components/instance.constructs.jsx b/client/src/components/instance.constructs.jsx index b69e69bd..9aa57ffc 100644 --- a/client/src/components/instance.constructs.jsx +++ b/client/src/components/instance.constructs.jsx @@ -120,9 +120,9 @@ function Construct(props) { e.stopPropagation(); e.preventDefault(); if (duplicateSkill || tutorialDisableEquip) return true; - if (itemEquip !== null) sendVboxApply(construct.id, itemEquip); - if (vboxSelected[0]) sendVboxAcceptEquip(construct.id); - if (itemUnequip.length && itemUnequip[0] !== construct.id) sendVboxUnequipApply(construct.id); + if (itemEquip !== null) return sendVboxApply(construct.id, itemEquip); + if (vboxSelected[0]) return sendVboxAcceptEquip(construct.id); + if (itemUnequip.length && itemUnequip[0] !== construct.id) return sendVboxUnequipApply(construct.id); setItemEquip(null); setItemUnequip([]); return true; diff --git a/client/src/events.jsx b/client/src/events.jsx index 5515ddba..c295e0e5 100644 --- a/client/src/events.jsx +++ b/client/src/events.jsx @@ -190,6 +190,7 @@ function registerEvents(store) { store.dispatch(actions.setItemEquip(null)); store.dispatch(actions.setItemUnequip([])); store.dispatch(actions.setVboxHighlight([])); + store.dispatch(actions.setVboxSelected([])); } function setAccountInstances(v) { diff --git a/client/src/socket.jsx b/client/src/socket.jsx index af3ece81..b89bc187 100644 --- a/client/src/socket.jsx +++ b/client/src/socket.jsx @@ -79,34 +79,42 @@ function createSocket(events) { function sendVboxAccept(instanceId, group, index) { send(['VboxAccept', { instance_id: instanceId, group, index }]); + events.clearInstance(); } function sendVboxAcceptEquip(instanceId, group, index, constructId) { send(['VboxAcceptEquip', { instance_id: instanceId, group, index, construct_id: constructId }]); + events.clearInstance(); } function sendVboxApply(instanceId, constructId, index) { send(['VboxApply', { instance_id: instanceId, construct_id: constructId, index }]); + events.clearInstance(); } function sendVboxUnequip(instanceId, constructId, target) { send(['VboxUnequip', { instance_id: instanceId, construct_id: constructId, target }]); + events.clearInstance(); } function sendVboxUnequipApply(instanceId, constructId, target, targetConstructId) { send(['VboxUnequipApply', { instance_id: instanceId, construct_id: constructId, target, target_construct_id: targetConstructId }]); + events.clearInstance(); } function sendVboxDiscard(instanceId) { send(['VboxDiscard', { instance_id: instanceId }]); + events.clearInstance(); } function sendVboxCombine(instanceId, indices) { send(['VboxCombine', { instance_id: instanceId, indices }]); + events.clearInstance(); } function sendVboxReclaim(instanceId, index) { send(['VboxReclaim', { instance_id: instanceId, index }]); + events.clearInstance(); } function sendItemInfo() {