vboxUnequipApply aka swap construct items
This commit is contained in:
parent
e5314a2257
commit
165c0b82a3
@ -19,6 +19,7 @@ const addState = connect(
|
|||||||
account,
|
account,
|
||||||
itemInfo,
|
itemInfo,
|
||||||
itemEquip,
|
itemEquip,
|
||||||
|
itemUnequip,
|
||||||
navInstance,
|
navInstance,
|
||||||
vboxSelected,
|
vboxSelected,
|
||||||
tutorial,
|
tutorial,
|
||||||
@ -36,14 +37,20 @@ const addState = connect(
|
|||||||
return ws.sendVboxUnequip(instance.id, constructId, item);
|
return ws.sendVboxUnequip(instance.id, constructId, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sendVboxUnequipApply(targetConstructId) {
|
||||||
|
return ws.sendVboxUnequipApply(instance.id, itemUnequip[0], itemUnequip[1], targetConstructId);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
instance,
|
instance,
|
||||||
player,
|
player,
|
||||||
account,
|
account,
|
||||||
sendVboxAcceptEquip,
|
sendVboxAcceptEquip,
|
||||||
|
sendVboxUnequipApply,
|
||||||
sendVboxApply,
|
sendVboxApply,
|
||||||
itemInfo,
|
itemInfo,
|
||||||
itemEquip,
|
itemEquip,
|
||||||
|
itemUnequip,
|
||||||
navInstance,
|
navInstance,
|
||||||
sendUnequip,
|
sendUnequip,
|
||||||
vboxSelected,
|
vboxSelected,
|
||||||
@ -83,6 +90,7 @@ function Construct(props) {
|
|||||||
construct,
|
construct,
|
||||||
iter,
|
iter,
|
||||||
itemEquip,
|
itemEquip,
|
||||||
|
itemUnequip,
|
||||||
instance,
|
instance,
|
||||||
mobileVisible,
|
mobileVisible,
|
||||||
player,
|
player,
|
||||||
@ -93,13 +101,13 @@ function Construct(props) {
|
|||||||
// Function Calls
|
// Function Calls
|
||||||
sendVboxApply,
|
sendVboxApply,
|
||||||
sendVboxAcceptEquip,
|
sendVboxAcceptEquip,
|
||||||
|
sendVboxUnequipApply,
|
||||||
sendUnequip,
|
sendUnequip,
|
||||||
setActiveConstruct,
|
setActiveConstruct,
|
||||||
setItemUnequip,
|
setItemUnequip,
|
||||||
setItemEquip,
|
setItemEquip,
|
||||||
setInfo,
|
setInfo,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const { vbox } = player;
|
const { vbox } = player;
|
||||||
|
|
||||||
const duplicateSkill = construct.skills.length !== 0 && construct.skills.every(sk => {
|
const duplicateSkill = construct.skills.length !== 0 && construct.skills.every(sk => {
|
||||||
@ -108,15 +116,16 @@ function Construct(props) {
|
|||||||
return sk.skill === vbox.bound[itemEquip];
|
return sk.skill === vbox.bound[itemEquip];
|
||||||
});
|
});
|
||||||
const tutorialDisableEquip = tutorialShouldDisableEquip(tutorial, iter, instance, construct);
|
const tutorialDisableEquip = tutorialShouldDisableEquip(tutorial, iter, instance, construct);
|
||||||
|
|
||||||
function onClick(e) {
|
function onClick(e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (duplicateSkill || tutorialDisableEquip) return true;
|
if (duplicateSkill || tutorialDisableEquip) return true;
|
||||||
if (vboxSelected[0]) sendVboxAcceptEquip(construct.id);
|
|
||||||
if (itemEquip !== null) sendVboxApply(construct.id, itemEquip);
|
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);
|
setItemEquip(null);
|
||||||
return setActiveConstruct(construct);
|
setItemUnequip([]);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function hoverInfo(e, info) {
|
function hoverInfo(e, info) {
|
||||||
@ -259,6 +268,7 @@ function Construct(props) {
|
|||||||
class InstanceConstructs extends preact.Component {
|
class InstanceConstructs extends preact.Component {
|
||||||
shouldComponentUpdate(newProps) {
|
shouldComponentUpdate(newProps) {
|
||||||
if (newProps.itemEquip !== this.props.itemEquip) return true;
|
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.tutorial !== this.props.tutorial) return true;
|
||||||
if (newProps.navInstance !== this.props.navInstance) return true;
|
if (newProps.navInstance !== this.props.navInstance) return true;
|
||||||
// JSON or Array objects
|
// JSON or Array objects
|
||||||
@ -272,6 +282,7 @@ class InstanceConstructs extends preact.Component {
|
|||||||
const {
|
const {
|
||||||
// Changing state variables
|
// Changing state variables
|
||||||
itemEquip,
|
itemEquip,
|
||||||
|
itemUnequip,
|
||||||
instance,
|
instance,
|
||||||
navInstance,
|
navInstance,
|
||||||
player,
|
player,
|
||||||
@ -284,6 +295,7 @@ class InstanceConstructs extends preact.Component {
|
|||||||
setActiveConstruct,
|
setActiveConstruct,
|
||||||
sendVboxApply,
|
sendVboxApply,
|
||||||
sendVboxAcceptEquip,
|
sendVboxAcceptEquip,
|
||||||
|
sendVboxUnequipApply,
|
||||||
setVboxHighlight,
|
setVboxHighlight,
|
||||||
setItemUnequip,
|
setItemUnequip,
|
||||||
setItemEquip,
|
setItemEquip,
|
||||||
@ -301,12 +313,14 @@ class InstanceConstructs extends preact.Component {
|
|||||||
iter: i,
|
iter: i,
|
||||||
construct: player.constructs[i],
|
construct: player.constructs[i],
|
||||||
itemEquip,
|
itemEquip,
|
||||||
|
itemUnequip,
|
||||||
instance,
|
instance,
|
||||||
setItemUnequip,
|
setItemUnequip,
|
||||||
setItemEquip,
|
setItemEquip,
|
||||||
player,
|
player,
|
||||||
sendVboxApply,
|
sendVboxApply,
|
||||||
sendVboxAcceptEquip,
|
sendVboxAcceptEquip,
|
||||||
|
sendVboxUnequipApply,
|
||||||
setInfo,
|
setInfo,
|
||||||
setActiveConstruct,
|
setActiveConstruct,
|
||||||
itemInfo,
|
itemInfo,
|
||||||
|
|||||||
@ -93,6 +93,10 @@ function createSocket(events) {
|
|||||||
send(['VboxUnequip', { instance_id: instanceId, construct_id: constructId, target }]);
|
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) {
|
function sendVboxDiscard(instanceId) {
|
||||||
send(['VboxDiscard', { instance_id: instanceId }]);
|
send(['VboxDiscard', { instance_id: instanceId }]);
|
||||||
}
|
}
|
||||||
@ -386,6 +390,7 @@ function createSocket(events) {
|
|||||||
sendVboxCombine,
|
sendVboxCombine,
|
||||||
sendVboxDiscard,
|
sendVboxDiscard,
|
||||||
sendVboxUnequip,
|
sendVboxUnequip,
|
||||||
|
sendVboxUnequipApply,
|
||||||
|
|
||||||
sendItemInfo,
|
sendItemInfo,
|
||||||
|
|
||||||
|
|||||||
@ -501,10 +501,10 @@ impl Instance {
|
|||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vbox_unequip(mut self, account: Uuid, target: Item, construct_id: Uuid) -> Result<Instance, Error> {
|
pub fn vbox_unequip(mut self, account: Uuid, target: Item, construct_id: Uuid, target_construct_id: Option<Uuid>) -> Result<Instance, Error> {
|
||||||
self.vbox_action_allowed(account)?;
|
self.vbox_action_allowed(account)?;
|
||||||
self.account_player(account)?
|
self.account_player(account)?
|
||||||
.vbox_unequip(target, construct_id)?;
|
.vbox_unequip(target, construct_id, target_construct_id)?;
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -324,8 +324,8 @@ impl Player {
|
|||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vbox_unequip(&mut self, target: Item, construct_id: Uuid) -> Result<&mut Player, Error> {
|
pub fn vbox_unequip(&mut self, target: Item, construct_id: Uuid, target_construct_id: Option<Uuid>) -> Result<&mut Player, Error> {
|
||||||
if self.vbox.bound.len() >= 9 {
|
if self.vbox.bound.len() >= 9 && !target_construct_id.is_some() {
|
||||||
return Err(err_msg("too many items bound"));
|
return Err(err_msg("too many items bound"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,7 +358,12 @@ impl Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.vbox.bound.push(target);
|
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)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -118,6 +118,7 @@ pub enum RpcRequest {
|
|||||||
VboxCombine { instance_id: Uuid, indices: Vec<usize> },
|
VboxCombine { instance_id: Uuid, indices: Vec<usize> },
|
||||||
VboxApply { instance_id: Uuid, construct_id: Uuid, index: usize },
|
VboxApply { instance_id: Uuid, construct_id: Uuid, index: usize },
|
||||||
VboxUnequip { instance_id: Uuid, construct_id: Uuid, target: Item },
|
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 },
|
VboxReclaim { instance_id: Uuid, index: usize },
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,7 +255,10 @@ impl Connection {
|
|||||||
Ok(RpcMessage::InstanceState(vbox_reclaim(&mut tx, account, instance_id, index)?)),
|
Ok(RpcMessage::InstanceState(vbox_reclaim(&mut tx, account, instance_id, index)?)),
|
||||||
|
|
||||||
RpcRequest::VboxUnequip { instance_id, construct_id, target } =>
|
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 {} =>
|
RpcRequest::MtxConstructSpawn {} =>
|
||||||
Ok(RpcMessage::ConstructSpawn(mtx::new_construct(&mut tx, account)?)),
|
Ok(RpcMessage::ConstructSpawn(mtx::new_construct(&mut tx, account)?)),
|
||||||
|
|||||||
@ -205,9 +205,9 @@ pub fn vbox_apply(tx: &mut Transaction, account: &Account, instance_id: Uuid, co
|
|||||||
return instance_update(tx, instance);
|
return instance_update(tx, instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vbox_unequip(tx: &mut Transaction, account: &Account, instance_id: Uuid, construct_id: Uuid, target: Item) -> Result<Instance, Error> {
|
pub fn vbox_unequip(tx: &mut Transaction, account: &Account, instance_id: Uuid, construct_id: Uuid, target: Item, target_construct_id: Option<Uuid>) -> Result<Instance, Error> {
|
||||||
let instance = instance_get(tx, instance_id)?
|
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);
|
return instance_update(tx, instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user