-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started on lockers. Can put items in but can't take them out
- Loading branch information
Showing
15 changed files
with
295 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use eo::{ | ||
data::{EOInt, EOShort}, | ||
protocol::Item, | ||
}; | ||
|
||
use super::Character; | ||
|
||
impl Character { | ||
pub fn add_bank_item(&mut self, item_id: EOShort, amount: EOInt) { | ||
let existing_item = self.bank.iter_mut().find(|item| item.id == item_id); | ||
|
||
if let Some(existing_item) = existing_item { | ||
existing_item.amount += amount; | ||
} else { | ||
self.bank.push(Item { | ||
id: item_id, | ||
amount, | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use eo::{ | ||
data::{EOShort, StreamReader}, | ||
protocol::{Item, PacketAction}, | ||
}; | ||
|
||
use crate::{map::MapHandle, player::PlayerHandle}; | ||
|
||
fn open(player_id: EOShort, map: MapHandle) { | ||
map.open_locker(player_id); | ||
} | ||
|
||
fn add(reader: StreamReader, player_id: EOShort, map: MapHandle) { | ||
reader.seek(2); | ||
|
||
let item = Item { | ||
id: reader.get_short(), | ||
amount: reader.get_three(), | ||
}; | ||
|
||
map.add_locker_item(player_id, item); | ||
} | ||
|
||
pub async fn locker(action: PacketAction, reader: StreamReader, player: PlayerHandle) { | ||
let player_id = match player.get_player_id().await { | ||
Ok(player_id) => player_id, | ||
Err(e) => { | ||
error!("Failed to get player id: {}", e); | ||
return; | ||
} | ||
}; | ||
|
||
let map = match player.get_map().await { | ||
Ok(map) => map, | ||
Err(e) => { | ||
error!("Failed to get map: {}", e); | ||
return; | ||
} | ||
}; | ||
|
||
match action { | ||
PacketAction::Open => open(player_id, map), | ||
PacketAction::Add => add(reader, player_id, map), | ||
_ => error!("Unhandled packet Locker_{:?}", action), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use std::cmp; | ||
|
||
use eo::{ | ||
data::{EOShort, StreamBuilder}, | ||
protocol::{Coords, Item, PacketAction, PacketFamily}, | ||
pubs::EmfTileSpec, | ||
}; | ||
|
||
use super::Map; | ||
|
||
impl Map { | ||
pub fn add_locker_item(&mut self, player_id: EOShort, item: Item) { | ||
let character = match self.characters.get(&player_id) { | ||
Some(character) => character, | ||
None => return, | ||
}; | ||
|
||
let adjacent_tiles = [ | ||
self.get_tile(&Coords { | ||
x: character.coords.x, | ||
y: character.coords.y - 1, | ||
}), | ||
self.get_tile(&Coords { | ||
x: character.coords.x, | ||
y: character.coords.y + 1, | ||
}), | ||
self.get_tile(&Coords { | ||
x: character.coords.x - 1, | ||
y: character.coords.y, | ||
}), | ||
self.get_tile(&Coords { | ||
x: character.coords.x + 1, | ||
y: character.coords.y, | ||
}), | ||
]; | ||
|
||
if !adjacent_tiles.iter().any(|tile| match tile { | ||
Some(tile) => *tile == EmfTileSpec::BankVault, | ||
None => false, | ||
}) { | ||
return; | ||
} | ||
|
||
let amount = cmp::min(character.get_item_amount(item.id), item.amount); | ||
|
||
if amount == 0 { | ||
return; | ||
} | ||
|
||
let character = match self.characters.get_mut(&player_id) { | ||
Some(character) => character, | ||
None => return, | ||
}; | ||
|
||
character.remove_item(item.id, amount); | ||
character.add_bank_item(item.id, amount); | ||
|
||
let mut builder = StreamBuilder::new(); | ||
builder.add_short(item.id); | ||
builder.add_int(character.get_item_amount(item.id)); | ||
|
||
let weight = character.get_weight(); | ||
builder.add_char(weight.current); | ||
builder.add_char(weight.max); | ||
|
||
for item in &character.bank { | ||
builder.add_short(item.id); | ||
builder.add_three(item.amount); | ||
} | ||
|
||
character.player.as_ref().unwrap().send( | ||
PacketAction::Reply, | ||
PacketFamily::Locker, | ||
builder.get(), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use eo::{ | ||
data::{EOShort, Serializeable, StreamBuilder}, | ||
protocol::{Coords, PacketAction, PacketFamily, ShortItem}, | ||
pubs::EmfTileSpec, | ||
}; | ||
|
||
use super::Map; | ||
|
||
impl Map { | ||
pub fn open_locker(&self, player_id: EOShort) { | ||
let character = match self.characters.get(&player_id) { | ||
Some(character) => character, | ||
None => return, | ||
}; | ||
|
||
let adjacent_tiles = [ | ||
self.get_tile(&Coords { | ||
x: character.coords.x, | ||
y: character.coords.y - 1, | ||
}), | ||
self.get_tile(&Coords { | ||
x: character.coords.x, | ||
y: character.coords.y + 1, | ||
}), | ||
self.get_tile(&Coords { | ||
x: character.coords.x - 1, | ||
y: character.coords.y, | ||
}), | ||
self.get_tile(&Coords { | ||
x: character.coords.x + 1, | ||
y: character.coords.y, | ||
}), | ||
]; | ||
|
||
if adjacent_tiles.iter().any(|tile| match tile { | ||
Some(tile) => *tile == EmfTileSpec::BankVault, | ||
None => false, | ||
}) { | ||
let packet = eo::protocol::server::locker::Open { | ||
locker_coords: character.coords, | ||
locker_items: character | ||
.bank | ||
.iter() | ||
.map(|item| ShortItem { | ||
id: item.id, | ||
amount: item.amount, | ||
}) | ||
.collect(), | ||
}; | ||
|
||
let mut builder = StreamBuilder::new(); | ||
packet.serialize(&mut builder); | ||
|
||
character.player.as_ref().unwrap().send( | ||
PacketAction::Open, | ||
PacketFamily::Locker, | ||
builder.get(), | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
INSERT INTO Bank (character_id, item_id, quantity) | ||
VALUES (:character_id, :item_id, :quantity); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
DELETE FROM Bank | ||
WHERE character_id = :character_id | ||
AND item_id = :item_id; |
Oops, something went wrong.