Merge branch 'master' of ssh://cryps.gg:40022/~/cryps
This commit is contained in:
commit
904a1e8a56
@ -202,6 +202,11 @@ impl Cryp {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn learn_mut(&mut self, s: Skill) -> &mut Cryp {
|
||||||
|
self.skills.push(CrypSkill::new(s));
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn forget(mut self, skill: Skill) -> Result<Cryp, Error> {
|
pub fn forget(mut self, skill: Skill) -> Result<Cryp, Error> {
|
||||||
match self.skills.iter().position(|s| s.skill == skill) {
|
match self.skills.iter().position(|s| s.skill == skill) {
|
||||||
Some(i) => {
|
Some(i) => {
|
||||||
|
|||||||
@ -70,6 +70,21 @@ impl Instance {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn player_update(mut self, player: Player) -> Result<Instance, Error> {
|
||||||
|
if self.phase != InstancePhase::Vbox {
|
||||||
|
return Err(err_msg("instance not in vbox phase"));
|
||||||
|
}
|
||||||
|
|
||||||
|
let i = self.players
|
||||||
|
.iter()
|
||||||
|
.position(|p| p.id == player.id)
|
||||||
|
.ok_or(err_msg("player_id not found"))?;
|
||||||
|
|
||||||
|
self.players[i] = player;
|
||||||
|
|
||||||
|
Ok(self)
|
||||||
|
}
|
||||||
|
|
||||||
fn player_ready(mut self, mut player: Player) -> Result<Instance, Error> {
|
fn player_ready(mut self, mut player: Player) -> Result<Instance, Error> {
|
||||||
if self.phase != InstancePhase::Vbox {
|
if self.phase != InstancePhase::Vbox {
|
||||||
panic!("instance not in vbox phase");
|
panic!("instance not in vbox phase");
|
||||||
@ -278,7 +293,7 @@ impl Instance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn instance_create(instance: Instance, tx: &mut Transaction) -> Result<Instance, Error> {
|
pub fn instance_create(tx: &mut Transaction, instance: Instance) -> Result<Instance, Error> {
|
||||||
let instance_bytes = to_vec(&instance)?;
|
let instance_bytes = to_vec(&instance)?;
|
||||||
|
|
||||||
let query = "
|
let query = "
|
||||||
@ -295,7 +310,7 @@ pub fn instance_create(instance: Instance, tx: &mut Transaction) -> Result<Insta
|
|||||||
return Ok(instance);
|
return Ok(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn instance_write(instance: Instance, tx: &mut Transaction) -> Result<Instance, Error> {
|
pub fn instance_update(tx: &mut Transaction, instance: Instance) -> Result<Instance, Error> {
|
||||||
let instance_bytes = to_vec(&instance)?;
|
let instance_bytes = to_vec(&instance)?;
|
||||||
|
|
||||||
let query = "
|
let query = "
|
||||||
@ -360,10 +375,10 @@ pub fn instance_get_open(tx: &mut Transaction) -> Result<Instance, Error> {
|
|||||||
|
|
||||||
pub fn instance_join(params: InstanceJoinParams, tx: &mut Transaction, account: &Account) -> Result<Player, Error> {
|
pub fn instance_join(params: InstanceJoinParams, tx: &mut Transaction, account: &Account) -> Result<Player, Error> {
|
||||||
let mut instance = match params.pve {
|
let mut instance = match params.pve {
|
||||||
true => instance_create(Instance::new().add_bots(), tx)?,
|
true => instance_create(tx, Instance::new().add_bots())?,
|
||||||
false => match instance_get_open(tx) {
|
false => match instance_get_open(tx) {
|
||||||
Ok(i) => i,
|
Ok(i) => i,
|
||||||
Err(_) => instance_create(Instance::new(), tx)?,
|
Err(_) => instance_create(tx, Instance::new())?,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -385,7 +400,7 @@ pub fn instance_join(params: InstanceJoinParams, tx: &mut Transaction, account:
|
|||||||
instance.start();
|
instance.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
instance_write(instance, tx)?;
|
instance_update(tx, instance)?;
|
||||||
|
|
||||||
return Ok(player);
|
return Ok(player);
|
||||||
}
|
}
|
||||||
@ -414,7 +429,7 @@ pub fn instance_ready(params: InstanceReadyParams, tx: &mut Transaction, account
|
|||||||
};
|
};
|
||||||
|
|
||||||
player_update(tx, player)?;
|
player_update(tx, player)?;
|
||||||
instance_write(instance, tx)?;
|
instance_update(tx, instance)?;
|
||||||
return Ok(game);
|
return Ok(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,7 @@ use account::Account;
|
|||||||
use cryp::{Cryp, cryp_get};
|
use cryp::{Cryp, cryp_get};
|
||||||
use vbox::{Vbox};
|
use vbox::{Vbox};
|
||||||
use rpc::{PlayerStateParams, PlayerCrypsSetParams};
|
use rpc::{PlayerStateParams, PlayerCrypsSetParams};
|
||||||
|
use instance::{Instance, instance_get, instance_update};
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
pub struct Score {
|
pub struct Score {
|
||||||
@ -64,6 +65,10 @@ impl Player {
|
|||||||
self.score.losses += 1;
|
self.score.losses += 1;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn cryp_get(&mut self, id: Uuid) -> Result<&mut Cryp, Error> {
|
||||||
|
self.cryps.iter_mut().find(|c| c.id == id).ok_or(err_msg("cryp not found"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn player_get(tx: &mut Transaction, account_id: Uuid, instance_id: Uuid) -> Result<Player, Error> {
|
pub fn player_get(tx: &mut Transaction, account_id: Uuid, instance_id: Uuid) -> Result<Player, Error> {
|
||||||
@ -109,6 +114,14 @@ pub fn player_create(tx: &mut Transaction, player: &Player, account: &Account) -
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn player_update(tx: &mut Transaction, player: Player) -> Result<Player, Error> {
|
pub fn player_update(tx: &mut Transaction, player: Player) -> Result<Player, Error> {
|
||||||
|
// update the instance this player is associated with
|
||||||
|
// if not a global player
|
||||||
|
if player.instance != Uuid::nil() {
|
||||||
|
let instance = instance_get(tx, player.instance)?
|
||||||
|
.player_update(player.clone())?;
|
||||||
|
instance_update(tx, instance)?;
|
||||||
|
}
|
||||||
|
|
||||||
let bytes = to_vec(&player)?;
|
let bytes = to_vec(&player)?;
|
||||||
|
|
||||||
let query = "
|
let query = "
|
||||||
@ -123,6 +136,7 @@ pub fn player_update(tx: &mut Transaction, player: Player) -> Result<Player, Err
|
|||||||
|
|
||||||
result.iter().next().ok_or(format_err!("player {:?} could not be written", player))?;
|
result.iter().next().ok_or(format_err!("player {:?} could not be written", player))?;
|
||||||
|
|
||||||
|
|
||||||
return Ok(player)
|
return Ok(player)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -302,19 +302,21 @@ pub fn vbox_drop(params: VboxDropParams, tx: &mut Transaction, account: &Account
|
|||||||
|
|
||||||
pub fn vbox_apply(params: VboxApplyParams, tx: &mut Transaction, account: &Account) -> Result<Player, Error> {
|
pub fn vbox_apply(params: VboxApplyParams, tx: &mut Transaction, account: &Account) -> Result<Player, Error> {
|
||||||
let mut player = player_get(tx, account.id, params.instance_id)?;
|
let mut player = player_get(tx, account.id, params.instance_id)?;
|
||||||
let mut cryp = cryp_get(tx, params.cryp_id, account.id)?;
|
|
||||||
|
|
||||||
let var = player.vbox.bound.remove(params.index);
|
let var = player.vbox.bound.remove(params.index);
|
||||||
|
let skill = var.skill()?;
|
||||||
|
|
||||||
|
// mess with cryp then release it
|
||||||
|
{
|
||||||
|
let cryp = player.cryp_get(params.cryp_id)?;
|
||||||
// done here because i teach them a tonne of skills for tests
|
// done here because i teach them a tonne of skills for tests
|
||||||
let max_skills = 4;
|
let max_skills = 4;
|
||||||
if cryp.skills.len() >= max_skills {
|
if cryp.skills.len() >= max_skills {
|
||||||
return Err(format_err!("cryp at max skills ({:?})", max_skills));
|
return Err(format_err!("cryp at max skills ({:?})", max_skills));
|
||||||
}
|
}
|
||||||
|
|
||||||
let skill = var.skill()?;
|
cryp.learn_mut(skill);
|
||||||
cryp = cryp.learn(skill);
|
}
|
||||||
cryp_write(cryp, tx)?;
|
|
||||||
return player_update(tx, player);
|
return player_update(tx, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user