fix item ids not being set correctly
This commit is contained in:
		
							parent
							
								
									5e9a94081c
								
							
						
					
					
						commit
						3a095a928d
					
				@ -77,6 +77,9 @@ pub fn join_room(id: ClientId,
 | 
			
		||||
 | 
			
		||||
    let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?;
 | 
			
		||||
    let area_client = client_location.get_local_client(id).map_err(|err| -> ClientLocationError { err.into() })?;
 | 
			
		||||
 | 
			
		||||
    item_manager.add_character_to_room(room_id, &client.character, area_client);
 | 
			
		||||
 | 
			
		||||
    let leader = client_location.get_room_leader(room_id).map_err(|err| -> ClientLocationError { err.into() })?;
 | 
			
		||||
    let join_room = builder::room::join_room(id, clients, client_location, room_id, &room)?;
 | 
			
		||||
    let add_to = builder::room::add_to_room(id, &client, &area_client, &leader, item_manager, level_table, room_id)?;
 | 
			
		||||
@ -84,8 +87,6 @@ pub fn join_room(id: ClientId,
 | 
			
		||||
    let room = rooms.get_mut(room_id.0).unwrap().as_mut().unwrap();
 | 
			
		||||
    room.bursting = true;
 | 
			
		||||
 | 
			
		||||
    item_manager.add_character_to_room(room_id, &client.character, area_client);
 | 
			
		||||
 | 
			
		||||
    let mut result: Box<dyn Iterator<Item=(ClientId, SendShipPacket)> + Send> = Box::new(
 | 
			
		||||
        vec![(id, SendShipPacket::JoinRoom(join_room))]
 | 
			
		||||
            .into_iter()
 | 
			
		||||
 | 
			
		||||
@ -59,6 +59,13 @@ pub async fn create_room<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id:
 | 
			
		||||
    create_room_with_difficulty(ship, id, name, password, Difficulty::Normal).await;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub async fn leave_room<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId) {
 | 
			
		||||
    ship.handle(id, &RecvShipPacket::LobbySelect(LobbySelect {
 | 
			
		||||
        menu: 3,
 | 
			
		||||
        lobby: 0,
 | 
			
		||||
    })).await.unwrap().for_each(drop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub async fn create_room_with_difficulty<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, name: &str, password: &str, difficulty: Difficulty) {
 | 
			
		||||
    ship.handle(id, &RecvShipPacket::CreateRoom(CreateRoom {
 | 
			
		||||
        unknown: [0; 2],
 | 
			
		||||
@ -79,4 +86,5 @@ pub async fn join_room<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: Cl
 | 
			
		||||
        menu: ROOM_MENU_ID,
 | 
			
		||||
        item: room_id,
 | 
			
		||||
    })).await.unwrap().for_each(drop);
 | 
			
		||||
    ship.handle(id, &RecvShipPacket::DoneBursting(DoneBursting {})).await.unwrap().for_each(drop);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										104
									
								
								tests/test_rooms.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										104
									
								
								tests/test_rooms.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,104 @@
 | 
			
		||||
use elseware::common::serverstate::{ClientId, ServerState};
 | 
			
		||||
use elseware::entity::gateway::{EntityGateway, InMemoryGateway};
 | 
			
		||||
use elseware::entity::item;
 | 
			
		||||
use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket};
 | 
			
		||||
 | 
			
		||||
use libpso::packet::ship::*;
 | 
			
		||||
use libpso::packet::messages::*;
 | 
			
		||||
 | 
			
		||||
#[path = "common.rs"]
 | 
			
		||||
mod common;
 | 
			
		||||
use common::*;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#[async_std::test]
 | 
			
		||||
async fn test_item_ids_reset_when_rejoining_rooms() {
 | 
			
		||||
    let mut entity_gateway = InMemoryGateway::new();
 | 
			
		||||
 | 
			
		||||
    let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
 | 
			
		||||
    let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
 | 
			
		||||
 | 
			
		||||
    for slot in 0..3 {
 | 
			
		||||
        entity_gateway.create_item(
 | 
			
		||||
            item::NewItemEntity {
 | 
			
		||||
                item: item::ItemDetail::Weapon(
 | 
			
		||||
                    item::weapon::Weapon {
 | 
			
		||||
                        weapon: item::weapon::WeaponType::Saber,
 | 
			
		||||
                        grind: 0,
 | 
			
		||||
                        special: None,
 | 
			
		||||
                        attrs: [None, None, None],
 | 
			
		||||
                        tekked: true,
 | 
			
		||||
                        modifiers: Vec::new(),
 | 
			
		||||
                    }
 | 
			
		||||
                ),
 | 
			
		||||
                location: item::ItemLocation::Inventory {
 | 
			
		||||
                    character_id: char1.id,
 | 
			
		||||
                    slot: slot,
 | 
			
		||||
                    equipped: false,
 | 
			
		||||
                }
 | 
			
		||||
            }).await.unwrap();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for slot in 0..10 {
 | 
			
		||||
        entity_gateway.create_item(
 | 
			
		||||
            item::NewItemEntity {
 | 
			
		||||
                item: item::ItemDetail::Weapon(
 | 
			
		||||
                    item::weapon::Weapon {
 | 
			
		||||
                        weapon: item::weapon::WeaponType::Saber,
 | 
			
		||||
                        grind: 0,
 | 
			
		||||
                        special: None,
 | 
			
		||||
                        attrs: [None, None, None],
 | 
			
		||||
                        tekked: true,
 | 
			
		||||
                        modifiers: Vec::new(),
 | 
			
		||||
                    }
 | 
			
		||||
                ),
 | 
			
		||||
                location: item::ItemLocation::Inventory {
 | 
			
		||||
                    character_id: char2.id,
 | 
			
		||||
                    slot: slot,
 | 
			
		||||
                    equipped: false,
 | 
			
		||||
                }
 | 
			
		||||
            }).await.unwrap();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let mut ship = ShipServerState::builder()
 | 
			
		||||
        .gateway(entity_gateway.clone())
 | 
			
		||||
        .build();
 | 
			
		||||
    log_in_char(&mut ship, ClientId(1), "a1", "a").await;
 | 
			
		||||
    log_in_char(&mut ship, ClientId(2), "a2", "a").await;
 | 
			
		||||
 | 
			
		||||
    join_lobby(&mut ship, ClientId(1)).await;
 | 
			
		||||
    join_lobby(&mut ship, ClientId(2)).await;
 | 
			
		||||
 | 
			
		||||
    create_room(&mut ship, ClientId(1), "room", "").await;
 | 
			
		||||
    let p = ship.handle(ClientId(2), &RecvShipPacket::MenuSelect(MenuSelect {
 | 
			
		||||
        menu: ROOM_MENU_ID,
 | 
			
		||||
        item: 0,
 | 
			
		||||
    })).await.unwrap().collect::<Vec<_>>();
 | 
			
		||||
    ship.handle(ClientId(2), &RecvShipPacket::DoneBursting(DoneBursting {})).await.unwrap().for_each(drop);
 | 
			
		||||
 | 
			
		||||
    match &p[1].1 {
 | 
			
		||||
        SendShipPacket::AddToRoom(add_to) => {
 | 
			
		||||
            println!("addto {:?}", add_to);
 | 
			
		||||
            assert_eq!(add_to.playerinfo.inventory.items.iter().map(|k| k.item_id).collect::<Vec<_>>(),
 | 
			
		||||
                       vec![0x210000,0x210001,0x210002,0x210003,0x210004,0x210005,0x210006,0x210007,0x210008,0x210009,
 | 
			
		||||
                            0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
 | 
			
		||||
        },
 | 
			
		||||
        _ => panic!(),
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    leave_room(&mut ship, ClientId(2)).await;
 | 
			
		||||
 | 
			
		||||
    let p = ship.handle(ClientId(2), &RecvShipPacket::MenuSelect(MenuSelect {
 | 
			
		||||
        menu: ROOM_MENU_ID,
 | 
			
		||||
        item: 0,
 | 
			
		||||
    })).await.unwrap().collect::<Vec<_>>();
 | 
			
		||||
 | 
			
		||||
    match &p[1].1 {
 | 
			
		||||
        SendShipPacket::AddToRoom(add_to) => {
 | 
			
		||||
            assert_eq!(add_to.playerinfo.inventory.items.iter().map(|k| k.item_id).collect::<Vec<_>>(),
 | 
			
		||||
                       vec![0x210000,0x210001,0x210002,0x210003,0x210004,0x210005,0x210006,0x210007,0x210008,0x210009,
 | 
			
		||||
                            0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
 | 
			
		||||
        },
 | 
			
		||||
        _ => panic!(),
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user