Added outfit purchase directives
parent
a6bc1a021d
commit
9f19becf0c
|
@ -5,6 +5,7 @@ use galactica_system::phys::{PhysImage, PhysSim, PhysSimShipHandle, PhysStepReso
|
|||
use galactica_system::PlayerDirective;
|
||||
use galactica_util::timing::Timing;
|
||||
use nalgebra::Point2;
|
||||
use std::iter;
|
||||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
|
||||
|
@ -51,16 +52,6 @@ impl<'a> Game {
|
|||
.get(&ContentIndex::new("shield generator"))
|
||||
.unwrap()
|
||||
.clone(),
|
||||
self.ct
|
||||
.outfits
|
||||
.get(&ContentIndex::new("blaster"))
|
||||
.unwrap()
|
||||
.clone(),
|
||||
self.ct
|
||||
.outfits
|
||||
.get(&ContentIndex::new("blaster"))
|
||||
.unwrap()
|
||||
.clone(),
|
||||
]);
|
||||
|
||||
return player;
|
||||
|
@ -131,9 +122,43 @@ impl<'a> Game {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn apply_directive(&mut self, directive: PlayerDirective, player: &PlayerAgent) {
|
||||
pub fn apply_directive(&mut self, directive: PlayerDirective, player: &mut PlayerAgent) {
|
||||
match directive {
|
||||
_ => self.phys_sim.apply_directive(directive, player),
|
||||
PlayerDirective::None => {}
|
||||
|
||||
PlayerDirective::BuyOutfit { outfit, count } => {
|
||||
let cost = outfit.cost * count;
|
||||
if player.credits >= cost {
|
||||
player.credits -= cost;
|
||||
let ship = self
|
||||
.phys_sim
|
||||
.get_ship_mut(&PhysSimShipHandle(player.ship.unwrap()))
|
||||
.unwrap();
|
||||
ship.add_outfits(iter::repeat(outfit).take(count as usize))
|
||||
}
|
||||
}
|
||||
|
||||
PlayerDirective::SellOutfit { outfit, count } => {
|
||||
let ship = self
|
||||
.phys_sim
|
||||
.get_ship_mut(&PhysSimShipHandle(player.ship.unwrap()))
|
||||
.unwrap();
|
||||
|
||||
if ship.get_data().get_outfits().has_outfit(&outfit, count) {
|
||||
for _ in 0..count {
|
||||
ship.remove_outfit(&outfit);
|
||||
}
|
||||
}
|
||||
|
||||
player.credits += outfit.cost * count;
|
||||
}
|
||||
|
||||
PlayerDirective::Engine(_)
|
||||
| PlayerDirective::Guns(_)
|
||||
| PlayerDirective::Land
|
||||
| PlayerDirective::TurnLeft(_)
|
||||
| PlayerDirective::TurnRight(_)
|
||||
| PlayerDirective::UnLand => self.phys_sim.apply_directive(directive, player),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ use rhai::{plugin::*, Dynamic, Module};
|
|||
#[allow(non_snake_case)]
|
||||
#[allow(non_upper_case_globals)]
|
||||
pub mod player_directive_module {
|
||||
use crate::ui::api::OutfitState;
|
||||
use galactica_system::PlayerDirective;
|
||||
|
||||
pub const None: PlayerDirective = PlayerDirective::None;
|
||||
|
@ -25,4 +26,24 @@ pub mod player_directive_module {
|
|||
pub fn Guns(state: bool) -> PlayerDirective {
|
||||
PlayerDirective::Guns(state)
|
||||
}
|
||||
|
||||
pub fn BuyOutfit(outfit: OutfitState, count: i64) -> PlayerDirective {
|
||||
if count <= 0 {
|
||||
return PlayerDirective::None;
|
||||
}
|
||||
PlayerDirective::BuyOutfit {
|
||||
outfit: outfit.get_outfit().unwrap(),
|
||||
count: count as u32,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn SellOutfit(outfit: OutfitState, count: i64) -> PlayerDirective {
|
||||
if count <= 0 {
|
||||
return PlayerDirective::None;
|
||||
}
|
||||
PlayerDirective::SellOutfit {
|
||||
outfit: outfit.get_outfit().unwrap(),
|
||||
count: count as u32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use galactica_content::Outfit;
|
||||
|
||||
/// An action the player wants to take in the game.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum PlayerDirective {
|
||||
|
@ -21,4 +25,26 @@ pub enum PlayerDirective {
|
|||
|
||||
/// Take off from the planet we're landed on
|
||||
UnLand,
|
||||
|
||||
/// Buy an outfit.
|
||||
/// This directive is ignored if the player does not have enough
|
||||
/// credits to buy the given number of outfits.
|
||||
BuyOutfit {
|
||||
/// The outfit to buy
|
||||
outfit: Arc<Outfit>,
|
||||
|
||||
/// How many of this outfit to buy
|
||||
count: u32,
|
||||
},
|
||||
|
||||
/// Sell an outfit.
|
||||
/// This directive is ignored if the player does not have enough
|
||||
/// outfits to sell.
|
||||
SellOutfit {
|
||||
/// The outfit to sell
|
||||
outfit: Arc<Outfit>,
|
||||
|
||||
/// How many of this outfit to sell
|
||||
count: u32,
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue