pay for constructs
This commit is contained in:
parent
f295235b52
commit
84c0a187c2
@ -10,7 +10,8 @@ use failure::err_msg;
|
||||
use account;
|
||||
use account::Account;
|
||||
|
||||
use construct::{Construct, construct_select, construct_write};
|
||||
use construct::{Construct, construct_select, construct_write, construct_spawn};
|
||||
use names::{name as generate_name};
|
||||
use img;
|
||||
|
||||
pub const FREE_MTX: [MtxVariant; 1] = [
|
||||
@ -22,6 +23,10 @@ pub const SHOP_LISTINGS: [Listing; 2] = [
|
||||
Listing { variant: MtxVariant::Invader, credits: 10 },
|
||||
];
|
||||
|
||||
const NEW_IMAGE_COST: i64 = 1;
|
||||
const NEW_NAME_COST: i64 = 5;
|
||||
const NEW_CONSTRUCT_COST: i64 = 50;
|
||||
|
||||
#[derive(Debug,Clone,PartialEq,Serialize,Deserialize)]
|
||||
pub struct Shop {
|
||||
owned: Vec<MtxVariant>,
|
||||
@ -71,8 +76,11 @@ pub struct Mtx {
|
||||
pub fn apply(tx: &mut Transaction, account: &Account, variant: MtxVariant, construct_id: Uuid, name: String) -> Result<Vec<Construct>, Error> {
|
||||
let mtx = select(tx, variant, account.id)?;
|
||||
let mut construct = construct_select(tx, construct_id, account.id)?;
|
||||
|
||||
account::debit(tx, account.id, 1)?;
|
||||
let cost = match mtx.variant {
|
||||
MtxVariant::Rename => NEW_NAME_COST,
|
||||
_ => NEW_IMAGE_COST,
|
||||
};
|
||||
account::debit(tx, account.id, cost)?;
|
||||
|
||||
construct = match mtx.variant {
|
||||
MtxVariant::Rename => construct.new_name(name),
|
||||
@ -112,6 +120,12 @@ pub fn select(tx: &mut Transaction, variant: MtxVariant, account: Uuid) -> Resul
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_construct(tx: &mut Transaction, account: &Account) -> Result<Construct, Error> {
|
||||
account::debit(tx, account.id, NEW_CONSTRUCT_COST)?;
|
||||
let construct = construct_spawn(tx, account.id, generate_name())?;
|
||||
Ok(construct)
|
||||
}
|
||||
|
||||
impl Mtx {
|
||||
pub fn new(variant: MtxVariant, account: Uuid) -> Mtx {
|
||||
match variant {
|
||||
|
||||
@ -8,17 +8,14 @@ use failure::Error;
|
||||
use failure::err_msg;
|
||||
|
||||
use pg::{Db};
|
||||
use construct::{Construct, construct_spawn};
|
||||
use construct::{Construct};
|
||||
use game::{Game, game_state, game_skill, game_ready};
|
||||
use account::{Account, account_constructs, account_instances};
|
||||
use account::{Account, account_constructs};
|
||||
use skill::{Skill, dev_resolve, Resolutions};
|
||||
use instance::{Instance, instance_state, instance_list, instance_new, instance_ready, instance_join};
|
||||
use vbox::{vbox_accept, vbox_apply, vbox_discard, vbox_combine, vbox_reclaim, vbox_unequip};
|
||||
use item::{Item, ItemInfoCtr, item_info};
|
||||
|
||||
use names::{name as generate_name};
|
||||
|
||||
|
||||
use mtx;
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
@ -154,7 +151,7 @@ pub fn receive(data: Vec<u8>, db: &Db, begin: Instant, account: &Option<Account>
|
||||
Ok(RpcMessage::InstanceState(vbox_unequip(&mut tx, account, instance_id, construct_id, target)?)),
|
||||
|
||||
RpcRequest::MtxConstructBuy {} =>
|
||||
Ok(RpcMessage::ConstructSpawn(construct_spawn(&mut tx, account.id, generate_name())?)),
|
||||
Ok(RpcMessage::ConstructSpawn(mtx::new_construct(&mut tx, account)?)),
|
||||
|
||||
RpcRequest::MtxConstructApply { mtx, construct_id, name } =>
|
||||
Ok(RpcMessage::AccountConstructs(mtx::apply(&mut tx, account, mtx, construct_id, name)?)),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user